From 545018f8f546704e62b034393ec4c3afad2dd064 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Mon, 6 Nov 2023 11:14:50 -0500 Subject: [PATCH] net: bugfix for router-init --- Cargo.lock | 12 ++++++++++++ src/net/mod.rs | 27 +++++++++++++++------------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0039b10f..0345647a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -189,6 +189,17 @@ dependencies = [ "term", ] +[[package]] +name = "async-recursion" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.32", +] + [[package]] name = "async-trait" version = "0.1.73" @@ -5031,6 +5042,7 @@ version = "0.1.0" dependencies = [ "aes-gcm 0.10.2", "anyhow", + "async-recursion", "async-trait", "base64 0.13.1", "bincode", diff --git a/src/net/mod.rs b/src/net/mod.rs index 5e926123..58d8edda 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -399,20 +399,16 @@ async fn direct_networking( // forwarding connections joinset match conn { Connection::Peer(peer_conn) => { - let (peer_tx, peer_rx) = unbounded_channel::(); - let peer = Arc::new(RwLock::new(Peer { - identity: peer_id, + save_new_peer( + &peer_id, routing_for, - sender: peer_tx, - })); - peers.insert(peer.read().await.identity.name.clone(), peer.clone()); - peer_connections.spawn(maintain_connection( - peer, + &mut peers, + &mut peer_connections, peer_conn, - peer_rx, - kernel_message_tx.clone(), - print_tx.clone(), - )); + None, + &kernel_message_tx, + &print_tx + ).await?; } Connection::Passthrough(passthrough_conn) => { forwarding_connections.spawn(maintain_passthrough( @@ -891,6 +887,13 @@ async fn handle_local_message( "we have connections with peers: {:#?}\r\n", peers.keys() )); + printout.push_str(&format!( + "we are routing for: {:#?}\r\n", + peers + .iter() + .filter(|(_, peer)| peer.read().await.routing_for) + .map(|(id, _)| id) + )); printout.push_str(&format!("we have {} entries in the PKI\r\n", pki.len())); printout.push_str(&format!( "we have {} open peer connections\r\n",