Skip to content

Commit

Permalink
fix symmetric mode responses for delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankurte committed Apr 23, 2024
1 parent 084535c commit 0638024
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
1 change: 0 additions & 1 deletion daemon/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ impl AsyncCore {

// Await operation completion
let r = rx.await;
warn!("rx: {r:?}");

match r {
Ok(CoreRes::Peer(info)) => Ok(info),
Expand Down
7 changes: 6 additions & 1 deletion daemon/src/core/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,15 @@ impl Core {
where
F: FnMut(&mut Service, &mut ServiceInfo) -> CoreRes,
{
debug!("Updating service: {id}");

// Look for matching peer
let s = match self.services.get_mut(id) {
Some(s) => s,
None => return CoreRes::NotFound,
None => {
error!("Service {id} not found");
return CoreRes::NotFound
},
};

// Run update function
Expand Down
20 changes: 15 additions & 5 deletions daemon/src/daemon/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ impl NetIf for Dsf<ByteSink> {
pri_key: Some(signing_key.clone()),
// target public key for asymmetric encryption
pub_key,
// Symmetric key must be in key cache
sec_key: peer_keys.and_then(|k| k.sec_key.clone()),
..Default::default()
// TODO: why do we need the secret key?
sec_key: peer_keys.as_ref().and_then(|k| k.sec_key.clone()),
// Symmetric key if enabled
sym_keys: peer_keys.as_ref().and_then(|k| k.sym_keys.clone()),
};

// Enable symmetric mode if supported
Expand Down Expand Up @@ -286,6 +287,8 @@ where

// DELEGATION: Handle unwrapped objects for constrained / delegated services
if !container.header().kind().is_message() {
let req_id = container.header().index();

// Handle raw object
let resp = match crate::net::handle_net_raw(
&engine,
Expand All @@ -302,7 +305,14 @@ where
}
};

// TODO(high): Send response
// Send response
let resp = net::Response::new(our_id, req_id as u16, resp, Flags::default());
if let Err(e) = net.net_send(vec![(addr, Some(id.clone()))], resp.into()).await {
error!("Failed to forward net response: {e:?}");
}

// Stop processing
return;
}

let message = match message {
Expand Down Expand Up @@ -346,7 +356,7 @@ where
&message.from(),
Box::new(move |p| {
if !p.flags.contains(PeerFlags::SYMMETRIC_ENABLED) {
warn!("Enabling symmetric message crypto for peer: {}", p.id);
info!("Enabling symmetric encryption for peer: {}", p.id);
p.flags |= PeerFlags::SYMMETRIC_ENABLED;
}
}),
Expand Down
6 changes: 5 additions & 1 deletion daemon/src/rpc/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ impl<T: Engine> PubSub for T {
// Issue subscription requests
let subs = do_subscribe(self, target.id.clone(), &peers).await?;

debug!("Updating service {}", target.id);

// Update local service state
self.svc_update(
target.id.clone(),
Box::new(|svc, info| {
info.state = ServiceState::Subscribed;
CoreRes::Id(svc.id())
CoreRes::Service(info.clone())
}),
)
.await?;
Expand All @@ -119,6 +121,8 @@ impl<T: Engine> PubSub for T {

// TODO: replicate if enabled

debug!("Subscribe okay!");

Ok(subs)
}

Expand Down

0 comments on commit 0638024

Please sign in to comment.