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