pub struct LinkProtocol {
pub version: u32,
pub circ_id_size: Size,
pub fixed_cell_length: usize,
pub first_circ_id: u32,
}Expand description
Link protocol version with version-dependent constants.
The Tor link protocol has evolved over time, with different versions using different field sizes and constants. This struct encapsulates the version-specific parameters needed for cell encoding and decoding.
§Version Differences
| Version | Circuit ID Size | First Circuit ID | Fixed Cell Length |
|---|---|---|---|
| 1-3 | 2 bytes (Short) | 0x0001 | 512 bytes |
| 4+ | 4 bytes (Long) | 0x80000000 | 514 bytes |
The first_circ_id determines the starting point for client-initiated
circuit identifiers. Clients use IDs with the high bit set (version 4+)
or starting from 1 (version 1-3).
§Example
use stem_rs::client::datatype::{LinkProtocol, Size};
// Version 3 uses 2-byte circuit IDs
let v3 = LinkProtocol::new(3);
assert_eq!(v3.circ_id_size, Size::Short);
assert_eq!(v3.first_circ_id, 0x01);
// Version 5 uses 4-byte circuit IDs
let v5 = LinkProtocol::new(5);
assert_eq!(v5.circ_id_size, Size::Long);
assert_eq!(v5.first_circ_id, 0x80000000);§Equality
LinkProtocol can be compared directly with u32 version numbers:
use stem_rs::client::datatype::LinkProtocol;
let protocol = LinkProtocol::new(5);
assert!(protocol == 5);
assert!(protocol != 4);Fields§
§version: u32The link protocol version number.
circ_id_size: SizeSize of circuit identifier fields (2 or 4 bytes).
fixed_cell_length: usizeTotal length of fixed-size cells in bytes.
first_circ_id: u32First circuit ID to use when creating circuits.
Clients pick circuit IDs from a range determined by the protocol version to avoid collisions with relay-initiated circuits.
Implementations§
Source§impl LinkProtocol
impl LinkProtocol
Sourcepub fn new(version: u32) -> Self
pub fn new(version: u32) -> Self
Creates a new LinkProtocol for the given version number.
This automatically configures all version-dependent constants based on the protocol specification.
§Arguments
version- The link protocol version (typically 4 or 5 for modern Tor)
§Example
use stem_rs::client::datatype::LinkProtocol;
let protocol = LinkProtocol::new(5);
assert_eq!(protocol.version, 5);
assert_eq!(protocol.fixed_cell_length, 514);Trait Implementations§
Source§impl Clone for LinkProtocol
impl Clone for LinkProtocol
Source§fn clone(&self) -> LinkProtocol
fn clone(&self) -> LinkProtocol
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more