View
217
Download
0
Category
Preview:
Citation preview
8/2/2019 Socket Programming Project 2
1/20
Socket Programming Project 2
Computer Networks
8/2/2019 Socket Programming Project 2
2/20
Goal
Simulating a peer-to-peer file-sharing network
via ad-hoc connections using TCP and UDP
sockets.
10% of the final grade.
Individual Assignment
Cheating = F Grade Hardcode nunki.usc.edu NOT
68.181.201.3.
8/2/2019 Socket Programming Project 2
3/20
Phases
The project has 3 major phases:
Registration of peers with the bootstrap server
Authentication of the content providers by the
bootstrap server
peer-to-peer content sharing.
8/2/2019 Socket Programming Project 2
4/20
Sockets
Order of execution
bootstrap_server
peers (all 4 of them concurrently)
content_provider
Phases 1 and 2
all communications are through UDP sockets.
Phase 3
all the communications are over TCP sockets.
8/2/2019 Socket Programming Project 2
5/20
Code Files
bootstrap_server
content_provider
You must create 2 concurrent content_providers
(by using fork() or a similar Unix system call).
peer
You must create 4 concurrent peers (by using
fork() or a similar Unix system call).
8/2/2019 Socket Programming Project 2
6/20
Identifier String Message Payload
Any of the following strings:peer1, peer2, peer3, peer4provider1, provider2bootstrap
The actual content of themessage such as, names,port numbers or IP addresses
Identifier String Message Payload
Any of the following strings:peer1, peer2, peer3, peer4provider1, provider2bootstrap
The actual content of themessage such as, names,port numbers or IP addresses
8/2/2019 Socket Programming Project 2
7/20
Bootstrap Server
UDP Port
Creates a text file directory.txt only ONCE.
Writes the information to it every time a newpeer registers itself with the bootstrap_server.
The bootstrap_server expects to hear
messages from all 4 peers before it receivesany messages from the content_providers.
8/2/2019 Socket Programming Project 2
8/20
Bootstrap Server
Bootstrap Server must retrieve some
information from the message(s) and store
them on a single line (for each peer) separated
by one space in the file directory.txt:
senders name , e.g. peer1
its TCP port number, e.g. 3451
its IP address, e.g. 128.125.61.23
group number, e.g. group1
8/2/2019 Socket Programming Project 2
9/20
Bootstrap Server
Authentication of the Content Provider
The bootstrap_server sends the filename
directory.txt as a message to that
content_provider.
Terminate bootstrap_server.
8/2/2019 Socket Programming Project 2
10/20
Peer1
Peer3
Peer4
Peer2
BOOTSTRAP_SERVER
UDP
SOCKET
UDP
SOCKET
UDP
SOCKET
UDP
SOCKET
8/2/2019 Socket Programming Project 2
11/20
Content Provider
Creates UDP socket and sends the username
and password to the bootstrap_server.
Receives filename.
Read the files in turn and find the peers that
subscribed to them.
Group# defines which peer subscribed to the
content_provider.
8/2/2019 Socket Programming Project 2
12/20
UDP
SOCKET
Content_Provider2
Peer1
Peer3
Peer4Peer2
BOOTSTRAP_SERVER
UDP
SOCKET
Content_Provider1
8/2/2019 Socket Programming Project 2
13/20
Content Provider
Identifies the peers.
Opens up a TCP connection
Sends the count of the number of peers andwelcome message to the peer.
Receives an ACK from the peer for every
message.
8/2/2019 Socket Programming Project 2
14/20
Content Provider
The content provider then sends the names
and TCP port numbers of the rest of its peer
subscribers to this peer subscriber in one long
message or several short messages.
Tears down the TCP connection
8/2/2019 Socket Programming Project 2
15/20
Peers
TCP/ UDP sockets
It then sends a message through the UDP
socket to the bootstrap_server. This message
contains its TCP port number, its IP address
and a randomly chosen group number (either
group1 or group2).
Checks whether the message is from the
Content Provider or a Peer.
8/2/2019 Socket Programming Project 2
16/20
Peer1
Peer3
Peer4
Peer2
BOOTSTRAP_SERVER
UDP
SOCKET
UDP
SOCKET
UDP
SOCKET
UDP
SOCKET
8/2/2019 Socket Programming Project 2
17/20
Peers
First peer has a number and a list of the
names and the TCP ports of the other peer
subscribers .
It first checks the number. If the number is
greater than 1, it decrements it by 1 and
establishes a new TCP connection through its
TCP socket to contact the first peer subscriberin this list.
8/2/2019 Socket Programming Project 2
18/20
Peers
Once the connection is accepted, it sends this
new number, the sentence welcome to group
# and the names and the TCP port numbers
of the rest of the subscribers in one longmessage or several short ones.
This goes on iteratively till the last peer is
reached.
8/2/2019 Socket Programming Project 2
19/20
TCPSOCKET
Content_Provider2
Peer1
Peer3
Peer4
Peer2
TCPSOCKET
Content_Provider1
Group1
Group2
TCPSOCKET
TCPSOCKET
STEP 1
STEP 2
STEP 3
8/2/2019 Socket Programming Project 2
20/20
Other Instructions
Assumptions
Requirements
Grading Criteria Cautionary Words
Etc
Recommended