From bf5c5cb5f9dfb7745e68303851877de19ae2ec0d Mon Sep 17 00:00:00 2001 From: qima Date: Fri, 13 Dec 2024 06:54:40 +0800 Subject: [PATCH] chore: dial instead of add into RT --- ant-networking/src/cmd.rs | 7 ++++++- autonomi/src/client/mod.rs | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ant-networking/src/cmd.rs b/ant-networking/src/cmd.rs index 6171fe0114..99e35136d9 100644 --- a/ant-networking/src/cmd.rs +++ b/ant-networking/src/cmd.rs @@ -507,7 +507,12 @@ impl SwarmDriver { NetworkSwarmCmd::AddPeerAddresses { addresses, sender } => { cmd_string = "AddPeerAddresses"; for (peer, addr) in addresses { - let _update = self.swarm.behaviour_mut().kademlia.add_address(&peer, addr); + if let Some(kbucket) = self.swarm.behaviour_mut().kademlia.kbucket(peer) { + let ilog2 = kbucket.range().0.ilog2(); + let peers = self.bootstrap_peers.entry(ilog2).or_default(); + peers.insert(peer); + } + let _ = self.dial(addr); } let _ = sender.send(()); } diff --git a/autonomi/src/client/mod.rs b/autonomi/src/client/mod.rs index 3f9fb81b94..eb3c63a753 100644 --- a/autonomi/src/client/mod.rs +++ b/autonomi/src/client/mod.rs @@ -99,7 +99,7 @@ impl Client { } pub async fn init_with_config(config: ClientConfig) -> Result { - let (network, _event_receiver) = build_client_and_run_swarm(config.local); + let (network, event_receiver) = build_client_and_run_swarm(config.local); let peers_args = PeersArgs { disable_mainnet_contacts: config.local, @@ -129,11 +129,24 @@ impl Client { if peers_with_p2p.len() < peers_len { tracing::warn!("Some bootstrap addresses have no peer ID, skipping them"); } - let _ = network.add_peer_addresses(peers_with_p2p).await; + + let network_clone = network.clone(); + let _handle = ant_networking::target_arch::spawn(async move { + if let Err(err) = network_clone.add_peer_addresses(peers_with_p2p).await { + error!("Failed to add addresses with err: {err:?}"); + } + }); + + let (sender, receiver) = futures::channel::oneshot::channel(); + ant_networking::target_arch::spawn(handle_event_receiver(event_receiver, sender)); + + receiver.await.expect("sender should not close")?; + debug!("Client is connected to the network"); Ok(Self { network, client_event_sender: Arc::new(None), + evm_network: Default::default(), }) }