weighted: logs

This commit is contained in:
folex 2020-03-27 19:57:05 +03:00
parent 0a4cd14efa
commit 816ccac1ff
3 changed files with 27 additions and 3 deletions

View File

@ -76,7 +76,6 @@ mod weighted;
pub use entry::*;
pub use sub_bucket::*;
use arrayvec::self;
use bucket::KBucket;
use libp2p_core::identity::ed25519::{Keypair, PublicKey};
use std::collections::{VecDeque};

View File

@ -95,6 +95,18 @@ pub enum InsertResult<TKey> {
Full,
}
impl<Key> std::fmt::Display for InsertResult<Key> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let descritpion = match self {
InsertResult::Inserted => "InsertResult::Inserted",
InsertResult::Pending { .. } => "InsertResult::Pending",
InsertResult::Full => "InsertResult::Full",
};
write!(f, "{}", descritpion)
}
}
/// The result of applying a pending node to a bucket, possibly
/// replacing an existing node.
#[derive(Debug, Clone, PartialEq, Eq)]
@ -213,11 +225,23 @@ where
/// the new node is added as the last element of the bucket.
///
pub fn insert(&mut self, node: Node<TKey, TVal>, status: NodeStatus) -> InsertResult<TKey> {
if node.weight > 0 {
let peer_id = bs58::encode(node.key.as_ref()).into_string();
let weight = node.weight;
let result = if node.weight > 0 {
self.weighted.insert(node, status)
} else {
self.swamp.insert(node, status)
}
};
println!(
"Bucket: inserting node {} weight {} -> {}",
peer_id,
weight,
result
);
result
}
fn is_full(&self, weighted: bool) -> bool {

View File

@ -318,6 +318,7 @@ where
keys.into_iter()
.map(move |w| {
println!("Weighted: iterating through {} weight", w);
map.get(&w)
.into_iter()
.map(|bucket| bucket.iter().map(|(n, s)| (&n.inner, s)))