peer-to-peer
applications Web stuff
paradigm socket API
HTTP, DNS, Web searching
1
Client-server architecture Pure P2P architecture
server:
no always-on server
always-on host
arbitrary end systems
permanent IP address directly communicate peer-peer
server farms for peers are intermittently
scaling connected and change IP
clients: addresses
client/server communicate with server
may be intermittently
connected
may have dynamic IP Highly scalable but
addresses difficult to manage
do not communicate
directly with each other
2: Application Layer 5 2: Application Layer 6
2
Sockets Addressing processes
to receive messages, identifier includes both
process sends/receives
host or host or
server server process must have IP address and port
messages to/from its identifier numbers associated with
socket controlled by
host device has unique process on host.
app developer
socket analogous to door process process
32-bit IP address Example port numbers:
sending process shoves socket socket
Q: does IP address of HTTP server: 80
message out door
host on which process Mail server: 25
TCP with TCP with
Internet
buffers,
sending process relies on buffers,
runs suffice for
transport infrastructure
variables variables to send HTTP message
on other side of door which identifying the to gaia.cs.umass.edu web
brings message to socket controlled process? server:
by OS
at receiving process A: No, many IP address: 128.119.245.12
API: (1) choice of transport protocol; (2) ability to fix processes can be Port number: 80
a few parameters (lots more on this later) running on same host more shortly…
2: Application Layer 9 2: Application Layer 10
3
Transport service requirements of common apps Internet transport protocols services
Application Data loss Bandwidth Time Sensitive TCP service: UDP service:
connection-oriented: setup unreliable data transfer
file transfer no loss elastic no required between client and between sending and
e-mail no loss elastic no server processes receiving process
Web documents no loss elastic no reliable transport between does not provide:
real-time audio/video loss-tolerant audio: 5kbps-1Mbps yes, 100’s msec sending and receiving process connection setup,
video:10kbps-5Mbps flow control: sender won’t reliability, flow control,
stored audio/video loss-tolerant same as above yes, few secs
overwhelm receiver congestion control, timing,
interactive games loss-tolerant few kbps up yes, 100’s msec throughput guarantee, or
congestion control: throttle
instant messaging no loss elastic yes and no security
sender when network
overloaded
does not provide: timing, Q: why bother? Why is
minimum throughput there a UDP?
guarantees, security
2: Application Layer 13 2: Application Layer 14
Web stuff
HTTP, DNS, Web searching
4
FTP: the file transfer protocol FTP: separate control, data connections
TCP control connection
FTP client contacts FTP port 21
FTP file transfer server at port 21, specifying
FTP FTP
user
interface
client server TCP as transport protocol
TCP data connection
user Client obtains authorization FTP port 20 FTP
local file remote file
at host over control connection client server
system system
Client browses remote
Server opens another TCP
transfer file to/from remote host
directory by sending
commands over control data connection to transfer
client/server model another file.
client: side that initiates transfer (either to/from connection.
remote) Control connection: “out of
When server receives file
server: remote host transfer command, server band”
ftp: RFC 959 opens 2nd TCP connection (for FTP server maintains “state”:
ftp server file) to client current directory, earlier
Control connection: port 21 After transferring one file, authentication
Data connection: port 20
server closes data
2: Application Layer 17 connection. 2: Application Layer 18
5
Electronic Mail outgoing
message queue Electronic Mail: mail servers
user mailbox
user user
Three major components: agent Mail Servers agent
user agents mail mailbox contains incoming mail
user user
mail servers
server
agent messages for user server
agent
simple mail transfer SMTP message queue of outgoing
mail SMTP
protocol: SMTP (to be sent) mail messages mail
server user server user
SMTP protocol between mail
SMTP agent
SMTP agent
User Agent servers to send email
a.k.a. “mail reader” SMTP messages SMTP
user user
composing, editing, reading mail client: sending mail mail
server agent agent
mail messages server server
Electronic Mail: SMTP [RFC 2821] Scenario: Alice sends message to Bob
1) Alice uses UA to compose 4) SMTP client sends Alice’s
message and “to” message over the TCP
uses TCP to reliably transfer email message from client
bob@someschool.edu connection
to server, port 25
2) Alice’s UA sends message 5) Bob’s mail server places the
direct transfer: sending server to receiving server
to her mail server; message message in Bob’s mailbox
three phases of transfer
placed in message queue 6) Bob invokes his user agent
handshaking (greeting) 3) Client side of SMTP opens to read message
transfer of messages TCP connection with Bob’s
closure mail server
command/response interaction
commands: ASCII text
response: status code and phrase 1
mail mail
server user
user
messages must be in 7-bit ASCII agent 2
server
agent
3 4 6
5
6
Sample SMTP interaction Try SMTP interaction for yourself:
S: 220 hamburger.edu
C: HELO crepes.fr telnet servername 25
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM: <alice@crepes.fr> see 220 reply from server
S: 250 alice@crepes.fr... Sender ok enter HELO, MAIL FROM, RCPT TO, DATA, QUIT
commands
C: RCPT TO: <bob@hamburger.edu>
S: 250 bob@hamburger.edu ... Recipient ok
C: DATA above lets you send email without using email client
S: 354 Enter mail, end with "." on a line by itself (reader)
C: Do you like ketchup?
C: How about pickles?
C: .
S: 250 Message accepted for delivery
C: QUIT
S: 221 hamburger.edu closing connection
7
Message format: multimedia extensions Mail access protocols
MIME: multimedia mail extension, RFC 2045, 2056 SMTP SMTP access user
additional lines in msg header declare MIME content user
agent protocol agent
type
sender’s mail receiver’s mail
From: alice@crepes.fr server server
MIME version
SMTP: delivery/storage to receiver’s server
To: bob@hamburger.edu
Subject: Picture of yummy crepe.
method used MIME-Version: 1.0 Mail access protocol: retrieval from server
to encode data Content-Transfer-Encoding: base64 POP: Post Office Protocol [RFC 1939]
• authorization (agent <-->server) and download
Content-Type: image/jpeg
multimedia data
type, subtype, base64 encoded data ..... IMAP: Internet Mail Access Protocol [RFC 1730]
parameter declaration ......................... • more features (more complex)
• manipulation of stored msgs on server
......base64 encoded data
encoded data
HTTP: Hotmail , Yahoo! Mail, etc.
8
P2P file sharing
Chapter2: Application layer
Example Alice chooses one of
the peers, Bob.
Principles of network applications Alice runs P2P client
application on her File is copied from
Architecture: client-server or P2P
notebook computer Bob’s PC to Alice’s
Services that an application needs notebook: HTTP
Intermittently
important application-level protocols connects to Internet; While Alice downloads,
P2P gets new IP address other users uploading
for each connection from Alice.
programming network applications
Asks for “Primal Fear” Alice’s peer is both a
socket API
Web client and a
Application displays
Web stuff transient Web server.
other peers that have
HTTP, DNS, Web searching copy of Primal Fear. All peers are servers =
highly scalable!
2: Application Layer 33 2: Application Layer 34
9
File distribution time: server-client File distribution time: P2P
Server Server
server sequentially F u1 d1 u2
server must send one F u1 d1 u2
sends N copies: us d2 copy: F/us time us d2
Time to distribute F
to N clients using = dcs = max { NF/us, F/min(di) }
i
client/server approach
dP2P = max { F/us, F/min(di) , NF/(us + Σui) }
increases linearly in N i
(for large N) 2: Application Layer 37 2: Application Layer 38
chunks of a file
3
Client-Server
2.5
1.5
obtain list
of peers
1
trading
0.5
chunks
0
0 5 10 15 20 25 30 35
peer
N
2: Application Layer 39 2: Application Layer 40
10
BitTorrent (2) Sending Chunks: tit-for-tat
BitTorrent (1) Pulling Chunks Alice sends chunks to four
neighbors currently
at any given time,
file divided into 256KB chunks. sending her chunks at the
different peers have highest rate
peer joining torrent: different subsets of
file chunks re-evaluate top 4 every
has no chunks, but will accumulate them over time
10 secs
registers with tracker to get list of peers, periodically, a peer
every 30 secs: randomly
connects to subset of peers (“neighbors”) (Alice) asks each
neighbor for list of select another peer,
while downloading, peer uploads chunks to other starts sending chunks
peers. chunks that they have.
newly chosen peer may
peers may come and go Alice sends requests
for her missing chunks join top 4
once peer has entire file, it may (selfishly) leave or “optimistically unchoke”
(altruistically) remain rarest first
11
P2P: centralized index P2P: problems with centralized directory
Bob
original “Napster” design centralized
single point of failure file transfer is
1) when peer connects, it directory server
1 performance bottleneck decentralized, but
informs central server: peers copyright infringement:
locating content is
IP address 1
“target” of lawsuit is highly centralized
content obvious
1 3
2) Alice queries for “Hey
2
Jude” 1
Alice
12
Gnutella: Peer joining Hierarchical Overlay
1. joining peer Alice must find another peer in between centralized
Gnutella network: use list of candidate peers index, query flooding
2. Alice sequentially attempts TCP connections with approaches
candidate peers until connection setup with Bob each peer is either a
3. Flooding: Alice sends Ping message to Bob; Bob super node or assigned to
forwards Ping message to his overlay neighbors a super node
(who then forward to their neighbors….)
TCP connection between
peers receiving Ping message respond to Alice peer and its super node.
with Pong message TCP connections between
4. Alice receives many Pong messages, and can then some pairs of super nodes. ordinary peer
setup additional TCP connections Super node tracks content group-leader peer
Peer leaving: see homework problem! (p20) in its children neighoring relationships
in overlay network
13
Socket programming Socket-programming using TCP
Goal: learn how to build client/server application that Socket: a door between application process and end-
communicate using sockets end-transport protocol (UCP or TCP)
Socket API socket TCP service: reliable transfer of bytes from one
introduced in BSD4.1 UNIX, process to another
a host-local,
1981 application-created,
explicitly created, used, OS-controlled interface controlled by
released by apps controlled by
(a “door”) into which process process application
application developer
client/server paradigm application process can developer socket
socket
two types of transport both send and TCP with controlled by
controlled by TCP with
service via socket API: receive messages to/from operating buffers, buffers, operating
internet variables system
another application system variables
unreliable datagram
process
reliable, byte stream- host or
host or
oriented server
server
2: Application Layer 53 2: Application Layer 54
14
Stream jargon Socket programming with TCP
keyboard monitor
inFromUser
or out of a process. input
stream
standard input (inFromUser
An input stream is Client stream) , sends to server via
attached to some input Process socket (outToServer
process
source for the process, stream)
e.g., keyboard or socket. 2) server reads line from socket
An output stream is 3) server converts line to
attached to an output uppercase, sends back to
inFromServer
outToServer
source, e.g., monitor or client
output input
stream stream
15
Example: Java server (TCP) Example: Java server (TCP), cont
import java.io.*;
import java.net.*;
Create output
class TCPServer { stream, attached DataOutputStream outToClient =
to socket new DataOutputStream(connectionSocket.getOutputStream());
public static void main(String argv[]) throws Exception
{ Read in line
String clientSentence;
from socket clientSentence = inFromClient.readLine();
Create String capitalizedSentence;
welcoming socket capitalizedSentence = clientSentence.toUpperCase() + '\n';
ServerSocket welcomeSocket = new ServerSocket(6789);
at port 6789 Write out line
outToClient.writeBytes(capitalizedSentence);
Wait, on welcoming while(true) { to socket
}
socket for contact Socket connectionSocket = welcomeSocket.accept(); }
by client } End of while loop,
BufferedReader inFromClient = loop back and wait for
Create input
stream, attached
new BufferedReader(new another client connection
InputStreamReader(connectionSocket.getInputStream()));
to socket
destination to each packet UDP provides unreliable transfer Create, address (hostid, port=x,
of groups of bytes (“datagrams”) send datagram request
server must extract IP using clientSocket
between client and server read request from
address, port of sender serverSocket
16
Example: Java client (UDP) Example: Java client (UDP)
keyboard monitor
import java.io.*;
import java.net.*;
inFromUser
input
stream
class UDPClient {
Client
Process public static void main(String args[]) throws Exception
Input: receives
process Create
{
packet (recall
thatTCP received input stream BufferedReader inFromUser =
Output: sends
packet (recall “byte stream”) Create
new BufferedReader(new InputStreamReader(System.in));
receivePacket
sendPacket
that TCP sent UDP UDP
client socket DatagramSocket clientSocket = new DatagramSocket();
packet packet
“byte stream”) Translate
InetAddress IPAddress = InetAddress.getByName("hostname");
client UDP hostname to IP
clientSocket
socket UDP
address using DNS byte[] sendData = new byte[1024];
socket
byte[] receiveData = new byte[1024];
to network from network
17
Example: Java server (UDP), cont
String sentence = new String(receivePacket.getData());
Get IP addr
InetAddress IPAddress = receivePacket.getAddress();
port #, of
sender int port = receivePacket.getPort();
sendData = capitalizedSentence.getBytes();
Create datagram
DatagramPacket sendPacket =
to send to client new DatagramPacket(sendData, sendData.length, IPAddress,
port);
Write out
datagram serverSocket.send(sendPacket);
to socket }
}
} End of while loop,
loop back and wait for
another datagram
2: Application Layer 69
18