changed how dns deals with cnames and recursion: remember cnames and implement recurs...
[pingcheck] / src / dns / dnsmaster.cpp
index 31814e4..5fa5139 100644 (file)
@@ -36,10 +36,10 @@ using I2n::Logger::GlobalLogger;
 DnsMasterItem DnsMaster::TheOnlyInstance;
 
 void DnsMaster::create_master(const IoServiceItem &io_serv,
-                              const boost::asio::ip::address &name_server,
-                              const int resolved_ip_ttl_threshold,
-                              const int max_address_resolution_attempts,
-                              const std::string &cache_file)
+                            const boost::asio::ip::address &default_name_server,
+                            const int resolved_ip_ttl_threshold,
+                            const int max_address_resolution_attempts,
+                            const std::string &cache_file)
 {
     if (TheOnlyInstance)
     {
@@ -51,7 +51,7 @@ void DnsMaster::create_master(const IoServiceItem &io_serv,
     GlobalLogger.info() << "Creating DNS Cache and Master";
     DnsCacheItem cache( new DnsCache(io_serv, cache_file) );
     TheOnlyInstance.reset( new DnsMaster(io_serv,
-                                         name_server,
+                                         default_name_server,
                                          resolved_ip_ttl_threshold,
                                          max_address_resolution_attempts,
                                          cache)
@@ -60,12 +60,12 @@ void DnsMaster::create_master(const IoServiceItem &io_serv,
 
 
 DnsMaster::DnsMaster(const IoServiceItem &io_serv,
-                     const boost::asio::ip::address &name_server,
+                     const boost::asio::ip::address &default_name_server,
                      const int resolved_ip_ttl_threshold,
                      const int max_address_resolution_attempts,
                      const DnsCacheItem &cache)
     : IoService( io_serv )
-    , NameServer( name_server )
+    , DefaultNameServer( default_name_server )
     , ResolvedIpTtlThreshold( resolved_ip_ttl_threshold )
     , MaxAddressResolutionAttempts( max_address_resolution_attempts )
     , Cache(cache)
@@ -108,8 +108,8 @@ ResolverItem& DnsMaster::get_resolver_for( const std::string &hostname,
 }
 
 
-ResolverItem& DnsMaster::get_resolver_for( const std::string &hostname,
-                                           const DnsIpProtocol &protocol )
+ResolverItem& DnsMaster::get_resolver_for(const std::string &hostname,
+                                    const DnsIpProtocol &protocol)
 {
     DnsMasterItem master = get_instance();
 
@@ -141,13 +141,26 @@ ResolverItem& DnsMaster::get_resolver_for( const std::string &hostname,
                                                        hostname,
                                                        protocol,
                                                        Cache,
-                                                       NameServer) );
+                                                       DefaultNameServer) );
             master->ResolverMap[key] = new_resolver;
         }
     }
     return master->ResolverMap[key];
 }
 
+// create resolver but do not remember it in ResolverMap
+ResolverItem DnsMaster::get_recursor_for(const std::string &hostname,
+                                         const DnsIpProtocol &protocol,
+                                    const boost::asio::ip::address &name_server)
+{
+    ResolverItem new_resolver( new DnsResolver(IoService,
+                                               hostname,
+                                               protocol,
+                                               Cache,
+                                               name_server) );
+    return new_resolver;
+}
+
 /**
  * return true if given hostname string actually is an IP
  *