UDP tracker protocol

Home

Introduction

The UDP tracker protocol is a high-performance low-overhead BitTorrent tracker protocol. URLs for this protocol look like udp://tracker:port.

Azureus, XBT Client and XBT Tracker support this protocol.

All values are send in network byte order (big endian). Do not expect packets to be exactly of a certain size. Future extensions could increase the size of packets.

Set n to 0.
If no response is received after 60 * 2 ^ n seconds, resend the connect request and increase n.
If a response is received, reset n to 0.


HTTP vs UDP

ProtocolPacketsNon-userUserTotal
HTTP10540247 + 119 + 6 * N = 366 + 6 * N906 + 6 * N
UDP416816 + 16 + 98 + 20 + 6 * N = 150 + 6 * N318 + 6 * N
HTTP - UDP6372216588
HTTP / UDP2.53.21.52.0

The UDP tracker protocol uses (less than) 50% of the bandwidth the HTTP tracker protocol uses. And because UDP is stateless, limits to the number of (open) TCP connections a router or server can handle, do not apply.


Structures

Before announcing or scraping, you have to obtain a connection ID.

  1. Choose a (random) transaction ID.
  2. Fill the connect input structure.
  3. Send the packet.
connect input
OffsetSizeNameValue
064-bit integerconnection_id0x41727101980
832-bit integeraction0
1232-bit integertransaction_id
16
  1. Receive the packet.
  2. Check whether the packet is at least 16 bytes.
  3. Check whether the transaction ID is equal to the one you chose.
  4. Check whether the action is connect.
  5. Store the connection ID for future use.
connect output
OffsetSizeNameValue
032-bit integeraction0
432-bit integertransaction_id
864-bit integerconnection_id
16
  1. Choose a (random) transaction ID.
  2. Fill the announce input structure.
  3. Send the packet.
announce input
OffsetSizeNameValue
064-bit integerconnection_id
832-bit integeraction1
1232-bit integertransaction_id
1620-byte stringinfo_hash
3620-byte stringpeer_id
5664-bit integerdownloaded
6464-bit integerleft
7264-bit integeruploaded
8032-bit integerevent
8432-bit integerIP address0
8832-bit integerkey
9232-bit integernum_want-1
9616-bit integerport
98
  1. Receive the packet.
  2. Check whether the packet is at least 20 bytes.
  3. Check whether the transaction ID is equal to the one you chose.
  4. Check whether the action is announce.
  5. Do not announce again until interval seconds have passed or an event has happened.
announce output
OffsetSizeNameValue
032-bit integeraction1
432-bit integertransaction_id
832-bit integerinterval
1232-bit integerleechers
1632-bit integerseeders
20 + 6 * n32-bit integerIP address
24 + 6 * n16-bit integerTCP port
20 + 6 * N

Up to about 74 torrents can be scraped at once. A full scrape can't be done with this protocol.

  1. Choose a (random) transaction ID.
  2. Fill the scrape input structure.
  3. Send the packet.
scrape input
OffsetSizeNameValue
064-bit integerconnection_id
832-bit integeraction2
1232-bit integertransaction_id
16 + 20 * n20-byte stringinfo_hash
16 + 20 * N
  1. Receive the packet.
  2. Check whether the packet is at least 8 bytes.
  3. Check whether the transaction ID is equal to the one you chose.
  4. Check whether the action is scrape.
scrape output
OffsetSizeNameValue
032-bit integeraction2
432-bit integertransaction_id
8 + 12 * n32-bit integerseeders
12 + 12 * n32-bit integercompleted
16 + 12 * n32-bit integerleechers
8 + 12 * N

If the tracker encounters an error, it might send an error packet.

  1. Receive the packet.
  2. Check whether the packet is at least 8 bytes.
  3. Check whether the transaction ID is equal to the one you chose.
error output
OffsetSizeNameValue
032-bit integeraction3
432-bit integertransaction_id
8stringmessage

If the tracker requires authentication, an authentication structure has to be appended to every packet you send to the tracker. The hash is the first 8 bytes of sha1(input + username + sha1(password)).

authenticate input
OffsetSizeName
08-byte zero-padded stringusername
88-byte stringhash
16

Actions


Events


XBT project at SF Donate to this project Valid CSS! Valid HTML 4.01!