polish removal of web seeds logic

This commit is contained in:
arvidn 2015-08-23 11:01:55 +02:00
parent be2b1d3991
commit 82a3683f7d
2 changed files with 43 additions and 25 deletions

View File

@ -559,7 +559,7 @@ namespace libtorrent
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
void use_interface(std::string net_interface); void use_interface(std::string net_interface);
#endif #endif
void connect_to_url_seed(std::list<web_seed_t>::iterator url); void connect_to_url_seed(std::list<web_seed_t>::iterator url);
bool connect_to_peer(torrent_peer* peerinfo, bool ignore_limit = false); bool connect_to_peer(torrent_peer* peerinfo, bool ignore_limit = false);
@ -1240,8 +1240,10 @@ namespace libtorrent
void setup_peer_class(); void setup_peer_class();
// The list of web seeds in this torrent. Seeds // The list of web seeds in this torrent. Seeds with fatal errors are
// with fatal errors are removed from the set // removed from the set. It's important that iteratores are not
// invalidated as entries are added and removed from this list, hence the
// std::list
std::list<web_seed_t> m_web_seeds; std::list<web_seed_t> m_web_seeds;
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
@ -1274,7 +1276,7 @@ namespace libtorrent
// these are the pieces we're currently // these are the pieces we're currently
// suggesting to peers. // suggesting to peers.
std::vector<suggest_piece_t> m_suggested_pieces; std::vector<suggest_piece_t> m_suggested_pieces;
std::vector<announce_entry> m_trackers; std::vector<announce_entry> m_trackers;
// this is an index into m_trackers // this is an index into m_trackers

View File

@ -6023,21 +6023,28 @@ namespace libtorrent
if (web->resolving) if (web->resolving)
{ {
web->removed = true; web->removed = true;
return;
} }
peer_connection* peer = static_cast<peer_connection*>(web->peer_info.connection); else
if (peer)
{ {
// if we have a connection for this web seed, we also need to #ifndef TORRENT_DISABLE_LOGGING
// disconnect it and clear its reference to the peer_info object debug_log("removing web seed: \"%s\"", web->url.c_str());
// that's part of the web_seed_t we're about to remove #endif
TORRENT_ASSERT(peer->m_in_use == 1337);
peer->disconnect(boost::asio::error::operation_aborted, op_bittorrent); peer_connection* peer = static_cast<peer_connection*>(web->peer_info.connection);
peer->set_peer_info(0); if (peer)
} {
if (has_picker()) picker().clear_peer(&web->peer_info); // if we have a connection for this web seed, we also need to
// disconnect it and clear its reference to the peer_info object
// that's part of the web_seed_t we're about to remove
TORRENT_ASSERT(peer->m_in_use == 1337);
peer->disconnect(boost::asio::error::operation_aborted, op_bittorrent);
peer->set_peer_info(0);
}
if (has_picker()) picker().clear_peer(&web->peer_info);
m_web_seeds.erase(web);
}
m_web_seeds.erase(web);
update_want_tick(); update_want_tick();
} }
@ -6095,7 +6102,7 @@ namespace libtorrent
remove_web_seed(web); remove_web_seed(web);
return; return;
} }
#ifdef TORRENT_USE_OPENSSL #ifdef TORRENT_USE_OPENSSL
if (protocol != "http" && protocol != "https") if (protocol != "http" && protocol != "https")
#else #else
@ -7080,6 +7087,7 @@ namespace libtorrent
for (std::list<web_seed_t>::const_iterator i = m_web_seeds.begin() for (std::list<web_seed_t>::const_iterator i = m_web_seeds.begin()
, end(m_web_seeds.end()); i != end; ++i) , end(m_web_seeds.end()); i != end; ++i)
{ {
if (i->removed) continue;
if (i->type == web_seed_entry::url_seed) if (i->type == web_seed_entry::url_seed)
url_list.push_back(i->url); url_list.push_back(i->url);
else if (i->type == web_seed_entry::http_seed) else if (i->type == web_seed_entry::http_seed)
@ -10111,6 +10119,7 @@ namespace libtorrent
if (w->peer_info.connection) continue; if (w->peer_info.connection) continue;
if (w->retry > aux::time_now()) continue; if (w->retry > aux::time_now()) continue;
if (w->resolving) continue; if (w->resolving) continue;
if (w->removed) continue;
connect_to_url_seed(w); connect_to_url_seed(w);
} }
@ -10928,6 +10937,7 @@ namespace libtorrent
, end(m_web_seeds.end()); i != end; ++i) , end(m_web_seeds.end()); i != end; ++i)
{ {
if (i->peer_info.banned) continue; if (i->peer_info.banned) continue;
if (i->removed) continue;
if (i->type != type) continue; if (i->type != type) continue;
ret.insert(i->url); ret.insert(i->url);
} }
@ -10940,6 +10950,7 @@ namespace libtorrent
, m_web_seeds.end() , m_web_seeds.end()
, (boost::bind(&web_seed_t::url, _1) , (boost::bind(&web_seed_t::url, _1)
== url && boost::bind(&web_seed_t::type, _1) == type)); == url && boost::bind(&web_seed_t::type, _1) == type));
if (i != m_web_seeds.end()) remove_web_seed(i); if (i != m_web_seeds.end()) remove_web_seed(i);
} }
@ -10957,9 +10968,6 @@ namespace libtorrent
TORRENT_ASSERT(i->resolving == false); TORRENT_ASSERT(i->resolving == false);
#ifndef TORRENT_DISABLE_LOGGING
debug_log("disconnect web seed: \"%s\"", i->url.c_str());
#endif
TORRENT_ASSERT(i->peer_info.connection); TORRENT_ASSERT(i->peer_info.connection);
i->peer_info.connection = 0; i->peer_info.connection = 0;
} }
@ -10973,11 +10981,18 @@ namespace libtorrent
, boost::bind(&web_seed_t::peer_info, _1)) == p); , boost::bind(&web_seed_t::peer_info, _1)) == p);
TORRENT_ASSERT(i != m_web_seeds.end()); TORRENT_ASSERT(i != m_web_seeds.end());
if (i == m_web_seeds.end()) return; if (i == m_web_seeds.end()) return;
if (i->peer_info.connection) i->peer_info.connection->disconnect(ec, op, error);
if (has_picker()) picker().clear_peer(&i->peer_info); peer_connection* peer = static_cast<peer_connection*>(i->peer_info.connection);
m_web_seeds.erase(i); if (peer)
update_want_tick(); {
m_need_save_resume_data = true; // if we have a connection for this web seed, we also need to
// disconnect it and clear its reference to the peer_info object
// that's part of the web_seed_t we're about to remove
TORRENT_ASSERT(peer->m_in_use == 1337);
peer->disconnect(ec, op, error);
peer->set_peer_info(0);
}
remove_web_seed(i);
} }
void torrent::retry_web_seed(peer_connection* p, int retry) void torrent::retry_web_seed(peer_connection* p, int retry)
@ -10990,6 +11005,7 @@ namespace libtorrent
TORRENT_ASSERT(i != m_web_seeds.end()); TORRENT_ASSERT(i != m_web_seeds.end());
if (i == m_web_seeds.end()) return; if (i == m_web_seeds.end()) return;
if (i->removed) return;
if (retry == 0) retry = settings().get_int(settings_pack::urlseed_wait_retry); if (retry == 0) retry = settings().get_int(settings_pack::urlseed_wait_retry);
i->retry = aux::time_now() + seconds(retry); i->retry = aux::time_now() + seconds(retry);
} }