From b0b7ba8650015d4ec9c49c11a027011a37d76b34 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Fri, 13 Oct 2023 10:33:12 -0400 Subject: [PATCH 1/4] bugfixes #1 --- src/net/connections.rs | 16 ++++++++++++---- src/net/mod.rs | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/net/connections.rs b/src/net/connections.rs index abfd0435..39326d22 100644 --- a/src/net/connections.rs +++ b/src/net/connections.rs @@ -217,10 +217,18 @@ pub async fn maintain_connection( // with the matching peer handler "sender". // if let Some(peer) = peers.read().await.get(to) { - let _ = peer.sender.send(( + let id = *id; + let to = to.clone(); + match peer.sender.send(( PeerMessage::Net(net_message), Some(forwarding_ack_tx.clone()), - )); + )) { + Ok(_) => {}, + Err(_) => { + peers.write().await.remove(&to); + message_tx.send((NetworkMessage::Nack(id), None)).unwrap(); + } + } } else { // if we don't have the peer, throw a nack. // println!("net: nacking message with id {id}\r"); @@ -467,10 +475,10 @@ async fn peer_handler( break; } println!("net: failed to deserialize message from {}\r", who); - continue; + break; } println!("net: failed to decrypt message from {}, could be spoofer\r", who); - continue; + break; } } => { // println!("net: lost peer {who}\r"); diff --git a/src/net/mod.rs b/src/net/mod.rs index 56fd63b5..952610ae 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -98,8 +98,16 @@ pub async fn networking( // if let Some(peer) = peers_read.get(target) { // println!("net: direct send to known peer\r"); - let _ = peer.sender.send((PeerMessage::Raw(km.clone()), None)); - continue; + match peer.sender.send((PeerMessage::Raw(km.clone()), None)) { + Ok(_) => continue, + Err(_) => { + // println!("net: failed to send to known peer\r"); + drop(peers_read); + peers.write().await.remove(target); + error_offline(km, &network_error_tx).await; + continue; + } + } } drop(peers_read); // @@ -585,14 +593,14 @@ async fn connect_to_routers( let response_shake = match timeout(TIMEOUT, handshake_rx.recv()).await { Ok(Some(Ok(NetworkMessage::HandshakeAck(shake)))) => shake, _ => { - println!("net: failed handshake with {router_name}\r"); + // println!("net: failed handshake with {router_name}\r"); conn_handle.abort(); let _ = routers_to_try_tx.send(router_name); continue; } }; let Ok(their_ephemeral_pk) = validate_handshake(&response_shake, &router_id) else { - println!("net: failed handshake with {router_name}\r"); + // println!("net: failed handshake with {router_name}\r"); conn_handle.abort(); let _ = routers_to_try_tx.send(router_name); continue; From a1614921b7d08703f27564166a07b0124b07910b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:33:44 +0000 Subject: [PATCH 2/4] Format Rust code using rustfmt --- src/net/connections.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net/connections.rs b/src/net/connections.rs index 39326d22..d6b70f85 100644 --- a/src/net/connections.rs +++ b/src/net/connections.rs @@ -223,7 +223,7 @@ pub async fn maintain_connection( PeerMessage::Net(net_message), Some(forwarding_ack_tx.clone()), )) { - Ok(_) => {}, + Ok(_) => {} Err(_) => { peers.write().await.remove(&to); message_tx.send((NetworkMessage::Nack(id), None)).unwrap(); From eb88f1cc1f4bdde1c4657e69594946772c32a5f9 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Fri, 13 Oct 2023 11:13:12 -0400 Subject: [PATCH 3/4] add delivery notif to !hi protocol --- modules/terminal/src/lib.rs | 14 +++++++++----- src/net/mod.rs | 27 +++++++++++++++++++++++++-- src/register.rs | 7 ++++--- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/modules/terminal/src/lib.rs b/modules/terminal/src/lib.rs index 4b9c393e..3a43c393 100644 --- a/modules/terminal/src/lib.rs +++ b/modules/terminal/src/lib.rs @@ -29,7 +29,7 @@ fn parse_command(our_name: &str, line: String) { }, &Request { inherit: false, - expects_response: None, + expects_response: Some(5), ipc: Some(message.into()), metadata: None, }, @@ -62,9 +62,9 @@ fn parse_command(our_name: &str, line: String) { } else { target_node.into() }, - process: ProcessId::from_str(target_process).unwrap_or_else(|_| - ProcessId::from_str(&format!("{}:sys:uqbar", target_process)).unwrap(), - ), + process: ProcessId::from_str(target_process).unwrap_or_else(|_| { + ProcessId::from_str(&format!("{}:sys:uqbar", target_process)).unwrap() + }), }, &Request { inherit: false, @@ -108,7 +108,11 @@ impl Guest for Component { }; parse_command(&our.node, command); } - _ => continue, + Message::Response((Response { ipc, metadata }, _)) => { + if let Some(txt) = &ipc { + print_to_terminal(0, &format!("net response: {}", txt)); + } + } } } } diff --git a/src/net/mod.rs b/src/net/mod.rs index 952610ae..c4a3a3c9 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -87,6 +87,7 @@ pub async fn networking( keys.clone(), pki.clone(), names.clone(), + kernel_message_tx.clone(), print_tx.clone(), ) .await; @@ -685,10 +686,13 @@ async fn handle_incoming_message( keys: PeerKeys, pki: OnchainPKI, names: PKINames, + kernel_message_tx: MessageSender, print_tx: PrintSender, ) { let data = match km.message { - Message::Response(_) => return, + Message::Response(_) => { + return; + } Message::Request(request) => match request.ipc { None => return, Some(ipc) => ipc, @@ -696,12 +700,31 @@ async fn handle_incoming_message( }; if km.source.node != our.name { + // respond to a text message with a simple "delivered" response let _ = print_tx .send(Printout { verbosity: 0, - content: format!("\x1b[3;32m{}: {}\x1b[0m", km.source.node, data,), + content: format!("\x1b[3;32m{}: {}\x1b[0m", km.source.node, data), }) .await; + let _ = kernel_message_tx.send(KernelMessage { + id: km.id, + source: Address { + node: our.name.clone(), + process: ProcessId::from_str("net:sys:uqbar").unwrap(), + }, + target: km.rsvp.unwrap_or(km.source), + rsvp: None, + message: Message::Response(( + Response { + ipc: Some("delivered".into()), + metadata: None, + }, + None, + )), + payload: None, + signed_capabilities: None, + }).await; } else { // available commands: "peers", "QnsUpdate" (see qns_indexer module) // first parse as raw string, then deserialize to NetActions object diff --git a/src/register.rs b/src/register.rs index 4f9fec64..afb78fef 100644 --- a/src/register.rs +++ b/src/register.rs @@ -112,9 +112,10 @@ async fn handle_post( }, allowed_routers: if ip == "localhost" || !info.direct { vec![ - "uqbar-router-1.uq".into(), // "0x8d9e54427c50660c6d4802f63edca86a9ca5fd6a78070c4635950e9d149ed441".into(), - "uqbar-router-2.uq".into(), // "0x06d331ed65843ecf0860c73292005d8103af20820546b2f8f9007d01f60595b1".into(), - "uqbar-router-3.uq".into(), // "0xe6ab611eb62e8aee0460295667f8179cda4315982717db4b0b3da6022deecac1".into(), + "testnode104.uq".into(), + // "uqbar-router-1.uq".into(), // "0x8d9e54427c50660c6d4802f63edca86a9ca5fd6a78070c4635950e9d149ed441".into(), + // "uqbar-router-2.uq".into(), // "0x06d331ed65843ecf0860c73292005d8103af20820546b2f8f9007d01f60595b1".into(), + // "uqbar-router-3.uq".into(), // "0xe6ab611eb62e8aee0460295667f8179cda4315982717db4b0b3da6022deecac1".into(), ] } else { vec![] From 2a566aa05f1cc52ab88a586c2001fa2054953f08 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 13 Oct 2023 15:13:42 +0000 Subject: [PATCH 4/4] Format Rust code using rustfmt --- src/net/mod.rs | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/net/mod.rs b/src/net/mod.rs index c4a3a3c9..b76be9ec 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -707,24 +707,26 @@ async fn handle_incoming_message( content: format!("\x1b[3;32m{}: {}\x1b[0m", km.source.node, data), }) .await; - let _ = kernel_message_tx.send(KernelMessage { - id: km.id, - source: Address { - node: our.name.clone(), - process: ProcessId::from_str("net:sys:uqbar").unwrap(), - }, - target: km.rsvp.unwrap_or(km.source), - rsvp: None, - message: Message::Response(( - Response { - ipc: Some("delivered".into()), - metadata: None, + let _ = kernel_message_tx + .send(KernelMessage { + id: km.id, + source: Address { + node: our.name.clone(), + process: ProcessId::from_str("net:sys:uqbar").unwrap(), }, - None, - )), - payload: None, - signed_capabilities: None, - }).await; + target: km.rsvp.unwrap_or(km.source), + rsvp: None, + message: Message::Response(( + Response { + ipc: Some("delivered".into()), + metadata: None, + }, + None, + )), + payload: None, + signed_capabilities: None, + }) + .await; } else { // available commands: "peers", "QnsUpdate" (see qns_indexer module) // first parse as raw string, then deserialize to NetActions object