morpheus_network::state::dns

Enum DnsResolveState

Source
pub enum DnsResolveState {
    Init,
    Resolving {
        query_handle: usize,
        start_tsc: TscTimestamp,
    },
    Resolved {
        ip: Ipv4Addr,
    },
    Failed {
        error: DnsError,
    },
}
Expand description

DNS resolution state machine.

Resolves a hostname to an IPv4 address using smoltcp’s DNS socket.

Variants§

§

Init

Initial state - not started

§

Resolving

Waiting for DNS response

Fields

§query_handle: usize

Query handle from smoltcp

§start_tsc: TscTimestamp

When query started (for timeout)

§

Resolved

Resolution complete

Fields

§ip: Ipv4Addr

Resolved IP address

§

Failed

Resolution failed

Fields

§error: DnsError

Error details

Implementations§

Source§

impl DnsResolveState

Source

pub fn new() -> Self

Create new DNS resolver in init state.

Source

pub fn start(&mut self, query_handle: usize, now_tsc: u64)

Start DNS resolution.

§Arguments
  • query_handle: Handle returned from smoltcp’s start_query()
  • now_tsc: Current TSC timestamp
Source

pub fn resolve(&mut self, ip: Ipv4Addr)

Mark as resolved with IP.

Source

pub fn fail(&mut self, error: DnsError)

Mark as failed.

Source

pub fn step( &mut self, dns_result: Result<Option<Ipv4Addr>, ()>, now_tsc: u64, timeout_ticks: u64, ) -> StepResult

Step the state machine.

§Arguments
  • dns_result: Result from smoltcp’s get_query_result():
    • Ok(Some(ip)): Resolved
    • Ok(None): Still pending
    • Err(_): Failed
  • now_tsc: Current TSC value
  • timeout_ticks: DNS timeout in TSC ticks
§Returns
  • Pending: Still resolving
  • Done: Resolved, call ip() to get result
  • Timeout: Query timed out
  • Failed: Query failed
Source

pub fn query_handle(&self) -> Option<usize>

Get query handle (if resolving).

Source

pub fn ip(&self) -> Option<Ipv4Addr>

Get resolved IP address (if complete).

Source

pub fn error(&self) -> Option<DnsError>

Get error (if failed).

Source

pub fn is_terminal(&self) -> bool

Check if resolution is complete (success or failure).

Source

pub fn is_resolved(&self) -> bool

Check if resolution succeeded.

Trait Implementations§

Source§

impl Debug for DnsResolveState

Source§

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

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

impl Default for DnsResolveState

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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, 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.