Skip to main content

BridgeLoop

Struct BridgeLoop 

Source
pub struct BridgeLoop<U, C, S, K>{ /* private fields */ }
Expand description

Carries frames from a downstream peer, through a Bridge, back to it.

§The handshake happens here, not upstream

A bridge is a server to the client in front of it, so the loop answers initialize itself rather than letting the request reach the upstream. That is what keeps the client on the revision the bridge chose and tells it only the capabilities the bridge can actually serve; forwarding the handshake would hand the client the upstream’s own answers to both questions.

Before a handshake completes, a request is refused rather than forwarded — the specification requires it, and a bridge that forwarded one would speak for a client the upstream had never accepted.

notifications/initialized is answered locally and not forwarded. The upstream session was initialised when the bridge connected, before any client existed; forwarding this one would tell the upstream a second client had arrived, describing a session it already considers open.

§What a loop knows before a client arrives

Only one leg. The upstream negotiated with its server when the bridge connected; the client that supplies the other leg has not shown up yet, and inventing one would put a second opinion next to the real one. So agreement is None until a handshake completes, and a caller reporting on a bridge can tell “these two sides share nothing” from “no client ever arrived” — a distinction a placeholder leg would erase.

§Examples

use protocol_droid::application::bridge::{BridgeLoop, ToolResultCodec, Wiring};

let wiring = Wiring::new(upstream, policy, server, codec);
let mut bridge_loop = BridgeLoop::new(wiring, config, source, sink);

Implementations§

Source§

impl<U, C, S, K> BridgeLoop<U, C, S, K>

Source

pub const fn new( wiring: Wiring<U, C>, config: DownstreamConfig, source: S, sink: K, ) -> Self

A loop waiting for a client’s handshake.

Source

pub fn agreement(&self) -> Option<&Agreement>

What this bridge knows about its two sides.

None until a handshake completes: there is one leg until then, and an agreement needs two. Inventing the missing one would put a second, fabricated opinion next to the real one.

Source

pub const fn connected(&self) -> bool

Whether a client has completed a handshake.

Source

pub async fn run(&mut self) -> Result<LoopReport, LoopError>

Runs until the downstream peer’s stream ends.

The handshake is part of this, not a separate step the caller has to remember: a caller that forgot it would forward a client’s initialize upstream and answer them with someone else’s capabilities.

§Errors

LoopError when the downstream pipe itself fails, or when a reply the bridge built cannot be written. A refusal from the upstream peer is not an error here — it is answered to the client and counted in LoopReport::failed.

Trait Implementations§

Source§

impl<U, C, S, K> Debug for BridgeLoop<U, C, S, K>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<U, C, S, K> Freeze for BridgeLoop<U, C, S, K>
where Option<Wiring<U, C>>: Freeze, Option<Box<Bridge<U, C>>>: Freeze, S: Freeze, K: Freeze,

§

impl<U, C, S, K> RefUnwindSafe for BridgeLoop<U, C, S, K>

§

impl<U, C, S, K> Send for BridgeLoop<U, C, S, K>
where Option<Wiring<U, C>>: Send, Option<Box<Bridge<U, C>>>: Send,

§

impl<U, C, S, K> Sync for BridgeLoop<U, C, S, K>
where Option<Wiring<U, C>>: Sync, Option<Box<Bridge<U, C>>>: Sync,

§

impl<U, C, S, K> Unpin for BridgeLoop<U, C, S, K>
where Option<Wiring<U, C>>: Unpin, Option<Box<Bridge<U, C>>>: Unpin, S: Unpin, K: Unpin,

§

impl<U, C, S, K> UnsafeUnpin for BridgeLoop<U, C, S, K>

§

impl<U, C, S, K> UnwindSafe for BridgeLoop<U, C, S, K>

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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