Napster

Resources

http://opennap.sourceforge.net/
http://opennap.sourceforge.net/napster.txt
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.

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.

Protocol

The napster protocol involves the transfer of large amounts of information, so of course it is built on TCP.

Many commands (cirka 100), coded as a 2 byte value.

user login
list of chat sites
joining a channel, describing connection speed
chatting
control of chat
searching
downloading
Organized in "families" according to functionality. For example, the 200 commands cover searching for and downloading music.

Example commands

200 - client search request
done on the centralized napster server

[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

100     client notification of shared file [CLIENT]
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.

Data exchange

All data exchange when using Napster is in terms of "packets"

Format of packets

[chunksize] [chunkinfo] [data]

chunksize

16 bit integer, size of data field in bytes
chunkinfo
16 bit integer code for the command contained in this packet
data
depends 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)

Interesting transactions

Three roles involved
client - run by the user
server - run by napster (the big database)
provider - may also be a client, provides actual music data
Getting a file
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 song

In 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
receive: IP address, port #, file checksum, line speed
<user selects a provider from the list returned>

To provider:

send: GET
receive: ack (app proto ack, not just TCP ack)
send: your id, file name, offset
includes the ability to specifiy an offset in a file so that a download resume is possible
receive: size of file in bytes
To server:
a command to say you are currently downloading
From provider:
receive: data for file