pub struct Handshake {
pub info_hash: [u8; 20],
pub peer_id: [u8; 20],
pub reserved: [u8; 8],
}Expand description
The BitTorrent handshake message.
The handshake is the first message exchanged between peers and includes:
- Protocol identifier (“BitTorrent protocol”)
- Reserved bytes (8 bytes, used for capability flags)
- Info hash (20 bytes, identifies the torrent)
- Peer ID (20 bytes, identifies the client)
§Reserved Bytes
Bits in the reserved bytes indicate protocol extensions:
Fields§
§info_hash: [u8; 20]The torrent’s info hash.
peer_id: [u8; 20]The sender’s peer ID.
reserved: [u8; 8]Reserved bytes for protocol extensions.
Implementations§
Source§impl Handshake
impl Handshake
Sourcepub fn new(info_hash: [u8; 20], peer_id: [u8; 20]) -> Self
pub fn new(info_hash: [u8; 20], peer_id: [u8; 20]) -> Self
Creates a new handshake with extension protocol and fast extension enabled.
Sourcepub fn new_v2(info_hash: [u8; 20], peer_id: [u8; 20]) -> Self
pub fn new_v2(info_hash: [u8; 20], peer_id: [u8; 20]) -> Self
Creates a new handshake with v2 support enabled.
This sets the extension protocol, fast extension, and v2 capability bits.
Sourcepub fn supports_extension_protocol(&self) -> bool
pub fn supports_extension_protocol(&self) -> bool
Returns true if the peer supports the extension protocol ([BEP-10]).
Sourcepub fn supports_fast_extension(&self) -> bool
pub fn supports_fast_extension(&self) -> bool
Returns true if the peer supports the fast extension ([BEP-6]).
Sourcepub fn supports_dht(&self) -> bool
pub fn supports_dht(&self) -> bool
Returns true if the peer supports DHT ([BEP-5]).
Sourcepub fn supports_v2(&self) -> bool
pub fn supports_v2(&self) -> bool
Returns true if the peer supports BitTorrent v2 ([BEP-52]).
The v2 capability is indicated by the 4th most significant bit in the last byte of the reserved field (bit 4, 0x10).
Sourcepub fn set_v2_support(&mut self, enabled: bool)
pub fn set_v2_support(&mut self, enabled: bool)
Sets the v2 support bit in the reserved field.