mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-29 09:41:34 +00:00
Sort weighted bucket iter() by weight
This commit is contained in:
@ -74,7 +74,7 @@ fn build_nodes_with_config(num: usize, cfg: KademliaConfig) -> (u64, Vec<(ed2551
|
|||||||
|
|
||||||
let local_id = local_public_key.clone().into_peer_id();
|
let local_id = local_public_key.clone().into_peer_id();
|
||||||
let store = MemoryStore::new(local_id.clone());
|
let store = MemoryStore::new(local_id.clone());
|
||||||
let trust = TrustGraph::new(HashMap::new());
|
let trust = TrustGraph::new(Vec::new());
|
||||||
let behaviour = Kademlia::with_config(ed25519_key.clone(), local_id.clone(), store, cfg.clone(), trust);
|
let behaviour = Kademlia::with_config(ed25519_key.clone(), local_id.clone(), store, cfg.clone(), trust);
|
||||||
result.push((ed25519_key, Swarm::new(transport, behaviour, local_id)));
|
result.push((ed25519_key, Swarm::new(transport, behaviour, local_id)));
|
||||||
}
|
}
|
||||||
|
@ -178,12 +178,6 @@ where
|
|||||||
/// the node that was replaced. `None` indicates that the nodes in the
|
/// the node that was replaced. `None` indicates that the nodes in the
|
||||||
/// bucket remained unchanged.
|
/// bucket remained unchanged.
|
||||||
pub fn apply_pending(&mut self) -> Vec<AppliedPending<TKey, TVal>> {
|
pub fn apply_pending(&mut self) -> Vec<AppliedPending<TKey, TVal>> {
|
||||||
// self.weighted
|
|
||||||
// .apply_pending()
|
|
||||||
// .iter()
|
|
||||||
// .chain(self.swamp.apply_pending().iter())
|
|
||||||
// .collect()
|
|
||||||
|
|
||||||
Iterator::chain(
|
Iterator::chain(
|
||||||
self.weighted.apply_pending().into_iter(),
|
self.weighted.apply_pending().into_iter(),
|
||||||
self.swamp.apply_pending().into_iter(),
|
self.swamp.apply_pending().into_iter(),
|
||||||
|
@ -311,11 +311,19 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter(&self) -> impl Iterator<Item = (&Node<TKey, TVal>, NodeStatus)> {
|
pub fn iter(&self) -> impl Iterator<Item = (&Node<TKey, TVal>, NodeStatus)> + '_ {
|
||||||
self.map
|
let mut keys = self.map.keys().collect::<Vec<_>>();
|
||||||
.values()
|
keys.sort();
|
||||||
|
let map: &HashMap<u32, _> = &self.map;
|
||||||
|
|
||||||
|
keys.into_iter()
|
||||||
|
.map(move |w| {
|
||||||
|
map.get(&w)
|
||||||
|
.into_iter()
|
||||||
.map(|bucket| bucket.iter().map(|(n, s)| (&n.inner, s)))
|
.map(|bucket| bucket.iter().map(|(n, s)| (&n.inner, s)))
|
||||||
.flatten()
|
.flatten()
|
||||||
|
})
|
||||||
|
.flatten()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn status(&self, key: &TKey) -> Option<NodeStatus> {
|
pub fn status(&self, key: &TKey) -> Option<NodeStatus> {
|
||||||
|
Reference in New Issue
Block a user