set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
-find_package(Boost 1.44 COMPONENTS filesystem program_options system REQUIRED)
+find_package(Boost 1.44 COMPONENTS filesystem program_options system serialization date_time REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
# package: boost-net-dns
include_directories(${CMAKE_SOURCE_DIR}/lib/boost-net-dns)
-# package: boost-signal_handler
-include_directories(${CMAKE_SOURCE_DIR}/lib/boost-signal_handler)
-
# package: libi2ncommon
pkg_check_modules(I2NCOMMON REQUIRED libi2ncommon)
include_directories(${I2NCOMMON_INCLUDE_DIRS})
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/hostaddress.cpp
+ dns/dnscache.cpp
+ dns/resolverbase.cpp
+ dns/dnsresolver.cpp
+ dns/dnsmaster.cpp
host/hoststatus.cpp
host/loglevel.cpp
host/logoutput.cpp
void set_resolved_ip_ttl_threshold(
const int resolved_ip_ttl_threshold );
+ std::string get_dns_cache_file() const;
+ void set_dns_cache_file(const std::string &dns_cache_file);
+
float get_ratio_random_hosts() const;
void set_ratio_random_hosts( const float ratio );
void set_print_version( const bool do_print );
bool get_print_version();
- std::string get_dns_cache_file() const;
- void set_dns_cache_file(const std::string &dns_cache_file);
-
bool randomize_hosts();
private:
int PingReplyTimeout;
int MaxAddressResolutionAttempts;
int ResolvedIpTtlThreshold;
+ std::string DnsCacheFile;
HostList Hosts;
float RatioRandomHosts;
bool PrintVersion;
- std::string DnsCacheFile;
rand_gen_type RandomNumberGenerator;
};
Christian Herdtweck, Intra2net AG 2015
*/
-#include "dns_neww/dnscache.h"
+#include "dns/dnscache.h"
#include <fstream>
#include <logfunc.hpp>
Christian Herdtweck, Intra2net AG 2015
*/
-#include "dns_neww/dnsmaster.h"
+#include "dns/dnsmaster.h"
#include <logfunc.hpp>
#include <boost/bind.hpp>
#include <boost/asio/placeholders.hpp>
-#include "dns_neww/ippseudoresolver.h"
-#include "dns_neww/dnsresolver.h"
+#include "dns/ippseudoresolver.h"
+#include "dns/dnsresolver.h"
using boost::bind;
using I2n::Logger::GlobalLogger;
return TheOnlyInstance;
}
+DnsMaster::~DnsMaster()
+{
+ GlobalLogger.info() << "DnsMaster is being destructed";
+
+ if (DnsMaster::TheOnlyInstance)
+ { // just to be sure ...
+ GlobalLogger.warning() << "DnsMaster is being destructed that is not "
+ << "singleton instance TheOnlyInstance!";
+ DnsMaster::TheOnlyInstance.reset();
+ }
+
+ // Items in ResolverMap and the DnsCache might still be referenced by
+ // Resolvers and are smart pointers, anyway --> nothing to do here
+}
+
ResolverItem& DnsMaster::get_resolver_for( const std::string &hostname,
#include "host/pinger.h" // for IoserviceItem
#include "host/pingprotocol.h"
-#include "dns_neww/dnscache.h"
-#include "dns_neww/resolverbase.h"
+#include "dns/dnscache.h"
+#include "dns/resolverbase.h"
class DnsMaster;
typedef boost::shared_ptr<DnsMaster> DnsMasterItem;
typedef boost::net::dns::type_t DnsIpProtocol;
-DnsIpProtocol DNS_IPv4 = boost::net::dns::type_a;
-DnsIpProtocol DNS_IPv6 = boost::net::dns::type_a6;
-DnsIpProtocol DNS_IPALL = boost::net::dns::type_all;
+const DnsIpProtocol DNS_IPv4 = boost::net::dns::type_a;
+const DnsIpProtocol DNS_IPv6 = boost::net::dns::type_a6;
+const DnsIpProtocol DNS_IPALL = boost::net::dns::type_all;
typedef std::pair<std::string, DnsIpProtocol> resolver_key_type;
typedef std::map<resolver_key_type, ResolverItem> resolver_map_type;
from https://github.com/softwareace/Boost.DNS
*/
-#include "dns_neww/dnsresolver.h"
+#include "dns/dnsresolver.h"
+
+#include <stdint.h>
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
const DnsCacheItem cache,
const boost::asio::ip::address &name_server)
: ResolverBase( io_serv, hostname, cache )
- , Socket( *io_serv, ip::udp::endpoint(ip::udp::v4(), 0) )
+ , Socket( *io_serv )
, ReceiveBuffer()
, Protocol( protocol )
, NameServer( name_server, Config::DNS_PORT )
, IsResolving( false )
{ }
+DnsResolver::~DnsResolver()
+{
+ boost::system::error_code error;
+ Socket.shutdown(boost::asio::ip::udp::socket::shutdown_both, error); //both=send&receive
+ if ( error )
+ GlobalLogger.warning() << "Received error " << error
+ << " when shutting down socket for DNS";
+ // in IcmpPinger always gave an error system:9
+ // (probably EBADF: Bad file descriptor)
+
+ Socket.close(error);
+ if ( error )
+ GlobalLogger.warning() << "Received error " << error
+ << " when closing socket for DNS";
+}
+
+
//==============================================================================
// ASYNC RESOLVE
//==============================================================================
/**
- * copied here code from boost::net::dns::resolve.hpp, since want async
+ * copied here code from boost::net::dns::resolve.hpp, since want async
* operation and that is used only internally, there
*/
void DnsResolver::do_resolve()
HostAddressVec cached_data = ResolverBase::get_cached_results();
// get threshold
- int resolved_ip_ttl_threshold = DnsMaster::get_instance()
- ->get_resolved_ip_ttl_threshold();
+ uint32_t resolved_ip_ttl_threshold = static_cast<uint32_t>(
+ DnsMaster::get_instance()->get_resolved_ip_ttl_threshold() );
// loop over addresses
BOOST_FOREACH( const HostAddress &addr, cached_data )
#ifndef DNS_RESOLVER_H
#define DNS_RESOLVER_H
-#include "dns_neww/dnsmaster.h"
+#include "dns/dnsmaster.h"
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/ip/udp.hpp>
#include <boost/system/error_code.hpp>
#include <boost/net/network_array.hpp> // dns_buffer_t
-#include "dns_neww/resolverbase.h"
-#include "dns_neww/dnsmaster.h"
-#include "dns_neww/dnscache.h"
+#include "dns/resolverbase.h"
+#include "dns/dnsmaster.h"
+#include "dns/dnscache.h"
class DnsResolver : public ResolverBase
protected:
void do_resolve();
+// internal helper functions
private:
void handle_resolve_timeout(const boost::system::error_code &error);
void handle_dns_result(const boost::system::error_code &error,
void stop_trying();
void wait_timer_timeout_handler(const boost::system::error_code &error);
+// variables
private:
boost::asio::ip::udp::socket Socket;
boost::net::dns_buffer_t ReceiveBuffer;
#include "dns/hostaddress.h"
#include <boost/version.hpp>
-#include <boost/serialization/serialization.hpp>
#include "boost_assert_handler.h"
{
Ttl = ttl;
}
-
-template<class Archive>
-void HostAddress::serialize(Archive & ar, const unsigned int version)
-{
- ar & Ip;
- ar & Ttl;
-}
#include <boost/asio.hpp>
#include <boost/serialization/access.hpp>
+#include <boost/serialization/nvp.hpp>
+#include <boost/serialization/split_member.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
#include "dns/timetolive.h"
/// time-to-live of the host IP
TimeToLive Ttl;
- /// serialization
+ /// serialization: needs to be implemented here or will not compile
+ // since there is no serialize in ip::address nor ptime,
+ // need to save in other formats here
friend class boost::serialization::access;
template<class Archive>
- void serialize(Archive & ar, const unsigned int version);
+ void save(Archive & ar, const unsigned int version) const
+ {
+ std::string ip = Ip.to_string();
+ std::string now_str = boost::posix_time::to_iso_string(
+ boost::posix_time::second_clock::universal_time());
+ uint32_t ttl_seconds_now = Ttl.get_updated_value();
+
+ ar & BOOST_SERIALIZATION_NVP(ip);
+ ar & BOOST_SERIALIZATION_NVP(now_str);
+ ar & BOOST_SERIALIZATION_NVP(ttl_seconds_now);
+ }
+
+ template<class Archive>
+ void load(Archive & ar, const unsigned int version)
+ {
+ std::string ip;
+ std::string save_time_str;
+ uint32_t ttl_seconds_at_save;
+ ar & BOOST_SERIALIZATION_NVP(ip);
+ ar & BOOST_SERIALIZATION_NVP(save_time_str);
+ ar & BOOST_SERIALIZATION_NVP(ttl_seconds_at_save);
+
+ // now convert to Ip and Ttl
+ Ip = boost::asio::ip::address::from_string(ip);
+ boost::posix_time::ptime save_time =
+ boost::posix_time::from_iso_string(save_time_str);
+ boost::posix_time::ptime now =
+ boost::posix_time::second_clock::universal_time();
+ uint32_t elapsed_seconds_since_save = (save_time - now).total_seconds();
+ if (elapsed_seconds_since_save > ttl_seconds_at_save)
+ Ttl = TimeToLive(0);
+ else
+ Ttl = TimeToLive(ttl_seconds_at_save - elapsed_seconds_since_save);
+ }
+
+ BOOST_SERIALIZATION_SPLIT_MEMBER()
};
//-----------------------------------------------------------------------------
#include <boost/asio/ip/address.hpp>
#include "dns/hostaddress.h"
-#include "dns_neww/resolverbase.h"
-#include "dns_neww/dnsmaster.h"
+#include "dns/resolverbase.h"
+#include "dns/dnsmaster.h"
namespace Config
{
Christian Herdtweck, Intra2net AG 2015
*/
-#include "dns_neww/resolverbase.h"
-#include "dns_neww/dnsmaster.h"
+#include "dns/resolverbase.h"
+#include "dns/dnsmaster.h"
#include <boost/bind.hpp>
+
ResolverBase::~ResolverBase()
-{
-}
+{ }
/**
* callbacks should be of type
#include <queue>
#include "host/pinger.h"
#include "dns/hostaddress.h"
-#include "dns_neww/dnscache.h"
+#include "dns/dnscache.h"
typedef boost::function<void(const bool, const int)> callback_type;
typedef std::queue<callback_type> callback_list_type;
class ResolverBase
{
public:
- virtual HostAddress get_next_ip() = 0;
-
virtual ~ResolverBase();
/**
*/
void async_resolve(const callback_type &callback);
+ virtual HostAddress get_next_ip() = 0;
virtual bool have_up_to_date_ip() = 0;
virtual int get_resolved_ip_count() = 0;
#include "boost_assert_handler.h"
-#include <boost/serialization/serialization.hpp>
-
using boost::date_time::time_resolution_traits_adapted64_impl;
using boost::posix_time::microsec_clock;
using boost::posix_time::ptime;
return remaining_seconds;
}
-
-template<class Archive>
-void TimeToLive::serialize(Archive & ar, const unsigned int version)
-{
- ar & Ttl;
- ar & TtlSetTime;
-}
#include <stdint.h>
#include <boost/asio.hpp>
-#include <boost/serialization/access.hpp>
//-----------------------------------------------------------------------------
// TimeToLive
/// the time when the time-to-live was set, so it is possible to know the
/// elapsed time
boost::posix_time::ptime TtlSetTime;
-
-
- /// serialization
- friend class boost::serialization::access;
- template<class Archive>
- void serialize(Archive & ar, const unsigned int version);
};
#endif // TIME_TO_LIVE_H
#include <boost/foreach.hpp>
#include "boost_assert_handler.h"
-#include "dns_neww/dnsmaster.h"
+#include "dns/dnsmaster.h"
#include "host/pingerfactory.h"
using namespace std;
#include <boost/shared_ptr.hpp>
#include <boost/circular_buffer.hpp>
-#include "dns_neww/resolverbase.h"
+#include "dns/resolverbase.h"
#include "host/pinger.h"
#include "host/pingprotocol.h"
#include "host/pingprotocol.h"
#include "host/pingscheduler.h"
#include "icmp/icmppinger.h" // contains IcmpPacketDistributor
-#include "dns_neww/dnsmaster.h"
+#include "dns/dnsmaster.h"
using namespace std;
${CMAKE_SOURCE_DIR}/src/config/option/pingreplytimeoutoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/maxaddressresolutionattemptsoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/resolvedipttlthresholdoption.cpp
+ ${CMAKE_SOURCE_DIR}/src/config/option/dnscachefileoption.cpp
${CMAKE_SOURCE_DIR}/src/host/loglevel.cpp
${CMAKE_SOURCE_DIR}/src/host/logoutput.cpp
${CMAKE_SOURCE_DIR}/src/host/pingprotocol.cpp
${CMAKE_SOURCE_DIR}/src/config/option/pingreplytimeoutoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/maxaddressresolutionattemptsoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/resolvedipttlthresholdoption.cpp
+ ${CMAKE_SOURCE_DIR}/src/config/option/dnscachefileoption.cpp
${CMAKE_SOURCE_DIR}/src/host/loglevel.cpp
${CMAKE_SOURCE_DIR}/src/host/logoutput.cpp
${CMAKE_SOURCE_DIR}/src/host/pingprotocol.cpp
${CMAKE_SOURCE_DIR}/src/config/option/pingreplytimeoutoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/maxaddressresolutionattemptsoption.cpp
${CMAKE_SOURCE_DIR}/src/config/option/resolvedipttlthresholdoption.cpp
+ ${CMAKE_SOURCE_DIR}/src/config/option/dnscachefileoption.cpp
${CMAKE_SOURCE_DIR}/src/host/loglevel.cpp
${CMAKE_SOURCE_DIR}/src/host/logoutput.cpp
${CMAKE_SOURCE_DIR}/src/host/pingprotocol.cpp