From ec472daee33d3814f0ba69d1e8a60e378a7abff5 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 12 Oct 2014 06:29:34 +0000 Subject: [PATCH] fix bug in peer_connection causing it to not connect when not having metadata --- src/peer_connection.cpp | 42 +++++++++++++++----------------- test/test_metadata_extension.cpp | 4 +-- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 87ebf4763..e6cfd3b71 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -541,24 +541,19 @@ namespace libtorrent peer_log("*** CLASS [ %s ]", m_ses.peer_classes().at(class_at(i))->label.c_str()); } #endif - if (!t || !t->ready_for_connections()) - return; - init(); - - error_code ec; - if (!t) + if (t && t->ready_for_connections()) { - TORRENT_ASSERT(!m_connecting); - disconnect(errors::torrent_aborted, op_bittorrent); - return; + init(); } - TORRENT_ASSERT(m_connecting); + // if this is an incoming connection, we're done here + if (!m_connecting) return; #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING peer_log(">>> OPEN [ protocol: %s ]", (m_remote.address().is_v4()?"IPv4":"IPv6")); #endif + error_code ec; m_socket->open(m_remote.protocol(), ec); if (ec) { @@ -586,7 +581,8 @@ namespace libtorrent #endif #if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - t->debug_log("START connect [%p] (%d)", this, int(t->num_peers())); + if (t) + t->debug_log("START connect [%p] (%d)", this, int(t->num_peers())); #endif m_socket->async_connect(m_remote @@ -595,7 +591,7 @@ namespace libtorrent sent_syn(m_remote.address().is_v6()); - if (t->alerts().should_post()) + if (t && t->alerts().should_post()) { t->alerts().post_alert(peer_connect_alert( t->get_handle(), remote(), pid(), m_socket->type())); @@ -5697,11 +5693,13 @@ namespace libtorrent { #ifdef TORRENT_VERBOSE_LOGGING peer_log("<<< CANNOT READ [ quota: %d " - "can-write-to-disk: %s queue-limit: %d disconnecting: %s ]" + "can-write-to-disk: %s queue-limit: %d disconnecting: %s " + " connecting: %s ]" , m_quota[download_channel] , ((m_channel_state[download_channel] & peer_info::bw_disk)?"no":"yes") , m_settings.get_int(settings_pack::max_queued_disk_bytes) - , (m_disconnecting?"yes":"no")); + , (m_disconnecting?"yes":"no") + , (m_connecting?"yes":"no")); #endif // if we block reading, waiting for the disk, we will wake up // by the disk_io_thread posting a message every time it drops @@ -6370,14 +6368,6 @@ namespace libtorrent RAND_add(&now, 8, 1.5); #endif - if (m_disconnecting) return; - - if (e) - { - connect_failed(e); - return; - } - // if t is NULL, we better not be connecting, since // we can't decrement the connecting counter boost::shared_ptr t = m_torrent.lock(); @@ -6389,6 +6379,14 @@ namespace libtorrent m_connecting = false; } + if (m_disconnecting) return; + + if (e) + { + connect_failed(e); + return; + } + TORRENT_ASSERT(!m_connected); m_connected = true; m_counters.inc_stats_counter(counters::num_peers_connected); diff --git a/test/test_metadata_extension.cpp b/test/test_metadata_extension.cpp index e2e272f2e..ade611c54 100644 --- a/test/test_metadata_extension.cpp +++ b/test/test_metadata_extension.cpp @@ -200,8 +200,8 @@ int test_main() const int timeout = 3; #endif -test_transfer(full_encryption | reverse, &create_ut_metadata_plugin, timeout); -test_transfer(full_encryption | utp, &create_ut_metadata_plugin, timeout); + test_transfer(full_encryption | reverse, &create_ut_metadata_plugin, timeout); + test_transfer(full_encryption | utp, &create_ut_metadata_plugin, timeout); test_transfer(reverse, &create_ut_metadata_plugin, timeout); #ifndef TORRENT_NO_DEPRECATE