Commit | Line | Data |
---|---|---|
0b72647e GMF |
1 | /* |
2 | The software in this package is distributed under the GNU General | |
3 | Public License version 2 (with a special exception described below). | |
4 | ||
5 | A copy of GNU General Public License (GPL) is included in this distribution, | |
6 | in the file COPYING.GPL. | |
7 | ||
8 | As a special exception, if other files instantiate templates or use macros | |
9 | or inline functions from this file, or you compile this file and link it | |
10 | with other works to produce a work based on this file, this file | |
11 | does not by itself cause the resulting work to be covered | |
12 | by the GNU General Public License. | |
13 | ||
14 | However the source code for this file must still be made available | |
15 | in accordance with section (3) of the GNU General Public License. | |
16 | ||
17 | This exception does not invalidate any other reasons why a work based | |
18 | on this file might be covered by the GNU General Public License. | |
19 | */ | |
20 | ||
ce8c4001 GMF |
21 | #ifndef PING_ROTATE_H |
22 | #define PING_ROTATE_H | |
0b72647e GMF |
23 | |
24 | #include <stdint.h> | |
25 | ||
26 | #include <string> | |
27 | ||
28 | #include <boost/asio.hpp> | |
29 | #include <boost/function.hpp> | |
e58d7507 | 30 | #include <boost/shared_ptr.hpp> |
a435b71b | 31 | #include <boost/circular_buffer.hpp> |
0b72647e | 32 | |
c5b4902d | 33 | #include "dns/resolverbase.h" |
0b72647e GMF |
34 | #include "host/pinger.h" |
35 | #include "host/pingprotocol.h" | |
36 | ||
37 | //----------------------------------------------------------------------------- | |
38 | // PingRotate | |
39 | //----------------------------------------------------------------------------- | |
40 | ||
a435b71b CH |
41 | typedef boost::circular_buffer<PingProtocol> CircularProtocolList; |
42 | ||
0b72647e GMF |
43 | /** |
44 | * @brief This class is a wrapper to the Pingers, and serves to alternate | |
45 | * between protocols. | |
46 | * Scope: one object per host. | |
47 | */ | |
823623d9 | 48 | class PingRotate |
0b72647e GMF |
49 | { |
50 | public: | |
51 | PingRotate( | |
365036be | 52 | const IoServiceItem io_serv, |
0b72647e | 53 | const std::string &network_interface, |
823623d9 GMF |
54 | const std::string &destination_address, |
55 | const uint16_t destination_port, | |
079d19ab CH |
56 | const int resolved_ip_ttl_threshold, |
57 | const int ping_reply_timeout, | |
8837460c | 58 | const PingProtocolList &protocol_list |
0b72647e GMF |
59 | ); |
60 | virtual ~PingRotate(); | |
61 | ||
823623d9 GMF |
62 | void ping( boost::function<void(bool)> ping_done_callback ); |
63 | ||
5a9bc2d1 CH |
64 | void stop_pinging(); |
65 | ||
9490a7bd | 66 | void start_resolving_ping_address(); |
823623d9 | 67 | int get_resolved_ip_count() const; |
d4b20892 | 68 | bool have_up_to_date_ip() const; |
0b72647e GMF |
69 | |
70 | private: | |
71 | // | |
72 | // Methods | |
73 | // | |
74 | ||
823623d9 | 75 | void set_ping_done_callback( boost::function<void(bool)> ping_done_callback ); |
d4828254 | 76 | void ping_done_handler( bool ping_success ) const; |
823623d9 | 77 | |
3eb8c4bd | 78 | void init_ping_protocol(); |
1513bb78 | 79 | void update_ping_protocol(); |
0b72647e GMF |
80 | void get_next_ping_protocol(); |
81 | bool can_change_ping_protocol() const; | |
82 | ||
bf761dd7 GMF |
83 | void update_dns_resolver( PingProtocol current_protocol ); |
84 | ||
9490a7bd CH |
85 | void try_to_ping(); |
86 | void dns_resolve_callback(const bool was_success, const int cname_count); | |
87 | ||
0b72647e GMF |
88 | // |
89 | // Attributes | |
90 | // | |
91 | ||
92 | /// The IO service object, which has the loop event | |
fc7ae593 | 93 | IoServiceItem IoService; |
0b72647e GMF |
94 | /// The network interface name |
95 | std::string NetworkInterfaceName; | |
9490a7bd CH |
96 | /// The Dns resolver |
97 | ResolverItem Resolver; | |
bf761dd7 | 98 | /// The address to ping |
9490a7bd | 99 | std::string DestinationAddress; |
823623d9 GMF |
100 | /// The port to ping at destination host (same port to all protocols in the list) |
101 | uint16_t DestinationPort; | |
079d19ab CH |
102 | /// time threshold for address resolution |
103 | int ResolvedIpTtlThreshold; | |
104 | /// timeout for ping reply | |
105 | const int PingReplyTimeout; | |
0b72647e | 106 | /// The list of protocols to ping |
a435b71b | 107 | CircularProtocolList ProtocolRotate; |
0b72647e GMF |
108 | /// Internal boost pinger object |
109 | PingerItem Ping; | |
110 | /// The callback function | |
111 | boost::function<void(bool)> PingDoneCallback; | |
9490a7bd CH |
112 | /// a flag whether DNS resolution is finished or currently underway |
113 | bool DnsResolutionFinished; | |
114 | /// a flag whether we should ping as soon as dns is ready | |
115 | bool WantToPing; | |
0b72647e GMF |
116 | }; |
117 | ||
823623d9 GMF |
118 | //----------------------------------------------------------------------------- |
119 | // PingRotateItem | |
120 | //----------------------------------------------------------------------------- | |
121 | ||
122 | typedef boost::shared_ptr<PingRotate> PingRotateItem; | |
123 | ||
0b72647e | 124 | #endif // PING_ROTATE_H |