Revert "Perform N pings using one protocol, then after those N pings, switch to"
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sun, 11 Mar 2012 20:26:03 +0000 (17:26 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sun, 11 Mar 2012 20:48:49 +0000 (17:48 -0300)
This reverts commit 46531881f06af5666d62a74836b1101cdcb779d9.

src/host/pingerfactory.cpp
src/host/pingerfactory.h
src/host/pingrotate.cpp
src/host/pingrotate.h
src/host/pingscheduler.cpp
src/host/pingscheduler.h
src/main.cpp

index cc50336..561d170 100644 (file)
@@ -116,7 +116,6 @@ PingerItem PingerFactory::createPinger(
  * @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.
@@ -128,13 +127,11 @@ PingerItem PingerFactory::createPinger(
  */
 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() );
@@ -149,7 +146,6 @@ PingRotateItem PingerFactory::createPinger(
             destination_address,
             destination_port,
             nameserver,
-            protocol_list,
-            protocol_fallback_count
+            protocol_list
     ) );
 }
index 8f2b71d..05d3415 100644 (file)
@@ -45,7 +45,6 @@ public:
 
     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,
index 2c94783..c8b3433 100644 (file)
@@ -46,7 +46,6 @@ using boost::shared_ptr;
  * @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,
@@ -54,8 +53,7 @@ PingRotate::PingRotate(
         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 ),
@@ -64,8 +62,6 @@ PingRotate::PingRotate(
     DestinationPort( destination_port ),
     Nameserver( nameserver ),
     ProtocolList( protocol_list ),
-    ProtocolFallbackCount( protocol_fallback_count ),
-    PingCount( 0 ),
     Ping(),
     PingDoneCallback()
 {
@@ -75,7 +71,7 @@ PingRotate::PingRotate(
     BOOST_ASSERT( !nameserver.empty() );
     BOOST_ASSERT( 0 < protocol_list.size() );
 
-    get_next_ping_protocol();
+    update_ping_protocol();
 }
 
 /**
@@ -95,7 +91,6 @@ PingRotate::~PingRotate()
 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 );
 
@@ -108,8 +103,6 @@ void PingRotate::ping( function<void(bool)> ping_done_callback )
             DestinationPort,
             boost::bind(&PingRotate::ping_done_handler, this, _1)
     );
-
-    PingCount++;
 }
 
 bool PingRotate::resolve_ping_address()
@@ -161,13 +154,9 @@ void PingRotate::get_next_ping_protocol()
 
 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 )
index 61b0f3c..f666d11 100644 (file)
@@ -18,8 +18,8 @@
  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>
 
@@ -51,8 +51,7 @@ public:
             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();
 
@@ -94,10 +93,6 @@ private:
     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
index ea0b128..6138afa 100644 (file)
@@ -53,7 +53,6 @@ using I2n::Logger::GlobalLogger;
  * @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.
@@ -64,7 +63,6 @@ PingScheduler::PingScheduler(
         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,
@@ -89,7 +87,6 @@ PingScheduler::PingScheduler(
 
     Ping = PingerFactory::createPinger(
             ping_protocol_list,
-            protocol_fallback_count,
             IoService,
             network_interface,
             destination_address,
index 0029297..583ff44 100644 (file)
@@ -53,7 +53,6 @@ public:
             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,
index 16fc853..17f685f 100644 (file)
@@ -123,7 +123,6 @@ void init_pingers(
         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(
@@ -131,7 +130,6 @@ void init_pingers(
                         destination_address,
                         destination_port,
                         protocol_list,
-                        protocol_fallback_count,
                         ping_interval_in_sec,
                         ping_fail_limit,
                         nameserver,