http://opennap.sourceforge.net/Napster was created by a company to facilitate the sharing of music files over the net. It uses a proprietary protocol, but it has been reverse engineered so detailed information is available about it.
http://opennap.sourceforge.net/napster.txt
Napster demonstrates several interesting design choices, and is partly a distributed and partly a centralized system.
Napster, Inc. maintains a centralized server farm to search for the music you want (big database). It uses redundancy in machines to handle the load and be improve reliability. DNS is used to distribute client requests among the servers.
A huge potential problem with a centralized design is having the server become a bottleneck. In the case of mp3s, there might also be a big legal issue as well. Napster gets around this by acting as a broker for music exchange. The actual transfer of data is done directly between the person with the music and the person who wants the music. No music files need be stored on napster's servers.
Many commands (cirka 100), coded as a 2 byte value.
user loginOrganized in "families" according to functionality. For example, the 200 commands cover searching for and downloading music.
list of chat sites
joining a channel, describing connection speed
chatting
control of chat
searching
downloading
done on the centralized napster server100 client notification of shared file [CLIENT][FILENAME CONTAINS "artist name"]
MAX_RESULTS <max>
[FILENAME CONTAINS "song"]
[LINESPEED <compare> <link-type>]
[BITRATE <compare> "<br>"]
[FREQ <compare> "<freq>"]The artist name and the song name are, obviously, treated
the same by the server; confirm this for yourself
on the windows client.max is a number; if it is greater than 100, the server will
only return 100 results.<compare> is one of the following:
"AT LEAST" "AT BEST" "EQUAL TO"<link-type> see 0x02 (client login) for a description
<br> is a number, in kbps
<freq> is a sample frequency, in Hz
Examples
FILENAME CONTAINS "Sneaker Pimps" MAX_RESULTS 75 FILENAME
CONTAINS "tesko suicide" BITRATE "AT LEAST" "128"MAX_RESULTS 100 FILENAME CONTAINS "Ventolin" LINESPEED
"EQUAL TO" 10
Sent by a client which wishes to register with the napster server a song to share with the world."<filename>" <md5> <size> <bitrate> <frequency> <time>
<md5> checksum which uniquely
identifies the file
<size> in bytes
<bitrate> in kbps
<frequency> in hz, sampling
frequency
<time> in seconds of
the track
Example:
"generic band - generic song.mp3" b92870e0d41bc8e698cf2f0a1ddfeac7 443332 128 44100 60
218 downloading file [CLIENT]
no data
Client sends this message to the server to indicate they are in the process of downloading a file. this adds 1 to the download count which the server maintains.
Format of packets
[chunksize] [chunkinfo] [data]chunksize
16 bit integer, size of data field in byteschunkinfo16 bit integer code for the command contained in this packetdatadepends on the command
for example, the song you want is the data field of a download command
separate fields in the data are separated by single spaces
strings are quoted (and the quotes are included in the data)
client - run by the userGetting a file
server - run by napster (the big database)
provider - may also be a client, provides actual music data
Client contacts server to find the file
Server returns list of provider who have this file
Client deals directly to the provider that has the songIn case of a client being behind a firewall, the client can push the data to you, so that it initiates the connection. The server sends a request to the client providing the song, and you wait hoping it establishes a connection to you.
To server:
send: username, filename<user selects a provider from the list returned>
receive: IP address, port #, file checksum, line speedTo provider:
send: GETTo server:
receive: ack (app proto ack, not just TCP ack)
send: your id, file name, offsetincludes the ability to specifiy an offset in a file so that a download resume is possiblereceive: size of file in bytesa command to say you are currently downloadingFrom provider:receive: data for file