|
@@ -94,12 +94,12 @@ impl Hosts {
|
|
|
/// our own inbound address, then checks whether it is already connected
|
|
/// our own inbound address, then checks whether it is already connected
|
|
|
/// (exists) or connecting (pending).
|
|
/// (exists) or connecting (pending).
|
|
|
/// Lastly adds matching address to the pending list.
|
|
/// Lastly adds matching address to the pending list.
|
|
|
- pub async fn greylist_fetch_address_with_lock(
|
|
|
|
|
|
|
+ pub async fn greylist_fetch_address(
|
|
|
&self,
|
|
&self,
|
|
|
p2p: P2pPtr,
|
|
p2p: P2pPtr,
|
|
|
transports: &[String],
|
|
transports: &[String],
|
|
|
- ) -> Option<(Url, u64)> {
|
|
|
|
|
- debug!(target: "store", "greylist_fetch_address_with_lock() [START]");
|
|
|
|
|
|
|
+ ) -> Option<Vec<(Url, u64)>> {
|
|
|
|
|
+ trace!(target: "store", "greylist_fetch_address() [START]");
|
|
|
// Collect hosts
|
|
// Collect hosts
|
|
|
let mut hosts = vec![];
|
|
let mut hosts = vec![];
|
|
|
|
|
|
|
@@ -133,47 +133,48 @@ impl Hosts {
|
|
|
// This is healthier for multiple slots to not compete for the same addrs.
|
|
// This is healthier for multiple slots to not compete for the same addrs.
|
|
|
hosts.shuffle(&mut OsRng);
|
|
hosts.shuffle(&mut OsRng);
|
|
|
|
|
|
|
|
- // Try to find an unused host in the set.
|
|
|
|
|
- for (host, last_seen) in hosts.iter() {
|
|
|
|
|
- // Check if we already have this connection established
|
|
|
|
|
- if p2p.exists(host).await {
|
|
|
|
|
- trace!(
|
|
|
|
|
- target: "net::hosts::greylist_fetch_address_with_lock()",
|
|
|
|
|
- "Host '{}' exists so skipping",
|
|
|
|
|
- host
|
|
|
|
|
- );
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Check if we already have this configured as a manual peer
|
|
|
|
|
- if self.settings.peers.contains(host) {
|
|
|
|
|
- trace!(
|
|
|
|
|
- target: "net::hosts::greylist_fetch_address_with_lock()",
|
|
|
|
|
- "Host '{}' configured as manual peer so skipping",
|
|
|
|
|
- host
|
|
|
|
|
- );
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Obtain a lock on this address to prevent duplicate connection
|
|
|
|
|
- if !p2p.add_pending(host).await {
|
|
|
|
|
- trace!(
|
|
|
|
|
- target: "net::hosts::greylist_fetch_address_with_lock()",
|
|
|
|
|
- "Host '{}' pending so skipping",
|
|
|
|
|
- host
|
|
|
|
|
- );
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- trace!(
|
|
|
|
|
- target: "net::hosts::greylist_fetch_address_with_lock()",
|
|
|
|
|
- "Found valid host '{}",
|
|
|
|
|
- host
|
|
|
|
|
- );
|
|
|
|
|
- return Some((host.clone(), last_seen.clone()))
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- None
|
|
|
|
|
|
|
+ Some(hosts)
|
|
|
|
|
+ //// Try to find an unused host in the set.
|
|
|
|
|
+ //for (host, last_seen) in hosts.iter() {
|
|
|
|
|
+ // // Check if we already have this connection established
|
|
|
|
|
+ // if p2p.exists(host).await {
|
|
|
|
|
+ // debug!(
|
|
|
|
|
+ // target: "store::greylist_fetch_address()",
|
|
|
|
|
+ // "Host '{}' exists so skipping",
|
|
|
|
|
+ // host
|
|
|
|
|
+ // );
|
|
|
|
|
+ // continue
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // // Check if we already have this configured as a manual peer
|
|
|
|
|
+ // if self.settings.peers.contains(host) {
|
|
|
|
|
+ // debug!(
|
|
|
|
|
+ // target: "store::greylist_fetch_address()",
|
|
|
|
|
+ // "Host '{}' configured as manual peer so skipping",
|
|
|
|
|
+ // host
|
|
|
|
|
+ // );
|
|
|
|
|
+ // continue
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // // Obtain a lock on this address to prevent duplicate connection
|
|
|
|
|
+ // if !p2p.add_pending(host).await {
|
|
|
|
|
+ // debug!(
|
|
|
|
|
+ // target: "store::greylist_fetch_address()",
|
|
|
|
|
+ // "Host '{}' pending so skipping",
|
|
|
|
|
+ // host
|
|
|
|
|
+ // );
|
|
|
|
|
+ // continue
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // debug!(
|
|
|
|
|
+ // target: "store::greylist_fetch_address()",
|
|
|
|
|
+ // "Found valid host '{}",
|
|
|
|
|
+ // host
|
|
|
|
|
+ // );
|
|
|
|
|
+ // return Some((host.clone(), last_seen.clone()))
|
|
|
|
|
+ //}
|
|
|
|
|
+
|
|
|
|
|
+ //None
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Loops through whitelist addresses to find an outbound address that we can
|
|
/// Loops through whitelist addresses to find an outbound address that we can
|
|
@@ -181,12 +182,12 @@ impl Hosts {
|
|
|
/// our own inbound address, then checks whether it is already connected
|
|
/// our own inbound address, then checks whether it is already connected
|
|
|
/// (exists) or connecting (pending).
|
|
/// (exists) or connecting (pending).
|
|
|
/// Lastly adds matching address to the pending list.
|
|
/// Lastly adds matching address to the pending list.
|
|
|
- pub async fn whitelist_fetch_address_with_lock(
|
|
|
|
|
|
|
+ pub async fn whitelist_fetch_address(
|
|
|
&self,
|
|
&self,
|
|
|
p2p: P2pPtr,
|
|
p2p: P2pPtr,
|
|
|
transports: &[String],
|
|
transports: &[String],
|
|
|
- ) -> Option<(Url, u64)> {
|
|
|
|
|
- debug!(target: "store", "whitelist_fetch_address_with_lock() [START]");
|
|
|
|
|
|
|
+ ) -> Option<Vec<(Url, u64)>> {
|
|
|
|
|
+ trace!(target: "store", "whitelist_fetch_address() [START]");
|
|
|
// Collect hosts
|
|
// Collect hosts
|
|
|
let mut hosts = vec![];
|
|
let mut hosts = vec![];
|
|
|
|
|
|
|
@@ -216,51 +217,68 @@ impl Hosts {
|
|
|
hosts.push((addr, last_seen));
|
|
hosts.push((addr, last_seen));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ debug!(target: "store::whitelist_fetch_address()",
|
|
|
|
|
+ "Grabbed hosts, length: {}", hosts.len());
|
|
|
|
|
+
|
|
|
// Randomize hosts list. Do not try to connect in a deterministic order.
|
|
// Randomize hosts list. Do not try to connect in a deterministic order.
|
|
|
// This is healthier for multiple slots to not compete for the same addrs.
|
|
// This is healthier for multiple slots to not compete for the same addrs.
|
|
|
hosts.shuffle(&mut OsRng);
|
|
hosts.shuffle(&mut OsRng);
|
|
|
|
|
|
|
|
- // Try to find an unused host in the set.
|
|
|
|
|
- for (host, last_seen) in hosts.iter() {
|
|
|
|
|
- // Check if we already have this connection established
|
|
|
|
|
- if p2p.exists(host).await {
|
|
|
|
|
- trace!(
|
|
|
|
|
- target: "net::hosts::whitelist_fetch_address_with_lock()",
|
|
|
|
|
- "Host '{}' exists so skipping",
|
|
|
|
|
- host
|
|
|
|
|
- );
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Check if we already have this configured as a manual peer
|
|
|
|
|
- if self.settings.peers.contains(host) {
|
|
|
|
|
- trace!(
|
|
|
|
|
- target: "net::hosts::whitelist_fetch_address_with_lock()",
|
|
|
|
|
- "Host '{}' configured as manual peer so skipping",
|
|
|
|
|
- host
|
|
|
|
|
- );
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Obtain a lock on this address to prevent duplicate connection
|
|
|
|
|
- if !p2p.add_pending(host).await {
|
|
|
|
|
- trace!(
|
|
|
|
|
- target: "net::hosts::whitelist_fetch_address_with_lock()",
|
|
|
|
|
- "Host '{}' pending so skipping",
|
|
|
|
|
- host
|
|
|
|
|
- );
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- trace!(
|
|
|
|
|
- target: "net::hosts::whitelist_fetch_address_with_lock()",
|
|
|
|
|
- "Found valid host '{}",
|
|
|
|
|
- host
|
|
|
|
|
- );
|
|
|
|
|
- return Some((host.clone(), last_seen.clone()))
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- None
|
|
|
|
|
|
|
+ Some(hosts)
|
|
|
|
|
+ //// Try to find an unused host in the set.
|
|
|
|
|
+ //for (host, last_seen) in hosts.iter() {
|
|
|
|
|
+ // debug!(target: "store::whitelist_fetch_address()",
|
|
|
|
|
+ // "Starting checks");
|
|
|
|
|
+ // // Check if we already have this connection established
|
|
|
|
|
+ // if p2p.exists(host).await {
|
|
|
|
|
+ // debug!(
|
|
|
|
|
+ // target: "store::whitelist_fetch_address()",
|
|
|
|
|
+ // "Host '{}' exists so skipping",
|
|
|
|
|
+ // host
|
|
|
|
|
+ // );
|
|
|
|
|
+ // continue
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // debug!(target: "store::whitelist_fetch_address()",
|
|
|
|
|
+ // "Connection is not already established");
|
|
|
|
|
+
|
|
|
|
|
+ // // Check if we already have this configured as a manual peer
|
|
|
|
|
+ // if self.settings.peers.contains(host) {
|
|
|
|
|
+ // debug!(
|
|
|
|
|
+ // target: "store::whitelist_fetch_address()",
|
|
|
|
|
+ // "Host '{}' configured as manual peer so skipping",
|
|
|
|
|
+ // host
|
|
|
|
|
+ // );
|
|
|
|
|
+ // continue
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // debug!(target: "store::whitelist_fetch_address()",
|
|
|
|
|
+ // "Connection not configured as manual peer");
|
|
|
|
|
+
|
|
|
|
|
+ // // Obtain a lock on this address to prevent duplicate connection
|
|
|
|
|
+ // if !p2p.add_pending(host).await {
|
|
|
|
|
+ // debug!(
|
|
|
|
|
+ // target: "store::whitelist_fetch_address()",
|
|
|
|
|
+ // "Host '{}' pending so skipping",
|
|
|
|
|
+ // host
|
|
|
|
|
+ // );
|
|
|
|
|
+ // continue
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // debug!(target: "store::whitelist_fetch_address()",
|
|
|
|
|
+ // "Connection not pending");
|
|
|
|
|
+
|
|
|
|
|
+ // debug!(
|
|
|
|
|
+ // target: "store::whitelist_fetch_address()",
|
|
|
|
|
+ // "Found valid host '{}",
|
|
|
|
|
+ // host
|
|
|
|
|
+ // );
|
|
|
|
|
+ // return Some((host.clone(), last_seen.clone()))
|
|
|
|
|
+ //}
|
|
|
|
|
+
|
|
|
|
|
+ //debug!(target: "store::whitelist_fetch_address()",
|
|
|
|
|
+ //"Exiting with NONE");
|
|
|
|
|
+ //None
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Loops through anchorlist addresses to find an outbound address that we can
|
|
/// Loops through anchorlist addresses to find an outbound address that we can
|
|
@@ -268,12 +286,12 @@ impl Hosts {
|
|
|
/// our own inbound address, then checks whether it is already connected
|
|
/// our own inbound address, then checks whether it is already connected
|
|
|
/// (exists) or connecting (pending).
|
|
/// (exists) or connecting (pending).
|
|
|
/// Lastly adds matching address to the pending list.
|
|
/// Lastly adds matching address to the pending list.
|
|
|
- pub async fn anchorlist_fetch_address_with_lock(
|
|
|
|
|
|
|
+ pub async fn anchorlist_fetch_address(
|
|
|
&self,
|
|
&self,
|
|
|
p2p: P2pPtr,
|
|
p2p: P2pPtr,
|
|
|
transports: &[String],
|
|
transports: &[String],
|
|
|
- ) -> Option<(Url, u64)> {
|
|
|
|
|
- debug!(target: "store", "anchorlist_fetch_address_with_lock() [START]");
|
|
|
|
|
|
|
+ ) -> Option<Vec<(Url, u64)>> {
|
|
|
|
|
+ trace!(target: "store", "anchorlist_fetch_address() [START]");
|
|
|
// Collect hosts
|
|
// Collect hosts
|
|
|
let mut hosts = vec![];
|
|
let mut hosts = vec![];
|
|
|
|
|
|
|
@@ -303,57 +321,131 @@ impl Hosts {
|
|
|
hosts.push((addr, last_seen));
|
|
hosts.push((addr, last_seen));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ debug!(target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ "Grabbed hosts, length: {}", hosts.len());
|
|
|
|
|
+
|
|
|
// Randomize hosts list. Do not try to connect in a deterministic order.
|
|
// Randomize hosts list. Do not try to connect in a deterministic order.
|
|
|
// This is healthier for multiple slots to not compete for the same addrs.
|
|
// This is healthier for multiple slots to not compete for the same addrs.
|
|
|
hosts.shuffle(&mut OsRng);
|
|
hosts.shuffle(&mut OsRng);
|
|
|
|
|
|
|
|
|
|
+ Some(hosts)
|
|
|
|
|
+ //// Try to find an unused host in the set.
|
|
|
|
|
+ //for (host, last_seen) in hosts.iter() {
|
|
|
|
|
+ // debug!(target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ // "Starting checks");
|
|
|
|
|
+ // // Check if we already have this connection established
|
|
|
|
|
+ // if p2p.exists(host).await {
|
|
|
|
|
+ // debug!(
|
|
|
|
|
+ // target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ // "Host '{}' exists so skipping",
|
|
|
|
|
+ // host
|
|
|
|
|
+ // );
|
|
|
|
|
+ // continue
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // debug!(target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ // "Connection is not already established");
|
|
|
|
|
+
|
|
|
|
|
+ // // Check if we already have this configured as a manual peer
|
|
|
|
|
+ // if self.settings.peers.contains(host) {
|
|
|
|
|
+ // debug!(
|
|
|
|
|
+ // target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ // "Host '{}' configured as manual peer so skipping",
|
|
|
|
|
+ // host
|
|
|
|
|
+ // );
|
|
|
|
|
+ // continue
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // debug!(target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ // "Connection not configured as manual peer");
|
|
|
|
|
+
|
|
|
|
|
+ // // Obtain a lock on this address to prevent duplicate connection
|
|
|
|
|
+ // if !p2p.add_pending(host).await {
|
|
|
|
|
+ // debug!(
|
|
|
|
|
+ // target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ // "Host '{}' pending so skipping",
|
|
|
|
|
+ // host
|
|
|
|
|
+ // );
|
|
|
|
|
+ // continue
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // debug!(target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ // "Connection not pending");
|
|
|
|
|
+
|
|
|
|
|
+ // debug!(
|
|
|
|
|
+ // target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ // "Found valid host '{}",
|
|
|
|
|
+ // host
|
|
|
|
|
+ // );
|
|
|
|
|
+ // return Some((host.clone(), last_seen.clone()))
|
|
|
|
|
+ //}
|
|
|
|
|
+
|
|
|
|
|
+ //debug!(target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ //"Exiting with NONE");
|
|
|
|
|
+ //None
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ pub async fn lock_check(&self, p2p: P2pPtr, hosts: Vec<(Url, u64)>) -> Option<(Url, u64)> {
|
|
|
// Try to find an unused host in the set.
|
|
// Try to find an unused host in the set.
|
|
|
- for (host, last_seen) in hosts.iter() {
|
|
|
|
|
|
|
+ for (host, last_seen) in hosts {
|
|
|
|
|
+ debug!(target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ "Starting checks");
|
|
|
// Check if we already have this connection established
|
|
// Check if we already have this connection established
|
|
|
- if p2p.exists(host).await {
|
|
|
|
|
- trace!(
|
|
|
|
|
- target: "net::hosts::anchorlist_fetch_address_with_lock()",
|
|
|
|
|
|
|
+ if p2p.exists(&host).await {
|
|
|
|
|
+ debug!(
|
|
|
|
|
+ target: "store::anchorlist_fetch_address()",
|
|
|
"Host '{}' exists so skipping",
|
|
"Host '{}' exists so skipping",
|
|
|
host
|
|
host
|
|
|
);
|
|
);
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ debug!(target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ "Connection is not already established");
|
|
|
|
|
+
|
|
|
// Check if we already have this configured as a manual peer
|
|
// Check if we already have this configured as a manual peer
|
|
|
- if self.settings.peers.contains(host) {
|
|
|
|
|
- trace!(
|
|
|
|
|
- target: "net::hosts::anchorlist_fetch_address_with_lock()",
|
|
|
|
|
|
|
+ if self.settings.peers.contains(&host) {
|
|
|
|
|
+ debug!(
|
|
|
|
|
+ target: "store::anchorlist_fetch_address()",
|
|
|
"Host '{}' configured as manual peer so skipping",
|
|
"Host '{}' configured as manual peer so skipping",
|
|
|
host
|
|
host
|
|
|
);
|
|
);
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ debug!(target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ "Connection not configured as manual peer");
|
|
|
|
|
+
|
|
|
// Obtain a lock on this address to prevent duplicate connection
|
|
// Obtain a lock on this address to prevent duplicate connection
|
|
|
- if !p2p.add_pending(host).await {
|
|
|
|
|
- trace!(
|
|
|
|
|
- target: "net::hosts::anchorlist_fetch_address_with_lock()",
|
|
|
|
|
|
|
+ if !p2p.add_pending(&host).await {
|
|
|
|
|
+ debug!(
|
|
|
|
|
+ target: "store::anchorlist_fetch_address()",
|
|
|
"Host '{}' pending so skipping",
|
|
"Host '{}' pending so skipping",
|
|
|
host
|
|
host
|
|
|
);
|
|
);
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- trace!(
|
|
|
|
|
- target: "net::hosts::anchorlist_fetch_address_with_lock()",
|
|
|
|
|
|
|
+ debug!(target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ "Connection not pending");
|
|
|
|
|
+
|
|
|
|
|
+ debug!(
|
|
|
|
|
+ target: "store::anchorlist_fetch_address()",
|
|
|
"Found valid host '{}",
|
|
"Found valid host '{}",
|
|
|
host
|
|
host
|
|
|
);
|
|
);
|
|
|
return Some((host.clone(), last_seen.clone()))
|
|
return Some((host.clone(), last_seen.clone()))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ debug!(target: "store::anchorlist_fetch_address()",
|
|
|
|
|
+ "Exiting with NONE");
|
|
|
None
|
|
None
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /// Stores an address on the greylist or updates its last_seen field if we already
|
|
|
|
|
|
|
+ /// Stores an address on the greylist or updates its last_seen field if we already
|
|
|
/// have the address.
|
|
/// have the address.
|
|
|
pub async fn greylist_store_or_update(&self, addrs: &[(Url, u64)]) -> Result<()> {
|
|
pub async fn greylist_store_or_update(&self, addrs: &[(Url, u64)]) -> Result<()> {
|
|
|
- debug!(target: "store::greylist_store_or_update()", "[START]");
|
|
|
|
|
|
|
+ trace!(target: "store::greylist_store_or_update()", "[START]");
|
|
|
|
|
|
|
|
// Filter addresses before writing to the greylist.
|
|
// Filter addresses before writing to the greylist.
|
|
|
let filtered_addrs = self.filter_addresses(addrs).await;
|
|
let filtered_addrs = self.filter_addresses(addrs).await;
|
|
@@ -375,20 +467,20 @@ impl Hosts {
|
|
|
Ok(())
|
|
Ok(())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /// Stores an address on the whitelist or updates its last_seen field if we already
|
|
|
|
|
|
|
+ /// Stores an address on the whitelist or updates its last_seen field if we already
|
|
|
/// have the address.
|
|
/// have the address.
|
|
|
pub async fn whitelist_store_or_update(&self, addrs: &[(Url, u64)]) -> Result<()> {
|
|
pub async fn whitelist_store_or_update(&self, addrs: &[(Url, u64)]) -> Result<()> {
|
|
|
- debug!(target: "net::hosts::whitelist_store_or_update()", "[START]");
|
|
|
|
|
|
|
+ trace!(target: "store::whitelist_store_or_update()", "[START]");
|
|
|
|
|
|
|
|
// No address filtering for whitelist (whitelist is created from greylist)
|
|
// No address filtering for whitelist (whitelist is created from greylist)
|
|
|
for (addr, last_seen) in addrs {
|
|
for (addr, last_seen) in addrs {
|
|
|
if !self.whitelist_contains(addr).await {
|
|
if !self.whitelist_contains(addr).await {
|
|
|
- debug!(target: "net::hosts::whitelist_store_or_update()",
|
|
|
|
|
|
|
+ debug!(target: "store::whitelist_store_or_update()",
|
|
|
"We do not have this entry in the whitelist. Adding to store...");
|
|
"We do not have this entry in the whitelist. Adding to store...");
|
|
|
|
|
|
|
|
self.whitelist_store(addr.clone(), last_seen.clone()).await;
|
|
self.whitelist_store(addr.clone(), last_seen.clone()).await;
|
|
|
} else {
|
|
} else {
|
|
|
- debug!(target: "net::hosts::whitelist_store_or_update()",
|
|
|
|
|
|
|
+ debug!(target: "store::whitelist_store_or_update()",
|
|
|
"We have this entry in the whitelist. Updating last seen...");
|
|
"We have this entry in the whitelist. Updating last seen...");
|
|
|
|
|
|
|
|
let index = self.get_whitelist_index_at_addr(addr).await?;
|
|
let index = self.get_whitelist_index_at_addr(addr).await?;
|
|
@@ -398,20 +490,20 @@ impl Hosts {
|
|
|
Ok(())
|
|
Ok(())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /// Stores an address on the anchorlist or updates its last_seen field if we already
|
|
|
|
|
|
|
+ /// Stores an address on the anchorlist or updates its last_seen field if we already
|
|
|
/// have the address.
|
|
/// have the address.
|
|
|
pub async fn anchorlist_store_or_update(&self, addrs: &[(Url, u64)]) -> Result<()> {
|
|
pub async fn anchorlist_store_or_update(&self, addrs: &[(Url, u64)]) -> Result<()> {
|
|
|
- debug!(target: "store::anchor_store_or_update()", "[START]");
|
|
|
|
|
|
|
+ trace!(target: "store::anchor_store_or_update()", "[START]");
|
|
|
|
|
|
|
|
// No address filtering for anchorlist (contains addresses we have already connected to)
|
|
// No address filtering for anchorlist (contains addresses we have already connected to)
|
|
|
for (addr, last_seen) in addrs {
|
|
for (addr, last_seen) in addrs {
|
|
|
if !self.anchorlist_contains(addr).await {
|
|
if !self.anchorlist_contains(addr).await {
|
|
|
- debug!(target: "net::hosts::anchorlist_store_or_update()",
|
|
|
|
|
|
|
+ debug!(target: "store::anchorlist_store_or_update()",
|
|
|
"We do not have this entry in the whitelist. Adding to store...");
|
|
"We do not have this entry in the whitelist. Adding to store...");
|
|
|
|
|
|
|
|
self.anchorlist_store(addr.clone(), last_seen.clone()).await;
|
|
self.anchorlist_store(addr.clone(), last_seen.clone()).await;
|
|
|
} else {
|
|
} else {
|
|
|
- debug!(target: "net::hosts::anchorlist_store_or_update()",
|
|
|
|
|
|
|
+ debug!(target: "store::anchorlist_store_or_update()",
|
|
|
"We have this entry in the anchorlist. Updating last seen...");
|
|
"We have this entry in the anchorlist. Updating last seen...");
|
|
|
|
|
|
|
|
let (index, entry) = self.get_anchorlist_entry_at_addr(addr).await?;
|
|
let (index, entry) = self.get_anchorlist_entry_at_addr(addr).await?;
|
|
@@ -423,27 +515,27 @@ impl Hosts {
|
|
|
|
|
|
|
|
/// Append host to the greylist. Called on learning of a new peer.
|
|
/// Append host to the greylist. Called on learning of a new peer.
|
|
|
pub async fn greylist_store(&self, addr: Url, last_seen: u64) {
|
|
pub async fn greylist_store(&self, addr: Url, last_seen: u64) {
|
|
|
- debug!(target: "net::hosts::greylist_store()", "hosts::greylist_store() [START]");
|
|
|
|
|
|
|
+ trace!(target: "store::greylist_store()", "hosts::greylist_store() [START]");
|
|
|
|
|
|
|
|
let mut greylist = self.greylist.write().await;
|
|
let mut greylist = self.greylist.write().await;
|
|
|
|
|
|
|
|
// Remove oldest element if the greylist reaches max size.
|
|
// Remove oldest element if the greylist reaches max size.
|
|
|
if greylist.len() == GREYLIST_MAX_LEN {
|
|
if greylist.len() == GREYLIST_MAX_LEN {
|
|
|
let last_entry = greylist.pop().unwrap();
|
|
let last_entry = greylist.pop().unwrap();
|
|
|
- debug!(target: "net::hosts::greylist_store()", "Greylist reached max size. Removed {:?}", last_entry);
|
|
|
|
|
|
|
+ debug!(target: "store::greylist_store()", "Greylist reached max size. Removed {:?}", last_entry);
|
|
|
} else {
|
|
} else {
|
|
|
- debug!(target: "net::hosts::greylist_store()", "Inserting {}", addr);
|
|
|
|
|
|
|
+ debug!(target: "store::greylist_store()", "Inserting {}", addr);
|
|
|
greylist.push((addr, last_seen));
|
|
greylist.push((addr, last_seen));
|
|
|
|
|
|
|
|
// Sort the list by last_seen.
|
|
// Sort the list by last_seen.
|
|
|
greylist.sort_by_key(|entry| entry.1);
|
|
greylist.sort_by_key(|entry| entry.1);
|
|
|
}
|
|
}
|
|
|
- debug!(target: "net::hosts::greylist_store()", "[END]");
|
|
|
|
|
|
|
+ trace!(target: "store::greylist_store()", "[END]");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Append host to the whitelist. Called after a successful interaction with an online peer.
|
|
/// Append host to the whitelist. Called after a successful interaction with an online peer.
|
|
|
pub async fn whitelist_store(&self, addr: Url, last_seen: u64) {
|
|
pub async fn whitelist_store(&self, addr: Url, last_seen: u64) {
|
|
|
- debug!(target: "net::hosts::whitelist_store()", "[START]");
|
|
|
|
|
|
|
+ trace!(target: "store::whitelist_store()", "[START]");
|
|
|
|
|
|
|
|
let mut whitelist = self.whitelist.write().await;
|
|
let mut whitelist = self.whitelist.write().await;
|
|
|
|
|
|
|
@@ -458,27 +550,27 @@ impl Hosts {
|
|
|
// Sort the list by last_seen.
|
|
// Sort the list by last_seen.
|
|
|
whitelist.sort_by_key(|entry| entry.1);
|
|
whitelist.sort_by_key(|entry| entry.1);
|
|
|
}
|
|
}
|
|
|
- debug!(target: "store::whitelist_store()", "[END]");
|
|
|
|
|
|
|
+ trace!(target: "store::whitelist_store()", "[END]");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Append host to the anchorlist. Called after we have successfully established a connection
|
|
/// Append host to the anchorlist. Called after we have successfully established a connection
|
|
|
/// to a peer.
|
|
/// to a peer.
|
|
|
pub async fn anchorlist_store(&self, addr: Url, last_seen: u64) {
|
|
pub async fn anchorlist_store(&self, addr: Url, last_seen: u64) {
|
|
|
- debug!(target: "net::hosts::anchorlist_store()", "[START]");
|
|
|
|
|
|
|
+ trace!(target: "store::anchorlist_store()", "[START]");
|
|
|
|
|
|
|
|
let mut anchorlist = self.anchorlist.write().await;
|
|
let mut anchorlist = self.anchorlist.write().await;
|
|
|
|
|
|
|
|
- debug!(target: "net::hosts::anchorlist_store()", "Inserting {}", addr);
|
|
|
|
|
|
|
+ debug!(target: "store::anchorlist_store()", "Inserting {}", addr);
|
|
|
anchorlist.push((addr, last_seen));
|
|
anchorlist.push((addr, last_seen));
|
|
|
|
|
|
|
|
// Sort the list by last_seen.
|
|
// Sort the list by last_seen.
|
|
|
anchorlist.sort_by_key(|entry| entry.1);
|
|
anchorlist.sort_by_key(|entry| entry.1);
|
|
|
- debug!(target: "net::hosts::anchorlist_store()", "[END]");
|
|
|
|
|
|
|
+ trace!(target: "store::anchorlist_store()", "[END]");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Downgrade a non-responsive host.
|
|
// Downgrade a non-responsive host.
|
|
|
- // TODO: it is perhaps more efficient simply to select another connection and allow
|
|
|
|
|
- // the greylist refinery process to filter address.
|
|
|
|
|
|
|
+ // TODO: it is perhaps more efficient simply to select another connection and allow
|
|
|
|
|
+ // the greylist refinery process to filter address.
|
|
|
pub async fn downgrade_host(&self, addr: &Url) -> Result<()> {
|
|
pub async fn downgrade_host(&self, addr: &Url) -> Result<()> {
|
|
|
if self.anchorlist_contains(addr).await {
|
|
if self.anchorlist_contains(addr).await {
|
|
|
debug!(target: "net::store::downgrade_host()",
|
|
debug!(target: "net::store::downgrade_host()",
|
|
@@ -508,7 +600,7 @@ impl Hosts {
|
|
|
|
|
|
|
|
/// Update the last_seen field of a peer on the greylist.
|
|
/// 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) {
|
|
pub async fn greylist_update_last_seen(&self, addr: &Url, last_seen: u64, index: usize) {
|
|
|
- debug!(target: "net::hosts::greylist_update_last_seen()", "[START]");
|
|
|
|
|
|
|
+ trace!(target: "store::greylist_update_last_seen()", "[START]");
|
|
|
|
|
|
|
|
let mut greylist = self.greylist.write().await;
|
|
let mut greylist = self.greylist.write().await;
|
|
|
|
|
|
|
@@ -517,12 +609,12 @@ impl Hosts {
|
|
|
// Sort the list by last_seen.
|
|
// Sort the list by last_seen.
|
|
|
greylist.sort_by_key(|entry| entry.1);
|
|
greylist.sort_by_key(|entry| entry.1);
|
|
|
|
|
|
|
|
- debug!(target: "store::greylist_update_last_seen()", "[END]");
|
|
|
|
|
|
|
+ trace!(target: "store::greylist_update_last_seen()", "[END]");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Update the last_seen field of a peer on the whitelist.
|
|
/// 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) {
|
|
pub async fn whitelist_update_last_seen(&self, addr: &Url, last_seen: u64, index: usize) {
|
|
|
- debug!(target: "store::whitelist_update_last_seen()", "[START]");
|
|
|
|
|
|
|
+ trace!(target: "store::whitelist_update_last_seen()", "[START]");
|
|
|
|
|
|
|
|
let mut whitelist = self.whitelist.write().await;
|
|
let mut whitelist = self.whitelist.write().await;
|
|
|
|
|
|
|
@@ -531,12 +623,12 @@ impl Hosts {
|
|
|
// Sort the list by last_seen.
|
|
// Sort the list by last_seen.
|
|
|
whitelist.sort_by_key(|entry| entry.1);
|
|
whitelist.sort_by_key(|entry| entry.1);
|
|
|
|
|
|
|
|
- debug!(target: "store::whitelist_update_last_seen()", "[END]");
|
|
|
|
|
|
|
+ trace!(target: "store::whitelist_update_last_seen()", "[END]");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Update the last_seen field of a peer on the anchorlist.
|
|
/// Update the last_seen field of a peer on the anchorlist.
|
|
|
pub async fn anchorlist_update_last_seen(&self, addr: &Url, last_seen: u64, index: usize) {
|
|
pub async fn anchorlist_update_last_seen(&self, addr: &Url, last_seen: u64, index: usize) {
|
|
|
- debug!(target: "store::anchorlist_update_last_seen()", "[START]");
|
|
|
|
|
|
|
+ trace!(target: "store::anchorlist_update_last_seen()", "[START]");
|
|
|
|
|
|
|
|
let mut anchorlist = self.anchorlist.write().await;
|
|
let mut anchorlist = self.anchorlist.write().await;
|
|
|
|
|
|
|
@@ -545,7 +637,7 @@ impl Hosts {
|
|
|
// Sort the list by last_seen.
|
|
// Sort the list by last_seen.
|
|
|
anchorlist.sort_by_key(|entry| entry.1);
|
|
anchorlist.sort_by_key(|entry| entry.1);
|
|
|
|
|
|
|
|
- debug!(target: "store::anchorlist_update_last_seen()", "[END]");
|
|
|
|
|
|
|
+ trace!(target: "store::anchorlist_update_last_seen()", "[END]");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Remove an entry from the greylist.
|
|
/// Remove an entry from the greylist.
|
|
@@ -624,7 +716,7 @@ impl Hosts {
|
|
|
|
|
|
|
|
/// Filter given addresses based on certain rulesets and validity.
|
|
/// Filter given addresses based on certain rulesets and validity.
|
|
|
async fn filter_addresses(&self, addrs: &[(Url, u64)]) -> Vec<(Url, u64)> {
|
|
async fn filter_addresses(&self, addrs: &[(Url, u64)]) -> Vec<(Url, u64)> {
|
|
|
- debug!(target: "net::hosts::filter_addresses()", "Filtering addrs: {:?}", addrs);
|
|
|
|
|
|
|
+ trace!(target: "store::filter_addresses()", "Filtering addrs: {:?}", addrs);
|
|
|
let mut ret = vec![];
|
|
let mut ret = vec![];
|
|
|
let localnet = self.settings.localnet;
|
|
let localnet = self.settings.localnet;
|
|
|
|
|
|
|
@@ -639,7 +731,7 @@ impl Hosts {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if self.is_rejected(addr_).await {
|
|
if self.is_rejected(addr_).await {
|
|
|
- debug!(target: "net::hosts::filter_addresses()", "Peer {} is rejected", addr_);
|
|
|
|
|
|
|
+ debug!(target: "store::filter_addresses()", "Peer {} is rejected", addr_);
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -680,7 +772,7 @@ impl Hosts {
|
|
|
if tor_hscrypto::pk::HsId::from_str(host_str).is_err() {
|
|
if tor_hscrypto::pk::HsId::from_str(host_str).is_err() {
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
- debug!(target: "net::hosts::filter_addresses()", "[Tor] Valid: {}", host_str);
|
|
|
|
|
|
|
+ debug!(target: "store::filter_addresses()", "[Tor] Valid: {}", host_str);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "p2p-nym")]
|
|
#[cfg(feature = "p2p-nym")]
|
|
@@ -688,7 +780,7 @@ impl Hosts {
|
|
|
|
|
|
|
|
#[cfg(feature = "p2p-tcp")]
|
|
#[cfg(feature = "p2p-tcp")]
|
|
|
"tcp" | "tcp+tls" => {
|
|
"tcp" | "tcp+tls" => {
|
|
|
- debug!(target: "net::hosts::filter_addresses()", "[TCP] Valid: {}", host_str);
|
|
|
|
|
|
|
+ debug!(target: "store::filter_addresses()", "[TCP] Valid: {}", host_str);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
_ => continue,
|
|
_ => continue,
|
|
@@ -904,13 +996,13 @@ impl Hosts {
|
|
|
if n == 0 {
|
|
if n == 0 {
|
|
|
return vec![]
|
|
return vec![]
|
|
|
}
|
|
}
|
|
|
- debug!(target: "store::whitelist_fetch_n_random_with_schemes", "[START]");
|
|
|
|
|
|
|
+ trace!(target: "store::whitelist_fetch_n_random_with_schemes", "[START]");
|
|
|
|
|
|
|
|
// Retrieve all peers corresponding to that transport schemes
|
|
// Retrieve all peers corresponding to that transport schemes
|
|
|
let hosts = self.whitelist_fetch_with_schemes(schemes, None).await;
|
|
let hosts = self.whitelist_fetch_with_schemes(schemes, None).await;
|
|
|
if hosts.is_empty() {
|
|
if hosts.is_empty() {
|
|
|
debug!(target: "store::whitelist_fetch_n_random_with_schemes",
|
|
debug!(target: "store::whitelist_fetch_n_random_with_schemes",
|
|
|
- "Whitelist is empty! Exiting...");
|
|
|
|
|
|
|
+ "Whitelist is empty {:?}! Exiting...", hosts);
|
|
|
return hosts
|
|
return hosts
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -918,7 +1010,7 @@ impl Hosts {
|
|
|
let urls = hosts.iter().choose_multiple(&mut OsRng, n.min(hosts.len()));
|
|
let urls = hosts.iter().choose_multiple(&mut OsRng, n.min(hosts.len()));
|
|
|
urls.iter().map(|&url| url.clone()).collect()
|
|
urls.iter().map(|&url| url.clone()).collect()
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/// Get up to limit peers that don't match the given transport schemes from the whitelist.
|
|
/// Get up to limit peers that don't match the given transport schemes from the whitelist.
|
|
|
/// If limit was not provided, return all matching peers.
|
|
/// If limit was not provided, return all matching peers.
|
|
|
pub async fn whitelist_fetch_excluding_schemes(
|
|
pub async fn whitelist_fetch_excluding_schemes(
|
|
@@ -974,14 +1066,14 @@ impl Hosts {
|
|
|
if n == 0 {
|
|
if n == 0 {
|
|
|
return vec![]
|
|
return vec![]
|
|
|
}
|
|
}
|
|
|
- debug!(target: "store::whitelist_fetch_excluding_schemes", "[START]");
|
|
|
|
|
|
|
+ trace!(target: "store::whitelist_fetch_excluding_schemes", "[START]");
|
|
|
|
|
|
|
|
// Retrieve all peers not corresponding to that transport schemes
|
|
// Retrieve all peers not corresponding to that transport schemes
|
|
|
let hosts = self.whitelist_fetch_excluding_schemes(schemes, None).await;
|
|
let hosts = self.whitelist_fetch_excluding_schemes(schemes, None).await;
|
|
|
|
|
|
|
|
if hosts.is_empty() {
|
|
if hosts.is_empty() {
|
|
|
debug!(target: "store::whitelist_fetch_n_random_excluding_schemes",
|
|
debug!(target: "store::whitelist_fetch_n_random_excluding_schemes",
|
|
|
- "Whitelist is empty! Exiting...");
|
|
|
|
|
|
|
+ "No address without schemes found! Exiting...");
|
|
|
return hosts
|
|
return hosts
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1021,7 +1113,7 @@ impl Hosts {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- debug!(target: "store::greylist_fetch_with_schemes", "END");
|
|
|
|
|
|
|
+ trace!(target: "store::greylist_fetch_with_schemes", "END");
|
|
|
|
|
|
|
|
ret
|
|
ret
|
|
|
}
|
|
}
|
|
@@ -1033,7 +1125,7 @@ impl Hosts {
|
|
|
schemes: &[String],
|
|
schemes: &[String],
|
|
|
limit: Option<usize>,
|
|
limit: Option<usize>,
|
|
|
) -> Vec<(Url, u64)> {
|
|
) -> Vec<(Url, u64)> {
|
|
|
- debug!(target: "store::whitelist_fetch_with_schemes", "[START]");
|
|
|
|
|
|
|
+ //debug!(target: "store::whitelist_fetch_with_schemes", "[START]");
|
|
|
let mut ret = vec![];
|
|
let mut ret = vec![];
|
|
|
|
|
|
|
|
if !self.is_empty_whitelist().await {
|
|
if !self.is_empty_whitelist().await {
|
|
@@ -1050,7 +1142,7 @@ impl Hosts {
|
|
|
parsed_limit -= 1;
|
|
parsed_limit -= 1;
|
|
|
if parsed_limit == 0 {
|
|
if parsed_limit == 0 {
|
|
|
debug!(target: "store::whitelist_fetch_with_schemes",
|
|
debug!(target: "store::whitelist_fetch_with_schemes",
|
|
|
- "Found matching white scheme, returning");
|
|
|
|
|
|
|
+ "Found matching white scheme, returning {:?}", ret);
|
|
|
return ret
|
|
return ret
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -1067,7 +1159,7 @@ impl Hosts {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- debug!(target: "store::whitelist_fetch_with_schemes", "END");
|
|
|
|
|
|
|
+ trace!(target: "store::whitelist_fetch_with_schemes", "END");
|
|
|
|
|
|
|
|
ret
|
|
ret
|
|
|
}
|
|
}
|
|
@@ -1079,7 +1171,7 @@ impl Hosts {
|
|
|
schemes: &[String],
|
|
schemes: &[String],
|
|
|
limit: Option<usize>,
|
|
limit: Option<usize>,
|
|
|
) -> Vec<(Url, u64)> {
|
|
) -> Vec<(Url, u64)> {
|
|
|
- debug!(target: "store::anchorlist_fetch_with_schemes", "[START]");
|
|
|
|
|
|
|
+ trace!(target: "store::anchorlist_fetch_with_schemes", "[START]");
|
|
|
let mut ret = vec![];
|
|
let mut ret = vec![];
|
|
|
|
|
|
|
|
if !self.is_empty_anchorlist().await {
|
|
if !self.is_empty_anchorlist().await {
|
|
@@ -1119,7 +1211,7 @@ impl Hosts {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- debug!(target: "store::anchorlist_fetch_with_schemes", "END");
|
|
|
|
|
|
|
+ trace!(target: "store::anchorlist_fetch_with_schemes", "END");
|
|
|
|
|
|
|
|
ret
|
|
ret
|
|
|
}
|
|
}
|
|
@@ -1325,230 +1417,230 @@ mod tests {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- #[test]
|
|
|
|
|
- fn test_fetch_address() {
|
|
|
|
|
- smol::block_on(async {
|
|
|
|
|
- let connect_count = 8;
|
|
|
|
|
- let n_anchor = 10;
|
|
|
|
|
- let n_white = 10;
|
|
|
|
|
- let n_grey = 10;
|
|
|
|
|
-
|
|
|
|
|
- let mut anchor_urls = vec![];
|
|
|
|
|
- let mut white_urls = vec![];
|
|
|
|
|
- let mut grey_urls = vec![];
|
|
|
|
|
- let mut fetched_urls = vec![];
|
|
|
|
|
-
|
|
|
|
|
- let ex = Arc::new(Executor::new());
|
|
|
|
|
-
|
|
|
|
|
- let settings = Settings {
|
|
|
|
|
- outbound_connections: 8,
|
|
|
|
|
- allowed_transports: vec!["tcp".to_string()],
|
|
|
|
|
- ..Default::default()
|
|
|
|
|
- };
|
|
|
|
|
- let p2p = P2p::new(settings, ex.clone()).await;
|
|
|
|
|
- let hosts = p2p.hosts();
|
|
|
|
|
-
|
|
|
|
|
- for i in 0..n_anchor {
|
|
|
|
|
- anchor_urls.push(Url::parse(&format!("tcp://anchorlist{}:123", i)).unwrap());
|
|
|
|
|
- }
|
|
|
|
|
- for i in 0..n_white {
|
|
|
|
|
- white_urls.push(Url::parse(&format!("tcp://whitelist{}:123", i)).unwrap());
|
|
|
|
|
- }
|
|
|
|
|
- for i in 0..n_grey {
|
|
|
|
|
- grey_urls.push(Url::parse(&format!("tcp://greylist{}:123", i)).unwrap());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Build up a hostlist
|
|
|
|
|
- for anchor in &anchor_urls {
|
|
|
|
|
- let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
- hosts.anchorlist_store(anchor.clone(), last_seen).await;
|
|
|
|
|
- }
|
|
|
|
|
- for white in &white_urls {
|
|
|
|
|
- let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
- hosts.whitelist_store(white.clone(), last_seen).await;
|
|
|
|
|
- }
|
|
|
|
|
- for grey in &grey_urls {
|
|
|
|
|
- let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
- hosts.greylist_store(grey.clone(), last_seen).await;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- assert!(!hosts.is_empty_anchorlist().await);
|
|
|
|
|
- assert!(!hosts.is_empty_whitelist().await);
|
|
|
|
|
- assert!(!hosts.is_empty_greylist().await);
|
|
|
|
|
-
|
|
|
|
|
- let transports = &p2p.settings().allowed_transports;
|
|
|
|
|
- let slot_count = p2p.settings().outbound_connections;
|
|
|
|
|
- let white_count = slot_count * p2p.settings().white_connection_percent / 100;
|
|
|
|
|
- let anchor_count = p2p.settings().anchor_connection_count;
|
|
|
|
|
-
|
|
|
|
|
- for i in 0..connect_count {
|
|
|
|
|
- if i < anchor_count {
|
|
|
|
|
- fetched_urls.push(
|
|
|
|
|
- hosts
|
|
|
|
|
- .anchorlist_fetch_address_with_lock(p2p.clone(), transports)
|
|
|
|
|
- .await
|
|
|
|
|
- .unwrap(),
|
|
|
|
|
- );
|
|
|
|
|
- } else if i < white_count {
|
|
|
|
|
- fetched_urls.push(
|
|
|
|
|
- hosts
|
|
|
|
|
- .whitelist_fetch_address_with_lock(p2p.clone(), transports)
|
|
|
|
|
- .await
|
|
|
|
|
- .unwrap(),
|
|
|
|
|
- );
|
|
|
|
|
- } else if i < slot_count {
|
|
|
|
|
- fetched_urls.push(
|
|
|
|
|
- hosts
|
|
|
|
|
- .greylist_fetch_address_with_lock(p2p.clone(), transports)
|
|
|
|
|
- .await
|
|
|
|
|
- .unwrap(),
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- assert!(anchor_urls.iter().any(|u| u.clone() == fetched_urls[0].0));
|
|
|
|
|
- assert!(anchor_urls.iter().any(|u| u.clone() == fetched_urls[1].0));
|
|
|
|
|
- assert!(white_urls.iter().any(|u| u.clone() == fetched_urls[2].0));
|
|
|
|
|
- assert!(white_urls.iter().any(|u| u.clone() == fetched_urls[3].0));
|
|
|
|
|
- assert!(grey_urls.iter().any(|u| u.clone() == fetched_urls[4].0));
|
|
|
|
|
- assert!(grey_urls.iter().any(|u| u.clone() == fetched_urls[5].0));
|
|
|
|
|
- assert!(grey_urls.iter().any(|u| u.clone() == fetched_urls[6].0));
|
|
|
|
|
- assert!(grey_urls.iter().any(|u| u.clone() == fetched_urls[7].0));
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- #[test]
|
|
|
|
|
- fn test_anchorlist_fetch() {
|
|
|
|
|
- smol::block_on(async {
|
|
|
|
|
- let n_anchor = 5;
|
|
|
|
|
- let n_white = 5;
|
|
|
|
|
- let n_grey = 10;
|
|
|
|
|
-
|
|
|
|
|
- let mut anchor_urls = vec![];
|
|
|
|
|
- let mut white_urls = vec![];
|
|
|
|
|
- let mut grey_urls = vec![];
|
|
|
|
|
-
|
|
|
|
|
- let ex = Arc::new(Executor::new());
|
|
|
|
|
- let ex_ = ex.clone();
|
|
|
|
|
-
|
|
|
|
|
- let settings =
|
|
|
|
|
- Settings { allowed_transports: vec!["tcp".to_string()], ..Default::default() };
|
|
|
|
|
-
|
|
|
|
|
- let p2p = P2p::new(settings, ex.clone()).await;
|
|
|
|
|
- let hosts = p2p.hosts();
|
|
|
|
|
-
|
|
|
|
|
- // Retrieve outbound transports
|
|
|
|
|
- let transports = &p2p.settings().allowed_transports;
|
|
|
|
|
-
|
|
|
|
|
- // First test that if we have anchorlist connections in our host list,
|
|
|
|
|
- // those will be selected first.
|
|
|
|
|
- for i in 0..n_anchor {
|
|
|
|
|
- anchor_urls.push(Url::parse(&format!("tcp://anchorlist{}:123", i)).unwrap());
|
|
|
|
|
- }
|
|
|
|
|
- for i in 0..n_white {
|
|
|
|
|
- white_urls.push(Url::parse(&format!("tcp://whitelist{}:123", i)).unwrap());
|
|
|
|
|
- }
|
|
|
|
|
- for i in 0..n_grey {
|
|
|
|
|
- grey_urls.push(Url::parse(&format!("tcp://greylist{}:123", i)).unwrap());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Build up a hostlist
|
|
|
|
|
- for anchor in &anchor_urls {
|
|
|
|
|
- let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
- hosts.anchorlist_store(anchor.clone(), last_seen).await;
|
|
|
|
|
- }
|
|
|
|
|
- for white in &white_urls {
|
|
|
|
|
- let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
- hosts.whitelist_store(white.clone(), last_seen).await;
|
|
|
|
|
- }
|
|
|
|
|
- for grey in &grey_urls {
|
|
|
|
|
- let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
- hosts.greylist_store(grey.clone(), last_seen).await;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- assert!(!hosts.is_empty_anchorlist().await);
|
|
|
|
|
- assert!(!hosts.is_empty_whitelist().await);
|
|
|
|
|
- assert!(!hosts.is_empty_greylist().await);
|
|
|
|
|
-
|
|
|
|
|
- let host =
|
|
|
|
|
- hosts.anchorlist_fetch_address_with_lock(p2p.clone(), &transports).await.unwrap();
|
|
|
|
|
-
|
|
|
|
|
- assert!(anchor_urls.iter().any(|u| u.clone() == host.0));
|
|
|
|
|
-
|
|
|
|
|
- // Now clear the hostlists and test that if we have no anchorlist connections in our host list,
|
|
|
|
|
- // we will select from the whitelist.
|
|
|
|
|
-
|
|
|
|
|
- let mut anchorlist = hosts.anchorlist.write().await;
|
|
|
|
|
- anchorlist.clear();
|
|
|
|
|
- drop(anchorlist);
|
|
|
|
|
-
|
|
|
|
|
- let mut whitelist = hosts.whitelist.write().await;
|
|
|
|
|
- whitelist.clear();
|
|
|
|
|
- drop(whitelist);
|
|
|
|
|
-
|
|
|
|
|
- let mut greylist = hosts.greylist.write().await;
|
|
|
|
|
- greylist.clear();
|
|
|
|
|
- drop(greylist);
|
|
|
|
|
-
|
|
|
|
|
- assert!(hosts.is_empty_anchorlist().await);
|
|
|
|
|
- assert!(hosts.is_empty_whitelist().await);
|
|
|
|
|
- assert!(hosts.is_empty_greylist().await);
|
|
|
|
|
-
|
|
|
|
|
- for i in 0..n_white {
|
|
|
|
|
- white_urls.push(Url::parse(&format!("tcp://whitelist{}:123", i)).unwrap());
|
|
|
|
|
- }
|
|
|
|
|
- for i in 0..n_grey {
|
|
|
|
|
- grey_urls.push(Url::parse(&format!("tcp://greylist{}:123", i)).unwrap());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- for white in &white_urls {
|
|
|
|
|
- let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
- hosts.whitelist_store(white.clone(), last_seen).await;
|
|
|
|
|
- }
|
|
|
|
|
- for grey in &grey_urls {
|
|
|
|
|
- let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
- hosts.greylist_store(grey.clone(), last_seen).await;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- assert!(hosts.is_empty_anchorlist().await);
|
|
|
|
|
- assert!(!hosts.is_empty_whitelist().await);
|
|
|
|
|
- assert!(!hosts.is_empty_greylist().await);
|
|
|
|
|
-
|
|
|
|
|
- let host =
|
|
|
|
|
- hosts.anchorlist_fetch_address_with_lock(p2p.clone(), &transports).await.unwrap();
|
|
|
|
|
-
|
|
|
|
|
- assert!(white_urls.iter().any(|u| u.clone() == host.0));
|
|
|
|
|
-
|
|
|
|
|
- // If we have no whitelist connections, select from the greylist.
|
|
|
|
|
- let mut whitelist = hosts.whitelist.write().await;
|
|
|
|
|
- whitelist.clear();
|
|
|
|
|
- drop(whitelist);
|
|
|
|
|
-
|
|
|
|
|
- let mut greylist = hosts.greylist.write().await;
|
|
|
|
|
- greylist.clear();
|
|
|
|
|
- drop(greylist);
|
|
|
|
|
-
|
|
|
|
|
- assert!(hosts.is_empty_anchorlist().await);
|
|
|
|
|
- assert!(hosts.is_empty_whitelist().await);
|
|
|
|
|
- assert!(hosts.is_empty_greylist().await);
|
|
|
|
|
-
|
|
|
|
|
- for i in 0..n_grey {
|
|
|
|
|
- grey_urls.push(Url::parse(&format!("tcp://greylist{}:123", i)).unwrap());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- for grey in &grey_urls {
|
|
|
|
|
- let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
- hosts.greylist_store(grey.clone(), last_seen).await;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- assert!(hosts.is_empty_anchorlist().await);
|
|
|
|
|
- assert!(hosts.is_empty_whitelist().await);
|
|
|
|
|
- assert!(!hosts.is_empty_greylist().await);
|
|
|
|
|
-
|
|
|
|
|
- let host =
|
|
|
|
|
- hosts.anchorlist_fetch_address_with_lock(p2p.clone(), &transports).await.unwrap();
|
|
|
|
|
-
|
|
|
|
|
- assert!(grey_urls.iter().any(|u| u.clone() == host.0));
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //#[test]
|
|
|
|
|
+ //fn test_fetch_address() {
|
|
|
|
|
+ // smol::block_on(async {
|
|
|
|
|
+ // let connect_count = 8;
|
|
|
|
|
+ // let n_anchor = 10;
|
|
|
|
|
+ // let n_white = 10;
|
|
|
|
|
+ // let n_grey = 10;
|
|
|
|
|
+
|
|
|
|
|
+ // let mut anchor_urls = vec![];
|
|
|
|
|
+ // let mut white_urls = vec![];
|
|
|
|
|
+ // let mut grey_urls = vec![];
|
|
|
|
|
+ // let mut fetched_urls = vec![];
|
|
|
|
|
+
|
|
|
|
|
+ // let ex = Arc::new(Executor::new());
|
|
|
|
|
+
|
|
|
|
|
+ // let settings = Settings {
|
|
|
|
|
+ // outbound_connections: 8,
|
|
|
|
|
+ // allowed_transports: vec!["tcp".to_string()],
|
|
|
|
|
+ // ..Default::default()
|
|
|
|
|
+ // };
|
|
|
|
|
+ // let p2p = P2p::new(settings, ex.clone()).await;
|
|
|
|
|
+ // let hosts = p2p.hosts();
|
|
|
|
|
+
|
|
|
|
|
+ // for i in 0..n_anchor {
|
|
|
|
|
+ // anchor_urls.push(Url::parse(&format!("tcp://anchorlist{}:123", i)).unwrap());
|
|
|
|
|
+ // }
|
|
|
|
|
+ // for i in 0..n_white {
|
|
|
|
|
+ // white_urls.push(Url::parse(&format!("tcp://whitelist{}:123", i)).unwrap());
|
|
|
|
|
+ // }
|
|
|
|
|
+ // for i in 0..n_grey {
|
|
|
|
|
+ // grey_urls.push(Url::parse(&format!("tcp://greylist{}:123", i)).unwrap());
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // // Build up a hostlist
|
|
|
|
|
+ // for anchor in &anchor_urls {
|
|
|
|
|
+ // let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
+ // hosts.anchorlist_store(anchor.clone(), last_seen).await;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // for white in &white_urls {
|
|
|
|
|
+ // let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
+ // hosts.whitelist_store(white.clone(), last_seen).await;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // for grey in &grey_urls {
|
|
|
|
|
+ // let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
+ // hosts.greylist_store(grey.clone(), last_seen).await;
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // assert!(!hosts.is_empty_anchorlist().await);
|
|
|
|
|
+ // assert!(!hosts.is_empty_whitelist().await);
|
|
|
|
|
+ // assert!(!hosts.is_empty_greylist().await);
|
|
|
|
|
+
|
|
|
|
|
+ // let transports = &p2p.settings().allowed_transports;
|
|
|
|
|
+ // let slot_count = p2p.settings().outbound_connections;
|
|
|
|
|
+ // let white_count = slot_count * p2p.settings().white_connection_percent / 100;
|
|
|
|
|
+ // let anchor_count = p2p.settings().anchor_connection_count;
|
|
|
|
|
+
|
|
|
|
|
+ // for i in 0..connect_count {
|
|
|
|
|
+ // if i < anchor_count {
|
|
|
|
|
+ // fetched_urls.push(
|
|
|
|
|
+ // hosts
|
|
|
|
|
+ // .anchorlist_fetch_address(p2p.clone(), transports)
|
|
|
|
|
+ // .await
|
|
|
|
|
+ // .unwrap(),
|
|
|
|
|
+ // );
|
|
|
|
|
+ // } else if i < white_count {
|
|
|
|
|
+ // fetched_urls.push(
|
|
|
|
|
+ // hosts
|
|
|
|
|
+ // .whitelist_fetch_address(p2p.clone(), transports)
|
|
|
|
|
+ // .await
|
|
|
|
|
+ // .unwrap(),
|
|
|
|
|
+ // );
|
|
|
|
|
+ // } else if i < slot_count {
|
|
|
|
|
+ // fetched_urls.push(
|
|
|
|
|
+ // hosts
|
|
|
|
|
+ // .greylist_fetch_address(p2p.clone(), transports)
|
|
|
|
|
+ // .await
|
|
|
|
|
+ // .unwrap(),
|
|
|
|
|
+ // );
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // assert!(anchor_urls.iter().any(|u| u.clone() == fetched_urls[0].0));
|
|
|
|
|
+ // assert!(anchor_urls.iter().any(|u| u.clone() == fetched_urls[1].0));
|
|
|
|
|
+ // assert!(white_urls.iter().any(|u| u.clone() == fetched_urls[2].0));
|
|
|
|
|
+ // assert!(white_urls.iter().any(|u| u.clone() == fetched_urls[3].0));
|
|
|
|
|
+ // assert!(grey_urls.iter().any(|u| u.clone() == fetched_urls[4].0));
|
|
|
|
|
+ // assert!(grey_urls.iter().any(|u| u.clone() == fetched_urls[5].0));
|
|
|
|
|
+ // assert!(grey_urls.iter().any(|u| u.clone() == fetched_urls[6].0));
|
|
|
|
|
+ // assert!(grey_urls.iter().any(|u| u.clone() == fetched_urls[7].0));
|
|
|
|
|
+ // })
|
|
|
|
|
+ //}
|
|
|
|
|
+
|
|
|
|
|
+ //#[test]
|
|
|
|
|
+ //fn test_anchorlist_fetch() {
|
|
|
|
|
+ // smol::block_on(async {
|
|
|
|
|
+ // let n_anchor = 5;
|
|
|
|
|
+ // let n_white = 5;
|
|
|
|
|
+ // let n_grey = 10;
|
|
|
|
|
+
|
|
|
|
|
+ // let mut anchor_urls = vec![];
|
|
|
|
|
+ // let mut white_urls = vec![];
|
|
|
|
|
+ // let mut grey_urls = vec![];
|
|
|
|
|
+
|
|
|
|
|
+ // let ex = Arc::new(Executor::new());
|
|
|
|
|
+ // let ex_ = ex.clone();
|
|
|
|
|
+
|
|
|
|
|
+ // let settings =
|
|
|
|
|
+ // Settings { allowed_transports: vec!["tcp".to_string()], ..Default::default() };
|
|
|
|
|
+
|
|
|
|
|
+ // let p2p = P2p::new(settings, ex.clone()).await;
|
|
|
|
|
+ // let hosts = p2p.hosts();
|
|
|
|
|
+
|
|
|
|
|
+ // // Retrieve outbound transports
|
|
|
|
|
+ // let transports = &p2p.settings().allowed_transports;
|
|
|
|
|
+
|
|
|
|
|
+ // // First test that if we have anchorlist connections in our host list,
|
|
|
|
|
+ // // those will be selected first.
|
|
|
|
|
+ // for i in 0..n_anchor {
|
|
|
|
|
+ // anchor_urls.push(Url::parse(&format!("tcp://anchorlist{}:123", i)).unwrap());
|
|
|
|
|
+ // }
|
|
|
|
|
+ // for i in 0..n_white {
|
|
|
|
|
+ // white_urls.push(Url::parse(&format!("tcp://whitelist{}:123", i)).unwrap());
|
|
|
|
|
+ // }
|
|
|
|
|
+ // for i in 0..n_grey {
|
|
|
|
|
+ // grey_urls.push(Url::parse(&format!("tcp://greylist{}:123", i)).unwrap());
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // // Build up a hostlist
|
|
|
|
|
+ // for anchor in &anchor_urls {
|
|
|
|
|
+ // let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
+ // hosts.anchorlist_store(anchor.clone(), last_seen).await;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // for white in &white_urls {
|
|
|
|
|
+ // let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
+ // hosts.whitelist_store(white.clone(), last_seen).await;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // for grey in &grey_urls {
|
|
|
|
|
+ // let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
+ // hosts.greylist_store(grey.clone(), last_seen).await;
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // assert!(!hosts.is_empty_anchorlist().await);
|
|
|
|
|
+ // assert!(!hosts.is_empty_whitelist().await);
|
|
|
|
|
+ // assert!(!hosts.is_empty_greylist().await);
|
|
|
|
|
+
|
|
|
|
|
+ // let host =
|
|
|
|
|
+ // hosts.anchorlist_fetch_address(p2p.clone(), &transports).await.unwrap();
|
|
|
|
|
+
|
|
|
|
|
+ // assert!(anchor_urls.iter().any(|u| u.clone() == host.0));
|
|
|
|
|
+
|
|
|
|
|
+ // // Now clear the hostlists and test that if we have no anchorlist connections in our host list,
|
|
|
|
|
+ // // we will select from the whitelist.
|
|
|
|
|
+
|
|
|
|
|
+ // let mut anchorlist = hosts.anchorlist.write().await;
|
|
|
|
|
+ // anchorlist.clear();
|
|
|
|
|
+ // drop(anchorlist);
|
|
|
|
|
+
|
|
|
|
|
+ // let mut whitelist = hosts.whitelist.write().await;
|
|
|
|
|
+ // whitelist.clear();
|
|
|
|
|
+ // drop(whitelist);
|
|
|
|
|
+
|
|
|
|
|
+ // let mut greylist = hosts.greylist.write().await;
|
|
|
|
|
+ // greylist.clear();
|
|
|
|
|
+ // drop(greylist);
|
|
|
|
|
+
|
|
|
|
|
+ // assert!(hosts.is_empty_anchorlist().await);
|
|
|
|
|
+ // assert!(hosts.is_empty_whitelist().await);
|
|
|
|
|
+ // assert!(hosts.is_empty_greylist().await);
|
|
|
|
|
+
|
|
|
|
|
+ // for i in 0..n_white {
|
|
|
|
|
+ // white_urls.push(Url::parse(&format!("tcp://whitelist{}:123", i)).unwrap());
|
|
|
|
|
+ // }
|
|
|
|
|
+ // for i in 0..n_grey {
|
|
|
|
|
+ // grey_urls.push(Url::parse(&format!("tcp://greylist{}:123", i)).unwrap());
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // for white in &white_urls {
|
|
|
|
|
+ // let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
+ // hosts.whitelist_store(white.clone(), last_seen).await;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // for grey in &grey_urls {
|
|
|
|
|
+ // let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
+ // hosts.greylist_store(grey.clone(), last_seen).await;
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // assert!(hosts.is_empty_anchorlist().await);
|
|
|
|
|
+ // assert!(!hosts.is_empty_whitelist().await);
|
|
|
|
|
+ // assert!(!hosts.is_empty_greylist().await);
|
|
|
|
|
+
|
|
|
|
|
+ // let host =
|
|
|
|
|
+ // hosts.anchorlist_fetch_address(p2p.clone(), &transports).await.unwrap();
|
|
|
|
|
+
|
|
|
|
|
+ // assert!(white_urls.iter().any(|u| u.clone() == host.0));
|
|
|
|
|
+
|
|
|
|
|
+ // // If we have no whitelist connections, select from the greylist.
|
|
|
|
|
+ // let mut whitelist = hosts.whitelist.write().await;
|
|
|
|
|
+ // whitelist.clear();
|
|
|
|
|
+ // drop(whitelist);
|
|
|
|
|
+
|
|
|
|
|
+ // let mut greylist = hosts.greylist.write().await;
|
|
|
|
|
+ // greylist.clear();
|
|
|
|
|
+ // drop(greylist);
|
|
|
|
|
+
|
|
|
|
|
+ // assert!(hosts.is_empty_anchorlist().await);
|
|
|
|
|
+ // assert!(hosts.is_empty_whitelist().await);
|
|
|
|
|
+ // assert!(hosts.is_empty_greylist().await);
|
|
|
|
|
+
|
|
|
|
|
+ // for i in 0..n_grey {
|
|
|
|
|
+ // grey_urls.push(Url::parse(&format!("tcp://greylist{}:123", i)).unwrap());
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // for grey in &grey_urls {
|
|
|
|
|
+ // let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
+ // hosts.greylist_store(grey.clone(), last_seen).await;
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // assert!(hosts.is_empty_anchorlist().await);
|
|
|
|
|
+ // assert!(hosts.is_empty_whitelist().await);
|
|
|
|
|
+ // assert!(!hosts.is_empty_greylist().await);
|
|
|
|
|
+
|
|
|
|
|
+ // let host =
|
|
|
|
|
+ // hosts.anchorlist_fetch_address(p2p.clone(), &transports).await.unwrap();
|
|
|
|
|
+
|
|
|
|
|
+ // assert!(grey_urls.iter().any(|u| u.clone() == host.0));
|
|
|
|
|
+ // });
|
|
|
|
|
+ //}
|
|
|
}
|
|
}
|