From f4cc9f755f35671826f678bbaf53e3d4d6b4770b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 12 Mar 2004 16:42:33 +0000 Subject: [PATCH] added support for compact=1 --- src/http_tracker_connection.cpp | 33 +++++++++++++++++++++++++++++---- src/policy.cpp | 9 +++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index ab0c786ab..1e9d07752 100755 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -44,6 +44,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/entry.hpp" #include "libtorrent/bencode.hpp" #include "libtorrent/torrent.hpp" +#include "libtorrent/io.hpp" using namespace libtorrent; @@ -154,6 +155,7 @@ namespace libtorrent // extension that tells the tracker that // we don't need any peer_id's in the response m_send_buffer += "&no_peer_id=1"; + m_send_buffer += "&compact=1"; m_send_buffer += " HTTP/1.0\r\nAccept-Encoding: gzip\r\n" "User-Agent: "; @@ -504,11 +506,34 @@ namespace libtorrent peer_list.clear(); - const entry::list_type& l = e["peers"].list(); - for(entry::list_type::const_iterator i = l.begin(); i != l.end(); ++i) + if (e["peers"].type() == entry::string_t) { - peer_entry p = extract_peer_info(*i); - peer_list.push_back(p); + std::string const& peers = e["peers"].string(); + for (std::string::const_iterator i = peers.begin(); + i != peers.end();) + { + if (std::distance(i, peers.end()) < 6) break; + + peer_entry p; + p.id.clear(); + std::stringstream ip_str; + ip_str << (int)detail::read_uint8(i) << "."; + ip_str << (int)detail::read_uint8(i) << "."; + ip_str << (int)detail::read_uint8(i) << "."; + ip_str << (int)detail::read_uint8(i); + p.ip = ip_str.str(); + p.port = detail::read_uint16(i); + peer_list.push_back(p); + } + } + else + { + const entry::list_type& l = e["peers"].list(); + for(entry::list_type::const_iterator i = l.begin(); i != l.end(); ++i) + { + peer_entry p = extract_peer_info(*i); + peer_list.push_back(p); + } } requester()->tracker_response(peer_list, interval); diff --git a/src/policy.cpp b/src/policy.cpp index a9ca9ee7c..a217fb68e 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -486,8 +486,17 @@ namespace libtorrent ++i) { peer_connection* c = i->connection; + // ignore peers that are choked or + // whose connection is closed if (c == 0) continue; if (c->is_choked()) continue; + + // if we still owe this peer some upload + // don't choke it + if (c->share_diff() > 0) continue; + + // select the one that has been waiting + // for an unchoke the longest if (last_unchoke > i->last_optimistically_unchoked) continue; last_unchoke = i->last_optimistically_unchoked; candidate = &(*i);