Chord-Based Structured P2P platform

Source: Internet
Author: User
Chord-Based Structured P2P platform

The Chord protocol describes how to locate the storage location of a given value, how to add a new node to the system, and how to recover from the failure (or departure) of an existing node. The core of chord is to provide a fast distributed Hash function to map values to the nodes where they are stored. The hash function balances the load. When the nth node joins (leaves) the network, only the O (1/n) score is moved to a different place. Chord makes it unnecessary for each node to know all other nodes, improving the scalability of continuous hash. A chord node only needs a small part of route information about other nodes. Because the information is distributed. A node needs to resolve the hash function through communication with some nodes. In a stable state, in a system with N nodes. Each node only needs to maintain O (logn) information about other nodes, and parse all searches only need o (logn) information.
To build this platform, the node routing and positioning of the chord layer are realized. This article designs the following six types:
1. Doc class: This class mainly describes all operations on documents. Supports document generation, search, insertion, deletion, and movement.
2. event class: This class mainly describes the operations of events and event stacks. It initializes the event stack, generates, deletes, inserts, and returns new events.
3. node class: This class describes all operations on nodes in the network and the construction of continuous hash functions. Added, deleted, and printed new nodes, as well as the construction of hash tables and random return of nodes.
4. Finger class: This class mainly describes the operations related to the node finger table. It allows you to create, delete, update, print, and search for node founders and successor nodes.
5. Request class: This class mainly implements features such as creating new requests, inserting a pending list, request processing, printing the request list, and copying the finger table of the successor node.
6. Fun class: This class provides functions such as adding nodes, leaving nodes, and self-adjusting networks.
For more information about Algorithm Implementation in the above class, see the program section. In the following sections, the author describes a basic Chord protocol, including the construction of continuous hash functions, key Value search and node addition and exit.

3.3.1 continuous Hash Function
The continuous hash function assigns an M-bit identifier to each node and value. The IP address of the hash node gets the identifier of the node. Similarly, the hash keyword can get the value identifier. The length of the identifier m must be ensured that the two nodes or values are hashed to the same identifier.
The hash function assigns the value to the node according to the following rules: the identifier is allocated in an orderly manner on the Ring of the 2 ^ m identifier. Key value K is allocated to the first node where the id value in the identifier space is greater than or equal to K. This node is called the successor node of the key value K and is represented as successor (K), that is, the first accessed node on the chord ring starting from K clockwise. It is a chord ring with 10 nodes and 5 values, which is M = 6. When a node n joins or leaves the Network, some values are re-allocated to achieve adaptive network.

A chord ring with 10 nodes. In fact, for any hash function, there are always some values that are not scattered by the hash function, however, in practical applications, these potential so-called bad sets are unlikely to appear. The introduction of randomness in hash functions has greatly improved. Given a set of values, we can find a random hash function, so that these values can be separated as much as possible. For standard hash, any non-targeted value set can be analyzed. Here, we regard them as random.
The prototype of the function is as follows:
Void initnodehashtable ()
/* Initialize the node hash table */
Node * addnode (int id)
/* Add the specified node information to the hash table */
Void deletenode (node * n)
/* Delete the specified node information in the hash table */
Node * getnode (int id)
/* Return the node information in the hash table */
Int getrandomactivenodeid ()
/* Randomly generate a dynamic node ID */
Int getrandomnodeid ()
/* Return a random node */
3.3.2 key-value search
This section describes an effective chord search algorithm that can accurately maintain route information. As mentioned above, assume that the key/node pair identifier is M bit. Each node N has a route table with a maximum of M records, which is called the finger table. The I entry in the node n table contains at least the difference between the ID of N and the first node s of the 2 ^ I-1, in other words, S = successor (n + 2 ^ i-1 ), the I must satisfy 1 <I <m, and S is represented as N. figher [I]. Each item in the finger table contains the ID of the ending point in the chord network and the corresponding real IP address.

The finger table of node n8 uses the finger table to search for key values. The main algorithm is as follows: if the ID of the value to be searched falls between N and the successor node of N, the find_successor operation is completed, return the subsequent node. Otherwise, N searches for the node M closest to this ID in his finger table, and recursively calls the find_successor function until the precursor node of the value ID is found.

The specific algorithm for implementing this function is as follows:

Node find_successor (node N, Id ID)
{Node m;
If (ID> node. ID & id <= node. Successor. ID)
Return successor;
Else
{
M = closest_preceding_node (n, ID );
Return find_successor (M, ID );
}
Node closest_preceding_node (node N, Id ID)
/* Find the node closest to the specified ID in the finger table of N */
{
For (INT I = N; I> 0; I ++)
{
If (N. Finger [I]> N. ID & N. Finger [I] <ID)
Return N. Finger [I];
}
Return N;
}

Article: http://blog.csdn.net/nwpuyjz2001/archive/2007/04/08/1556755.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.