Skip to main content

HopHandler

Trait HopHandler 

Source
pub trait HopHandler: Send + Sync {
    // Required methods
    fn protocol(&self) -> ProtocolSpec;
    fn handshake<'a>(
        &'a self,
        stream: BoxStream,
        target: &'a TargetAddr,
        hop: &'a ProxyHopSpec,
        hop_index: usize,
    ) -> Pin<Box<dyn Future<Output = Result<BoxStream, Box<dyn Error + Send + Sync>>> + Send + 'a>>;

    // Provided method
    fn open<'a>(
        &'a self,
        _endpoint: &'a EndpointSpec,
        _hop: &'a ProxyHopSpec,
        _target: &'a TargetAddr,
    ) -> Option<Pin<Box<dyn Future<Output = Result<BoxStream, Box<dyn Error + Send + Sync>>> + Send + 'a>>> { ... }
}
Expand description

Trait for performing protocol-specific handshakes through proxy hops.

Each protocol (HTTP CONNECT, SOCKS4, SOCKS5) provides an implementation of this trait to handle its specific handshake logic.

§Dyn Compatibility

This trait is dyn-compatible and can be used with Box<dyn HopHandler>.

Required Methods§

Source

fn protocol(&self) -> ProtocolSpec

Returns the protocol this handler supports.

Source

fn handshake<'a>( &'a self, stream: BoxStream, target: &'a TargetAddr, hop: &'a ProxyHopSpec, hop_index: usize, ) -> Pin<Box<dyn Future<Output = Result<BoxStream, Box<dyn Error + Send + Sync>>> + Send + 'a>>

Perform the protocol handshake over the given stream.

The handler should:

  1. Perform the protocol-specific handshake (e.g., HTTP CONNECT, SOCKS5 greeting)
  2. Request connection to the specified target
  3. Return the upgraded stream on success

hop_index is the 0-based position of this hop in the chain. Handlers that use connection pooling (e.g., H2) must include this value in pool keys to prevent cross-chain connection reuse.

Provided Methods§

Source

fn open<'a>( &'a self, _endpoint: &'a EndpointSpec, _hop: &'a ProxyHopSpec, _target: &'a TargetAddr, ) -> Option<Pin<Box<dyn Future<Output = Result<BoxStream, Box<dyn Error + Send + Sync>>> + Send + 'a>>>

Establish the transport for a hop whose protocol is not carried over a TCP socket (for example QUIC). TCP-backed handlers use the default.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§