diff --git a/include/libtorrent/policy.hpp b/include/libtorrent/policy.hpp index 0496457da..918f4ee83 100755 --- a/include/libtorrent/policy.hpp +++ b/include/libtorrent/policy.hpp @@ -91,21 +91,9 @@ namespace libtorrent // called when an incoming connection is accepted void new_connection(peer_connection& c); - // this is called if a peer timed-out or - // forcefully closed the connection. This - // will mark the connection as non-reconnectale - void peer_failed(peer_connection const& c); - // the given connection was just closed void connection_closed(const peer_connection& c); - // is called when a peer is believed to have - // sent invalid data - void ban_peer(peer_connection const& c); - - // is called on peers that become seeds - void set_seed(peer_connection const& c); - // the peer has got at least one interesting piece void peer_is_interesting(peer_connection& c); diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 949f9fbfd..7a209805d 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -726,7 +726,6 @@ namespace libtorrent { assert(m_peer_info); m_peer_info->seed = true; - t->get_policy().set_seed(*this); if (t->is_seed()) { throw protocol_error("seed to seed connection redundant, disconnecting"); @@ -783,9 +782,26 @@ namespace libtorrent { m_have_piece = bitfield; m_num_pieces = std::count(bitfield.begin(), bitfield.end(), true); + + if (m_peer_info) m_peer_info->seed = true; return; } + int num_pieces = std::count(bitfield.begin(), bitfield.end(), true); + if (num_pieces == int(m_have_piece.size())) + { +#ifdef TORRENT_VERBOSE_LOGGING + (*m_logger) << " *** THIS IS A SEED ***\n"; +#endif + assert(m_peer_info); + m_peer_info->seed = true; + // if we're a seed too, disconnect + if (t->is_seed()) + { + throw protocol_error("seed to seed connection redundant, disconnecting"); + } + } + // let the torrent know which pieces the // peer has bool interesting = false; @@ -809,21 +825,6 @@ namespace libtorrent } } - if (m_num_pieces == int(m_have_piece.size())) - { -#ifdef TORRENT_VERBOSE_LOGGING - (*m_logger) << " *** THIS IS A SEED ***\n"; -#endif - assert(m_peer_info); - m_peer_info->seed = true; - t->get_policy().set_seed(*this); - // if we're a seed too, disconnect - if (t->is_seed()) - { - throw protocol_error("seed to seed connection redundant, disconnecting"); - } - } - if (interesting) t->get_policy().peer_is_interesting(*this); } diff --git a/src/policy.cpp b/src/policy.cpp index dc713bb14..d25585042 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -853,45 +853,6 @@ namespace libtorrent } } - void policy::ban_peer(peer_connection const& c) - { - INVARIANT_CHECK; - - iterator i = std::find_if( - m_peers.begin() - , m_peers.end() - , match_peer_connection(c)); - - if (i == m_peers.end()) - { - // this is probably an http seed - if (web_peer_connection const* p = dynamic_cast(&c)) - { - m_torrent->remove_url_seed(p->url()); - } - return; - } - - i->type = peer::not_connectable; - i->ip.port(0); - i->banned = true; - } - - void policy::set_seed(peer_connection const& c) - { - INVARIANT_CHECK; - - iterator i = std::find_if( - m_peers.begin() - , m_peers.end() - , match_peer_connection(c)); - - // it might be an http-seed - if (i == m_peers.end()) return; - - i->seed = true; - } - void policy::new_connection(peer_connection& c) { assert(!c.is_local()); diff --git a/src/torrent.cpp b/src/torrent.cpp index 43c4351b3..b82f7ea8a 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -894,7 +894,22 @@ namespace libtorrent , get_handle() , "banning peer because of too many corrupt pieces")); } - m_policy->ban_peer(*p->second); + + // mark the peer as banned + policy::peer* peerinfo = p->second->peer_info_struct(); + if (peerinfo) + { + peerinfo->banned = true; + } + else + { + // it might be a web seed + if (web_peer_connection const* wpc + = dynamic_cast(p->second)) + { + remove_url_seed(wpc->url()); + } + } #if defined(TORRENT_VERBOSE_LOGGING) (*p->second->m_logger) << "*** BANNING PEER 'too many corrupt pieces'\n";