Skip to content

Navigation Menu

Sign up
Adam edited this page Feb 12, 2015 · 13 revisions

Welcome to the cnt5106c wiki!

The handshake consists of three parts: handshake header, zero bits, and peer ID. The length of the handshake message is 32 bytes. The handshake header is 18-byte string ‘P2PFILESHARINGPROJ’, which is followed by 10-byte zero bits, which is followed by 4-byte peer ID which is the integer representation of the peer ID. handshake header zero bits peer ID

After handshaking, each peer can send a stream of actual messages. An actual message consists of

  • 4-byte message length field
  • 1-byte message type
  • a message payload with variable size

Message length

The 4-byte message length specifies the message length in bytes. It does not include the length of the message length field itself.

Message Type

The 1-byte message type field specifies the type of the message. There are eight types of messages

Message Type Value
Choke 0
unchoke 1
interested 2
not interested 3
have 4
bitfield 5
request 6
piece 7

Message Payload

Choke, Unchoke, Interested, Not Interested

No Payload

Have

have messages have a payload that contains a 4-byte piece index field

Bitfield

bitfield messages in only sent as the first message right after handshaking is done when a connection is established. bitfield messages have a bitfield as its payload. Each bit in the bitfield payload represents whether the peer has the corresponding piece or not. the first byte of the bitfield corresponds to the piece indices 0 - 7 from high bit to low bit, respectively. The net one corresponds to piece indices 8 - 15, etc. Spare bits at the end are set to zero. Peers that don't have anything yet may skip a bitfield message.

Request

request message have a payload which consists of a 4-byte piece index field. Note that request message payload defined here is different from that of BitTorrent. We don't divide a into smaller subpieces.

Piece

piece messages have a payload which consists of a 4-byte piece index field and the content of the piece.

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /