TorDNSEL

Struct TorDNSEL 

Source
pub struct TorDNSEL {
    pub fingerprint: String,
    pub published: Option<DateTime<Utc>>,
    pub last_status: Option<DateTime<Utc>>,
    pub exit_addresses: Vec<(Ipv4Addr, DateTime<Utc>)>,
    /* private fields */
}
Expand description

A TorDNSEL exit list entry for a single relay.

Each entry represents one Tor exit relay and contains information about when it was last seen and what IP addresses it uses for exiting traffic.

§Structure

A TorDNSEL entry contains:

  • The relay’s fingerprint (40-character hex string)
  • Publication and last-seen timestamps
  • One or more exit addresses with observation times

§Exit Addresses

A relay may have multiple exit addresses because:

  • It may use different addresses for different exit ports
  • It may have changed addresses over time
  • It may be multi-homed (multiple network interfaces)

Each exit address is paired with the time it was observed being used.

§Example

use stem_rs::descriptor::tordnsel::TorDNSEL;

let content = r#"ExitNode 003A71137D959748C8157C4A76ECA639CEF5E33E
Published 2024-01-01 12:00:00
LastStatus 2024-01-01 13:00:00
ExitAddress 192.168.1.1 2024-01-01 13:30:00
"#;

let entry = TorDNSEL::parse(content)?;
assert_eq!(entry.fingerprint, "003A71137D959748C8157C4A76ECA639CEF5E33E");
assert_eq!(entry.exit_addresses.len(), 1);

Fields§

§fingerprint: String

SHA-1 fingerprint of the relay’s identity key.

This is a 40-character hexadecimal string that uniquely identifies the relay. It matches the fingerprint in server descriptors and consensus documents.

§published: Option<DateTime<Utc>>

Time when the relay published its descriptor.

This indicates when the relay last updated its server descriptor. May be None if the field was missing or unparseable.

§last_status: Option<DateTime<Utc>>

Time when the relay was last seen in a network status.

This indicates when the relay was last included in a consensus document. A relay not seen recently may no longer be active. May be None if the field was missing or unparseable.

§exit_addresses: Vec<(Ipv4Addr, DateTime<Utc>)>

List of exit addresses observed for this relay.

Each entry is a tuple of (IPv4 address, observation time). The observation time indicates when TorDNSEL detected that the relay was using this address for exit traffic.

A relay may have multiple exit addresses if it uses different addresses for different connections or has changed addresses.

Implementations§

Source§

impl TorDNSEL

Source

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

Parses a TorDNSEL entry from a string.

This method parses a single exit list entry containing information about one relay.

§Arguments
  • content - The entry content as a string
§Returns

A parsed TorDNSEL entry on success.

§Errors

Returns Error::Parse if:

  • The ExitNode line is missing
  • The fingerprint is not a valid 40-character hex string

Note: Invalid timestamps are silently ignored rather than causing errors.

§Example
use stem_rs::descriptor::tordnsel::TorDNSEL;

let content = r#"ExitNode 003A71137D959748C8157C4A76ECA639CEF5E33E
Published 2024-01-01 12:00:00
ExitAddress 192.168.1.1 2024-01-01 13:30:00
"#;

let entry = TorDNSEL::parse(content)?;
assert_eq!(entry.fingerprint, "003A71137D959748C8157C4A76ECA639CEF5E33E");
Source

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

Parses a TorDNSEL entry from raw bytes.

This is the byte-oriented version of parse(), useful when reading directly from files or network streams.

§Arguments
  • content - The entry content as bytes (UTF-8 encoded)
§Returns

A parsed TorDNSEL entry on success.

§Errors

Returns Error::Parse if:

  • The ExitNode line is missing
  • The fingerprint is not a valid 40-character hex string
§Note

Invalid UTF-8 sequences are replaced with the Unicode replacement character (U+FFFD) rather than causing an error.

Source

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

Returns the raw bytes of the original entry content.

This provides access to the exact bytes that were parsed, useful for debugging or storing entries in their original format.

§Returns

A byte slice containing the original entry content.

Source

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

Returns lines that were not recognized during parsing.

Unrecognized lines are preserved for forward compatibility with future exit list format extensions.

§Returns

A slice of strings, each representing an unrecognized line. Empty if all lines were recognized.

Source

pub fn to_descriptor_string(&self) -> String

Converts the entry back to its string representation.

This produces a string in the standard TorDNSEL format that can be parsed again or written to a file.

§Returns

A string containing the entry in standard format.

§Example
use stem_rs::descriptor::tordnsel::TorDNSEL;

let content = r#"ExitNode 003A71137D959748C8157C4A76ECA639CEF5E33E
Published 2024-01-01 12:00:00
ExitAddress 192.168.1.1 2024-01-01 13:30:00
"#;

let entry = TorDNSEL::parse(content)?;
let output = entry.to_descriptor_string();
assert!(output.contains("ExitNode 003A71137D959748C8157C4A76ECA639CEF5E33E"));

Trait Implementations§

Source§

impl Clone for TorDNSEL

Source§

fn clone(&self) -> TorDNSEL

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 TorDNSEL

Source§

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

Formats the value using the given formatter. Read more

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.