forked from premiere/premiere-libtorrent
remove_peer() and attach_peer() error handling
This commit is contained in:
parent
aae12250ae
commit
8b3624b25b
|
@ -661,7 +661,7 @@ namespace libtorrent {
|
||||||
// this will remove the peer and make sure all
|
// this will remove the peer and make sure all
|
||||||
// the pieces it had have their reference counter
|
// the pieces it had have their reference counter
|
||||||
// decreased in the piece_picker
|
// decreased in the piece_picker
|
||||||
void remove_peer(std::shared_ptr<peer_connection> p);
|
void remove_peer(std::shared_ptr<peer_connection> p) noexcept;
|
||||||
|
|
||||||
// cancel requests to this block from any peer we're
|
// cancel requests to this block from any peer we're
|
||||||
// connected to on this torrent
|
// connected to on this torrent
|
||||||
|
@ -1112,12 +1112,7 @@ namespace libtorrent {
|
||||||
void inc_num_connecting(torrent_peer* pp)
|
void inc_num_connecting(torrent_peer* pp)
|
||||||
{
|
{
|
||||||
++m_num_connecting;
|
++m_num_connecting;
|
||||||
TORRENT_ASSERT(m_num_connecting <= int(m_connections.size()));
|
if (pp->seed) ++m_num_connecting_seeds;
|
||||||
if (pp->seed)
|
|
||||||
{
|
|
||||||
++m_num_connecting_seeds;
|
|
||||||
TORRENT_ASSERT(m_num_connecting_seeds <= int(m_connections.size()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void dec_num_connecting(torrent_peer* pp)
|
void dec_num_connecting(torrent_peer* pp)
|
||||||
{
|
{
|
||||||
|
@ -1162,7 +1157,7 @@ namespace libtorrent {
|
||||||
void on_error(error_code const& ec) override;
|
void on_error(error_code const& ec) override;
|
||||||
|
|
||||||
// trigger deferred disconnection of peers
|
// trigger deferred disconnection of peers
|
||||||
void on_remove_peers();
|
void on_remove_peers() noexcept;
|
||||||
|
|
||||||
void ip_filter_updated();
|
void ip_filter_updated();
|
||||||
|
|
||||||
|
|
|
@ -5404,7 +5404,7 @@ namespace libtorrent {
|
||||||
m_connections.erase(i);
|
m_connections.erase(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent::remove_peer(std::shared_ptr<peer_connection> p)
|
void torrent::remove_peer(std::shared_ptr<peer_connection> p) noexcept
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(p);
|
TORRENT_ASSERT(p);
|
||||||
TORRENT_ASSERT(is_single_thread());
|
TORRENT_ASSERT(is_single_thread());
|
||||||
|
@ -5489,11 +5489,14 @@ namespace libtorrent {
|
||||||
TORRENT_ASSERT(m_num_seeds > 0);
|
TORRENT_ASSERT(m_num_seeds > 0);
|
||||||
--m_num_seeds;
|
--m_num_seeds;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
if (pp->connection && m_peer_list)
|
||||||
|
{
|
||||||
torrent_state st = get_peer_list_state();
|
torrent_state st = get_peer_list_state();
|
||||||
if (m_peer_list) m_peer_list->connection_closed(*p, m_ses.session_time(), &st);
|
m_peer_list->connection_closed(*p, m_ses.session_time(), &st);
|
||||||
peers_erased(st.erased);
|
peers_erased(st.erased);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
p->set_peer_info(nullptr);
|
p->set_peer_info(nullptr);
|
||||||
|
|
||||||
|
@ -5501,7 +5504,7 @@ namespace libtorrent {
|
||||||
update_want_tick();
|
update_want_tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent::on_remove_peers()
|
void torrent::on_remove_peers() noexcept
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(is_single_thread());
|
TORRENT_ASSERT(is_single_thread());
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
@ -6587,8 +6590,6 @@ namespace libtorrent {
|
||||||
std::shared_ptr<peer_connection> c = std::make_shared<bt_peer_connection>(
|
std::shared_ptr<peer_connection> c = std::make_shared<bt_peer_connection>(
|
||||||
pack, m_ses.get_peer_id());
|
pack, m_ses.get_peer_id());
|
||||||
|
|
||||||
TORRENT_TRY
|
|
||||||
{
|
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
c->m_in_constructor = false;
|
c->m_in_constructor = false;
|
||||||
#endif
|
#endif
|
||||||
|
@ -6616,6 +6617,8 @@ namespace libtorrent {
|
||||||
m_peers_to_disconnect.reserve(m_connections.size() + 1);
|
m_peers_to_disconnect.reserve(m_connections.size() + 1);
|
||||||
|
|
||||||
sorted_insert(m_connections, c.get());
|
sorted_insert(m_connections, c.get());
|
||||||
|
TORRENT_TRY
|
||||||
|
{
|
||||||
m_ses.insert_peer(c);
|
m_ses.insert_peer(c);
|
||||||
need_peer_list();
|
need_peer_list();
|
||||||
m_peer_list->set_connection(peerinfo, c.get());
|
m_peer_list->set_connection(peerinfo, c.get());
|
||||||
|
@ -6720,7 +6723,7 @@ namespace libtorrent {
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
bool torrent::attach_peer(peer_connection* p)
|
bool torrent::attach_peer(peer_connection* p) try
|
||||||
{
|
{
|
||||||
// INVARIANT_CHECK;
|
// INVARIANT_CHECK;
|
||||||
|
|
||||||
|
@ -6992,6 +6995,14 @@ namespace libtorrent {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
p->disconnect(errors::torrent_not_ready, operation_t::bittorrent);
|
||||||
|
// from the peer's point of view it was never really added to the torrent.
|
||||||
|
// So we need to clean it up here before propagating the error
|
||||||
|
remove_peer(p->self());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool torrent::want_tick() const
|
bool torrent::want_tick() const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue