Эх сурвалжийг харах

net: working greylist protocol

Working on this commit:

* Nodes connect to a seed node, do ProtocolAddr, ping themselves and send over their ADDR if the address is reachable.
* Seed nodes add addresses into greylist, probe them to make sure they're reachable, then promote to whitelist and send to other peers.
* On receiving whitelisted addresses, nodes add to greylist and after performing refinery process, promote to whitelist.

Still TODO:

* reimplement address filtering
* test: unstable_sort_by_key
* implement "anchor" connections when we've already established a connection to a node
* keep track of how many times we ping ourselves to avoid redundant self ping
* idle handshake protocol
lunar-mining 2 жил өмнө
parent
commit
0639e9bdf7

+ 3 - 1
bin/lilith/src/main.rs

@@ -411,7 +411,9 @@ async fn realmain(args: Args, ex: Arc<Executor<'static>>) -> Result<()> {
     info!(target: "lilith", "Caught termination signal, cleaning up and exiting...");
 
     // Save in-memory hosts to tsv file
-    save_hosts(&expand_path(&args.hosts_file)?, &lilith.networks).await;
+    //info!(target: "lilith", "Saving hosts...");
+    // TODO: FIXME: this is broken
+    //save_hosts(&expand_path(&args.hosts_file)?, &lilith.networks).await;
 
     info!(target: "lilith", "Stopping JSON-RPC server...");
     rpc_task.stop().await;

+ 10 - 28
src/net/hosts/refinery.rs

@@ -77,47 +77,29 @@ impl GreylistRefinery {
 
             if hosts.is_empty_greylist().await {
                 warn!(target: "net::refinery::run()",
-                "Greylist is empty! Cannot start refinery process. Sleeping...");
-                sleep(5).await;
+                "Greylist is empty! Cannot start refinery process");
             } else {
                 debug!(target: "net::refinery::run()", "Starting refinery process");
                 // Randomly select an entry from the greylist.
-                let greylist = hosts.greylist.read().await;
-                let position = rand::thread_rng().gen_range(0..greylist.len());
-                let entry = &greylist[position];
+                let (entry, position) = hosts.greylist_fetch_random().await;
                 let url = &entry.0;
 
                 if ping_node(url, self.p2p().clone()).await {
-                    let whitelist = hosts.whitelist.read().await;
-                    // Remove oldest element if the whitelist reaches max size.
-                    if whitelist.len() == 1000 {
-                        // Last element in vector should have the oldest timestamp.
-                        // This should never crash as only returns None when whitelist len() == 0.
-                        let mut whitelist = hosts.whitelist.write().await;
-                        let entry = whitelist.pop().unwrap();
-                        debug!(target: "net::refinery::run()", "Whitelist reached max size. Removed host {}", entry.0);
-                    }
-
                     // Peer is responsive. Update last_seen and add it to the whitelist.
                     let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
 
                     // Append to the whitelist.
-                    debug!(target: "net::refinery::run()", "Adding peer {} to whitelist", url);
-                    let mut whitelist = hosts.whitelist.write().await;
-                    whitelist.push((url.clone(), last_seen));
-
-                    // Sort whitelist by last_seen.
-                    whitelist.sort_unstable_by_key(|entry| entry.1);
+                    hosts.whitelist_store_or_update(url, last_seen).await.unwrap();
 
                     // Remove whitelisted peer from the greylist.
-                    debug!(target: "net::refinery::run()", "Removing whitelisted peer {} from greylist", url);
-                    let mut greylist = hosts.greylist.write().await;
-                    greylist.remove(position);
-                } else {
-                    let mut greylist = hosts.greylist.write().await;
-                    greylist.remove(position);
-                    debug!(target: "net::refinery::run()", "Peer {} is not response. Removed from greylist", url);
+                    hosts.greylist_remove(url, position).await;
                 }
+                // TODO: verify this behavior against monero impl.
+                //else {
+                //    let mut greylist = hosts.greylist.write().await;
+                //    greylist.remove(position);
+                //    debug!(target: "net::refinery::run()", "Peer {} is not response. Removed from greylist", url);
+                //}
             }
 
             // TODO: create a custom net setting for this timer

+ 145 - 111
src/net/hosts/store.rs

@@ -22,6 +22,7 @@ use log::{debug, trace, warn};
 use rand::{
     prelude::{IteratorRandom, SliceRandom},
     rngs::OsRng,
+    Rng,
 };
 use smol::lock::RwLock;
 use url::Url;
@@ -39,6 +40,9 @@ pub type HostsPtr = Arc<Hosts>;
 // TODO: This could perhaps be more exhaustive?
 pub const LOCAL_HOST_STRS: [&str; 2] = ["localhost", "localhost.localdomain"];
 
+const WHITELIST_MAX_LEN: usize = 5000;
+const GREYLIST_MAX_LEN: usize = 2000;
+
 /// Manages a store of network addresses
 pub struct Hosts {
     // Intermediary node list that is periodically probed and updated to whitelist.
@@ -159,37 +163,41 @@ impl Hosts {
     // Otherwise, update the last_seen field.
     // TODO: test the performance of this method. It might be costly.
     pub async fn whitelist_store_or_update(&self, addr: &Url, last_seen: u64) -> Result<()> {
-        debug!(target: "net::hosts::whitelist_store_or_update()",
-        "hosts::whitelist_store_or_update() [START]");
+        debug!(target: "net::hosts::whitelist_store_or_update()", "[START]");
 
         if !self.whitelist_contains(addr).await {
+            debug!(target: "net::hosts::whitelist_store_or_update()",
+        "We do not have this entry in the whitelist. Adding to store...");
+
             self.whitelist_store(addr, last_seen).await;
         } else {
+            debug!(target: "net::hosts::whitelist_store_or_update()",
+        "We have this entry in the whitelist. Updating last seen...");
+
             let index = self.get_whitelist_index_at_addr(addr).await?;
             self.whitelist_update_last_seen(addr, last_seen, index).await;
         }
         Ok(())
     }
 
-    // Update the last_seen field for a Url on the whitelist.
-    pub async fn whitelist_update(&self, addr: &Url, last_seen: u64) -> Result<()> {
-        let index = self.get_whitelist_index_at_addr(addr).await?;
-        self.whitelist_update_last_seen(addr, last_seen, index).await;
-        Ok(())
-    }
+    //// Update the last_seen field for a Url on the whitelist.
+    //pub async fn whitelist_update(&self, addr: &Url, last_seen: u64) -> Result<()> {
+    //    let index = self.get_whitelist_index_at_addr(addr).await?;
+    //    self.whitelist_update_last_seen(addr, last_seen, index).await;
+    //    Ok(())
+    //}
 
     pub async fn greylist_store_or_update(&self, addrs: &[(Url, u64)]) -> Result<()> {
-        debug!(target: "net::hosts::greylist_store_or_update()",
-        "hosts::greylist_store_or_update() [START]");
+        debug!(target: "net::hosts::store::greylist_store_or_update()", "[START]");
 
         for (addr, last_seen) in addrs {
             if !self.greylist_contains(addr).await {
-                debug!(target: "net::greylist_store_or_update()", "New greylist candidate found!");
-                // TODO: clean this up: greylist_store one item at a time
-                self.greylist_store(&[(addr.clone(), last_seen.clone())]).await;
+                debug!(target: "net::hosts::store::greylist_store_or_update()", "We do not have this entry in the greylist. Adding to store...");
+
+                self.greylist_store(&addr, last_seen.clone()).await;
             } else {
-                debug!(target: "net::greylist_store_or_update()",
-                "Existing greylist entry found. Updating last_seen...");
+                debug!(target: "net::hosts::store::greylist_store_or_update()",
+                "We have this entry in the greylist. Updating last seen...");
 
                 let index = self.get_greylist_index_at_addr(addr).await?;
                 self.greylist_update_last_seen(addr, last_seen.clone(), index).await;
@@ -199,85 +207,80 @@ impl Hosts {
     }
 
     // Append host to the greylist. Called on learning of a new peer.
-    pub async fn greylist_store(&self, addrs: &[(Url, u64)]) {
+    // TODO: FIXME: address filtering
+    pub async fn greylist_store(&self, addr: &Url, last_seen: u64) {
         debug!(target: "net::hosts::greylist_store()", "hosts::greylist_store() [START]");
 
-        debug!(target: "net::hosts::greylist_store()", "Filtering addresses...");
-        let filtered_addrs = self.filter_addresses(addrs).await;
-        let filtered_addrs_len = filtered_addrs.len();
+        let mut greylist = self.greylist.try_write().unwrap();
 
-        debug!(target: "net::hosts::greylist_store()", "Filtered addresses.");
-        if !filtered_addrs.is_empty() {
-            debug!(target: "net::hosts::greylist_store()", "Starting greylist write...");
-            let mut greylist = self.greylist.write().await;
-            debug!(target: "net::hosts::greylist_store()", "Achieved write lock on greylist!");
-
-            // Remove oldest element if the greylist reaches max size.
-            if greylist.len() == 5000 {
-                let last_entry = greylist.pop().unwrap();
-                debug!(target: "net::hosts::greylist_store()", "Greylist reached max size. Removed {:?}", last_entry);
-            } else {
-                for (addr, last_seen) in filtered_addrs {
-                    debug!(target: "net::hosts::greylist_store()", "Inserting {}", addr);
-                    greylist.push((addr.clone(), last_seen.clone()))
-                }
-
-                // Sort the list by last_seen.
-                greylist.sort_unstable_by_key(|entry| entry.1);
-            }
+        // Remove oldest element if the greylist reaches max size.
+        if greylist.len() == GREYLIST_MAX_LEN {
+            let last_entry = greylist.pop().unwrap();
+            debug!(target: "net::hosts::greylist_store()", "Greylist reached max size. Removed {:?}", last_entry);
         } else {
-            debug!(target: "net::hosts::greylist_store()", "Empty address message...")
-        }
+            debug!(target: "net::hosts::greylist_store()", "Inserting {}", addr);
+            greylist.push((addr.clone(), last_seen.clone()));
 
-        self.store_subscriber.notify(filtered_addrs_len).await;
-        debug!(target: "net::hosts::greylist_store()", "hosts::greylist_store() [END]");
+            // Sort the list by last_seen.
+            greylist.sort_by_key(|entry| entry.1);
+        }
+        debug!(target: "net::hosts::greylist_store()", "[END]");
     }
 
     // Append host to the whitelist. Called after a successful interaction with an online peer.
+    // TODO: FIXME: address filtering
     pub async fn whitelist_store(&self, addr: &Url, last_seen: u64) {
-        debug!(target: "net::hosts::whitelist_store()", "hosts::whitelist_store() [START]");
-
-        let mut whitelist = self.whitelist.write().await;
+        debug!(target: "net::hosts::whitelist_store()", "[START]");
 
-        debug!(target: "net::hosts::whitelist_store()", "Inserting {}. Last seen {:?}", addr, last_seen);
+        let mut whitelist = self.whitelist.try_write().unwrap();
 
         // Remove oldest element if the whitelist reaches max size.
-        if whitelist.len() == 1000 {
+        if whitelist.len() == WHITELIST_MAX_LEN {
             let last_entry = whitelist.pop().unwrap();
-            debug!(target: "net::hosts::whitelist_store()", "Whitelist reached max size. Removed {:?}", last_entry);
-        }
-        whitelist.push((addr.clone(), last_seen));
-
-        // Sort the list by last_seen.
-        whitelist.sort_unstable_by_key(|entry| entry.1);
+            debug!(target: "net::hosts::store::whitelist_store()", "Whitelist reached max size. Removed {:?}", last_entry);
+        } else {
+            debug!(target: "net::hosts::store::whitelist_store()", "Inserting {}. Last seen {:?}", addr, last_seen);
+            whitelist.push((addr.clone(), last_seen));
 
-        debug!(target: "net::hosts::whitelist_store()", "hosts::whitelist_store() [END]");
+            // Sort the list by last_seen.
+            whitelist.sort_by_key(|entry| entry.1);
+        }
+        debug!(target: "net::hosts::store::whitelist_store()", "[END]");
     }
 
     // Update the last_seen field of a peer on the whitelist.
     pub async fn whitelist_update_last_seen(&self, addr: &Url, last_seen: u64, index: usize) {
-        debug!(target: "net::hosts::update_last_seen()", "hosts::update_last_seen() [START]");
+        debug!(target: "net::hosts::store::whitelist_update_last_seen()", "[START]");
 
-        let mut whitelist = self.whitelist.write().await;
+        let mut whitelist = self.whitelist.try_write().unwrap();
 
         whitelist[index] = (addr.clone(), last_seen);
+
+        // Sort the list by last_seen.
+        whitelist.sort_by_key(|entry| entry.1);
+
+        debug!(target: "net::hosts::store::whitelist_update_last_seen()", "[END]");
     }
 
     // Update the last_seen field of a peer on the greylist.
     pub async fn greylist_update_last_seen(&self, addr: &Url, last_seen: u64, index: usize) {
-        debug!(target: "net::hosts::greylist_update_last_seen()", 
-               "hosts::greylist_update_last_seen() [START]");
+        debug!(target: "net::hosts::greylist_update_last_seen()", "[START]");
 
-        let mut greylist = self.greylist.write().await;
+        let mut greylist = self.greylist.try_write().unwrap();
 
         greylist[index] = (addr.clone(), last_seen);
+
+        // Sort the list by last_seen.
+        greylist.sort_by_key(|entry| entry.1);
+
+        debug!(target: "net::hosts::store::greylist_update_last_seen()", "[END]");
     }
 
     pub async fn whitelist_downgrade(&self, addr: &Url) {
         // First lookup the entry using its addr.
         let mut entry = vec![];
 
-        let whitelist = self.whitelist.read().await;
+        let whitelist = self.whitelist.try_read().unwrap();
         for (url, time) in whitelist.iter() {
             if url == addr {
                 entry.push((url.clone(), time.clone()));
@@ -288,7 +291,7 @@ impl Hosts {
         assert!(entry.len() == 1);
 
         // Remove this item from the whitelist.
-        let mut whitelist = self.whitelist.write().await;
+        let mut whitelist = self.whitelist.try_write().unwrap();
         // TODO: test!
         let index = whitelist.iter().position(|x| *x == entry[0]);
         // This should never fail since the entry exists.
@@ -297,7 +300,17 @@ impl Hosts {
         // Add it to the greylist.
         let addr = entry[0].0.clone();
         let last_seen = entry[0].1.clone();
-        self.greylist_store(&[(addr, last_seen)]).await;
+        self.greylist_store(&addr, last_seen).await;
+    }
+
+    pub async fn greylist_remove(&self, addr: &Url, position: usize) {
+        debug!(target: "net::refinery::run()", "Removing whitelisted peer {} from greylist", addr);
+        let mut greylist = self.greylist.try_write().unwrap();
+
+        greylist.remove(position);
+
+        // Sort the list by last_seen.
+        greylist.sort_by_key(|entry| entry.1);
     }
 
     pub async fn subscribe_store(&self) -> Result<Subscription<usize>> {
@@ -511,6 +524,13 @@ impl Hosts {
         urls.iter().map(|&url| url.clone()).collect()
     }
 
+    pub async fn greylist_fetch_random(&self) -> ((Url, u64), usize) {
+        let greylist = self.greylist.read().await;
+        let position = rand::thread_rng().gen_range(0..greylist.len());
+        let entry = &greylist[position];
+        (entry.clone(), position.clone())
+    }
+
     /// Get up to n random whitelisted peers that match the given transport schemes from the hosts set.
     pub async fn whitelist_fetch_n_random_with_schemes(
         &self,
@@ -521,16 +541,19 @@ impl Hosts {
         if n == 0 {
             return vec![]
         }
+        debug!(target: "store::whitelist_fetch_n_random_with_schemes", "[START]");
 
         // Retrieve all peers corresponding to that transport schemes
         let hosts = self.whitelist_fetch_with_schemes(schemes, None).await;
         if hosts.is_empty() {
-            warn!(target: "store::whitelist_fetch_n_random_with_schemes",
+            debug!(target: "store::whitelist_fetch_n_random_with_schemes",
                   "Whitelist is empty! Exiting...");
             return hosts
         }
 
         // Grab random ones
+        debug!(target: "store::whitelist_fetch_n_random_with_schemes",
+               "whitelist is not empty! sending whitelist contents");
         let urls = hosts.iter().choose_multiple(&mut OsRng, n.min(hosts.len()));
         urls.iter().map(|&url| url.clone()).collect()
     }
@@ -545,28 +568,34 @@ impl Hosts {
         if n == 0 {
             return vec![]
         }
+        debug!(target: "store::whitelist_fetch_excluding_schemes", "[START]");
 
         // Retrieve all peers not corresponding to that transport schemes
         let hosts = self.whitelist_fetch_excluding_schemes(schemes, None).await;
         if hosts.is_empty() {
-            warn!(target: "store::whitelist_fetch_n_random_excluding_schemes",
+            debug!(target: "store::whitelist_fetch_n_random_excluding_schemes",
                   "Whitelist is empty! Exiting...");
             return hosts
         }
 
         // Grab random ones
+        debug!(target: "store::whitelist_fetch_n_random_excluding_schemes",
+               "whitelist is not empty! sending whitelist contents");
+
         let urls = hosts.iter().choose_multiple(&mut OsRng, n.min(hosts.len()));
         urls.iter().map(|&url| url.clone()).collect()
     }
 
     /// Get up to limit peers that match the given transport schemes from the whitelist.
     /// If limit was not provided, return all matching peers.
-    pub async fn whitelist_fetch_with_schemes(
+    async fn whitelist_fetch_with_schemes(
         &self,
         schemes: &[String],
         limit: Option<usize>,
     ) -> Vec<(Url, u64)> {
-        let whitelist = self.whitelist.read().await;
+        debug!(target: "store::whitelist_fetch_with_schemes", "[START]");
+        let whitelist = self.whitelist.try_read().unwrap();
+
         let mut limit = match limit {
             Some(l) => l.min(whitelist.len()),
             None => whitelist.len(),
@@ -582,6 +611,7 @@ impl Hosts {
                 ret.push((addr.clone(), *last_seen));
                 limit -= 1;
                 if limit == 0 {
+                    debug!(target: "store::whitelist_fetch_with_schemes", "Found matching scheme, returning");
                     return ret
                 }
             }
@@ -589,7 +619,9 @@ impl Hosts {
 
         // If we didn't find any, pick some from the greylist
         if ret.is_empty() {
-            for (addr, last_seen) in self.greylist.read().await.iter() {
+            debug!(target: "store::whitelist_fetch_with_schemes", "No matching schemes! We must look at greylist");
+            let greylist = self.greylist.try_read().unwrap();
+            for (addr, last_seen) in greylist.iter() {
                 if schemes.contains(&addr.scheme().to_string()) {
                     ret.push((addr.clone(), *last_seen));
                     limit -= 1;
@@ -600,6 +632,8 @@ impl Hosts {
             }
         }
 
+        debug!(target: "store::whitelist_fetch_with_schemes", "END");
+
         ret
     }
 
@@ -690,50 +724,50 @@ mod tests {
         });
     }
 
-    #[test]
-    fn test_greylist_store() {
-        let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
-
-        smol::block_on(async {
-            let settings = Settings {
-                localnet: false,
-                external_addrs: vec![
-                    Url::parse("tcp://foo.bar:123").unwrap(),
-                    Url::parse("tcp://lol.cat:321").unwrap(),
-                ],
-                ..Default::default()
-            };
-
-            let hosts = Hosts::new(Arc::new(settings.clone()));
-            let mut external_addrs = vec![];
-            for addr in settings.external_addrs {
-                external_addrs.push((addr, last_seen))
-            }
-
-            hosts.greylist_store(&external_addrs).await;
-            assert!(hosts.is_empty_greylist().await);
-
-            let local_hosts = vec![
-                (Url::parse("tcp://localhost:3921").unwrap(), last_seen),
-                (Url::parse("tor://[::1]:21481").unwrap(), last_seen),
-                (Url::parse("tcp://192.168.10.65:311").unwrap(), last_seen),
-                (Url::parse("tcp+tls://0.0.0.0:2312").unwrap(), last_seen),
-                (Url::parse("tcp://255.255.255.255:2131").unwrap(), last_seen),
-            ];
-            hosts.greylist_store(&local_hosts).await;
-            assert!(hosts.is_empty_greylist().await);
-
-            let remote_hosts = vec![
-                (Url::parse("tcp://dark.fi:80").unwrap(), last_seen),
-                (Url::parse("tcp://http.cat:401").unwrap(), last_seen),
-                (Url::parse("tcp://foo.bar:111").unwrap(), last_seen),
-            ];
-            hosts.greylist_store(&remote_hosts).await;
-            assert!(hosts.greylist_contains(&remote_hosts[0].0).await);
-            assert!(hosts.greylist_contains(&remote_hosts[1].0).await);
-            assert!(!hosts.greylist_contains(&remote_hosts[2].0).await);
-        });
-    }
+    //#[test]
+    //fn test_greylist_store() {
+    //    let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
+
+    //    smol::block_on(async {
+    //        let settings = Settings {
+    //            localnet: false,
+    //            external_addrs: vec![
+    //                Url::parse("tcp://foo.bar:123").unwrap(),
+    //                Url::parse("tcp://lol.cat:321").unwrap(),
+    //            ],
+    //            ..Default::default()
+    //        };
+
+    //        let hosts = Hosts::new(Arc::new(settings.clone()));
+    //        let mut external_addrs = vec![];
+    //        for addr in settings.external_addrs {
+    //            external_addrs.push((addr, last_seen))
+    //        }
+
+    //        hosts.greylist_store(&external_addrs).await;
+    //        assert!(hosts.is_empty_greylist().await);
+
+    //        let local_hosts = vec![
+    //            (Url::parse("tcp://localhost:3921").unwrap(), last_seen),
+    //            (Url::parse("tor://[::1]:21481").unwrap(), last_seen),
+    //            (Url::parse("tcp://192.168.10.65:311").unwrap(), last_seen),
+    //            (Url::parse("tcp+tls://0.0.0.0:2312").unwrap(), last_seen),
+    //            (Url::parse("tcp://255.255.255.255:2131").unwrap(), last_seen),
+    //        ];
+    //        hosts.greylist_store(&local_hosts).await;
+    //        assert!(hosts.is_empty_greylist().await);
+
+    //        let remote_hosts = vec![
+    //            (Url::parse("tcp://dark.fi:80").unwrap(), last_seen),
+    //            (Url::parse("tcp://http.cat:401").unwrap(), last_seen),
+    //            (Url::parse("tcp://foo.bar:111").unwrap(), last_seen),
+    //        ];
+    //        hosts.greylist_store(&remote_hosts).await;
+    //        assert!(hosts.greylist_contains(&remote_hosts[0].0).await);
+    //        assert!(hosts.greylist_contains(&remote_hosts[1].0).await);
+    //        assert!(!hosts.greylist_contains(&remote_hosts[2].0).await);
+    //    });
+    //}
 
     #[test]
     fn test_whitelist_store() {

+ 10 - 6
src/net/protocol/protocol_address.rs

@@ -128,6 +128,9 @@ impl ProtocolAddress {
             // TODO: Verify this limit. It should be the max number of all our allowed transports,
             //       plus their mixing.
             if get_addrs_msg.transports.len() > 20 {
+                warn!(target: "net::protocol_address::handle_receive_get_addrs()",
+                "Sending empty Addrs message");
+
                 // TODO: Should this error out, effectively ending the connection?
                 let addrs_msg = AddrsMessage { addrs: vec![] };
                 self.channel.send(&addrs_msg).await?;
@@ -135,6 +138,8 @@ impl ProtocolAddress {
             }
 
             // First we grab address with the requested transports
+            debug!(target: "net::protocol_address::handle_receive_get_addrs()",
+            "Fetching whitelist entries with schemes");
             let mut addrs = self
                 .hosts
                 .whitelist_fetch_n_random_with_schemes(&get_addrs_msg.transports, get_addrs_msg.max)
@@ -142,6 +147,8 @@ impl ProtocolAddress {
 
             // Then we grab addresses without the requested transports
             // to fill a 2 * max length vector.
+            debug!(target: "net::protocol_address::handle_receive_get_addrs()",
+            "Fetching whitelist entries without schemes");
             let remain = 2 * get_addrs_msg.max - addrs.len() as u32;
             addrs.append(
                 &mut self
@@ -167,21 +174,18 @@ impl ProtocolAddress {
         let type_id = self.channel.session_type_id();
 
         if type_id != SESSION_OUTBOUND {
-            warn!(target: "net::protocol_address::send_my_addrs()",
-            "Not an outbound session. Stopping");
+            debug!(target: "net::protocol_address::send_my_addrs()", "Not an outbound session. Stopping");
             return Ok(())
         }
 
         if self.settings.external_addrs.is_empty() {
-            warn!(target: "net::protocol_address::send_my_addrs()",
-            "External addr not configured. Stopping");
+            debug!(target: "net::protocol_address::send_my_addrs()", "External addr not configured. Stopping");
             return Ok(())
         }
 
         // Do nothing if advertise is set to false
         if self.settings.advertise == false {
-            warn!(target: "net::protocol_address::send_my_addrs()",
-            "Advertise is false. Stopping");
+            debug!(target: "net::protocol_address::send_my_addrs()", "Advertise is false. Stopping");
             return Ok(())
         }
 

+ 25 - 27
src/net/tests.rs

@@ -31,7 +31,7 @@ use crate::{
 };
 
 // Number of nodes to spawn and number of peers each node connects to
-const N_NODES: usize = 1;
+const N_NODES: usize = 5;
 const N_CONNS: usize = 2;
 
 // TODO: test whitelist propagation between peers
@@ -42,10 +42,10 @@ const N_CONNS: usize = 2;
 fn p2p_test() {
     let mut cfg = simplelog::ConfigBuilder::new();
     //cfg.add_filter_ignore("sled".to_string());
-    cfg.add_filter_ignore("net::channel::subscribe_stop()".to_string());
+    //cfg.add_filter_ignore("net::channel::subscribe_stop()".to_string());
     //cfg.add_filter_ignore("net::hosts".to_string());
     //cfg.add_filter_ignore("net::session".to_string());
-    cfg.add_filter_ignore("net::message_subscriber".to_string());
+    //cfg.add_filter_ignore("net::message_subscriber".to_string());
     //cfg.add_filter_ignore("net::protocol_ping".to_string());
     //cfg.add_filter_ignore("net::protocol_version".to_string());
     //cfg.add_filter_ignore("net::protocol_jobs_manager".to_string());
@@ -90,23 +90,23 @@ async fn hostlist_propagation(ex: Arc<Executor<'static>>) {
     let mut p2p_instances = vec![];
     //let mut rng = rand::thread_rng();
 
-    info!("Initializing seed network");
-    let settings = Settings {
-        localnet: true,
-        inbound_addrs: vec![seed_addr.clone()],
-        external_addrs: vec![seed_addr.clone()],
-        outbound_connections: 0,
-        outbound_connect_timeout: 2,
-        inbound_connections: usize::MAX,
-        peers: vec![],
-        allowed_transports: vec!["tcp".to_string()],
-        node_id: "seed".to_string(),
-        //advertise: true,
-        ..Default::default()
-    };
-
-    let p2p = P2p::new(settings, ex.clone()).await;
-    p2p_instances.push(p2p);
+    //info!("Initializing seed network");
+    //let settings = Settings {
+    //    localnet: true,
+    //    inbound_addrs: vec![seed_addr.clone()],
+    //    external_addrs: vec![seed_addr.clone()],
+    //    outbound_connections: 0,
+    //    outbound_connect_timeout: 2,
+    //    inbound_connections: usize::MAX,
+    //    peers: vec![],
+    //    allowed_transports: vec!["tcp".to_string()],
+    //    node_id: "seed".to_string(),
+    //    //advertise: true,
+    //    ..Default::default()
+    //};
+
+    //let p2p = P2p::new(settings, ex.clone()).await;
+    //p2p_instances.push(p2p);
 
     info!("Initializing outbound nodes");
     for i in 0..N_NODES {
@@ -143,20 +143,18 @@ async fn hostlist_propagation(ex: Arc<Executor<'static>>) {
         p2p.clone().start().await.unwrap();
     }
 
-    info!("Waiting 30s until all peers connect");
-    sleep(30).await;
+    info!("Waiting 10s until all peers connect");
+    sleep(15).await;
 
     info!("Inspecting peerlists...");
     for p2p in p2p_instances.iter() {
         let hosts = p2p.hosts();
-        info!("START peerlist {}", p2p.settings().node_id);
         assert!(!hosts.is_empty_greylist().await);
         let greylist = hosts.greylist.read().await;
-        for (url, last_seen) in greylist.iter() {
-            info!("{}", url);
-            info!("{}", last_seen);
+        info!("Peer {}", p2p.settings().node_id);
+        for (i, (url, last_seen)) in greylist.iter().enumerate() {
+            info!("Greylist entry {}: {}, {}", i, url, last_seen);
         }
-        info!("END peerlist {}", p2p.settings().node_id);
     }
 
     // Stop the P2P network