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
impl TransparentProxy
Sourcepub fn new(config: ProxyConfig, observer: Arc<dyn ProxyObserver>) -> Self
pub fn new(config: ProxyConfig, observer: Arc<dyn ProxyObserver>) -> Self
Create a new proxy with the given configuration and observer.
Sourcepub fn with_hook(
config: ProxyConfig,
observer: Arc<dyn ProxyObserver>,
hook: Arc<dyn ProxyHook>,
) -> Self
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.
Sourcepub fn cancel_token(&self) -> CancellationToken
pub fn cancel_token(&self) -> CancellationToken
Returns a cancellation token that can be used to trigger shutdown.
Sourcepub fn control(&self) -> ProxyControl
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.
Sourcepub async fn run(&self) -> Result<(), ProxyError>
pub async fn run(&self) -> Result<(), ProxyError>
Run the proxy accept loop. Blocks until cancelled or a fatal listener error occurs.
Sourcefn dispatch(&self, accepted: AcceptedConn)
fn dispatch(&self, accepted: AcceptedConn)
Spawn a session for an accepted connection, picking the right entry point based on the negotiated transport.
fn next_session_id(&self) -> SessionId
fn emit_session_started( &self, session_id: SessionId, client_addr: SocketAddr, client_transport: &str, )
fn new_session( &self, session_id: SessionId, client_alpn: Vec<u8>, ) -> ProxySession
Sourcefn listener_config(&self) -> ListenerConfig
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.
Sourcefn session_config(&self) -> ProxySessionConfig
fn session_config(&self) -> ProxySessionConfig
A fresh ProxySessionConfig carrying every field of this proxy’s
template, built once per accepted connection.