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§
Sourcefn protocol(&self) -> ProtocolSpec
fn protocol(&self) -> ProtocolSpec
Returns the protocol this handler supports.
Sourcefn 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>>
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:
- Perform the protocol-specific handshake (e.g., HTTP CONNECT, SOCKS5 greeting)
- Request connection to the specified target
- 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§
Sourcefn 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>>>
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".