Remove session init context

This commit is contained in:
Michael Mikovsky
2026-06-01 11:33:17 -06:00
parent f2bc2d912d
commit 64e53c8cfe
2 changed files with 4 additions and 38 deletions
+2 -5
View File
@@ -4,7 +4,7 @@ use crate::{
interface::{InterfaceEventKind, InterfaceStore, InterfaceTarget},
protocol::{
Endpoint, Packet, PacketQueue, Procedure, ProcedureOut, Session, SessionCtx, SessionEntry,
SessionFamily, SessionInit, SessionInitError, SessionStatus,
SessionFamily, SessionInitError, SessionStatus,
},
};
@@ -147,10 +147,7 @@ pub fn dispatch_session<L, S>(
return;
};
let packet_path = packet.path.clone();
let mut init = SessionInit::new(hook_id, packet_path);
match S::init(leaf, packet, &mut init) {
match S::init(leaf, packet) {
Ok(state) => {
family.entries.push(SessionEntry::new(hook_id, path, state));
+2 -33
View File
@@ -20,9 +20,8 @@ use crate::interface::SessionView;
/// fn init(
/// leaf: &mut MyLeafState,
/// packet: Packet,
/// ctx: &mut SessionInit,
/// ) -> Result<Self, SessionInitError> {
/// Ok(MySessionState::from_open(leaf, packet, ctx))
/// Ok(MySessionState::from_open(leaf, packet))
/// }
///
/// fn update(
@@ -47,7 +46,7 @@ pub trait Session<L>: Sized {
/// 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, SessionInitError>;
fn init(leaf: &mut L, packet: Packet) -> Result<Self, SessionInitError>;
/// Advances one active hook session.
///
@@ -73,36 +72,6 @@ pub trait Session<L>: Sized {
}
}
/// Context passed to [`Session::init`].
///
/// This carries routing metadata that the generated leaf already knows before the
/// session state exists. Protocols that need source paths should encode them in the
/// packet payload; `packet_path` is the destination path that routed the packet here.
pub struct SessionInit {
hook_id: HookID,
packet_path: Vec<u32>,
}
impl SessionInit {
/// Creates initialization metadata for a delivered packet.
pub fn new(hook_id: HookID, packet_path: Vec<u32>) -> Self {
Self {
hook_id,
packet_path,
}
}
/// Returns the hook id that will identify the new session.
pub fn hook_id(&self) -> HookID {
self.hook_id
}
/// Returns the destination path from the packet that reached this leaf.
pub fn packet_path(&self) -> &[u32] {
&self.packet_path
}
}
/// Error returned when a packet cannot create a new session.
pub enum SessionInitError {
/// The packet was intentionally consumed without creating state or sending output.