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
| Type | Value Size | Description |
|---|---|---|
| 0 | 6 bytes | IPv4 address (4) + port (2) |
| 1 | 18 bytes | IPv6 address (16) + port (2) |
| 2 | 20 bytes | SHA-1 identity fingerprint |
| 3 | 32 bytes | Ed25519 identity fingerprint |
| 4+ | variable | Unknown/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.
IPv6
TLS connection to an IPv6 address.
Fingerprint
SHA-1 identity fingerprint (20 bytes).
Ed25519
Ed25519 identity fingerprint (32 bytes).
Unknown
Unrecognized link specifier type.
Implementations§
Source§impl LinkSpecifier
impl LinkSpecifier
Sourcepub fn link_type(&self) -> u8
pub fn link_type(&self) -> u8
Returns the link type byte for this specifier.
| Type | Meaning |
|---|---|
| 0 | IPv4 |
| 1 | IPv6 |
| 2 | Fingerprint |
| 3 | Ed25519 |
| 4+ | Unknown |
Sourcepub fn value(&self) -> Vec<u8> ⓘ
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
Sourcepub fn pack(&self) -> Vec<u8> ⓘ
pub fn pack(&self) -> Vec<u8> ⓘ
Packs the link specifier into its wire format.
§Returns
A Vec<u8> containing: [type (1), length (1), value...]
Sourcepub fn unpack(data: &[u8]) -> Result<Self, Error>
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.
Sourcepub fn pop(packed: &[u8]) -> Result<(Self, &[u8]), Error>
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
impl Clone for LinkSpecifier
Source§fn clone(&self) -> LinkSpecifier
fn clone(&self) -> LinkSpecifier
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more