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: ExchangeKeyWhat identifies it.
protocol: ProtocolIdWhich protocol is speaking over it.
mrp: MrpIts 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: InstantWhen it was opened.
last_activity: InstantWhen 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: boolWhether 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
impl Exchange
Sourcepub fn new(
key: ExchangeKey,
protocol: ProtocolId,
params: MrpParams,
now: Instant,
) -> Self
pub fn new( key: ExchangeKey, protocol: ProtocolId, params: MrpParams, now: Instant, ) -> Self
Opens an exchange.
Sourcepub const fn touch(&mut self, now: Instant)
pub const fn touch(&mut self, now: Instant)
Records that a message arrived on this exchange or went out on it.
Sourcepub fn is_abandoned(&self, now: Instant, idle: Duration) -> bool
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.
Sourcepub fn to_peer(self, peer: Peer) -> Self
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.
Sourcepub fn is_transport_reliable(&self) -> bool
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.