增加服务端加密、完善客户端加密

This commit is contained in:
lubeilin
2023-08-27 11:58:32 +08:00
parent 81764433d8
commit 0472b1590e
42 changed files with 2546 additions and 887 deletions
+2
View File
@@ -31,4 +31,6 @@ pub struct DeviceItem {
pub nat_traversal_type: String,
pub rt: String,
pub status: String,
pub client_secret: bool,
pub current_client_secret:bool,
}
+4
View File
@@ -75,6 +75,7 @@ pub fn command_list(vnt: &Vnt) -> Vec<DeviceItem> {
let info = vnt.current_device();
let device_list = vnt.device_list();
let mut list = Vec::new();
let current_client_secret = vnt.client_encrypt();
for peer in device_list {
let name = peer.name;
let virtual_ip = peer.virtual_ip.to_string();
@@ -105,6 +106,7 @@ pub fn command_list(vnt: &Vnt) -> Vec<DeviceItem> {
("relay".to_string(), "".to_string())
};
let status = format!("{:?}", peer.status);
let client_secret = peer.client_secret;
let item = DeviceItem {
name,
virtual_ip,
@@ -114,6 +116,8 @@ pub fn command_list(vnt: &Vnt) -> Vec<DeviceItem> {
nat_traversal_type,
rt,
status,
client_secret,
current_client_secret,
};
list.push(item);
}
+5 -21
View File
@@ -1,5 +1,5 @@
use std::io;
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
use std::io::Write;
use tokio::net::UdpSocket;
use vnt::core::Vnt;
@@ -15,27 +15,11 @@ impl CommandServer {
impl CommandServer {
pub async fn start(self, vnt: Vnt) -> io::Result<()> {
let mut port = 21637 as u16;
let udp = loop {
match UdpSocket::bind(SocketAddr::V4(SocketAddrV4::new(
Ipv4Addr::new(127, 0, 0, 1),
port,
))).await {
Ok(udp) => {
break udp;
}
Err(e) => {
if e.kind() == io::ErrorKind::AddrInUse {
port += 1;
} else {
log::error!("创建udp失败 {:?}", e);
return Err(e);
}
}
}
};
let udp = UdpSocket::bind("127.0.0.1:0").await?;
let path_buf = crate::app_home()?.join("command-port");
std::fs::write(path_buf, udp.local_addr()?.port().to_string())?;
let mut file = std::fs::File::create(path_buf)?;
file.write_all(udp.local_addr()?.port().to_string().as_bytes())?;
file.sync_all()?;
let mut buf = [0u8; 64];
loop {
let (len, addr) = udp.recv_from(&mut buf).await?;