Przeglądaj źródła

net: add p2p-socks5 and p2p-i2p features

oars 1 rok temu
rodzic
commit
78ede4afa1
3 zmienionych plików z 19 dodań i 2 usunięć
  1. 7 0
      Cargo.toml
  2. 3 2
      src/net/hosts.rs
  3. 9 0
      src/net/transport/mod.rs

+ 7 - 0
Cargo.toml

@@ -227,10 +227,17 @@ net-defaults = [
 
     "p2p-tor",
     #"p2p-nym",
+    "p2p-i2p",
 ]
 
 p2p-unix = []
 
+p2p-socks5 = []
+
+p2p-i2p = [
+    "p2p-socks5"
+]
+
 net = ["net-defaults"]
 
 rpc = [

+ 3 - 2
src/net/hosts.rs

@@ -40,7 +40,6 @@ use super::{
 use crate::{
     system::{Publisher, PublisherPtr, Subscription},
     util::{
-        encoding::base32,
         file::{load_file, save_file},
         most_frequent_or_any,
         path::expand_path,
@@ -1358,6 +1357,7 @@ impl Hosts {
                     );
                 }
 
+                #[cfg(feature = "p2p-i2p")]
                 "i2p" | "i2p+tls" => {
                     if !Self::is_i2p_host(host_str) {
                         continue
@@ -1602,6 +1602,7 @@ impl Hosts {
         None
     }
 
+    #[cfg(feature = "p2p-i2p")]
     fn is_i2p_host(host: &str) -> bool {
         if !host.ends_with(".i2p") {
             return false
@@ -1614,7 +1615,7 @@ impl Hosts {
 
         if name.ends_with(".b32") {
             let b32 = name.trim_end_matches(".b32");
-            let decoded = base32::decode(b32);
+            let decoded = crate::util::encoding::base32::decode(b32);
             // decoded should be a SHA256 hash
             return decoded.is_some() && decoded.unwrap().len() == 32
         }

+ 9 - 0
src/net/transport/mod.rs

@@ -30,6 +30,7 @@ use std::io::ErrorKind;
 pub(crate) mod tls;
 
 /// SOCKS5 proxy client
+#[cfg(feature = "p2p-socks5")]
 pub mod socks5;
 
 /// TCP transport
@@ -77,9 +78,11 @@ pub enum DialerVariant {
     Unix(unix::UnixDialer),
 
     /// SOCKS5 proxy
+    #[cfg(feature = "p2p-socks5")]
     Socks5(socks5::Socks5Dialer),
 
     /// SOCKS5 proxy with TLS
+    #[cfg(feature = "p2p-socks5")]
     Socks5Tls(socks5::Socks5Dialer),
 }
 
@@ -199,6 +202,7 @@ impl Dialer {
                 Ok(Self { endpoint, variant })
             }
 
+            #[cfg(feature = "p2p-socks5")]
             "socks5" => {
                 // Build a SOCKS5 dialer
                 enforce_hostport!(endpoint);
@@ -207,6 +211,7 @@ impl Dialer {
                 Ok(Self { endpoint, variant })
             }
 
+            #[cfg(feature = "p2p-socks5")]
             "socks5+tls" => {
                 // Build a SOCKS5 dialer with TLS encapsulation
                 enforce_hostport!(endpoint);
@@ -215,6 +220,7 @@ impl Dialer {
                 Ok(Self { endpoint, variant })
             }
 
+            #[cfg(feature = "p2p-i2p")]
             "i2p" => {
                 // Build a Socks5 Dialer for I2p
                 enforce_hostport!(endpoint);
@@ -225,6 +231,7 @@ impl Dialer {
                 Ok(Self { endpoint, variant })
             }
 
+            #[cfg(feature = "p2p-i2p")]
             "i2p+tls" => {
                 // Build a SOCKS5 dialer with TLS encapsulation for I2p
                 enforce_hostport!(endpoint);
@@ -303,11 +310,13 @@ impl Dialer {
                 Ok(Box::new(stream))
             }
 
+            #[cfg(feature = "p2p-socks5")]
             DialerVariant::Socks5(dialer) => {
                 let stream = dialer.do_dial().await?;
                 Ok(Box::new(stream))
             }
 
+            #[cfg(feature = "p2p-socks5")]
             DialerVariant::Socks5Tls(dialer) => {
                 let stream = dialer.do_dial().await?;
                 let tlsupgrade = tls::TlsUpgrade::new().await;