MP2: P2P File Server
description
Transcript of MP2: P2P File Server
1
MP2: P2P File Server
Hoang Nguyen
2
Outline
• Basic network concepts revisited – Client/Server, Peer-to-peer– IP address, TCP/UDP
• Basic network programming revisited– Server socket, Client Socket– Send/Receive data– Data Serialization: converting objects to bits
• Network Design: Control/Data plane– MP explanation– Implementation suggestions/hints
3
Basic network concepts revisited
4
Basic network concepts (1)
• Client/server– Servers = machines providing network services– Clients = machines connecting to servers and
use network services– Example: FTP server/FTP client
5
Basic network concepts (2)
• A server provides a network service through a “port”– Has to “bind” to a particular port
• Clients requests for a specific service at a server via a pre-defined port
• E.g.: Port 21: FTP control, Port 20: FTP data• Port: (0..65535)
– 0..1023: well-known ports, requiring admin right to bind– 1024..49151: registered ports (for propriety apps)– The rest: dynamic/private ports
6
Basic network concepts (3)
• What is a Protocol?– A convention standard that controls or enables the
connection, communication and data transfer between two parties.
• Example: – “Protocol” to apply to UIUC– “Admission protocol”
• In our MP, we will have to define our own “protocols” and use some existing network protocols
7
Basic network concepts (3)
• IP address: a tuple of four 8-bit integers– E.g.: 128.174.252.84
• Host name: name representative of IP– E.g.: www.cs.uiuc.edu
• TCP: Transmission Control Protocol– Reliable, ordered, heavy-weight, streaming
(connection-oriented/stateful)– Suitable for any applications requiring reliability such as FTP
• UDP: User Datagram Protocol – Unreliable, not-ordered, light-weight, datagrams
(connectionless/stateless)– Suitable for any protocols that can tolerate reasonable losses such as
video/audio/real-time streaming
8
Basic network programming revisited
9
Basic network programming revisited
• Highly recommended tutorial– Beej's Guide to Network Programming
Using Internet Sockets
• http://beej.us/guide/bgnet/• Make sure you go through until
Section 7 (esp. Section 6 and Section 7.4)
10
Network Socket
• A socket is a one end of a two-way communications link between two programs running on the network– In UNIX, socket is just a file descriptor on which
send() and recv() can be used.
• As mentioned above, a socket can be – SOCK_STREAM: streaming, reliable, connection-
oriented, ordered– SOCK_DGRAM: datagram, unreliable, connection-
less, not-ordered
11
How to create a server socket?
• Pseudo-code & examplefill out address informationsock_fd = create/set socket optionbind to the portlisten for incoming connectionswhile (forever || not crash)
client_fd = accept a client socketcreate a process/thread to
communicate with the client
… // ready to send/recv
12
Comments
• sock_fd: Server socket keeps listening for incoming connections– If the accept() function is not invoked, no client
connection can be accepted
– If the number of pending connections exceeds the backlog, any incoming requests are refused.
• client_fd: socket to communicate with the client – Think of it like a file descriptor.
13
How to create a client socket?
• Pseudo-code & examplefill out address information (hostname, port)sock_fd = connect to the server
… // ready to send/recv
14
Sending/Receiving data
• no_send = send(sock_fd, data, len, flag)
• no_recv = recv(sock_fd, buf, max_len, flag)
• Example
15
Data serialization
• Converting data objects into bits• Three ways:
1) Use readable string description: e.g. “text ‘this is a text’, int 1, float 1.1234”
2) Sending raw data, passing it send() (dangerous, un-portable)double d = 3490.15926535;send(s, &d, sizeof d, 0);
3) Encode the data into a portable binary form. The receiver encodes it. (see pack(), unpack() in the tutorial)
16
Control/Data Plane
• Control plane: a set of protocols/software to bootstrap/setup and control the communication
• Data plane: a set of protocols/software to transmit data
• E.g.: FTP has two ports for control channel (21) and data channel (20)
17
In our MP…
Stream (Play, FF, Rewind) A/V Files
Insert (Upload) A/V Files
Setup UDP Connection between Client and a Specific
Peer-Server
Setup TCP Connection between Client and a Specific
Peer-Server
UDP/IP Protocol Stack
TCP/IP Protocol Stack
Insert/Delete/Search Stream Request Control Protocols and Services
Dispatcher setup Peer-Server addition/Connection setup between
Dispatcher and Peer-Servers for Control Purposes
TCP/IP Protocol Stack
Data Plane Functions Control Plane Functions
18
An example implementation of control plane
for our MP1) Dispatcher setup peer-to-peer
connections
2) Handling a client request
19
Entities (1)
• A server has– a server socket listening on port 7000 for
dispatcher setup connection request– a client socket to communicate with dispatcher
obtained once accepting dispatcher setup connection request
– an on-demand server socket listening on a on-demand port for the client to send/recv data
20
Entities (2)
• A dispatcher has– several client sockets for connections to each
server– a server socket listening on port 8000 for
clients to send/recv control messages
• A client has – A client socket to send/recv control messages
to the dispatcher– A client socket to send/recv data to the server
21
Dispatcher setup connection
Socket on port 7000
Setup connection request
socket
Socket on port 8000
socketSetup connection request
Bi-directional
Bi-directional
cairo
cairosanjose
22
Handling a client request
socket
socket
Bi-directional
Bi-directional
Socket on port 8000
cairo
cairosanjose
1. request2. request
3. response
4. response