using boost::posix_time::seconds;
using I2n::Logger::GlobalLogger;
+
namespace Config
{
int SaveTimerSeconds = 60;
, Ttl( ttl )
{}
+
+const string DnsCache::DoNotUseCacheFile = "do not use cache file!";
+
DnsCache::DnsCache(const IoServiceItem &io_serv,
const std::string &cache_file)
: IpCache()
else if (CacheFile.empty())
GlobalLogger.warning()
<< "DnsCache: skip saving because file name empty!";
- else if (CacheFile == DO_NOT_USE_CACHE_FILE)
+ else if (CacheFile == DoNotUseCacheFile)
GlobalLogger.info() << "DnsCache: configured not to use cache file";
else
{
//oa << boost::serialization::make_nvp("CnameCache", CnameCache);
oa & BOOST_SERIALIZATION_NVP(IpCache);
oa & BOOST_SERIALIZATION_NVP(CnameCache);
- GlobalLogger.info() << "DnsCache: saved to cache file " << CacheFile;
+ GlobalLogger.info() << "DnsCache: saved to cache file "
+ << CacheFile;
HasChanged = false;
}
{
if (CacheFile.empty())
GlobalLogger.warning()
- << "DnsCache: cannot load because cache file name is empty!";
- else if (CacheFile == DO_NOT_USE_CACHE_FILE)
+ << "DnsCache: cannot load because cache file name is empty!";
+ else if (CacheFile == DoNotUseCacheFile)
GlobalLogger.info() << "DnsCache: configured not to use cache file";
else if ( !I2n::file_exists(CacheFile) )
GlobalLogger.warning() << "DnsCache: cannot load because cache file "
}
catch (boost::archive::archive_exception &exc)
{
- GlobalLogger.warning() << "DnsCache: archive exception loading from "
- << CacheFile << ": " << exc.what();
+ GlobalLogger.warning()
+ << "DnsCache: archive exception loading from " << CacheFile
+ << ": " << exc.what();
}
catch (std::exception &exc)
{
while ( result.empty() )
{
current_cname = get_cname(current_host, check_up_to_date);
- current_host = key_for_hostname(current_cname.Host);
- if (current_host.empty())
+ if (current_cname.Host.empty())
break;
- else if (++n_recursions >= Config::MaxRetrievalRecursions)
+
+ current_host = key_for_hostname(current_cname.Host);
+ if (++n_recursions >= Config::MaxRetrievalRecursions)
{
GlobalLogger.warning() << "DnsCache: reached recursion limit of "
<< n_recursions << " in recursive IP retrieval!";
BOOST_FOREACH( HostAddress &addr, result )
{
if (addr.get_ttl().get_value() > min_cname_ttl)
+ {
+ GlobalLogger.debug() << "DnsCache: using shorter CNAME TTL";
addr.set_ttl(cname_ttl);
+ }
}
}
std::string DnsCache::get_first_outdated_cname(const std::string &hostname,
const uint32_t ttl_thresh)
{
- std::string up_to_date_host = hostname;
+ std::string first_outdated = hostname;
Cname cname;
int n_recursions = 0;
while (true)
break;
}
- cname = get_cname(up_to_date_host);
- if (key_for_hostname(cname.Host).empty())
+ cname = get_cname(first_outdated);
+ if (cname.Host.empty())
// reached end of cname list
break;
else if (cname.Ttl.get_updated_value() > ttl_thresh)
// cname is up to date --> continue looking
- up_to_date_host = cname.Host;
+ first_outdated = cname.Host;
else
- // cname is out of date --> return that
+ { // cname is out of date --> return its target
+ first_outdated = cname.Host;
break;
+ }
}
- return up_to_date_host;
+ return first_outdated;
}
// (created using vim -- the world's best text editor)