BitTorrent PEX Message Flags for Seeders and Encryption
Peer Exchange (PEX) messages in the BitTorrent protocol allow clients
to share known peers directly without querying a central tracker. Within
a PEX message, binary flags mapped to each peer indicate their status
and connection capabilities. Specifically, the protocol uses the
added.f field, where the 0x01 bitflag denotes
that a peer supports Protocol Encryption (MSE/PE) and the
0x02 bitflag denotes that the peer is a seeder. These flags
allow clients to filter unnecessary connections and enforce security
preferences efficiently.
Structure of the PEX Message
The standard Peer Exchange extension (BEP 11 / ut_pex)
formats its payload as a Bencoded dictionary. When a client shares newly
discovered peers, it populates two parallel fields:
added: A compact byte string containing the IP addresses and port numbers of the peers.added.f: A sequence of single-byte flags where each byte corresponds to the peer at the identical index in theaddedlist.
The Specific PEX Flags
Each byte in the added.f string functions as a bitfield
to convey the following properties:
1. Encryption Support
(0x01)
- Bit Value:
0x01(binary00000001) - Meaning: The peer supports Message Stream Encryption (MSE) / Protocol Encryption (PE).
- Usage: When a client enforces mandatory protocol encryption or prefers encrypted handshakes, it checks for this flag to establish an encrypted transport channel immediately, bypassing unencrypted handshakes.
2. Seeder Status (0x02)
- Bit Value:
0x02(binary00000010) - Meaning: The peer possesses 100% of the torrent data and acts strictly as a seeder (upload-only).
- Usage: Clients that are also seeders use this flag to ignore the peer, as seeders do not need to connect to other seeders. Leechers can use this flag to prioritize connections to peers with complete data.
Combined Flag Values
Because these flags are bitfields, they can be combined using bitwise OR operations. For example:
0x00: A standard leecher with no encryption support.0x01: A leecher that supports encryption.0x02: A seeder that does not support encryption.0x03(0x01 | 0x02): A seeder that supports encryption.
Additional BEP 11 Flags
While 0x01 and 0x02 are the primary flags
for encryption and seeding, modern extensions also define:
0x04: Indicates support for the Micro Transport Protocol (uTP / BEP 29).0x08: Indicates support for NAT traversal via BEP 55 (Holepunch extension).