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:
Michael Mikovsky
2026-04-25 11:27:29 -06:00
parent ba3f28a78c
commit 6bdf59c5c9
13 changed files with 63 additions and 106 deletions
-9
View File
@@ -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()
+2 -2
View File
@@ -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 -47
View File
@@ -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()
})
}
}
+2 -2
View File
@@ -5,8 +5,8 @@ mod hook;
mod routing;
pub use endpoint::{
ChildRoute, ConnectionState, Endpoint, EndpointError, EndpointOutcome, Ingress, LeafBehavior,
LeafSpec, LocalEvent, ProtocolEndpoint,
ChildRoute, ConnectionState, Endpoint, EndpointError, EndpointOutcome, Ingress, LeafSpec,
LocalEvent, ProtocolEndpoint,
};
pub use hook::{ActiveHook, HookConflict, HookKey, HookTable, PendingHook};
pub use routing::{