Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
node: only consider onion addresses if onion is configured
◌ CI pending Fintan Halpenny committed 5 months ago
commit c58eece4d8d2f81c5fc3c4a90c9c28be0d283963
parent 0ec084fc232f0df8c1bbcbb89ce8394e8a81d988
2 pending (2 total) View logs
3 files changed +17 -0
modified crates/radicle-node/src/runtime.rs
@@ -190,11 +190,18 @@ impl Runtime {

        if config.connect.is_empty() && stores.addresses().is_empty()? {
            log::info!(target: "node", "Address book is empty. Adding bootstrap nodes..");
+
            let is_onion_routable = config.onion.is_some();

            for (alias, version, addrs) in config.network.bootstrap() {
                for addr in addrs {
                    let (id, addr) = addr.into();

+
                    // Discard the any of the onion addresses, if the
+
                    // configuration does not support onion addresses
+
                    if !is_onion_routable && addr.is_onion() {
+
                        continue;
+
                    }
+

                    stores.addresses_mut().insert(
                        &id,
                        version,
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