deal with case that have no IP from DNS nor from Cache
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 22 May 2015 10:01:24 +0000 (12:01 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 22 May 2015 10:01:24 +0000 (12:01 +0200)
src/host/hoststatus.cpp
src/host/pingscheduler.cpp

index 6f7d590..d620e58 100644 (file)
@@ -63,7 +63,7 @@ HostStatus::~HostStatus()
  */
 void HostStatus::set_resolved_ip_count( const int resolved_ip_count )
 {
-    BOOST_ASSERT( 1 <= resolved_ip_count );
+    BOOST_ASSERT( 0 <= resolved_ip_count );
 
     if (resolved_ip_count != ResolvedIpCount)
     {   // assume that the target has changed --> reset counters
index 481d394..abeb02d 100644 (file)
@@ -205,7 +205,10 @@ void PingScheduler::ping_when_ready()
             << "-- treat like a failed ping.";
 
         // skip the ping and directly call ping_done_handler
+        HostAnalyzer.set_resolved_ip_count(1);   // must have been 0 --> failed
+             // ping would create failed assumption (nPings > nIPs)
         ping_done_handler(false);
+        HostAnalyzer.set_resolved_ip_count(0);   // set back
     }
     else
     {
@@ -446,17 +449,25 @@ void PingScheduler::dns_resolve_callback(const bool was_success,
     else
     {   // host name resolution failed; try again bypassing first outdated CNAME
         // or using cached IP
-        ContinueOnOutdatedIps = true;
-        update_log_prefix();
-
         std::string skip_host = Resolver->get_skip_cname();
 
         if (skip_host.empty())
-        {   // continue with IP
-            GlobalLogger.notice() << LogPrefix << "DNS failed, "
-                << "try anyway with cached data";
-
+        {   // try to continue with cached IPs
             int ip_count = Resolver->get_resolved_ip_count(false);
+
+            if (ip_count == 0)
+                GlobalLogger.notice() << LogPrefix << "DNS failed "
+                    << "and have no cached IPs either --> cannot ping";
+                // ping_when_ready will deal with this case
+            else
+            {
+                ContinueOnOutdatedIps = true;
+                update_log_prefix();
+
+                GlobalLogger.notice() << LogPrefix << "DNS failed, "
+                    << "try anyway with cached data";
+            }
+
             GlobalLogger.info() << LogPrefix << "Set resolved_ip_count to "
                 << ip_count << " (IPs may be outdated=" << true << ")";
             HostAnalyzer.set_resolved_ip_count( ip_count );
@@ -465,6 +476,8 @@ void PingScheduler::dns_resolve_callback(const bool was_success,
         }
         else
         {   // have CNAME to continue
+            ContinueOnOutdatedIps = true;
+            update_log_prefix();
             GlobalLogger.notice() << LogPrefix << "DNS failed, "
                 << "try again skipping a CNAME and resolving "
                 << skip_host << " directly";