Home > Specs > BitTorrent > DHT
Find Node
The purpose of this message is to obtain nodes from the remote table that are the closest to a target node ID. Using a series of these queries the global DHT can be traversed to find the nodes closest to any node ID.
The Find Node 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
find_node
to indicate this is a find node 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:
target
The value should be set to the 20-byte target node 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.
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.
id
The value should be set to the 20-byte node ID of the responding node.