From ba172954e648a0e921e86b382478f95c0a0fef95 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 20 Dec 2007 23:58:58 +0000 Subject: [PATCH] accept have messages without having metadata and without having received a bitfield --- src/bt_peer_connection.cpp | 5 +++++ src/peer_connection.cpp | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 384bc2375..64e4d749c 100755 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -1339,6 +1339,11 @@ namespace libtorrent send_allowed_set(); 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 lazy_pieces[50]; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index afc53947b..25de92b51 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -909,8 +909,26 @@ namespace libtorrent << " <== HAVE [ piece: " << index << "]\n"; #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 (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 " "than the number of pieces");