Client-Server Programming
Spring Semester, 2005 Gnutella |
||
---|---|---|
© 2005 All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated April 5, 2005 |
CS 580 Client-Server Programming
Spring Semester, 2005
Doc 15 Gnutella
Contents
The Gnutella Protocol Specification v0.4, Document Revision 1.2, http://www9.limewire.com/developer/gnutella_protocol_0.4.pdf
Copyright ©, All rights reserved. 2005 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA. OpenContent ( http://www.opencontent.org/opl.shtml ) license defines the copyright on this document.
CS580 Spring 2005 | Doc 15, Gnutella Slide # 2 |
Peer-to-peer
Gnutella program is both a server and a client: servent
No central server
Protocol does not discuss how one knows about other servents
CS580 Spring 2005 | Doc 15, Gnutella Slide # 3 |
Basic Idea
Servent connects to 1 or more remote servents
Can
Ping the network
Send a request for a file to see who has it
To get a file from a servent
Connect to the servent directly with http request
CS580 Spring 2005 | Doc 15, Gnutella Slide # 4 |
Basic Protocol
Connect to another servent with
GNUTELLA CONNECT/<protocol version string>\n\n
Where <protocol version string> is 0.4
If the remote servent accepts the connection it must respond with
GNUTELLA OK\n\n
Both servents then can then send messages
CS580 Spring 2005 | Doc 15, Gnutella Slide # 5 |
Ping – who is on the network
Pong – response to a ping
Query – search the network for data
QueryHit – response to query
Push – Used to allow servents work behind firewall
Each Request/Response starts with a header
CS580 Spring 2005 | Doc 15, Gnutella Slide # 6 |
Desciptor ID |
Payload Descriptor |
TTL |
Hops |
Payload Length |
|||
Byte offset |
0 |
15 |
16 |
17 |
18 |
19 |
22 |
Descriptor ID
16 byte string
Uniquely identifies Request/Response
Payload Descriptor
Value |
Meaning |
0x00 |
Ping |
0x01 |
Pong |
0x40 |
Push |
0x80 |
Query |
0x81 |
QueryHit |
TTL
Time to live
Number of times message will be forwarded by servents
Many servents will set TTL to 5 if is it larger
Each servent that gets the message reduces TTL by one before forwarding the message
CS580 Spring 2005 | Doc 15, Gnutella Slide # 7 |
Hops
Number of times message has been forwarded
Each servent that gets the message increase Hop by one before forwarding
Payload Length
Length of rest of message
CS580 Spring 2005 | Doc 15, Gnutella Slide # 8 |
No more content other then header
CS580 Spring 2005 | Doc 15, Gnutella Slide # 9 |
Sent only in response to a ping
Servent can cache pongs of other servents
Port |
IP Address |
Number of files shared |
Number of kilobytes shared |
|||||
Byte offset |
0 |
1 |
2 |
5 |
6 |
9 |
10 |
13 |
Port
Port that responding servent can accept incoming connections
IP Address
IP Address of responding servent
This field uses big-endian format
CS580 Spring 2005 | Doc 15, Gnutella Slide # 10 |
Minimum Speed |
Search Criteria |
|||
Byte offset |
0 |
1 |
2 |
… |
Minimum Speed
Minimum speed (of connection) in kb/second of servents that should respond to this message
Search Criteria
Nul (0x00) terminated search string
Length of string must be included in the payload length field
CS580 Spring 2005 | Doc 15, Gnutella Slide # 11 |
Sent in response to a Query
Descriptor ID in header should contain same value as the Query
Number of hits |
Port |
IP Address |
Speed |
Result Set |
Servent Identifier |
||||||
Byte offset |
0 |
1 |
2 |
3 |
6 |
7 |
10 |
11 |
… |
n |
n+16 |
Number of hits
Number of hits in the result set
Port
Port number on which responding servent can accept incoming connections
IP Address
IP Address of responding servent
This field uses big-endian format
Speed
Speed of responding host’s connection in kb/second
CS580 Spring 2005 | Doc 15, Gnutella Slide # 12 |
Result Set
File Index |
File Size |
File Name |
||||
Byte offset |
0 |
3 |
4 |
7 |
8 |
… |
File Index
A number used by host to identify the file
File Size
Size in bytes of the file
File Name
Double-nul (0x0000) terminated name of the file
Servent Identifier
A 16-byte string uniquely identifying the responding servent on the network.
“This is typically some function of the servent’s network address”
CS580 Spring 2005 | Doc 15, Gnutella Slide # 13 |
Extended Query Hit
Number of hits |
Port |
IP Address |
Speed |
Result Set |
Trailer |
Servent Identifier |
|||||||
Byte offset |
0 |
1 |
2 |
3 |
6 |
7 |
10 |
11 |
… |
n |
m |
m+1 |
m+17 |
Trailer
Vender Code |
Open Data Size |
Open Data |
Private data |
|||
Byte offset |
0 |
3 |
4 |
5 |
6 |
n |
How do we know if the trailer exists?
How do we know the length of the private data?
CS580 Spring 2005 | Doc 15, Gnutella Slide # 14 |
Servent Identifier |
File Index |
IP Address |
Port |
|||||
Byte offset |
0 |
15 |
16 |
19 |
20 |
23 |
24 |
25 |
Servent Identifier
A 16-byte string uniquely identifying the servent on the network that should push the file
File Index
Index of the file to push
IP Address
IP Address of to which the file should be pushed
This field uses big-endian format
Port
Port to which the file should be pushed
CS580 Spring 2005 | Doc 15, Gnutella Slide # 15 |
Pong messages
Can only be send along path the carried the Ping
Servents should not forward a pong if they did not see the ping
QueryHit
Can only be send along path the carried the Query
Servents should not forward a query hit if they did not see the query
Push
Can only be send along path the carried the QueryHit
Servents should not forward a push if they did not see the query hit
Fowarding
Forward all Ping and Querys to all directly connected servents except to the one that sent it
Decrement TTL and increment Hops field
Don’t forward messages that you have seen before
CS580 Spring 2005 | Doc 15, Gnutella Slide # 16 |
In response to a QueryHit download the file by using http.
Request the file uses following format:
GET /get/<File Index>/<File Name>/ HTTP/1.0\r\n
Connection: Keep-Alive\r\n
Range: bytes=0-\r\n
User-Agent: Gnutella\r\n 3 \r\n
Remote servent responses with:
HTTP 200 OK\r\n
Server: Gnutella\r\n
Content-type: application/binary\r\n
Content-length: fileSize\r\n
\r\n
Copyright ©, All rights reserved.
2005 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.