node: Only consider onion addresses if configured
There is an unfortunate lack of single-responsibility with handling the addresses to connect to. This is a band-aid fix until the point in time where this can better improved.
This commit is contained in:
parent
93d2ed8c61
commit
45abb881a3
|
|
@ -2490,6 +2490,7 @@ where
|
||||||
.filter(|entry| !self.sessions.contains_key(&entry.node))
|
.filter(|entry| !self.sessions.contains_key(&entry.node))
|
||||||
.filter(|entry| !self.config.external_addresses.contains(&entry.address.addr))
|
.filter(|entry| !self.config.external_addresses.contains(&entry.address.addr))
|
||||||
.filter(|entry| &entry.node != self.nid())
|
.filter(|entry| &entry.node != self.nid())
|
||||||
|
.filter(|entry| !entry.address.addr.is_onion() || self.config.onion.is_some())
|
||||||
.fold(HashMap::new(), |mut acc, entry| {
|
.fold(HashMap::new(), |mut acc, entry| {
|
||||||
acc.entry(entry.node)
|
acc.entry(entry.node)
|
||||||
.and_modify(|e: &mut Peer| e.addresses.push(entry.address.clone()))
|
.and_modify(|e: &mut Peer| e.addresses.push(entry.address.clone()))
|
||||||
|
|
|
||||||
|
|
@ -484,6 +484,14 @@ impl Address {
|
||||||
&self.0.host
|
&self.0.host
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if the [`HostName`] is a Tor onion address.
|
||||||
|
pub fn is_onion(&self) -> bool {
|
||||||
|
match self.0.host {
|
||||||
|
HostName::Tor(_) => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Return the port number of the [`Address`].
|
/// Return the port number of the [`Address`].
|
||||||
pub fn port(&self) -> u16 {
|
pub fn port(&self) -> u16 {
|
||||||
self.0.port
|
self.0.port
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue