RMIT Logo

P2P Application Guide

Introduction Setup Peer Server Centralised DHT Presentation Architecture-Basic Architecture-Operation

DHT P2P System

Another function of this set of programs is to use what are known as Distributed Hash Tables (DHT) to allow peers to form a network without the help of a server (as was demonstrated in the previous guide). This DHT setup in particular is designed to allow file sharing between peers (peers may upload and download files from the network).

Chord Algorithm

The first peer in the system establishes the network as the only node in the network. Once a peer connects to an already established node in the network, it becomes part of the P2P network. As you can see, there is no real central node in the configuration. Once the network is established, nodes can be removed as needed and whenever a new peer wants to join the network, they can join from any node currently in the network. This is vitally different from the centralised model because there is no single point of entry into the network.

Once there are nodes in the network, there needs to be a DHT algorithm to determine where items should be added to and retrieved from in the network. This implementation uses the Chord algorithm.

In Chord, each node is assigned an ID in the network. This is generally comprised of a hash of the IP address and port. A modulus operator is then applied to the number to ensure that it is within the bounds of the predetermined network size. For example, a Chord network with an ID space of 256 will allow for IDs in the range of 0 - 255.

When thinking about each node's responsibility, it is easier to think of the network as a ring (even though the physical network topology is irrelevant in this case). Ring ID 0 is placed at the top of a circle with IDs increasing in a clockwise direction. A successor of a node is the one with the next largest ID (the one slightly in front of it) and the predecessor is the one with the next smallest ID (the one slightly behind it).

When determining which node is responsible for storing an item, we hash the name of the item to produce another ID that belongs in the ring. If the ID of the new item lies in between a given node and it's predecessor node, it is deemed responsible for storing that item. When other nodes want to access that item, they hash the file name (information they already know) and are able to locate it in the network.

In its most primitive form, Chord consists of nodes linearly passing messages in one direction through the ring until the desired node is contacted. However, this is costly in terms of both network traffic and time. However storing the contact information of the entire network inside each node is also not desirable as for larger Chord rings, this will take a linear toll on space.

This implementation fills what is known as a finger table that includes the contact information of only a handful of nodes. There are some technical details on exactly how these nodes are determined however, the general idea is to store successors of exponentially increasing distance. The effect of this is that we know a fair bit about successors close to us but only a little bit about successors far away.

When routing in a Chord ring, a node will look for the node with the closest ID in the finger table. As mentioned before, if the ID is close to us, the node we pick is a quite accurate decision but for IDs far away from us, it's more of a ballpark estimate. This request is forwarded from node to node until it reaches the intended destination. The aim is to get closer and closer to the correct node with each consecutive hop.

NOTE: If you are planning to run multiple instances of the P2P Peer to connect with each other, it is recommended that you make a copy of the entire ChatClient program (as many as are needed) and run it from there. The programs log all their network traffic in a file titled "log.txt" which can cause I/O issues when multiple instances of the program try to edit the same file.

Starting your own Chord Ring

  1. Run the P2P Peer application.
  2. Click the check box to run the program in DHT mode. If you have a Presentation Server running, then enter the IP address and port number for it, otherwise, leave the default values as is. Leave the option to join an existing DHT setup unchecked.
  3. Click the Login button. You should see the DHT interface appear.
  4. Starting a Chord Ring.

Joining an Existing Chord Ring

  1. Run the P2P Peer application.
  2. Click the check box to run the program in DHT mode. If you have a Presentation Server running, then enter the IP address and port number for it, otherwise, leave the default values as is. Check the option to join an existing DHT setup unchecked. You should then type in the address and port number of any DHT node that is already part of the ring that you are attempting to join.
  3. Click the Login button. You should see the DHT interface appear.
  4. Joining a Chord Ring.

Uploading files to the Chord Ring

  1. Once you have successfully logged into a DHT Ring, ensure that you are switched to the Upload tab.
  2. Click on the Select File button. A file choosing interface will appear and allow you to select a file to upload. Once you have navigated to the file you wish to upload, click Open. To complete the upload, click the Upload button or click the Select File button to change your selection.
  3. Choosing a file to upload.

  4. The node that you sent the initial Upload request to should be highlighted in the Finger Table. Once the correct node has replied back and transfer has occurred, a dialogue will appear on screen to notify you that your file has been successfully uploaded to the DHT ring.
  5. File uploaded.

Downloading files from the Chord Ring

  1. Once you have successfully logged into a DHT Ring, ensure that you are switched to the Download tab.
  2. Type the name of the file you wish to download and click the Download button.
  3. Choosing a file to download.

  4. The node that you sent the initial Download request to should be highlighted in the Finger Table. Provided that the file has been uploaded to the DHT ring, the correct node should reply back and transfer should occur. The file will be stored in the "src" folder of the program (alongside any other files that are uploaded to this node).
  5. File downloaded.