What Is the BitTorrent HAVE Message and When Is It Sent?

In the BitTorrent peer-to-peer protocol, the “have” message is a lightweight communication signal used to notify connected peers that a client has successfully acquired and validated a specific piece of a shared file. This article explains the structure and role of the “have” message, how it differs from initial state announcements, and the exact conditions under which a client broadcasts it across the swarm to optimize file distribution.

Understanding the “HAVE” Message

The “have” message is a core message type in the BitTorrent peer wire protocol, assigned the standard message ID of 4. Its payload consists of a single, fixed-size 4-byte (32-bit) integer representing the zero-based index of a specific file piece.

Because files in BitTorrent are split into equal-sized chunks called pieces, peers need a way to track which chunks their connected neighbors possess. The “have” message serves as an incremental update to a peer’s availability status, consuming minimal bandwidth compared to sending full-state messages.

When the “HAVE” Message Is Broadcast

A BitTorrent client broadcasts a “have” message to its connected peers under specific, sequential conditions:

  1. Piece Completion: The client finishes downloading all individual blocks (sub-pieces) that constitute a single piece.
  2. Cryptographic Verification: The client computes the SHA-1 hash of the newly assembled piece and compares it against the expected hash provided in the .torrent metadata.
  3. Immediate Swarm Broadcast: Once the hash is verified as valid and uncorrupted, the client immediately sends a “have” message containing that piece’s index to all actively connected peers in the swarm.

If the hash verification fails, the piece is discarded, and no “have” message is generated.

Purpose and Function Within the Swarm

Broadcasting the “have” message is critical for several protocol operations:

Selective Broadcasting and Extensions

Under standard conditions, the message is broadcast to all connected peers. However, modified behaviors exist: