|
@@ -222,16 +222,19 @@ impl HostContainer {
|
|
|
/// have the address.
|
|
/// have the address.
|
|
|
pub async fn store_or_update(&self, color: HostColor, addrs: &[(Url, u64)]) {
|
|
pub async fn store_or_update(&self, color: HostColor, addrs: &[(Url, u64)]) {
|
|
|
trace!(target: "net::hosts::store_or_update()", "[START] {:?}", color);
|
|
trace!(target: "net::hosts::store_or_update()", "[START] {:?}", color);
|
|
|
- let color = color as usize;
|
|
|
|
|
|
|
+ let color = color.clone() as usize;
|
|
|
|
|
+
|
|
|
for (addr, last_seen) in addrs {
|
|
for (addr, last_seen) in addrs {
|
|
|
if !self.contains(color, addr).await {
|
|
if !self.contains(color, addr).await {
|
|
|
debug!(target: "net::hosts::store_or_update()",
|
|
debug!(target: "net::hosts::store_or_update()",
|
|
|
- "We do not have {} in the hostlist. Adding to store...", addr);
|
|
|
|
|
|
|
+ "We do not have {} in {:?} list. Adding to store...", addr,
|
|
|
|
|
+ HostColor::try_from(color).unwrap());
|
|
|
|
|
|
|
|
self.store(color, addr.clone(), *last_seen).await;
|
|
self.store(color, addr.clone(), *last_seen).await;
|
|
|
} else {
|
|
} else {
|
|
|
debug!(target: "net::hosts::store_or_update()",
|
|
debug!(target: "net::hosts::store_or_update()",
|
|
|
- "We have {} in the hostlist. Updating last seen...", addr);
|
|
|
|
|
|
|
+ "We have {} in {:?} list. Updating last seen...", addr,
|
|
|
|
|
+ HostColor::try_from(color).unwrap());
|
|
|
|
|
|
|
|
let position = self
|
|
let position = self
|
|
|
.get_index_at_addr(color, addr.clone())
|
|
.get_index_at_addr(color, addr.clone())
|
|
@@ -831,7 +834,8 @@ impl Hosts {
|
|
|
false
|
|
false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /// Filter given addresses based on certain rulesets and validity.
|
|
|
|
|
|
|
+ /// Filter given addresses based on certain rulesets and validity. Strictly called only on
|
|
|
|
|
+ /// the first time learning of a new peer.
|
|
|
async fn filter_addresses(
|
|
async fn filter_addresses(
|
|
|
&self,
|
|
&self,
|
|
|
settings: SettingsPtr,
|
|
settings: SettingsPtr,
|
|
@@ -858,6 +862,15 @@ impl Hosts {
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Reject this peer if it's already stored on the hostlist.
|
|
|
|
|
+ if self.container.contains(HostColor::Gold as usize, addr_).await ||
|
|
|
|
|
+ self.container.contains(HostColor::White as usize, addr_).await
|
|
|
|
|
+ {
|
|
|
|
|
+ debug!(target: "net::hosts::filter_addresses()",
|
|
|
|
|
+ "We already have {} in the hostlist. Skipping", addr_);
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
let host_str = addr_.host_str().unwrap();
|
|
let host_str = addr_.host_str().unwrap();
|
|
|
|
|
|
|
|
if !localnet {
|
|
if !localnet {
|
|
@@ -925,22 +938,16 @@ impl Hosts {
|
|
|
match destination {
|
|
match destination {
|
|
|
// Downgrade to grey. Remove from white and gold.
|
|
// Downgrade to grey. Remove from white and gold.
|
|
|
HostColor::Grey => {
|
|
HostColor::Grey => {
|
|
|
- // Remove from the Anchorlist.
|
|
|
|
|
self.container.remove_if_exists(HostColor::Gold, addr).await;
|
|
self.container.remove_if_exists(HostColor::Gold, addr).await;
|
|
|
-
|
|
|
|
|
- // Remove from the Whitelist.
|
|
|
|
|
self.container.remove_if_exists(HostColor::White, addr).await;
|
|
self.container.remove_if_exists(HostColor::White, addr).await;
|
|
|
|
|
|
|
|
- // Write to the Greylist.
|
|
|
|
|
self.container.store_or_update(HostColor::Grey, &[(addr.clone(), last_seen)]).await;
|
|
self.container.store_or_update(HostColor::Grey, &[(addr.clone(), last_seen)]).await;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Remove from Greylist, add to Whitelist. Called by the Refinery.
|
|
// Remove from Greylist, add to Whitelist. Called by the Refinery.
|
|
|
HostColor::White => {
|
|
HostColor::White => {
|
|
|
- // Remove from the Greylist.
|
|
|
|
|
self.container.remove_if_exists(HostColor::Grey, addr).await;
|
|
self.container.remove_if_exists(HostColor::Grey, addr).await;
|
|
|
|
|
|
|
|
- // Add to the Whitelist.
|
|
|
|
|
self.container
|
|
self.container
|
|
|
.store_or_update(HostColor::White, &[(addr.clone(), last_seen)])
|
|
.store_or_update(HostColor::White, &[(addr.clone(), last_seen)])
|
|
|
.await;
|
|
.await;
|
|
@@ -948,13 +955,9 @@ impl Hosts {
|
|
|
|
|
|
|
|
// Upgrade to gold. Remove from white or grey.
|
|
// Upgrade to gold. Remove from white or grey.
|
|
|
HostColor::Gold => {
|
|
HostColor::Gold => {
|
|
|
- // Remove from the Greylist.
|
|
|
|
|
self.container.remove_if_exists(HostColor::Grey, addr).await;
|
|
self.container.remove_if_exists(HostColor::Grey, addr).await;
|
|
|
-
|
|
|
|
|
- // Remove from the Whitelist.
|
|
|
|
|
self.container.remove_if_exists(HostColor::White, addr).await;
|
|
self.container.remove_if_exists(HostColor::White, addr).await;
|
|
|
|
|
|
|
|
- // Add to the Anchorlist.
|
|
|
|
|
self.container.store_or_update(HostColor::Gold, &[(addr.clone(), last_seen)]).await;
|
|
self.container.store_or_update(HostColor::Gold, &[(addr.clone(), last_seen)]).await;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -969,16 +972,10 @@ impl Hosts {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Remove from the Greylist.
|
|
|
|
|
self.container.remove_if_exists(HostColor::Grey, addr).await;
|
|
self.container.remove_if_exists(HostColor::Grey, addr).await;
|
|
|
-
|
|
|
|
|
- // Remove from the Whitelist.
|
|
|
|
|
self.container.remove_if_exists(HostColor::White, addr).await;
|
|
self.container.remove_if_exists(HostColor::White, addr).await;
|
|
|
-
|
|
|
|
|
- // Remove from the Anchorlist.
|
|
|
|
|
self.container.remove_if_exists(HostColor::Gold, addr).await;
|
|
self.container.remove_if_exists(HostColor::Gold, addr).await;
|
|
|
|
|
|
|
|
- // Add to the Blacklist.
|
|
|
|
|
self.container
|
|
self.container
|
|
|
.store_or_update(HostColor::Black, &[(addr.clone(), last_seen)])
|
|
.store_or_update(HostColor::Black, &[(addr.clone(), last_seen)])
|
|
|
.await;
|
|
.await;
|