pub struct ProtocolStateMachine { /* private fields */ }
Expand description
Protocol state manager
Implementations§
Source§impl ProtocolStateMachine
impl ProtocolStateMachine
Sourcepub fn new(protocol_version: ProtocolVersion) -> Self
pub fn new(protocol_version: ProtocolVersion) -> Self
Create a new protocol state machine
Sourcepub fn with_config(
protocol_version: ProtocolVersion,
config: StateMachineConfig,
) -> Self
pub fn with_config( protocol_version: ProtocolVersion, config: StateMachineConfig, ) -> Self
Create with custom configuration
Sourcepub fn current_state(&self) -> &ProtocolState
pub fn current_state(&self) -> &ProtocolState
Get current state
Sourcepub fn active_sessions(&self) -> usize
pub fn active_sessions(&self) -> usize
Get active sessions count
Sourcepub fn protocol_version(&self) -> &ProtocolVersion
pub fn protocol_version(&self) -> &ProtocolVersion
Get protocol version
Sourcepub fn transition_to(
&mut self,
new_state: ProtocolState,
reason: String,
) -> Result<(), StateError>
pub fn transition_to( &mut self, new_state: ProtocolState, reason: String, ) -> Result<(), StateError>
Transition to a new state
Sourcepub fn create_session(
&mut self,
peer_id: Vec<u8>,
protocol_version: ProtocolVersion,
capabilities: Vec<String>,
) -> Result<Uuid, StateError>
pub fn create_session( &mut self, peer_id: Vec<u8>, protocol_version: ProtocolVersion, capabilities: Vec<String>, ) -> Result<Uuid, StateError>
Create a new session
Sourcepub fn update_session_state(
&mut self,
session_id: Uuid,
new_state: ProtocolState,
) -> Result<(), StateError>
pub fn update_session_state( &mut self, session_id: Uuid, new_state: ProtocolState, ) -> Result<(), StateError>
Update session state
Sourcepub fn get_session(&self, session_id: &Uuid) -> Option<&SessionInfo>
pub fn get_session(&self, session_id: &Uuid) -> Option<&SessionInfo>
Get session information
Sourcepub fn remove_session(&mut self, session_id: &Uuid) -> Option<SessionInfo>
pub fn remove_session(&mut self, session_id: &Uuid) -> Option<SessionInfo>
Remove a session
Sourcepub fn process_message(
&mut self,
message: &Message,
session_id: Option<Uuid>,
) -> Result<(), StateError>
pub fn process_message( &mut self, message: &Message, session_id: Option<Uuid>, ) -> Result<(), StateError>
Process a protocol message and update state accordingly
Sourcepub fn get_state_history(&self) -> &[StateTransition]
pub fn get_state_history(&self) -> &[StateTransition]
Get state transition history
Sourcepub fn get_sessions(&self) -> &HashMap<Uuid, SessionInfo>
pub fn get_sessions(&self) -> &HashMap<Uuid, SessionInfo>
Get all active sessions
Sourcepub fn is_healthy(&self) -> bool
pub fn is_healthy(&self) -> bool
Check if the state machine is in a healthy state
Sourcepub fn get_metrics(&self) -> StateMachineMetrics
pub fn get_metrics(&self) -> StateMachineMetrics
Get state machine metrics
Trait Implementations§
Source§impl Debug for ProtocolStateMachine
impl Debug for ProtocolStateMachine
Source§impl StateManager for ProtocolStateMachine
impl StateManager for ProtocolStateMachine
Source§fn init() -> Result<ProtocolStateMachine, StateError>
fn init() -> Result<ProtocolStateMachine, StateError>
Initialize protocol state.
Source§fn transition(&mut self, new_state: ProtocolState) -> Result<(), StateError>
fn transition(&mut self, new_state: ProtocolState) -> Result<(), StateError>
Transition to a new state.
Source§fn get_state(&self) -> &ProtocolState
fn get_state(&self) -> &ProtocolState
Get current state.
Source§fn validate_transition(&self, new_state: &ProtocolState) -> bool
fn validate_transition(&self, new_state: &ProtocolState) -> bool
Validate state transition.
Auto Trait Implementations§
impl Freeze for ProtocolStateMachine
impl RefUnwindSafe for ProtocolStateMachine
impl Send for ProtocolStateMachine
impl Sync for ProtocolStateMachine
impl Unpin for ProtocolStateMachine
impl UnwindSafe for ProtocolStateMachine
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 more