diff --git a/vnt/src/handle/handshaker.rs b/vnt/src/handle/handshaker.rs index 840bf55..62658f5 100644 --- a/vnt/src/handle/handshaker.rs +++ b/vnt/src/handle/handshaker.rs @@ -1,12 +1,16 @@ use std::io; +use protobuf::Message; + #[cfg(feature = "server_encrypt")] use crate::cipher::RsaCipher; use crate::handle::{GATEWAY_IP, SELF_IP}; -use crate::proto::message::{HandshakeRequest, SecretHandshakeRequest}; +use crate::proto::message::HandshakeRequest; +#[cfg(feature = "server_encrypt")] +use crate::proto::message::SecretHandshakeRequest; +#[cfg(feature = "server_encrypt")] use crate::protocol::body::RSA_ENCRYPTION_RESERVED; use crate::protocol::{service_packet, NetPacket, Protocol, Version, MAX_TTL}; -use protobuf::Message; pub enum HandshakeEnum { NotSecret, diff --git a/vnt/src/handle/recv_data/server.rs b/vnt/src/handle/recv_data/server.rs index 654d8b8..ccf284e 100644 --- a/vnt/src/handle/recv_data/server.rs +++ b/vnt/src/handle/recv_data/server.rs @@ -1,7 +1,7 @@ use std::io; use std::net::Ipv4Addr; -use std::ops::Sub; use std::sync::Arc; +#[cfg(feature = "server_encrypt")] use std::time::{Duration, Instant}; use crossbeam_utils::atomic::AtomicCell; @@ -21,10 +21,11 @@ use crate::cipher::Cipher; use crate::cipher::RsaCipher; use crate::external_route::ExternalRoute; use crate::handle::callback::{ErrorInfo, ErrorType, HandshakeInfo, RegisterInfo, VntCallback}; +#[cfg(feature = "server_encrypt")] +use crate::handle::handshaker; use crate::handle::recv_data::PacketHandler; use crate::handle::{ - handshaker, registrar, BaseConfigInfo, ConnectStatus, CurrentDeviceInfo, PeerDeviceInfo, - GATEWAY_IP, + registrar, BaseConfigInfo, ConnectStatus, CurrentDeviceInfo, PeerDeviceInfo, GATEWAY_IP, }; use crate::nat::NatTest; use crate::proto; @@ -46,7 +47,8 @@ pub struct ServerPacketHandler { config_info: BaseConfigInfo, nat_test: NatTest, callback: Call, - time: Arc>, + #[cfg(feature = "server_encrypt")] + up_key_time: Arc>, route_record: Arc>>, external_route: ExternalRoute, } @@ -73,7 +75,8 @@ impl ServerPacketHandler { config_info, nat_test, callback, - time: Arc::new(AtomicCell::new(Instant::now().sub(Duration::from_secs(60)))), + #[cfg(feature = "server_encrypt")] + up_key_time: Arc::new(AtomicCell::new(Instant::now() - Duration::from_secs(60))), route_record: Arc::new(Mutex::default()), external_route, } @@ -97,9 +100,12 @@ impl PacketHandler for ServerPacketHandler { { let mutex_guard = self.rsa_cipher.lock(); if let Some(rsa_cipher) = mutex_guard.as_ref() { - let last = self.time.load(); + let last = self.up_key_time.load(); if last.elapsed() < Duration::from_secs(1) - || self.time.compare_exchange(last, Instant::now()).is_err() + || self + .up_key_time + .compare_exchange(last, Instant::now()) + .is_err() { //短时间不重复上传服务端密钥 return Ok(());