DHT stats

This commit is contained in:
Igor Katson 2021-07-14 00:48:53 +01:00
parent 4e31eb6547
commit fe4dcb226f
4 changed files with 140 additions and 101 deletions

View file

@ -6,13 +6,13 @@ use std::{
use librqbit_core::id20::Id20;
use log::debug;
#[derive(Debug)]
#[derive(Debug, Clone)]
enum BucketTreeNode {
Leaf(Vec<RoutingTableNode>),
LeftRight(Box<BucketTree>, Box<BucketTree>),
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct BucketTree {
bits: u8,
start: Id20,
@ -302,7 +302,7 @@ impl Default for BucketTree {
}
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct RoutingTableNode {
id: Id20,
addr: SocketAddr,
@ -356,7 +356,7 @@ impl RoutingTableNode {
}
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct RoutingTable {
id: Id20,
size: usize,
@ -371,6 +371,9 @@ impl RoutingTable {
size: 0,
}
}
pub fn len(&self) -> usize {
self.size
}
pub fn sorted_by_distance_from(&self, id: Id20) -> Vec<&RoutingTableNode> {
let mut result = Vec::with_capacity(self.size);
for node in self.buckets.iter() {