From f530388bfdd4c3d46f42f30e6f2ff1cd9c27035d Mon Sep 17 00:00:00 2001 From: Filip Bozic <70634661+fbozic@users.noreply.github.com> Date: Tue, 21 May 2024 09:52:01 +0200 Subject: [PATCH] feat: replace HashMap with BTreeMap for relays and rendezvous --- examples/chat/src/network.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/chat/src/network.rs b/examples/chat/src/network.rs index e36a208..f4842e9 100644 --- a/examples/chat/src/network.rs +++ b/examples/chat/src/network.rs @@ -1,4 +1,5 @@ use std::collections::hash_map::{self, HashMap}; +use std::collections::BTreeMap; use std::time::Duration; use libp2p::futures::prelude::*; @@ -37,7 +38,7 @@ pub async fn run( relay_addresses: Vec, rendezvous_addresses: Vec, ) -> eyre::Result<(NetworkClient, mpsc::Receiver)> { - let mut rendezvous = HashMap::new(); + let mut rendezvous = BTreeMap::new(); for address in &rendezvous_addresses { let entry = match peek_peer_id(&address) { Ok(peer_id) => (peer_id, RendezvousEntry::new(address.clone())), @@ -48,7 +49,7 @@ pub async fn run( rendezvous.insert(entry.0, entry.1); } - let mut relays = HashMap::new(); + let mut relays = BTreeMap::new(); for address in &relay_addresses { let entry = match peek_peer_id(&address) { Ok(peer_id) => (peer_id, RelayEntry::new(address.clone())), @@ -105,9 +106,9 @@ async fn run_init_dial( async fn init( keypair: identity::Keypair, - relays: HashMap, + relays: BTreeMap, rendezvous_namespace: rendezvous::Namespace, - rendezvous: HashMap, + rendezvous: BTreeMap, ) -> eyre::Result<( NetworkClient, mpsc::Receiver, @@ -166,9 +167,9 @@ pub(crate) struct EventLoop { swarm: Swarm, command_receiver: mpsc::Receiver, event_sender: mpsc::Sender, - relays: HashMap, + relays: BTreeMap, rendezvous_namespace: rendezvous::Namespace, - rendezvous: HashMap, + rendezvous: BTreeMap, pending_dial: HashMap>>>, } @@ -231,9 +232,9 @@ impl EventLoop { swarm: Swarm, command_receiver: mpsc::Receiver, event_sender: mpsc::Sender, - relays: HashMap, + relays: BTreeMap, rendezvous_namespace: rendezvous::Namespace, - rendezvous: HashMap, + rendezvous: BTreeMap, ) -> Self { Self { swarm,