From 77d856916c9966912f1bc7a1c8509c152db6cfa1 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Fri, 21 Feb 2014 19:27:58 -0300 Subject: [PATCH] allow DHT tracker to report untested peers in case we are short of "known good" ones (recently connected). this change permit some peers from resume file to be reported right away, without waiting torrent to unpause. --- libtorrent/src/torrent.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index 79698f6c..9952ede7 100644 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -2083,19 +2083,24 @@ namespace libtorrent //TORRENT_ASSERT(m_allow_peers); - // [MF] use m_dht->announce with myself=false to update dht tracker with peers we know - { + // [MF] use m_dht->announce with myself=false to update dht tracker with peers we know. + // in case we are short of "known good" peers (recently connected), in second pass we report the others. + int minPeersToAnnounce = 10; + for(int pass = 0; pass < 2 && minPeersToAnnounce > 0; pass++) { policy::const_iterator i = get_policy().begin_peer(); policy::const_iterator end = get_policy().end_peer(); - for (; i != end; ++i) { + for (; i != end && (!pass || minPeersToAnnounce > 0); ++i) { policy::peer const* p = *i; - bool connect_recently = !p->banned && int(p->failcount) < settings().max_failcount && - p->last_connected && (m_ses.session_time() - p->last_connected) < (4*3600); - if( p->connectable && ( p->connection || connect_recently) ) { + if( !p->banned && int(p->failcount) < settings().max_failcount ) { + bool connect_recently = !p->failcount && p->last_connected && + (m_ses.session_time() - p->last_connected) < (4*3600); + if( p->connectable && (p->connection || connect_recently || pass) ) { m_ses.m_dht->announce(name(), m_torrent_file->info_hash() , p->address(), p->port, p->seed, false, m_policy.num_peers() , boost::bind(&nop)); + minPeersToAnnounce--; + } } } }