accept have messages without having metadata and without having received a bitfield

This commit is contained in:
Arvid Norberg 2007-12-20 23:58:58 +00:00
parent 3b4cccf1dd
commit ba172954e6
2 changed files with 24 additions and 1 deletions

View File

@ -1339,6 +1339,11 @@ namespace libtorrent
send_allowed_set(); send_allowed_set();
return; return;
} }
else if (t->num_pieces() == 0)
{
// don't send a bitfield if we don't have any pieces
return;
}
int num_pieces = bitfield.size(); int num_pieces = bitfield.size();
int lazy_pieces[50]; int lazy_pieces[50];

View File

@ -909,8 +909,26 @@ namespace libtorrent
<< " <== HAVE [ piece: " << index << "]\n"; << " <== HAVE [ piece: " << index << "]\n";
#endif #endif
if (!t->valid_metadata() && index > int(m_have_piece.size()))
{
if (index < 65536)
{
// if we don't have metadata
// and we might not have received a bitfield
// extend the bitmask to fit the new
// have message
m_have_piece.resize(index + 1, false);
}
else
{
// unless the index > 64k, in which case
// we just ignore it
return;
}
}
// if we got an invalid message, abort // if we got an invalid message, abort
if (index >= (int)m_have_piece.size() || index < 0) if (index >= int(m_have_piece.size()) || index < 0)
throw protocol_error("got 'have'-message with higher index " throw protocol_error("got 'have'-message with higher index "
"than the number of pieces"); "than the number of pieces");