Skip to main content

Listener

Struct Listener 

Source
pub struct Listener { /* private fields */ }
Expand description

One externally reachable messaging namespace.

A Listener is a namespace, not a socket and not a transport: it owns the endpoint routing table and nothing else (master doc §3). Credentials belong to the individual bindings, because they are transport-specific — a QUIC binding needs a certificate and key, a future in-process or adapter binding needs neither — and because two interfaces of one service may legitimately present different certificates.

Implementations§

Source§

impl Listener

Source

pub async fn bind_quic( &self, addr: SocketAddr, tls: impl Into<ServerTls>, ) -> Result<Binding, Error>

Adds a native QUIC binding with its own server identity.

tls may be a bare crate::Identity — the binding then accepts anonymous peers — or a ServerTls that also requires clients to present an identity it trusts. The material is loaded and validated here, so a misconfigured certificate fails before the socket serves anything. Pass port 0 to let the OS choose; read it back with Binding::local_addr.

Several bindings may serve the same Listener, each with its own identity: the endpoints they expose are the same, the identities they present need not be.

Source

pub async fn bind_quic_socket( &self, socket: UdpSocket, tls: impl Into<ServerTls>, ) -> Result<Binding, Error>

Adds a native QUIC binding on a socket that is already bound.

For a process that received its socket rather than binding it: from its predecessor over SCM_RIGHTS after Binding::hand_over, or through socket activation. Otherwise it is exactly Listener::bind_quic.

The socket is taken as it is: weida neither binds it nor sets options on it, and Binding::local_addr reports the address it is bound to. The socket is an OS socket, so a binding made here is never on a simulated network.

A predecessor that called hand_over no longer reads the socket, so the successor may serve it at once; it calls Binding::take_over once its endpoints are registered.

Source

pub async fn bind_relay( &self, relay: &str, via: impl Into<ClientTls>, tls: impl Into<ServerTls>, ) -> Result<Binding, Error>

Serves this Listener’s endpoints through a relay, for a peer that can only dial out (crate::Relay, docs/PROTOCOL.md §9.6).

Dials relay, a weida://[relay-key@]host[:port]/.weida/relay address, on via’s terms and registers there under the key via presents, which therefore needs an identity. A dialler reaches the endpoints as weida+relay://<key>@[relay-key@]host[:port]/path, with QUIC and TLS end to end: tls is this side’s server identity and client trust, exactly as for Listener::bind_quic, and every endpoint sees the dialler’s own key, not the relay’s.

The registration is kept as a dialled address is: a lost relay is redialled and registered again under the runtime’s crate::ReconnectPolicy, reported on Binding::relay_events. The first registration’s failure is returned, and nothing is served then: Error::Rejected where the relay refused it.

Source

pub fn bind_inproc(&self, bus: &str) -> Result<LocalBinding, Error>

Binds this Listener’s endpoints on an in-process bus.

The counterpart of Listener::bind_quic for the transport that has no socket: weida+inproc://<bus>/<path> reaches the same endpoints from the same process, with the same frames, the same HELLO and the same negotiation, and without TLS or credentials (docs/PROTOCOL.md §2.1, decisions/0010 §4.1). The bus name is at most 256 bytes and unique within the process; binding a name twice fails with Error::AlreadyRegistered.

Source

pub fn bind_unix(&self, path: impl AsRef<Path>) -> Result<UnixBinding, Error>

Binds this Listener’s endpoints on an AF_UNIX socket.

SOCK_STREAM on a filesystem path, no TLS and no credentials of our own: the peer is proved by the kernel instead (decisions/0010 §4.4, §4.5). A live listener on the path is refused (ErrorKind::AddrInUse); a socket file a crash left behind is replaced. The socket is bound in a private 0700 directory next to path, given mode 0600 there rather than inheriting umask, and renamed into place, so it is never visible with another mode. The directory is still what makes that safe: whoever can write it can rename over the node afterwards (docs/research/ipc.md §1.2, §7), so path MUST live in a directory this process owns and no other user may write.

Connections are grouped into peers by decision 0012: the first connection is the peer, further ones carry its group token and are admitted only if the kernel credentials match.

Source

pub fn replier(&self, path: &str) -> Result<Replier, Error>

Registers a replier for path.

The path must be a valid endpoint path and must not already be registered on this listener.

Source

pub fn puller(&self, path: &str) -> Result<Puller, Error>

Registers a puller for path.

Pull binds and Push connects, mirroring Rep/Req. The path must be a valid endpoint path and must not already be registered on this listener, whatever pattern claimed it.

Source

pub fn publisher(&self, path: &str) -> Result<Publisher, Error>

Registers a publisher for path.

Pub binds and Sub connects. Nothing inbound is accepted on the path — the registration claims it exclusively — and subscriptions that arrived before this call are already recorded, so a publisher created after its subscribers still reaches them.

Source

pub fn radio(&self, path: &str) -> Result<Radio, Error>

Registers a radio for path (decisions/0034 §4.6).

RADIO binds and DISH connects. Nothing inbound is accepted on the path; a dish’s join is a SUBSCRIBE and lands in the radio. Every segment goes to the dishes joined when it opens, and each copy is dropped rather than waited for: by its successor, by the dish’s max_age, or by the dish’s byte budget.

Source

pub fn acceptor(&self, path: &str) -> Result<Acceptor, Error>

Registers a raw L0 acceptor for path.

Below the patterns: an acceptor takes both stream kinds on one path and hands them over tagged (crate::Incoming), leaving the shape of the conversation to the application. The path is claimed exactly like a replier’s or a puller’s.

Source

pub fn relay(&self) -> Result<Relay, Error>

Serves a relay on this Listener: hidden peers register through Listener::bind_relay, and diallers reach them through weida+relay:// addresses (Relay, docs/PROTOCOL.md §9.6).

Claims RELAY_PATH on every binding of this Listener, so a second call fails with Error::AlreadyRegistered. Each registration and each tunnel waits at Relay::accept for the application to admit or refuse it.

Source

pub fn pair(&self, path: &str) -> Result<Paired, Error>

Registers a bound paired endpoint for path.

PAIR is one connection and one peer, carrying one-way transfers in both directions (ARCHITECTURE.md §6b). It adds no wire vocabulary: a paired endpoint talks to a bare crate::Peer or Acceptor on the same path, which is the test that proves the pattern layer is API and nothing else.

The one-peer rule is enforced at dispatch: the first connection to send here claims the endpoint, and a stream from any other is refused with LIMIT_EXCEEDED while the first keeps working.

Source

pub fn respondent(&self, path: &str) -> Result<Respondent, Error>

Registers a respondent for path.

A survey question is an exchange, so a respondent’s route is byte-for-byte a replier’s: the same request route, the same accept queue, the same backpressure. What makes it a survey is entirely on the asking side — the fan-out and the deadline — so this pattern adds no routing and no wire vocabulary.

Source

pub fn bus( &self, path: &str, tls: impl Into<ClientTls>, ) -> Result<BusMember, Error>

Registers a bus member on path that dials the others on tls’s terms.

The only factory that takes both a path and dialling terms, because a bus member is the one role that is bound and dialling at once (ARCHITECTURE.md §6b): it accepts on its own path with a puller’s route and reaches the others with crate::BusMember::connect.

Trait Implementations§

Source§

impl Clone for Listener

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Listener

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Instrument for T

Source§

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

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

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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