diff --git a/include/libtorrent/bt_peer_connection.hpp b/include/libtorrent/bt_peer_connection.hpp index 53e9667fc..636d4ace6 100755 --- a/include/libtorrent/bt_peer_connection.hpp +++ b/include/libtorrent/bt_peer_connection.hpp @@ -375,7 +375,7 @@ namespace libtorrent int m_sync_bytes_read; // hold information about latest allocated send buffer - // need to check for non zero (begin, end) for operations with this + // need to check for non zero (begin, end) for operations with this buffer::interval m_enc_send_buffer; // initialized during write_pe1_2_dhkey, and destroyed on diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index ce7e61ec5..63ee4eec1 100755 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -176,6 +176,9 @@ namespace libtorrent void set_non_prioritized(bool b) { m_non_prioritized = b; } + void fast_reconnect(bool r) { m_fast_reconnect = r; } + bool fast_reconnect() const { return m_fast_reconnect; } + // this adds an announcement in the announcement queue // it will let the peer know that we have the given piece void announce_piece(int index); @@ -732,6 +735,13 @@ namespace libtorrent // the number of bytes send to the disk-io // thread that hasn't yet been completely written. int m_outstanding_writing_bytes; + + // if this is true, the disconnection + // timestamp is not updated when the connection + // is closed. This means the time until we can + // reconnect to this peer is shorter, and likely + // immediate. + bool m_fast_reconnect; #ifndef NDEBUG public: diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 56d9307a9..8cd43ce2a 100755 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -205,6 +205,7 @@ namespace libtorrent // if this fails, we need to reconnect // fast. pi->connected = time_now() - seconds(m_ses.settings().min_reconnect_time); + fast_reconnect(true); write_pe1_2_dhkey(); m_state = read_pe_dhkey; @@ -380,7 +381,7 @@ namespace libtorrent buffer::interval send_buf = allocate_send_buffer(dh_key_len + pad_size); - std::copy (m_DH_key_exchange->get_local_key(), + std::copy(m_DH_key_exchange->get_local_key(), m_DH_key_exchange->get_local_key() + dh_key_len, send_buf.begin); @@ -571,7 +572,7 @@ namespace libtorrent const sha1_hash remote_key = h.final(); assert(!m_RC4_handler.get()); - m_RC4_handler.reset (new RC4_handler (local_key, remote_key)); + m_RC4_handler.reset(new RC4_handler (local_key, remote_key)); #ifdef TORRENT_VERBOSE_LOGGING (*m_logger) << " computed RC4 keys\n"; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 327bb2074..8978ff6ac 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -119,6 +119,7 @@ namespace libtorrent , m_remote_dl_rate(0) , m_remote_dl_update(time_now()) , m_outstanding_writing_bytes(0) + , m_fast_reconnect(false) #ifndef NDEBUG , m_in_constructor(true) #endif @@ -195,6 +196,7 @@ namespace libtorrent , m_remote_dl_rate(0) , m_remote_dl_update(time_now()) , m_outstanding_writing_bytes(0) + , m_fast_reconnect(false) #ifndef NDEBUG , m_in_constructor(true) #endif diff --git a/src/policy.cpp b/src/policy.cpp index 212e09f3c..fad9dc072 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -1340,7 +1340,11 @@ namespace libtorrent p->connection = 0; p->optimistically_unchoked = false; - p->connected = time_now(); + // if fast reconnect is true, we won't + // update the timestamp, and it will remain + // the time when we initiated the connection. + if (!c.fast_reconnect()) + p->connected = time_now(); if (c.failed()) {