improved peer exchange performance by sharing incoming connections which advertize listen port

This commit is contained in:
Arvid Norberg 2012-01-04 20:49:54 +00:00
parent 315ff0bb83
commit 61e8d3dd49
5 changed files with 41 additions and 5 deletions

View File

@ -1,3 +1,4 @@
* improved peer exchange performance by sharing incoming connections which advertize listen port
* deprecate set_ratio(), and per-peer rate limits * deprecate set_ratio(), and per-peer rate limits
* add web seed support for torrents with pad files * add web seed support for torrents with pad files
* introduced a more scalable API for torrent status updates (post_torrent_updates()) and updated client_test to use it * introduced a more scalable API for torrent status updates (post_torrent_updates()) and updated client_test to use it

View File

@ -402,6 +402,10 @@ namespace libtorrent
// if it was an incoming connection, it is remote // if it was an incoming connection, it is remote
bool is_local() const { return m_active; } bool is_local() const { return m_active; }
bool received_listen_port() const { return m_received_listen_port; }
void received_listen_port()
{ m_received_listen_port = true; }
bool on_local_network() const; bool on_local_network() const;
bool ignore_bandwidth_limits() const bool ignore_bandwidth_limits() const
{ return m_ignore_bandwidth_limits; } { return m_ignore_bandwidth_limits; }
@ -1053,6 +1057,10 @@ namespace libtorrent
// could be considered: true = local, false = remote // could be considered: true = local, false = remote
bool m_active:1; bool m_active:1;
// is true if we learn the incoming connections listening
// during the extended handshake
bool m_received_listen_port:1;
// other side says that it's interested in downloading // other side says that it's interested in downloading
// from us. // from us.
bool m_peer_interested:1; bool m_peer_interested:1;

View File

@ -1777,8 +1777,10 @@ namespace libtorrent
{ {
t->get_policy().update_peer_port(listen_port t->get_policy().update_peer_port(listen_port
, peer_info_struct(), peer_info::incoming); , peer_info_struct(), peer_info::incoming);
received_listen_port();
if (is_disconnecting()) return; if (is_disconnecting()) return;
} }
// there should be a version too // there should be a version too
// but where do we put that info? // but where do we put that info?

View File

@ -170,6 +170,7 @@ namespace libtorrent
, m_choke_rejects(0) , m_choke_rejects(0)
, m_fast_reconnect(false) , m_fast_reconnect(false)
, m_active(outgoing) , m_active(outgoing)
, m_received_listen_port(false)
, m_peer_interested(false) , m_peer_interested(false)
, m_peer_choked(true) , m_peer_choked(true)
, m_interesting(false) , m_interesting(false)
@ -320,6 +321,7 @@ namespace libtorrent
, m_choke_rejects(0) , m_choke_rejects(0)
, m_fast_reconnect(false) , m_fast_reconnect(false)
, m_active(outgoing) , m_active(outgoing)
, m_received_listen_port(false)
, m_peer_interested(false) , m_peer_interested(false)
, m_peer_choked(true) , m_peer_choked(true)
, m_interesting(false) , m_interesting(false)

View File

@ -72,9 +72,10 @@ namespace libtorrent { namespace
bool send_peer(peer_connection const& p) bool send_peer(peer_connection const& p)
{ {
// don't send out peers that we haven't connected to // don't send out those peers that we haven't connected to
// (that have connected to us) // (that have connected to us) and that aren't sharing their
if (!p.is_local()) return false; // listening port
if (!p.is_local() && !p.received_listen_port()) return false;
// don't send out peers that we haven't successfully connected to // don't send out peers that we haven't successfully connected to
if (p.is_connecting()) return false; if (p.is_connecting()) return false;
return true; return true;
@ -136,7 +137,7 @@ namespace libtorrent { namespace
peer_connection* peer = *i; peer_connection* peer = *i;
if (!send_peer(*peer)) continue; if (!send_peer(*peer)) continue;
tcp::endpoint const& remote = peer->remote(); tcp::endpoint remote = peer->remote();
m_old_peers.insert(remote); m_old_peers.insert(remote);
std::set<tcp::endpoint>::iterator di = dropped.find(remote); std::set<tcp::endpoint>::iterator di = dropped.find(remote);
@ -151,6 +152,13 @@ namespace libtorrent { namespace
bt_peer_connection* p = static_cast<bt_peer_connection*>(peer); bt_peer_connection* p = static_cast<bt_peer_connection*>(peer);
// if the peer has told us which port its listening on,
// use that port. But only if we didn't connect to the peer.
// if we connected to it, use the port we know works
policy::peer *pi = 0;
if (!p->is_local() && (pi = peer->peer_info_struct()) && pi->port > 0)
remote.port(pi->port);
// no supported flags to set yet // no supported flags to set yet
// 0x01 - peer supports encryption // 0x01 - peer supports encryption
// 0x02 - peer is a seed // 0x02 - peer is a seed
@ -502,11 +510,26 @@ namespace libtorrent { namespace
// no supported flags to set yet // no supported flags to set yet
// 0x01 - peer supports encryption // 0x01 - peer supports encryption
// 0x02 - peer is a seed // 0x02 - peer is a seed
// 0x04 - supports uTP. This is only a positive flags
// passing 0 doesn't mean the peer doesn't
// support uTP
// 0x08 - supports holepunching protocol. If this
// flag is received from a peer, it can be
// used as a rendezvous point in case direct
// connections to the peer fail
int flags = p->is_seed() ? 2 : 0; int flags = p->is_seed() ? 2 : 0;
#ifndef TORRENT_DISABLE_ENCRYPTION #ifndef TORRENT_DISABLE_ENCRYPTION
flags |= p->supports_encryption() ? 1 : 0; flags |= p->supports_encryption() ? 1 : 0;
#endif #endif
tcp::endpoint const& remote = peer->remote(); flags |= p->get_socket()->get<utp_stream>() ? 4 : 0;
flags |= p->supports_holepunch() ? 8 : 0;
tcp::endpoint remote = peer->remote();
policy::peer *pi = 0;
if (!p->is_local() && (pi = peer->peer_info_struct()) && pi->port > 0)
remote.port(pi->port);
// i->first was added since the last time // i->first was added since the last time
if (remote.address().is_v4()) if (remote.address().is_v4())
{ {