|
@@ -21,7 +21,7 @@ use std::{
|
|
|
fs,
|
|
fs,
|
|
|
fs::File,
|
|
fs::File,
|
|
|
sync::Arc,
|
|
sync::Arc,
|
|
|
- time::UNIX_EPOCH,
|
|
|
|
|
|
|
+ time::{Instant, UNIX_EPOCH},
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
use log::{debug, error, info, trace, warn};
|
|
use log::{debug, error, info, trace, warn};
|
|
@@ -225,6 +225,7 @@ impl Hosts {
|
|
|
/// * We already have this connection established
|
|
/// * We already have this connection established
|
|
|
/// * We already have this configured as a manual peer
|
|
/// * We already have this configured as a manual peer
|
|
|
/// * This address is already pending a connection
|
|
/// * This address is already pending a connection
|
|
|
|
|
+ /// * This peer is migrating between hostlists
|
|
|
pub async fn check_address_with_lock(
|
|
pub async fn check_address_with_lock(
|
|
|
&self,
|
|
&self,
|
|
|
p2p: P2pPtr,
|
|
p2p: P2pPtr,
|
|
@@ -254,6 +255,16 @@ impl Hosts {
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Check this peer isn't currently being migrated from hostlists
|
|
|
|
|
+ if self.is_migrating(&host).await {
|
|
|
|
|
+ debug!(
|
|
|
|
|
+ target: "store::check_address_with_lock()",
|
|
|
|
|
+ "Host '{}' is migrating so skipping",
|
|
|
|
|
+ host
|
|
|
|
|
+ );
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 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 {
|
|
if !p2p.add_pending(&host).await {
|
|
|
debug!(
|
|
debug!(
|
|
@@ -655,11 +666,13 @@ impl Hosts {
|
|
|
/// If they've been quarantined for more than a configured limit, forget them.
|
|
/// If they've been quarantined for more than a configured limit, forget them.
|
|
|
pub async fn quarantine(&self, url: &Url) {
|
|
pub async fn quarantine(&self, url: &Url) {
|
|
|
debug!(target: "store::remove()", "Quarantining peer {}", url);
|
|
debug!(target: "store::remove()", "Quarantining peer {}", url);
|
|
|
|
|
+ let timer = Instant::now();
|
|
|
let mut q = self.quarantine.write().await;
|
|
let mut q = self.quarantine.write().await;
|
|
|
if let Some(retries) = q.get_mut(url) {
|
|
if let Some(retries) = q.get_mut(url) {
|
|
|
*retries += 1;
|
|
*retries += 1;
|
|
|
debug!(target: "net::hosts::quarantine()", "Peer {} quarantined {} times", url, retries);
|
|
debug!(target: "net::hosts::quarantine()", "Peer {} quarantined {} times", url, retries);
|
|
|
if *retries == self.settings.hosts_quarantine_limit {
|
|
if *retries == self.settings.hosts_quarantine_limit {
|
|
|
|
|
+ debug!(target: "net::hosts::quarantine()", "Reached quarantine limited after {:?}", timer.elapsed());
|
|
|
debug!(target: "net::hosts::quarantine()", "Removing from hostlist {}", url);
|
|
debug!(target: "net::hosts::quarantine()", "Removing from hostlist {}", url);
|
|
|
self.remove_host(url).await;
|
|
self.remove_host(url).await;
|
|
|
debug!(target: "net::hosts::quarantine()", "Banning peer {}", url);
|
|
debug!(target: "net::hosts::quarantine()", "Banning peer {}", url);
|
|
@@ -667,7 +680,7 @@ impl Hosts {
|
|
|
self.mark_rejected(url).await;
|
|
self.mark_rejected(url).await;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- debug!(target: "net::hosts::remove()", "Added peer {} to quarantine", url);
|
|
|
|
|
|
|
+ debug!(target: "net::hosts::quarantine()", "Added peer {} to quarantine", url);
|
|
|
q.insert(url.clone(), 0);
|
|
q.insert(url.clone(), 0);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|