Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
I2P Support
✗ CI failure Lorenz Leutgeb committed 2 months ago
commit 4919ad36064a99e4be9e6efdd1e7d0352d3e9b65
parent 550d153bbccb827c04b296512e0f8a8e24971873
1 failed (1 total) View logs
16 files changed +155 -36
modified Cargo.lock
@@ -673,7 +673,7 @@ dependencies = [
[[package]]
name = "cypheraddr"
version = "0.4.0"
-
source = "git+https://github.com/cyphernet-labs/cyphernet.rs?rev=888ee2a3468c8bbfdc868238fd67505401aa0ee4#888ee2a3468c8bbfdc868238fd67505401aa0ee4"
+
source = "git+https://github.com/lorenzleutgeb/cyphernet.rs.git?branch=push-ooltwtzkpvlk#ca0fedcac9f1075d516ce1f0129f4aa9b73ee81e"
dependencies = [
 "amplify",
 "base32",
@@ -684,7 +684,7 @@ dependencies = [
[[package]]
name = "cyphergraphy"
version = "0.3.0"
-
source = "git+https://github.com/cyphernet-labs/cyphernet.rs?rev=888ee2a3468c8bbfdc868238fd67505401aa0ee4#888ee2a3468c8bbfdc868238fd67505401aa0ee4"
+
source = "git+https://github.com/lorenzleutgeb/cyphernet.rs.git?branch=push-ooltwtzkpvlk#ca0fedcac9f1075d516ce1f0129f4aa9b73ee81e"
dependencies = [
 "amplify",
 "ec25519",
@@ -694,7 +694,7 @@ dependencies = [
[[package]]
name = "cyphernet"
version = "0.5.2"
-
source = "git+https://github.com/cyphernet-labs/cyphernet.rs?rev=888ee2a3468c8bbfdc868238fd67505401aa0ee4#888ee2a3468c8bbfdc868238fd67505401aa0ee4"
+
source = "git+https://github.com/lorenzleutgeb/cyphernet.rs.git?branch=push-ooltwtzkpvlk#ca0fedcac9f1075d516ce1f0129f4aa9b73ee81e"
dependencies = [
 "cypheraddr",
 "cyphergraphy",
@@ -2289,7 +2289,7 @@ dependencies = [
[[package]]
name = "noise-framework"
version = "0.4.0"
-
source = "git+https://github.com/cyphernet-labs/cyphernet.rs?rev=888ee2a3468c8bbfdc868238fd67505401aa0ee4#888ee2a3468c8bbfdc868238fd67505401aa0ee4"
+
source = "git+https://github.com/lorenzleutgeb/cyphernet.rs.git?branch=push-ooltwtzkpvlk#ca0fedcac9f1075d516ce1f0129f4aa9b73ee81e"
dependencies = [
 "amplify",
 "chacha20poly1305",
@@ -3794,7 +3794,7 @@ dependencies = [
[[package]]
name = "socks5-client"
version = "0.4.1"
-
source = "git+https://github.com/cyphernet-labs/cyphernet.rs?rev=888ee2a3468c8bbfdc868238fd67505401aa0ee4#888ee2a3468c8bbfdc868238fd67505401aa0ee4"
+
source = "git+https://github.com/lorenzleutgeb/cyphernet.rs.git?branch=push-ooltwtzkpvlk#ca0fedcac9f1075d516ce1f0129f4aa9b73ee81e"
dependencies = [
 "amplify",
 "cypheraddr",
modified Cargo.toml
@@ -98,4 +98,5 @@ debug = true
incremental = false

[patch.crates-io]
-
cyphernet.git = "https://github.com/cyphernet-labs/cyphernet.rs?rev=888ee2a3468c8bbfdc868238fd67505401aa0ee4"
+
cyphernet = { git = "https://github.com/lorenzleutgeb/cyphernet.rs.git", branch = "push-ooltwtzkpvlk" }
+
cypheraddr = { git = "https://github.com/lorenzleutgeb/cyphernet.rs.git", branch = "push-ooltwtzkpvlk" }
modified crates/radicle-cli/Cargo.toml
@@ -14,7 +14,8 @@ name = "rad"
path = "src/main.rs"

[features]
-
default = ["tor"]
+
default = ["i2p", "tor"]
+
i2p = ["radicle/i2p"]
tor = ["radicle/tor"]

[dependencies]
modified crates/radicle-cli/src/terminal/format.rs
@@ -47,6 +47,11 @@ pub fn addr_compact(address: &Address) -> Paint<String> {
                .collect::<String>();
            format!("{start}…{end}")
        }
+
        #[cfg(feature = "i2p")]
+
        HostName::I2p(i2p) => {
+
            // TODO: Base32 addresses can be shortened like onion addresses.
+
            i2p.to_string()
+
        }
        _ => unreachable!(),
    };

modified crates/radicle-node/Cargo.toml
@@ -10,7 +10,8 @@ build = "build.rs"
rust-version.workspace = true

[features]
-
default = ["backtrace", "systemd", "structured-logger", "socket2", "tor"]
+
default = ["backtrace", "i2p", "systemd", "structured-logger", "socket2", "tor"]
+
i2p = ["cyphernet/i2p", "radicle/i2p", "radicle-protocol/i2p"]
systemd = ["dep:radicle-systemd"]
test = ["radicle/test", "radicle-crypto/test", "radicle-crypto/cyphernet", "radicle-protocol/test", "qcheck", "snapbox"]
tor = ["cyphernet/tor", "radicle/tor", "radicle-protocol/tor"]
modified crates/radicle-node/src/wire.rs
@@ -19,7 +19,7 @@ use radicle::node::device::Device;

use radicle::collections::{RandomMap, RandomSet};
use radicle::crypto;
-
#[cfg(feature = "tor")]
+
#[cfg(any(feature = "tor", feature = "i2p"))]
use radicle::node::config::AddressConfig;
use radicle::node::Link;
use radicle::node::NodeId;
@@ -1084,6 +1084,30 @@ pub fn dial<G: Ecdh<Pk = NodeId>>(
    signer: G,
    config: &radicle::node::Config,
) -> io::Result<WireSession<G>> {
+
    #[cfg(any(feature = "tor", feature = "i2p"))]
+
    fn proxy_or_forward<H: std::fmt::Display>(
+
        config: &AddressConfig,
+
        global_proxy: Option<net::SocketAddr>,
+
        host: H,
+
        port: u16,
+
    ) -> io::Result<NetAddr<InetHost>> {
+
        match config {
+
            // In proxy mode, simply use the configured proxy address.
+
            // This takes precedence over any global proxy.
+
            AddressConfig::Proxy { address } => Ok((*address).into()),
+
            // In "forward" mode, if a global proxy is set, we use that, otherwise
+
            // we treat the address as a regular DNS name.
+
            AddressConfig::Forward => Ok(global_proxy
+
                .map(Into::into)
+
                .unwrap_or_else(|| NetAddr::new(InetHost::Dns(host.to_string()), port))),
+
            // If address type support isn't configured, refuse to connect.
+
            AddressConfig::Drop => Err(io::Error::new(
+
                io::ErrorKind::Unsupported,
+
                "no configuration found for address type",
+
            )),
+
        }
+
    }
+

    // Determine what address to establish a TCP connection with, given the remote peer
    // address and our node configuration.
    let inet_addr: NetAddr<InetHost> = match (&remote_addr.host, config.proxy) {
@@ -1094,27 +1118,11 @@ pub fn dial<G: Ecdh<Pk = NodeId>>(
        (HostName::Dns(dns), None) => NetAddr::new(InetHost::Dns(dns.clone()), remote_addr.port),
        // For onion addresses, handle with care.
        #[cfg(feature = "tor")]
-
        (HostName::Tor(onion), proxy) => match config.onion {
-
            // In onion proxy mode, simply use the configured proxy address.
-
            // This takes precedence over any global proxy.
-
            AddressConfig::Proxy { address } => address.into(),
-
            // In "forward" mode, if a global proxy is set, we use that, otherwise
-
            // we treat `.onion` addresses as regular DNS names.
-
            AddressConfig::Forward => {
-
                if let Some(proxy) = proxy {
-
                    proxy.into()
-
                } else {
-
                    NetAddr::new(InetHost::Dns(onion.to_string()), remote_addr.port)
-
                }
-
            }
-
            // If onion address support isn't configured, refuse to connect.
-
            AddressConfig::Drop => {
-
                return Err(io::Error::new(
-
                    io::ErrorKind::Unsupported,
-
                    "no configuration found for .onion addresses",
-
                ));
-
            }
-
        },
+
        (HostName::Tor(onion), proxy) => {
+
            proxy_or_forward(&config.onion, proxy, onion, remote_addr.port)?
+
        }
+
        #[cfg(feature = "i2p")]
+
        (HostName::I2p(i2p), proxy) => proxy_or_forward(&config.i2p, proxy, i2p, remote_addr.port)?,
        _ => {
            return Err(io::Error::new(
                io::ErrorKind::Unsupported,
modified crates/radicle-protocol/Cargo.toml
@@ -9,6 +9,7 @@ edition.workspace = true
rust-version.workspace = true

[features]
+
i2p = ["cyphernet/i2p"]
test = ["radicle/test", "radicle-crypto/test", "radicle-crypto/cyphernet", "qcheck"]
tor = ["cyphernet/tor"]

@@ -36,4 +37,4 @@ paste = "1.0.15"
qcheck = { workspace = true }
qcheck-macros = { workspace = true }
radicle = { workspace = true, features = ["test"] }
-
radicle-crypto = { workspace = true, features = ["test", "cyphernet"] }
+
radicle-crypto = { workspace = true, features = ["test", "cyphernet"] }

\ No newline at end of file
modified crates/radicle-protocol/src/service.rs
@@ -2627,11 +2627,18 @@ where
    ///
    /// If the [`Address`] is an `.onion` address and the service supports onion
    /// routing then this will return `true`.
+
    ///
+
    /// # I2P
+
    ///
+
    /// If the [`Address`] is an I2P address and the service supports I2P
+
    /// connections then this will return `true`.
    fn is_supported_address(&self, address: &Address) -> bool {
        match AddressType::from(address) {
            // Only consider onion addresses if configured.
            #[cfg(feature = "tor")]
            AddressType::Onion => self.config.onion != AddressConfig::Drop,
+
            #[cfg(feature = "i2p")]
+
            AddressType::I2p => self.config.i2p != AddressConfig::Drop,
            AddressType::Dns | AddressType::Ipv4 | AddressType::Ipv6 => true,
        }
    }
modified crates/radicle-protocol/src/wire.rs
@@ -15,6 +15,8 @@ use std::string::FromUtf8Error;

use bytes::{Buf, BufMut};

+
#[cfg(feature = "i2p")]
+
use cyphernet::addr::i2p;
#[cfg(feature = "tor")]
use cyphernet::addr::tor;

@@ -62,6 +64,9 @@ pub enum Invalid {
    #[cfg(feature = "tor")]
    #[error("invalid onion address: {0}")]
    OnionAddr(#[from] tor::OnionAddrDecodeError),
+
    #[cfg(feature = "i2p")]
+
    #[error("invalid i2p address: {0}")]
+
    I2pAddr(#[from] i2p::I2pAddrParseError),
    #[error("invalid timestamp: {actual_millis} millis")]
    Timestamp { actual_millis: u64 },

@@ -266,6 +271,13 @@ impl Encode for cyphernet::addr::tor::OnionAddrV3 {
    }
}

+
#[cfg(feature = "i2p")]
+
impl Encode for i2p::I2pAddr {
+
    fn encode(&self, buf: &mut impl BufMut) {
+
        self.to_string().encode(buf)
+
    }
+
}
+

impl Encode for UserAgent {
    fn encode(&self, buf: &mut impl BufMut) {
        self.as_ref().encode(buf)
@@ -549,6 +561,16 @@ impl Decode for tor::OnionAddrV3 {
    }
}

+
#[cfg(feature = "i2p")]
+
impl Decode for i2p::I2pAddr {
+
    fn decode(buf: &mut impl Buf) -> Result<Self, Error> {
+
        let s = String::decode(buf)?;
+
        let addr = i2p::I2pAddr::from_str(&s).map_err(Invalid::from)?;
+

+
        Ok(addr)
+
    }
+
}
+

impl Encode for Timestamp {
    fn encode(&self, buf: &mut impl BufMut) {
        self.deref().encode(buf)
modified crates/radicle-protocol/src/wire/message.rs
@@ -2,6 +2,8 @@ use std::{mem, net};

use bytes::Buf;
use bytes::BufMut;
+
#[cfg(feature = "i2p")]
+
use cyphernet::addr::i2p;
#[cfg(feature = "tor")]
use cyphernet::addr::tor;
use cyphernet::addr::{HostName, NetAddr};
@@ -83,6 +85,8 @@ pub enum AddressType {
    Dns = 3,
    #[cfg(feature = "tor")]
    Onion = 4,
+
    #[cfg(feature = "i2p")]
+
    I2p = 5,
}

impl From<AddressType> for u8 {
@@ -99,6 +103,8 @@ impl From<&Address> for AddressType {
            HostName::Dns(_) => AddressType::Dns,
            #[cfg(feature = "tor")]
            HostName::Tor(_) => AddressType::Onion,
+
            #[cfg(feature = "i2p")]
+
            HostName::I2p(_) => AddressType::I2p,
            _ => todo!(), // FIXME(cloudhead): Maxim will remove `non-exhaustive`
        }
    }
@@ -114,6 +120,8 @@ impl TryFrom<u8> for AddressType {
            3 => Ok(AddressType::Dns),
            #[cfg(feature = "tor")]
            4 => Ok(AddressType::Onion),
+
            #[cfg(feature = "i2p")]
+
            5 => Ok(AddressType::I2p),
            _ => Err(other),
        }
    }
@@ -348,7 +356,7 @@ impl wire::Decode for Message {

impl wire::Encode for Address {
    fn encode(&self, buf: &mut impl BufMut) {
-
        match self.host {
+
        match &self.host {
            HostName::Ip(net::IpAddr::V4(ip)) => {
                u8::from(AddressType::Ipv4).encode(buf);
                ip.octets().encode(buf);
@@ -366,6 +374,11 @@ impl wire::Encode for Address {
                u8::from(AddressType::Onion).encode(buf);
                addr.encode(buf);
            }
+
            #[cfg(feature = "i2p")]
+
            HostName::I2p(addr) => {
+
                u8::from(AddressType::I2p).encode(buf);
+
                addr.encode(buf);
+
            }
            _ => {
                unimplemented!(
                    "Encoding not defined for addresses of the same type as the following: {:?}",
@@ -405,6 +418,12 @@ impl wire::Decode for Address {

                HostName::Tor(onion)
            }
+
            #[cfg(feature = "i2p")]
+
            Ok(AddressType::I2p) => {
+
                let i2p: i2p::I2pAddr = wire::Decode::decode(buf)?;
+

+
                HostName::I2p(i2p)
+
            }
            Err(other) => return Err(wire::Invalid::AddressType { actual: other }.into()),
        };
        let port = u16::decode(buf)?;
modified crates/radicle/Cargo.toml
@@ -11,6 +11,7 @@ rust-version.workspace = true

[features]
default = []
+
i2p = ["cyphernet/i2p"]
test = ["tempfile", "qcheck", "radicle-crypto/test", "radicle-cob/test"]
logger = ["colored", "chrono"]
qcheck = [
modified crates/radicle/src/node.rs
@@ -428,8 +428,8 @@ impl TryFrom<&sqlite::Value> for Alias {
    feature = "schemars",
    derive(schemars::JsonSchema),
    schemars(description = "\
-
    An IP address, or a DNS name, or a Tor onion name, followed by the symbol ':', \
-
    followed by a TCP port number.\
+
    An IP address, or a DNS name, or a Tor onion name, or I2P address,
+
    followed by the symbol ':', followed by a TCP port number.\
")
)]
pub struct Address(
@@ -439,6 +439,7 @@ pub struct Address(
        regex(pattern = r"^.+:((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}))$"),
        extend("examples" = [
            "xmrhfasfg5suueegrnc4gsgyi2tyclcy5oz7f5drnrodmdtob6t2ioyd.onion:8776",
+
            "f2atcc7udeub5kh4nkljtjwyk7ikjviorufzgwnfwhkphljl3vhq.b32.i2p:8776",
            "seed.example.com:8776",
            "192.0.2.0:31337",
        ]),
@@ -485,6 +486,15 @@ impl Address {
        }
    }

+
    /// Returns `true` if the [`HostName`] is an I2P address.
+
    #[cfg(feature = "i2p")]
+
    pub fn is_i2p(&self) -> bool {
+
        match self.0.host {
+
            HostName::I2p(_) => true,
+
            _ => false,
+
        }
+
    }
+

    /// Return the port number of the [`Address`].
    pub fn port(&self) -> u16 {
        self.0.port
modified crates/radicle/src/node/address.rs
@@ -203,6 +203,8 @@ pub enum AddressType {
    Dns = 3,
    #[cfg(feature = "tor")]
    Onion = 4,
+
    #[cfg(feature = "i2p")]
+
    I2p = 5,
}

impl From<AddressType> for u8 {
@@ -219,6 +221,8 @@ impl From<&Address> for AddressType {
            HostName::Dns(_) => AddressType::Dns,
            #[cfg(feature = "tor")]
            HostName::Tor(_) => AddressType::Onion,
+
            #[cfg(feature = "i2p")]
+
            HostName::I2p(_) => AddressType::I2p,
            _ => todo!(), // FIXME(cloudhead): Maxim will remove `non-exhaustive`
        }
    }
@@ -234,6 +238,8 @@ impl TryFrom<u8> for AddressType {
            3 => Ok(AddressType::Dns),
            #[cfg(feature = "tor")]
            4 => Ok(AddressType::Onion),
+
            #[cfg(feature = "i2p")]
+
            5 => Ok(AddressType::I2p),
            _ => Err(other),
        }
    }
modified crates/radicle/src/node/address/store.rs
@@ -537,6 +537,8 @@ impl TryFrom<&sql::Value> for AddressType {
                "dns" => Ok(AddressType::Dns),
                #[cfg(feature = "tor")]
                "onion" => Ok(AddressType::Onion),
+
                #[cfg(feature = "i2p")]
+
                "i2p" => Ok(AddressType::I2p),
                _ => Err(err),
            },
            _ => Err(err),
@@ -552,6 +554,8 @@ impl sql::BindableWithIndex for AddressType {
            Self::Dns => "dns".bind(stmt, i),
            #[cfg(feature = "tor")]
            Self::Onion => "onion".bind(stmt, i),
+
            #[cfg(feature = "i2p")]
+
            Self::I2p => "i2p".bind(stmt, i),
        }
    }
}
modified crates/radicle/src/node/config.rs
@@ -275,7 +275,7 @@ pub struct RateLimits {
    schemars(description = "\
    A node address to connect to. Format: An Ed25519 public key in multibase encoding, \
    followed by the symbol '@', followed by an IP address, or a DNS name, or a Tor onion \
-
    name, followed by the symbol ':', followed by a TCP port number.\
+
    name, or an I2P address, followed by the symbol ':', followed by a TCP port number.\
")
)]
pub struct ConnectAddress(
@@ -286,6 +286,7 @@ pub struct ConnectAddress(
        extend("examples" = [
            "z6MkrLMMsiPWUcNPHcRajuMi9mDfYckSoJyPwwnknocNYPm7@rosa.radicle.xyz:8776",
            "z6MkvUJtYD9dHDJfpevWRT98mzDDpdAtmUjwyDSkyqksUr7C@xmrhfasfg5suueegrnc4gsgyi2tyclcy5oz7f5drnrodmdtob6t2ioyd.onion:8776",
+
            "z6Mkvky2mnSYCTUMKRdAUoZXBXLLKtnWEkWeYQcGjjnmobAU@f2atcc7udeub5kh4nkljtjwyk7ikjviorufzgwnfwhkphljl3vhq.b32.i2p:8776",
            "z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi@seed.example.com:8776",
            "z6MkkfM3tPXNPrPevKr3uSiQtHPuwnNhu2yUVjgd2jXVsVz5@192.0.2.0:31337",
        ]),
@@ -355,7 +356,7 @@ pub enum Relay {
#[derive(Debug, Copy, Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", tag = "mode")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
-
#[cfg(feature = "tor")]
+
#[cfg(any(feature = "tor", feature = "i2p"))]
pub enum AddressConfig {
    /// Proxy connections to this address type.
    Proxy {
@@ -439,6 +440,10 @@ pub struct Config {
    #[cfg(feature = "tor")]
    #[serde(default, skip_serializing_if = "crate::serde_ext::is_default")]
    pub onion: AddressConfig,
+
    /// I2P address config.
+
    #[cfg(feature = "i2p")]
+
    #[serde(default, skip_serializing_if = "crate::serde_ext::is_default")]
+
    pub i2p: AddressConfig,
    /// Peer-to-peer network.
    #[serde(default)]
    pub network: Network,
@@ -489,6 +494,8 @@ impl Config {
            proxy: None,
            #[cfg(feature = "tor")]
            onion: AddressConfig::Drop,
+
            #[cfg(feature = "i2p")]
+
            i2p: AddressConfig::Drop,
            relay: Relay::default(),
            limits: Limits::default(),
            workers: Workers::default(),
modified crates/radicle/src/test/arbitrary.rs
@@ -6,6 +6,8 @@ use std::{iter, net};

use crypto::test::signer::MockSigner;
use crypto::{PublicKey, Unverified};
+
#[cfg(feature = "i2p")]
+
use cyphernet::addr::i2p::I2pAddr;
#[cfg(feature = "tor")]
use cyphernet::{addr::tor::OnionAddrV3, EcPk};
use qcheck::Arbitrary;
@@ -301,6 +303,30 @@ impl Arbitrary for Address {
                );
                cyphernet::addr::HostName::Tor(addr)
            }
+
            #[cfg(feature = "i2p")]
+
            AddressType::I2p => {
+
                let address = if bool::arbitrary(g) {
+
                    let mut rng = fastrand::Rng::with_seed(u64::arbitrary(g));
+

+
                    let name: String = iter::repeat_with(|| rng.alphanumeric()).take(56).collect();
+

+
                    name + ".b32"
+
                } else {
+
                    g.choose(&["iris.radicle.example", "rosa.radicle.example"])
+
                        .unwrap()
+
                        .to_string()
+
                };
+

+
                let suffix = if bool::arbitrary(g) {
+
                    ".i2p"
+
                } else {
+
                    ".i2p.alt"
+
                };
+

+
                let address = address + suffix;
+

+
                cyphernet::addr::HostName::I2p(I2pAddr::from_str(&address).unwrap())
+
            }
        };

        Address::from(cyphernet::addr::NetAddr {