* @brief Create a Pinger object suitable to the given list of protocols.
*
* @param protocol_list A list of the available ping protocols.
- * @param protocol_fallback_count The amount of pings to perform before change the protocol.
* @param io_serv The @c io_service object.
* @param network_interface The network interface name from where the ping
* packet will be sent.
*/
PingRotateItem PingerFactory::createPinger(
const PingProtocolList &protocol_list,
- const int protocol_fallback_count,
io_service &io_serv,
const string &network_interface,
const string &destination_address,
const uint16_t destination_port,
const string &nameserver
-
)
{
BOOST_ASSERT( 0 < protocol_list.size() );
destination_address,
destination_port,
nameserver,
- protocol_list,
- protocol_fallback_count
+ protocol_list
) );
}
static PingRotateItem createPinger(
const PingProtocolList &protocol_list,
- const int protocol_fallback_count,
boost::asio::io_service &io_serv,
const std::string &network_interface,
const std::string &destination_address,
* @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.
- * @param protocol_fallback_count The amount of pings to perform before change the protocol.
*/
PingRotate::PingRotate(
io_service &io_serv,
const string &destination_address,
const uint16_t destination_port,
const string &nameserver,
- const PingProtocolList protocol_list,
- const int protocol_fallback_count
+ const PingProtocolList protocol_list
) :
IoService( io_serv ),
NetworkInterfaceName( network_interface ),
DestinationPort( destination_port ),
Nameserver( nameserver ),
ProtocolList( protocol_list ),
- ProtocolFallbackCount( protocol_fallback_count ),
- PingCount( 0 ),
Ping(),
PingDoneCallback()
{
BOOST_ASSERT( !nameserver.empty() );
BOOST_ASSERT( 0 < protocol_list.size() );
- get_next_ping_protocol();
+ update_ping_protocol();
}
/**
void PingRotate::ping( function<void(bool)> ping_done_callback )
{
BOOST_ASSERT( ( 0 < DestinationPort ) && ( DestinationPort < numeric_limits<uint16_t>::max() ) );
- BOOST_ASSERT( ( 0 <= PingCount ) && ( PingCount < numeric_limits<int>::max() ) );
set_ping_done_callback( ping_done_callback );
DestinationPort,
boost::bind(&PingRotate::ping_done_handler, this, _1)
);
-
- PingCount++;
}
bool PingRotate::resolve_ping_address()
bool PingRotate::can_change_ping_protocol() const
{
- BOOST_ASSERT( ( 0 <= ProtocolFallbackCount ) && ( ProtocolFallbackCount < numeric_limits<int>::max() ) );
- BOOST_ASSERT( ( 0 <= PingCount ) && ( PingCount < numeric_limits<int>::max() ) );
-
// 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 ( PingCount >= ProtocolFallbackCount );
+ return true;
}
void PingRotate::update_dns_resolver( PingProtocol current_protocol )
on this file might be covered by the GNU General Public License.
*/
-#ifndef PING_ROTATE_H
-#define PING_ROTATE_H
+#ifndef PIN_GROTATE_H
+#define PIN_GROTATE_H
#include <stdint.h>
const std::string &destination_address,
const uint16_t destination_port,
const std::string &nameserver,
- const PingProtocolList protocol_list,
- const int protocol_fallback_count
+ const PingProtocolList protocol_list
);
virtual ~PingRotate();
std::string Nameserver;
/// The list of protocols to ping
PingProtocolList ProtocolList;
- /// The amount of pings to perform before change the protocol
- const int ProtocolFallbackCount;
- /// The amount of pings performed
- int PingCount;
/// Internal boost pinger object
PingerItem Ping;
/// The callback function
* @param destination_address The remote address to ping.
* @param destination_port The remote port to ping.
* @param ping_protocol_list A list of protocols to use.
- * @param ping_protocol_fallback_count The amount of pings to perform before change the protocol.
* @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.
const string &destination_address,
const uint16_t destination_port,
const PingProtocolList ping_protocol_list,
- const int protocol_fallback_count,
const long ping_interval_in_sec,
const int ping_fail_percentage_limit,
const string &nameserver,
Ping = PingerFactory::createPinger(
ping_protocol_list,
- protocol_fallback_count,
IoService,
network_interface,
destination_address,
const std::string &destination_address,
const uint16_t destination_port,
const PingProtocolList ping_protocol_list,
- const int protocol_fallback_count,
const long ping_interval_in_sec,
const int ping_fail_percentage_limit,
const std::string &nameserver,
string destination_address = host->get_address();
uint16_t destination_port = host->get_port();
PingProtocolList protocol_list = host->get_ping_protocol_list();
- int protocol_fallback_count = host->get_ping_protocol_fallback_count();
int ping_interval_in_sec = host->get_interval_in_sec();
PingSchedulerItem scheduler(
new PingScheduler(
destination_address,
destination_port,
protocol_list,
- protocol_fallback_count,
ping_interval_in_sec,
ping_fail_limit,
nameserver,