network fixes
This commit is contained in:
@@ -19,12 +19,18 @@ impl RoutingTable {
|
||||
// Get counts by crypto kind
|
||||
let entry_count = self.inner.read().cached_entry_counts();
|
||||
|
||||
let min_peer_count = self.with_config(|c| c.network.dht.min_peer_count as usize);
|
||||
let (min_peer_count, min_peer_refresh_time_ms) = self.with_config(|c| {
|
||||
(
|
||||
c.network.dht.min_peer_count as usize,
|
||||
c.network.dht.min_peer_refresh_time_ms,
|
||||
)
|
||||
});
|
||||
|
||||
// For the PublicInternet routing domain, get list of all peers we know about
|
||||
// even the unreliable ones, and ask them to find nodes close to our node too
|
||||
|
||||
let mut ord = FuturesOrdered::new();
|
||||
let cur_ts = get_timestamp();
|
||||
|
||||
for crypto_kind in VALID_CRYPTO_KINDS {
|
||||
// Do we need to peer minimum refresh this crypto kind?
|
||||
@@ -37,16 +43,26 @@ impl RoutingTable {
|
||||
}
|
||||
|
||||
let routing_table = self.clone();
|
||||
|
||||
let mut filters = VecDeque::new();
|
||||
let filter = Box::new(
|
||||
move |_rti: &RoutingTableInner, opt_entry: Option<Arc<BucketEntry>>| {
|
||||
// Keep only the entries that contain the crypto kind we're looking for
|
||||
if let Some(entry) = opt_entry {
|
||||
entry.with_inner(|e| e.crypto_kinds().contains(&crypto_kind))
|
||||
} else {
|
||||
VALID_CRYPTO_KINDS.contains(&crypto_kind)
|
||||
}
|
||||
move |rti: &RoutingTableInner, opt_entry: Option<Arc<BucketEntry>>| {
|
||||
let entry = opt_entry.unwrap().clone();
|
||||
entry.with(rti, |_rti, e| {
|
||||
// Keep only the entries that contain the crypto kind we're looking for
|
||||
let compatible_crypto = e.crypto_kinds().contains(&crypto_kind);
|
||||
if !compatible_crypto {
|
||||
return false;
|
||||
}
|
||||
// Keep only the entries we haven't talked to in the min_peer_refresh_time
|
||||
if let Some(last_q_ts) = e.peer_stats().rpc_stats.last_question_ts {
|
||||
if cur_ts.saturating_sub(last_q_ts.as_u64())
|
||||
< (min_peer_refresh_time_ms as u64 * 1_000u64)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
})
|
||||
},
|
||||
) as RoutingTableEntryFilter;
|
||||
filters.push_front(filter);
|
||||
|
Reference in New Issue
Block a user