Skip to main content

RmSession

Struct RmSession 

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

A Resource Manager’s side of one S2 session.

Sans-I/O: it never touches a socket and never reads a clock. Feed it text and a now, drain what it wants to send, drain what it wants to tell you.

use s2_kit::prelude::*;
use s2_kit::session::{RmConfig, RmSession};

let now: Timestamp = "2024-01-01T12:00:00Z".parse().unwrap();
let mut rm = RmSession::new(RmConfig::default(), details);
rm.open(now);

let hello = rm.poll_transmit().unwrap();
assert_eq!(hello.kind, MessageKind::Handshake);

Implementations§

Source§

impl RmSession

Source

pub fn new(config: RmConfig, details: ResourceManagerDetails) -> Self

A session for one resource, not yet opened.

Source

pub fn set_inbound_policy(&mut self, policy: Box<dyn InboundPolicy + Send>)

Install a hook consulted before every inbound message is acknowledged.

This is the only way to answer TEMPORARY_ERROR or PERMANENT_ERROR: the engine chooses every other status itself, synchronously, so that an acknowledgement can never be forgotten or delayed.

Source

pub fn state(&self) -> &SessionState

Where the session has got to.

Source

pub fn profile(&self) -> WireProfile

The wire profile in use.

Source

pub fn negotiated_version(&self) -> Option<&ProtocolVersion>

The version string the handshake settled on, exactly as it crossed the wire — or the pre-negotiated one under S2 Connect. None until then.

profile is what the codec reads with; this is what an operator greps for, and the evidence R2’s trigger is evaluated on: which string a peer actually selects.

Source

pub fn stats(&self) -> Stats

What this session has done, for an operator’s metrics rather than for the application: how many messages crossed, how many were refused, and how long the peer takes to answer.

Source

pub fn registry(&self) -> &Registry

Everything this session has learned, for a validator or a user interface.

Source

pub fn open(&mut self, now: Timestamp)

Begin. The Resource Manager speaks first.

With a handshake, this queues one. With a version already agreed — S2 Connect — it goes straight to sending the resource’s details, which is what S2C §Communication - JSON messages requires.

Source

pub fn poll_transmit(&mut self) -> Option<Outgoing>

The next message to put on the wire.

Source

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

The next thing the application needs to know.

Source

pub fn poll_timeout(&self) -> Option<Timestamp>

When handle_timeout next has something to do.

Source

pub fn handle_text(&mut self, text: &str, now: Timestamp) -> Inbound

Feed in one text frame. Never fails: every failure is answered and reported.

A frame that arrives after the session is over is ignored rather than answered: the transport is gone, so an acknowledgement queued for it is one nobody will ever read — and a closed session that keeps filling its outbox is a closed session that keeps growing. handle_message makes the same check; this one is for the frames that never get that far.

Source

pub fn handle_message(&mut self, message: Message, now: Timestamp) -> Inbound

Feed in one already-decoded message.

Source

pub fn handle_timeout(&mut self, now: Timestamp)

Let time pass: expire acknowledgements and activate scheduled descriptions.

Source

pub fn transport_closed(&mut self, now: Timestamp)

The transport went away.

Source

pub fn send( &mut self, message: impl Into<Message>, now: Timestamp, ) -> Result<MessageHandle, SendError>

Send a message.

Refused at the call site when the state table does not allow it, when it does not exist in the negotiated profile, or — unless validate_outbound is off — when it would only earn an INVALID_CONTENT in reply.

Source

pub fn instruction_status( &mut self, instruction_id: Id, status: InstructionStatus, now: Timestamp, ) -> Result<MessageHandle, SendError>

Report what became of an instruction.

The second of the two answers an instruction gets: the reception status said the message was read, this says what the household did about it.

Source

pub fn request_session( &mut self, request: SessionRequestType, diagnostic: Option<String>, now: Timestamp, ) -> Result<MessageHandle, SendError>

Ask the peer to end or restart the session.

Source

pub fn close(&mut self)

End the session locally.

Trait Implementations§

Source§

impl Debug for RmSession

Source§

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

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

impl Session for RmSession

Source§

type Event = RmEvent

What this side tells its application about.
Source§

fn open(&mut self, now: Timestamp)

Begin. Has no effect on a session that is already open.
Source§

fn handle_text(&mut self, text: &str, now: Timestamp) -> Inbound

Feed in one frame as it arrived from the transport.
Source§

fn handle_message(&mut self, message: Message, now: Timestamp) -> Inbound

Feed in one already-decoded message.
Source§

fn handle_timeout(&mut self, now: Timestamp)

Tell the session the time has reached Self::poll_timeout.
Source§

fn transport_closed(&mut self, now: Timestamp)

Tell the session its transport has gone.
Source§

fn poll_transmit(&mut self) -> Option<Outgoing>

Take the next frame to send, if any.
Source§

fn poll_event(&mut self) -> Option<RmEvent>

Take the next event for the application, if any.
Source§

fn poll_timeout(&self) -> Option<Timestamp>

When the session next needs to be woken, if ever.
Source§

fn state(&self) -> &SessionState

Where the session has got to.
Source§

fn negotiated_version(&self) -> Option<&ProtocolVersion>

The version string the handshake settled on, once it has.
Source§

fn registry(&self) -> &Registry

Everything the session has learned about its peer.
Source§

fn stats(&self) -> Stats

What this session has done, for an operator’s metrics.
Source§

fn close(&mut self)

Queue a close.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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