Kademlia

How can we download torrents even when the tracker is down ?

Every torrent client uses a DHT (Distributed Hash Table) algorithm Kademlia invented by Petar Maymounkov & David Mazières.

 

Lets Begin :-)

  • Every torrent client has a DHT node with it. (Mostly enabled by default)
  • The node is assigned a 160 bit id.
  • Every torrent also has an "infohash" - 160 bits.

The nodes are arranged as the leaves in a giant binary tree. The id corresponds to the nodes position.

If we only had 3 bit ids the below would be the entire network.

Distance between nodes

  • XOR is used to measure the distance between to id's or nodes.

Why XOR ?

  • Has a lot of interesting properties.[1]
  • d(x,y) = d(y,x), unidirectional, d(x,x) =0 etc
  • Unidirectional - there is only one point with a given distance from a given point.

Protocol

  • Originally 3 RPC's - Find Node, Find Value, Store Value.

Find Node

  • Ping list of known nodes that are closest to the node we want to find.
  • We then recursively ping those nodes in the same way till we find our node.
  • Closeness is measured using the "distance" defined by the XOR.

Find Value

  • Similar to find node.
  • But in this case we get the list of IP's instead who have our torrent.
  • We search for the infohash - 1E69917FBAA2C767BCA463A96B5572785C6D8A12 - (Pride & Prejudice)

Routing Table - List of nodes with us.

  • Stored in K-buckets
  • Gives preference to older active nodes.

References

Kademlia

By cosmiclattes

Kademlia

  • 680
Loading comments...

More from cosmiclattes