mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Align protocol runtime with spec boundaries
Move demo leaf echo behavior out of the core protocol runtime, treat procedure IDs as opaque protocol fields, and return direct registered children in endpoint introspection to match the spec.
This commit is contained in:
@@ -14,7 +14,7 @@ pub struct NodeId(pub usize);
|
||||
/// Supported demo leaf kinds.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum LeafKind {
|
||||
/// Uses the built-in echo leaf behavior from `unshell`.
|
||||
/// Demo leaf that returns the incoming payload through the declared hook.
|
||||
Echo,
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ fn echo_leaf() -> ScenarioDefinition {
|
||||
name: "Echo Leaf".to_owned(),
|
||||
description: "Call a concrete leaf and watch the hook finish normally.".to_owned(),
|
||||
highlights: vec![
|
||||
"The leaf uses the built-in `Echo` behavior from the core runtime.".to_owned(),
|
||||
"The demo application echoes the payload after the protocol runtime delivers the call locally.".to_owned(),
|
||||
"The final response sets `end_hook = true`.".to_owned(),
|
||||
],
|
||||
root: NodeSpec {
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
use std::collections::{BTreeMap, VecDeque};
|
||||
|
||||
use crossbeam_channel::unbounded;
|
||||
use unshell::protocol::tree::{ChildRoute, ConnectionState, LeafBehavior, ProtocolEndpoint};
|
||||
use unshell::protocol::tree::{ChildRoute, ConnectionState, ProtocolEndpoint};
|
||||
|
||||
use crate::model::{DemoTree, LeafKind, NodeId, ScenarioDefinition, Selection};
|
||||
use crate::model::{DemoTree, NodeId, ScenarioDefinition, Selection};
|
||||
|
||||
use super::knowledge::{InspectorMode, RootKnowledge};
|
||||
use super::types::{ChatSession, SimError, SimNode, Simulation};
|
||||
@@ -53,9 +53,6 @@ impl Simulation {
|
||||
.map(|leaf| unshell::protocol::tree::LeafSpec {
|
||||
name: leaf.name.clone(),
|
||||
procedures: leaf.procedures.clone(),
|
||||
behavior: match leaf.kind {
|
||||
LeafKind::Echo => LeafBehavior::Echo,
|
||||
},
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
use unshell::protocol::{CallMessage, PacketHeader};
|
||||
|
||||
use crate::model::{EndpointProcedureKind, EndpointProcedureSpec, NodeId};
|
||||
use crate::model::{EndpointProcedureKind, EndpointProcedureSpec, LeafKind, NodeId};
|
||||
|
||||
use super::super::super::types::{SimError, Simulation};
|
||||
|
||||
@@ -17,13 +17,32 @@ impl Simulation {
|
||||
pub(super) fn handle_application_call(
|
||||
&mut self,
|
||||
node_id: NodeId,
|
||||
_header: &PacketHeader,
|
||||
header: &PacketHeader,
|
||||
message: &CallMessage,
|
||||
) -> Result<(), SimError> {
|
||||
let Some(hook) = &message.response_hook else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
if let Some(leaf_name) = &header.dst_leaf {
|
||||
let leaf = self.require_leaf(node_id, leaf_name)?.clone();
|
||||
match leaf.kind {
|
||||
LeafKind::Echo => {
|
||||
let frame = self.make_endpoint_data_frame(
|
||||
node_id,
|
||||
hook.return_path.clone(),
|
||||
hook.hook_id,
|
||||
message.procedure_id.clone(),
|
||||
message.data.clone(),
|
||||
true,
|
||||
)?;
|
||||
self.record_trace(node_id, format!("leaf {leaf_name} echoed {} bytes", message.data.len()));
|
||||
self.process_local_frame(node_id, frame)?;
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Clone the procedure spec once so later reply generation can borrow the
|
||||
// rest of the simulator state freely.
|
||||
let procedure = self
|
||||
|
||||
Reference in New Issue
Block a user