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:
@@ -47,13 +47,6 @@ impl ChildRoute {
|
||||
}
|
||||
}
|
||||
|
||||
/// Test leaf behavior implemented by the endpoint runtime.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum LeafBehavior {
|
||||
/// Mirrors the incoming payload back over the declared response hook.
|
||||
Echo,
|
||||
}
|
||||
|
||||
/// Static leaf metadata used for procedure dispatch and introspection.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct LeafSpec {
|
||||
@@ -61,8 +54,6 @@ pub struct LeafSpec {
|
||||
pub name: String,
|
||||
/// Procedures supported by the leaf.
|
||||
pub procedures: Vec<String>,
|
||||
/// Built-in behavior used by the lightweight test runtime.
|
||||
pub behavior: LeafBehavior,
|
||||
}
|
||||
|
||||
/// Where a frame entered the local endpoint.
|
||||
|
||||
@@ -42,6 +42,12 @@ impl ProtocolEndpoint {
|
||||
.to_vec()
|
||||
} else {
|
||||
to_bytes::<RkyvError>(&EndpointIntrospection {
|
||||
sub_endpoints: self
|
||||
.children
|
||||
.iter()
|
||||
.filter(|child| child.state == super::core::ConnectionState::Registered)
|
||||
.filter_map(|child| child.path.get(self.path.len()).cloned())
|
||||
.collect(),
|
||||
leaves: self
|
||||
.leaves
|
||||
.values()
|
||||
|
||||
@@ -17,6 +17,6 @@ mod introspection;
|
||||
mod receive;
|
||||
|
||||
pub use core::{
|
||||
ChildRoute, ConnectionState, Endpoint, EndpointError, EndpointOutcome, Ingress, LeafBehavior,
|
||||
LeafSpec, LocalEvent, ProtocolEndpoint,
|
||||
ChildRoute, ConnectionState, Endpoint, EndpointError, EndpointOutcome, Ingress, LeafSpec,
|
||||
LocalEvent, ProtocolEndpoint,
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
use alloc::vec;
|
||||
|
||||
use crate::protocol::{
|
||||
CallMessage, DataMessage, PacketType, ProtocolFault, decode_frame,
|
||||
introspection::INTROSPECTION_PROCEDURE_ID, validate_call, validate_header,
|
||||
CallMessage, PacketType, ProtocolFault, decode_frame, introspection::INTROSPECTION_PROCEDURE_ID,
|
||||
validate_call, validate_header,
|
||||
};
|
||||
|
||||
use super::super::{HookKey, PendingHook, RouteDecision};
|
||||
@@ -77,51 +77,10 @@ impl ProtocolEndpoint {
|
||||
self.hooks.activate_pending(key, header.src_path.clone());
|
||||
}
|
||||
|
||||
match header
|
||||
.dst_leaf
|
||||
.as_ref()
|
||||
.and_then(|name| self.leaves.get(name))
|
||||
{
|
||||
Some(leaf) if leaf.behavior == super::core::LeafBehavior::Echo && key.is_some() => {
|
||||
let hook = message.response_hook.expect("synchronized");
|
||||
let response = DataMessage {
|
||||
procedure_id: message.procedure_id.clone(),
|
||||
data: message.data,
|
||||
end_hook: true,
|
||||
};
|
||||
let response_header = crate::protocol::PacketHeader {
|
||||
packet_type: PacketType::Data,
|
||||
src_path: self.path.clone(),
|
||||
dst_path: hook.return_path.clone(),
|
||||
dst_leaf: None,
|
||||
hook_id: Some(hook.hook_id),
|
||||
};
|
||||
let route = self.decide_route(&hook.return_path);
|
||||
self.hooks
|
||||
.remove_active(&HookKey::new(hook.return_path.clone(), hook.hook_id));
|
||||
|
||||
match route {
|
||||
RouteDecision::Local => Ok(EndpointOutcome {
|
||||
events: vec![LocalEvent::Data {
|
||||
header: response_header,
|
||||
message: response,
|
||||
}],
|
||||
..EndpointOutcome::default()
|
||||
}),
|
||||
_ => {
|
||||
let frame = crate::protocol::encode_packet(&response_header, &response)?;
|
||||
Ok(EndpointOutcome {
|
||||
forwards: vec![(route, frame)],
|
||||
..EndpointOutcome::default()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => Ok(EndpointOutcome {
|
||||
events: vec![LocalEvent::Call { header, message }],
|
||||
..EndpointOutcome::default()
|
||||
}),
|
||||
}
|
||||
Ok(EndpointOutcome {
|
||||
events: vec![LocalEvent::Call { header, message }],
|
||||
..EndpointOutcome::default()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user