mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
net: Use AtomicBool for dnet_enabled mark
This commit is contained in:
@@ -121,9 +121,9 @@ impl Darkfid {
|
|||||||
let switch = params[0].get::<bool>().unwrap();
|
let switch = params[0].get::<bool>().unwrap();
|
||||||
|
|
||||||
if *switch {
|
if *switch {
|
||||||
self.p2p.dnet_enable().await;
|
self.p2p.dnet_enable();
|
||||||
} else {
|
} else {
|
||||||
self.p2p.dnet_disable().await;
|
self.p2p.dnet_disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonResponse::new(JsonValue::Boolean(true), id).into()
|
JsonResponse::new(JsonValue::Boolean(true), id).into()
|
||||||
|
|||||||
@@ -77,9 +77,9 @@ impl DarkIrc {
|
|||||||
let switch = params[0].get::<bool>().unwrap();
|
let switch = params[0].get::<bool>().unwrap();
|
||||||
|
|
||||||
if *switch {
|
if *switch {
|
||||||
self.p2p.dnet_enable().await;
|
self.p2p.dnet_enable();
|
||||||
} else {
|
} else {
|
||||||
self.p2p.dnet_disable().await;
|
self.p2p.dnet_disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonResponse::new(JsonValue::Boolean(true), id).into()
|
JsonResponse::new(JsonValue::Boolean(true), id).into()
|
||||||
|
|||||||
@@ -129,9 +129,9 @@ impl JsonRpcInterface {
|
|||||||
let switch = params[0].get::<bool>().unwrap();
|
let switch = params[0].get::<bool>().unwrap();
|
||||||
|
|
||||||
if *switch {
|
if *switch {
|
||||||
self.p2p.dnet_enable().await;
|
self.p2p.dnet_enable();
|
||||||
} else {
|
} else {
|
||||||
self.p2p.dnet_disable().await;
|
self.p2p.dnet_disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonResponse::new(JsonValue::Boolean(true), id).into()
|
JsonResponse::new(JsonValue::Boolean(true), id).into()
|
||||||
|
|||||||
@@ -156,9 +156,9 @@ impl JsonRpcInterface {
|
|||||||
let switch = params[0].get::<bool>().unwrap();
|
let switch = params[0].get::<bool>().unwrap();
|
||||||
|
|
||||||
if *switch {
|
if *switch {
|
||||||
self.p2p.dnet_enable().await;
|
self.p2p.dnet_enable();
|
||||||
} else {
|
} else {
|
||||||
self.p2p.dnet_disable().await;
|
self.p2p.dnet_disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(JsonValue::Boolean(true))
|
Ok(JsonValue::Boolean(true))
|
||||||
|
|||||||
@@ -93,9 +93,9 @@ impl Dchat {
|
|||||||
let switch = params[0].get::<bool>().unwrap();
|
let switch = params[0].get::<bool>().unwrap();
|
||||||
|
|
||||||
if *switch {
|
if *switch {
|
||||||
self.p2p.dnet_enable().await;
|
self.p2p.dnet_enable();
|
||||||
} else {
|
} else {
|
||||||
self.p2p.dnet_disable().await;
|
self.p2p.dnet_disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonResponse::new(JsonValue::Boolean(true), id).into()
|
JsonResponse::new(JsonValue::Boolean(true), id).into()
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ use crate::util::time::NanoTimestamp;
|
|||||||
macro_rules! dnetev {
|
macro_rules! dnetev {
|
||||||
($self:expr, $event_name:ident, $($code:tt)*) => {
|
($self:expr, $event_name:ident, $($code:tt)*) => {
|
||||||
{
|
{
|
||||||
if *$self.p2p().dnet_enabled.lock().await {
|
if $self.p2p().dnet_enabled.load(std::sync::atomic::Ordering::SeqCst) {
|
||||||
let event = DnetEvent::$event_name(dnet::$event_name $($code)*);
|
let event = DnetEvent::$event_name(dnet::$event_name $($code)*);
|
||||||
$self.p2p().dnet_notify(event).await;
|
$self.p2p().dnet_notify(event).await;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,14 +16,16 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::{
|
||||||
|
atomic::{AtomicBool, Ordering},
|
||||||
|
Arc,
|
||||||
|
};
|
||||||
|
|
||||||
use futures::{stream::FuturesUnordered, TryFutureExt};
|
use futures::{stream::FuturesUnordered, TryFutureExt};
|
||||||
use futures_rustls::rustls::crypto::{ring, CryptoProvider};
|
use futures_rustls::rustls::crypto::{ring, CryptoProvider};
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use smol::{
|
use smol::{
|
||||||
fs::{self, unix::PermissionsExt},
|
fs::{self, unix::PermissionsExt},
|
||||||
lock::Mutex,
|
|
||||||
stream::StreamExt,
|
stream::StreamExt,
|
||||||
};
|
};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
@@ -70,7 +72,7 @@ pub struct P2p {
|
|||||||
/// Reference to configured [`SeedSyncSession`]
|
/// Reference to configured [`SeedSyncSession`]
|
||||||
session_seedsync: SeedSyncSessionPtr,
|
session_seedsync: SeedSyncSessionPtr,
|
||||||
/// Enable network debugging
|
/// Enable network debugging
|
||||||
pub dnet_enabled: Mutex<bool>,
|
pub dnet_enabled: AtomicBool,
|
||||||
/// The publisher for which we can give dnet info over
|
/// The publisher for which we can give dnet info over
|
||||||
dnet_publisher: PublisherPtr<DnetEvent>,
|
dnet_publisher: PublisherPtr<DnetEvent>,
|
||||||
}
|
}
|
||||||
@@ -108,7 +110,7 @@ impl P2p {
|
|||||||
session_refine: RefineSession::new(),
|
session_refine: RefineSession::new(),
|
||||||
session_seedsync: SeedSyncSession::new(),
|
session_seedsync: SeedSyncSession::new(),
|
||||||
|
|
||||||
dnet_enabled: Mutex::new(false),
|
dnet_enabled: AtomicBool::new(false),
|
||||||
dnet_publisher: Publisher::new(),
|
dnet_publisher: Publisher::new(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -266,14 +268,14 @@ impl P2p {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Enable network debugging
|
/// Enable network debugging
|
||||||
pub async fn dnet_enable(&self) {
|
pub fn dnet_enable(&self) {
|
||||||
*self.dnet_enabled.lock().await = true;
|
self.dnet_enabled.store(true, Ordering::SeqCst);
|
||||||
warn!("[P2P] Network debugging enabled!");
|
warn!("[P2P] Network debugging enabled!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disable network debugging
|
/// Disable network debugging
|
||||||
pub async fn dnet_disable(&self) {
|
pub fn dnet_disable(&self) {
|
||||||
*self.dnet_enabled.lock().await = false;
|
self.dnet_enabled.store(false, Ordering::SeqCst);
|
||||||
warn!("[P2P] Network debugging disabled!");
|
warn!("[P2P] Network debugging disabled!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user