From f997f4c22661eb81915936518e8d0247dc40661c Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 6 Apr 2004 20:11:18 +0000 Subject: [PATCH] *** empty log message *** --- docs/udp_tracker_protocol.html | 122 +++++++++++++++++++++++++-------- docs/udp_tracker_protocol.rst | 62 ++++++++++++----- src/policy.cpp | 6 +- src/session.cpp | 85 ----------------------- 4 files changed, 141 insertions(+), 134 deletions(-) diff --git a/docs/udp_tracker_protocol.html b/docs/udp_tracker_protocol.html index 46583557f..35671381f 100644 --- a/docs/udp_tracker_protocol.html +++ b/docs/udp_tracker_protocol.html @@ -10,6 +10,37 @@

Bittorrent udp-tracker protocol extension

+ +
+

introduction

A tracker with the protocol "udp://" in its URI is supposed to be contacted using this protocol.

This protocol is supported by @@ -22,6 +53,7 @@ are specified with ANSI-C standard types.

If no response to a request is received within 15 seconds, resend the request. If no reply has been received after 60 seconds, stop retrying.

+

connecting

@@ -181,35 +213,9 @@ in the reply. Use -1 for default. port The port you're listening on. - - -

If the server requires authorization, the following structure has to be -appended on the announce packet.

- ----- - - - - - - - - - - - - - - + + +
sizenamedescription
uint8_t[20]passwd_hashThe sha1-hash of the announce packet -with the password appended. The -announce message here means the -mandatory part, not including this -authentication appendix.
int8_t[]usernameThe rest of the packet is the -username.
uint16_textensionsSee extensions
@@ -315,9 +321,18 @@ scrape. transaction_id Randomized by client. +int16_t +num_info_hashes +The number of info-hashes that will +follow. + +uint16_t +extensions +See extensions. + -

The rest of the packet contains a variable number of the following structure:

+

The following structure is repeated num_info_hashes times:

@@ -445,6 +460,53 @@ describing the error. +
+

extensions

+

The extensions field is a bitmask. The following +bits are assigned:

+
+ +
+
+
+

authentication

+

The packet will have an authentication part +appended to it. It has the following format:

+
+++++ + + + + + + + + + + + + + + + + + + + + +
sizenamedescription
int8_tusername_lengthThe number of characters in the +username.
int8_t[]usernameThe username, the number of characters +as specified in the previous field.
uint8_t[20]passwd_hashsha1(packet + sha1(password)) +The packet in this case means the +entire packet except these 20 bytes +that are the password hash.
+

credits

Protocol designed by Olaf van der Spek

diff --git a/docs/udp_tracker_protocol.rst b/docs/udp_tracker_protocol.rst index c6b184d67..e541b69ca 100755 --- a/docs/udp_tracker_protocol.rst +++ b/docs/udp_tracker_protocol.rst @@ -2,6 +2,12 @@ Bittorrent udp-tracker protocol extension ========================================= +.. contents:: + + +introduction +++++++++++++ + A tracker with the protocol "udp://" in its URI is supposed to be contacted using this protocol. @@ -113,21 +119,7 @@ Client sends packet: +-------------+---------------------+----------------------------------------+ | uint16_t | port | The port you're listening on. | +-------------+---------------------+----------------------------------------+ - -If the server requires authorization, the following structure has to be -appended on the announce packet. - -+-------------+---------------------+----------------------------------------+ -| size | name | description | -+=============+=====================+========================================+ -| uint8_t[20] | passwd_hash | The sha1-hash of the announce packet | -| | | with the password appended. The | -| | | announce message here means the | -| | | mandatory part, not including this | -| | | authentication appendix. | -+-------------+---------------------+----------------------------------------+ -| int8_t[] | username | The rest of the packet is the | -| | | username. | +| uint16_t | extensions | See extensions_ | +-------------+---------------------+----------------------------------------+ @@ -184,8 +176,13 @@ Client sends packet: +-------------+---------------------+----------------------------------------+ | int32_t | transaction_id | Randomized by client. | +-------------+---------------------+----------------------------------------+ +| int16_t | num_info_hashes | The number of info-hashes that will | +| | | follow. | ++-------------+---------------------+----------------------------------------+ +| uint16_t | extensions | See extensions_. | ++-------------+---------------------+----------------------------------------+ -The rest of the packet contains a variable number of the following structure: +The following structure is repeated ``num_info_hashes`` times: +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -221,6 +218,7 @@ The rest of the packet contains a variable number of the following structures: | | | leechers. | +-------------+---------------------+----------------------------------------+ + errors ++++++ @@ -253,6 +251,38 @@ The action fields has the following encoding: * error = 3 (only in server replies) +extensions +++++++++++ + +The extensions field is a bitmask. The following +bits are assigned: + + * 1 = authentication_. + + + +authentication +++++++++++++++ + +The packet will have an authentication part +appended to it. It has the following format: + ++-------------+---------------------+----------------------------------------+ +| size | name | description | ++=============+=====================+========================================+ +| int8_t | username_length | The number of characters in the | +| | | username. | ++-------------+---------------------+----------------------------------------+ +| int8_t[] | username | The username, the number of characters | +| | | as specified in the previous field. | ++-------------+---------------------+----------------------------------------+ +| uint8_t[20] | passwd_hash | sha1(packet + sha1(password)) | +| | | The packet in this case means the | +| | | entire packet except these 20 bytes | +| | | that are the password hash. | ++-------------+---------------------+----------------------------------------+ + + credits +++++++ diff --git a/src/policy.cpp b/src/policy.cpp index 042d8f769..d5f5e6ef7 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -548,8 +548,8 @@ namespace libtorrent // remove old disconnected peers from the list m_peers.erase( std::remove_if(m_peers.begin() - , m_peers.end() - , old_disconnected_peer()) + , m_peers.end() + , old_disconnected_peer()) , m_peers.end()); // ------------------------------------- @@ -747,7 +747,7 @@ namespace libtorrent // if the connection comes from the tracker, // it's probably just a NAT-check. Ignore the // num connections constraint then. - // TODO: mske sure this works + // TODO: make sure this works // TODO: only allow _one_ connection to use this // override at a time if (m_torrent->num_peers() >= m_max_connections diff --git a/src/session.cpp b/src/session.cpp index c60703430..f71085280 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -77,91 +77,6 @@ namespace std }; #endif -namespace -{ -/* - int saturated_add(int a, int b) - { - assert(a>=0); - assert(b>=0); - - int sum=a+b; - if(sum<0) - sum=std::numeric_limits::max(); - - assert(sum>=a && sum>=b); - return sum; - } -*/ - // adjusts the upload rates of every peer connection - // to make sure the sum of all send quotas equals - // the given upload_limit. An upload limit of - // std::numeric_limits::max() means unlimited upload - // rate, but the rates of each peer has to be set anyway, - // since it depends on the download rate from the peer. -/* - void control_upload_rates( - int upload_limit, - libtorrent::detail::session_impl::connection_map connections) - { - assert(upload_limit >= 0); - - using namespace libtorrent; - std::vector requests; - - for (detail::session_impl::connection_map::iterator c = connections.begin(); - c != connections.end(); ++c) - { - boost::shared_ptr p = c->second; - requests.push_back(p->upload_bandwidth_quota()); - } - - allocate_resources(upload_limit, requests); - - for (detail::session_impl::connection_map::iterator c = connections.begin(); - c != connections.end(); ++c) - { - boost::shared_ptr p = c->second; - p->update_send_quota_left(); - } - } -*/ -/* - void control_number_of_connections( - int connections_limit, - libtorrent::detail::session_impl::torrent_map hash_list) - { - assert(connections_limit >= 0); - - using namespace libtorrent; - std::vector torrents; - - for (detail::session_impl::torrent_map::iterator c = hash_list.begin(); - c != hash_list.end(); ++c) - { - boost::shared_ptr t = c->second; - - int estimated_capacity=t->num_peers()+1; - int limit =t->get_policy().get_max_connections(); - if(limit==-1) - limit=std::numeric_limits::max(); - - torrents.push_back(resource_consumer(t,limit,estimated_capacity)); - } - - allocate_resources(connections_limit, torrents); - - for (std::vector::iterator r=torrents.begin(); - r!=torrents.end(); ++r) - { - // TODO: inform torrent of how many connections it's allowed. -// boost::any_cast > -// (r->who())->set_send_quota(r->allowed_use()); - } - } -*/ -} - namespace libtorrent { namespace detail {