Skip to main content

Exchange

Struct Exchange 

Source
pub struct Exchange {
    pub key: ExchangeKey,
    pub protocol: ProtocolId,
    pub mrp: Mrp,
    pub peer: Option<Peer>,
    pub opened: Instant,
    pub last_activity: Instant,
    pub ephemeral: bool,
}
Expand description

One open exchange.

Fields§

§key: ExchangeKey

What identifies it.

§protocol: ProtocolId

Which protocol is speaking over it.

§mrp: Mrp

Its reliability state.

§peer: Option<Peer>

Where the peer is, once a message has arrived from it or the caller has said.

It decides two things: where a reply goes, and — per Core §4.12.4 — whether MRP runs on this exchange at all, since BTP and TCP carry their own reliability.

§opened: Instant

When it was opened.

§last_activity: Instant

When a message last arrived on it or went out on it.

This, not Exchange::opened, is what ExchangeTable::reap judges: a chunked read or a BDX transfer is legitimately long-lived, and reaping by age would cut it off mid-transfer. What must not survive is an exchange nothing is using.

§ephemeral: bool

Whether this is §4.10.5.2’s ephemeral exchange.

“Create an ephemeral exchange from the incoming message and send an immediate standalone acknowledgement … The message SHALL NOT be forwarded to the upper layer … The ephemeral exchange created for such duplicate or unknown messages with R Flag set is automatically closed in Standalone acknowledgement processing.”

It exists for exactly one reason: a reliable message this node cannot act on still owes its sender an acknowledgement, or the sender retransmits it five times. Holding a real exchange open to do that is what lets a stranger fill the table.

Implementations§

Source§

impl Exchange

Source

pub fn new( key: ExchangeKey, protocol: ProtocolId, params: MrpParams, now: Instant, ) -> Self

Opens an exchange.

Source

pub const fn ephemeral(self) -> Self

The same exchange, marked ephemeral (§4.10.5.2).

Source

pub const fn touch(&mut self, now: Instant)

Records that a message arrived on this exchange or went out on it.

Source

pub fn is_abandoned(&self, now: Instant, idle: Duration) -> bool

Whether nothing has used this exchange for idle and nothing is pending on it.

§4.10.5.3 step 2 is the second half: “Wait for all pending retransmissions associated with the Exchange to complete. If the retransmission list for the Exchange is empty, remove the Exchange. Otherwise, leave the Exchange open and only close it once the retransmission list is empty.” An exchange still trying to deliver something is not abandoned, however quiet the peer has been.

Source

pub fn to_peer(self, peer: Peer) -> Self

The same exchange with its peer known from the start — what an initiator has, since it chose who to talk to.

Source

pub fn is_transport_reliable(&self) -> bool

Whether the transport underneath supplies its own reliability, so §4.12.4’s “SHOULD NOT set the R Flag” applies.

An exchange whose peer is not yet known is assumed to be on UDP: MRP is the default and the conservative choice, since an unnecessary acknowledgement costs a round trip while a missing one costs the message.

Trait Implementations§

Source§

impl Clone for Exchange

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Exchange

Source§

impl Debug for Exchange

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Exchange

Source§

impl PartialEq for Exchange

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Exchange

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.