pub struct ProtocolHandshaker {
pub local_offer: HandshakeOffer,
pub stats: Arc<HandshakeStats>,
}Expand description
Drives the protocol negotiation for a single local peer.
A ProtocolHandshaker is constructed once per local node and then
called for every incoming or outgoing connection to negotiate shared
parameters with the remote peer.
§Thread safety
The statistics field uses Arc<HandshakeStats> so the same stats object
can be shared across tasks/threads without requiring &mut self.
Fields§
§local_offer: HandshakeOfferThe offer that the local node will present to every remote peer.
stats: Arc<HandshakeStats>Accumulated handshake statistics.
Implementations§
Source§impl ProtocolHandshaker
impl ProtocolHandshaker
Sourcepub fn new(local_offer: HandshakeOffer) -> Self
pub fn new(local_offer: HandshakeOffer) -> Self
Create a new handshaker with the given local offer.
Sourcepub fn local_features(&self) -> Vec<FeatureFlag>
pub fn local_features(&self) -> Vec<FeatureFlag>
Return the feature flags advertised by the local peer.
Sourcepub fn negotiate(
&self,
remote: &HandshakeOffer,
) -> Result<HandshakeResult, HandshakeError>
pub fn negotiate( &self, remote: &HandshakeOffer, ) -> Result<HandshakeResult, HandshakeError>
Negotiate protocol parameters with a remote peer.
On success, returns a HandshakeResult describing the agreed
parameters. On failure, returns a HandshakeError.
§Steps
- Validate the remote offer.
- Check that major versions match.
- Intersect feature-flag bitmasks.
- Agree on the smaller of the two maximum frame sizes.
- Choose the lower of the two protocol versions as the agreed version so that the less-advanced peer is never asked to speak a version it cannot fully implement.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ProtocolHandshaker
impl RefUnwindSafe for ProtocolHandshaker
impl Send for ProtocolHandshaker
impl Sync for ProtocolHandshaker
impl Unpin for ProtocolHandshaker
impl UnsafeUnpin for ProtocolHandshaker
impl UnwindSafe for ProtocolHandshaker
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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