mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-03 03:36:30 +03:00
Merge pull request #201 from uqbar-dao/dr/add-hi-to-mock-networking
add hi-protocol to mock networking
This commit is contained in:
commit
c3419018ff
@ -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(
|
||||
|
@ -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?;
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user