With pinger its not entirely bad now, but still pretty horrible
This commit is contained in:
parent
8d58a9f419
commit
fee2690aae
2 changed files with 49 additions and 59 deletions
|
|
@ -348,15 +348,9 @@ impl BucketTree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn add_node(
|
||||
&mut self,
|
||||
self_id: &Id20,
|
||||
id: Id20,
|
||||
addr: SocketAddr,
|
||||
on_questionable_node: impl FnMut(Id20, SocketAddr) -> bool,
|
||||
) -> InsertResult {
|
||||
pub fn add_node(&mut self, self_id: &Id20, id: Id20, addr: SocketAddr) -> InsertResult {
|
||||
let idx = self.get_leaf(&id);
|
||||
self.insert_into_leaf(idx, self_id, id, addr, on_questionable_node)
|
||||
self.insert_into_leaf(idx, self_id, id, addr)
|
||||
}
|
||||
fn insert_into_leaf(
|
||||
&mut self,
|
||||
|
|
@ -364,7 +358,6 @@ impl BucketTree {
|
|||
self_id: &Id20,
|
||||
id: Id20,
|
||||
addr: SocketAddr,
|
||||
mut on_questionable_node: impl FnMut(Id20, SocketAddr) -> bool,
|
||||
) -> InsertResult {
|
||||
// The loop here is for this case:
|
||||
// in case we split a node into two, and it degenerates into all the leaves
|
||||
|
|
@ -399,17 +392,6 @@ impl BucketTree {
|
|||
return InsertResult::Added;
|
||||
}
|
||||
|
||||
// Ping first questionable node
|
||||
if let Some(questionable_node) = nodes
|
||||
.nodes
|
||||
.iter_mut()
|
||||
.find(|r| matches!(r.status(), NodeStatus::Questionable))
|
||||
{
|
||||
if on_questionable_node(questionable_node.id, questionable_node.addr) {
|
||||
questionable_node.mark_outgoing_request();
|
||||
}
|
||||
}
|
||||
|
||||
// Try replace a bad node
|
||||
if let Some(bad_node) = nodes
|
||||
.nodes
|
||||
|
|
@ -633,15 +615,12 @@ impl RoutingTable {
|
|||
self.buckets.iter_leaves()
|
||||
}
|
||||
|
||||
pub fn add_node(
|
||||
&mut self,
|
||||
id: Id20,
|
||||
addr: SocketAddr,
|
||||
on_questionable_node: impl FnMut(Id20, SocketAddr) -> bool,
|
||||
) -> InsertResult {
|
||||
let res = self
|
||||
.buckets
|
||||
.add_node(&self.id, id, addr, on_questionable_node);
|
||||
pub fn iter(&self) -> impl Iterator<Item = &'_ RoutingTableNode> + '_ {
|
||||
self.buckets.iter()
|
||||
}
|
||||
|
||||
pub fn add_node(&mut self, id: Id20, addr: SocketAddr) -> InsertResult {
|
||||
let res = self.buckets.add_node(&self.id, id, addr);
|
||||
let replaced = match &res {
|
||||
InsertResult::WasExisting => false,
|
||||
InsertResult::ReplacedBad(..) => true,
|
||||
|
|
@ -782,7 +761,7 @@ mod tests {
|
|||
for _ in 0..length.unwrap_or(16536) {
|
||||
let other_id = random_id_20();
|
||||
let addr = generate_socket_addr();
|
||||
rtable.add_node(other_id, addr, |_, _| false);
|
||||
rtable.add_node(other_id, addr);
|
||||
}
|
||||
rtable
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue