This commit is contained in:
lubeilin
2024-03-19 23:54:33 +08:00
parent b36cc352d5
commit 30b1e71aa1
9 changed files with 16 additions and 17 deletions
+7 -7
View File
@@ -1,16 +1,16 @@
use rand::Rng;
use std::fs::File;
use std::io::Write;
use rand::Rng;
fn main() {
// 生成随机序列号
let serial_number = format!("{}-{}-{}",rand::thread_rng().gen_range(100..1000)
,rand::thread_rng().gen_range(100..1000)
,rand::thread_rng().gen_range(100..1000));
let generated_code = format!(
r#"pub const SERIAL_NUMBER: &str = "{}";"#,
serial_number
let serial_number = format!(
"{}-{}-{}",
rand::thread_rng().gen_range(100..1000),
rand::thread_rng().gen_range(100..1000),
rand::thread_rng().gen_range(100..1000)
);
let generated_code = format!(r#"pub const SERIAL_NUMBER: &str = "{}";"#, serial_number);
let dest_path = "src/generated_serial_number.rs";
let mut file = File::create(&dest_path).unwrap();
file.write_all(generated_code.as_bytes()).unwrap();
+1
View File
@@ -31,6 +31,7 @@ impl VntCallback for VntHandler {
}
fn error(&self, info: ErrorInfo) {
log::error!("error {:?}", info);
println!("{}", style(format!("error {}", info)).red());
match info.code {
ErrorType::TokenError
+1 -1
View File
@@ -15,8 +15,8 @@ use vnt::core::{Config, Vnt};
mod command;
mod config;
mod console_out;
mod root_check;
mod generated_serial_number;
mod root_check;
pub fn app_home() -> io::Result<PathBuf> {
let root_path = match std::env::current_exe() {
+1 -1
View File
@@ -226,7 +226,7 @@ impl Punch {
}
pub fn punch(&mut self, buf: &[u8], id: Ipv4Addr, nat_info: NatInfo) -> io::Result<()> {
if !self.context.route_table.need_punch(&id) {
log::info!("已打洞成功,无需打洞:{:?}",id);
log::info!("已打洞成功,无需打洞:{:?}", id);
return Ok(());
}
if self.is_tcp && nat_info.tcp_port != 0 {
+2 -2
View File
@@ -19,8 +19,8 @@ pub fn addr_request(
config: BaseConfigInfo,
) {
addr_request0(&context, &current_device_info, &server_cipher, &config);
// 9秒发送一次
let rs = scheduler.timeout(Duration::from_secs(9), |s| {
// 17秒发送一次
let rs = scheduler.timeout(Duration::from_secs(17), |s| {
addr_request(s, context, current_device_info, server_cipher, config)
});
if !rs {
+2 -2
View File
@@ -12,7 +12,7 @@ use crate::cipher::Cipher;
use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo};
use crate::protocol::body::ENCRYPTION_RESERVED;
use crate::protocol::control_packet::PingPacket;
use crate::protocol::{control_packet, NetPacket, Protocol, Version, MAX_TTL};
use crate::protocol::{control_packet, NetPacket, Protocol, Version};
use crate::util::Scheduler;
/// 定时发送心跳包
@@ -216,7 +216,7 @@ fn heartbeat_packet(
net_packet.set_version(Version::V1);
net_packet.set_protocol(Protocol::Control);
net_packet.set_transport_protocol(control_packet::Protocol::Ping.into());
net_packet.first_set_ttl(MAX_TTL);
net_packet.first_set_ttl(5);
net_packet.set_source(src);
net_packet.set_destination(dest);
let mut ping = PingPacket::new(net_packet.payload_mut())?;
-1
View File
@@ -86,7 +86,6 @@ fn idle_gateway0<Call: VntCallback>(
ErrorType::Disconnect,
format!("connect:{},error:{:?}", cur.connect_server, e),
));
log::warn!("{:?}", e);
}
}
fn idle_route0<Call: VntCallback>(
+1 -2
View File
@@ -268,6 +268,7 @@ impl<Call: VntCallback> ServerPacketHandler<Call> {
log::info!("ip发生变化,old:{:?},response={:?}", old, response);
}
if let Err(e) = self.device.set_ip(virtual_ip, virtual_netmask) {
log::error!("LocalIpExists {:?}", e);
self.callback.error(ErrorInfo::new_msg(
ErrorType::LocalIpExists,
format!("set_ip {:?}", e),
@@ -421,12 +422,10 @@ impl<Call: VntCallback> ServerPacketHandler<Call> {
self.callback.error(err);
}
InErrorPacket::IpAlreadyExists => {
log::error!("IpAlreadyExists");
let err = ErrorInfo::new(ErrorType::IpAlreadyExists);
self.callback.error(err);
}
InErrorPacket::InvalidIp => {
log::error!("InvalidIp");
let err = ErrorInfo::new(ErrorType::InvalidIp);
self.callback.error(err);
}
+1 -1
View File
@@ -97,7 +97,7 @@ pub fn base_handle(
net_packet.set_version(Version::V1);
net_packet.set_protocol(protocol::Protocol::IpTurn);
net_packet.set_transport_protocol(ip_turn_packet::Protocol::Ipv4.into());
net_packet.first_set_ttl(3);
net_packet.first_set_ttl(6);
net_packet.set_source(src_ip);
net_packet.set_destination(dest_ip);
if dest_ip == current_device.virtual_gateway {