Home > Specs > BitTorrent > DHT
Get Peers
The purpose if this message is to get peers from the remote peer database that have announced into the exact target hash ID. If no peers are in the node's peer database, this message acts exactly like a
Find Node message, and will return a list of closest nodes from the remote node table instead.
The get peers query is sent as a plain BEncoded map, in a single UDP packet. It has the following keys:
y
Set the value of this key to the string
q
because this is a query.
q
Set the value of this to the string
get_peers
to indicate this is a get peers query.
t
Set the value of this to a random 4-byte transaction ID.
a
This value is an inner map that represents the query arguments. It contains the following keys:
info_hash
The value should be set to the 20-byte info hash ID that we are searching for.
id
The value should be set to the 20-byte local node ID.
The ping response is also a plain BEncoded map, in a single UDP packet. It has the following keys:
y
Set the value of this key to the string
r
because this is a response.
t
Set the value of this to the transaction ID from the original query that we are responding to.
r
This value is an inner map that represents the response to the query. It contains the following keys:
nodes
This is a compact representation in string form of the nodes in the remote node table that are closest to the target ID. Each node is a 20-byte node ID followed by a 4-byte IPv4 address followed by a 2-byte big-endian port. If the
values
key is present, this key will not be included.
nodes6
This is a compact representation in string form of the nodes in the remote node table that are closest to the target ID. Each node is a 20-byte node ID followed by a 16-byte IPv6 address followed by a 2-byte big-endian port. If the
values
key is present, this key will not be included.
values
This is a list of strings, one for each peer returned from the database. Each string contains a compact 4-byte IPv4 address or 16-byte IPv6 address, followed by a 2-byte big-endian port number. If this value is present, there will not be a
nodes
or
nodes6
key, and a regular
Find Node message should be used to see if there are any closer nodes in the remote table.
token
This is a string that must be included in an
Announce message.
id
The value should be set to the 20-byte node ID of the responding node.