forked from premiere/premiere-libtorrent
update peer ranks when our external IP changes
This commit is contained in:
parent
6bda2f7430
commit
60af1aa451
|
@ -105,7 +105,8 @@ namespace libtorrent
|
|||
// calculate the priority of a peer based on its address. One of the
|
||||
// endpoint should be our own. The priority is symmetric, so it doesn't
|
||||
// matter which is which
|
||||
TORRENT_EXTRA_EXPORT boost::uint32_t peer_priority(tcp::endpoint e1, tcp::endpoint e2);
|
||||
TORRENT_EXTRA_EXPORT boost::uint32_t peer_priority(
|
||||
tcp::endpoint e1, tcp::endpoint e2);
|
||||
|
||||
void request_a_block(torrent& t, peer_connection& c);
|
||||
|
||||
|
@ -147,6 +148,10 @@ namespace libtorrent
|
|||
|
||||
void set_seed(policy::peer* p, bool s);
|
||||
|
||||
// this clears all cached peer priorities. It's called when
|
||||
// our external IP changes
|
||||
void clear_peer_prio();
|
||||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
bool has_connection(const peer_connection* p);
|
||||
#endif
|
||||
|
|
|
@ -216,6 +216,8 @@ namespace libtorrent
|
|||
void abort();
|
||||
bool is_aborted() const { return m_abort; }
|
||||
|
||||
void new_external_ip();
|
||||
|
||||
torrent_status::state_t state() const { return (torrent_status::state_t)m_state; }
|
||||
void set_state(torrent_status::state_t s);
|
||||
|
||||
|
|
|
@ -447,6 +447,13 @@ namespace libtorrent
|
|||
, m_finished(false)
|
||||
{ TORRENT_ASSERT(t); }
|
||||
|
||||
void policy::clear_peer_prio()
|
||||
{
|
||||
for (peers_t::iterator i = m_peers.begin()
|
||||
, end(m_peers.end()); i != end; ++i)
|
||||
(*i)->peer_rank = 0;
|
||||
}
|
||||
|
||||
// disconnects and removes all peers that are now filtered
|
||||
void policy::ip_filter_updated()
|
||||
{
|
||||
|
@ -1903,7 +1910,6 @@ namespace libtorrent
|
|||
// TOOD: pass in both an IPv6 and IPv4 address here
|
||||
boost::uint32_t policy::peer::rank(external_ip const& external, int external_port) const
|
||||
{
|
||||
//TODO 3: how do we deal with our external address changing? Pass in a force-update maybe? and keep a version number in policy
|
||||
if (peer_rank == 0)
|
||||
peer_rank = peer_priority(
|
||||
tcp::endpoint(external.external_address(this->address()), external_port)
|
||||
|
|
|
@ -6241,6 +6241,12 @@ retry:
|
|||
if (m_alerts.should_post<external_ip_alert>())
|
||||
m_alerts.post_alert(external_ip_alert(ip));
|
||||
|
||||
for (torrent_map::iterator i = m_torrents.begin()
|
||||
, end(m_torrents.end()); i != end; ++i)
|
||||
{
|
||||
i->second->new_external_ip();
|
||||
}
|
||||
|
||||
// since we have a new external IP now, we need to
|
||||
// restart the DHT with a new node ID
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
|
|
|
@ -8594,6 +8594,11 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
void torrent::new_external_ip()
|
||||
{
|
||||
m_policy.clear_peer_prio();
|
||||
}
|
||||
|
||||
void torrent::set_state(torrent_status::state_t s)
|
||||
{
|
||||
TORRENT_ASSERT(m_ses.is_network_thread());
|
||||
|
|
Loading…
Reference in New Issue