| 1308 | } |
| 1309 | |
| 1310 | void node_impl::terminate_inactive_connections_loop() |
| 1311 | { |
| 1312 | VERIFY_CORRECT_THREAD(); |
| 1313 | std::list<peer_connection_ptr> peers_to_disconnect_gently; |
| 1314 | std::list<peer_connection_ptr> peers_to_disconnect_forcibly; |
| 1315 | std::list<peer_connection_ptr> peers_to_send_keep_alive; |
| 1316 | std::list<peer_connection_ptr> peers_to_terminate; |
| 1317 | |
| 1318 | _recent_block_interval_in_seconds = _delegate->get_current_block_interval_in_seconds(); |
| 1319 | |
| 1320 | // Disconnect peers that haven't sent us any data recently |
| 1321 | // These numbers are just guesses and we need to think through how this works better. |
| 1322 | // If we and our peers get disconnected from the rest of the network, we will not |
| 1323 | // receive any blocks or transactions from the rest of the world, and that will |
| 1324 | // probably make us disconnect from our peers even though we have working connections to |
| 1325 | // them (but they won't have sent us anything since they aren't getting blocks either). |
| 1326 | // This might not be so bad because it could make us initiate more connections and |
| 1327 | // reconnect with the rest of the network, or it might just futher isolate us. |
| 1328 | { |
| 1329 | // As usual, the first step is to walk through all our peers and figure out which |
| 1330 | // peers need action (disconneting, sending keepalives, etc), then we walk through |
| 1331 | // those lists yielding at our leisure later. |
| 1332 | ASSERT_TASK_NOT_PREEMPTED(); |
| 1333 | |
| 1334 | uint32_t handshaking_timeout = _peer_inactivity_timeout; |
| 1335 | fc::time_point handshaking_disconnect_threshold = fc::time_point::now() - fc::seconds(handshaking_timeout); |
| 1336 | for( const peer_connection_ptr handshaking_peer : _handshaking_connections ) |
| 1337 | if( handshaking_peer->connection_initiation_time < handshaking_disconnect_threshold && |
| 1338 | handshaking_peer->get_last_message_received_time() < handshaking_disconnect_threshold && |
| 1339 | handshaking_peer->get_last_message_sent_time() < handshaking_disconnect_threshold ) |
| 1340 | { |
| 1341 | wlog( "Forcibly disconnecting from handshaking peer ${peer} due to inactivity of at least ${timeout} seconds", |
| 1342 | ( "peer", handshaking_peer->get_remote_endpoint() )("timeout", handshaking_timeout ) ); |
| 1343 | wlog("Peer's negotiating status: ${status}, bytes sent: ${sent}, bytes received: ${received}", |
| 1344 | ("status", handshaking_peer->negotiation_status) |
| 1345 | ("sent", handshaking_peer->get_total_bytes_sent()) |
| 1346 | ("received", handshaking_peer->get_total_bytes_received())); |
| 1347 | handshaking_peer->connection_closed_error = fc::exception(FC_LOG_MESSAGE(warn, "Terminating handshaking connection due to inactivity of ${timeout} seconds. Negotiating status: ${status}, bytes sent: ${sent}, bytes received: ${received}", |
| 1348 | ("peer", handshaking_peer->get_remote_endpoint()) |
| 1349 | ("timeout", handshaking_timeout) |
| 1350 | ("status", handshaking_peer->negotiation_status) |
| 1351 | ("sent", handshaking_peer->get_total_bytes_sent()) |
| 1352 | ("received", handshaking_peer->get_total_bytes_received()))); |
| 1353 | peers_to_disconnect_forcibly.push_back( handshaking_peer ); |
| 1354 | } |
| 1355 | |
| 1356 | // timeout for any active peers is two block intervals |
| 1357 | uint32_t active_disconnect_timeout = 10 * _recent_block_interval_in_seconds; |
| 1358 | uint32_t active_send_keepalive_timeout = active_disconnect_timeout / 2; |
| 1359 | |
| 1360 | // set the ignored request time out to 1 second. When we request a block |
| 1361 | // or transaction from a peer, this timeout determines how long we wait for them |
| 1362 | // to reply before we give up and ask another peer for the item. |
| 1363 | // Ideally this should be significantly shorter than the block interval, because |
| 1364 | // we'd like to realize the block isn't coming and fetch it from a different |
| 1365 | // peer before the next block comes in. At the current target of 3 second blocks, |
| 1366 | // 1 second seems reasonable. When we get closer to our eventual target of 1 second |
| 1367 | // blocks, this will need to be re-evaluated (i.e., can we set the timeout to 500ms |
nothing calls this directly
no test coverage detected