pub struct ProtocolVersionManager { /* private fields */ }Expand description
Central registry and negotiation engine for protocol versions.
Peers register their local ProtocolDescriptors and then call negotiate
when a remote peer’s descriptor arrives. The manager updates internal
statistics for every attempt.
Implementations§
Source§impl ProtocolVersionManager
impl ProtocolVersionManager
Sourcepub fn register(&mut self, descriptor: ProtocolDescriptor) -> bool
pub fn register(&mut self, descriptor: ProtocolDescriptor) -> bool
Register a local ProtocolDescriptor.
Returns true if this is a new registration, false if a descriptor
with the same name already existed and was overwritten.
Sourcepub fn negotiate(
&mut self,
protocol: &str,
remote: &ProtocolDescriptor,
) -> Option<NegotiationResult>
pub fn negotiate( &mut self, protocol: &str, remote: &ProtocolDescriptor, ) -> Option<NegotiationResult>
Attempt to negotiate with a remote peer’s ProtocolDescriptor.
Returns Some(NegotiationResult) on success, None when:
- The protocol is not registered locally, or
- The versions are
Incompatiblein both directions.
Compatibility check flow:
- We check the remote version against our local descriptor’s
min_compatiblefloor. - We also check our local version against the remote descriptor’s
min_compatiblefloor — we must be acceptable to them too. - If both checks pass, a
NegotiationResultis produced.
Agreed version selection:
The session runs at min(local.version, remote.version) — the older of
the two — ensuring that neither side uses features unavailable to the
other.
Sourcepub fn find_common_features(local: &[String], remote: &[String]) -> Vec<String>
pub fn find_common_features(local: &[String], remote: &[String]) -> Vec<String>
Compute the intersection of two feature sets, preserving the order of the local side.
Sourcepub fn get_descriptor(&self, protocol: &str) -> Option<&ProtocolDescriptor>
pub fn get_descriptor(&self, protocol: &str) -> Option<&ProtocolDescriptor>
Look up the registered descriptor for a protocol by name.
Sourcepub fn is_registered(&self, protocol: &str) -> bool
pub fn is_registered(&self, protocol: &str) -> bool
Return true if a descriptor for protocol has been registered.
Sourcepub fn supported_protocols(&self) -> Vec<&str>
pub fn supported_protocols(&self) -> Vec<&str>
Return all registered protocol names as string slices.
Sourcepub fn stats(&self) -> &VersionStats
pub fn stats(&self) -> &VersionStats
Read-only view of the accumulated negotiation statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ProtocolVersionManager
impl RefUnwindSafe for ProtocolVersionManager
impl Send for ProtocolVersionManager
impl Sync for ProtocolVersionManager
impl Unpin for ProtocolVersionManager
impl UnsafeUnpin for ProtocolVersionManager
impl UnwindSafe for ProtocolVersionManager
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more