LinkSpecifier

Enum LinkSpecifier 

Source
pub enum LinkSpecifier {
    IPv4 {
        address: String,
        port: u16,
    },
    IPv6 {
        address: String,
        port: u16,
    },
    Fingerprint {
        fingerprint: [u8; 20],
    },
    Ed25519 {
        fingerprint: [u8; 32],
    },
    Unknown {
        link_type: u8,
        value: Vec<u8>,
    },
}
Expand description

Method of communicating with a relay in a circuit.

Link specifiers describe how to connect to a relay when extending a circuit. They are used in EXTEND2 cells to specify the next hop. Multiple specifiers can be provided to give the extending relay options for how to connect.

For more information, see the EXTEND cell specification.

§Wire Format

+----------+--------+------------------+
| Type (1) | Len (1)| Value (Len bytes)|
+----------+--------+------------------+

§Variants

TypeValue SizeDescription
06 bytesIPv4 address (4) + port (2)
118 bytesIPv6 address (16) + port (2)
220 bytesSHA-1 identity fingerprint
332 bytesEd25519 identity fingerprint
4+variableUnknown/future types

§Example

use stem_rs::client::datatype::LinkSpecifier;

// Create an IPv4 link specifier
let spec = LinkSpecifier::IPv4 {
    address: "192.168.1.1".to_string(),
    port: 9001,
};

// Pack and unpack
let packed = spec.pack();
let (unpacked, _) = LinkSpecifier::pop(&packed).unwrap();

match unpacked {
    LinkSpecifier::IPv4 { address, port } => {
        assert_eq!(address, "192.168.1.1");
        assert_eq!(port, 9001);
    }
    _ => panic!("Expected IPv4"),
}

Variants§

§

IPv4

TLS connection to an IPv4 address.

Fields

§address: String

The relay’s IPv4 address.

§port: u16

The relay’s ORPort.

§

IPv6

TLS connection to an IPv6 address.

Fields

§address: String

The relay’s IPv6 address (fully expanded form).

§port: u16

The relay’s ORPort.

§

Fingerprint

SHA-1 identity fingerprint (20 bytes).

Fields

§fingerprint: [u8; 20]

The relay’s SHA-1 identity fingerprint.

§

Ed25519

Ed25519 identity fingerprint (32 bytes).

Fields

§fingerprint: [u8; 32]

The relay’s Ed25519 identity fingerprint.

§

Unknown

Unrecognized link specifier type.

Fields

§link_type: u8

The raw link type byte.

§value: Vec<u8>

The raw value bytes.

Implementations§

Source§

impl LinkSpecifier

Returns the link type byte for this specifier.

TypeMeaning
0IPv4
1IPv6
2Fingerprint
3Ed25519
4+Unknown
Source

pub fn value(&self) -> Vec<u8>

Returns the encoded value bytes for this specifier.

The format depends on the specifier type:

  • IPv4: 4-byte address + 2-byte port
  • IPv6: 16-byte address + 2-byte port
  • Fingerprint: 20-byte SHA-1 hash
  • Ed25519: 32-byte public key
Source

pub fn pack(&self) -> Vec<u8>

Packs the link specifier into its wire format.

§Returns

A Vec<u8> containing: [type (1), length (1), value...]

Source

pub fn unpack(data: &[u8]) -> Result<Self, Error>

Unpacks a link specifier from its wire format.

§Arguments
  • data - The packed link specifier bytes
§Errors

Returns Error::Protocol if the data is malformed.

Source

pub fn pop(packed: &[u8]) -> Result<(Self, &[u8]), Error>

Unpacks a link specifier from the start of a byte slice, returning the remainder.

§Arguments
  • packed - The byte slice to read from
§Returns

A tuple of (LinkSpecifier, remainder).

§Errors

Returns Error::Protocol if:

  • The data is too short for the header
  • The specified length exceeds the available data
  • The value size doesn’t match the expected size for the type

Trait Implementations§

Source§

impl Clone for LinkSpecifier

Source§

fn clone(&self) -> LinkSpecifier

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 LinkSpecifier

Source§

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

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

impl PartialEq for LinkSpecifier

Source§

fn eq(&self, other: &LinkSpecifier) -> 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 Eq for LinkSpecifier

Source§

impl StructuralPartialEq for LinkSpecifier

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.