diff --git a/easytier/src/common/global_ctx.rs b/easytier/src/common/global_ctx.rs index dcd71a6..9a71f10 100644 --- a/easytier/src/common/global_ctx.rs +++ b/easytier/src/common/global_ctx.rs @@ -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) diff --git a/easytier/src/connector/manual.rs b/easytier/src/connector/manual.rs index e5cf808..1feb461 100644 --- a/easytier/src/connector/manual.rs +++ b/easytier/src/connector/manual.rs @@ -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 } diff --git a/easytier/src/easytier-core.rs b/easytier/src/easytier-core.rs index 080f3ba..72d662d 100644 --- a/easytier/src/easytier-core.rs +++ b/easytier/src/easytier-core.rs @@ -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, #[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) => { diff --git a/easytier/src/instance/instance.rs b/easytier/src/instance/instance.rs index 4b38ebc..4a895d0 100644 --- a/easytier/src/instance/instance.rs +++ b/easytier/src/instance/instance.rs @@ -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?;