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

src: Use peers() instead of channels() method where applicable

The following messages are now only broadcast to peers (inbound/ manual/
outbound session) and not seed or refinery connections:

* EventGraph DAG sync
* OutboundSession `GetAddrs`

The following changes have been made to the p2p API:

* p2p.broadcast() now only sends to peers, not seeds or refine connections.
* p2p.is_connected() only reports peer connections, not all (seed, refinery) connections.
draoi 2 лет назад
Родитель
Сommit
3b0e012126
5 измененных файлов с 19 добавлено и 15 удалено
  1. 1 1
      src/event_graph/mod.rs
  2. 4 2
      src/net/hosts.rs
  3. 6 4
      src/net/p2p.rs
  4. 6 6
      src/net/session/outbound_session.rs
  5. 2 2
      src/net/tests.rs

+ 1 - 1
src/event_graph/mod.rs

@@ -211,7 +211,7 @@ impl EventGraph {
         //   from the beginning
 
         // Get references to all our peers.
-        let channels = self.p2p.hosts().channels();
+        let channels = self.p2p.hosts().peers();
         let mut communicated_peers = channels.len();
         info!(
             target: "event_graph::dag_sync()",

+ 4 - 2
src/net/hosts.rs

@@ -979,7 +979,8 @@ impl Hosts {
         debug!(target: "net::hosts::unregister()", "Unregistered: {}", &addr);
     }
 
-    /// Returns the list of connected channels.
+    /// Return the list of all connected channels, including seed and
+    /// refinery connections.
     pub fn channels(&self) -> Vec<ChannelPtr> {
         let registry = self.registry.lock().unwrap();
         let mut channels = Vec::new();
@@ -992,7 +993,8 @@ impl Hosts {
         channels
     }
 
-    /// Returns the list of connected channels, excluding seed connections.
+    /// Return the list of connected peers. Seed and refinery connections
+    /// are not taken into account.
     pub fn peers(&self) -> Vec<ChannelPtr> {
         let registry = self.registry.lock().unwrap();
         let mut channels = Vec::new();

+ 6 - 4
src/net/p2p.rs

@@ -169,16 +169,16 @@ impl P2p {
         self.session_refine().stop().await;
     }
 
-    /// Broadcasts a message concurrently across all active channels.
+    /// Broadcasts a message concurrently across all active peers.
     pub async fn broadcast<M: Message>(&self, message: &M) {
         self.broadcast_with_exclude(message, &[]).await
     }
 
-    /// Broadcasts a message concurrently across active channels, excluding
+    /// Broadcasts a message concurrently across active peers, excluding
     /// the ones provided in `exclude_list`.
     pub async fn broadcast_with_exclude<M: Message>(&self, message: &M, exclude_list: &[Url]) {
         let mut channels = Vec::new();
-        for channel in self.hosts().channels() {
+        for channel in self.hosts().peers() {
             if exclude_list.contains(channel.address()) {
                 continue
             }
@@ -213,8 +213,10 @@ impl P2p {
         let _results: Vec<_> = futures.collect().await;
     }
 
+    /// Check whether this node has connections to any peers. This method will
+    /// not report seedsync or refinery connections.
     pub fn is_connected(&self) -> bool {
-        !self.hosts().channels().is_empty()
+        !self.hosts().peers().is_empty()
     }
 
     /// Return an atomic pointer to the set network settings

+ 6 - 6
src/net/session/outbound_session.rs

@@ -458,9 +458,9 @@ pub trait PeerDiscoveryBase {
     fn p2p(&self) -> P2pPtr;
 }
 
-/// Main PeerDiscovery process that loops through connected channels
+/// Main PeerDiscovery process that loops through connected peers
 /// and sends out a `GetAddrs` when it is active. If there are no
-/// connected channels after two attempts, connect to our seed nodes
+/// connected peers after two attempts, connect to our seed nodes
 /// and perform `SeedSyncSession`.
 struct PeerDiscovery {
     process: StoppableTaskPtr,
@@ -494,7 +494,7 @@ impl PeerDiscoveryBase for PeerDiscovery {
     }
 
     /// Activate peer discovery if not active already. For the first two
-    /// attempts, this will loop through all connected P2P channels and send
+    /// attempts, this will loop through all connected P2P peers and send
     /// out a `GetAddrs` message to request more peers. Other parts of the
     /// P2P stack will then handle the incoming addresses and place them in
     /// the hosts list.  
@@ -555,12 +555,12 @@ impl PeerDiscoveryBase for PeerDiscovery {
             // First 2 times try sending GetAddr to the network.
             // 3rd time do a seed sync.
             if self.p2p().is_connected() && current_attempt <= 2 {
-                // Broadcast the GetAddrs message to all active channels.
-                // If we have no active channels, we will perform a SeedSyncSession instead.
+                // Broadcast the GetAddrs message to all active peers.
+                // If we have no active peers, we will perform a SeedSyncSession instead.
 
                 info!(
                     target: "net::outbound_session::peer_discovery()",
-                    "[P2P] Requesting addrs from active channels. Attempt: {}",
+                    "[P2P] Requesting addrs from active peers. Attempt: {}",
                     current_attempt
                 );
 

+ 2 - 2
src/net/tests.rs

@@ -459,8 +459,8 @@ async fn p2p_test_real(ex: Arc<Executor<'static>>) {
         info!("========================================================");
         info!("Checking manual node={}", p2p.settings().read().await.node_id);
         info!("========================================================");
-        let channels = p2p.hosts().channels();
-        assert!(channels.len() == N_CONNS * 2);
+        let peers = p2p.hosts().peers();
+        assert!(peers.len() == N_CONNS * 2);
     }
 
     info!("========================================================");