Skip to main content

TransparentProxy

Struct TransparentProxy 

Source
pub struct TransparentProxy {
    config: ProxyConfig,
    observer: Arc<dyn ProxyObserver>,
    hook: Arc<dyn ProxyHook>,
    cancel: CancellationToken,
    next_session_id: AtomicU64,
    control: Arc<ControlPlane>,
    client_socket: Option<Arc<dyn AsyncUdpSocket>>,
}
Expand description

A transparent MoQT proxy that accepts client connections and forwards traffic to an upstream relay.

Each accepted connection spawns a ProxySession that handles bidirectional stream forwarding with inline MoQT frame parsing. The client-facing transport (raw QUIC vs WebTransport) is chosen by the client via ALPN and dispatched automatically — no configuration required.

Fields§

§config: ProxyConfig§observer: Arc<dyn ProxyObserver>§hook: Arc<dyn ProxyHook>§cancel: CancellationToken§next_session_id: AtomicU64§control: Arc<ControlPlane>

What a ProxyControl reads and what every session registers with.

Constructed with the proxy rather than with the listener, because TransparentProxy::control has to answer before run() is awaited: a caller that owns the proxy is usually the caller about to give up its thread of control to the accept loop, so a handle that could only be taken afterwards could not be taken at all.

§client_socket: Option<Arc<dyn AsyncUdpSocket>>

The socket the client-facing endpoint is bound over, when the caller supplied one.

None — the ordinary case — makes run() bind its own socket at ListenerConfig::bind_addr, which is what this proxy has always done. Some(_) is set only by TransparentProxy::set_impaired_socket — named in plain code font because it exists only under the impair feature, so a link to it from this always-compiled field would not resolve — which is also where the handle that arms it is recorded, so the socket and the thing that impairs it can only arrive together.

Implementations§

Source§

impl TransparentProxy

Source

pub fn new(config: ProxyConfig, observer: Arc<dyn ProxyObserver>) -> Self

Create a new proxy with the given configuration and observer.

Source

pub fn with_hook( config: ProxyConfig, observer: Arc<dyn ProxyObserver>, hook: Arc<dyn ProxyHook>, ) -> Self

Create a new proxy with a custom hook for frame mutation.

Source

pub fn cancel_token(&self) -> CancellationToken

Returns a cancellation token that can be used to trigger shutdown.

Source

pub fn control(&self) -> ProxyControl

A handle onto this proxy — the address it bound, and the sessions it is running.

Callable at any point after the proxy is constructed, and meant to be called before TransparentProxy::run is awaited: run() does not return until the proxy is finished, so a caller that waited for it would never get a handle to a proxy that was doing anything. Every question a handle answers is defined for a proxy that has not bound yet — see ProxyControl.

Cheap, and cheap to keep: the handle is one Arc onto state the proxy already holds, and clones of it share that state rather than copying it.

Source

pub async fn run(&self) -> Result<(), ProxyError>

Run the proxy accept loop. Blocks until cancelled or a fatal listener error occurs.

Source

fn dispatch(&self, accepted: AcceptedConn)

Spawn a session for an accepted connection, picking the right entry point based on the negotiated transport.

Source

fn next_session_id(&self) -> SessionId

Source

fn emit_session_started( &self, session_id: SessionId, client_addr: SocketAddr, client_transport: &str, )

Source

fn new_session( &self, session_id: SessionId, client_alpn: Vec<u8>, ) -> ProxySession

Source

fn listener_config(&self) -> ListenerConfig

A fresh ListenerConfig carrying every field of this proxy’s template — every field but one, and the exception is stated at the pattern below rather than left to be noticed.

Source

fn session_config(&self) -> ProxySessionConfig

A fresh ProxySessionConfig carrying every field of this proxy’s template, built once per accepted connection.

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

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