diff --git a/Cargo.toml b/Cargo.toml index 80d6cfe..54a2ec3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,10 +9,11 @@ repository = "https://github.com/rapiz1/rathole" readme = "README.md" [features] -default = ["tls", "server", "client"] -tls = ["tokio-native-tls"] +default = ["tls", "server", "client", "noise"] server = [] client = [] +tls = ["tokio-native-tls"] +noise = ["snowstorm", "base64"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [profile.bench] @@ -41,5 +42,5 @@ socket2 = "0.4" fdlimit = "0.2.1" tokio-native-tls = { version = "0.3.0", optional = true } async-trait = "0.1.52" -snowstorm = "0.1.3" -base64 = "0.13.0" +snowstorm = { version = "0.1.3", optional = true } +base64 = { version = "0.13.0", optional = true } diff --git a/src/client.rs b/src/client.rs index a703ca2..dc9e75b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -5,7 +5,7 @@ use crate::protocol::{ self, read_ack, read_control_cmd, read_data_cmd, read_hello, Ack, Auth, ControlChannelCmd, DataChannelCmd, UdpTraffic, CURRENT_PROTO_VRESION, HASH_WIDTH_IN_BYTES, }; -use crate::transport::{NoiseTransport, TcpTransport, Transport}; +use crate::transport::{TcpTransport, Transport}; use anyhow::{anyhow, bail, Context, Result}; use backoff::ExponentialBackoff; use bytes::{Bytes, BytesMut}; @@ -18,6 +18,8 @@ use tokio::sync::{broadcast, mpsc, oneshot, RwLock}; use tokio::time::{self, Duration}; use tracing::{debug, error, info, instrument, Instrument, Span}; +#[cfg(feature = "noise")] +use crate::transport::NoiseTransport; #[cfg(feature = "tls")] use crate::transport::TlsTransport; @@ -47,8 +49,13 @@ pub async fn run_client(config: &Config, shutdown_rx: broadcast::Receiver) crate::helper::feature_not_compile("tls") } TransportType::Noise => { - let mut client = Client::::from(config).await?; - client.run(shutdown_rx).await + #[cfg(feature = "noise")] + { + let mut client = Client::::from(config).await?; + client.run(shutdown_rx).await + } + #[cfg(not(feature = "noise"))] + crate::helper::feature_not_compile("noise") } } } diff --git a/src/lib.rs b/src/lib.rs index 3810766..1cf9299 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,7 @@ fn get_str_from_keypair_type(curve: KeypairType) -> &'static str { } } +#[cfg(feature = "noise")] fn genkey(curve: Option) -> Result<()> { let curve = curve.unwrap_or(DEFAULT_CURVE); let builder = snowstorm::Builder::new( @@ -50,6 +51,11 @@ fn genkey(curve: Option) -> Result<()> { Ok(()) } +#[cfg(not(feature = "noise"))] +fn genkey(curve: Option) -> Result<()> { + crate::helper::feature_not_compile("nosie") +} + pub async fn run(args: &Cli, shutdown_rx: broadcast::Receiver) -> Result<()> { if args.genkey.is_some() { return genkey(args.genkey.unwrap()); diff --git a/src/server.rs b/src/server.rs index 61809c0..7da2f98 100644 --- a/src/server.rs +++ b/src/server.rs @@ -6,9 +6,7 @@ use crate::protocol::{ self, read_auth, read_hello, Ack, ControlChannelCmd, DataChannelCmd, Hello, UdpTraffic, HASH_WIDTH_IN_BYTES, }; -#[cfg(feature = "tls")] -use crate::transport::TlsTransport; -use crate::transport::{NoiseTransport, TcpTransport, Transport}; +use crate::transport::{TcpTransport, Transport}; use anyhow::{anyhow, bail, Context, Result}; use backoff::backoff::Backoff; use backoff::ExponentialBackoff; @@ -24,6 +22,11 @@ use tokio::sync::{broadcast, mpsc, RwLock}; use tokio::time; use tracing::{debug, error, info, info_span, instrument, warn, Instrument, Span}; +#[cfg(feature = "noise")] +use crate::transport::NoiseTransport; +#[cfg(feature = "tls")] +use crate::transport::TlsTransport; + type ServiceDigest = protocol::Digest; // SHA256 of a service name type Nonce = protocol::Digest; // Also called `session_key` @@ -56,8 +59,13 @@ pub async fn run_server(config: &Config, shutdown_rx: broadcast::Receiver) crate::helper::feature_not_compile("tls") } TransportType::Noise => { - let mut server = Server::::from(config).await?; - server.run(shutdown_rx).await?; + #[cfg(feature = "noise")] + { + let mut server = Server::::from(config).await?; + server.run(shutdown_rx).await?; + } + #[cfg(not(feature = "noise"))] + crate::helper::feature_not_compile("noise") } } diff --git a/src/transport/mod.rs b/src/transport/mod.rs index 85abe30..5139afd 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -27,5 +27,7 @@ mod tls; #[cfg(feature = "tls")] pub use tls::TlsTransport; +#[cfg(feature = "noise")] mod noise; +#[cfg(feature = "noise")] pub use noise::NoiseTransport;