Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
node: only consider onion addresses if onion is configured
Merged fintohaps opened 5 months ago

There is an unfortunate lack of single-responsibility with handling the addresses in our code at the moment. This means that adding addresses to the table, and reading them from the table are spread across the code base.

A couple of places were found to further filter out onion addresses, if the configuration does not have an onion address.

This is a band-aid fix until the point in time where this can better improved.

2 files changed +10 -0 93d2ed8c 45abb881
modified crates/radicle-protocol/src/service.rs
@@ -2490,6 +2490,7 @@ where
                    .filter(|entry| !self.sessions.contains_key(&entry.node))
                    .filter(|entry| !self.config.external_addresses.contains(&entry.address.addr))
                    .filter(|entry| &entry.node != self.nid())
+
                    .filter(|entry| !entry.address.addr.is_onion() || self.config.onion.is_some())
                    .fold(HashMap::new(), |mut acc, entry| {
                        acc.entry(entry.node)
                            .and_modify(|e: &mut Peer| e.addresses.push(entry.address.clone()))
@@ -2606,6 +2607,7 @@ where
            .filter_map(|peer| {
                peer.addresses
                    .into_iter()
+
                    .filter(|ka| !ka.addr.is_onion() || self.config.onion.is_some())
                    .find(|ka| match (ka.last_success, ka.last_attempt) {
                        // If we succeeded the last time we tried, this is a good address.
                        // If it's been long enough that we failed to connect, we also try again.
modified crates/radicle/src/node.rs
@@ -484,6 +484,14 @@ impl Address {
        &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`].
    pub fn port(&self) -> u16 {
        self.0.port