fix relay
This commit is contained in:
parent
539f2085e9
commit
36f95692f6
@ -1267,29 +1267,43 @@ impl NetworkManager {
|
|||||||
_last_ts: u64,
|
_last_ts: u64,
|
||||||
cur_ts: u64,
|
cur_ts: u64,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
// log_net!("--- network manager relay_management task");
|
|
||||||
|
|
||||||
// Get our node's current node info and network class and do the right thing
|
// Get our node's current node info and network class and do the right thing
|
||||||
let routing_table = self.routing_table();
|
let routing_table = self.routing_table();
|
||||||
let node_info = routing_table.get_own_node_info();
|
let node_info = routing_table.get_own_node_info();
|
||||||
let network_class = self.get_network_class();
|
let network_class = self.get_network_class();
|
||||||
|
let mut node_info_changed = false;
|
||||||
|
|
||||||
// Do we know our network class yet?
|
// Do we know our network class yet?
|
||||||
if let Some(network_class) = network_class {
|
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
|
// 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();
|
let mut inner = self.inner.lock();
|
||||||
if let Some(relay_node) = inner.relay_node.clone() {
|
if let Some(relay_node) = inner.relay_node.clone() {
|
||||||
let state = relay_node.operate(|e| e.state(cur_ts));
|
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;
|
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?
|
// Do we need a relay?
|
||||||
if node_info.requires_relay() {
|
if !has_relay && node_info.requires_relay() {
|
||||||
// Do we need an outbound relay?
|
// Do we need an outbound relay?
|
||||||
if network_class.outbound_wants_relay() {
|
if network_class.outbound_wants_relay() {
|
||||||
// The outbound relay is the host of the PWA
|
// The outbound relay is the host of the PWA
|
||||||
@ -1301,19 +1315,28 @@ impl NetworkManager {
|
|||||||
outbound_relay_peerinfo.node_id.key,
|
outbound_relay_peerinfo.node_id.key,
|
||||||
outbound_relay_peerinfo.signed_node_info,
|
outbound_relay_peerinfo.signed_node_info,
|
||||||
)?;
|
)?;
|
||||||
|
info!("Outbound relay node selected: {}", nr);
|
||||||
inner.relay_node = Some(nr);
|
inner.relay_node = Some(nr);
|
||||||
|
node_info_changed = true;
|
||||||
}
|
}
|
||||||
// Otherwise we must need an inbound relay
|
// Otherwise we must need an inbound relay
|
||||||
} else {
|
} else {
|
||||||
// Find a node in our routing table that is an acceptable inbound relay
|
// Find a node in our routing table that is an acceptable inbound relay
|
||||||
if let Some(nr) = routing_table.find_inbound_relay(cur_ts) {
|
if let Some(nr) = routing_table.find_inbound_relay(cur_ts) {
|
||||||
let mut inner = self.inner.lock();
|
let mut inner = self.inner.lock();
|
||||||
|
info!("Inbound relay node selected: {}", nr);
|
||||||
inner.relay_node = Some(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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ const UNRELIABLE_PING_INTERVAL_SECS: u32 = 5;
|
|||||||
|
|
||||||
// Keepalive pings are done occasionally to ensure holepunched public dialinfo
|
// 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
|
// 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
|
// How many times do we try to ping a never-reached node before we call it dead
|
||||||
const NEVER_REACHED_PING_COUNT: u32 = 3;
|
const NEVER_REACHED_PING_COUNT: u32 = 3;
|
||||||
|
@ -84,6 +84,10 @@ impl RoutingTable {
|
|||||||
for (n, gdi) in gdis.iter().enumerate() {
|
for (n, gdi) in gdis.iter().enumerate() {
|
||||||
out += &format!(" {:>2}: {:?}\n", n, gdi);
|
out += &format!(" {:>2}: {:?}\n", n, gdi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out += "Own PeerInfo:\n";
|
||||||
|
out += &format!(" {:#?}\n", self.get_own_peer_info());
|
||||||
|
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +352,7 @@ impl ClientApi {
|
|||||||
let registration_map1 = registration_map.clone();
|
let registration_map1 = registration_map.clone();
|
||||||
let regs = &mut registration_map.borrow_mut().registrations;
|
let regs = &mut registration_map.borrow_mut().registrations;
|
||||||
for (&id, mut registration) in regs.iter_mut() {
|
for (&id, mut registration) in regs.iter_mut() {
|
||||||
if registration.requests_in_flight > 5 {
|
if registration.requests_in_flight >= 256 {
|
||||||
println!(
|
println!(
|
||||||
"too many requests in flight: {}",
|
"too many requests in flight: {}",
|
||||||
registration.requests_in_flight
|
registration.requests_in_flight
|
||||||
|
Loading…
Reference in New Issue
Block a user