Merge pull request #201 from uqbar-dao/dr/add-hi-to-mock-networking

add hi-protocol to mock networking
This commit is contained in:
doria 2024-01-24 16:33:27 -03:00 committed by GitHub
commit c3419018ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 2 deletions

View File

@ -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(

View File

@ -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?;
}
}
},
}