UDP Tracker Protocol

This description of the UDP tracker protocol is adapted from this page by Arvid Norberg.

A tracker with the protocol “udp://” in its URI is should be contacted with this protocol.

All values are sent in network byte order (big-endian).

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.

Transaction IDs sent in request messages are returned in response messages.

Connection ID returned by tracker in connect response message should be sent by client in later requests. The initial connection ID sent in connect requests shoudl be 0x41727101980 in network byte order.

Action values in requests and responses should be taken from the Actions table.

When a message is followed by a structure labeled repeating:, the rest of the message is zero or more of that structure.

Fields with type [T; N] are N instances of values of type T with no extra padding.

Fields with type [T; NAME] are NAME instances of values of type T with no extra padding, where NAME is an integer field of the same message.

Files with type [T] are zero or more instances of values of type T with no extra padding, which make up any trailing bytes of the message.

Actions

namevalue
connect0
announce1
scrape2
error3

Events

namevalue
none0
completed1
started2
stopped3

Error

typenamedescription
i32action
i32transaction_id
[i8]error_stringrest of packet is string describing error

Connect

Request

typename
i64connection_id
i32action
i32transaction_id

Response

typename
i32action
i32transaction_id
i64connection_id

Announce

Request

typenamedescription
i64connection_id
i32action
i32transaction_id
[i8; 20]info_hashtorrent infohash
[i8; 20]peer_idpeer ID
i64downloadedbytes downloaded this session
i64leftbytes left to download
i64uploadedbytes uploaded this session
i32eventfrom Events table
u32ip0 to use sender of this UDP packet
u32keyrandomly generated by client, unknown function.
i32num_wantmaximum number of peers to send in reply, use -1 for default
u16portlistening port
u16extensions

Response

typenamedescription
i32action
i32transaction_id
i32intervalseconds to wait announcing again
i32leechersnumber of peers in swarm that have not finished downloading
i32seedersnumber of peers in swarm that have finished downloading

repeating:

typenamedescription
i32ippeer IP
i16portpeer listening port

Scrape

Request

typename
i64connection_id
i32action
i32transaction_id

repeating:

typename
[i8; 20]info_hash

Response

typename
i32action
i32transaction_id

repeating:

typenamedescription
i32completepeers in swarm that have finished downloding
i32downloadedtimes torrent has been downloaded
i32incompletepeers that have not finished downloading

Extensions

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

namebit
authentication1
request string2

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.

Authentication

The packet will have authentication information appended to it.

passwd_hash is the first eight bytes of sha1(packet || sha1(password)), where packet is the bytes of the packet, less the final 8 bytes that are passwd_hash.

typename
i8username_length
[i8; username_lengthusername
[u8; 8]passwd_hash

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:

typename
i8request_length
[i8; request_length]request_string

request_string is the string that comes after the hostname 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.|

Credits

Protocol designed by Olaf van der Spek and extended by Arvid Norberg