LinkProtocol

Struct LinkProtocol 

Source
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

VersionCircuit ID SizeFirst Circuit IDFixed Cell Length
1-32 bytes (Short)0x0001512 bytes
4+4 bytes (Long)0x80000000514 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: u32

The link protocol version number.

§circ_id_size: Size

Size of circuit identifier fields (2 or 4 bytes).

§fixed_cell_length: usize

Total length of fixed-size cells in bytes.

§first_circ_id: u32

First 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

Source

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

Source§

fn clone(&self) -> LinkProtocol

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LinkProtocol

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<u32> for LinkProtocol

Source§

fn from(version: u32) -> Self

Creates a LinkProtocol from a version number.

Source§

impl Hash for LinkProtocol

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq<u32> for LinkProtocol

Source§

fn eq(&self, other: &u32) -> bool

Compares the protocol version with a u32.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for LinkProtocol

Source§

fn eq(&self, other: &LinkProtocol) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for LinkProtocol

Source§

impl Eq for LinkProtocol

Source§

impl StructuralPartialEq for LinkProtocol

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.