From a0631312ca5b4bb248edda5425e7e7442331690a Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Wed, 24 Jan 2024 15:20:59 -0300 Subject: [PATCH] add hi-protocol to mock networking --- src/main.rs | 1 + src/net/mock.rs | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1a37aa9f..fd51f0f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -450,6 +450,7 @@ async fn main() { our.name.clone(), kernel_message_sender.clone(), net_message_receiver, + print_sender.clone(), network_error_sender, )); tasks.spawn(state::state_sender( diff --git a/src/net/mock.rs b/src/net/mock.rs index 82a4bbde..44e16459 100644 --- a/src/net/mock.rs +++ b/src/net/mock.rs @@ -15,6 +15,7 @@ pub async fn mock_client( node_identity: types::NodeId, send_to_loop: Sender, mut recv_from_loop: Receiver, + print_tx: types::PrintSender, _network_error_sender: types::NetworkErrorSender, ) -> anyhow::Result<()> { let url = format!("ws://127.0.0.1:{}", port); @@ -39,8 +40,44 @@ pub async fn mock_client( // Deserialize and forward the message to the loop // println!("{}:mock: incoming {}\r", node_identity, message); if let Binary(ref bin) = message { - let kernel_message: types::KernelMessage = rmp_serde::from_slice(bin)?; - send_to_loop.send(kernel_message).await?; + let km: types::KernelMessage = rmp_serde::from_slice(bin)?; + if km.target.process == "net:distro:sys" { + if let types::Message::Request(types::Request { ref body, .. }) = km.message { + print_tx + .send(types::Printout { + verbosity: 0, + content: format!( + "\x1b[3;32m{}: {}\x1b[0m", + km.source.node, + std::str::from_utf8(body).unwrap_or("!!message parse error!!") + ), + }) + .await?; + send_to_loop + .send(types::KernelMessage { + id: km.id, + source: types::Address { + node: node_identity.clone(), + process: types::ProcessId::new(Some("net"), "distro", "sys"), + }, + target: km.rsvp.as_ref().unwrap_or(&km.source).clone(), + rsvp: None, + message: types::Message::Response(( + types::Response { + inherit: false, + body: "delivered".as_bytes().to_vec(), + metadata: None, + capabilities: vec![], + }, + None, + )), + lazy_load_blob: None, + }) + .await?; + } + } else { + send_to_loop.send(km).await?; + } } }, }