Home Page > > Details

Help With SE 3314B Assignment,Help With Java Programming Assignment, Python,c/c++ Course AssignmentDebug Matlab Programming| Statistics,

Abdelkader Ouda page 1 Winter 2020
WESTERN UNIVERSITY - CANADA
FACULTY OF ENGINEERING
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING
SE 3314B – NETWORK NETWORKS APPLICATIONS
Assignment 2: A Peer Node
Due Date: March 9, 2020
This assignment is to be done individually. Cheating is prohibited in this assignment, that is not to show
your code to any other student, do not look at any other student's code, and do not put your code in any
public domain. However, getting help is easy and available, just ask the instructor or the TAs. At the same
time, you are encouraged to discuss your problems (if any) with other students in general terms but the
actual program design and code must be your own.
Please note that the consequences of cheating are much, much worse than getting a low mark for that
particular item of work. The very best case is that you get a zero for the whole thing. Keep in mind that
turning in your own work would have at least gotten you a few marks, better than a zero.
1. Objectives
The majority of socket programs, including GetImage/imageDB of assignment 1, follows the client-server
paradigm, where a server waits on a well-known port for clients' connections. In this assignment, you'll explore
peer-to-peer programming. You will be re-using most of the functions you built in assignment1 to create a
new program for the peer. If you didn't manage to get these functions to work in assignment1, no problem
you still have the chance to make your new code works in this assignment. A peer is basically both a server
and a client. It accepts connections from other peers and also connects to one or more peers.
2. Introduction
The peer program takes three optional arguments on the command line:
> node peer [-p : -n -v ]
The -p option tells the peer program which peer to connect to initially. If this option is not provided, the
peer starts as a server listening on a random, ephemeral port. The -n option allows the user to set a peer's
maximum peering relationships is equal to 2. The -v option works
similarly to the same option for GetImage in assignment1.
To bootstrap the peer-to-peer (p2p) network, we first start a peer by itself. Every time a peer runs, it prints
its IP address and port number it is listening on. When a peer is run with the IPaddress:port of another peer
as its command line argument, the new peer tries to join the provided peer in the p2p network by creating a
socket and connecting to the peer.
Abdelkader Ouda page 2 Winter 2020
A peer that receives a join request will accept the peer if and only if its peer table is not full. Whether a
join request is accepted or not, the peer sends back to the requesting peer the IPaddress:port of a peer that is
saved in its peer table (if the table is not empty). This will help the newly joined peer find more peers to join.
Take a step back and look at the big picture, see how code implemented in two different programs in
assignment1 are now residing in the same program and how this program is serving the role of both a client
and a server. In this assignment, a custom Peer-to-Peer Transport Protocol (cPTP) for peer communication
will be built and used. The subsequent sections describe the structure and mechanism of this protocol.
The main goal of this assignment is to gain an early experience with protocol design as you are designing
a simple peer-to-peer join protocol, with redirection.
3. Task 1: Server Side
Your first task is to implement the server side of the peer program. If peer is run without any option on
the command line, reuse your imageDB server code to announce for its IPaddress and port number and be
ready to accept other peers join requests.
If a new peer is trying to connect to this peer and this peer's peering table is
not full, handleClientJoining(sock) should accept the connection and then send back a message packet (see
Figure 1) with field set to 1, (1 means Welcome). The new peer is then
stored in the peer table. On the other hand, if the peer table is full, handleClientJoining(sock) is invoked again
to receive the request but it sends back a redirect message packet -
direct). All times it fills in the fields of the message: V must be set to 3314 (only in this assignment). The
holds the number of peers attached to the cPTP message packet.
The figure below shows the cPTP message packet structure.
0
0 1 2 3 4 5 6 7 8 9
1
0 1 2 3 4 5 6 7 8 9
2
0 1 2 3 4 5 6 7 8 9
3
0 1
V = 3314 Message Type
Sender
Number of peers
Reserved Peer port number
Peer IPv4 address
Figure 1: The cPTP message packet format
This structure stores the cPTP message type is
one byte, it is Welcome Re- . The sender ID is 4 bytes, the
bytes, holds the number of peers included in the message pac
assignment we allow each peer a maximum of 2 partners). Followed by 2 reserved bytes, not used in this
4 bytes. Although each peer may have up to 2 partners, we store the IPaddress and port number of only one
joined peer.
4. Task 2: Client Side
Only if
Number of
peers is not
zero
Abdelkader Ouda page 3 Winter 2020
If a peer is run with the -p option, the user must provide a known peer IP address and port number to
connect to, with the port number separated from the peer IP address by a colon. Keep in mind that, a peer
joining a p2p network simply connects to another peer, without sending any messages, so using a different
version number with the -v command line option will not affect the join process.
Note that Node.js would have assigned a random, ephemeral source port to the connected socket. Find
out the assigned ephemeral source port number and store it along with the IPv4 address of the current host.
Note also that, the program will be managing for activities on both the socket connected to the known peer
and the socket on which you're listening for connection from other peers.
The peer program checks for activity on each connected peer's socket. If there's an incoming packet, it
receives the message and examine it packet. It first checks the version number of the received packet. If it is
not , the message will be ignored. Assuming the version number checks out, the receipt of a packet
carrying another peer causes the third peer's address and port number to be printed out. If the received packet
is of type 2, it printed out that the join has been declined (redirected) and exits the program. The user can
then manually try to connect to the third peer returned in the redirect packet by running the peer program
again.
You're not required to handle peer leaving the p2p network: once a peer departs, its partner peer is not
required to clean up its peer table and be ready to accept another peer. You can assume that a peer is only torn
down when the whole p2p network is being torn down. It is required, however, that when a peer leaves, its
partner does not crash.
5. Sample execution run
Below is a running scenario as an example to show the execution of the program and to summarize the
requirements of this assignment. After finish building the program peer, save it in four different working
folders, p1, p2, p3, and p4. Open four command line windows, one for each of these created folders.
1. On the first window, run peer program without any command line argument:
p1> node peer
It should print to screen (with a different port number, depicted in bold here), not that the folder name
information, the program should recognize it automatically:
This peer address is 127.0.0.1: 43945 located at p1
2. On the second window, run peer with the following command line argument (replacing the port
number with the one printed out on the first item above:
p2> node peer -p 127.0.0.1:43945
It should print to screen (with different port numbers and time stamp):
Connected to peer p1:43945 at timestamp: 457
This peer address is 127.0.0.1:56535 located at p2
Abdelkader Ouda page 4 Winter 2020
Received ack from p1:43945
Meanwhile, on the first window, you should see the following additional line printed to screen:
This peer address is 127.0.0.1: 43945 located at p1
Connected from peer 127.0.0.1:56535
3. On the third window, run peer with the following command line argument (replacing the port
number with the one from the first item above)
p3> node peer -p 127.0.0.1:43945
It should print to screen (with different port numbers and time stamp):
Connected to peer p1:43945 at timestamp: 492
This peer address is 127.0.0.1:48141 located at p3
Received ack from p1:43945
which is peered with: 127.0.0.1:56535
Meanwhile, on the first window, you should see the following additional line printed to screen:
This peer address is 127.0.0.1: 43945 located at p1
Connected from peer 127.0.0.1:56535
Connected from peer 127.0.0.1:48141
4. On the fourth window, run peer with the following command line argument (replacing the port
number with the one from the first item above)
P4> node peer -p 127.0.0.1:43945
It should print to screen (with different port numbers and time stamp):
Connected to peer p1:43945 at timestamp: 712
This peer address is 127.0.0.1:40231 located at p4
Received ack from p1:43945
which is peered with: 127.0.0.1:56535
Abdelkader Ouda page 5 Winter 2020
Join redirected, try to connect to the peer above.
Meanwhile, on the first window, you should see the following additional line printed to screen:
This peer address is 127.0.0.1: 43945 located at p1
Connected from peer 127.0.0.1:56535
Connected from peer 127.0.0.1:48141
Peer table full: 127.0.0.1:40231 redirected
5. Staying on the fourth window, run peer again with the following command line argument (replacing
the port number with the one from the fourth step item above)
P4> node peer -p 127.0.0.1:56535
It should print to screen (with different port numbers):
Connected to peer p2:56535 at timestamp: 1090
This peer address is 127.0.0.1:50095 located at p4
Received ack from p2:56535
which is peered with: 127.0.0.1:43945
Meanwhile, on the second window on p2, you should see the following additional line printed to screen:
Connected to peer 127.0.0.1:43945 at timestamp: 457
This peer address is 127.0.0.1:56535 located at p2
Received ack from 127.0.0.1:43945
Connected from peer 127.0.0.1:50095
That ends our sample execution/test scenario and you can quit all four peers.
The above is a very simple test case to check that your peers are communicating with each other. You
should further test your p2p network with other test cases of your own. Recall that a peer is not required to
accept another peer if its partner departs.
Hand In
Submit the final version of your source code (Fully commented and formatted) through OWL by the due
date mentioned above. This should include one compressed achieve file (zip file) having all JS files for the peer
program including the package.json file and name it yourUWOID-SE3314b-assignment2.zip.

Contact Us - Email:99515681@qq.com    WeChat:codinghelp
Programming Assignment Help!