bug fix and improve (#81)

1. fix manual connector do not retry if dns resolve failed.
2. allow not creating tun device if no virtual ipv4 is assigned.
This commit is contained in:
Sijie.Sun 2024-05-05 16:18:05 +08:00 committed by GitHub
parent 638013a93d
commit e5b537267e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 13 deletions

View File

@ -31,7 +31,7 @@ pub enum GlobalCtxEvent {
ConnectionError(String, String, String), // (local url, remote url, error message)
Connecting(url::Url),
ConnectError(String, String), // (dst, error message)
ConnectError(String, String, String), // (dst, ip version, error message)
VpnPortalClientConnected(String, String), // (portal, client ip)
VpnPortalClientDisconnected(String, String), // (portal, client ip)

View File

@ -192,8 +192,13 @@ impl ManualConnectorManager {
let (_, connector) = data.connectors.remove(&dead_url).unwrap();
let insert_succ = data.reconnecting.insert(dead_url.clone());
assert!(insert_succ);
reconn_tasks.spawn(async move {
sender.send(Self::conn_reconnect(data_clone.clone(), dead_url, connector).await).await.unwrap();
let reconn_ret = Self::conn_reconnect(data_clone.clone(), dead_url.clone(), connector.clone()).await;
sender.send(reconn_ret).await.unwrap();
data_clone.reconnecting.remove(&dead_url).unwrap();
data_clone.connectors.insert(dead_url.clone(), connector);
});
}
log::info!("reconn_interval tick, done");
@ -355,10 +360,13 @@ impl ManualConnectorManager {
} else if ret.as_ref().unwrap().is_err() {
reconn_ret = Err(ret.unwrap().unwrap_err());
}
data.global_ctx.issue_event(GlobalCtxEvent::ConnectError(
dead_url.clone(),
format!("{:?}", ip_version),
format!("{:?}", reconn_ret),
));
}
}
data.reconnecting.remove(&dead_url).unwrap();
data.connectors.insert(dead_url.clone(), connector);
reconn_ret
}

View File

@ -55,7 +55,11 @@ struct Cli {
)]
network_secret: String,
#[arg(short, long, help = "ipv4 address of this vpn node")]
#[arg(
short,
long,
help = "ipv4 address of this vpn node, if empty, this node will only forward packets and no TUN device will be created"
)]
ipv4: Option<String>,
#[arg(short, long, help = "peers to connect initially")]
@ -417,8 +421,11 @@ pub async fn async_main(cli: Cli) {
print_event(format!("connecting to peer. dst: {}", dst));
}
GlobalCtxEvent::ConnectError(dst, err) => {
print_event(format!("connect to peer error. dst: {}, err: {}", dst, err));
GlobalCtxEvent::ConnectError(dst, ip_version, err) => {
print_event(format!(
"connect to peer error. dst: {}, ip_version: {}, err: {}",
dst, ip_version, err
));
}
GlobalCtxEvent::VpnPortalClientConnected(portal, client_addr) => {

View File

@ -276,11 +276,6 @@ impl Instance {
}
pub async fn run(&mut self) -> Result<(), Error> {
self.prepare_tun_device().await?;
if let Some(ipv4_addr) = self.global_ctx.get_ipv4() {
self.assign_ipv4_to_tun_device(ipv4_addr).await?;
}
self.listener_manager
.lock()
.await
@ -297,7 +292,11 @@ impl Instance {
)?);
self.ip_proxy.as_ref().unwrap().start().await?;
self.run_proxy_cidrs_route_updater();
if let Some(ipv4_addr) = self.global_ctx.get_ipv4() {
self.prepare_tun_device().await?;
self.assign_ipv4_to_tun_device(ipv4_addr).await?;
self.run_proxy_cidrs_route_updater();
}
self.udp_hole_puncher.lock().await.run().await?;