pub struct Gateway { /* private fields */ }Expand description
Connectivity boundary for one or more procs.
Implementations§
Source§impl Gateway
impl Gateway
Sourcepub fn current() -> Self
pub fn current() -> Self
Return the gateway for the current execution context.
This is the gateway attached to Proc::current().
Sourcepub fn uid(&self) -> &Uid
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).
Sourcepub fn default_location(&self) -> Location
pub fn default_location(&self) -> Location
The gateway’s default advertised location.
Sourcepub fn forwarder(&self) -> BoxedMailboxSender
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.
Sourcepub fn set_default_location(&self, location: Location)
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.
Sourcepub fn attach_peer(
&self,
uid: Uid,
sender: BoxedMailboxSender,
) -> Result<PeerAttachGuard, PeerAttachError>
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.
Sourcepub fn serve(
&self,
addr: ChannelAddr,
) -> Result<GatewayServeHandle, ChannelError>
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.
Sourcepub fn serve_duplex(
&self,
addr: ChannelAddr,
) -> Result<GatewayServeHandle, ChannelError>
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 inpeers(so source routes addressed toVia(peer_uid, ...)flow back through the duplex), replies with [AttachAck::Accepted] carryingVia(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
MessageEnvelopeenters 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.
Sourcepub fn serve_mux_with_listener(
&self,
addr: ChannelAddr,
listener: Option<TcpListener>,
) -> Result<GatewayServeHandle, ChannelError>
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).
Sourcepub fn serve_with_listener(
&self,
addr: ChannelAddr,
listener: Option<TcpListener>,
) -> Result<GatewayServeHandle, ChannelError>
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.
Sourcepub async fn serve_via(&self, addr: ChannelAddr) -> Result<GatewayServeHandle>
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 MailboxSender for Gateway
impl MailboxSender for Gateway
Source§fn post_unchecked(
&self,
envelope: MessageEnvelope,
return_handle: PortHandle<Undeliverable<MessageEnvelope>>,
)
fn post_unchecked( &self, envelope: MessageEnvelope, return_handle: PortHandle<Undeliverable<MessageEnvelope>>, )
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,
fn flush<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
post is synchronous (e.g. local in-process delivery).Source§fn post(
&self,
envelope: MessageEnvelope,
return_handle: PortHandle<Undeliverable<MessageEnvelope>>,
)
fn post( &self, envelope: MessageEnvelope, return_handle: PortHandle<Undeliverable<MessageEnvelope>>, )
Auto Trait Implementations§
impl Freeze for Gateway
impl RefUnwindSafe for Gateway
impl Send for Gateway
impl Sync for Gateway
impl Unpin for Gateway
impl UnsafeUnpin for Gateway
impl UnwindSafe for Gateway
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> BoxableMailboxSender for Twhere
T: MailboxSender + Clone + 'static,
impl<T> BoxableMailboxSender for Twhere
T: MailboxSender + Clone + 'static,
Source§fn boxed(&self) -> BoxedMailboxSender
fn boxed(&self) -> BoxedMailboxSender
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoBoxedMailboxSender for Twhere
T: MailboxSender + 'static,
impl<T> IntoBoxedMailboxSender for Twhere
T: MailboxSender + 'static,
Source§fn into_boxed(self) -> BoxedMailboxSender
fn into_boxed(self) -> BoxedMailboxSender
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].