| 29 | | Node IDs are chosen at random from the same 160-bit space as BitTorrent |
| 30 | | infohashes [#entropy]_. A "distance metric" is used to compare two node IDs or a node |
| 31 | | ID and an infohash for "closeness." Nodes must maintain a routing table |
| 32 | | containing the contact information for a small number of other nodes. |
| 33 | | The routing table becomes more detailed as IDs get closer to the node's |
| 34 | | own ID. Nodes know about many other nodes in the DHT that have IDs that |
| 35 | | are "close" to their own but have only a handful of contacts with IDs |
| 36 | | that are very far away from their own. |
| | 30 | Node IDs are chosen at random from the same 160-bit space as |
| | 31 | BitTorrent infohashes [#entropy]_. A "distance metric" is used to |
| | 32 | compare two node IDs or a node ID and an infohash for "closeness." |
| | 33 | Nodes must maintain a routing table containing the contact information |
| | 34 | for a small number of other nodes. The routing table becomes more |
| | 35 | detailed as IDs get closer to the node's own ID. Nodes know about many |
| | 36 | other nodes in the DHT that have IDs that are "close" to their own but |
| | 37 | have only a handful of contacts with IDs that are very far away from |
| | 38 | their own. |
| 200 | | Contact information for peers is encoded as a 6-byte string. Also |
| 201 | | known as "Compact IP-address/port info" the 4-byte IP address is in |
| 202 | | network byte order with the 2 byte port in network byte order |
| 203 | | concatenated onto the end. |
| 204 | | |
| 205 | | Contact information for nodes is encoded as a 26-byte string. |
| 206 | | Also known as "Compact node info" the 20-byte Node ID in network byte |
| 207 | | order has the compact IP-address/port info concatenated to the end. |
| | 202 | ---------------- |
| | 203 | |
| | 204 | Contact information for peers is encoded as a 6-byte string. Also |
| | 205 | known as "Compact IP-address/port info" the 4-byte IP address is in |
| | 206 | network byte order with the 2 byte port in network byte order |
| | 207 | concatenated onto the end. |
| | 208 | |
| | 209 | Contact information for nodes is encoded as a 26-byte string. |
| | 210 | Also known as "Compact node info" the 20-byte Node ID in network byte |
| | 211 | order has the compact IP-address/port info concatenated to the end. |
| 210 | | Queries, or KRPC message dictionaries with a "y" value of "q", |
| 211 | | contain two additional keys; "q" and "a". Key "q" has a string value |
| 212 | | containing the method name of the query. Key "a" has a dictionary value |
| 213 | | containing named arguments to the query. |
| | 214 | ------- |
| | 215 | |
| | 216 | Queries, or KRPC message dictionaries with a "y" value of "q", |
| | 217 | contain two additional keys; "q" and "a". Key "q" has a string value |
| | 218 | containing the method name of the query. Key "a" has a dictionary value |
| | 219 | containing named arguments to the query. |
| 216 | | Responses, or KRPC message dictionaries with a "y" value of "r", |
| 217 | | contain one additional key "r". The value of "r" is a dictionary |
| 218 | | containing named return values. Response messages are sent upon |
| 219 | | successful completion of a query. |
| | 222 | --------- |
| | 223 | |
| | 224 | Responses, or KRPC message dictionaries with a "y" value of "r", |
| | 225 | contain one additional key "r". The value of "r" is a dictionary |
| | 226 | containing named return values. Response messages are sent upon |
| | 227 | successful completion of a query. |
| 222 | | Errors, or KRPC message dictionaries with a "y" value of "e", |
| 223 | | contain one additional key "e". The value of "e" is a list. The first |
| 224 | | element is an integer representing the error code. The second element |
| 225 | | is a string containing the error message. Errors are sent when a query |
| 226 | | cannot be fulfilled. The following table describes the possible error |
| 227 | | codes: |
| | 230 | ------ |
| | 231 | |
| | 232 | Errors, or KRPC message dictionaries with a "y" value of "e", |
| | 233 | contain one additional key "e". The value of "e" is a list. The first |
| | 234 | element is an integer representing the error code. The second element |
| | 235 | is a string containing the error message. Errors are sent when a query |
| | 236 | cannot be fulfilled. The following table describes the possible error |
| | 237 | codes: |
| 258 | | The most basic query is a ping. "q" = "ping" A ping query has a |
| 259 | | single argument, "id" the value is a 20-byte string containing the |
| 260 | | senders node ID in network byte order. The appropriate response to a |
| 261 | | ping has a single key "id" containing the node ID of the responding |
| 262 | | node. |
| | 268 | ---- |
| | 269 | |
| | 270 | The most basic query is a ping. "q" = "ping" A ping query has a |
| | 271 | single argument, "id" the value is a 20-byte string containing the |
| | 272 | senders node ID in network byte order. The appropriate response to a |
| | 273 | ping has a single key "id" containing the node ID of the responding |
| | 274 | node. |
| 285 | | Find node is used to find the contact information for a node given |
| 286 | | its ID. "q" == "find_node" A find_node query has two arguments, "id" |
| 287 | | containing the node ID of the querying node, and "target" containing |
| 288 | | the ID of the node sought by the queryer. When a node receives a |
| 289 | | find_node query, it should respond with a key "nodes" and value of a |
| 290 | | string containing the compact node info for the target node or the K |
| 291 | | (8) closest good nodes in its own routing table. |
| | 297 | --------- |
| | 298 | |
| | 299 | Find node is used to find the contact information for a node given |
| | 300 | its ID. "q" == "find_node" A find_node query has two arguments, "id" |
| | 301 | containing the node ID of the querying node, and "target" containing |
| | 302 | the ID of the node sought by the queryer. When a node receives a |
| | 303 | find_node query, it should respond with a key "nodes" and value of a |
| | 304 | string containing the compact node info for the target node or the K |
| | 305 | (8) closest good nodes in its own routing table. |
| 314 | | Get peers associated with a torrent infohash. "q" = "get_peers" A |
| 315 | | get_peers query has two arguments, "id" containing the node ID of the |
| 316 | | querying node, and "info_hash" containing the infohash of the torrent. |
| 317 | | If the queried node has peers for the infohash, they are returned in a |
| 318 | | key "values" as a list of strings. Each string containing "compact" format |
| 319 | | peer information for a single peer. If the queried node has no |
| 320 | | peers for the infohash, a key "nodes" is returned containing the K |
| 321 | | nodes in the queried nodes routing table closest to the infohash |
| 322 | | supplied in the query. In either case a "token" key is also included in |
| 323 | | the return value. The token value is a required argument for a future |
| 324 | | announce_peer query. The token value should be a short binary string. |
| | 328 | --------- |
| | 329 | |
| | 330 | Get peers associated with a torrent infohash. "q" = "get_peers" A |
| | 331 | get_peers query has two arguments, "id" containing the node ID of the |
| | 332 | querying node, and "info_hash" containing the infohash of the torrent. |
| | 333 | If the queried node has peers for the infohash, they are returned in a |
| | 334 | key "values" as a list of strings. Each string containing "compact" format |
| | 335 | peer information for a single peer. If the queried node has no |
| | 336 | peers for the infohash, a key "nodes" is returned containing the K |
| | 337 | nodes in the queried nodes routing table closest to the infohash |
| | 338 | supplied in the query. In either case a "token" key is also included in |
| | 339 | the return value. The token value is a required argument for a future |
| | 340 | announce_peer query. The token value should be a short binary string. |
| 355 | | Announce that the peer, controlling the querying node, is downloading |
| 356 | | a torrent on a port. announce_peer has four arguments: "id" containing the node ID of the |
| 357 | | querying node, "info_hash" containing the infohash of the torrent, |
| 358 | | "port" containing the port as an integer, and the "token" received in |
| 359 | | response to a previous get_peers query. The queried node must verify |
| 360 | | that the token was previously sent to the same IP address as the |
| 361 | | querying node. Then the queried node should store the IP address of the |
| 362 | | querying node and the supplied port number under the infohash in its |
| 363 | | store of peer contact information. |
| | 371 | ------------- |
| | 372 | |
| | 373 | Announce that the peer, controlling the querying node, is downloading |
| | 374 | a torrent on a port. announce_peer has four arguments: "id" containing the node ID of the |
| | 375 | querying node, "info_hash" containing the infohash of the torrent, |
| | 376 | "port" containing the port as an integer, and the "token" received in |
| | 377 | response to a previous get_peers query. The queried node must verify |
| | 378 | that the token was previously sent to the same IP address as the |
| | 379 | querying node. Then the queried node should store the IP address of the |
| | 380 | querying node and the supplied port number under the infohash in its |
| | 381 | store of peer contact information. |
| 385 | | |
| 386 | | Send questions, comments and corrections to editor@bittorrent.org |
| 387 | | |
| 388 | | |
| 389 | | .. [Kademlia] Peter Maymounkov, David Mazieres, "`Kademlia: A Peer-to-peer Information System Based on the XOR Metric`_", IPTPS 2002. |
| 390 | | |
| 391 | | .. _`Kademlia: A Peer-to-peer Information System Based on the XOR Metric`: http://www.cs.rice.edu/Conferences/IPTPS02/109.pdf |
| | 403 | References |
| | 404 | ========== |
| | 405 | |
| | 406 | .. [#Kademlia] Peter Maymounkov, David Mazieres, "Kademlia: A Peer-to-peer Information System Based on the XOR Metric", *IPTPS 2002*. http://www.cs.rice.edu/Conferences/IPTPS02/109.pdf |