Explorar el Código

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.
draoi hace 2 años
padre
commit
76934ac216
Se han modificado 2 ficheros con 4 adiciones y 3 borrados
  1. 1 1
      src/net/connector.rs
  2. 3 2
      src/net/hosts.rs

+ 1 - 1
src/net/connector.rs

@@ -102,7 +102,7 @@ impl Connector {
             Either::Left((Err(e), _)) => {
             Either::Left((Err(e), _)) => {
                 // If we get ENETUNREACH, we don't have IPv6 connectivity so note it down.
                 // If we get ENETUNREACH, we don't have IPv6 connectivity so note it down.
                 if e.raw_os_error() == Some(libc::ENETUNREACH) {
                 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;
                         false;
                 }
                 }
                 Err(e.into())
                 Err(e.into())

+ 3 - 2
src/net/hosts.rs

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