mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Reuse host hook keys during inbound hook resolution
This commit is contained in:
@@ -50,22 +50,20 @@ impl ProtocolEndpoint {
|
|||||||
message: DataMessage,
|
message: DataMessage,
|
||||||
) -> Result<EndpointOutcome, EndpointError> {
|
) -> Result<EndpointOutcome, EndpointError> {
|
||||||
let hook_id = header.hook_id.expect("validated");
|
let hook_id = header.hook_id.expect("validated");
|
||||||
let key = if let Some(key) =
|
let host_key = HookKey::new(self.path.clone(), hook_id);
|
||||||
self.hooks
|
let key = if let Some(key) = self
|
||||||
.resolve_active_key(&self.path, hook_id, &header.src_path)
|
.hooks
|
||||||
|
.resolve_active_key_for_host(&host_key, &header.src_path)
|
||||||
{
|
{
|
||||||
key
|
key
|
||||||
} else {
|
} else if self.hooks.pending(&host_key).is_some_and(|pending| {
|
||||||
let pending_key = HookKey::new(self.path.clone(), hook_id);
|
|
||||||
if self.hooks.pending(&pending_key).is_some_and(|pending| {
|
|
||||||
pending.caller_src_path == header.src_path
|
pending.caller_src_path == header.src_path
|
||||||
&& pending.procedure_id == message.procedure_id
|
&& pending.procedure_id == message.procedure_id
|
||||||
}) {
|
}) {
|
||||||
self.hooks.activate_pending(&pending_key);
|
self.hooks.activate_pending(&host_key);
|
||||||
pending_key
|
host_key
|
||||||
} else {
|
} else {
|
||||||
return Ok(EndpointOutcome::Dropped);
|
return Ok(EndpointOutcome::Dropped);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(active) = self.hooks.active(&key) else {
|
let Some(active) = self.hooks.active(&key) else {
|
||||||
@@ -101,9 +99,10 @@ impl ProtocolEndpoint {
|
|||||||
message: FaultMessage,
|
message: FaultMessage,
|
||||||
) -> Result<EndpointOutcome, EndpointError> {
|
) -> Result<EndpointOutcome, EndpointError> {
|
||||||
let hook_id = header.hook_id.expect("validated");
|
let hook_id = header.hook_id.expect("validated");
|
||||||
|
let pending_key = HookKey::new(self.path.clone(), hook_id);
|
||||||
if let Some(key) = self
|
if let Some(key) = self
|
||||||
.hooks
|
.hooks
|
||||||
.resolve_active_key(&self.path, hook_id, &header.src_path)
|
.resolve_active_key_for_host(&pending_key, &header.src_path)
|
||||||
{
|
{
|
||||||
self.hooks.remove_active(&key);
|
self.hooks.remove_active(&key);
|
||||||
return Ok(EndpointOutcome::Local(LocalEvent::Fault {
|
return Ok(EndpointOutcome::Local(LocalEvent::Fault {
|
||||||
@@ -113,7 +112,6 @@ impl ProtocolEndpoint {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
let pending_key = HookKey::new(self.path.clone(), hook_id);
|
|
||||||
if self
|
if self
|
||||||
.hooks
|
.hooks
|
||||||
.pending(&pending_key)
|
.pending(&pending_key)
|
||||||
|
|||||||
@@ -183,17 +183,26 @@ impl HookTable {
|
|||||||
return_path: &[String],
|
return_path: &[String],
|
||||||
hook_id: u64,
|
hook_id: u64,
|
||||||
peer_path: &[String],
|
peer_path: &[String],
|
||||||
|
) -> Option<HookKey> {
|
||||||
|
let host_key = HookKey::new(return_path.to_vec(), hook_id);
|
||||||
|
self.resolve_active_key_for_host(&host_key, peer_path)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn resolve_active_key_for_host(
|
||||||
|
&self,
|
||||||
|
host_key: &HookKey,
|
||||||
|
peer_path: &[String],
|
||||||
) -> Option<HookKey> {
|
) -> Option<HookKey> {
|
||||||
if let Some(key) = self
|
if let Some(key) = self
|
||||||
.active_by_peer
|
.active_by_peer
|
||||||
.get(&hook_id)
|
.get(&host_key.hook_id)
|
||||||
.and_then(|peer_paths| peer_paths.get(peer_path))
|
.and_then(|peer_paths| peer_paths.get(peer_path))
|
||||||
{
|
{
|
||||||
return Some(key.clone());
|
return Some(key.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
let host_key = HookKey::new(return_path.to_vec(), hook_id);
|
self.active.contains_key(host_key).then(|| host_key.clone())
|
||||||
self.active.contains_key(&host_key).then_some(host_key)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Marks the local side finished and returns `true` once both sides are finished.
|
/// Marks the local side finished and returns `true` once both sides are finished.
|
||||||
|
|||||||
Reference in New Issue
Block a user