支持--no-default-features编译

This commit is contained in:
lubeilin
2024-05-11 13:30:16 +08:00
parent 0e4294415e
commit d8a9ec5732
9 changed files with 25 additions and 3 deletions
+1
View File
@@ -84,6 +84,7 @@ features说明
| sm4_cbc | 支持sm4_cbc加密 | 是 |
| server_encrypt | 支持服务端加密 | 是 |
| ip_proxy | 内置ip代理 | 是 |
| port_mapping | 端口映射 | 是 |
### ip转发/代理
如果编译时去除了内置的ip代理(或使用--no-proxy关闭了代理),则可以使用网卡NAT转发来实现点对网,
+3
View File
@@ -185,7 +185,10 @@ pub fn command_info(vnt: &Vnt) -> Info {
.unwrap_or("None".to_string());
let up = vnt.up_stream();
let down = vnt.down_stream();
#[cfg(feature = "port_mapping")]
let port_mapping_list = vnt.config().port_mapping_list.clone();
#[cfg(not(feature = "port_mapping"))]
let port_mapping_list = vec![];
let in_ips = vnt.config().in_ips.clone();
let out_ips = vnt.config().out_ips.clone();
Info {
+4
View File
@@ -52,9 +52,13 @@ pub enum CipherModel {
impl Display for CipherModel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match self {
#[cfg(any(feature = "aes_gcm", feature = "server_encrypt"))]
CipherModel::AesGcm => "aes_gcm".to_string(),
#[cfg(feature = "aes_cbc")]
CipherModel::AesCbc => "aes_cbc".to_string(),
#[cfg(feature = "aes_ecb")]
CipherModel::AesEcb => "aes_ecb".to_string(),
#[cfg(feature = "sm4_cbc")]
CipherModel::Sm4Cbc => "sm4_cbc".to_string(),
CipherModel::None => "none".to_string(),
};
+5 -2
View File
@@ -6,7 +6,7 @@ use std::time::Duration;
use crossbeam_utils::atomic::AtomicCell;
use parking_lot::{Mutex, RwLock};
use rand::Rng;
use rsa::signature::digest::Digest;
use sha2::Digest;
#[cfg(not(target_os = "android"))]
use tun::device::IFace;
@@ -167,7 +167,10 @@ impl Vnt {
let down_counter =
U64Adder::with_capacity(config.ports.as_ref().map(|v| v.len()).unwrap_or_default() + 8);
let down_count_watcher = down_counter.watch();
let handshake = Handshake::new(rsa_cipher.clone());
let handshake = Handshake::new(
#[cfg(feature = "server_encrypt")]
rsa_cipher.clone(),
);
let up_counter = SingleU64Adder::new();
let up_count_watcher = up_counter.watch();
let tun_helper = TunDeviceHelper::new(
+7 -1
View File
@@ -4,6 +4,7 @@ use std::sync::Arc;
use std::time::{Duration, Instant};
use crossbeam_utils::atomic::AtomicCell;
#[cfg(feature = "server_encrypt")]
use parking_lot::Mutex;
use protobuf::Message;
@@ -28,12 +29,16 @@ pub enum HandshakeEnum {
#[derive(Clone)]
pub struct Handshake {
time: Arc<AtomicCell<Instant>>,
#[cfg(feature = "server_encrypt")]
rsa_cipher: Arc<Mutex<Option<RsaCipher>>>,
}
impl Handshake {
pub fn new(rsa_cipher: Arc<Mutex<Option<RsaCipher>>>) -> Self {
pub fn new(
#[cfg(feature = "server_encrypt")] rsa_cipher: Arc<Mutex<Option<RsaCipher>>>,
) -> Self {
Handshake {
time: Arc::new(AtomicCell::new(Instant::now() - Duration::from_secs(60))),
#[cfg(feature = "server_encrypt")]
rsa_cipher,
}
}
@@ -54,6 +59,7 @@ impl Handshake {
let mut request = HandshakeRequest::new();
request.secret = secret;
request.version = crate::VNT_VERSION.to_string();
#[cfg(feature = "server_encrypt")]
if let Some(finger) = self.rsa_cipher.lock().as_ref().map(|v| v.finger().clone()) {
request.key_finger = finger;
}
+1
View File
@@ -193,6 +193,7 @@ impl<Call: VntCallback> PacketHandler for ServerPacketHandler<Call> {
}
return Ok(());
}
#[cfg(feature = "server_encrypt")]
if let Ok(rsa_cipher) = RsaCipher::new(&response.public_key) {
self.rsa_cipher.lock().replace(rsa_cipher);
}
+1
View File
@@ -19,6 +19,7 @@ use crate::handle::tun_tap::channel_group::channel_group;
use crate::handle::{check_dest, CurrentDeviceInfo, PeerDeviceInfo};
#[cfg(feature = "ip_proxy")]
use crate::ip_proxy::IpProxyMap;
#[cfg(feature = "ip_proxy")]
use crate::ip_proxy::ProxyHandler;
use crate::protocol;
use crate::protocol::body::ENCRYPTION_RESERVED;
+1
View File
@@ -3,6 +3,7 @@ use crate::cipher::Cipher;
use crate::external_route::ExternalRoute;
use crate::handle::tun_tap::channel_group::GroupSyncSender;
use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo};
#[cfg(feature = "ip_proxy")]
use crate::ip_proxy::IpProxyMap;
use crate::util::{SingleU64Adder, StopManager};
use crossbeam_utils::atomic::AtomicCell;
@@ -10,6 +10,7 @@ use crate::channel::context::ChannelContext;
use crate::cipher::Cipher;
use crate::external_route::ExternalRoute;
use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo};
#[cfg(feature = "ip_proxy")]
use crate::ip_proxy::IpProxyMap;
use crate::util::{SingleU64Adder, StopManager};
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
@@ -98,6 +99,7 @@ impl TunDeviceHelper {
context,
current_device,
ip_route,
#[cfg(feature = "ip_proxy")]
ip_proxy_map,
client_cipher,
server_cipher,