Skip to content

Commit

Permalink
Merge pull request #2250 from subspace/use-bootstrap-nodes-for-probin…
Browse files Browse the repository at this point in the history
…g-too

Use bootstrap nodes for probing too alongside connected peers
  • Loading branch information
nazar-pc authored Nov 20, 2023
2 parents 55e84ec + 3a16647 commit 010abcf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions crates/subspace-networking/src/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ where
..Default::default()
},
local_peer_id,
servers: bootstrap_addresses.clone(),
},
});

Expand Down
28 changes: 20 additions & 8 deletions crates/subspace-networking/src/protocols/autonat_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,39 @@ use tracing::debug;
pub(crate) struct Config {
pub(crate) inner_config: AutonatConfig,
pub(crate) local_peer_id: PeerId,
pub(crate) servers: Vec<Multiaddr>,
}

pub(crate) struct Behaviour {
inner: Autonat,
config: Config,
private_ips_enabled: bool,
listen_addresses: HashSet<Multiaddr>,
}

impl Behaviour {
pub(crate) fn new(config: Config) -> Self {
let mut inner = Autonat::new(config.local_peer_id, config.inner_config.clone());

for server in config.servers {
let maybe_peer_id = server.iter().find_map(|protocol| {
if let Protocol::P2p(peer_id) = protocol {
Some(peer_id)
} else {
None
}
});
if let Some(peer_id) = maybe_peer_id {
inner.add_server(peer_id, Some(server));
}
}

Self {
inner: Autonat::new(config.local_peer_id, config.inner_config.clone()),
config,
inner,
private_ips_enabled: !config.inner_config.only_global_ips,
listen_addresses: Default::default(),
}
}

fn private_ips_enabled(&self) -> bool {
!self.config.inner_config.only_global_ips
}

fn address_corresponds_to_listening_addresses(&self, addr: &Multiaddr) -> bool {
let Some(candidate_protocol) = addr.iter().find_map(|protocol| match protocol {
udp @ Protocol::Udp(_) => Some(udp),
Expand Down Expand Up @@ -105,7 +117,7 @@ impl NetworkBehaviour for Behaviour {
//TODO: handle listener address change
self.listen_addresses.insert(addr.addr.clone());

if self.private_ips_enabled() || is_global_address_or_dns(addr.addr) {
if self.private_ips_enabled || is_global_address_or_dns(addr.addr) {
self.inner.on_swarm_event(new_listen_addr_event);
} else {
debug!(addr=?addr.addr, "Skipped listening address in AutonatWrapper.");
Expand Down

0 comments on commit 010abcf

Please sign in to comment.