ServerDescriptor

Struct ServerDescriptor 

Source
pub struct ServerDescriptor {
Show 40 fields pub nickname: String, pub fingerprint: Option<String>, pub address: IpAddr, pub or_port: u16, pub socks_port: Option<u16>, pub dir_port: Option<u16>, pub or_addresses: Vec<(IpAddr, u16, bool)>, pub platform: Option<Vec<u8>>, pub tor_version: Option<Version>, pub operating_system: Option<String>, pub published: DateTime<Utc>, pub uptime: Option<u64>, pub contact: Option<Vec<u8>>, pub link_protocols: Option<Vec<String>>, pub circuit_protocols: Option<Vec<String>>, pub bandwidth_avg: u64, pub bandwidth_burst: u64, pub bandwidth_observed: u64, pub exit_policy: ExitPolicy, pub exit_policy_v6: Option<String>, pub bridge_distribution: BridgeDistribution, pub family: HashSet<String>, pub hibernating: bool, pub allow_single_hop_exits: bool, pub allow_tunneled_dir_requests: bool, pub extra_info_cache: bool, pub extra_info_digest: Option<String>, pub extra_info_sha256_digest: Option<String>, pub is_hidden_service_dir: bool, pub protocols: HashMap<String, Vec<u32>>, pub onion_key: Option<String>, pub onion_key_crosscert: Option<String>, pub ntor_onion_key: Option<String>, pub ntor_onion_key_crosscert: Option<String>, pub ntor_onion_key_crosscert_sign: Option<String>, pub signing_key: Option<String>, pub ed25519_certificate: Option<String>, pub ed25519_master_key: Option<String>, pub ed25519_signature: Option<String>, pub signature: String, /* private fields */
}
Expand description

A server descriptor containing metadata about a Tor relay.

Server descriptors are the primary documents that relays publish to describe themselves. They contain identity information, network addresses, bandwidth capabilities, exit policies, and cryptographic keys needed for circuit construction.

§Fields Overview

CategoryFields
Identitynickname, fingerprint, contact
Networkaddress, or_port, dir_port, or_addresses
Bandwidthbandwidth_avg, bandwidth_burst, bandwidth_observed
Policyexit_policy, exit_policy_v6
Keysonion_key, signing_key, ntor_onion_key, Ed25519 keys
Protocolsprotocols, link_protocols, circuit_protocols
Metadataplatform, tor_version, published, uptime

§Invariants

  • nickname is 1-19 alphanumeric characters
  • fingerprint is 40 uppercase hex characters (if present)
  • or_port is non-zero
  • published is a valid UTC timestamp
  • signature is always present and non-empty

§Example

use stem_rs::descriptor::{ServerDescriptor, Descriptor};

let content = std::fs::read_to_string("server-descriptor").unwrap();
let desc = ServerDescriptor::parse(&content).unwrap();

println!("Nickname: {}", desc.nickname);
println!("Address: {}:{}", desc.address, desc.or_port);
println!("Published: {}", desc.published);
println!("Bandwidth: {} B/s avg, {} B/s observed",
         desc.bandwidth_avg, desc.bandwidth_observed);

if let Some(ref fp) = desc.fingerprint {
    println!("Fingerprint: {}", fp);
}

if let Some(ref version) = desc.tor_version {
    println!("Tor version: {}", version);
}

§Thread Safety

ServerDescriptor is Send and Sync as it contains only owned data.

Fields§

§nickname: String

The relay’s nickname (1-19 alphanumeric characters).

§fingerprint: Option<String>

The relay’s fingerprint (40 hex characters), derived from identity key.

§address: IpAddr

The relay’s primary IPv4 address.

§or_port: u16

The relay’s onion routing port (always non-zero).

§socks_port: Option<u16>

The relay’s SOCKS port (deprecated, usually None).

§dir_port: Option<u16>

The relay’s directory port for serving cached descriptors.

§or_addresses: Vec<(IpAddr, u16, bool)>

Additional addresses (IPv4 or IPv6) the relay listens on. Each tuple is (address, port, is_ipv6).

§platform: Option<Vec<u8>>

Raw platform string (e.g., “Tor 0.4.7.10 on Linux”).

§tor_version: Option<Version>

Parsed Tor version from the platform string.

§operating_system: Option<String>

Operating system from the platform string.

§published: DateTime<Utc>

When this descriptor was published (UTC).

§uptime: Option<u64>

Seconds the relay has been running.

§contact: Option<Vec<u8>>

Contact information for the relay operator.

§link_protocols: Option<Vec<String>>

Supported link protocol versions (legacy).

§circuit_protocols: Option<Vec<String>>

Supported circuit protocol versions (legacy).

§bandwidth_avg: u64

Average bandwidth in bytes per second the relay is willing to sustain.

§bandwidth_burst: u64

Maximum bandwidth in bytes per second for short bursts.

§bandwidth_observed: u64

Bandwidth in bytes per second the relay has actually observed.

§exit_policy: ExitPolicy

The relay’s exit policy (rules for what traffic it will exit).

§exit_policy_v6: Option<String>

IPv6 exit policy summary (e.g., “accept 80,443” or “reject 1-65535”).

§bridge_distribution: BridgeDistribution

How this bridge wants to be distributed (bridges only).

§family: HashSet<String>

Fingerprints of related relays (same operator).

§hibernating: bool

Whether the relay is currently hibernating (reduced service).

§allow_single_hop_exits: bool

Whether the relay allows single-hop exits (security risk).

§allow_tunneled_dir_requests: bool

Whether the relay accepts tunneled directory requests.

§extra_info_cache: bool

Whether the relay caches extra-info descriptors.

§extra_info_digest: Option<String>

SHA-1 digest of the relay’s extra-info descriptor.

§extra_info_sha256_digest: Option<String>

SHA-256 digest of the relay’s extra-info descriptor.

§is_hidden_service_dir: bool

Whether the relay serves as a hidden service directory.

§protocols: HashMap<String, Vec<u32>>

Supported protocol versions (modern format). Maps protocol name to list of supported versions.

§onion_key: Option<String>

RSA onion key for circuit creation (PEM format).

§onion_key_crosscert: Option<String>

Cross-certification of onion key by identity key.

§ntor_onion_key: Option<String>

Curve25519 onion key for ntor handshake (base64).

§ntor_onion_key_crosscert: Option<String>

Cross-certification of ntor key.

§ntor_onion_key_crosscert_sign: Option<String>

Sign bit for ntor key cross-certification.

§signing_key: Option<String>

RSA signing key (PEM format).

§ed25519_certificate: Option<String>

Ed25519 identity certificate (PEM format).

§ed25519_master_key: Option<String>

Ed25519 master key (base64).

§ed25519_signature: Option<String>

Ed25519 signature over the descriptor.

§signature: String

RSA signature over the descriptor (PEM format).

Implementations§

Source§

impl ServerDescriptor

Source

pub fn new( nickname: String, address: IpAddr, or_port: u16, published: DateTime<Utc>, signature: String, ) -> Self

Creates a new server descriptor with minimal required fields.

This creates a descriptor with default values for optional fields. Use this for testing or when constructing descriptors programmatically.

§Arguments
  • nickname - The relay’s nickname (1-19 alphanumeric characters)
  • address - The relay’s primary IP address
  • or_port - The relay’s onion routing port
  • published - When this descriptor was published
  • signature - The RSA signature (PEM format)
§Example
use stem_rs::descriptor::ServerDescriptor;
use chrono::Utc;
use std::net::IpAddr;

let desc = ServerDescriptor::new(
    "MyRelay".to_string(),
    "192.168.1.1".parse().unwrap(),
    9001,
    Utc::now(),
    "-----BEGIN SIGNATURE-----\ntest\n-----END SIGNATURE-----".to_string(),
);

assert_eq!(desc.nickname, "MyRelay");
assert_eq!(desc.or_port, 9001);

Trait Implementations§

Source§

impl Clone for ServerDescriptor

Source§

fn clone(&self) -> ServerDescriptor

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 ServerDescriptor

Source§

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

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

impl Descriptor for ServerDescriptor

Source§

fn parse(content: &str) -> Result<Self, Error>

Parses a descriptor from its string content. Read more
Source§

fn to_descriptor_string(&self) -> String

Serializes the descriptor to its canonical string format. Read more
Source§

fn digest( &self, hash: DigestHash, encoding: DigestEncoding, ) -> Result<String, Error>

Computes the cryptographic digest of the descriptor. Read more
Source§

fn raw_content(&self) -> &[u8]

Returns the raw bytes of the original descriptor content. Read more
Source§

fn unrecognized_lines(&self) -> &[String]

Returns lines from the descriptor that were not recognized. Read more
Source§

impl Display for ServerDescriptor

Source§

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

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

impl FromStr for ServerDescriptor

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for ServerDescriptor

Source§

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

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.