mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-12-25 23:39:22 -05:00
dont run routing table ticks that require the network until it has started up
This commit is contained in:
parent
b37e2cc3c9
commit
e82cdbbfce
@ -237,7 +237,7 @@ impl AttachmentManager {
|
||||
}
|
||||
|
||||
// see if we need to restart the network
|
||||
if netman.needs_restart() {
|
||||
if netman.network_needs_restart() {
|
||||
info!("Restarting network");
|
||||
restart = true;
|
||||
break;
|
||||
|
@ -117,8 +117,9 @@ pub(crate) enum NodeContactMethod {
|
||||
/// Must use outbound relay to reach the node
|
||||
OutboundRelay(NodeRef),
|
||||
}
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
|
||||
struct NodeContactMethodCacheKey {
|
||||
node_ids: TypedKeyGroup,
|
||||
own_node_info_ts: Timestamp,
|
||||
target_node_info_ts: Timestamp,
|
||||
target_node_ref_filter: Option<NodeRefFilter>,
|
||||
@ -305,6 +306,13 @@ impl NetworkManager {
|
||||
.net
|
||||
.clone()
|
||||
}
|
||||
fn opt_net(&self) -> Option<Network> {
|
||||
self.unlocked_inner
|
||||
.components
|
||||
.read()
|
||||
.as_ref()
|
||||
.map(|x| x.net.clone())
|
||||
}
|
||||
fn receipt_manager(&self) -> ReceiptManager {
|
||||
self.unlocked_inner
|
||||
.components
|
||||
@ -512,9 +520,16 @@ impl NetworkManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn needs_restart(&self) -> bool {
|
||||
let net = self.net();
|
||||
net.needs_restart()
|
||||
pub fn network_needs_restart(&self) -> bool {
|
||||
self.opt_net()
|
||||
.map(|net| net.needs_restart())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn network_is_started(&self) -> bool {
|
||||
self.opt_net()
|
||||
.and_then(|net| net.is_started())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn generate_node_status(&self, _routing_domain: RoutingDomain) -> NodeStatus {
|
||||
|
@ -72,8 +72,8 @@ pub const MAX_CAPABILITIES: usize = 64;
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
struct NetworkInner {
|
||||
/// true if the low-level network is running
|
||||
network_started: bool,
|
||||
/// Some(true) if the low-level network is running, Some(false) if it is not, None if it is in transit
|
||||
network_started: Option<bool>,
|
||||
/// set if the network needs to be restarted due to a low level configuration change
|
||||
/// such as dhcp release or change of address or interfaces being added or removed
|
||||
network_needs_restart: bool,
|
||||
@ -137,7 +137,7 @@ pub(in crate::network_manager) struct Network {
|
||||
impl Network {
|
||||
fn new_inner() -> NetworkInner {
|
||||
NetworkInner {
|
||||
network_started: false,
|
||||
network_started: Some(false),
|
||||
network_needs_restart: false,
|
||||
needs_public_dial_info_check: false,
|
||||
network_already_cleared: false,
|
||||
@ -675,6 +675,8 @@ impl Network {
|
||||
|
||||
#[instrument(level = "debug", err, skip_all)]
|
||||
pub async fn startup(&self) -> EyreResult<()> {
|
||||
self.inner.lock().network_started = None;
|
||||
let startup_func = async {
|
||||
// initialize interfaces
|
||||
self.unlocked_inner.interfaces.refresh().await?;
|
||||
|
||||
@ -819,7 +821,10 @@ impl Network {
|
||||
|
||||
// start listeners
|
||||
if protocol_config.inbound.contains(ProtocolType::UDP) {
|
||||
self.bind_udp_protocol_handlers(&mut editor_public_internet, &mut editor_local_network)
|
||||
self.bind_udp_protocol_handlers(
|
||||
&mut editor_public_internet,
|
||||
&mut editor_local_network,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
if protocol_config.inbound.contains(ProtocolType::WS) {
|
||||
@ -862,9 +867,17 @@ impl Network {
|
||||
editor_public_internet.commit(true).await;
|
||||
editor_local_network.commit(true).await;
|
||||
|
||||
info!("network started");
|
||||
self.inner.lock().network_started = true;
|
||||
Ok(())
|
||||
};
|
||||
let res = startup_func.await;
|
||||
if res.is_err() {
|
||||
info!("network failed to start");
|
||||
self.inner.lock().network_started = Some(false);
|
||||
return res;
|
||||
}
|
||||
|
||||
info!("network started");
|
||||
self.inner.lock().network_started = Some(true);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -872,7 +885,7 @@ impl Network {
|
||||
self.inner.lock().network_needs_restart
|
||||
}
|
||||
|
||||
pub fn is_started(&self) -> bool {
|
||||
pub fn is_started(&self) -> Option<bool> {
|
||||
self.inner.lock().network_started
|
||||
}
|
||||
|
||||
|
@ -394,6 +394,7 @@ impl NetworkManager {
|
||||
|
||||
// Get cache key
|
||||
let ncm_key = NodeContactMethodCacheKey {
|
||||
node_ids: target_node_ref.node_ids(),
|
||||
own_node_info_ts: routing_table.get_own_node_info_ts(routing_domain),
|
||||
target_node_info_ts: target_node_ref.node_info_ts(routing_domain),
|
||||
target_node_ref_filter: target_node_ref.filter_ref().cloned(),
|
||||
|
@ -76,15 +76,7 @@ impl NetworkManager {
|
||||
}
|
||||
|
||||
pub fn get_veilid_state(&self) -> Box<VeilidStateNetwork> {
|
||||
let has_state = self
|
||||
.unlocked_inner
|
||||
.components
|
||||
.read()
|
||||
.as_ref()
|
||||
.map(|c| c.net.is_started())
|
||||
.unwrap_or(false);
|
||||
|
||||
if !has_state {
|
||||
if !self.network_is_started() {
|
||||
return Box::new(VeilidStateNetwork {
|
||||
started: false,
|
||||
bps_down: 0.into(),
|
||||
|
@ -52,7 +52,7 @@ pub const MAX_CAPABILITIES: usize = 64;
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
struct NetworkInner {
|
||||
network_started: bool,
|
||||
network_started: Option<bool>,
|
||||
network_needs_restart: bool,
|
||||
protocol_config: ProtocolConfig,
|
||||
}
|
||||
@ -74,7 +74,7 @@ pub(in crate::network_manager) struct Network {
|
||||
impl Network {
|
||||
fn new_inner() -> NetworkInner {
|
||||
NetworkInner {
|
||||
network_started: false,
|
||||
network_started: Some(false),
|
||||
network_needs_restart: false,
|
||||
protocol_config: Default::default(),
|
||||
}
|
||||
@ -334,6 +334,8 @@ impl Network {
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
pub async fn startup(&self) -> EyreResult<()> {
|
||||
self.inner.lock().network_started = None;
|
||||
let startup_func = async {
|
||||
log_net!(debug "starting network");
|
||||
// get protocol config
|
||||
let protocol_config = {
|
||||
@ -395,9 +397,18 @@ impl Network {
|
||||
|
||||
// commit routing table edits
|
||||
editor_public_internet.commit(true).await;
|
||||
Ok(())
|
||||
};
|
||||
|
||||
self.inner.lock().network_started = true;
|
||||
log_net!(debug "network started");
|
||||
let res = startup_func.await;
|
||||
if res.is_err() {
|
||||
info!("network failed to start");
|
||||
self.inner.lock().network_started = Some(false);
|
||||
return res;
|
||||
}
|
||||
|
||||
info!("network started");
|
||||
self.inner.lock().network_started = Some(true);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -405,7 +416,7 @@ impl Network {
|
||||
self.inner.lock().network_needs_restart
|
||||
}
|
||||
|
||||
pub fn is_started(&self) -> bool {
|
||||
pub fn is_started(&self) -> Option<bool> {
|
||||
self.inner.lock().network_started
|
||||
}
|
||||
|
||||
|
@ -287,6 +287,9 @@ impl RoutingTable {
|
||||
Ok(NodeContactMethod::Direct(v)) => v,
|
||||
Ok(v) => {
|
||||
log_rtab!(warn "invalid contact method for bootstrap, ignoring peer: {:?}", v);
|
||||
let _ = routing_table
|
||||
.network_manager()
|
||||
.get_node_contact_method(nr.clone());
|
||||
return;
|
||||
}
|
||||
Err(e) => {
|
||||
|
@ -149,6 +149,11 @@ impl RoutingTable {
|
||||
inner.refresh_cached_entry_counts()
|
||||
};
|
||||
|
||||
// Only do the rest if the network has started
|
||||
if !self.network_manager().network_is_started() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let min_peer_count = self.with_config(|c| c.network.dht.min_peer_count as usize);
|
||||
|
||||
// Figure out which tables need bootstrap or peer minimum refresh
|
||||
|
Loading…
Reference in New Issue
Block a user