DHT principle
DHT is the core routing algorithm of the peer-network (structured-peer), mainly using the consistent hash, the nodes and resources are represented as a hash value, put into this large hash ring, each node is responsible for routing resources close to it.
I. Important CONCEPTS:
1.node
In charge of peer-to-peer routing information, the network is responsible for
2.peer
Responsible for managing resources, generating seed files, publishing resource information
3.nodeid
The unique identifier of the node, which is a 160bit hash value
4.infohash
The unique identifier of the resource is also a 160bit hash value, which uses the same algorithm as the Nodeid
5. Distance
The distance is the value of two hash values for XOR (XOR) operation, the smaller the value, the closer the distance
Distance between nodes and resources: Nodeid XOR Infohash
Distance between two nodes: Nodeid1 xor Nodeid2
6. Seed Files
A profile of a resource that includes the Infohash (160bit) of the resource, the machine (nodeId IP port) of the resource, and the list of n machines (nodeId IP port) closest to the machine where the resource resides
Two. Typical Scenario Description:
1. New node joins the network
The newly installed peer-to client is an isolated node that has no connection to other nodes, and how to join a peer-to network? Need to have a seed file that has multiple node information in the peer network,
Based on the list of nodes in the seed file, connect to the peer-to network and get routing information to get the list of nodes closest to this new node
2. Publishing Resources
A. Infohash of generating resources
B. Find and Infohash the nearest n nodes, broadcast the new resource information to the N node and tell them that I have some resources
The-----node generates resources, but its routing information is not on this node (nor on the nearest m node of the node), but on the nearest N node to the resource Infohash
3. Find a resource and download
A. Finding n node closest to a resource (using Nodeid xor infohash to calculate distance)
B. Send the resource query information to these node, and if you have the details of this resource, return it to the client, otherwise return the node list closer to the resource to the client
C. Until the resource provider information is queried, if no information is found and no closer node is available, it means that the resource does not have a provider
D. After locating node information (nodeid,ip,port), request resources from this node
DHT Algorithm principle Description