Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
959f2aa783 | ||
|
|
99b2aa9522 | ||
|
|
561fa9f8fe | ||
|
|
ad9dd6a7f7 | ||
|
|
65758eb94c | ||
|
|
fb7ccf4d11 |
@@ -86,6 +86,34 @@ A virtual network tool (VPN)
|
|||||||
- p2p组播/广播
|
- p2p组播/广播
|
||||||
- 客户端数据加密
|
- 客户端数据加密
|
||||||
- 服务端数据加密
|
- 服务端数据加密
|
||||||
|
### 结构
|
||||||
|
<details> <summary>展开</summary>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
|
||||||
|
0 15 31
|
||||||
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|e |s |unused| 版本(4) | 协议(8) | 上层协议(8) |初始ttl(4)|生存时间(4) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| 源ip地址(32) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| 目的ip地址(32) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| 数据体(n) |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| |
|
||||||
|
| 指纹(96) |
|
||||||
|
| |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
注:
|
||||||
|
1. e为是否加密标志,s为服务端通信包标志,unused占两位未使用;
|
||||||
|
2. 开启加密时,数据体为加密后的密文(加密方式取决于密码长度和加密模式),
|
||||||
|
且会存在指纹,指纹使用sha256生成,用于对数据包完整性和真实性的校验
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
### Todo
|
### Todo
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "common"
|
name = "common"
|
||||||
version = "1.2.0"
|
version = "1.2.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# 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
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "vnt-cli"
|
name = "vnt-cli"
|
||||||
version = "1.2.0"
|
version = "1.2.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# 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
|
||||||
|
|||||||
+11
-1
@@ -50,9 +50,19 @@
|
|||||||
### --ip `<IP>`
|
### --ip `<IP>`
|
||||||
指定虚拟ip,指定的ip不能和其他设备重复,必须有效并且在服务端所属网段下,默认情况由服务端分配
|
指定虚拟ip,指定的ip不能和其他设备重复,必须有效并且在服务端所属网段下,默认情况由服务端分配
|
||||||
### --par `<parallel>`
|
### --par `<parallel>`
|
||||||
任务并行度(必须为正整数),默认值为2,该值表示处理网卡读写的任务数,组网设备数较多、处理延迟较大时可适当调大此值
|
任务并行度(必须为正整数),默认值为1,该值表示处理网卡读写的任务数,组网设备数较多、处理延迟较大时可适当调大此值
|
||||||
### --thread `<thread>`
|
### --thread `<thread>`
|
||||||
线程数(必须为正整数),默认为核心数乘2,该值表示处理网络读写、ip代理、打洞等用到的线程数,组网设备数较多、处理延迟较大时可适当调大此值
|
线程数(必须为正整数),默认为核心数乘2,该值表示处理网络读写、ip代理、打洞等用到的线程数,组网设备数较多、处理延迟较大时可适当调大此值
|
||||||
|
### --model `<model>`
|
||||||
|
加密模式,可选值 aes_gcm/aes_cbc,默认使用aes_gcm,通常情况使用aes_cbc性能更好
|
||||||
|
|
||||||
|
| 密码位数 | model | 加密算法 |
|
||||||
|
|-------|--------|------------|
|
||||||
|
| 1~8位 | aes_gcm | AES128-GCM |
|
||||||
|
| `>=`8 | aes_gcm | AES256-GCM |
|
||||||
|
| 1~8位 | aes_cbc | AES128-CBC |
|
||||||
|
| `>=`8 | aes_cbc | AES256-CBC |
|
||||||
|
|
||||||
### --relay
|
### --relay
|
||||||
禁用p2p,在网络环境很差时,只使用服务器中转效果可能更好(可以配合--tcp参数一起使用)
|
禁用p2p,在网络环境很差时,只使用服务器中转效果可能更好(可以配合--tcp参数一起使用)
|
||||||
### --list
|
### --list
|
||||||
|
|||||||
+20
-4
@@ -208,7 +208,7 @@ fn main() {
|
|||||||
println!("--thread invalid");
|
println!("--thread invalid");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("version 1.2.0");
|
println!("version {}",vnt::VNT_VERSION);
|
||||||
let config = Config::new(tap,
|
let config = Config::new(tap,
|
||||||
token, device_id, name,
|
token, device_id, name,
|
||||||
server_address, server_address_str,
|
server_address, server_address_str,
|
||||||
@@ -348,7 +348,7 @@ async fn main0(config: Config, show_cmd: bool) {
|
|||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = vnt.wait_stop()=>{
|
_ = vnt.wait_stop()=>{
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
_ = signal::ctrl_c()=>{
|
_ = signal::ctrl_c()=>{
|
||||||
let _ = vnt.stop();
|
let _ = vnt.stop();
|
||||||
@@ -377,7 +377,7 @@ async fn main0(config: Config, show_cmd: bool) {
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = vnt.wait_stop()=>{
|
_ = vnt.wait_stop()=>{
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
_ = signal::ctrl_c()=>{
|
_ = signal::ctrl_c()=>{
|
||||||
let _ = vnt.stop();
|
let _ = vnt.stop();
|
||||||
@@ -399,6 +399,22 @@ async fn main0(config: Config, show_cmd: bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(unix)]
|
||||||
|
tokio::select! {
|
||||||
|
_ = vnt.wait_stop()=>{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_ = signal::ctrl_c()=>{
|
||||||
|
let _ = vnt.stop();
|
||||||
|
vnt.wait_stop_ms(std::time::Duration::from_secs(3)).await;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_ = sigterm.recv()=>{
|
||||||
|
let _ = vnt.stop();
|
||||||
|
vnt.wait_stop_ms(std::time::Duration::from_secs(3)).await;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
vnt.wait_stop().await;
|
vnt.wait_stop().await;
|
||||||
}
|
}
|
||||||
@@ -436,7 +452,7 @@ fn command(cmd: &str, vnt: &Vnt) -> bool {
|
|||||||
|
|
||||||
fn print_usage(program: &str, _opts: Options) {
|
fn print_usage(program: &str, _opts: Options) {
|
||||||
println!("Usage: {} [options]", program);
|
println!("Usage: {} [options]", program);
|
||||||
println!("version:1.2.0");
|
println!("version:{}",vnt::VNT_VERSION);
|
||||||
println!("Options:");
|
println!("Options:");
|
||||||
println!(" -k <token> {}", green("必选,使用相同的token,就能组建一个局域网络".to_string()));
|
println!(" -k <token> {}", green("必选,使用相同的token,就能组建一个局域网络".to_string()));
|
||||||
println!(" -n <name> 给设备一个名字,便于区分不同设备,默认使用系统版本");
|
println!(" -n <name> 给设备一个名字,便于区分不同设备,默认使用系统版本");
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "vnt-jni"
|
name = "vnt-jni"
|
||||||
version = "1.2.0"
|
version = "1.2.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# 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
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "vnt"
|
name = "vnt"
|
||||||
version = "1.2.0"
|
version = "1.2.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# 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
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ use crate::proto::message::{HandshakeRequest, HandshakeResponse, SecretHandshake
|
|||||||
use crate::protocol::{MAX_TTL, NetPacket, Protocol, service_packet, Version};
|
use crate::protocol::{MAX_TTL, NetPacket, Protocol, service_packet, Version};
|
||||||
use crate::protocol::body::ENCRYPTION_RESERVED;
|
use crate::protocol::body::ENCRYPTION_RESERVED;
|
||||||
|
|
||||||
const VERSION: &'static str = "1.2.0";
|
|
||||||
|
|
||||||
pub enum HandshakeEnum {
|
pub enum HandshakeEnum {
|
||||||
NotSecret,
|
NotSecret,
|
||||||
@@ -24,7 +23,7 @@ pub enum HandshakeEnum {
|
|||||||
fn handshake_request_packet(secret: bool) -> crate::Result<NetPacket<Vec<u8>>> {
|
fn handshake_request_packet(secret: bool) -> crate::Result<NetPacket<Vec<u8>>> {
|
||||||
let mut request = HandshakeRequest::new();
|
let mut request = HandshakeRequest::new();
|
||||||
request.secret = secret;
|
request.secret = secret;
|
||||||
request.version = VERSION.to_string();
|
request.version = crate::VNT_VERSION.to_string();
|
||||||
let bytes = request.write_to_bytes()?;
|
let bytes = request.write_to_bytes()?;
|
||||||
let buf = vec![0u8; 12 + bytes.len()];
|
let buf = vec![0u8; 12 + bytes.len()];
|
||||||
let mut net_packet = NetPacket::new(buf)?;
|
let mut net_packet = NetPacket::new(buf)?;
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ fn registration_request_packet(
|
|||||||
request.virtual_ip = ip.into();
|
request.virtual_ip = ip.into();
|
||||||
request.allow_ip_change = allow_ip_change;
|
request.allow_ip_change = allow_ip_change;
|
||||||
request.is_fast = is_fast;
|
request.is_fast = is_fast;
|
||||||
request.version = "1.2.0".to_string();
|
request.version = crate::VNT_VERSION.to_string();
|
||||||
request.client_secret = client_secret;
|
request.client_secret = client_secret;
|
||||||
let bytes = request.write_to_bytes()?;
|
let bytes = request.write_to_bytes()?;
|
||||||
let buf = vec![0u8; 12 + bytes.len() + ENCRYPTION_RESERVED];
|
let buf = vec![0u8; 12 + bytes.len() + ENCRYPTION_RESERVED];
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
|
pub const VNT_VERSION:&'static str = "1.2.1";
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ pub fn create_device(device_type: DeviceType,
|
|||||||
config.layer(tun::Layer::L2);
|
config.layer(tun::Layer::L2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let dev = tun::create(&config).unwrap();
|
let dev = tun::create(&config).expect("tun/tap failed to create");
|
||||||
let packet_information = dev.has_packet_information();
|
let packet_information = dev.has_packet_information();
|
||||||
let queue = dev.queue(0).unwrap();
|
let queue = dev.queue(0).unwrap();
|
||||||
let reader = queue.reader();
|
let reader = queue.reader();
|
||||||
|
|||||||
Reference in New Issue
Block a user