Skip to main content

Gateway

Struct Gateway 

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

Connectivity boundary for one or more procs.

Implementations§

Source§

impl Gateway

Source

pub fn new() -> Self

Create a fresh unserved gateway with dial-based forwarding.

Source

pub fn isolated() -> Self

Create a fresh unserved local-only gateway.

Source

pub fn global() -> &'static Self

Return the process-wide global gateway.

Source

pub fn current() -> Self

Return the gateway for the current execution context.

This is the gateway attached to Proc::current().

Source

pub fn uid(&self) -> &Uid

This gateway’s stable uid. Peers route messages back to procs attached here by addressing them as Location::Via(this_uid, inner).

Source

pub fn default_location(&self) -> Location

The gateway’s default advertised location.

Source

pub fn forwarder(&self) -> BoxedMailboxSender

The outbound forwarder. Inbound traffic for destinations that don’t match a bound proc, route, or via peer is handed off to this sender.

Source

pub fn set_default_location(&self, location: Location)

Set the gateway’s fallback advertised location.

If any serves are active, the newest active normal serve or Gateway::serve_via session remains the advertised default. This location is used once all active serves stop.

Source

pub fn attach_peer( &self, uid: Uid, sender: BoxedMailboxSender, ) -> Result<PeerAttachGuard, PeerAttachError>

Register a gateway peer that is reachable through sender. Messages whose destination location has an outermost Location::Via hop carrying uid are forwarded through sender after peeling the hop. The returned guard removes the entry on drop.

Used by [Gateway::attach] and the duplex accept loop in Gateway::serve_duplex. Hosts also use this for spawned child proc gateways.

Returns PeerAttachError if a peer with the same uid is already attached.

Source

pub fn serve( &self, addr: ChannelAddr, ) -> Result<GatewayServeHandle, ChannelError>

Serve this gateway on the provided channel address.

When serving the first local ChannelAddr::any address, the gateway binds the local address that was reserved when the gateway was created. Local reservation is separate from local binding so a gateway can have a stable location before it has a runtime available to run a server. Later local any serves allocate fresh local ports, so the gateway can have multiple active local servers.

Serving updates the gateway’s default location to the newly served address. When that server stops, the default location falls back to the previous active normal serve or serve_via session, or to the reserved fallback location when no serve remains.

Source

pub fn serve_duplex( &self, addr: ChannelAddr, ) -> Result<GatewayServeHandle, ChannelError>

Open a duplex endpoint that accepts both regular inbound envelope traffic and gateway-attach handshakes from peers.

On each connection the first message determines the branch:

  • an [AttachRequest] control envelope enters the attach branch — this gateway records the peer’s uid in peers (so source routes addressed to Via(peer_uid, ...) flow back through the duplex), replies with [AttachAck::Accepted] carrying Via(peer_uid, default_location), and serves remaining traffic from the duplex into this gateway. If the peer cannot be registered, it replies with [AttachAck::Rejected] and closes the connection.
  • a regular MessageEnvelope enters the inbound branch and is served straight through.

Returns a GatewayServeHandle of kind ServeDuplex. The accept loop respects .stop("reason").

Errors if addr’s transport cannot carry the duplex protocol (e.g. local transport). Callers that may be handed a non-duplex address should branch on ChannelTransport::supports_duplex and use [serve] instead.

Source

pub fn serve_mux_with_listener( &self, addr: ChannelAddr, listener: Option<TcpListener>, ) -> Result<GatewayServeHandle, ChannelError>

Serve this gateway on addr (optionally with a pre-bound TCP listener) using a muxed listener: simplex clients (dialed via channel::dial) and duplex attach clients (dialed via channel::duplex::dial) share one address, demultiplexed at the link layer by channel::serve_mux.

Simplex traffic is served straight into this gateway; duplex connections run the same [AttachWire] accept path as serve_duplex — i.e. there is a single attach protocol regardless of whether a frontend is muxed or a plain duplex endpoint. Requires a net transport (serve_mux rejects non-net addresses).

Like serve_with_listener, this registers the bound address as an active serve location (so the gateway delivers frontend-addressed traffic in-process and adopts it as the default location).

Source

pub fn serve_with_listener( &self, addr: ChannelAddr, listener: Option<TcpListener>, ) -> Result<GatewayServeHandle, ChannelError>

Serve this gateway on addr, optionally using an already-bound listener.

This chooses a duplex accept loop for duplex-capable transports and a simplex mailbox receiver otherwise. Serving updates the gateway’s advertised default location to the concrete bound address. Callers that need to construct procs using that address can call Gateway::default_location after this returns.

Source

pub async fn serve_via(&self, addr: ChannelAddr) -> Result<GatewayServeHandle>

Connect this gateway to a peer gateway’s [serve_duplex] endpoint using the attach handshake.

Dials addr, sends this gateway’s uid as [AttachRequest], receives [AttachAck::Accepted] with the via location the peer assigned, sets that location as this gateway’s [default_location] (so every address handed out by this gateway carries the via prefix), installs the duplex sender as this gateway’s outbound forwarder, and serves inbound traffic from the duplex locally. If the peer returns [AttachAck::Rejected], the rejection reason is returned as an error.

Multiple serve_via sessions may be active. The newest active normal serve or serve_via session is this gateway’s advertised default location, while older active locations remain valid. The newest active serve_via supplies the outbound forwarder.

Trait Implementations§

Source§

impl Clone for Gateway

Source§

fn clone(&self) -> Gateway

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 Gateway

Source§

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

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

impl MailboxSender for Gateway

Source§

fn post_unchecked( &self, envelope: MessageEnvelope, return_handle: PortHandle<Undeliverable<MessageEnvelope>>, )

Raw transport: no policy.
Source§

fn flush<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Wait until all messages previously posted through this sender have been delivered (wire-acked) or confirmed undeliverable. The default implementation is a no-op, appropriate for senders whose post is synchronous (e.g. local in-process delivery).
Source§

fn post( &self, envelope: MessageEnvelope, return_handle: PortHandle<Undeliverable<MessageEnvelope>>, )

Apply hop semantics (TTL decrement; undeliverable on 0), then delegate to transport.

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> BoxableMailboxSender for T
where T: MailboxSender + Clone + 'static,

Source§

fn boxed(&self) -> BoxedMailboxSender

A boxed clone of this MailboxSender.
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.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

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> IntoBoxedMailboxSender for T
where T: MailboxSender + 'static,

Source§

fn into_boxed(self) -> BoxedMailboxSender

Rehome this MailboxSender into a BoxedMailboxSender.
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
Source§

impl<T> MailboxServer for T
where T: MailboxSender + Clone + Sync + Send + 'static,

Source§

fn serve( self, rx: impl Rx<MessageEnvelope> + Send + 'static, ) -> MailboxServerHandle

Serve the provided port on the given channel on this sender on a background task which may be joined with the returned handle. The task fails on any send error.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> PortSender for T
where T: MailboxSender + ?Sized,

Source§

fn serialize_and_send<M: RemoteMessage>( &self, port: &PortRef<M>, message: M, return_handle: PortHandle<Undeliverable<MessageEnvelope>>, ) -> Result<(), MailboxSenderError>

Deliver a message to the provided port.
Source§

fn serialize_and_send_once<M: RemoteMessage>( &self, once_port: OncePortRef<M>, message: M, return_handle: PortHandle<Undeliverable<MessageEnvelope>>, ) -> Result<(), MailboxSenderError>

Deliver a message to a one-shot port, consuming the provided port, which is not reusable.
§

impl<T> QuoteExt for T
where T: ?Sized,

§

fn push_quoted<'q, Q, S>(&mut self, _q: Q, s: S)
where Q: QuoteInto<T>, S: Into<Quotable<'q>>,

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

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

§

fn vzip(self) -> V

§

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> Allocation for T
where T: RefUnwindSafe + Send + Sync,

§

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

§

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

Source§

impl<M> Message for M
where M: Send + Sync + 'static,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,