Skip to main content

PeerConnection

Struct PeerConnection 

Source
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

Source

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.

Source

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.

Source

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.

Get the link ID.

Source

pub fn direction(&self) -> LinkDirection

Get the connection direction.

Source

pub fn handshake_state(&self) -> HandshakeState

Get the handshake state.

Source

pub fn expected_identity(&self) -> Option<&PeerIdentity>

Get the expected/learned peer identity, if known.

Source

pub fn is_outbound(&self) -> bool

Check if this is an outbound connection.

Source

pub fn is_inbound(&self) -> bool

Check if this is an inbound connection.

Source

pub fn is_in_progress(&self) -> bool

Check if handshake is in progress.

Source

pub fn is_complete(&self) -> bool

Check if handshake completed.

Source

pub fn is_failed(&self) -> bool

Check if handshake failed.

Source

pub fn started_at(&self) -> u64

When the connection started.

Source

pub fn last_activity(&self) -> u64

When the last activity occurred.

Source

pub fn duration(&self, current_time_ms: u64) -> u64

Connection duration so far.

Source

pub fn idle_time(&self, current_time_ms: u64) -> u64

Time since last activity.

Get link statistics.

Get mutable link statistics.

Source

pub fn our_index(&self) -> Option<SessionIndex>

Get our session index (if set).

Source

pub fn set_our_index(&mut self, index: SessionIndex)

Set our session index.

Source

pub fn their_index(&self) -> Option<SessionIndex>

Get their session index (if known).

Source

pub fn set_their_index(&mut self, index: SessionIndex)

Set their session index.

Source

pub fn transport_id(&self) -> Option<TransportId>

Get the transport ID (if set).

Source

pub fn set_transport_id(&mut self, id: TransportId)

Set the transport ID.

Source

pub fn source_addr(&self) -> Option<&TransportAddr>

Get the source address (if known).

Source

pub fn set_source_addr(&mut self, addr: TransportAddr)

Set the source address.

Source

pub fn remote_epoch(&self) -> Option<[u8; 8]>

Get the remote peer’s startup epoch (available after handshake).

Source

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.

Source

pub fn set_handshake_msg2(&mut self, msg2: Vec<u8>)

Store the wire-format msg2 bytes for resend on duplicate msg1.

Source

pub fn handshake_msg1(&self) -> Option<&[u8]>

Get the stored msg1 bytes (if any).

Source

pub fn handshake_msg2(&self) -> Option<&[u8]>

Get the stored msg2 bytes (if any).

Source

pub fn resend_count(&self) -> u32

Number of resends performed.

Source

pub fn next_resend_at_ms(&self) -> u64

When the next resend is scheduled (Unix ms).

Source

pub fn record_resend(&mut self, next_resend_at_ms: u64)

Record a resend and schedule the next one.

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn has_session(&self) -> bool

Check if we have a completed session ready to take.

Source

pub fn mark_failed(&mut self)

Mark handshake as failed.

Source

pub fn touch(&mut self, current_time_ms: u64)

Update last activity timestamp.

Source

pub fn is_timed_out(&self, current_time_ms: u64, timeout_ms: u64) -> bool

Check if the connection has timed out.

Trait Implementations§

Source§

impl Debug for PeerConnection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more