Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
protocol: ensure `connect` supports connecting address
✗ CI failure Fintan Halpenny committed 3 months ago
commit 090caf39eb5cf58c08989186ef3850cdd3ab94e0
parent 44f75abfc039f020415502ad7193343829d2e6bc
1 failed (1 total) View logs
1 file changed +25 -6
modified crates/radicle-protocol/src/service.rs
@@ -221,6 +221,8 @@ pub enum ConnectError {
    SelfConnection,
    #[error("outbound connection limit reached when attempting {nid} ({addr})")]
    LimitReached { nid: NodeId, addr: Address },
+
    #[error("attempted connection to {nid}, but the node is not configured to support the address {addr}")]
+
    UnsupportedAddress { nid: NodeId, addr: Address },
}

/// A store for all node data.
@@ -2254,6 +2256,9 @@ where
        if nid == self.node_id() {
            return Err(ConnectError::SelfConnection);
        }
+
        if !self.is_supported_address(&addr) {
+
            return Err(ConnectError::UnsupportedAddress { nid, addr });
+
        }
        if self.sessions.contains_key(&nid) {
            return Err(ConnectError::SessionExists { nid });
        }
@@ -2492,7 +2497,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())
+
                    .filter(|entry| self.is_supported_address(&entry.address.addr))
                    .fold(HashMap::new(), |mut acc, entry| {
                        acc.entry(entry.node)
                            .and_modify(|e: &mut Peer| e.addresses.push(entry.address.clone()))
@@ -2630,11 +2635,7 @@ where
                    })
                    .map(|ka| (peer.nid, ka))
            })
-
            .filter(|(_, ka)| match AddressType::from(&ka.addr) {
-
                // Only consider onion addresses if configured.
-
                AddressType::Onion => self.config.onion.is_some(),
-
                AddressType::Dns | AddressType::Ipv4 | AddressType::Ipv6 => true,
-
            });
+
            .filter(|(_, ka)| self.is_supported_address(&ka.addr));

        // Peers we are going to attempt connections to.
        let connect = available.take(wanted).collect::<Vec<_>>();
@@ -2678,6 +2679,24 @@ where
            }
        }
    }
+

+
    /// Checks if the [`Address`] supported for connecting to.
+
    ///
+
    /// # IPv4/IPv6/DNS
+
    ///
+
    /// Always returns `true`.
+
    ///
+
    /// # Tor
+
    ///
+
    /// If the [`Address`] is an `.onion` address and the service supports onion
+
    /// routing then this will return `true`.
+
    fn is_supported_address(&self, address: &Address) -> bool {
+
        match AddressType::from(address) {
+
            // Only consider onion addresses if configured.
+
            AddressType::Onion => self.config.onion.is_some(),
+
            AddressType::Dns | AddressType::Ipv4 | AddressType::Ipv6 => true,
+
        }
+
    }
}

/// Gives read access to the service state.