2004-01-22 23:45:52 +01:00
|
|
|
Bittorrent udp-tracker protocol extension
|
|
|
|
=========================================
|
|
|
|
|
2014-10-14 04:06:20 +02:00
|
|
|
:Author: Arvid Norberg, arvid@libtorrent.org
|
2005-11-01 19:30:39 +01:00
|
|
|
|
|
|
|
.. contents:: Table of contents
|
|
|
|
:depth: 2
|
|
|
|
:backlinks: none
|
2004-04-06 22:11:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
introduction
|
2005-11-01 19:30:39 +01:00
|
|
|
------------
|
2004-04-06 22:11:18 +02:00
|
|
|
|
2004-01-22 23:45:52 +01:00
|
|
|
A tracker with the protocol "udp://" in its URI
|
|
|
|
is supposed to be contacted using this protocol.
|
|
|
|
|
|
|
|
This protocol is supported by
|
|
|
|
xbt-tracker_.
|
|
|
|
|
|
|
|
|
|
|
|
.. _xbt-tracker: http://xbtt.sourceforge.net
|
|
|
|
|
|
|
|
For additional information and descritptions of
|
|
|
|
the terminology used in this document, see
|
|
|
|
the `protocol specification`__
|
|
|
|
|
|
|
|
__ http://wiki.theory.org/index.php/BitTorrentSpecification
|
|
|
|
|
|
|
|
All values are sent in network byte order (big endian). The sizes
|
|
|
|
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
|
2005-11-01 19:30:39 +01:00
|
|
|
----------
|
2004-01-22 23:45:52 +01:00
|
|
|
|
|
|
|
Client sends packet:
|
|
|
|
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| size | name | description |
|
|
|
|
+=============+=====================+========================================+
|
2004-04-17 12:47:31 +02:00
|
|
|
| int64_t | connection_id | Must be initialized to 0x41727101980 |
|
|
|
|
| | | in network byte order. This will |
|
|
|
|
| | | identify the protocol. |
|
2004-01-22 23:45:52 +01:00
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int32_t | action | 0 for a connection request |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int32_t | transaction_id | Randomized by client. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
|
|
|
|
Server replies with packet:
|
|
|
|
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| size | name | description |
|
|
|
|
+=============+=====================+========================================+
|
|
|
|
| int32_t | action | Describes the type of packet, in this |
|
|
|
|
| | | case it should be 0, for connect. |
|
|
|
|
| | | If 3 (for error) see errors_. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int32_t | transaction_id | Must match the transaction_id sent |
|
|
|
|
| | | from the client. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int64_t | connection_id | A connection id, this is used when |
|
|
|
|
| | | further information is exchanged with |
|
|
|
|
| | | the tracker, to identify you. |
|
|
|
|
| | | This connection id can be reused for |
|
|
|
|
| | | multiple requests, but if it's cached |
|
|
|
|
| | | for too long, it will not be valid |
|
|
|
|
| | | anymore. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
|
|
|
|
|
|
|
|
announcing
|
2005-11-01 19:30:39 +01:00
|
|
|
----------
|
2004-01-22 23:45:52 +01:00
|
|
|
|
|
|
|
Client sends packet:
|
|
|
|
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| size | name | description |
|
|
|
|
+=============+=====================+========================================+
|
|
|
|
| int64_t | connection_id | The connection id acquired from |
|
|
|
|
| | | establishing the connection. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int32_t | action | Action. in this case, 1 for announce. |
|
2004-04-17 12:47:31 +02:00
|
|
|
| | | See actions_. |
|
2004-01-22 23:45:52 +01:00
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int32_t | transaction_id | Randomized by client. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int8_t[20] | info_hash | The info-hash of the torrent you want |
|
|
|
|
| | | announce yourself in. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int8_t[20] | peer_id | Your peer id. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int64_t | downloaded | The number of byte you've downloaded |
|
|
|
|
| | | in this session. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int64_t | left | The number of bytes you have left to |
|
|
|
|
| | | download until you're finished. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int64_t | uploaded | The number of bytes you have uploaded |
|
|
|
|
| | | in this session. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int32_t | event | The event, one of |
|
|
|
|
| | | |
|
|
|
|
| | | * none = 0 |
|
|
|
|
| | | * completed = 1 |
|
|
|
|
| | | * started = 2 |
|
|
|
|
| | | * stopped = 3 |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| uint32_t | ip | Your ip address. Set to 0 if you want |
|
|
|
|
| | | the tracker to use the ``sender`` of |
|
|
|
|
| | | this udp packet. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
2004-04-03 00:21:20 +02:00
|
|
|
| uint32_t | key | A unique key that is randomized by the |
|
|
|
|
| | | client. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
2004-01-22 23:45:52 +01:00
|
|
|
| int32_t | num_want | The maximum number of peers you want |
|
|
|
|
| | | in the reply. Use -1 for default. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| uint16_t | port | The port you're listening on. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
2004-04-06 22:11:18 +02:00
|
|
|
| uint16_t | extensions | See extensions_ |
|
2004-04-03 00:21:20 +02:00
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
|
|
|
|
|
2004-01-22 23:45:52 +01:00
|
|
|
Server replies with packet:
|
|
|
|
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| size | name | description |
|
|
|
|
+=============+=====================+========================================+
|
|
|
|
| int32_t | action | The action this is a reply to. Should |
|
|
|
|
| | | in this case be 1 for announce. |
|
|
|
|
| | | If 3 (for error) see errors_. |
|
2004-04-17 12:47:31 +02:00
|
|
|
| | | See actions_. |
|
2004-01-22 23:45:52 +01:00
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int32_t | transaction_id | Must match the transaction_id sent |
|
|
|
|
| | | in the announce request. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int32_t | interval | the number of seconds you should wait |
|
|
|
|
| | | until reannouncing yourself. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
2004-04-03 00:21:20 +02:00
|
|
|
| int32_t | leechers | The number of peers in the swarm that |
|
|
|
|
| | | has not finished downloading. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int32_t | seeders | The number of peers in the swarm that |
|
|
|
|
| | | has finished downloading and are |
|
|
|
|
| | | seeding. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
2004-01-22 23:45:52 +01:00
|
|
|
|
|
|
|
The rest of the server reply is a variable number of the following structure:
|
|
|
|
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| size | name | description |
|
|
|
|
+=============+=====================+========================================+
|
|
|
|
| int32_t | ip | The ip of a peer in the swarm. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
2004-01-28 12:37:46 +01:00
|
|
|
| uint16_t | port | The peer's listen port. |
|
2004-01-22 23:45:52 +01:00
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
|
|
|
|
|
|
|
|
scraping
|
2005-11-01 19:30:39 +01:00
|
|
|
--------
|
2004-01-22 23:45:52 +01:00
|
|
|
|
|
|
|
Client sends packet:
|
|
|
|
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| size | name | description |
|
|
|
|
+=============+=====================+========================================+
|
|
|
|
| int64_t | connection_id | The connection id retreived from the |
|
|
|
|
| | | establishing of the connection. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int32_t | action | The action, in this case, 2 for |
|
2004-04-17 12:47:31 +02:00
|
|
|
| | | scrape. See actions_. |
|
2004-01-22 23:45:52 +01:00
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int32_t | transaction_id | Randomized by client. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
2004-04-03 00:21:20 +02:00
|
|
|
|
2008-02-01 20:23:46 +01:00
|
|
|
The following structure is repeated for each info-hash to scrape, but limited by
|
|
|
|
the MTU.
|
2004-04-03 00:21:20 +02:00
|
|
|
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| size | name | description |
|
|
|
|
+=============+=====================+========================================+
|
2004-01-28 12:37:46 +01:00
|
|
|
| int8_t[20] | info_hash | The info hash that is to be scraped. |
|
2004-01-22 23:45:52 +01:00
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
|
2004-04-03 00:21:20 +02:00
|
|
|
|
2004-01-22 23:45:52 +01:00
|
|
|
Server replies with packet:
|
|
|
|
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| size | name | description |
|
|
|
|
+=============+=====================+========================================+
|
|
|
|
| int32_t | action | The action, should in this case be |
|
|
|
|
| | | 2 for scrape. |
|
|
|
|
| | | If 3 (for error) see errors_. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int32_t | transaction_id | Must match the sent transaction id. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
|
2004-04-17 12:47:31 +02:00
|
|
|
The rest of the packet contains the following structures once for each info-hash
|
|
|
|
you asked in the scrape request.
|
2004-01-22 23:45:52 +01:00
|
|
|
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| size | name | description |
|
|
|
|
+=============+=====================+========================================+
|
2009-06-26 21:01:37 +02:00
|
|
|
| int32_t | complete | The current number of connected seeds. |
|
2004-01-22 23:45:52 +01:00
|
|
|
+-------------+---------------------+----------------------------------------+
|
2009-06-26 21:01:37 +02:00
|
|
|
| int32_t | downloaded | The number of times this torrent has |
|
|
|
|
| | | been downloaded. |
|
2004-01-22 23:45:52 +01:00
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int32_t | incomplete | The current number of connected |
|
|
|
|
| | | leechers. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
|
2004-04-06 22:11:18 +02:00
|
|
|
|
2004-01-22 23:45:52 +01:00
|
|
|
errors
|
2005-11-01 19:30:39 +01:00
|
|
|
------
|
2004-04-03 00:21:20 +02:00
|
|
|
|
|
|
|
In case of a tracker error,
|
2004-01-22 23:45:52 +01:00
|
|
|
|
2004-04-03 00:21:20 +02:00
|
|
|
server replies packet:
|
2004-01-22 23:45:52 +01:00
|
|
|
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| size | name | description |
|
|
|
|
+=============+=====================+========================================+
|
|
|
|
| int32_t | action | The action, in this case 3, for error. |
|
2004-04-17 12:47:31 +02:00
|
|
|
| | | See actions_. |
|
2004-01-22 23:45:52 +01:00
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int32_t | transaction_id | Must match the transaction_id sent |
|
|
|
|
| | | from the client. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
2004-01-28 12:37:46 +01:00
|
|
|
| int8_t[] | error_string | The rest of the packet is a string |
|
2004-01-22 23:45:52 +01:00
|
|
|
| | | describing the error. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
|
|
|
|
|
|
|
|
actions
|
2005-11-01 19:30:39 +01:00
|
|
|
-------
|
2004-01-22 23:45:52 +01:00
|
|
|
|
2004-01-23 01:42:12 +01:00
|
|
|
The action fields has the following encoding:
|
2004-01-22 23:45:52 +01:00
|
|
|
|
|
|
|
* connect = 0
|
|
|
|
* announce = 1
|
|
|
|
* scrape = 2
|
|
|
|
* error = 3 (only in server replies)
|
|
|
|
|
|
|
|
|
2004-04-06 22:11:18 +02:00
|
|
|
extensions
|
2005-11-01 19:30:39 +01:00
|
|
|
----------
|
2004-04-06 22:11:18 +02:00
|
|
|
|
|
|
|
The extensions field is a bitmask. The following
|
|
|
|
bits are assigned:
|
|
|
|
|
|
|
|
* 1 = authentication_.
|
2012-08-23 23:02:09 +02:00
|
|
|
* 2 = `request string`_.
|
2004-04-06 22:11:18 +02:00
|
|
|
|
2012-08-23 23:02:09 +02:00
|
|
|
If multiple bits are present in the extension field, the extension
|
|
|
|
bodies are appended to the packet in the order of least significant
|
|
|
|
bit first. For instance, if both bit 1 and 2 are set, the extension
|
|
|
|
represented by bit 1 comes first, followed by the extension represented
|
|
|
|
by bit 2.
|
2004-04-06 22:11:18 +02:00
|
|
|
|
|
|
|
authentication
|
2005-11-01 19:30:39 +01:00
|
|
|
~~~~~~~~~~~~~~
|
2004-04-06 22:11:18 +02:00
|
|
|
|
|
|
|
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. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
2004-04-17 12:47:31 +02:00
|
|
|
| uint8_t[8] | passwd_hash | sha1(packet + sha1(password)) |
|
2004-04-06 22:11:18 +02:00
|
|
|
| | | The packet in this case means the |
|
2004-04-17 12:47:31 +02:00
|
|
|
| | | entire packet except these 8 bytes |
|
|
|
|
| | | that are the password hash. These are |
|
|
|
|
| | | the 8 first bytes (most significant) |
|
|
|
|
| | | from the 20 bytes hash calculated. |
|
2004-04-06 22:11:18 +02:00
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
|
2012-08-23 23:02:09 +02:00
|
|
|
request string
|
|
|
|
--------------
|
|
|
|
|
|
|
|
The request string extension is meant to allow torrent creators pass along
|
|
|
|
cookies back to the tracker. This can be useful for authenticating that a
|
|
|
|
torrent is allowed to be tracked by a tracker for instance. It could also
|
|
|
|
be used to authenticate users by generating torrents with unique tokens
|
|
|
|
in the tracker URL for each user. The extension body has the following format:
|
|
|
|
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| size | name | description |
|
|
|
|
+=============+=====================+========================================+
|
2013-04-24 18:44:21 +02:00
|
|
|
| int8_t | request length | The number of bytes in the request |
|
2012-08-23 23:02:09 +02:00
|
|
|
| | | string. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
|
|
|
| int8_t[] | request string | The string that comes after the host- |
|
|
|
|
| | | name and port in the udp tracker URL. |
|
|
|
|
| | | Typically this starts with "/announce" |
|
|
|
|
| | | The bittorrent client is not expected |
|
|
|
|
| | | to append query string arguments for |
|
|
|
|
| | | stats reporting, like "uploaded" and |
|
|
|
|
| | | "downloaded" since this is already |
|
|
|
|
| | | reported in the udp tracker protocol. |
|
|
|
|
| | | However, the client is free to add |
|
|
|
|
| | | arguments as extensions. |
|
|
|
|
+-------------+---------------------+----------------------------------------+
|
2004-04-06 22:11:18 +02:00
|
|
|
|
2004-01-22 23:45:52 +01:00
|
|
|
credits
|
2005-11-01 19:30:39 +01:00
|
|
|
-------
|
2004-01-22 23:45:52 +01:00
|
|
|
|
2012-08-23 23:02:09 +02:00
|
|
|
Protocol designed by Olaf van der Spek and extended by Arvid Norberg
|
2004-01-22 23:45:52 +01:00
|
|
|
|