Skip to main content

Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

Sans-I/O session driver.

Implementations§

Source§

impl Session

Source

pub fn new() -> Self

Construct a fresh, unconnected session with default timeouts.

Source

pub fn with_response_timeout(self, timeout: Duration) -> Self

Set the per-attempt response timeout. Retransmits fire after this long without an ack.

Source

pub fn with_total_timeout(self, timeout: Duration) -> Self

Set the total budget for a single packet across all retransmits. When this elapses, the packet is dropped and Event::Timeout is emitted.

Source

pub fn response_timeout(&self) -> Duration

Current per-attempt response timeout. Adapters wrap their inbound reads in this so Self::tick can fire even when the transport stays idle.

Source

pub fn total_timeout(&self) -> Duration

Current total per-packet budget across all retransmits.

Source

pub fn is_synced(&self) -> bool

True once an ss handshake reply has been received.

Source

pub fn max_block_size(&self) -> Option<u16>

Device-advertised maximum payload bytes per packet, set during the SYNC handshake.

Source

pub fn protocol_version(&self) -> Option<&str>

Device-advertised protocol version, set during the SYNC handshake.

Source

pub fn current_sync(&self) -> u8

Current sync counter value. Diagnostic accessor used in tests; not load-bearing for protocol clients.

Source

pub fn has_pending(&self) -> bool

True if a packet is currently in flight (sent, awaiting ack).

Source

pub fn reset(&mut self)

Reset the session to its construction baseline.

Drops any in-flight packet, queued packets, pending outbound bytes, pending events, and inbound buffer; clears the sync counter, sync state, and device-advertised values. Timeouts (response_timeout / total_timeout) are preserved.

Use this after observing Event::OutOfSync before calling connect again: the BFT protocol has no way to resynchronise mid-stream, so the only recovery path is to clear local state and redo the handshake from scratch.

Source

pub fn connect(&mut self, now: Instant)

Queue the SYNC control packet (protocol=0, packet_type=1). The caller should already have written the ASCII trigger b"M28B1\n" before calling this.

Source

pub fn send( &mut self, protocol: u8, packet_type: u8, payload: &[u8], now: Instant, )

Queue a binary packet for transmission.

If the session is idle (no packet in flight), the bytes are pushed to the outbound queue immediately. Otherwise the packet waits until the in-flight packet is acked.

§Panics

Panics if:

  • the session has not yet observed an ss handshake reply (is_synced() == false) — without a device-confirmed sync counter, the packet would go out with sync=0 and almost certainly desynchronise the protocol;
  • protocol > 15, packet_type > 15, or the payload is longer than codec::MAX_PAYLOAD.

All of the above are programmer errors; production callers should drive connect to completion, observe Event::Synced, and clamp payload size to max_block_size.

Source

pub fn poll_outbound(&mut self) -> Option<Vec<u8>>

Drain a single chunk of bytes the caller should write to the wire. Returns None when no more bytes are pending.

Source

pub fn feed(&mut self, bytes: &[u8], now: Instant)

Push received bytes from the wire. Bytes are accumulated until a newline-terminated ASCII line is recognised, at which point an Event is queued for poll_event.

now is used to timestamp any queued packet that gets dispatched as a side effect of an inbound ack — fully sans-I/O, no internal wall-clock reads.

Source

pub fn poll_event(&mut self) -> Option<Event>

Drain the next queued event. Returns None when the queue is empty.

Source

pub fn tick(&mut self, now: Instant)

Drive retransmit and total-timeout logic. Callers should call this at least as often as the per-attempt response timeout.

Trait Implementations§

Source§

impl Debug for Session

Source§

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

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

impl Default for Session

Source§

fn default() -> Self

Returns the “default value” for a type. 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, 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, 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.