diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index 8d57b27ec..7b08ec11e 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -111,6 +111,7 @@ namespace libtorrent , initial_picker_threshold(4) , allowed_fast_set_size(10) , max_outstanding_disk_bytes_per_connection(64 * 1024) + , handshake_timeout(10) #ifndef TORRENT_DISABLE_DHT , use_dht_as_fallback(true) #endif @@ -270,6 +271,11 @@ namespace libtorrent // to not completely disrupt normal downloads. int max_outstanding_disk_bytes_per_connection; + // the number of seconds to wait for a handshake + // response from a peer. If no response is received + // within this time, the peer is disconnected. + int handshake_timeout; + #ifndef TORRENT_DISABLE_DHT // while this is true, the dht will note be used unless the // tracker is online diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 2032b54c5..5def3438d 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -3000,13 +3000,12 @@ namespace libtorrent return true; } - // if it takes more than 5 seconds to receive - // handshake, disconnect - if (in_handshake() && d > seconds(5)) + // do not stall waiting for a handshake + if (in_handshake() && d > seconds(m_ses.settings().handshake_timeout)) { #ifdef TORRENT_VERBOSE_LOGGING - (*m_logger) << time_now_string() << " *** NO HANDSHAKE [ " - << total_seconds(d) << " seconds ago ] ***\n"; + (*m_logger) << time_now_string() << " *** NO HANDSHAKE [ waited " + << total_seconds(d) << " seconds ] ***\n"; #endif return true; }