mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
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:
@@ -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())
|
||||
|
||||
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user