mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Store session state directly
This commit is contained in:
@@ -17,9 +17,7 @@ macro_rules! unshell_leaf {
|
||||
state: $State,
|
||||
outbox: $crate::protocol::LeafOutbox,
|
||||
$(
|
||||
$session_field: $crate::protocol::SessionFamily<
|
||||
<$Session as $crate::protocol::Session<$State>>::State,
|
||||
>,
|
||||
$session_field: $crate::protocol::SessionFamily<$Session>,
|
||||
)*
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ pub fn dispatch_session<L, S>(
|
||||
endpoint: &Endpoint,
|
||||
leaf_id: u32,
|
||||
leaf: &mut L,
|
||||
family: &mut SessionFamily<S::State>,
|
||||
family: &mut SessionFamily<S>,
|
||||
packet: Packet,
|
||||
outbox: &mut LeafOutbox,
|
||||
interface: &mut Option<&mut InterfaceStore>,
|
||||
@@ -215,7 +215,7 @@ pub fn dispatch_session<L, S>(
|
||||
pub fn update_session_family<L, S>(
|
||||
leaf_id: u32,
|
||||
leaf: &mut L,
|
||||
family: &mut SessionFamily<S::State>,
|
||||
family: &mut SessionFamily<S>,
|
||||
interface: &mut Option<&mut InterfaceStore>,
|
||||
) where
|
||||
S: Session<L>,
|
||||
@@ -338,7 +338,7 @@ pub fn flush_leaf_outbox(
|
||||
pub fn flush_session_family<L, S>(
|
||||
endpoint: &mut Endpoint,
|
||||
leaf_id: u32,
|
||||
family: &mut SessionFamily<S::State>,
|
||||
family: &mut SessionFamily<S>,
|
||||
interface: &mut Option<&mut InterfaceStore>,
|
||||
) where
|
||||
S: Session<L>,
|
||||
|
||||
+9
-17
@@ -9,26 +9,25 @@ use crate::interface::SessionView;
|
||||
///
|
||||
/// A session family maps one outer `procedure_id` to many live hook instances. The
|
||||
/// generated leaf owns packet grouping, retry-safe output flushing, and final cleanup;
|
||||
/// the session implementation owns only application behavior.
|
||||
/// the session value owns one hook's application behavior and mutable state.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// impl Session<MyLeafState> for MySession {
|
||||
/// impl Session<MyLeafState> for MySessionState {
|
||||
/// const PROCEDURE_ID: u32 = 7;
|
||||
/// type State = MySessionState;
|
||||
///
|
||||
/// fn init(
|
||||
/// leaf: &mut MyLeafState,
|
||||
/// packet: Packet,
|
||||
/// ctx: &mut SessionInit,
|
||||
/// ) -> Result<Self::State, SessionInitError> {
|
||||
/// ) -> Result<Self, SessionInitError> {
|
||||
/// Ok(MySessionState::from_open(leaf, packet, ctx))
|
||||
/// }
|
||||
///
|
||||
/// fn update(
|
||||
/// leaf: &mut MyLeafState,
|
||||
/// session: &mut Self::State,
|
||||
/// session: &mut Self,
|
||||
/// incoming: &mut PacketQueue,
|
||||
/// ctx: &mut SessionCtx<'_>,
|
||||
/// ) -> SessionStatus {
|
||||
@@ -39,23 +38,16 @@ use crate::interface::SessionView;
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub trait Session<L> {
|
||||
pub trait Session<L>: Sized {
|
||||
/// Outer packet procedure id used by every packet in this session family.
|
||||
const PROCEDURE_ID: u32;
|
||||
|
||||
/// Application state stored for one live hook.
|
||||
type State;
|
||||
|
||||
/// Creates one session state from a packet whose hook has no active session.
|
||||
/// Creates one session value from a packet whose hook has no active session.
|
||||
///
|
||||
/// The generated runtime derives all response routing from hook state. Session
|
||||
/// initialization therefore returns only application state or a protocol-level
|
||||
/// rejection; it never stores or receives a caller reply path.
|
||||
fn init(
|
||||
leaf: &mut L,
|
||||
packet: Packet,
|
||||
ctx: &mut SessionInit,
|
||||
) -> Result<Self::State, SessionInitError>;
|
||||
fn init(leaf: &mut L, packet: Packet, ctx: &mut SessionInit) -> Result<Self, SessionInitError>;
|
||||
|
||||
/// Advances one active hook session.
|
||||
///
|
||||
@@ -65,7 +57,7 @@ pub trait Session<L> {
|
||||
/// generated retry rules.
|
||||
fn update(
|
||||
leaf: &mut L,
|
||||
session: &mut Self::State,
|
||||
session: &mut Self,
|
||||
incoming: &mut PacketQueue,
|
||||
ctx: &mut SessionCtx<'_>,
|
||||
) -> SessionStatus;
|
||||
@@ -73,7 +65,7 @@ pub trait Session<L> {
|
||||
#[cfg(feature = "interface_ratatui")]
|
||||
fn render_ratatui(
|
||||
_: &L,
|
||||
_: &Self::State,
|
||||
_: &Self,
|
||||
_: &mut SessionView,
|
||||
_: &mut ratatui::Frame<'_>,
|
||||
_: ratatui::layout::Rect,
|
||||
|
||||
Reference in New Issue
Block a user