network interface changes cleanup

This commit is contained in:
Christien Rioux
2023-10-12 21:17:47 -04:00
parent 54c403ebfb
commit ebd36d82ef
8 changed files with 84 additions and 69 deletions

View File

@@ -658,12 +658,20 @@ impl DiscoveryContext {
return;
}
// Did external addresses change from the last time we made dialinfo?
// Did external address change from the last time we made dialinfo?
// Disregard port for this because we only need to know if the ip address has changed
// If the port has changed it will change only for this protocol and will be overwritten individually by each protocol discover()
let some_clear_network_callback = {
let inner = self.inner.lock();
let ext_1 = inner.external_1.as_ref().unwrap().address;
let ext_2 = inner.external_2.as_ref().unwrap().address;
if (ext_1 != ext_2) || Some(ext_1) != self.unlocked_inner.existing_external_address {
let ext_1 = inner.external_1.as_ref().unwrap().address.address();
let ext_2 = inner.external_2.as_ref().unwrap().address.address();
if (ext_1 != ext_2)
|| Some(ext_1)
!= self
.unlocked_inner
.existing_external_address
.map(|ea| ea.address())
{
// External address was not found, or has changed, go ahead and clear the network so we can do better
Some(self.unlocked_inner.clear_network_callback.clone())
} else {

View File

@@ -375,15 +375,14 @@ impl Network {
addrs
}
// See if our interface addresses have changed, if so we need to punt the network
// and redo all our addresses. This is overkill, but anything more accurate
// would require inspection of routing tables that we dont want to bother with
// See if our interface addresses have changed, if so redo public dial info if necessary
async fn check_interface_addresses(&self) -> EyreResult<bool> {
if !self.unlocked_inner.interfaces.refresh().await? {
return Ok(false);
}
self.inner.lock().network_needs_restart = true;
self.inner.lock().needs_public_dial_info_check = true;
Ok(true)
}
@@ -700,7 +699,7 @@ impl Network {
self.unlocked_inner
.interfaces
.with_interfaces(|interfaces| {
trace!("interfaces: {:#?}", interfaces);
debug!("interfaces: {:#?}", interfaces);
for intf in interfaces.values() {
// Skip networks that we should never encounter
@@ -978,9 +977,8 @@ impl Network {
_l: u64,
_t: u64,
) -> EyreResult<()> {
if self.check_interface_addresses().await? {
info!("interface addresses changed, restarting network");
}
self.check_interface_addresses().await?;
Ok(())
}

View File

@@ -50,13 +50,11 @@ impl Network {
let mut add = false;
if let Some(edi) = existing_dial_info.get(&(pt, at)) {
if did.class < edi.class {
// Better dial info class was found, clear existing dialinfo for this pt/at pair
if did.class <= edi.class {
// Better or same dial info class was found, clear existing dialinfo for this pt/at pair
// Only keep one dial info per protocol/address type combination
clear = true;
add = true;
} else if did.class == edi.class {
// Same dial info class, just add dial info
add = true;
}
// Otherwise, don't upgrade, don't add, this is worse than what we have already
} else {