Skip to content

Commit

Permalink
refactor(autonomi): dial instead of add to RT
Browse files Browse the repository at this point in the history
  • Loading branch information
b-zee committed Dec 16, 2024
1 parent a3ed778 commit a418909
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions autonomi/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub use ant_evm::Amount;
use ant_evm::EvmNetwork;
use ant_networking::{interval, multiaddr_is_global, Network, NetworkBuilder, NetworkEvent};
use ant_protocol::{version::IDENTIFY_PROTOCOL_STR, CLOSE_GROUP_SIZE};
use libp2p::{identity::Keypair, multiaddr::Protocol, Multiaddr};
use libp2p::{identity::Keypair, Multiaddr};
use std::{collections::HashSet, sync::Arc, time::Duration};
use tokio::sync::mpsc;

Expand Down Expand Up @@ -103,33 +103,25 @@ impl Client {

let peers_args = PeersArgs {
disable_mainnet_contacts: config.local,
addrs: config.peers.unwrap_or_default(),
..Default::default()
};

let peers = if let Some(peers) = config.peers {
peers
} else {
match peers_args.get_addrs(None, None).await {
Ok(peers) => peers,
Err(e) => return Err(e),
}
let peers = match peers_args.get_addrs(None, None).await {
Ok(peers) => peers,
Err(e) => return Err(e),
};

let peers_len = peers.len();
// Add peers to the routing table.
let peers_with_p2p: Vec<_> = peers
.into_iter()
.filter_map(|addr| {
addr.iter().find_map(|p| match p {
Protocol::P2p(id) => Some((id, addr.clone())),
_ => None,
})
})
.collect();
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 peers = peers.to_vec();
let _handle = ant_networking::target_arch::spawn(async move {
for addr in peers {
if let Err(err) = network_clone.dial(addr.clone()).await {
error!("Failed to dial addr={addr} with err: {err:?}");
eprintln!("addr={addr} Failed to dial: {err:?}");
};
}
});

Ok(Self {
network,
Expand Down

0 comments on commit a418909

Please sign in to comment.