net: use sync Mutex for ipv6_available

Locks should be sync for simple data operations and async if:

1. the lock must be held across an .await point
2. the new data being stored in the lock is calculated from data already inside the lock

Since ipv6_available is a fast and simple data operation it is more appropiate to use
a sync Mutex here.
This commit is contained in:
draoi
2024-06-24 12:23:22 +02:00
parent e8465235d0
commit 76934ac216
2 changed files with 4 additions and 3 deletions

View File

@@ -102,7 +102,7 @@ impl Connector {
Either::Left((Err(e), _)) => {
// If we get ENETUNREACH, we don't have IPv6 connectivity so note it down.
if e.raw_os_error() == Some(libc::ENETUNREACH) {
*self.session.upgrade().unwrap().p2p().hosts().ipv6_available.lock().await =
*self.session.upgrade().unwrap().p2p().hosts().ipv6_available.lock().unwrap() =
false;
}
Err(e.into())

View File

@@ -20,7 +20,8 @@ use std::{collections::HashMap, fmt, fs, fs::File, sync::Arc, time::Instant};
use log::{debug, error, info, trace, warn};
use rand::{prelude::IteratorRandom, rngs::OsRng, Rng};
use smol::lock::{Mutex, RwLock};
use smol::lock::RwLock;
use std::sync::Mutex;
use url::Url;
use super::{settings::SettingsPtr, ChannelPtr};
@@ -1089,7 +1090,7 @@ impl Hosts {
debug!(target: "net::hosts::filter_addresses()", "Filtering addrs: {:?}", addrs);
let mut ret = vec![];
let localnet = self.settings.localnet;
let ipv6_available = *self.ipv6_available.lock().await;
let ipv6_available: bool = { *self.ipv6_available.lock().unwrap() };
'addr_loop: for (addr_, last_seen) in addrs {
// Validate that the format is `scheme://host_str:port`