mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-17 13:56:47 +00:00
handles case where a request in the allow fast set is rejected and saves banned peers in resume data
This commit is contained in:
parent
b2ae9f1db1
commit
9ed93af6b2
@ -115,6 +115,7 @@ namespace libtorrent
|
||||
std::vector<piece_picker::downloading_piece> unfinished_pieces;
|
||||
std::vector<piece_picker::block_info> block_info;
|
||||
std::vector<tcp::endpoint> peers;
|
||||
std::vector<tcp::endpoint> banned_peers;
|
||||
entry resume_data;
|
||||
|
||||
// this is true if this torrent is being processed (checked)
|
||||
|
@ -730,6 +730,15 @@ namespace libtorrent
|
||||
<< " *** PIECE NOT IN REQUEST QUEUE\n";
|
||||
}
|
||||
#endif
|
||||
if (has_peer_choked())
|
||||
{
|
||||
// if we're choked and we got a rejection of
|
||||
// a piece in the allowed fast set, remove it
|
||||
// from the allow fast set.
|
||||
std::vector<int>::iterator i = std::find(
|
||||
m_allowed_fast.begin(), m_allowed_fast.end(), r.piece);
|
||||
if (i != m_allowed_fast.end()) m_allowed_fast.erase(i);
|
||||
}
|
||||
if (m_request_queue.empty())
|
||||
{
|
||||
if (m_download_queue.size() < 2)
|
||||
|
@ -673,8 +673,11 @@ namespace libtorrent
|
||||
for (iterator i = m_peers.begin(); i != m_peers.end();)
|
||||
{
|
||||
// this timeout has to be customizable!
|
||||
// don't remove banned peers, they should
|
||||
// remain banned
|
||||
if (i->second.connection == 0
|
||||
&& i->second.connected != min_time()
|
||||
&& !i->second.banned
|
||||
&& now - i->second.connected > minutes(120))
|
||||
{
|
||||
if (p) p->clear_peer(&i->second);
|
||||
|
@ -254,6 +254,14 @@ namespace detail
|
||||
t->torrent_ptr->get_policy().peer_from_tracker(*i, id
|
||||
, peer_info::resume_data, 0);
|
||||
}
|
||||
|
||||
for (std::vector<tcp::endpoint>::const_iterator i = t->banned_peers.begin();
|
||||
i != t->banned_peers.end(); ++i)
|
||||
{
|
||||
policy::peer* p = t->torrent_ptr->get_policy().peer_from_tracker(*i, id
|
||||
, peer_info::resume_data, 0);
|
||||
if (p) p->banned = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2371,9 +2379,9 @@ namespace detail
|
||||
|
||||
// the peers
|
||||
|
||||
if (rd.find_key("peers"))
|
||||
if (entry* peers_entry = rd.find_key("peers"))
|
||||
{
|
||||
entry::list_type& peer_list = rd["peers"].list();
|
||||
entry::list_type& peer_list = peers_entry->list();
|
||||
|
||||
std::vector<tcp::endpoint> tmp_peers;
|
||||
tmp_peers.reserve(peer_list.size());
|
||||
@ -2389,6 +2397,24 @@ namespace detail
|
||||
peers.swap(tmp_peers);
|
||||
}
|
||||
|
||||
if (entry* banned_peers_entry = rd.find_key("banned_peers"))
|
||||
{
|
||||
entry::list_type& peer_list = banned_peers_entry->list();
|
||||
|
||||
std::vector<tcp::endpoint> tmp_peers;
|
||||
tmp_peers.reserve(peer_list.size());
|
||||
for (entry::list_type::iterator i = peer_list.begin();
|
||||
i != peer_list.end(); ++i)
|
||||
{
|
||||
tcp::endpoint a(
|
||||
address::from_string((*i)["ip"].string())
|
||||
, (unsigned short)(*i)["port"].integer());
|
||||
tmp_peers.push_back(a);
|
||||
}
|
||||
|
||||
banned_peers.swap(tmp_peers);
|
||||
}
|
||||
|
||||
// read piece map
|
||||
const entry::list_type& slots = rd["slots"].list();
|
||||
if ((int)slots.size() > info.num_pieces())
|
||||
|
@ -2397,6 +2397,8 @@ namespace libtorrent
|
||||
#ifndef NDEBUG
|
||||
void torrent::check_invariant() const
|
||||
{
|
||||
session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
|
||||
|
||||
int num_uploads = 0;
|
||||
std::map<piece_block, int> num_requests;
|
||||
for (const_peer_iterator i = begin(); i != end(); ++i)
|
||||
|
@ -737,14 +737,23 @@ namespace libtorrent
|
||||
}
|
||||
// write local peers
|
||||
|
||||
ret["peers"] = entry::list_type();
|
||||
entry::list_type& peer_list = ret["peers"].list();
|
||||
entry::list_type& banned_peer_list = ret["banned_peers"].list();
|
||||
|
||||
policy& pol = t->get_policy();
|
||||
|
||||
for (policy::iterator i = pol.begin_peer()
|
||||
, end(pol.end_peer()); i != end; ++i)
|
||||
{
|
||||
if (i->second.banned)
|
||||
{
|
||||
tcp::endpoint ip = i->second.ip;
|
||||
entry peer(entry::dictionary_t);
|
||||
peer["ip"] = ip.address().to_string();
|
||||
peer["port"] = ip.port();
|
||||
banned_peer_list.push_back(peer);
|
||||
continue;
|
||||
}
|
||||
// we cannot save remote connection
|
||||
// since we don't know their listen port
|
||||
// unless they gave us their listen port
|
||||
@ -752,8 +761,7 @@ namespace libtorrent
|
||||
// so, if the peer is not connectable (i.e. we
|
||||
// don't know its listen port) or if it has
|
||||
// been banned, don't save it.
|
||||
if (i->second.type == policy::peer::not_connectable
|
||||
|| i->second.banned) continue;
|
||||
if (i->second.type == policy::peer::not_connectable) continue;
|
||||
|
||||
tcp::endpoint ip = i->second.ip;
|
||||
entry peer(entry::dictionary_t);
|
||||
|
Loading…
x
Reference in New Issue
Block a user