=> Technique=> exercise
Updated : 2020-10-19
The idea of this exercise is to better understand the Peer-2-Peer systems (Computer Network
s.168-175 (and see wiki: peer2peer).
This architecture differs from the 'normal' client-server (see wiki: client-server).
Simple P2P is distributed system.
Simple P2P consists of a centralized registry database, along with several 'peer's. They are communicating through a protocol in three steps (referring to the figure below):
Figure from Kurose & Ross
Be aware of all three elements can be implemented on the same or on different computers and the two Peers could (but not necessary) be implemented in the same program.
The Three elements
This is the central Registry Database, which contains pairs of filename and
belonging addresses ( Make a class 'FileEndPoint' with an ip-address as a string and a port-number ) of Peers.
You should consider a data structure 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 REST-service.
You should use these three web services:
Implement the Interface. For storing the registration information, you could
hold the register as a static collection OR as a database of your own taste.
At the server role, you have two functionality.
Registration / Deregistration
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 information.
The upload of a file to a peer-client, i.e. when a tcp-client connect read the first 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, (or WPF - you have not learned how to make tcp-socket call form App's i.e. MVVM- this is rather tricky).
Code example of listing files
String path = @" << some location on the disk >> ";
foreach (string filename in Directory.GetFiles(path))
// do something
See github: https://github.com/rf19da2c1-1c/DemoAfDictionary
See appendix A en exercise http://pele-easj.dk/2020e-tek/exercises/socket/HttpServerChallenge.pdf