mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-30 19:21:19 +00:00
weighted: logs
This commit is contained in:
parent
0a4cd14efa
commit
816ccac1ff
@ -76,7 +76,6 @@ mod weighted;
|
|||||||
pub use entry::*;
|
pub use entry::*;
|
||||||
pub use sub_bucket::*;
|
pub use sub_bucket::*;
|
||||||
|
|
||||||
use arrayvec::self;
|
|
||||||
use bucket::KBucket;
|
use bucket::KBucket;
|
||||||
use libp2p_core::identity::ed25519::{Keypair, PublicKey};
|
use libp2p_core::identity::ed25519::{Keypair, PublicKey};
|
||||||
use std::collections::{VecDeque};
|
use std::collections::{VecDeque};
|
||||||
|
@ -95,6 +95,18 @@ pub enum InsertResult<TKey> {
|
|||||||
Full,
|
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
|
/// The result of applying a pending node to a bucket, possibly
|
||||||
/// replacing an existing node.
|
/// replacing an existing node.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
@ -213,11 +225,23 @@ where
|
|||||||
/// the new node is added as the last element of the bucket.
|
/// 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> {
|
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)
|
self.weighted.insert(node, status)
|
||||||
} else {
|
} else {
|
||||||
self.swamp.insert(node, status)
|
self.swamp.insert(node, status)
|
||||||
}
|
};
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Bucket: inserting node {} weight {} -> {}",
|
||||||
|
peer_id,
|
||||||
|
weight,
|
||||||
|
result
|
||||||
|
);
|
||||||
|
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_full(&self, weighted: bool) -> bool {
|
fn is_full(&self, weighted: bool) -> bool {
|
||||||
|
@ -318,6 +318,7 @@ where
|
|||||||
|
|
||||||
keys.into_iter()
|
keys.into_iter()
|
||||||
.map(move |w| {
|
.map(move |w| {
|
||||||
|
println!("Weighted: iterating through {} weight", w);
|
||||||
map.get(&w)
|
map.get(&w)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|bucket| bucket.iter().map(|(n, s)| (&n.inner, s)))
|
.map(|bucket| bucket.iter().map(|(n, s)| (&n.inner, s)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user