fixed checking of fast and suggest messages when used with magnet links

This commit is contained in:
Arvid Norberg 2009-09-01 04:41:50 +00:00
parent 1f5a722b01
commit f7ebefb285
4 changed files with 79 additions and 7 deletions

View File

@ -76,6 +76,7 @@ release 0.14.6
* added missing functions to python binding related to torrent creation * added missing functions to python binding related to torrent creation
* fixed to add filename on web seed urls that lack it * fixed to add filename on web seed urls that lack it
* fixed BOOST_ASIO_HASH_MAP_BUCKETS define for boost 1.39 * fixed BOOST_ASIO_HASH_MAP_BUCKETS define for boost 1.39
* fixed checking of fast and suggest messages when used with magnet links
release 0.14.5 release 0.14.5

View File

@ -3575,6 +3575,8 @@ session_settings
int optimistic_disk_retry; int optimistic_disk_retry;
bool disable_hash_check; bool disable_hash_check;
int max_suggest_pieces;
}; };
``user_agent`` this is the client identification to the tracker. ``user_agent`` this is the client identification to the tracker.
@ -4000,6 +4002,10 @@ to verify all downloaded data. It may be useful to turn this off for performance
profiling and simulation scenarios. Do not disable the hash check for regular profiling and simulation scenarios. Do not disable the hash check for regular
bittorrent clients. bittorrent clients.
``max_suggest_pieces`` is the max number of suggested piece indices received
from a peer that's remembered. If a peer floods suggest messages, this limit
prevents libtorrent from using too much RAM. It defaults to 10.
pe_settings pe_settings
=========== ===========

View File

@ -179,6 +179,7 @@ namespace libtorrent
, optimistic_disk_retry(10 * 60) , optimistic_disk_retry(10 * 60)
, disable_hash_checks(false) , disable_hash_checks(false)
, allow_i2p_mixed(false) , allow_i2p_mixed(false)
, max_suggest_pieces(10)
{} {}
// this is the user agent that will be sent to the tracker // this is the user agent that will be sent to the tracker
@ -633,6 +634,11 @@ namespace libtorrent
// the anonymization of i2p, but still wants to // the anonymization of i2p, but still wants to
// be able to connect to i2p peers. // be able to connect to i2p peers.
bool allow_i2p_mixed; bool allow_i2p_mixed;
// the max number of pieces that a peer can
// suggest to use before we start dropping
// previous suggested piece
int max_suggest_pieces;
}; };
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT

View File

@ -535,6 +535,32 @@ namespace libtorrent
boost::shared_ptr<torrent> t = associated_torrent().lock(); boost::shared_ptr<torrent> t = associated_torrent().lock();
m_have_piece.resize(t->torrent_file().num_pieces(), m_have_all); m_have_piece.resize(t->torrent_file().num_pieces(), m_have_all);
m_num_pieces = m_have_piece.count(); m_num_pieces = m_have_piece.count();
// now that we know how many pieces there are
// remove any invalid allowed_fast and suggest pieces
// now that we know what the number of pieces are
for (std::vector<int>::iterator i = m_allowed_fast.begin();
i != m_allowed_fast.end();)
{
if (*i < m_num_pieces)
{
++i;
continue;
}
i = m_allowed_fast.erase(i);
}
for (std::vector<int>::iterator i = m_suggested_pieces.begin();
i != m_suggested_pieces.end();)
{
if (*i < m_num_pieces)
{
++i;
continue;
}
i = m_suggested_pieces.erase(i);
}
if (m_num_pieces == int(m_have_piece.size())) if (m_num_pieces == int(m_have_piece.size()))
{ {
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
@ -739,6 +765,10 @@ namespace libtorrent
m_suggested_pieces.begin(), m_suggested_pieces.end(), index); m_suggested_pieces.begin(), m_suggested_pieces.end(), index);
if (i != m_suggested_pieces.end()) m_suggested_pieces.erase(i); if (i != m_suggested_pieces.end()) m_suggested_pieces.erase(i);
// remove allowed fast pieces
i = std::find(m_allowed_fast.begin(), m_allowed_fast.end(), index);
if (i != m_allowed_fast.end()) m_allowed_fast.erase(i);
if (has_piece(index)) if (has_piece(index))
{ {
// if we got a piece that this peer has // if we got a piece that this peer has
@ -1167,10 +1197,34 @@ namespace libtorrent
#endif #endif
if (is_disconnecting()) return; if (is_disconnecting()) return;
if (t->have_piece(index)) return; if (index < 0)
{
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING
(*m_logger) << time_now_string() << " <== INVALID_SUGGEST_PIECE [ " << index << " ]\n";
#endif
return;
}
if (m_suggested_pieces.size() > 9) if (t->valid_metadata())
{
if (index >= int(m_have_piece.size()))
{
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING
(*m_logger) << time_now_string() << " <== INVALID_ALLOWED_FAST [ " << index << " | s: "
<< int(m_have_piece.size()) << " ]\n";
#endif
return;
}
// if we already have the piece, we can
// ignore this message
if (t->have_piece(index))
return;
}
if (m_suggested_pieces.size() > m_ses.m_settings.max_suggest_pieces)
m_suggested_pieces.erase(m_suggested_pieces.begin()); m_suggested_pieces.erase(m_suggested_pieces.begin());
m_suggested_pieces.push_back(index); m_suggested_pieces.push_back(index);
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
@ -2439,10 +2493,17 @@ namespace libtorrent
} }
#endif #endif
if (is_disconnecting()) return; if (is_disconnecting()) return;
if (index < 0)
{
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING
(*m_logger) << time_now_string() << " <== INVALID_ALLOWED_FAST [ " << " ]\n";
#endif
return;
}
if (t->valid_metadata()) if (t->valid_metadata())
{ {
if (index < 0 || index >= int(m_have_piece.size())) if (index >= int(m_have_piece.size()))
{ {
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING
(*m_logger) << time_now_string() << " <== INVALID_ALLOWED_FAST [ " << index << " | s: " (*m_logger) << time_now_string() << " <== INVALID_ALLOWED_FAST [ " << index << " | s: "
@ -2457,6 +2518,8 @@ namespace libtorrent
return; return;
} }
// if we don't have the metadata, we'll verify
// this piece index later
m_allowed_fast.push_back(index); m_allowed_fast.push_back(index);
// if the peer has the piece and we want // if the peer has the piece and we want
@ -2476,10 +2539,6 @@ namespace libtorrent
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t); TORRENT_ASSERT(t);
m_allowed_fast.erase(std::remove_if(m_allowed_fast.begin()
, m_allowed_fast.end(), bind(&torrent::have_piece, t, _1))
, m_allowed_fast.end());
// TODO: sort the allowed fast set in priority order // TODO: sort the allowed fast set in priority order
return m_allowed_fast; return m_allowed_fast;
} }