ZiBaT => CoDS => exercise
Simple Napster
Peer to Peer

Updated : 2018-03-13

Exercise: PowerNap (Simple Napster)

The idea of this exercise is to better understand the Peer-2-Peer systems (ComputerNetwork chap 2 s.168-175  (and see wiki: peer2peer). 
This architecture differs from the 'normal' client-server (sse wiki: client-server).  

Introduction

Simple Napster is a Napster-look a like distribuered system. Napster was one of the first to use peer-to-peer for fil-sharing and was quickly widely known.

Simple Napster Constists of a centralized registry database, along with severals  'peer's  to comunicate the protocol was in 3 steps (refering to the figure below)

  1. When a new Peer would like to use the Simple Napster, It have to registry its own files in a centralized unit (a registration database),
    Then this centralized register have all knowledge of filenames and where to find them i.e. ip-adresses and port numbers. 
  2. When a Peer would like to downloade a file, the Peer have to search in the central register to get a list of ip-addresses together with the port number of Peer-servers who provide this file..
  3. Now the Peer have to pick one from the list and then set up  a connection for downloading the file.
figure of P2P communication
Figure from Kurose & Ross

Logical view of the system

Logical view  

Be aware of all three elements can be implemented on the same or on diffrent computers and the two Peer's could (but necessary) be implemented in the same program.

Desciption of the three elements  

the Three elements

Registry server

This is the centrale Registry Database, which contains pairs of filename and belonging addresses(ServerAddress a class with two properties IpAddress(string) and port(int)) of Peers.
You should consider a datastructure for holding a filename (a key) and a set of addresses (this could be a Dictionary-structure).
The Registry Server must be implemented as a Web-service which must be provided through an REST interface.

REST service interface

You should use these three web services:

You must create a WCF-project, where you can implement a REST web-service provider (see former web-service exercise)) including the three services, together with the class ServerAddress (having the porperties String IP-address , int port - plus a default constructor).

Implementation -- This require Knowledge of TCP-programmeing - comming later

Implement the Interface. For storing the registration informations you could create a 'Persistence' datastructure.

Peer Server role

At the server role you have two functionallity.

Registration / Deregistration

The registration and deregistration of files i.e. when it starts it register at the REST-service all files provided from this server (Hint: use the File class at some 'root-catalog' and then the method getFiles() to get access to all the files to be provided or registered -- see below). When closing the peer-server should clean up the registration by deregister all the files whereby the register server do not have old outdated informations.

Filesharing

The upload of a file to a peer-client, i.e. when a tcp-client conenct read the fisrt line which follow the format: 'GET filename', then send back the requested file.

Peer Client role

The get the wishes of a requested file any GUI e.g. Console, WPF but APP will require anothe way of TCP-Socket programming sp leave this out.
The ask the registry service through the GET REST-service and from the response create a socket connection to one of the peer-servers in the List, send the request ('GET filename') and wait for the file to be downloaded.

Code example of listing files

  

String path = @" << some location on the disk >> ";

if (Directory.Exists(path))
{
   foreach (string filename in Directory.GetFiles(path))
   {
      // do something
   }
}