Skip to content

Commit

Permalink
chore: dial instead of add into RT
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Dec 13, 2024
1 parent a683c81 commit bf5c5cb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion ant-networking/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}
Expand Down
17 changes: 15 additions & 2 deletions autonomi/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Client {
}

pub async fn init_with_config(config: ClientConfig) -> Result<Self, ant_bootstrap::Error> {
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,
Expand Down Expand Up @@ -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(),
})
}

Expand Down

0 comments on commit bf5c5cb

Please sign in to comment.