Home > Specs > BitTorrent
DHT
DHT stands for Distributed Hash Table. It is a decentralized way to find other peers in the same torrent. All nodes participating in the DHT share responsibility for indexing torrent peers.
Each node has a randomly chosen node ID that is 20 bytes long. Note that a torrent info hash is also 20 bytes long.
Node Table
The node table keeps track of a subset of other nodes. It does this by pinging the remote nodes at regular intervals. The probability of any particular remote node being tracked in the local table depends on how close its node ID is to the local node ID. Using a series of queries, it is possible to traverse the tables of remote nodes to find nodes that are the closest to any particular node ID.
Peer Database
The peer DB serves the same purpose as a conventional UDP tracker. A peer can announce itself as being in a particular torrent, and is also provided a list of other peers that have recently announced themselves for the same torrent. The probability of any node being used to announce a torrent depends on how close the node ID is to the torrent info hash ID.
Messages are sent over UDP as plain BEncoded messages.
Ping
This message verifies a node is online.
Find Node
This message requests a list of nodes that are closest to a target node ID.
Get Peers
This is the same as Find Node except the response should also contain a list of peers from the Peer DB that have announced the target info-hash.
Announce
After a Get Peers message is responded to, this message is used to add the local node to the list of peers for the target info-hash in the Peer DB.