pub struct ProtocolDispatcher { /* private fields */ }Expand description
Dispatches a connection to the appropriate protocol handler based on sniffed initial bytes.
Implementations§
Source§impl ProtocolDispatcher
impl ProtocolDispatcher
Sourcepub fn new(
detectors: Vec<Box<dyn ProtocolDetector>>,
max_sniff: usize,
handshake_timeout: Duration,
) -> Self
pub fn new( detectors: Vec<Box<dyn ProtocolDetector>>, max_sniff: usize, handshake_timeout: Duration, ) -> Self
Creates a new ProtocolDispatcher.
§Arguments
detectors- Ordered list of protocol detectors. The first match wins.max_sniff- Maximum number of bytes to buffer for protocol detection.handshake_timeout- Maximum time to spend on protocol detection.
Sourcepub fn with_defaults(
detectors: Vec<Box<dyn ProtocolDetector>>,
handshake_timeout: Duration,
) -> Self
pub fn with_defaults( detectors: Vec<Box<dyn ProtocolDetector>>, handshake_timeout: Duration, ) -> Self
Creates a new ProtocolDispatcher with default sniff buffer size.
Sourcepub fn protocol_ids(&self) -> Vec<ProtocolId>
pub fn protocol_ids(&self) -> Vec<ProtocolId>
Returns the list of registered protocol IDs.
Sourcepub async fn dispatch(
&self,
stream: BoxStream,
) -> Result<(ProtocolId, ReplayStream), DispatchError>
pub async fn dispatch( &self, stream: BoxStream, ) -> Result<(ProtocolId, ReplayStream), DispatchError>
Dispatches a connection by sniffing its initial bytes and matching against registered protocol detectors.
Returns the matched protocol ID and a ReplayStream. The sniffed
prefix bytes are consumed by the detection reads performed here, so
the returned stream is positioned immediately after the sniffed
prefix — they are NOT replayed on subsequent reads. The sniffed
bytes remain available for inspection via ReplayStream::buffer
and ReplayStream::buffered_remaining.
Auto Trait Implementations§
impl !RefUnwindSafe for ProtocolDispatcher
impl !UnwindSafe for ProtocolDispatcher
impl Freeze for ProtocolDispatcher
impl Send for ProtocolDispatcher
impl Sync for ProtocolDispatcher
impl Unpin for ProtocolDispatcher
impl UnsafeUnpin for ProtocolDispatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more