cleaned up policy a bit, moved the seed check in on_bitfield to be performed before the piece picker is updated

This commit is contained in:
Arvid Norberg 2007-04-13 01:53:25 +00:00
parent 3293bf9b6e
commit 0e5ce5dd9d
4 changed files with 33 additions and 68 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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<web_peer_connection const*>(&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());

View File

@ -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<web_peer_connection const*>(p->second))
{
remove_url_seed(wpc->url());
}
}
#if defined(TORRENT_VERBOSE_LOGGING)
(*p->second->m_logger) << "*** BANNING PEER 'too many corrupt pieces'\n";