|
|
@@ -364,8 +364,8 @@ impl HostContainer {
|
|
|
|
|
|
let mut list = self.hostlists[color].write().unwrap();
|
|
|
list.push((addr.clone(), last_seen));
|
|
|
- debug!(target: "net::hosts::store()", "Added [{}] to {:?} list",
|
|
|
- addr, HostColor::try_from(color).unwrap());
|
|
|
+ debug!(target: "net::hosts::store()", "Added [{addr}] to {:?} list",
|
|
|
+ HostColor::try_from(color).unwrap());
|
|
|
|
|
|
trace!(target: "net::hosts::store()", "[END] list={:?}",
|
|
|
HostColor::try_from(color).unwrap());
|
|
|
@@ -379,11 +379,11 @@ impl HostContainer {
|
|
|
let mut list = self.hostlists[color_code].write().unwrap();
|
|
|
if let Some(entry) = list.iter_mut().find(|(u, _)| *u == addr) {
|
|
|
entry.1 = last_seen;
|
|
|
- debug!(target: "net::hosts::store_or_update()", "Updated [{}] entry on {:?} list",
|
|
|
- addr, color.clone());
|
|
|
+ debug!(target: "net::hosts::store_or_update()", "Updated [{addr}] entry on {:?} list",
|
|
|
+ color.clone());
|
|
|
} else {
|
|
|
list.push((addr.clone(), last_seen));
|
|
|
- debug!(target: "net::hosts::store_or_update()", "Added [{}] to {:?} list", addr, color);
|
|
|
+ debug!(target: "net::hosts::store_or_update()", "Added [{addr}] to {color:?} list");
|
|
|
}
|
|
|
trace!(target: "net::hosts::store_or_update()", "[STOP]");
|
|
|
}
|
|
|
@@ -422,7 +422,7 @@ impl HostContainer {
|
|
|
transport_mixing: bool,
|
|
|
tor_socks5_proxy: Url,
|
|
|
) -> Vec<(Url, u64)> {
|
|
|
- trace!(target: "net::hosts::fetch_addrs()", "[START] {:?}", color);
|
|
|
+ trace!(target: "net::hosts::fetch_addrs()", "[START] {color:?}");
|
|
|
let mut hosts = vec![];
|
|
|
let index = color as usize;
|
|
|
|
|
|
@@ -574,7 +574,7 @@ impl HostContainer {
|
|
|
schemes: &[String],
|
|
|
) -> Option<((Url, u64), usize)> {
|
|
|
// Retrieve all peers corresponding to that transport schemes
|
|
|
- trace!(target: "net::hosts::fetch_random_with_schemes()", "[START] {:?}", color);
|
|
|
+ trace!(target: "net::hosts::fetch_random_with_schemes()", "[START] {color:?}");
|
|
|
let list = self.fetch_with_schemes(color as usize, schemes, None);
|
|
|
|
|
|
if list.is_empty() {
|
|
|
@@ -588,7 +588,7 @@ impl HostContainer {
|
|
|
|
|
|
/// Get up to n random peers. Schemes are not taken into account.
|
|
|
pub(in crate::net) fn fetch_n_random(&self, color: HostColor, n: u32) -> Vec<(Url, u64)> {
|
|
|
- trace!(target: "net::hosts::fetch_n_random()", "[START] {:?}", color);
|
|
|
+ trace!(target: "net::hosts::fetch_n_random()", "[START] {color:?}");
|
|
|
let n = n as usize;
|
|
|
if n == 0 {
|
|
|
return vec![]
|
|
|
@@ -618,7 +618,7 @@ impl HostContainer {
|
|
|
schemes: &[String],
|
|
|
n: u32,
|
|
|
) -> Vec<(Url, u64)> {
|
|
|
- trace!(target: "net::hosts::fetch_n_random_with_schemes()", "[START] {:?}", color);
|
|
|
+ trace!(target: "net::hosts::fetch_n_random_with_schemes()", "[START] {color:?}");
|
|
|
let index = color as usize;
|
|
|
let n = n as usize;
|
|
|
if n == 0 {
|
|
|
@@ -646,7 +646,7 @@ impl HostContainer {
|
|
|
schemes: &[String],
|
|
|
n: u32,
|
|
|
) -> Vec<(Url, u64)> {
|
|
|
- trace!(target: "net::hosts::fetch_excluding_schemes()", "[START] {:?}", color);
|
|
|
+ trace!(target: "net::hosts::fetch_excluding_schemes()", "[START] {color:?}");
|
|
|
let index = color as usize;
|
|
|
let n = n as usize;
|
|
|
if n == 0 {
|
|
|
@@ -671,7 +671,7 @@ impl HostContainer {
|
|
|
let color_code = color.clone() as usize;
|
|
|
let mut list = self.hostlists[color_code].write().unwrap();
|
|
|
if let Some(position) = list.iter().position(|(u, _)| u == addr) {
|
|
|
- debug!(target: "net::hosts::remove_if_exists()", "Removing addr={} list={:?}", addr, color);
|
|
|
+ debug!(target: "net::hosts::remove_if_exists()", "Removing addr={addr} list={color:?}");
|
|
|
list.remove(position);
|
|
|
}
|
|
|
}
|
|
|
@@ -732,7 +732,7 @@ impl HostContainer {
|
|
|
|
|
|
debug!(
|
|
|
target: "net::hosts::resize()",
|
|
|
- "{:?}list reached max size. Removed {:?}", color, last_entry,
|
|
|
+ "{color:?}list reached max size. Removed {last_entry:?}"
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
@@ -756,7 +756,7 @@ impl HostContainer {
|
|
|
// misreporting the last_seen field.
|
|
|
if now < last_seen {
|
|
|
debug!(target: "net::hosts::refresh()",
|
|
|
- "last_seen [{}] is newer than current system time [{}]. Skipping", now, last_seen);
|
|
|
+ "last_seen [{now}] is newer than current system time [{last_seen}]. Skipping");
|
|
|
continue
|
|
|
}
|
|
|
if (now - last_seen) > max_age {
|
|
|
@@ -765,7 +765,7 @@ impl HostContainer {
|
|
|
}
|
|
|
|
|
|
for item in old_items {
|
|
|
- debug!(target: "net::hosts::refresh()", "Removing {:?}", item);
|
|
|
+ debug!(target: "net::hosts::refresh()", "Removing {item:?}");
|
|
|
self.remove_if_exists(color.clone(), &item);
|
|
|
}
|
|
|
}
|
|
|
@@ -784,7 +784,7 @@ impl HostContainer {
|
|
|
|
|
|
let contents = load_file(&path);
|
|
|
if let Err(e) = contents {
|
|
|
- warn!(target: "net::hosts::load_hosts()", "Failed retrieving saved hosts: {}", e);
|
|
|
+ warn!(target: "net::hosts::load_hosts()", "Failed retrieving saved hosts: {e}");
|
|
|
return Ok(())
|
|
|
}
|
|
|
|
|
|
@@ -794,7 +794,7 @@ impl HostContainer {
|
|
|
let url = match Url::parse(data[1]) {
|
|
|
Ok(u) => u,
|
|
|
Err(e) => {
|
|
|
- debug!(target: "net::hosts::load_hosts()", "Skipping malformed URL {}", e);
|
|
|
+ debug!(target: "net::hosts::load_hosts()", "Skipping malformed URL {e}");
|
|
|
continue
|
|
|
}
|
|
|
};
|
|
|
@@ -802,7 +802,7 @@ impl HostContainer {
|
|
|
let last_seen = match data[2].parse::<u64>() {
|
|
|
Ok(t) => t,
|
|
|
Err(e) => {
|
|
|
- debug!(target: "net::hosts::load_hosts()", "Skipping malformed last seen {}", e);
|
|
|
+ debug!(target: "net::hosts::load_hosts()", "Skipping malformed last seen {e}");
|
|
|
continue
|
|
|
}
|
|
|
};
|
|
|
@@ -854,15 +854,14 @@ impl HostContainer {
|
|
|
|
|
|
for (name, list) in hostlist {
|
|
|
for (url, last_seen) in list {
|
|
|
- tsv.push_str(&format!("{}\t{}\t{}\n", name, url, last_seen));
|
|
|
+ tsv.push_str(&format!("{name}\t{url}\t{last_seen}\n"));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if !tsv.is_empty() {
|
|
|
- info!(target: "net::hosts::save_hosts()", "Saving hosts to: {:?}",
|
|
|
- path);
|
|
|
+ info!(target: "net::hosts::save_hosts()", "Saving hosts to: {path:?}");
|
|
|
if let Err(e) = save_file(&path, &tsv) {
|
|
|
- error!(target: "net::hosts::save_hosts()", "Failed saving hosts: {}", e);
|
|
|
+ error!(target: "net::hosts::save_hosts()", "Failed saving hosts: {e}");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -941,8 +940,8 @@ impl Hosts {
|
|
|
// Then ensure we aren't currently trying to add this peer to the hostlist.
|
|
|
for (i, (addr, last_seen)) in filtered_addrs.iter().enumerate() {
|
|
|
if let Err(e) = self.try_register(addr.clone(), HostState::Insert) {
|
|
|
- debug!(target: "net::hosts::store_or_update", "Cannot insert addr={}, err={}",
|
|
|
- addr.clone(), e);
|
|
|
+ debug!(target: "net::hosts::store_or_update", "Cannot insert addr={}, err={e}",
|
|
|
+ addr.clone());
|
|
|
|
|
|
continue
|
|
|
}
|
|
|
@@ -975,8 +974,8 @@ impl Hosts {
|
|
|
) -> Result<HostState> {
|
|
|
let mut registry = self.registry.lock().unwrap();
|
|
|
|
|
|
- trace!(target: "net::hosts::try_update_registry()", "Try register addr={}, state={}",
|
|
|
- addr, &new_state);
|
|
|
+ trace!(target: "net::hosts::try_update_registry()", "Try register addr={addr}, state={}",
|
|
|
+ &new_state);
|
|
|
|
|
|
if registry.contains_key(&addr) {
|
|
|
let current_state = registry.get(&addr).unwrap().clone();
|
|
|
@@ -995,13 +994,13 @@ impl Hosts {
|
|
|
registry.insert(addr.clone(), state.clone());
|
|
|
}
|
|
|
|
|
|
- trace!(target: "net::hosts::try_update_registry()", "Returning result {:?}", result);
|
|
|
+ trace!(target: "net::hosts::try_update_registry()", "Returning result {result:?}");
|
|
|
|
|
|
result
|
|
|
} else {
|
|
|
// We don't know this peer. We can safely update the state.
|
|
|
- debug!(target: "net::hosts::try_update_registry()", "Inserting addr={}, state={}",
|
|
|
- addr, &new_state);
|
|
|
+ debug!(target: "net::hosts::try_update_registry()", "Inserting addr={addr}, state={}",
|
|
|
+ &new_state);
|
|
|
|
|
|
registry.insert(addr.clone(), new_state.clone());
|
|
|
|
|
|
@@ -1040,12 +1039,12 @@ impl Hosts {
|
|
|
if let Err(e) = self.try_register(host.clone(), HostState::Connect) {
|
|
|
trace!(
|
|
|
target: "net::hosts::check_addrs",
|
|
|
- "Skipping addr={}, err={}", host.clone(), e,
|
|
|
+ "Skipping addr={}, err={e}", host.clone(),
|
|
|
);
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
- debug!(target: "net::hosts::check_addrs()", "Found valid host {}", host);
|
|
|
+ debug!(target: "net::hosts::check_addrs()", "Found valid host {host}");
|
|
|
return Some((host.clone(), last_seen))
|
|
|
}
|
|
|
|
|
|
@@ -1220,9 +1219,9 @@ impl Hosts {
|
|
|
for scheme in schemes {
|
|
|
for &port in &ports {
|
|
|
let url_string = if port == 0 {
|
|
|
- format!("{}://{}", scheme, hostname)
|
|
|
+ format!("{scheme}://{hostname}")
|
|
|
} else {
|
|
|
- format!("{}://{}:{}", scheme, hostname, port)
|
|
|
+ format!("{scheme}://{hostname}:{port}")
|
|
|
};
|
|
|
|
|
|
if let Ok(url) = Url::parse(&url_string) {
|
|
|
@@ -1250,7 +1249,7 @@ impl Hosts {
|
|
|
/// Filter given addresses based on certain rulesets and validity. Strictly called only on
|
|
|
/// the first time learning of new peers.
|
|
|
async fn filter_addresses(&self, addrs: &[(Url, u64)]) -> Vec<(Url, u64)> {
|
|
|
- debug!(target: "net::hosts::filter_addresses", "Filtering addrs: {:?}", addrs);
|
|
|
+ debug!(target: "net::hosts::filter_addresses", "Filtering addrs: {addrs:?}");
|
|
|
let mut ret = vec![];
|
|
|
|
|
|
// Acquire read lock on P2P settings. Dropped when this function finishes.
|
|
|
@@ -1261,7 +1260,7 @@ impl Hosts {
|
|
|
if addr_.host_str().is_none() || addr_.port().is_none() || addr_.cannot_be_a_base() {
|
|
|
debug!(
|
|
|
target: "net::hosts::filter_addresses",
|
|
|
- "[{}] has invalid addr format. Skipping", addr_,
|
|
|
+ "[{addr_}] has invalid addr format. Skipping"
|
|
|
);
|
|
|
continue
|
|
|
}
|
|
|
@@ -1270,7 +1269,7 @@ impl Hosts {
|
|
|
if settings.seeds.contains(addr_) {
|
|
|
debug!(
|
|
|
target: "net::hosts::filter_addresses",
|
|
|
- "[{}] is a configured seed. Skipping", addr_,
|
|
|
+ "[{addr_}] is a configured seed. Skipping"
|
|
|
);
|
|
|
continue
|
|
|
}
|
|
|
@@ -1279,7 +1278,7 @@ impl Hosts {
|
|
|
if settings.peers.contains(addr_) {
|
|
|
debug!(
|
|
|
target: "net::hosts::filter_addresses",
|
|
|
- "[{}] is a configured peer. Skipping", addr_,
|
|
|
+ "[{addr_}] is a configured peer. Skipping"
|
|
|
);
|
|
|
continue
|
|
|
}
|
|
|
@@ -1290,7 +1289,7 @@ impl Hosts {
|
|
|
{
|
|
|
debug!(
|
|
|
target: "net::hosts::filter_addresses",
|
|
|
- "[{}] is blacklisted", addr_,
|
|
|
+ "[{addr_}] is blacklisted"
|
|
|
);
|
|
|
continue
|
|
|
}
|
|
|
@@ -1304,7 +1303,7 @@ impl Hosts {
|
|
|
if host == ext.host().unwrap() {
|
|
|
debug!(
|
|
|
target: "net::hosts::filter_addresses",
|
|
|
- "[{}] is our own external addr. Skipping", addr_,
|
|
|
+ "[{addr_}] is our own external addr. Skipping"
|
|
|
);
|
|
|
continue 'addr_loop
|
|
|
}
|
|
|
@@ -1315,7 +1314,7 @@ impl Hosts {
|
|
|
if addr_.port() == ext.port() {
|
|
|
debug!(
|
|
|
target: "net::hosts::filter_addresses",
|
|
|
- "[{}] is our own localnet port. Skipping", addr_,
|
|
|
+ "[{addr_}] is our own localnet port. Skipping"
|
|
|
);
|
|
|
continue 'addr_loop
|
|
|
}
|
|
|
@@ -1328,7 +1327,7 @@ impl Hosts {
|
|
|
if !settings.localnet && self.is_local_host(addr_) {
|
|
|
debug!(
|
|
|
target: "net::hosts::filter_addresses",
|
|
|
- "[{}] Filtering non-global ranges", addr_,
|
|
|
+ "[{addr_}] Filtering non-global ranges"
|
|
|
);
|
|
|
continue
|
|
|
}
|
|
|
@@ -1343,7 +1342,7 @@ impl Hosts {
|
|
|
}
|
|
|
trace!(
|
|
|
target: "net::hosts::filter_addresses",
|
|
|
- "[Tor] Valid: {}", host_str,
|
|
|
+ "[Tor] Valid: {host_str}"
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -1353,7 +1352,7 @@ impl Hosts {
|
|
|
"tcp" | "tcp+tls" => {
|
|
|
trace!(
|
|
|
target: "net::hosts::filter_addresses",
|
|
|
- "[TCP] Valid: {}", host_str,
|
|
|
+ "[TCP] Valid: {host_str}"
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -1364,7 +1363,7 @@ impl Hosts {
|
|
|
}
|
|
|
trace!(
|
|
|
target: "net::hosts::filter_addresses",
|
|
|
- "[I2p] Valid: {}", host_str,
|
|
|
+ "[I2p] Valid: {host_str}"
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -1404,7 +1403,7 @@ impl Hosts {
|
|
|
self.container.contains(HostColor::White as usize, addr_) ||
|
|
|
self.container.contains(HostColor::Grey as usize, addr_)
|
|
|
{
|
|
|
- debug!(target: "net::hosts::filter_addresses", "[{}] exists! Skipping", addr_);
|
|
|
+ debug!(target: "net::hosts::filter_addresses", "[{addr_}] exists! Skipping");
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
@@ -1430,7 +1429,7 @@ impl Hosts {
|
|
|
|
|
|
/// Downgrade host to Greylist, remove from Gold or White list.
|
|
|
pub fn greylist_host(&self, addr: &Url, last_seen: u64) -> Result<()> {
|
|
|
- debug!(target: "net::hosts:greylist_host()", "Downgrading addr={}", addr);
|
|
|
+ debug!(target: "net::hosts:greylist_host()", "Downgrading addr={addr}");
|
|
|
self.move_host(addr, last_seen, HostColor::Grey)?;
|
|
|
|
|
|
// Free up this addr for future operations.
|
|
|
@@ -1440,7 +1439,7 @@ impl Hosts {
|
|
|
}
|
|
|
|
|
|
pub fn whitelist_host(&self, addr: &Url, last_seen: u64) -> Result<()> {
|
|
|
- debug!(target: "net::hosts:whitelist_host()", "Upgrading addr={}", addr);
|
|
|
+ debug!(target: "net::hosts:whitelist_host()", "Upgrading addr={addr}");
|
|
|
self.move_host(addr, last_seen, HostColor::White)?;
|
|
|
|
|
|
// Free up this addr for future operations.
|
|
|
@@ -1468,14 +1467,13 @@ impl Hosts {
|
|
|
last_seen: u64,
|
|
|
destination: HostColor,
|
|
|
) -> Result<()> {
|
|
|
- debug!(target: "net::hosts::move_host()", "Trying to move addr={} destination={:?}",
|
|
|
- addr, destination);
|
|
|
+ debug!(target: "net::hosts::move_host()", "Trying to move addr={addr} destination={destination:?}");
|
|
|
|
|
|
// If we cannot register this address as move, this will simply return here.
|
|
|
self.try_register(addr.clone(), HostState::Move)?;
|
|
|
|
|
|
- debug!(target: "net::hosts::move_host()", "Moving addr={} destination={:?}",
|
|
|
- addr.clone(), destination);
|
|
|
+ debug!(target: "net::hosts::move_host()", "Moving addr={} destination={destination:?}",
|
|
|
+ addr.clone());
|
|
|
|
|
|
match destination {
|
|
|
// Downgrade to grey. Remove from white and gold.
|
|
|
@@ -1719,7 +1717,7 @@ mod tests {
|
|
|
Url::parse("tcp://192.168.10.65").unwrap(),
|
|
|
];
|
|
|
for host in local_hosts {
|
|
|
- eprintln!("{}", host);
|
|
|
+ eprintln!("{host}");
|
|
|
assert!(hosts.is_local_host(&host));
|
|
|
}
|
|
|
let remote_hosts: Vec<Url> = vec![
|
|
|
@@ -1833,14 +1831,14 @@ mod tests {
|
|
|
// Insert 5 items into the darklist with an old timestamp.
|
|
|
for i in 0..5 {
|
|
|
let last_seen = old_timestamp + i;
|
|
|
- let url = Url::parse(&format!("tcp://old_darklist{}:123", i)).unwrap();
|
|
|
+ let url = Url::parse(&format!("tcp://old_darklist{i}:123")).unwrap();
|
|
|
hosts.container.store(HostColor::Dark as usize, url.clone(), last_seen);
|
|
|
}
|
|
|
|
|
|
// Insert another 5 items into the darklist with a recent timestamp.
|
|
|
for i in 0..5 {
|
|
|
let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
- let url = Url::parse(&format!("tcp://new_darklist{}:123", i)).unwrap();
|
|
|
+ let url = Url::parse(&format!("tcp://new_darklist{i}:123")).unwrap();
|
|
|
hosts.container.store(HostColor::Dark as usize, url.clone(), last_seen);
|
|
|
}
|
|
|
|
|
|
@@ -1862,7 +1860,7 @@ mod tests {
|
|
|
// Insert another 5 items into the darklist with a timestamp from the future.
|
|
|
for i in 0..5 {
|
|
|
let last_seen = future_timestamp;
|
|
|
- let url = Url::parse(&format!("tcp://future_darklist{}:123", i)).unwrap();
|
|
|
+ let url = Url::parse(&format!("tcp://future_darklist{i}:123")).unwrap();
|
|
|
hosts.container.store(HostColor::Dark as usize, url.clone(), last_seen);
|
|
|
}
|
|
|
|
|
|
@@ -1884,14 +1882,14 @@ mod tests {
|
|
|
for i in 0..10 {
|
|
|
sleep(1).await;
|
|
|
let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
- let url = Url::parse(&format!("tcp://whitelist{}:123", i)).unwrap();
|
|
|
+ let url = Url::parse(&format!("tcp://whitelist{i}:123")).unwrap();
|
|
|
hosts.container.store(HostColor::White as usize, url.clone(), last_seen);
|
|
|
}
|
|
|
|
|
|
for (url, last_seen) in
|
|
|
hosts.container.hostlists[HostColor::White as usize].read().unwrap().iter()
|
|
|
{
|
|
|
- println!("{} {}", url, last_seen);
|
|
|
+ println!("{url} {last_seen}");
|
|
|
}
|
|
|
|
|
|
let entry = hosts.container.fetch_last(HostColor::White).unwrap();
|