@@ -22,6 +22,7 @@ class peer_probe : public graphene::net::peer_connection_delegate
22
22
bool _done = false ;
23
23
graphene::net::peer_connection_ptr _connection = graphene::net::peer_connection::make_shared(this );
24
24
fc::promise<void >::ptr _probe_complete_promise = fc::promise<void >::create(" probe_complete" );
25
+ fc::future<void > _timeout_handler;
25
26
26
27
fc::ip::endpoint _remote;
27
28
graphene::net::node_id_t _node_id;
@@ -50,6 +51,15 @@ class peer_probe : public graphene::net::peer_connection_delegate
50
51
chain_id,
51
52
fc::variant_object ());
52
53
54
+ constexpr uint16_t timeout = 180 ; // seconds
55
+ _timeout_handler = fc::schedule ( [this ]() {
56
+ wlog ( " Communication with peer ${remote} took too long, closing connection" , (" remote" , _remote) );
57
+ wdump ( (_peers)(_peers.size ()) );
58
+ _timeout_handler = fc::future<void >();
59
+ _we_closed_connection = true ;
60
+ _connection->close_connection ();
61
+ }, fc::time_point::now () + fc::seconds (timeout), " timeout_handler" );
62
+
53
63
_connection->send_message (hello);
54
64
} catch ( const fc::exception & e ) {
55
65
ilog ( " Got exception when connecting to peer ${endpoint} ${e}" ,
@@ -156,8 +166,9 @@ class peer_probe : public graphene::net::peer_connection_delegate
156
166
{
157
167
// Note: In rare cases, the peer may neither send us an address_message nor close the connection,
158
168
// causing us to wait forever.
159
- // We tolerate it, because this program (network_mapper) is not critical .
169
+ // In this case the timeout handler will close the connection .
160
170
_done = true ;
171
+ _timeout_handler.cancel ();
161
172
_probe_complete_promise->set_value ();
162
173
}
163
174
@@ -230,7 +241,7 @@ int main(int argc, char** argv)
230
241
const auto & update_info_by_address_info = [ &address_info_by_node_id, &my_node_id, &nodes_already_visited,
231
242
&nodes_to_visit_set, &nodes_to_visit ] ( const graphene::net::address_info& info )
232
243
{
233
- if ( info.node_id == my_node_id) // We should not be in the list, just be defensive here
244
+ if ( info.node_id == graphene::net::node_id_t ( my_node_id) ) // We should not be in the list, be defensive
234
245
return ;
235
246
if (nodes_already_visited.find (info.remote_endpoint ) == nodes_already_visited.end () &&
236
247
nodes_to_visit_set.find (info.remote_endpoint ) == nodes_to_visit_set.end ())
@@ -361,7 +372,8 @@ int main(int argc, char** argv)
361
372
constexpr uint16_t pair_depth = 2 ;
362
373
for (auto & node_and_connections : connections_by_node_id)
363
374
for (const graphene::net::address_info& this_connection : node_and_connections.second )
364
- if ( this_connection.node_id != my_node_id ) // We should not be in the list, just be defensive here
375
+ if ( this_connection.node_id != graphene::net::node_id_t (my_node_id) ) // We should not be in the list,
376
+ // just be defensive here
365
377
dot_stream << " \" " << fc::variant ( node_and_connections.first , pair_depth ).as_string ()
366
378
<< " \" -- \" " << fc::variant ( this_connection.node_id , 1 ).as_string () << " \" ;\n " ;
367
379
0 commit comments