peer table cleanup
async cleanup
This commit is contained in:
@@ -834,12 +834,42 @@ impl RoutingTable {
|
||||
}
|
||||
|
||||
pub fn get_recent_peers(&self) -> Vec<(DHTKey, RecentPeersEntry)> {
|
||||
let inner = self.inner.read();
|
||||
inner
|
||||
.recent_peers
|
||||
.iter()
|
||||
.map(|(k, v)| (k.clone(), v.clone()))
|
||||
.collect()
|
||||
let mut recent_peers = Vec::new();
|
||||
let mut dead_peers = Vec::new();
|
||||
let mut out = Vec::new();
|
||||
|
||||
// collect all recent peers
|
||||
{
|
||||
let inner = self.inner.read();
|
||||
for (k, _v) in &inner.recent_peers {
|
||||
recent_peers.push(*k);
|
||||
}
|
||||
}
|
||||
|
||||
// look up each node and make sure the connection is still live
|
||||
// (uses same logic as send_data, ensuring last_connection works for UDP)
|
||||
for e in &recent_peers {
|
||||
let mut dead = true;
|
||||
if let Some(nr) = self.lookup_node_ref(*e) {
|
||||
if let Some(last_connection) = nr.last_connection() {
|
||||
out.push((*e, RecentPeersEntry { last_connection }));
|
||||
dead = false;
|
||||
}
|
||||
}
|
||||
if dead {
|
||||
dead_peers.push(e);
|
||||
}
|
||||
}
|
||||
|
||||
// purge dead recent peers
|
||||
{
|
||||
let mut inner = self.inner.write();
|
||||
for d in dead_peers {
|
||||
inner.recent_peers.remove(d);
|
||||
}
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
pub fn touch_recent_peer(&self, node_id: DHTKey, last_connection: ConnectionDescriptor) {
|
||||
|
@@ -299,7 +299,7 @@ impl NodeRef {
|
||||
out
|
||||
}
|
||||
|
||||
pub async fn last_connection(&self) -> Option<ConnectionDescriptor> {
|
||||
pub fn last_connection(&self) -> Option<ConnectionDescriptor> {
|
||||
// Get the last connection and the last time we saw anything with this connection
|
||||
let (last_connection, last_seen) =
|
||||
self.operate(|rti, e| e.last_connection(rti, self.filter.clone()))?;
|
||||
@@ -308,7 +308,7 @@ impl NodeRef {
|
||||
if last_connection.protocol_type().is_connection_oriented() {
|
||||
// Look the connection up in the connection manager and see if it's still there
|
||||
let connection_manager = self.routing_table.network_manager().connection_manager();
|
||||
connection_manager.get_connection(last_connection).await?;
|
||||
connection_manager.get_connection(last_connection)?;
|
||||
} else {
|
||||
// If this is not connection oriented, then we check our last seen time
|
||||
// to see if this mapping has expired (beyond our timeout)
|
||||
|
Reference in New Issue
Block a user