From 36f95692f68d752c631adb427ab8225c1ecd642d Mon Sep 17 00:00:00 2001 From: John Smith Date: Tue, 5 Jul 2022 19:47:25 -0400 Subject: [PATCH] fix relay --- veilid-core/src/network_manager/mod.rs | 37 +++++++++++++++---- veilid-core/src/routing_table/bucket_entry.rs | 2 +- veilid-core/src/routing_table/debug.rs | 4 ++ veilid-server/src/client_api.rs | 2 +- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/veilid-core/src/network_manager/mod.rs b/veilid-core/src/network_manager/mod.rs index f7d02974..03eddfb1 100644 --- a/veilid-core/src/network_manager/mod.rs +++ b/veilid-core/src/network_manager/mod.rs @@ -1267,29 +1267,43 @@ impl NetworkManager { _last_ts: u64, cur_ts: u64, ) -> Result<(), String> { - // log_net!("--- network manager relay_management task"); - // Get our node's current node info and network class and do the right thing let routing_table = self.routing_table(); let node_info = routing_table.get_own_node_info(); let network_class = self.get_network_class(); + let mut node_info_changed = false; // Do we know our network class yet? if let Some(network_class) = network_class { // If we already have a relay, see if it is dead, or if we don't need it any more - { + let has_relay = { let mut inner = self.inner.lock(); if let Some(relay_node) = inner.relay_node.clone() { let state = relay_node.operate(|e| e.state(cur_ts)); - if matches!(state, BucketEntryState::Dead) || !node_info.requires_relay() { - // Relay node is dead or no longer needed + // Relay node is dead or no longer needed + if matches!(state, BucketEntryState::Dead) { + info!("Relay node died, dropping relay {}", relay_node); inner.relay_node = None; + node_info_changed = true; + false + } else if !node_info.requires_relay() { + info!( + "Relay node no longer required, dropping relay {}", + relay_node + ); + inner.relay_node = None; + node_info_changed = true; + false + } else { + true } + } else { + false } - } + }; // Do we need a relay? - if node_info.requires_relay() { + if !has_relay && node_info.requires_relay() { // Do we need an outbound relay? if network_class.outbound_wants_relay() { // The outbound relay is the host of the PWA @@ -1301,19 +1315,28 @@ impl NetworkManager { outbound_relay_peerinfo.node_id.key, outbound_relay_peerinfo.signed_node_info, )?; + info!("Outbound relay node selected: {}", nr); inner.relay_node = Some(nr); + node_info_changed = true; } // Otherwise we must need an inbound relay } else { // Find a node in our routing table that is an acceptable inbound relay if let Some(nr) = routing_table.find_inbound_relay(cur_ts) { let mut inner = self.inner.lock(); + info!("Inbound relay node selected: {}", nr); inner.relay_node = Some(nr); + node_info_changed = true; } } } } + // Re-send our node info if we selected a relay + if node_info_changed { + self.routing_table().send_node_info_updates().await; + } + Ok(()) } diff --git a/veilid-core/src/routing_table/bucket_entry.rs b/veilid-core/src/routing_table/bucket_entry.rs index c2e77024..0b469e46 100644 --- a/veilid-core/src/routing_table/bucket_entry.rs +++ b/veilid-core/src/routing_table/bucket_entry.rs @@ -22,7 +22,7 @@ const UNRELIABLE_PING_INTERVAL_SECS: u32 = 5; // Keepalive pings are done occasionally to ensure holepunched public dialinfo // remains valid, as well as to make sure we remain in any relay node's routing table -const KEEPALIVE_PING_INTERVAL_SECS: u32 = 20; +const KEEPALIVE_PING_INTERVAL_SECS: u32 = 10; // How many times do we try to ping a never-reached node before we call it dead const NEVER_REACHED_PING_COUNT: u32 = 3; diff --git a/veilid-core/src/routing_table/debug.rs b/veilid-core/src/routing_table/debug.rs index 471e58a3..7e3cc7d6 100644 --- a/veilid-core/src/routing_table/debug.rs +++ b/veilid-core/src/routing_table/debug.rs @@ -84,6 +84,10 @@ impl RoutingTable { for (n, gdi) in gdis.iter().enumerate() { out += &format!(" {:>2}: {:?}\n", n, gdi); } + + out += "Own PeerInfo:\n"; + out += &format!(" {:#?}\n", self.get_own_peer_info()); + out } diff --git a/veilid-server/src/client_api.rs b/veilid-server/src/client_api.rs index f87df9f9..cafe89cb 100644 --- a/veilid-server/src/client_api.rs +++ b/veilid-server/src/client_api.rs @@ -352,7 +352,7 @@ impl ClientApi { let registration_map1 = registration_map.clone(); let regs = &mut registration_map.borrow_mut().registrations; for (&id, mut registration) in regs.iter_mut() { - if registration.requests_in_flight > 5 { + if registration.requests_in_flight >= 256 { println!( "too many requests in flight: {}", registration.requests_in_flight