pub struct SessionEndpoint { /* private fields */ }Expand description
Point-to-point session endpoint with state machine. A point-to-point session endpoint.
This is the common building block for all session types. It encapsulates:
- Identity (session_id, instance_id)
- State machine (control role, attachment, phase)
- Communication (message receive, state publication)
The endpoint starts in Neutral + Unattached state by default.
Implementations§
Source§impl SessionEndpoint
impl SessionEndpoint
Sourcepub fn new(
session_id: SessionId,
instance_id: InstanceId,
transport: Arc<MessageTransport>,
msg_rx: Receiver<SessionMessage>,
) -> Self
pub fn new( session_id: SessionId, instance_id: InstanceId, transport: Arc<MessageTransport>, msg_rx: Receiver<SessionMessage>, ) -> Self
Create a new endpoint in Neutral + Unattached state.
Sourcepub fn new_attached(
session_id: SessionId,
instance_id: InstanceId,
peer: InstanceId,
role: ControlRole,
phase: SessionPhase,
transport: Arc<MessageTransport>,
msg_rx: Receiver<SessionMessage>,
) -> Self
pub fn new_attached( session_id: SessionId, instance_id: InstanceId, peer: InstanceId, role: ControlRole, phase: SessionPhase, transport: Arc<MessageTransport>, msg_rx: Receiver<SessionMessage>, ) -> Self
Create a new endpoint with pre-attached state.
Used when creating a session that is already attached to a peer (e.g., ResponderSession which is pre-attached to the initiator).
Sourcepub fn session_id(&self) -> SessionId
pub fn session_id(&self) -> SessionId
Get the session ID.
Sourcepub fn instance_id(&self) -> InstanceId
pub fn instance_id(&self) -> InstanceId
Get this endpoint’s instance ID.
Sourcepub fn control_role(&self) -> ControlRole
pub fn control_role(&self) -> ControlRole
Get the current control role.
Sourcepub fn is_attached(&self) -> bool
pub fn is_attached(&self) -> bool
Check if a peer is attached.
Sourcepub fn peer(&self) -> Option<InstanceId>
pub fn peer(&self) -> Option<InstanceId>
Get the attached peer’s instance ID.
Sourcepub fn phase(&self) -> SessionPhase
pub fn phase(&self) -> SessionPhase
Get the current session phase.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Check if the session is in a terminal state.
Sourcepub fn set_phase(&mut self, phase: SessionPhase)
pub fn set_phase(&mut self, phase: SessionPhase)
Set the session phase.
Sourcepub fn set_control_role(&mut self, role: ControlRole)
pub fn set_control_role(&mut self, role: ControlRole)
Set the control role.
Use this for direct role changes (e.g., when processing YieldControl or AcquireControl messages).
Sourcepub fn accept_attachment(&mut self, peer: InstanceId, role: ControlRole)
pub fn accept_attachment(&mut self, peer: InstanceId, role: ControlRole)
Accept an attachment from a peer.
Transitions from Unattached to Attached and sets the control role.
Sourcepub fn detach(&mut self) -> Option<InstanceId>
pub fn detach(&mut self) -> Option<InstanceId>
Detach from the current peer.
Returns the detached peer’s instance ID if there was one.
Sourcepub fn yield_control(&mut self) -> Result<()>
pub fn yield_control(&mut self) -> Result<()>
Yield control to peer.
Transitions from Controller to Neutral.
Returns Err if not currently Controller.
Sourcepub fn acquire_control(&mut self) -> Result<()>
pub fn acquire_control(&mut self) -> Result<()>
Acquire control from peer.
Transitions from Neutral or Controllee to Controller.
The peer must be in Neutral state for this to succeed.
Sourcepub fn peer_yielded_control(&mut self)
pub fn peer_yielded_control(&mut self)
Handle a peer yielding control to us.
Transitions to Neutral (peer has yielded, we can now acquire if we want).
Sourcepub fn peer_acquired_control(&mut self) -> Result<()>
pub fn peer_acquired_control(&mut self) -> Result<()>
Handle a peer acquiring control.
Transitions from Neutral to Controllee.
Sourcepub async fn recv(&mut self) -> Option<SessionMessage>
pub async fn recv(&mut self) -> Option<SessionMessage>
Receive the next message.
Returns None when the channel is closed.
Sourcepub fn try_recv(&mut self) -> Result<SessionMessage, TryRecvError>
pub fn try_recv(&mut self) -> Result<SessionMessage, TryRecvError>
Try to receive a message without blocking.
Sourcepub async fn send_attach(
&self,
peer: InstanceId,
as_role: ControlRole,
) -> Result<()>
pub async fn send_attach( &self, peer: InstanceId, as_role: ControlRole, ) -> Result<()>
Send an attach message to a peer.
Sourcepub async fn send_detach(&self) -> Result<()>
pub async fn send_detach(&self) -> Result<()>
Send a detach message to the current peer.
Sourcepub async fn send_yield_control(&self) -> Result<()>
pub async fn send_yield_control(&self) -> Result<()>
Send yield control message to peer.
Sourcepub async fn send_acquire_control(&self) -> Result<()>
pub async fn send_acquire_control(&self) -> Result<()>
Send acquire control message to peer.
Sourcepub async fn send_to(&self, peer: InstanceId, msg: SessionMessage) -> Result<()>
pub async fn send_to(&self, peer: InstanceId, msg: SessionMessage) -> Result<()>
Send a message to a specific peer.
Sourcepub async fn send(&self, msg: SessionMessage) -> Result<()>
pub async fn send(&self, msg: SessionMessage) -> Result<()>
Send a message to the currently attached peer.
Sourcepub fn publish_state(&self, g2_blocks: Vec<BlockInfo>, g3_pending: usize)
pub fn publish_state(&self, g2_blocks: Vec<BlockInfo>, g3_pending: usize)
Publish the current state snapshot.
This updates all watchers with the new state.
Sourcepub fn publish_state_with_layer_range(
&self,
g2_blocks: Vec<BlockInfo>,
g3_pending: usize,
layer_range: Option<Range<usize>>,
)
pub fn publish_state_with_layer_range( &self, g2_blocks: Vec<BlockInfo>, g3_pending: usize, layer_range: Option<Range<usize>>, )
Publish state with layer range information.
Used for layerwise transfer where specific layers are ready.
Sourcepub fn state_rx(&self) -> Receiver<SessionStateSnapshot>
pub fn state_rx(&self) -> Receiver<SessionStateSnapshot>
Get a receiver for state updates.
Returns a watch receiver that will receive state snapshots whenever they are published.
Sourcepub fn transport(&self) -> &Arc<MessageTransport> ⓘ
pub fn transport(&self) -> &Arc<MessageTransport> ⓘ
Get the transport for direct access (for legacy interop).
Auto Trait Implementations§
impl !RefUnwindSafe for SessionEndpoint
impl !UnwindSafe for SessionEndpoint
impl Freeze for SessionEndpoint
impl Send for SessionEndpoint
impl Sync for SessionEndpoint
impl Unpin for SessionEndpoint
impl UnsafeUnpin for SessionEndpoint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);