ZiBaT
=> CoDS => exercise |
Peer to Peer |
Updated : 2018-03-13 |
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).
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)
Figure from Kurose & Ross |
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.
the Three elements
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.
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).
Implement the Interface. For storing the registration informations you could
create a 'Persistence' datastructure.
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.
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
}
}