Просмотр исходного кода

net: Remove SettingsPtr type alias

parazyd 2 лет назад
Родитель
Сommit
795e2300cb

+ 4 - 4
src/net/connector.rs

@@ -16,7 +16,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use std::time::Duration;
+use std::{sync::Arc, time::Duration};
 
 use futures::{
     future::{select, Either},
@@ -29,7 +29,7 @@ use super::{
     channel::{Channel, ChannelPtr},
     hosts::HostColor,
     session::SessionWeakPtr,
-    settings::SettingsPtr,
+    settings::Settings,
     transport::Dialer,
 };
 use crate::{system::CondVar, Error, Result};
@@ -37,7 +37,7 @@ use crate::{system::CondVar, Error, Result};
 /// Create outbound socket connections
 pub struct Connector {
     /// P2P settings
-    settings: SettingsPtr,
+    settings: Arc<Settings>,
     /// Weak pointer to the session
     pub session: SessionWeakPtr,
     /// Stop signal that aborts the connector if received.
@@ -46,7 +46,7 @@ pub struct Connector {
 
 impl Connector {
     /// Create a new connector with given network settings
-    pub fn new(settings: SettingsPtr, session: SessionWeakPtr) -> Self {
+    pub fn new(settings: Arc<Settings>, session: SessionWeakPtr) -> Self {
         Self { settings, session, stop_signal: CondVar::new() }
     }
 

+ 4 - 4
src/net/hosts.rs

@@ -28,7 +28,7 @@ use log::{debug, error, info, trace, warn};
 use rand::{prelude::IteratorRandom, rngs::OsRng, Rng};
 use url::Url;
 
-use super::{settings::SettingsPtr, ChannelPtr};
+use super::{settings::Settings, ChannelPtr};
 use crate::{
     system::{Publisher, PublisherPtr, Subscription},
     util::{
@@ -817,12 +817,12 @@ pub struct Hosts {
     pub(in crate::net) ipv6_available: Mutex<bool>,
 
     /// Pointer to configured P2P settings
-    settings: SettingsPtr,
+    settings: Arc<Settings>,
 }
 
 impl Hosts {
     /// Create a new hosts list
-    pub(in crate::net) fn new(settings: SettingsPtr) -> HostsPtr {
+    pub(in crate::net) fn new(settings: Arc<Settings>) -> HostsPtr {
         Arc::new(Self {
             registry: Mutex::new(HashMap::new()),
             container: HostContainer::new(),
@@ -1105,7 +1105,7 @@ impl Hosts {
 
     /// Filter given addresses based on certain rulesets and validity. Strictly called only on
     /// the first time learning of new peers.
-    fn filter_addresses(&self, settings: SettingsPtr, addrs: &[(Url, u64)]) -> Vec<(Url, u64)> {
+    fn filter_addresses(&self, settings: Arc<Settings>, addrs: &[(Url, u64)]) -> Vec<(Url, u64)> {
         debug!(target: "net::hosts::filter_addresses()", "Filtering addrs: {:?}", addrs);
         let mut ret = vec![];
         let localnet = self.settings.localnet;

+ 3 - 3
src/net/p2p.rs

@@ -40,7 +40,7 @@ use super::{
         InboundSession, InboundSessionPtr, ManualSession, ManualSessionPtr, OutboundSession,
         OutboundSessionPtr, RefineSession, RefineSessionPtr, SeedSyncSession, SeedSyncSessionPtr,
     },
-    settings::{Settings, SettingsPtr},
+    settings::Settings,
 };
 use crate::{
     system::{ExecutorPtr, Publisher, PublisherPtr, Subscription},
@@ -60,7 +60,7 @@ pub struct P2p {
     /// Protocol registry
     protocol_registry: ProtocolRegistry,
     /// P2P network settings
-    settings: SettingsPtr,
+    settings: Arc<Settings>,
     /// Reference to configured [`ManualSession`]
     session_manual: ManualSessionPtr,
     /// Reference to configured [`InboundSession`]
@@ -223,7 +223,7 @@ impl P2p {
     }
 
     /// Return an atomic pointer to the set network settings
-    pub fn settings(&self) -> SettingsPtr {
+    pub fn settings(&self) -> Arc<Settings> {
         self.settings.clone()
     }
 

+ 2 - 2
src/net/protocol/protocol_address.rs

@@ -30,7 +30,7 @@ use super::{
         message_publisher::MessageSubscription,
         p2p::P2pPtr,
         session::SESSION_OUTBOUND,
-        settings::SettingsPtr,
+        settings::Settings,
     },
     protocol_base::{ProtocolBase, ProtocolBasePtr},
     protocol_jobs_manager::{ProtocolJobsManager, ProtocolJobsManagerPtr},
@@ -62,7 +62,7 @@ pub struct ProtocolAddress {
     addrs_sub: MessageSubscription<AddrsMessage>,
     get_addrs_sub: MessageSubscription<GetAddrsMessage>,
     hosts: HostsPtr,
-    settings: SettingsPtr,
+    settings: Arc<Settings>,
     jobsman: ProtocolJobsManagerPtr,
 }
 

+ 2 - 2
src/net/protocol/protocol_ping.rs

@@ -32,7 +32,7 @@ use super::{
         message::{PingMessage, PongMessage},
         message_publisher::MessageSubscription,
         p2p::P2pPtr,
-        settings::SettingsPtr,
+        settings::Settings,
     },
     protocol_base::{ProtocolBase, ProtocolBasePtr},
     protocol_jobs_manager::{ProtocolJobsManager, ProtocolJobsManagerPtr},
@@ -47,7 +47,7 @@ pub struct ProtocolPing {
     channel: ChannelPtr,
     ping_sub: MessageSubscription<PingMessage>,
     pong_sub: MessageSubscription<PongMessage>,
-    settings: SettingsPtr,
+    settings: Arc<Settings>,
     jobsman: ProtocolJobsManagerPtr,
 }
 

+ 2 - 2
src/net/protocol/protocol_seed.rs

@@ -29,7 +29,7 @@ use super::{
         message::{AddrsMessage, GetAddrsMessage},
         message_publisher::MessageSubscription,
         p2p::P2pPtr,
-        settings::SettingsPtr,
+        settings::Settings,
     },
     protocol_base::{ProtocolBase, ProtocolBasePtr},
 };
@@ -39,7 +39,7 @@ use crate::Result;
 pub struct ProtocolSeed {
     channel: ChannelPtr,
     hosts: HostsPtr,
-    settings: SettingsPtr,
+    settings: Arc<Settings>,
     addr_sub: MessageSubscription<AddrsMessage>,
 }
 

+ 3 - 3
src/net/protocol/protocol_version.rs

@@ -32,7 +32,7 @@ use super::super::{
     channel::ChannelPtr,
     message::{VerackMessage, VersionMessage},
     message_publisher::MessageSubscription,
-    settings::SettingsPtr,
+    settings::Settings,
 };
 use crate::{Error, Result};
 
@@ -42,13 +42,13 @@ pub struct ProtocolVersion {
     channel: ChannelPtr,
     version_sub: MessageSubscription<VersionMessage>,
     verack_sub: MessageSubscription<VerackMessage>,
-    settings: SettingsPtr,
+    settings: Arc<Settings>,
 }
 
 impl ProtocolVersion {
     /// Create a new version protocol. Makes a version and version ack
     /// subscription, then adds them to a version protocol instance.
-    pub async fn new(channel: ChannelPtr, settings: SettingsPtr) -> Arc<Self> {
+    pub async fn new(channel: ChannelPtr, settings: Arc<Settings>) -> Arc<Self> {
         // Creates a version subscription
         let version_sub =
             channel.subscribe_msg::<VersionMessage>().await.expect("Missing version dispatcher!");

+ 2 - 2
src/net/session/manual_session.rs

@@ -47,7 +47,7 @@ use super::{
     Session, SessionBitFlag, SESSION_MANUAL,
 };
 use crate::{
-    net::{hosts::HostState, settings::SettingsPtr},
+    net::{hosts::HostState, settings::Settings},
     system::{sleep, LazyWeak, StoppableTask, StoppableTaskPtr},
     Error, Result,
 };
@@ -117,7 +117,7 @@ struct Slot {
 }
 
 impl Slot {
-    fn new(session: Weak<ManualSession>, addr: Url, settings: SettingsPtr) -> Arc<Self> {
+    fn new(session: Weak<ManualSession>, addr: Url, settings: Arc<Settings>) -> Arc<Self> {
         Arc::new(Self {
             addr,
             process: StoppableTask::new(),

+ 7 - 6
src/net/session/seedsync_session.rs

@@ -42,14 +42,15 @@
 //! function. This runs the version exchange protocol, stores the channel in the
 //! p2p list of channels, and subscribes to a stop signal.
 
-use async_trait::async_trait;
-use futures::stream::{FuturesUnordered, StreamExt};
-use log::{debug, info, warn};
-use smol::lock::Mutex;
 use std::sync::{
     atomic::{AtomicBool, Ordering::SeqCst},
     Arc, Weak,
 };
+
+use async_trait::async_trait;
+use futures::stream::{FuturesUnordered, StreamExt};
+use log::{debug, info, warn};
+use smol::lock::Mutex;
 use url::Url;
 
 use super::{
@@ -57,7 +58,7 @@ use super::{
         connector::Connector,
         hosts::HostColor,
         p2p::{P2p, P2pPtr},
-        settings::SettingsPtr,
+        settings::Settings,
     },
     Session, SessionBitFlag, SESSION_SEED,
 };
@@ -153,7 +154,7 @@ struct Slot {
 }
 
 impl Slot {
-    fn new(session: Weak<SeedSyncSession>, addr: Url, settings: SettingsPtr) -> Arc<Self> {
+    fn new(session: Weak<SeedSyncSession>, addr: Url, settings: Arc<Settings>) -> Arc<Self> {
         Arc::new(Self {
             addr,
             process: StoppableTask::new(),

+ 0 - 5
src/net/settings.rs

@@ -16,14 +16,9 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use std::sync::Arc;
-
 use structopt::StructOpt;
 use url::Url;
 
-/// Atomic pointer to network settings
-pub type SettingsPtr = Arc<Settings>;
-
 /// P2P network settings. The scope of this is a P2P network instance
 /// configured by the library user.
 #[derive(Debug, Clone)]