Chord protocol. Distribuited Hash Table (DHT). Peer to peer. (P2P)

4.9k views Asked by At

I'm trying to implement this protocol: http://en.wikipedia.org/wiki/Chord_(peer-to-peer)

What i understood from it is that each node that joins the "circle" is placed in a random place inside the circle, depending on it's hashed IP+port value. But my question is ... how can i obtain an integer value (index) for each node? How to i assign the unique hash value of the ip+port to a unique index number...Some functions check to see if for example an id is inside an interval (e.g. id>n & id<=successor), so it seems i need a unique int for each node, i can't just use the hash value. Any suggestions?

2

There are 2 answers

2
Steve On BEST ANSWER

You can download the Chord implementation from the creators (It's free)

http://pdos.csail.mit.edu/chord/#downloads

(Sorry thought you just wanted a working DHT!)

[edit] I believe the hash based approach is the best way if you want to avoid naming collisions. However, if you need to use INT's you could introduce a slight overhead by having your DHT manage naming collisions and dealing with it in some form. Then to ensure you have an int representation you could just multiple the final two addresses spaces of the IP address. e.g ip = 192.168.2.14 the ID would be 28.

This obviously makes your system less robust. Any reason you can't use hashes?

[/edit]

0
LeslieK On

Can't you just convert your hashed value to an int?

For example, in python, after you take the sha1 hash of (ip-address + port), you get 20 bytes (160 bits). (ip-address is a string and port is an int)

Convert the bytes to an int. You get a number between 0 and 2**160 - 1. For example,

Let data_in_bytes be the hash value.

(int).from_bytes(data_in_bytes, byteorder='big') is the integer value.

One way of measuring distance between 2 hash values is to use the XOR operator. int1 ^ int2 is the distance between 2 nodes on the circle.