did minor changes; used this version for testing over week-end
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 30 Apr 2015 16:34:55 +0000 (18:34 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 4 May 2015 14:57:59 +0000 (16:57 +0200)
src/dns/dnscache.cpp
src/dns/dnsresolver.cpp
src/host/pingscheduler.cpp

index 7f48183..c79ef83 100644 (file)
@@ -217,7 +217,7 @@ void DnsCache::update(const std::string &hostname,
             << " removes CNAME to " << get_cname(hostname).Host << "!";
         update(hostname, Cname());   // overwrite with "empty" cname
     }
-    GlobalLogger.debug() << "DnsCache: update IPs for " << key
+    GlobalLogger.info() << "DnsCache: update IPs for " << key
                         << " to " << new_ips.size() << "-list";
     IpCache[key] = new_ips;
     HasChanged = true;
@@ -273,12 +273,12 @@ HostAddressVec DnsCache::get_ips(const std::string &hostname,
         }
         result = result_up_to_date;
     }
-    GlobalLogger.debug() << "DnsCache: request IPs for " << key
+    /*GlobalLogger.debug() << "DnsCache: request IPs for " << key
                          << " --> " << result.size() << "-list";
     BOOST_FOREACH( const HostAddress &addr, result )
         GlobalLogger.debug() << "DnsCache:    " << addr.get_ip().to_string()
                              << " (TTL " << addr.get_ttl().get_updated_value()
-                             << "s)";
+                             << "s)"; */
     return result;
 }
 
@@ -290,9 +290,9 @@ Cname DnsCache::get_cname(const std::string &hostname,
 {
     std::string key = key_for_hostname(hostname);
     Cname result_obj = CnameCache[key];
-    GlobalLogger.debug() << "DnsCache: request CNAME for " << key
+    /*GlobalLogger.debug() << "DnsCache: request CNAME for " << key
                          << " --> \"" << result_obj.Host << "\" (TTL "
-                         << result_obj.Ttl.get_updated_value() << "s)";
+                         << result_obj.Ttl.get_updated_value() << "s)";*/
     if (result_obj.Host.empty())
         return result_obj;
 
@@ -355,7 +355,7 @@ HostAddressVec DnsCache::get_ips_recursive(const std::string &hostname,
         {
             if (addr.get_ttl().get_updated_value() > min_cname_ttl)
             {
-                GlobalLogger.debug() << "DnsCache: using shorter CNAME TTL";
+                //GlobalLogger.debug() << "DnsCache: using shorter CNAME TTL";
                 addr.set_ttl(cname_ttl);
             }
         }
index 085eda0..52c485c 100644 (file)
@@ -232,6 +232,7 @@ void DnsResolver::handle_dns_result(const boost::system::error_code &error,
                                                           &result_name_servers);
     // results should have the logical order
     // Hostname [ --> cname1 --> cname2 --> ... --> cnameN ] [ --> ips ]
+    // for cname count to be correct; rest of code should not be affected if not
 
     // remember cname list (if there were any)
     BOOST_FOREACH( const src_cname_pair &host_and_cname, result_cnames )
index 15f10fa..430b5e0 100644 (file)
@@ -170,7 +170,8 @@ void PingScheduler::ping_when_ready()
 {
     if ( !WantToPing )
     {
-        GlobalLogger.info() << LogPrefix << "waiting for ping request";
+        GlobalLogger.info() << LogPrefix << "waiting for ping request "
+            << "(should take less than " << PingIntervalInSec << "s)";
         return;
     }
     else if ( Resolver && Resolver->is_resolving() )
@@ -213,13 +214,18 @@ void PingScheduler::ping_when_ready()
     else
     {
         uint32_t ttl = ip.get_ttl().get_updated_value();
-        boost::posix_time::ptime now =
+        std::string expiry;
+        if (ttl == 0)
+            expiry = "out of date!";
+        else
+        {
+            boost::posix_time::ptime now =
                                   boost::posix_time::second_clock::local_time();
-        std::string expiry =
-                        boost::posix_time::to_simple_string(now + seconds(ttl));
+            expiry = boost::posix_time::to_simple_string(now + seconds(ttl));
+        }
 
         GlobalLogger.info() << LogPrefix << "pinging IP " << ip.get_ip()
-            << " with TTL " << ttl << "s (until " << expiry << ")";
+            << " with TTL " << ttl << "s (" << expiry << ")";
         Ping->ping( ip.get_ip(),
                     DestinationPort,
                     boost::bind(&PingScheduler::ping_done_handler, this, _1) );
@@ -373,12 +379,13 @@ void PingScheduler::update_dns_resolver( PingProtocol current_protocol )
                                                            current_protocol);
 
     // get number of up-to-date IPs
+    // TODO should check here, if they will be up to date in PingIntervalInSec
     bool check_up_to_date = true;
     int ip_count = Resolver->get_resolved_ip_count(check_up_to_date);
     if (ip_count > 0)
     {
         GlobalLogger.info() << LogPrefix << "Set resolved_ip_count to "
-            << ip_count << " where IPs may be outdated: " << false;
+            << ip_count << " where IPs may be outdated: " << !check_up_to_date;
         HostAnalyzer.set_resolved_ip_count( ip_count );
 
         if (Resolver->is_resolving())
@@ -388,8 +395,12 @@ void PingScheduler::update_dns_resolver( PingProtocol current_protocol )
         ping_when_ready();
     }
     else
+    {
+        GlobalLogger.info() << LogPrefix
+                            << "No up-to-date IPs --> start resolve";
         start_resolving_ping_address();
-        // set resolved_ip_count in resolve callback
+        // set resolved_ip_count will be called in resolve callback
+    }
 }
 
 void PingScheduler::start_resolving_ping_address()