pub struct PeerConnection { /* private fields */ }Expand description
A connection in the handshake phase, before authentication completes.
For outbound connections, we know the expected peer identity from config. For inbound connections, we learn the identity during the Noise handshake.
Implementations§
Source§impl PeerConnection
impl PeerConnection
Sourcepub fn outbound(
link_id: LinkId,
expected_identity: PeerIdentity,
current_time_ms: u64,
) -> Self
pub fn outbound( link_id: LinkId, expected_identity: PeerIdentity, current_time_ms: u64, ) -> Self
Create a new outbound connection (we are initiating).
For outbound, we know who we’re trying to reach from configuration.
The Noise handshake will be initialized when start_handshake is called.
Sourcepub fn inbound(link_id: LinkId, current_time_ms: u64) -> Self
pub fn inbound(link_id: LinkId, current_time_ms: u64) -> Self
Create a new inbound connection (they are initiating).
For inbound, we don’t know who they are until we decrypt their identity from Noise message 1.
Sourcepub fn inbound_with_transport(
link_id: LinkId,
transport_id: TransportId,
source_addr: TransportAddr,
current_time_ms: u64,
) -> Self
pub fn inbound_with_transport( link_id: LinkId, transport_id: TransportId, source_addr: TransportAddr, current_time_ms: u64, ) -> Self
Create a new inbound connection with transport information.
Used when processing msg1 where we know the transport and source address.
Sourcepub fn direction(&self) -> LinkDirection
pub fn direction(&self) -> LinkDirection
Get the connection direction.
Sourcepub fn handshake_state(&self) -> HandshakeState
pub fn handshake_state(&self) -> HandshakeState
Get the handshake state.
Sourcepub fn expected_identity(&self) -> Option<&PeerIdentity>
pub fn expected_identity(&self) -> Option<&PeerIdentity>
Get the expected/learned peer identity, if known.
Sourcepub fn is_outbound(&self) -> bool
pub fn is_outbound(&self) -> bool
Check if this is an outbound connection.
Sourcepub fn is_inbound(&self) -> bool
pub fn is_inbound(&self) -> bool
Check if this is an inbound connection.
Sourcepub fn is_in_progress(&self) -> bool
pub fn is_in_progress(&self) -> bool
Check if handshake is in progress.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Check if handshake completed.
Sourcepub fn started_at(&self) -> u64
pub fn started_at(&self) -> u64
When the connection started.
Sourcepub fn last_activity(&self) -> u64
pub fn last_activity(&self) -> u64
When the last activity occurred.
Sourcepub fn link_stats(&self) -> &LinkStats
pub fn link_stats(&self) -> &LinkStats
Get link statistics.
Sourcepub fn link_stats_mut(&mut self) -> &mut LinkStats
pub fn link_stats_mut(&mut self) -> &mut LinkStats
Get mutable link statistics.
Sourcepub fn our_index(&self) -> Option<SessionIndex>
pub fn our_index(&self) -> Option<SessionIndex>
Get our session index (if set).
Sourcepub fn set_our_index(&mut self, index: SessionIndex)
pub fn set_our_index(&mut self, index: SessionIndex)
Set our session index.
Sourcepub fn their_index(&self) -> Option<SessionIndex>
pub fn their_index(&self) -> Option<SessionIndex>
Get their session index (if known).
Sourcepub fn set_their_index(&mut self, index: SessionIndex)
pub fn set_their_index(&mut self, index: SessionIndex)
Set their session index.
Sourcepub fn transport_id(&self) -> Option<TransportId>
pub fn transport_id(&self) -> Option<TransportId>
Get the transport ID (if set).
Sourcepub fn set_transport_id(&mut self, id: TransportId)
pub fn set_transport_id(&mut self, id: TransportId)
Set the transport ID.
Sourcepub fn source_addr(&self) -> Option<&TransportAddr>
pub fn source_addr(&self) -> Option<&TransportAddr>
Get the source address (if known).
Sourcepub fn set_source_addr(&mut self, addr: TransportAddr)
pub fn set_source_addr(&mut self, addr: TransportAddr)
Set the source address.
Sourcepub fn remote_epoch(&self) -> Option<[u8; 8]>
pub fn remote_epoch(&self) -> Option<[u8; 8]>
Get the remote peer’s startup epoch (available after handshake).
Sourcepub fn set_handshake_msg1(&mut self, msg1: Vec<u8>, first_resend_at_ms: u64)
pub fn set_handshake_msg1(&mut self, msg1: Vec<u8>, first_resend_at_ms: u64)
Store the wire-format msg1 bytes for resend and schedule the first resend.
Sourcepub fn set_handshake_msg2(&mut self, msg2: Vec<u8>)
pub fn set_handshake_msg2(&mut self, msg2: Vec<u8>)
Store the wire-format msg2 bytes for resend on duplicate msg1.
Sourcepub fn handshake_msg1(&self) -> Option<&[u8]>
pub fn handshake_msg1(&self) -> Option<&[u8]>
Get the stored msg1 bytes (if any).
Sourcepub fn handshake_msg2(&self) -> Option<&[u8]>
pub fn handshake_msg2(&self) -> Option<&[u8]>
Get the stored msg2 bytes (if any).
Sourcepub fn resend_count(&self) -> u32
pub fn resend_count(&self) -> u32
Number of resends performed.
Sourcepub fn next_resend_at_ms(&self) -> u64
pub fn next_resend_at_ms(&self) -> u64
When the next resend is scheduled (Unix ms).
Sourcepub fn record_resend(&mut self, next_resend_at_ms: u64)
pub fn record_resend(&mut self, next_resend_at_ms: u64)
Record a resend and schedule the next one.
Sourcepub fn start_handshake(
&mut self,
our_keypair: Keypair,
epoch: [u8; 8],
current_time_ms: u64,
) -> Result<Vec<u8>, NoiseError>
pub fn start_handshake( &mut self, our_keypair: Keypair, epoch: [u8; 8], current_time_ms: u64, ) -> Result<Vec<u8>, NoiseError>
Start the handshake as initiator and generate message 1.
For outbound connections only. Returns the handshake message to send. The epoch is our startup epoch, encrypted into msg1 for restart detection.
Sourcepub fn receive_handshake_init(
&mut self,
our_keypair: Keypair,
epoch: [u8; 8],
message: &[u8],
current_time_ms: u64,
) -> Result<Vec<u8>, NoiseError>
pub fn receive_handshake_init( &mut self, our_keypair: Keypair, epoch: [u8; 8], message: &[u8], current_time_ms: u64, ) -> Result<Vec<u8>, NoiseError>
Initialize responder and process incoming message 1.
For inbound connections only. Returns the handshake message 2 to send. The epoch is our startup epoch, encrypted into msg2 for restart detection.
Sourcepub fn complete_handshake(
&mut self,
message: &[u8],
current_time_ms: u64,
) -> Result<(), NoiseError>
pub fn complete_handshake( &mut self, message: &[u8], current_time_ms: u64, ) -> Result<(), NoiseError>
Complete the handshake by processing message 2.
For outbound connections only (initiator completing handshake).
Sourcepub fn take_session(&mut self) -> Option<NoiseSession>
pub fn take_session(&mut self) -> Option<NoiseSession>
Take the completed Noise session.
Returns the NoiseSession for use in ActivePeer. Can only be called once after handshake completes.
Sourcepub fn has_session(&self) -> bool
pub fn has_session(&self) -> bool
Check if we have a completed session ready to take.
Sourcepub fn mark_failed(&mut self)
pub fn mark_failed(&mut self)
Mark handshake as failed.
Sourcepub fn is_timed_out(&self, current_time_ms: u64, timeout_ms: u64) -> bool
pub fn is_timed_out(&self, current_time_ms: u64, timeout_ms: u64) -> bool
Check if the connection has timed out.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PeerConnection
impl RefUnwindSafe for PeerConnection
impl Send for PeerConnection
impl Sync for PeerConnection
impl Unpin for PeerConnection
impl UnsafeUnpin for PeerConnection
impl UnwindSafe for PeerConnection
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
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