Enum SocketAddr

Source
#[non_exhaustive]
pub enum SocketAddr { Inet(SocketAddr), Unix(SocketAddr), }
Expand description

Any address that Arti can listen on or connect to.

We use this type when we want to make streams without being concerned whether they are AF_UNIX streams, TCP streams, or so forth.

To avoid confusion, you might want to avoid importing this type directly. Instead, import rtcompat::general and refer to this type as general::SocketAddr.

§String representation

Any general::SocketAddr has up to two string representations:

  1. A qualified representation, consisting of a schema (either “unix” or “inet”), followed by a single colon, followed by the address itself represented as a string.

    Examples: unix:/path/to/socket, inet:127.0.0.1:9999, inet:[::1]:9999.

    The “unnamed” AF_UNIX address is represented as unix:.

  2. A unqualified representation, consisting of a net::SocketAddr address represented as a string.

    Examples: 127.0.0.1:9999, [::1]:9999.

Note that not every general::SocketAddr has a string representation! Currently, the ones that might not be representable are:

  • “Abstract” AF_UNIX addresses (a Linux feature)
  • AF_UNIX addresses whose path name is not UTF-8.

Note also that string representations may contain whitespace or other unusual characters. /var/run/arti socket is a valid filename, so unix:/var/run/arti socket is a valid representation.

We may add new schemas in the future. If we do, any new schema will begin with an ascii alphabetical character, and will consist only of ascii alphanumeric characters, the character -, and the character _.

§Network address representation

When representing a net::Socketaddr address as a string, we use the formats implemented by std::net::SocketAddr’s FromStr implementation. In contrast with the textual representations of Ipv4Addr and Ipv6Addr, these formats are not currently very well specified by Rust. Therefore we describe them here:

  • A SocketAddrV4 is encoded as:
  • A SocketAddrV6 is encoded as:
    • a left square bracket ([),
    • an IPv6 address,
    • optionally, a percent sign (%) and a 32-bit decimal integer
    • a right square bracket (]),
    • a colon (:),
    • a 16-bit decimal integer.

Note that the above implementation does not provide any way to encode the flowinfo member of a SocketAddrV6. Any flowinfo information set in an address will therefore be lost when the address is encoded.

TODO: We should try to get Rust’s stdlib specify these formats, so we don’t have to. There is an open PR at https://github.com/rust-lang/rust/pull/131790.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Inet(SocketAddr)

An IPv4 or IPv6 address on the internet.

§

Unix(SocketAddr)

A local AF_UNIX address.

(Note that unix::SocketAddr is unconstructable on platforms where it is not supported.)

Implementations§

Source§

impl SocketAddr

Source

pub fn display_lossy(&self) -> DisplayLossy<'_>

Return a wrapper object that can be used to display this address.

The resulting display might be lossy, depending on whether this address can be represented as a string.

The displayed format here is intentionally undocumented; it may change in the future.

Source

pub fn try_to_string(&self) -> Option<String>

If possible, return a qualified string representation for this address.

Otherwise return None.

Source

pub fn as_pathname(&self) -> Option<&Path>

If this address has an associated filesystem path, return that path.

Trait Implementations§

Source§

impl<'a> Arbitrary<'a> for SocketAddr

Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<SocketAddr, Error>

Generate an arbitrary value of Self from the given unstructured data. Read more
§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl Clone for SocketAddr

Source§

fn clone(&self) -> SocketAddr

Returns a copy 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 SocketAddr

Source§

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

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

impl From<SocketAddr> for SocketAddr

Source§

fn from(value: SocketAddr) -> SocketAddr

Converts to this type from the input type.
Source§

impl From<SocketAddr> for SocketAddr

Source§

fn from(value: SocketAddr) -> SocketAddr

Converts to this type from the input type.
Source§

impl FromStr for SocketAddr

Source§

type Err = AddrParseError

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

fn from_str(s: &str) -> Result<SocketAddr, <SocketAddr as FromStr>::Err>

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

impl NetStreamListener<SocketAddr> for Listener

Source§

type Stream = Stream

The type of connections returned by Self::incoming().
Source§

type Incoming = IncomingStreams

The type of [stream::Stream] returned by Self::incoming().
Source§

fn incoming(self) -> IncomingStreams

Wrap this listener into a new [stream::Stream] that yields streams and addresses.
Source§

fn local_addr(&self) -> IoResult<SocketAddr>

Return the local address that this listener is bound to.
Source§

impl PartialEq for SocketAddr

Source§

fn eq(&self, other: &SocketAddr) -> bool

Return true if two SocketAddrs are equal.

For Inet addresses, delegates to std::net::SocketAddr::eq.

For Unix addresses, treats two addresses as equal if any of the following is true:

  • Both addresses have the same path.
  • Both addresses are unnamed.
  • (Linux only) Both addresses have the same abstract name.

Addresses of different types are always unequal.

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.

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> NetStreamProvider<SocketAddr> for T

Source§

type Stream = Stream

The type for the connections returned by Self::connect().
Source§

type Listener = Listener

The type for the listeners returned by Self::listen().
Source§

fn connect<'life0, 'life1, 'async_trait>( &'life0 self, addr: &'life1 SocketAddr, ) -> Pin<Box<dyn Future<Output = Result<Stream, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, T: 'async_trait,

Launch a connection connection to a given socket address. Read more
Source§

fn listen<'life0, 'life1, 'async_trait>( &'life0 self, addr: &'life1 SocketAddr, ) -> Pin<Box<dyn Future<Output = Result<Listener, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, T: 'async_trait,

Open a listener on a given socket address.
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T