From: Guilherme Maciel Ferreira Date: Mon, 5 Mar 2012 11:18:46 +0000 (-0300) Subject: The DNS address resolution is synchronized with the protocol change. X-Git-Tag: v1.5~1^2~17 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=bf761dd7b8c652f39ccca0637464c355cc20bf82;p=pingcheck The DNS address resolution is synchronized with the protocol change. - In this way, when the new protocol requires a different IP version, the DNS resolver is called again to get the according Address Resource Record. - Still needs some intelligence. --- diff --git a/src/host/pingrotate.cpp b/src/host/pingrotate.cpp index 0b0ce8b..4d11fde 100644 --- a/src/host/pingrotate.cpp +++ b/src/host/pingrotate.cpp @@ -20,11 +20,10 @@ #include "host/pingrotate.h" -#include - #include #include +#include "dns/dnsresolverfactory.h" #include "host/pingerfactory.h" using namespace std; @@ -58,8 +57,10 @@ PingRotate::PingRotate( ) : IoService( io_serv ), NetworkInterfaceName( network_interface ), - IpList( destination_address, nameserver ), + IpList(), + DestinationAddess( destination_address ), DestinationPort( destination_port ), + Nameserver( nameserver ), ProtocolList( protocol_list ), Ping(), PingDoneCallback() @@ -69,6 +70,8 @@ PingRotate::PingRotate( BOOST_ASSERT( 0 < destination_port ); BOOST_ASSERT( !nameserver.empty() ); BOOST_ASSERT( 0 < protocol_list.size() ); + + update_ping_protocol(); } /** @@ -91,10 +94,10 @@ void PingRotate::ping( function ping_done_callback ) set_ping_done_callback( ping_done_callback ); - string destination_ip = IpList.get_next_ip(); - update_ping_protocol(); + string destination_ip = IpList->get_next_ip(); + Ping->ping( destination_ip, DestinationPort, @@ -104,17 +107,17 @@ void PingRotate::ping( function ping_done_callback ) bool PingRotate::resolve_ping_address() { - return IpList.resolve(); + return IpList->resolve(); } int PingRotate::get_resolved_ip_count() const { - return IpList.get_resolved_ip_count(); + return IpList->get_resolved_ip_count(); } bool PingRotate::expired_resolved_ip() const { - return IpList.expired_resolved_ip(); + return IpList->expired_resolved_ip(); } void PingRotate::set_ping_done_callback( function ping_done_callback ) @@ -141,13 +144,27 @@ void PingRotate::get_next_ping_protocol() { PingProtocol ping_protocol = ProtocolList.front(); - rotate( ProtocolList.begin(), ++ProtocolList.begin(), ProtocolList.end() ); + ProtocolList.pop_front(); Ping = PingerFactory::createPinger( ping_protocol, IoService, NetworkInterfaceName ); + + update_dns_resolver( ping_protocol ); } } bool PingRotate::can_change_ping_protocol() const { + // TODO can_change_ping_protocol() and get_next_ping_protocol() may be implemented in a Algorithm + // class that can be exchanged in this class to provide an algorithm neutral class return true; } + +void PingRotate::update_dns_resolver( PingProtocol current_protocol ) +{ + IpList = DnsResolverFactory::createResolver( DestinationAddess, Nameserver, current_protocol ); + + // when the protocol change, there is a chance that the IP version required by the new + // protocol differ from the previous one, thus it is required to resolve the address again. + // FIXME add some intelligence here to decide if the new protocol requires to update the DNS + resolve_ping_address(); +} diff --git a/src/host/pingrotate.h b/src/host/pingrotate.h index 90df802..ab49f59 100644 --- a/src/host/pingrotate.h +++ b/src/host/pingrotate.h @@ -73,6 +73,8 @@ private: void get_next_ping_protocol(); bool can_change_ping_protocol() const; + void update_dns_resolver( PingProtocol current_protocol ); + // // Attributes // @@ -82,9 +84,13 @@ private: /// The network interface name std::string NetworkInterfaceName; /// The list of IPs which are aliases to the host DNS - DnsResolver IpList; + DnsResolverItem IpList; + /// The address to ping + std::string DestinationAddess; /// The port to ping at destination host (same port to all protocols in the list) uint16_t DestinationPort; + /// Server to resolve the addresses + std::string Nameserver; /// The list of protocols to ping PingProtocolList ProtocolList; /// Internal boost pinger object