This commit is contained in:
John Smith
2022-03-26 21:25:24 -04:00
parent cc715dfc96
commit 53cd521ba8
11 changed files with 232 additions and 101 deletions
@@ -65,6 +65,13 @@ impl BucketEntry {
self.dial_infos.sort();
}
pub fn update_single_dial_info(&mut self, dial_info: &DialInfo) {
let dif = dial_info.make_filter(true);
self.dial_infos.retain(|di| !di.matches_filter(&dif));
self.dial_infos.push(dial_info.clone());
self.dial_infos.sort();
}
pub fn first_filtered_dial_info<F>(&self, filter: F) -> Option<DialInfo>
where
F: Fn(&DialInfo) -> bool,
@@ -189,7 +196,7 @@ impl BucketEntry {
state = BucketEntryState::Unreliable;
}
match self.state(cur_ts) {
match state {
BucketEntryState::Reliable => {
// If we are in a reliable state, we need a ping on an exponential scale
match self.peer_stats.ping_stats.last_pinged {
+25 -3
View File
@@ -263,7 +263,7 @@ impl RoutingTable {
fn trigger_changed_dial_info(inner: &mut RoutingTableInner) {
// Clear 'seen dial info' bits on routing table entries so we know to ping them
for b in inner.buckets {
for b in &mut inner.buckets {
for e in b.entries_mut() {
e.1.set_seen_our_dial_info(false);
}
@@ -451,6 +451,21 @@ impl RoutingTable {
Ok(nr)
}
// Add a node if it doesn't exist, or update a single dial info on an already registered node
pub fn update_node_with_single_dial_info(
&self,
node_id: DHTKey,
dial_info: &DialInfo,
) -> Result<NodeRef, String> {
let nr = self.create_node_ref(node_id)?;
nr.operate(move |e| -> Result<(), String> {
e.update_single_dial_info(dial_info);
Ok(())
})?;
Ok(nr)
}
fn operate_on_bucket_entry<T, F>(&self, node_id: DHTKey, f: F) -> T
where
F: FnOnce(&mut BucketEntry) -> T,
@@ -484,8 +499,15 @@ impl RoutingTable {
);
// register nodes we'd found
let mut out = Vec::<NodeRef>::with_capacity(res.peers.len());
for p in res.peers {
self.register_find_node_answer(res)
}
pub fn register_find_node_answer(&self, fna: FindNodeAnswer) -> Result<Vec<NodeRef>, String> {
let node_id = self.node_id();
// register nodes we'd found
let mut out = Vec::<NodeRef>::with_capacity(fna.peers.len());
for p in fna.peers {
// if our own node if is in the list then ignore it, as we don't add ourselves to our own routing table
if p.node_id.key == node_id {
continue;
@@ -48,11 +48,9 @@ impl NodeRef {
// Returns if this node has seen and acknowledged our node's dial info yet
pub fn has_seen_our_dial_info(&self) -> bool {
let nm = self.routing_table.network_manager();
self.operate(|e| e.has_seen_our_dial_info())
}
pub fn set_seen_our_dial_info(&self) {
let nm = self.routing_table.network_manager();
self.operate(|e| e.set_seen_our_dial_info(true));
}