fix some more network issues

This commit is contained in:
Christien Rioux 2023-07-13 18:52:03 -04:00
parent 79f3722c9c
commit 70a0346cc3
9 changed files with 68 additions and 21 deletions

View File

@ -19,7 +19,7 @@ cfg_if! {
if #[cfg(feature="rt-async-std")] {
use async_std_resolver::{config, resolver, resolver_from_system_conf, AsyncStdResolver as AsyncResolver};
} else if #[cfg(feature="rt-tokio")] {
use trust_dns_resolver::{config, TokioAsyncResolver as AsyncResolver, error::ResolveError};
use trust_dns_resolver::{config, TokioAsyncResolver as AsyncResolver, error::ResolveError, error::ResolveErrorKind};
pub async fn resolver(
config: config::ResolverConfig,
@ -66,6 +66,12 @@ cfg_if! {
Ok(resolver)
}
}
async fn reset_resolver() {
let mut resolver_lock = RESOLVER.lock().await;
*resolver_lock = None;
}
}
}
@ -107,9 +113,17 @@ pub async fn txt_lookup<S: AsRef<str>>(host: S) -> EyreResult<Vec<String>> {
} else {
let resolver = get_resolver().await?;
let txt_result = resolver
let txt_result = match resolver
.txt_lookup(host.as_ref())
.await?;
.await {
Ok(v) => v,
Err(e) => {
if matches!(e.kind(), ResolveErrorKind::NoConnections) {
reset_resolver().await;
}
bail!("txt_lookup error: {}", e);
}
};
let mut out = Vec::new();
for x in txt_result.iter() {
for s in x.txt_data() {

View File

@ -39,8 +39,8 @@ impl RawUdpProtocolHandler {
NetworkResult::Value(None) => {
continue;
}
#[cfg(feature = "network-result-extra")]
nres => {
#[cfg(feature = "network-result-extra")]
log_network_result!(
"UDP::recv_message insert_frame failed: {:?} <= size={} remote_addr={}",
nres,
@ -49,6 +49,10 @@ impl RawUdpProtocolHandler {
);
continue;
}
#[cfg(not(feature = "network-result-extra"))]
_ => {
continue;
}
};
// Check length of reassembled message (same for all protocols)

View File

@ -12,29 +12,29 @@ impl NetworkManager {
/// Sending to a node requires determining a NetworkClass compatible mechanism
pub fn send_data(
&self,
target_node_ref: NodeRef,
destination_node_ref: NodeRef,
data: Vec<u8>,
) -> SendPinBoxFuture<EyreResult<NetworkResult<SendDataKind>>> {
let this = self.clone();
Box::pin(
async move {
// Get the best way to contact this node
let contact_method = this.get_node_contact_method(target_node_ref.clone())?;
let contact_method = this.get_node_contact_method(destination_node_ref.clone())?;
// If we need to relay, do it
let (contact_method, node_ref, relayed) = match contact_method {
let (contact_method, target_node_ref, relayed) = match contact_method {
NodeContactMethod::OutboundRelay(relay_nr)
| NodeContactMethod::InboundRelay(relay_nr) => {
let cm = this.get_node_contact_method(relay_nr.clone())?;
(cm, relay_nr, true)
}
cm => (cm, target_node_ref.clone(), false),
cm => (cm, destination_node_ref.clone(), false),
};
#[cfg(feature = "verbose-tracing")]
debug!(
"ContactMethod: {:?} for {:?}",
contact_method, target_node_ref
contact_method, destination_node_ref
);
// Try the contact method
@ -43,15 +43,15 @@ impl NetworkManager {
| NodeContactMethod::InboundRelay(relay_nr) => {
// Relay loop or multiple relays
bail!(
"Relay loop or multiple relays detected: {} -> {} -> {}",
"Relay loop or multiple relays detected: destination {} resolved to target {} via extraneous relay {}",
destination_node_ref,
target_node_ref,
node_ref,
relay_nr
);
}
NodeContactMethod::Direct(dial_info) => {
network_result_try!(
this.send_data_ncm_direct(node_ref, dial_info, data).await?
this.send_data_ncm_direct(target_node_ref, dial_info, data).await?
)
}
NodeContactMethod::SignalReverse(relay_nr, target_node_ref) => {

View File

@ -86,5 +86,11 @@ impl NetworkManager {
if let Err(e) = self.unlocked_inner.rolling_transfers_task.stop().await {
warn!("rolling_transfers_task not stopped: {}", e);
}
debug!("stopping routing table tasks");
let routing_table = self.routing_table();
routing_table.cancel_tasks().await;
// other tasks will get cancelled via the 'shutdown' mechanism
}
}

View File

@ -188,7 +188,8 @@ impl RouteSpecStore {
}
let Some(our_peer_info) = rti.get_own_peer_info(RoutingDomain::PublicInternet) else {
bail!("Can't allocate route until we have our own peer info");
log_rtab!(debug "unable to allocate route until we have our own peer info");
return Ok(None);
};
// Get relay node if we have one

View File

@ -124,7 +124,16 @@ impl RoutingTable {
let mut bsnames = Vec::<String>::new();
for bh in bootstrap {
// Get TXT record for bootstrap (bootstrap.veilid.net, or similar)
let records = intf::txt_lookup(&bh).await?;
let records = match intf::txt_lookup(&bh).await {
Ok(v) => v,
Err(e) => {
warn!(
"Network may be down. No bootstrap resolution for '{}': {}",
bh, e
);
continue;
}
};
for record in records {
// Split the bootstrap name record by commas
for rec in record.split(',') {
@ -152,7 +161,10 @@ impl RoutingTable {
// look up boostrap node txt records
let bsnirecords = match intf::txt_lookup(&bsname).await {
Err(e) => {
warn!("bootstrap node txt lookup failed for {}: {}", bsname, e);
warn!(
"Network may be down. Bootstrap node txt lookup failed for {}: {}",
bsname, e
);
return None;
}
Ok(v) => v,
@ -171,7 +183,7 @@ impl RoutingTable {
let txt_version: u8 = match records[0].parse::<u8>() {
Ok(v) => v,
Err(e) => {
warn!(
log_rtab!(warn
"invalid txt_version specified in bootstrap node txt record: {}",
e
);
@ -182,7 +194,7 @@ impl RoutingTable {
BOOTSTRAP_TXT_VERSION_0 => {
match self.process_bootstrap_records_v0(records).await {
Err(e) => {
warn!(
log_rtab!(error
"couldn't process v0 bootstrap records from {}: {}",
bsname, e
);
@ -196,7 +208,7 @@ impl RoutingTable {
}
}
_ => {
warn!("unsupported bootstrap txt record version");
log_rtab!(warn "unsupported bootstrap txt record version");
continue;
}
};

View File

@ -179,6 +179,14 @@ impl RoutingTable {
return Ok(());
}
// If we don't have our own peer info then don't do this yet
if self
.get_own_peer_info(RoutingDomain::PublicInternet)
.is_none()
{
return Ok(());
};
// Test locally allocated routes first
// This may remove dead routes
let routes_needing_testing = self.get_allocated_routes_to_test(cur_ts);

View File

@ -80,6 +80,10 @@ elif [ "$OS" == "macos" ]; then
# sudo arch -x86_64 gem install ffi
sudo arch -x86_64 gem install cocoapods
if [ "$(uname -p)" == "arm" ]; then
sudo softwareupdate --install-rosetta --agree-to-license
fi
# ensure platforms are enabled in flutter
flutter config --enable-macos-desktop --enable-ios --enable-android
fi

View File

@ -61,7 +61,6 @@ impl PeerMessages {
if assembly.data.len() != len as usize {
// Drop the assembly and just go with the new fragment as starting a new assembly
let seq = assembly.seq;
drop(assembly);
self.remove_assembly(ass);
self.new_assembly(timestamp, seq, off, len, chunk);
return false;
@ -74,7 +73,6 @@ impl PeerMessages {
// if fragments overlap, drop the old assembly and go with a new one
if !assembly.parts.is_disjoint(&part) {
let seq = assembly.seq;
drop(assembly);
self.remove_assembly(ass);
self.new_assembly(timestamp, seq, off, len, chunk);
return false;