Implementation of find node in kademlia torrent routing table

I have already reviewed a number of documents on this topic, but there is something not entirely clear. For example, a bit torrent document ( http://www.bittorrent.org/beps/bep_0005.html ) indicates

The routing table is divided into "buckets", each of which covers parts of the space. An empty table has one bucket with identification space range min = 0, max = 2 ^ 160. When a node with the identifier "N" is inserted into the table, it is placed in a bucket that has min <= N <Maximum. an empty table has only one bucket, so any node must fit into it. each bucket can only hold K nodes, currently eight, before they become “full”. When a bucket is filled with known good nodes, no more nodes can be added unless our own node ID is in the range of the bucket. In this case, the bucket is replaced by two new buckets, each with a half range of the old bucket and the nodes from the old bucket distributed between two new ones. For a new table with one bucket,the full bucket is always divided into two new buckets covering the ranges 0..2 ^ 159 and 2 ^ 159..2 ^ 160.

This is slightly different from other documents regarding the kademlia routing table, where the buckets are located according to the bit identifier of the node identifier, but there is one more confusing thing. When we answer the query "find node", we must find the 8 closest nodes to the requested one using the XOR operation. I saw some implementations going through each element of the routing table that performs the XOR operation, and thus finding the 8 closest elements. It also seems to me that the processor is spending money.

. -, , node, . , , XOR ( ), , .

, 0 99, 8 XOR, , . , , , node . , , , XOR node, , , .

, - ?

+4
1

, kademlia, node, .

bittorrent , , kademlia. , .

, , , XOR node, , , ALL .

- , BEP5 - CIDR-like (. SO), , , .

BEP5- bucket node. - / .

, , .

, , , , 20 , .

, ( node, ) (XOR) .

XOR-distance - ( XOR == ), . , .

N .

, , , DHT node , , , , , CPU, XOR .

.. .


, . ).

A 000... 
B 00100... 
C 0010100... 
D 0010101000... 
E 0010101001...
F 001010101... 
G 00101011... 
H 001011... 
I 0011... 
J 01... 
K 1... 

, :

T = 0010011010111111001111100101011000001010010100001100100010011100000000100100000111001101100110110110101100010100111010111001101111110101001001001000100000001001

, , , , , .

, B, .

B 5 , XOR T 00000???????.... 5 .

B T, , , 00000.... , , , B, 00001.... , T xor 00001... -> 00101110101111110[...].

, , H.

H B

- , 6 - :

00100...      -> B
001011...     -> H
001010101...  -> F
0010101000... -> D
0010101001... -> E
00101011...   -> G

. , :

00000...
000010...
000011000...
0000110010...
0000110011...
00001101...

, :

  • ,
  • XOR bucket ( )
  • XOR
  • , XORed.
  • goto 2

TL; DR: " , " . , .

+3

All Articles