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

net,bin/lilith: allow localhost to be blacklisted in localnet mode, this will allow us to test banning/blacklisting features

oars 1 жил өмнө
parent
commit
c183c6f377

+ 2 - 2
bin/lilith/src/main.rs

@@ -201,7 +201,7 @@ impl Lilith {
                         debug!(target: "net::refinery:::whitelist_refinery",
                        "Host {url} is not responsive. Downgrading from whitelist");
 
-                        hosts.greylist_host(url, *last_seen)?;
+                        hosts.greylist_host(url, *last_seen).await?;
 
                         continue
                     }
@@ -212,7 +212,7 @@ impl Lilith {
                     // This node is active. Update the last seen field.
                     let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
 
-                    hosts.whitelist_host(url, last_seen)?;
+                    hosts.whitelist_host(url, last_seen).await?;
                 }
                 None => {
                     debug!(target: "net::refinery::whitelist_refinery",

+ 1 - 1
src/net/channel.rs

@@ -514,7 +514,7 @@ impl Channel {
 
         let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
         info!(target: "net::channel::ban()", "Blacklisting peer={peer}");
-        match self.p2p().hosts().move_host(&peer, last_seen, HostColor::Black) {
+        match self.p2p().hosts().move_host(&peer, last_seen, HostColor::Black).await {
             Ok(()) => {
                 info!(target: "net::channel::ban()", "Peer={peer} blacklisted successfully");
             }

+ 6 - 6
src/net/hosts.rs

@@ -1447,9 +1447,9 @@ impl Hosts {
     }
 
     /// Downgrade host to Greylist, remove from Gold or White list.
-    pub fn greylist_host(&self, addr: &Url, last_seen: u64) -> Result<()> {
+    pub async fn greylist_host(&self, addr: &Url, last_seen: u64) -> Result<()> {
         debug!(target: "net::hosts:greylist_host()", "Downgrading addr={addr}");
-        self.move_host(addr, last_seen, HostColor::Grey)?;
+        self.move_host(addr, last_seen, HostColor::Grey).await?;
 
         // Free up this addr for future operations.
         self.unregister(addr);
@@ -1457,9 +1457,9 @@ impl Hosts {
         Ok(())
     }
 
-    pub fn whitelist_host(&self, addr: &Url, last_seen: u64) -> Result<()> {
+    pub async fn whitelist_host(&self, addr: &Url, last_seen: u64) -> Result<()> {
         debug!(target: "net::hosts:whitelist_host()", "Upgrading addr={addr}");
-        self.move_host(addr, last_seen, HostColor::White)?;
+        self.move_host(addr, last_seen, HostColor::White).await?;
 
         // Free up this addr for future operations.
         self.unregister(addr);
@@ -1480,7 +1480,7 @@ impl Hosts {
     /// The state transition from `Move` to `Connected` or `Suspend` are both valid operations.
     /// In some cases, `unregister()` can be called after `move_host()` to explicitly mark
     /// the host state as `Free`.
-    pub(in crate::net) fn move_host(
+    pub(in crate::net) async fn move_host(
         &self,
         addr: &Url,
         last_seen: u64,
@@ -1530,7 +1530,7 @@ impl Hosts {
                 if addr.host_str().is_some() {
                     // Localhost connections should never enter the blacklist
                     // This however allows any Tor, Nym and I2p connections.
-                    if self.is_local_host(addr) {
+                    if !self.settings.read().await.localnet && self.is_local_host(addr) {
                         return Ok(());
                     }
 

+ 5 - 2
src/net/session/mod.rs

@@ -83,7 +83,7 @@ pub async fn remove_sub_on_stop(
         // error in this case.
         match hosts.fetch_last_seen(addr) {
             Some(last_seen) => {
-                if let Err(e) = hosts.move_host(addr, last_seen, HostColor::Grey) {
+                if let Err(e) = hosts.move_host(addr, last_seen, HostColor::Grey).await {
                     error!(target: "net::session::remove_sub_on_stop()",
             "Failed to move host {} to Greylist! Err={e}", addr.clone());
                 }
@@ -203,7 +203,10 @@ pub trait Session: Sync {
 
                     let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
 
-                    self.p2p().hosts().move_host(channel.address(), last_seen, HostColor::Gold)?;
+                    self.p2p()
+                        .hosts()
+                        .move_host(channel.address(), last_seen, HostColor::Gold)
+                        .await?;
                 }
 
                 // Attempt to add channel to registry

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

@@ -388,7 +388,7 @@ impl Slot {
                 );
 
                 // Peer disconnected during the registry process. We'll downgrade this peer now.
-                self.p2p().hosts().move_host(&addr, last_seen, HostColor::Grey)?;
+                self.p2p().hosts().move_host(&addr, last_seen, HostColor::Grey).await?;
 
                 // Mark its state as Suspend, which sends this node to the Refinery for processing.
                 self.p2p().hosts().try_register(addr.clone(), HostState::Suspend).unwrap();
@@ -431,7 +431,7 @@ impl Slot {
                 }
 
                 // At this point we failed to connect. We'll downgrade this peer now.
-                self.p2p().hosts().move_host(&addr, last_seen, HostColor::Grey)?;
+                self.p2p().hosts().move_host(&addr, last_seen, HostColor::Grey).await?;
 
                 // Mark its state as Suspend, which sends it to the Refinery for processing.
                 self.p2p().hosts().try_register(addr.clone(), HostState::Suspend).unwrap();

+ 1 - 1
src/net/session/refine_session.rs

@@ -294,7 +294,7 @@ impl GreylistRefinery {
                     );
                     let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
 
-                    hosts.whitelist_host(url, last_seen).unwrap();
+                    hosts.whitelist_host(url, last_seen).await.unwrap();
 
                     debug!(target: "net::refinery", "GreylistRefinery complete!");