BitTorrent Protocol: Interested vs Not Interested Messages
In the BitTorrent peer-to-peer protocol, communication between peers relies on distinct state flags to manage data flow efficiently. Among the most fundamental of these are the “interested” and “not interested” state messages, which signal whether a client wants pieces of a file that a connected peer possesses. Together with “choked” and “unchoked” states, these messages form the core state machine that controls when and how data requests are transmitted across the swarm.
The Role of Peer States in BitTorrent
Every peer connection in BitTorrent is symmetric and bidirectional, meaning both sides maintain two independent state variables regarding each other:
- Choked / Unchoked: Dictates whether a peer is permitted to request data from the other.
- Interested / Not Interested: Dictates whether a peer desires data from the other.
Data transfer only occurs when a peer is simultaneously interested in the remote peer and unchoked by that remote peer.
The “Interested” Message
The “interested” message is a fixed-length notification consisting of
a single byte (Message ID 2) preceded by a 4-byte length
prefix of 1.
- Trigger: A client sends an “interested” message
when it evaluates the remote peer’s piece availability—usually received
via
bitfieldorhavemessages—and finds at least one piece it does not yet have. - Purpose: It notifies the remote peer that the local client wants to download data.
- Effect: It places the client in the remote peer’s
candidate pool for unchoking. Once the remote peer chooses to unchoke
the client, data requests (
requestmessages) can begin.
The “Not Interested” Message
The “not interested” message is also a fixed-length notification,
consisting of Message ID 3 with a 4-byte length prefix of
1.
- Trigger: A client sends a “not interested” message when the remote peer no longer has any pieces the client needs. This occurs when the client finishes downloading all shared pieces, completes the entire torrent, or if the remote peer’s piece set becomes redundant.
- Purpose: It informs the remote peer that no further data requests will be made, regardless of choking status.
- Effect: It allows the remote peer to reallocate its upload bandwidth and unchoke slots to other peers in the swarm that are actively seeking data.
Interaction Between States
The combination of the interested and choked states determines the behavior of the connection:
- Interested and Choked: The client wants data, but the remote peer is not currently uploading to it.
- Interested and Unchoked: The client wants data and has permission to download; active piece requests take place.
- Not Interested and Choked: No data is wanted, and no upload slots are allocated.
- Not Interested and Unchoked: The remote peer has opened an upload slot, but the client does not require any data. This typically prompts the remote peer to choke the client and allocate the slot elsewhere.
By utilizing “interested” and “not interested” messages, BitTorrent clients minimize unnecessary network overhead and ensure upload bandwidth is directed exclusively to peers ready to consume it.