mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
add treetest protocol simulator and ui
This commit is contained in:
@@ -60,7 +60,16 @@ impl ProtocolEndpoint {
|
||||
header: PacketHeader,
|
||||
message: DataMessage,
|
||||
) -> Result<EndpointOutcome, EndpointError> {
|
||||
let key = HookKey::new(self.path.clone(), header.hook_id.expect("validated"));
|
||||
let hook_id = header.hook_id.expect("validated");
|
||||
let key = self
|
||||
.hooks
|
||||
.active(&HookKey::new(self.path.clone(), hook_id))
|
||||
.map(|_| HookKey::new(self.path.clone(), hook_id))
|
||||
.or_else(|| {
|
||||
self.hooks
|
||||
.find_active_key_by_peer(hook_id, &header.src_path)
|
||||
})
|
||||
.unwrap_or_else(|| HookKey::new(self.path.clone(), hook_id));
|
||||
|
||||
if self.hooks.active(&key).is_none() {
|
||||
let matches = self.hooks.pending(&key).is_some_and(|pending| {
|
||||
|
||||
@@ -124,6 +124,25 @@ impl HookTable {
|
||||
self.active.get_mut(key)
|
||||
}
|
||||
|
||||
/// Finds an active hook key for a non-host peer receiving continued data.
|
||||
///
|
||||
/// Rationale: `hook_id` is scoped to the hook host, so a subordinate peer
|
||||
/// cannot derive the full key from the packet header alone. The peer uses
|
||||
/// its already-validated active state to recover the host-scoped key.
|
||||
pub fn find_active_key_by_peer(&self, hook_id: u64, peer_path: &[String]) -> Option<HookKey> {
|
||||
let mut matches = self
|
||||
.active
|
||||
.iter()
|
||||
.filter(|(_key, active)| active.hook_id == hook_id && active.peer_path == peer_path)
|
||||
.map(|(key, _)| key.clone());
|
||||
|
||||
let first = matches.next()?;
|
||||
if matches.next().is_some() {
|
||||
return None;
|
||||
}
|
||||
Some(first)
|
||||
}
|
||||
|
||||
pub fn pending_len(&self) -> usize {
|
||||
self.pending.len()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user