[mio] 完善提示信息
This commit is contained in:
+11
-1
@@ -2,7 +2,7 @@ use std::process;
|
||||
|
||||
use console::style;
|
||||
|
||||
use vnt::handle::callback::ConnectInfo;
|
||||
use vnt::handle::callback::{ConnectInfo, ErrorType};
|
||||
use vnt::{DeviceInfo, ErrorInfo, HandshakeInfo, RegisterInfo, VntCallback};
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -32,6 +32,16 @@ impl VntCallback for VntHandler {
|
||||
|
||||
fn error(&self, info: ErrorInfo) {
|
||||
println!("{}", style(format!("error {}", info)).red());
|
||||
match info.code {
|
||||
ErrorType::TokenError
|
||||
| ErrorType::AddressExhausted
|
||||
| ErrorType::IpAlreadyExists
|
||||
| ErrorType::InvalidIp
|
||||
| ErrorType::LocalIpExists => {
|
||||
self.stop();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn stop(&self) {
|
||||
|
||||
@@ -30,7 +30,6 @@ impl CommandServer {
|
||||
let (len, addr) = udp.recv_from(&mut buf)?;
|
||||
match std::str::from_utf8(&buf[..len]) {
|
||||
Ok(cmd) => {
|
||||
log::info!("收到cmd={:?}", cmd);
|
||||
if let Ok(out) = command(cmd, &vnt) {
|
||||
if let Err(e) = udp.send_to(out.as_bytes(), addr) {
|
||||
log::warn!("cmd={},err={:?}", cmd, e);
|
||||
@@ -56,6 +55,7 @@ fn save_port(port: u16) -> io::Result<()> {
|
||||
}
|
||||
|
||||
fn command(cmd: &str, vnt: &Vnt) -> io::Result<String> {
|
||||
let cmd = cmd.trim();
|
||||
let out_str = match cmd {
|
||||
"route" => serde_yaml::to_string(&crate::command::command_route(vnt))
|
||||
.unwrap_or_else(|e| format!("error {:?}", e)),
|
||||
@@ -68,7 +68,10 @@ fn command(cmd: &str, vnt: &Vnt) -> io::Result<String> {
|
||||
"stopped".to_string()
|
||||
}
|
||||
_ => {
|
||||
format!("command '{}' not found. \n Try to enter: 'help'\n", cmd)
|
||||
format!(
|
||||
"command '{}' not found. Try to enter: 'route'/'list'/'stop' \n",
|
||||
cmd
|
||||
)
|
||||
}
|
||||
};
|
||||
Ok(out_str)
|
||||
|
||||
@@ -171,7 +171,7 @@ pub fn read_config(file_path: &str) -> io::Result<(Config, bool)> {
|
||||
file_conf.device_name,
|
||||
use_channel_type,
|
||||
file_conf.packet_loss,
|
||||
file_conf.packet_delay
|
||||
file_conf.packet_delay,
|
||||
)
|
||||
.unwrap();
|
||||
Ok((config, file_conf.cmd))
|
||||
|
||||
+14
-6
@@ -296,8 +296,9 @@ fn main() {
|
||||
.expect("--packet-loss");
|
||||
let packet_delay = matches
|
||||
.opt_get::<u32>("packet-delay")
|
||||
.expect("--packet-delay").unwrap_or(0);
|
||||
let config = Config::new(
|
||||
.expect("--packet-delay")
|
||||
.unwrap_or(0);
|
||||
let config = match Config::new(
|
||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||
tap,
|
||||
token,
|
||||
@@ -324,9 +325,14 @@ fn main() {
|
||||
device_name,
|
||||
use_channel_type,
|
||||
packet_loss,
|
||||
packet_delay
|
||||
)
|
||||
.unwrap();
|
||||
packet_delay,
|
||||
) {
|
||||
Ok(config) => config,
|
||||
Err(e) => {
|
||||
println!("config error: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
(config, cmd)
|
||||
};
|
||||
println!("version {}", vnt::VNT_VERSION);
|
||||
@@ -467,7 +473,9 @@ fn print_usage(program: &str, _opts: Options) {
|
||||
println!(" --use-channel <p2p> 使用通道 relay/p2p/all,默认两者都使用");
|
||||
println!(" --nic <tun0> 指定虚拟网卡名称");
|
||||
println!(" --packet-loss <0> 模拟丢包,取值0~1之间的小数,程序会按设定的概率主动丢包,可用于模拟弱网");
|
||||
println!(" --packet-delay <0> 模拟延迟,整数,单位毫秒(ms),程序会按设定的值延迟发包,可用于模拟弱网");
|
||||
println!(
|
||||
" --packet-delay <0> 模拟延迟,整数,单位毫秒(ms),程序会按设定的值延迟发包,可用于模拟弱网"
|
||||
);
|
||||
|
||||
println!();
|
||||
println!(
|
||||
|
||||
Reference in New Issue
Block a user