From f259e34f867c6ab04446846f918bb756c3a9ef33 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 12 May 2008 10:10:39 +0000 Subject: [PATCH] peer_connection fix for incoming connections --- include/libtorrent/bt_peer_connection.hpp | 1 + include/libtorrent/peer_connection.hpp | 1 + src/bt_peer_connection.cpp | 3 ++- src/peer_connection.cpp | 8 +++++--- src/session_impl.cpp | 18 +++++++++++++++--- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/libtorrent/bt_peer_connection.hpp b/include/libtorrent/bt_peer_connection.hpp index eddf9aef9..f82d5070c 100755 --- a/include/libtorrent/bt_peer_connection.hpp +++ b/include/libtorrent/bt_peer_connection.hpp @@ -100,6 +100,7 @@ namespace libtorrent bt_peer_connection( aux::session_impl& ses , boost::shared_ptr s + , tcp::endpoint const& remote , policy::peer* peerinfo); void start(); diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index db6148653..a2c1792a9 100755 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -121,6 +121,7 @@ namespace libtorrent peer_connection( aux::session_impl& ses , boost::shared_ptr s + , tcp::endpoint const& remote , policy::peer* peerinfo); // this function is called after it has been constructed and properly diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 415a88b52..bf45c2f23 100755 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -125,8 +125,9 @@ namespace libtorrent bt_peer_connection::bt_peer_connection( session_impl& ses , boost::shared_ptr s + , tcp::endpoint const& remote , policy::peer* peerinfo) - : peer_connection(ses, s, peerinfo) + : peer_connection(ses, s, remote, peerinfo) , m_state(read_protocol_identifier) #ifndef TORRENT_DISABLE_EXTENSIONS , m_supports_extensions(false) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 6cd987ed1..a4fa9ba42 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -64,7 +64,7 @@ namespace libtorrent session_impl& ses , boost::weak_ptr tor , shared_ptr s - , tcp::endpoint const& remote + , tcp::endpoint const& endp , policy::peer* peerinfo) : #ifndef NDEBUG @@ -86,7 +86,7 @@ namespace libtorrent , m_last_receive(time_now()) , m_last_sent(time_now()) , m_socket(s) - , m_remote(remote) + , m_remote(endp) , m_torrent(tor) , m_active(true) , m_peer_interested(false) @@ -164,6 +164,7 @@ namespace libtorrent peer_connection::peer_connection( session_impl& ses , boost::shared_ptr s + , tcp::endpoint const& endp , policy::peer* peerinfo) : #ifndef NDEBUG @@ -185,6 +186,7 @@ namespace libtorrent , m_last_receive(time_now()) , m_last_sent(time_now()) , m_socket(s) + , m_remote(endp) , m_active(false) , m_peer_interested(false) , m_peer_choked(true) @@ -244,7 +246,7 @@ namespace libtorrent #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING error_code ec; - TORRENT_ASSERT(m_socket->remote_endpoint(ec) == remote() || ec); + TORRENT_ASSERT(m_socket->remote_endpoint(ec) == m_remote || ec); m_logger = m_ses.create_log(remote().address().to_string(ec) + "_" + boost::lexical_cast(remote().port()), m_ses.listen_port()); (*m_logger) << "*** INCOMING CONNECTION\n"; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 5f6fb90a9..778738a88 100755 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -847,7 +847,13 @@ namespace aux { // check if we have any active torrents // if we don't reject the connection - if (m_torrents.empty()) return; + if (m_torrents.empty()) + { +#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) + (*m_logger) << " There are no torrents, disconnect\n"; +#endif + return; + } bool has_active_torrent = false; for (torrent_map::iterator i = m_torrents.begin() @@ -859,10 +865,16 @@ namespace aux { break; } } - if (!has_active_torrent) return; + if (!has_active_torrent) + { +#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) + (*m_logger) << " There are no _active_ torrents, disconnect\n"; +#endif + return; + } boost::intrusive_ptr c( - new bt_peer_connection(*this, s, 0)); + new bt_peer_connection(*this, s, endp, 0)); #ifndef NDEBUG c->m_in_constructor = false; #endif