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
impl RmSession
Sourcepub fn new(config: RmConfig, details: ResourceManagerDetails) -> Self
pub fn new(config: RmConfig, details: ResourceManagerDetails) -> Self
A session for one resource, not yet opened.
Sourcepub fn set_inbound_policy(&mut self, policy: Box<dyn InboundPolicy + Send>)
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.
Sourcepub fn state(&self) -> &SessionState
pub fn state(&self) -> &SessionState
Where the session has got to.
Sourcepub fn profile(&self) -> WireProfile
pub fn profile(&self) -> WireProfile
The wire profile in use.
Sourcepub fn negotiated_version(&self) -> Option<&ProtocolVersion>
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.
Sourcepub fn stats(&self) -> Stats
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.
Sourcepub fn registry(&self) -> &Registry
pub fn registry(&self) -> &Registry
Everything this session has learned, for a validator or a user interface.
Sourcepub fn open(&mut self, now: Timestamp)
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.
Sourcepub fn poll_transmit(&mut self) -> Option<Outgoing>
pub fn poll_transmit(&mut self) -> Option<Outgoing>
The next message to put on the wire.
Sourcepub fn poll_event(&mut self) -> Option<RmEvent>
pub fn poll_event(&mut self) -> Option<RmEvent>
The next thing the application needs to know.
Sourcepub fn poll_timeout(&self) -> Option<Timestamp>
pub fn poll_timeout(&self) -> Option<Timestamp>
When handle_timeout next has something to do.
Sourcepub fn handle_text(&mut self, text: &str, now: Timestamp) -> Inbound
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.
Sourcepub fn handle_message(&mut self, message: Message, now: Timestamp) -> Inbound
pub fn handle_message(&mut self, message: Message, now: Timestamp) -> Inbound
Feed in one already-decoded message.
Sourcepub fn handle_timeout(&mut self, now: Timestamp)
pub fn handle_timeout(&mut self, now: Timestamp)
Let time pass: expire acknowledgements and activate scheduled descriptions.
Sourcepub fn transport_closed(&mut self, now: Timestamp)
pub fn transport_closed(&mut self, now: Timestamp)
The transport went away.
Sourcepub fn send(
&mut self,
message: impl Into<Message>,
now: Timestamp,
) -> Result<MessageHandle, SendError>
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.
Sourcepub fn instruction_status(
&mut self,
instruction_id: Id,
status: InstructionStatus,
now: Timestamp,
) -> Result<MessageHandle, SendError>
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.
Sourcepub fn request_session(
&mut self,
request: SessionRequestType,
diagnostic: Option<String>,
now: Timestamp,
) -> Result<MessageHandle, SendError>
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.
Trait Implementations§
Source§impl Session for RmSession
impl Session for RmSession
Source§fn handle_text(&mut self, text: &str, now: Timestamp) -> Inbound
fn handle_text(&mut self, text: &str, now: Timestamp) -> Inbound
Source§fn handle_message(&mut self, message: Message, now: Timestamp) -> Inbound
fn handle_message(&mut self, message: Message, now: Timestamp) -> Inbound
Source§fn handle_timeout(&mut self, now: Timestamp)
fn handle_timeout(&mut self, now: Timestamp)
Self::poll_timeout.