Ping(),
WantToPing( false ),
LogPrefix(),
- ContinueOnOutdatedIps( false );
+ ContinueOnOutdatedIps( false )
{
BOOST_ASSERT( !network_interface.empty() );
BOOST_ASSERT( !destination_address.empty() );
// ping as soon as dns is ready
WantToPing = true;
- try_to_ping();
+ ping_when_ready();
}
-void PingScheduler::try_to_ping()
+void PingScheduler::ping_when_ready()
{
if ( !WantToPing )
{
GlobalLogger.info() << "PingScheduler: start ping";
WantToPing = false;
+ // try to get an up-to-date IP
HostAddress ip = Resolver->get_next_ip();
+
if ( !ip.is_valid() && ContinueOnOutdatedIps)
- {
+ { // we failed to resolve --> try to use outdated IP
GlobalLogger.info() << LogPrefix << "Checking for outdated IPs";
bool check_up_to_date = false;
ip = Resolver->get_next_ip(check_up_to_date);
GlobalLogger.error() << LogPrefix << "No IP to ping "
<< "-- this should not have happened!!";
WantToPing = true;
- if ( !Resolver.is_resolving() )
+ if ( !Resolver->is_resolving() )
start_resolving_ping_address();
}
+
+ // next time try with up-to-date IP
+ ContinueOnOutdatedIps = false;
}
//------------------------------------------------------------------------------
// show "!" after host name if running on outdated IPs
-void update_log_prefix()
+void PingScheduler::update_log_prefix()
{
std::stringstream temp;
temp << "PS(" << DestinationAddress;
GlobalLogger.warning() << "PingScheduler: have up to date IPs but "
<< "resolver seems to be resolving all the same... "
<< "Start pinging anyway!";
- try_to_ping();
+ ping_when_ready();
}
else
start_resolving_ping_address();
// TODO this is too simple, but need to think more about how to update here!
// (may have to switch back some time to resolver for original host or so
- ContinueOnOutdatedIps = true;
+ ContinueOnOutdatedIps = !was_success;
update_log_prefix();
if ( was_success )
{
HostAnalyzer.set_resolved_ip_count( Resolver->get_resolved_ip_count());
- try_to_ping();
+ ping_when_ready();
}
else
{ // host name resolution failed; try again bypassing first outdated CNAME
+ // or using cached IP
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";
HostAnalyzer.set_resolved_ip_count(0);
- try_to_ping();
+ ping_when_ready();
}
else
- {
+ { // have CNAME to continue
GlobalLogger.notice() << LogPrefix << "DNS failed, "
<< "try again skipping a CNAME and resolving "
<< skip_host << " directly";
Resolver = DnsMaster::get_instance()
->get_resolver_for(skip_host, *ProtocolIter);
- // the original resolver is still alive and cached by DnsMaster
- // and counting down the time to re-try on its own
start_resolving_ping_address();
+
+ // (the original resolver is still alive and cached by DnsMaster and
+ // counting down time to re-try on its own until cancel_resolve)
}
}
}