peer_connection fix for incoming connections

This commit is contained in:
Arvid Norberg 2008-05-12 10:10:39 +00:00
parent 756dbe3316
commit f259e34f86
5 changed files with 24 additions and 7 deletions

View File

@ -100,6 +100,7 @@ namespace libtorrent
bt_peer_connection( bt_peer_connection(
aux::session_impl& ses aux::session_impl& ses
, boost::shared_ptr<socket_type> s , boost::shared_ptr<socket_type> s
, tcp::endpoint const& remote
, policy::peer* peerinfo); , policy::peer* peerinfo);
void start(); void start();

View File

@ -121,6 +121,7 @@ namespace libtorrent
peer_connection( peer_connection(
aux::session_impl& ses aux::session_impl& ses
, boost::shared_ptr<socket_type> s , boost::shared_ptr<socket_type> s
, tcp::endpoint const& remote
, policy::peer* peerinfo); , policy::peer* peerinfo);
// this function is called after it has been constructed and properly // this function is called after it has been constructed and properly

View File

@ -125,8 +125,9 @@ namespace libtorrent
bt_peer_connection::bt_peer_connection( bt_peer_connection::bt_peer_connection(
session_impl& ses session_impl& ses
, boost::shared_ptr<socket_type> s , boost::shared_ptr<socket_type> s
, tcp::endpoint const& remote
, policy::peer* peerinfo) , policy::peer* peerinfo)
: peer_connection(ses, s, peerinfo) : peer_connection(ses, s, remote, peerinfo)
, m_state(read_protocol_identifier) , m_state(read_protocol_identifier)
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
, m_supports_extensions(false) , m_supports_extensions(false)

View File

@ -64,7 +64,7 @@ namespace libtorrent
session_impl& ses session_impl& ses
, boost::weak_ptr<torrent> tor , boost::weak_ptr<torrent> tor
, shared_ptr<socket_type> s , shared_ptr<socket_type> s
, tcp::endpoint const& remote , tcp::endpoint const& endp
, policy::peer* peerinfo) , policy::peer* peerinfo)
: :
#ifndef NDEBUG #ifndef NDEBUG
@ -86,7 +86,7 @@ namespace libtorrent
, m_last_receive(time_now()) , m_last_receive(time_now())
, m_last_sent(time_now()) , m_last_sent(time_now())
, m_socket(s) , m_socket(s)
, m_remote(remote) , m_remote(endp)
, m_torrent(tor) , m_torrent(tor)
, m_active(true) , m_active(true)
, m_peer_interested(false) , m_peer_interested(false)
@ -164,6 +164,7 @@ namespace libtorrent
peer_connection::peer_connection( peer_connection::peer_connection(
session_impl& ses session_impl& ses
, boost::shared_ptr<socket_type> s , boost::shared_ptr<socket_type> s
, tcp::endpoint const& endp
, policy::peer* peerinfo) , policy::peer* peerinfo)
: :
#ifndef NDEBUG #ifndef NDEBUG
@ -185,6 +186,7 @@ namespace libtorrent
, m_last_receive(time_now()) , m_last_receive(time_now())
, m_last_sent(time_now()) , m_last_sent(time_now())
, m_socket(s) , m_socket(s)
, m_remote(endp)
, m_active(false) , m_active(false)
, m_peer_interested(false) , m_peer_interested(false)
, m_peer_choked(true) , m_peer_choked(true)
@ -244,7 +246,7 @@ namespace libtorrent
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING
error_code ec; 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) + "_" m_logger = m_ses.create_log(remote().address().to_string(ec) + "_"
+ boost::lexical_cast<std::string>(remote().port()), m_ses.listen_port()); + boost::lexical_cast<std::string>(remote().port()), m_ses.listen_port());
(*m_logger) << "*** INCOMING CONNECTION\n"; (*m_logger) << "*** INCOMING CONNECTION\n";

View File

@ -847,7 +847,13 @@ namespace aux {
// check if we have any active torrents // check if we have any active torrents
// if we don't reject the connection // 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; bool has_active_torrent = false;
for (torrent_map::iterator i = m_torrents.begin() for (torrent_map::iterator i = m_torrents.begin()
@ -859,10 +865,16 @@ namespace aux {
break; 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<peer_connection> c( boost::intrusive_ptr<peer_connection> c(
new bt_peer_connection(*this, s, 0)); new bt_peer_connection(*this, s, endp, 0));
#ifndef NDEBUG #ifndef NDEBUG
c->m_in_constructor = false; c->m_in_constructor = false;
#endif #endif