<node id="n8::n77">
<data key="d6">
<y:ShapeNode>
- <y:Geometry height="30.0" width="133.666015625" x="191.8416015624996" y="884.4569626028557"/>
+ <y:Geometry height="30.0" width="132.72265625" x="192.3132812499996" y="884.4569626028557"/>
<y:Fill color="#339966" transparent="false"/>
<y:BorderStyle color="#000000" type="line" width="1.0"/>
- <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="123.666015625" x="5.0" y="6.015625">expired_resolved_ip<y:LabelModel>
+ <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="122.72265625" x="5.0" y="6.015625">have_up_to_date_ip<y:LabelModel>
<y:SmartNodeLabelModel distance="4.0"/>
</y:LabelModel>
<y:ModelParameter>
<node id="n8::n79">
<data key="d6">
<y:ShapeNode>
- <y:Geometry height="30.0" width="133.666015625" x="1125.833816706751" y="884.4569626028557"/>
+ <y:Geometry height="30.0" width="132.72265625" x="1126.305496394251" y="884.4569626028557"/>
<y:Fill color="#C0C0C0" transparent="false"/>
<y:BorderStyle color="#000000" type="line" width="1.0"/>
- <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="123.666015625" x="5.0" y="6.015625">expired_resolved_ip<y:LabelModel>
+ <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="17.96875" modelName="custom" textColor="#000000" visible="true" width="122.72265625" x="5.0" y="6.015625">have_up_to_date_ip<y:LabelModel>
<y:SmartNodeLabelModel distance="4.0"/>
</y:LabelModel>
<y:ModelParameter>
</data>
</node>
<node id="n8::n81">
- <data key="d5"/>
<data key="d6">
<y:ShapeNode>
<y:Geometry height="30.0" width="91.537109375" x="1137.9041113209191" y="1453.2514246819078"/>
</data>
</node>
<node id="n8::n86">
- <data key="d5"/>
<data key="d6">
<y:ShapeNode>
<y:Geometry height="30.0" width="25.443359375" x="1157.6505289713537" y="1375.3148893585071"/>
</data>
</node>
<node id="n8::n87">
- <data key="d5"/>
<data key="d6">
<y:ShapeNode>
<y:Geometry height="30.0" width="25.443359375" x="271.5360026041667" y="1342.1701756464631"/>
</data>
</edge>
<edge id="n8::e80" source="n8::n13" target="n8::n81">
- <data key="d9"/>
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="0.0" sy="0.0" tx="0.0" ty="0.0">
</data>
</edge>
<edge id="n8::e85" source="n8::n70" target="n8::n87">
- <data key="d9"/>
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="0.0" sy="0.0" tx="0.0" ty="0.0"/>
</data>
</edge>
<edge id="n8::e86" source="n8::n87" target="n8::n86">
- <data key="d9"/>
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="0.0" sy="0.0" tx="0.0" ty="0.0"/>
config/option/maxaddressresolutionattemptsoption.cpp
config/option/resolvedipttlthresholdoption.cpp
config/option/dnscachefileoption.cpp
+ #dns/dnsresolver.cpp
+ #dns/dnsresolverfactory.cpp
+ dns/hostaddress.cpp
+ dns/timetolive.cpp
dns_neww/dnscache.cpp
dns_neww/resolverbase.cpp
dns_neww/dnsresolver.cpp
dns_neww/dnsmaster.cpp
- dns/dnsresolver.cpp
- dns/dnsresolverfactory.cpp
- dns/hostaddress.cpp
- dns/timetolive.cpp
host/hoststatus.cpp
host/loglevel.cpp
host/logoutput.cpp
ResolverBase::~ResolverBase()
{
- DnsMaster::get_instance()->unregister_resolver(Hostname);
}
/**
* packet will be sent.
* @param destination_address The remote address to ping.
* @param destination_port The remote port to ping.
- * @param nameserver Server to resolve the addresses.
*
* @return a Pinger object to able to ping using the given list of protocols.
*/
const string &network_interface,
const string &destination_address,
const uint16_t destination_port,
- const string &nameserver,
const int resolved_ip_ttl_threshold,
const int ping_reply_timeout
)
BOOST_ASSERT( !network_interface.empty() );
BOOST_ASSERT( !destination_address.empty() );
BOOST_ASSERT( 0 < destination_port );
- BOOST_ASSERT( !nameserver.empty() );
return PingRotateItem( new PingRotate(
io_serv,
network_interface,
destination_address,
destination_port,
- nameserver,
resolved_ip_ttl_threshold,
ping_reply_timeout,
protocol_list
const std::string &network_interface,
const std::string &destination_address,
const uint16_t destination_port,
- const std::string &nameserver,
const int resolved_ip_ttl_threshold,
const int ping_reply_timeout
);
#include "host/pingrotate.h"
+#include <logfunc.hpp>
+
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include "boost_assert_handler.h"
-#include "dns/dnsresolverfactory.h"
+#include "dns_neww/dnsmaster.h"
#include "host/pingerfactory.h"
using namespace std;
using boost::function;
using boost::shared_ptr;
+using I2n::Logger::GlobalLogger;
+
//-----------------------------------------------------------------------------
// PingRotate
//-----------------------------------------------------------------------------
* dispatch the pings.
* @param destination_address The remote address to ping.
* @param destination_port The remote port to ping.
- * @param nameserver Server to resolve the addresses.
* @param protocol_list A list of protocols to be used to ping the
* host. The protocols will be used in the order they are in the list.
*/
const string &network_interface,
const string &destination_address,
const uint16_t destination_port,
- const string &nameserver,
const int resolved_ip_ttl_threshold,
const int ping_reply_timeout,
const PingProtocolList &protocol_list
) :
IoService( io_serv ),
NetworkInterfaceName( network_interface ),
- IpList(),
- DestinationAddess( destination_address ),
+ Resolver(),
+ DestinationAddress( destination_address ),
DestinationPort( destination_port ),
- Nameserver( nameserver ),
ResolvedIpTtlThreshold( resolved_ip_ttl_threshold ),
PingReplyTimeout( ping_reply_timeout ),
ProtocolRotate( protocol_list.size() ),
Ping(),
- PingDoneCallback()
+ PingDoneCallback(),
+ DnsResolutionFinished( true ),
+ WantToPing( false )
{
BOOST_ASSERT( !network_interface.empty() );
BOOST_ASSERT( !destination_address.empty() );
BOOST_ASSERT( 0 < destination_port );
- BOOST_ASSERT( !nameserver.empty() );
BOOST_ASSERT( 0 < protocol_list.size() );
// fill circular buffer with protocols
update_ping_protocol();
- string destination_ip = IpList->get_next_ip();
+ WantToPing = true;
+ try_to_ping();
+}
+
+void PingRotate::try_to_ping()
+{
+ if ( !WantToPing )
+ {
+ GlobalLogger.info() << "PingRotate: not pinging yet (not requested to)";
+ return;
+ }
+ else if ( !DnsResolutionFinished )
+ {
+ GlobalLogger.info() << "PingRotate: not pinging yet (DNS not finished)";
+ return;
+ }
+
+ GlobalLogger.info() << "PingRotate: start ping";
+ WantToPing = false;
+ string destination_ip = Resolver->get_next_ip().get_ip().to_string();
+ // TODO: pinger will probably re-create IP from this
+ // --> change pingers to accept ip::address
Ping->ping(
destination_ip,
Ping->stop_pinging();
}
-bool PingRotate::resolve_ping_address() //lint !e1762
+void PingRotate::start_resolving_ping_address() //lint !e1762
{
- return IpList->resolve();
+ DnsResolutionFinished = false;
+ Resolver->async_resolve( boost::bind(&PingRotate::dns_resolve_callback,
+ this, _1, _2) );
}
int PingRotate::get_resolved_ip_count() const
{
- return IpList->get_resolved_ip_count();
+ return Resolver->get_resolved_ip_count();
}
bool PingRotate::have_up_to_date_ip() const
{
- return IpList->have_up_to_date_ip();
+ return Resolver->have_up_to_date_ip();
}
void PingRotate::set_ping_done_callback( function<void(bool)> ping_done_callback )
void PingRotate::update_dns_resolver( PingProtocol current_protocol )
{
- IpList = DnsResolverFactory::createResolver( DestinationAddess, Nameserver, ResolvedIpTtlThreshold, current_protocol );
+ // DNS master caches created resolvers and resolved IPs, so this will
+ // probably just return an existing resolver with already resolved IPs for
+ // requested protocol ( ICMP/TCP is ignored, only IPv4/v6 is important)
+ Resolver = DnsMaster::get_instance()->get_resolver_for(DestinationAddress,
+ current_protocol);
+ // start resolving if no ips available
+ if ( !Resolver->have_up_to_date_ip() )
+ start_resolving_ping_address();
+}
- // 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(); //lint !e534
+void PingRotate::dns_resolve_callback(const bool was_success,
+ const int cname_count)
+{
+ GlobalLogger.info() << "PingRotate: dns resolution finished "
+ << "with success = " << was_success << " "
+ << "and cname_count = " << cname_count;
+ if (DnsResolutionFinished)
+ { // there were probably several calls to async_resolve before it could
+ // finish --> ignore this callback
+ GlobalLogger.info() << "PingRotate: dns resolve callback called "
+ << "but dns is marked as finished already - ignore";
+ return;
+ }
+ else
+ {
+ DnsResolutionFinished = true;
+ try_to_ping();
+ }
}
#include <boost/shared_ptr.hpp>
#include <boost/circular_buffer.hpp>
-#include "dns/dnsresolver.h"
+#include "dns_neww/resolverbase.h"
#include "host/pinger.h"
#include "host/pingprotocol.h"
const std::string &network_interface,
const std::string &destination_address,
const uint16_t destination_port,
- const std::string &nameserver,
const int resolved_ip_ttl_threshold,
const int ping_reply_timeout,
const PingProtocolList &protocol_list
void stop_pinging();
- bool resolve_ping_address();
+ void start_resolving_ping_address();
int get_resolved_ip_count() const;
bool have_up_to_date_ip() const;
void update_dns_resolver( PingProtocol current_protocol );
+ void try_to_ping();
+ void dns_resolve_callback(const bool was_success, const int cname_count);
+
//
// Attributes
//
IoServiceItem IoService;
/// The network interface name
std::string NetworkInterfaceName;
- /// The list of IPs which are aliases to the host DNS
- DnsResolverItem IpList;
+ /// The Dns resolver
+ ResolverItem Resolver;
/// The address to ping
- std::string DestinationAddess;
+ std::string DestinationAddress;
/// 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;
/// time threshold for address resolution
int ResolvedIpTtlThreshold;
/// timeout for ping reply
PingerItem Ping;
/// The callback function
boost::function<void(bool)> PingDoneCallback;
+ /// a flag whether DNS resolution is finished or currently underway
+ bool DnsResolutionFinished;
+ /// a flag whether we should ping as soon as dns is ready
+ bool WantToPing;
};
//-----------------------------------------------------------------------------
#include <logfunc.hpp>
#include "boost_assert_handler.h"
-#include "dns/dnsresolver.h"
#include "host/pingerfactory.h"
#include "icmp/icmppinger.h"
#include "link/linkstatus.h"
* @param ping_protocol_list A list of protocols to use.
* @param ping_interval_in_sec Amount of time between each ping.
* @param ping_fail_percentage_limit Maximum amount of pings that can fail.
- * @param nameserver Server to resolve the addresses.
* @param link_analyzer The object to monitor the link status.
* @param first_delay Delay in seconds from start_pinging to first ping attempt
*/
const PingProtocolList &ping_protocol_list,
const long ping_interval_in_sec,
const int ping_fail_percentage_limit,
- const string &nameserver,
- const int max_address_resolution_attempts,
const int ping_reply_timeout,
const int resolved_ip_ttl_threshold,
LinkStatusItem link_analyzer,
HostAnalyzer( destination_address, ping_fail_percentage_limit, link_analyzer ),
FirstDelay( first_delay ),
AddressResolutionAttempts( 0 ),
- MaxAddressResolutionAttempts( max_address_resolution_attempts ),
EverHadAnyIP( false ),
Ping()
{
BOOST_ASSERT( 0 < destination_port );
BOOST_ASSERT( 0 < ping_interval_in_sec );
BOOST_ASSERT( (0 <= ping_fail_percentage_limit) && (ping_fail_percentage_limit <= 100) );
- BOOST_ASSERT( !nameserver.empty() );
Ping = PingerFactory::createPinger(
ping_protocol_list,
network_interface,
destination_address,
destination_port,
- nameserver,
resolved_ip_ttl_threshold,
ping_reply_timeout
);
// determine if address resolution is required
if ( !ips_up_to_date )
{
- ips_up_to_date = Ping->resolve_ping_address(); // try to resolve
+ Ping->start_resolving_ping_address(); // try to resolve
if ( ips_up_to_date )
{
EverHadAnyIP = true;
else
{ // no IPs --> try again later, possibly report offline before
AddressResolutionAttempts++;
- if (AddressResolutionAttempts >= MaxAddressResolutionAttempts)
+ if (AddressResolutionAttempts >= 10) //MaxAddressResolutionAttempts)
{
GlobalLogger.notice() << "No IPs after " << AddressResolutionAttempts << " DNS queries!";
HostAnalyzer.report_dns_resolution_failure();
const PingProtocolList &ping_protocol_list,
const long ping_interval_in_sec,
const int ping_fail_percentage_limit,
- const std::string &nameserver,
- const int max_address_resolution_attempts,
const int ping_reply_timeout,
const int resolved_ip_ttl_threshold,
LinkStatusItem link_analyzer,
int FirstDelay;
/// number of attempts at Address Resolution
int AddressResolutionAttempts;
- int MaxAddressResolutionAttempts;
/// flag whether any DNS lookup succeeded
// (comparing get_ip_count to 0 might violate assertion in dnsresolver.cpp)
bool EverHadAnyIP;
#include "config/host.h"
#include "link/linkstatus.h"
#include "host/loglevel.h"
-#include "host/pingerfactory.h"
#include "host/pingprotocol.h"
#include "host/pingscheduler.h"
#include "icmp/icmppinger.h" // contains IcmpPacketDistributor
+#include "dns_neww/dnsmaster.h"
using namespace std;
)
{
string default_network_interface = configuration->get_source_network_interface();
- string nameserver = configuration->get_nameserver();
int ping_fail_limit = configuration->get_ping_fail_limit();
- int max_address_resolution_attempts = configuration->get_max_address_resolution_attempts();
int ping_reply_timeout = configuration->get_ping_reply_timeout();
int resolved_ip_ttl_threshold = configuration->get_resolved_ip_ttl_threshold();
protocol_list,
ping_interval_in_sec,
ping_fail_limit,
- nameserver,
- max_address_resolution_attempts,
ping_reply_timeout,
resolved_ip_ttl_threshold,
status_notifier,
io_service_temp.swap( io_service );
io_service_temp.reset();
+ // create Dns master
+ boost::asio::ip::address name_server_ip =
+ boost::asio::ip::address::from_string(
+ configuration->get_nameserver() );
+
+ DnsMaster::create_master(
+ io_service,
+ name_server_ip,
+ configuration->get_resolved_ip_ttl_threshold(),
+ configuration->get_max_address_resolution_attempts(),
+ configuration->get_dns_cache_file() );
+
init_pingers( io_service, configuration, status_notifier, &scheduler_list );
install_signal_handlers( io_service, log_level );