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