mirror of
https://mirror.suhoan.cn/https://github.com/EasyTier/EasyTier.git
synced 2025-12-12 20:57:26 +08:00
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:
@@ -31,7 +31,7 @@ pub enum GlobalCtxEvent {
|
|||||||
ConnectionError(String, String, String), // (local url, remote url, error message)
|
ConnectionError(String, String, String), // (local url, remote url, error message)
|
||||||
|
|
||||||
Connecting(url::Url),
|
Connecting(url::Url),
|
||||||
ConnectError(String, String), // (dst, error message)
|
ConnectError(String, String, String), // (dst, ip version, error message)
|
||||||
|
|
||||||
VpnPortalClientConnected(String, String), // (portal, client ip)
|
VpnPortalClientConnected(String, String), // (portal, client ip)
|
||||||
VpnPortalClientDisconnected(String, String), // (portal, client ip)
|
VpnPortalClientDisconnected(String, String), // (portal, client ip)
|
||||||
|
|||||||
@@ -192,8 +192,13 @@ impl ManualConnectorManager {
|
|||||||
let (_, connector) = data.connectors.remove(&dead_url).unwrap();
|
let (_, connector) = data.connectors.remove(&dead_url).unwrap();
|
||||||
let insert_succ = data.reconnecting.insert(dead_url.clone());
|
let insert_succ = data.reconnecting.insert(dead_url.clone());
|
||||||
assert!(insert_succ);
|
assert!(insert_succ);
|
||||||
|
|
||||||
reconn_tasks.spawn(async move {
|
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");
|
log::info!("reconn_interval tick, done");
|
||||||
@@ -355,10 +360,13 @@ impl ManualConnectorManager {
|
|||||||
} else if ret.as_ref().unwrap().is_err() {
|
} else if ret.as_ref().unwrap().is_err() {
|
||||||
reconn_ret = Err(ret.unwrap().unwrap_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
|
reconn_ret
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,11 @@ struct Cli {
|
|||||||
)]
|
)]
|
||||||
network_secret: String,
|
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>,
|
ipv4: Option<String>,
|
||||||
|
|
||||||
#[arg(short, long, help = "peers to connect initially")]
|
#[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));
|
print_event(format!("connecting to peer. dst: {}", dst));
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalCtxEvent::ConnectError(dst, err) => {
|
GlobalCtxEvent::ConnectError(dst, ip_version, err) => {
|
||||||
print_event(format!("connect to peer error. dst: {}, err: {}", dst, err));
|
print_event(format!(
|
||||||
|
"connect to peer error. dst: {}, ip_version: {}, err: {}",
|
||||||
|
dst, ip_version, err
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalCtxEvent::VpnPortalClientConnected(portal, client_addr) => {
|
GlobalCtxEvent::VpnPortalClientConnected(portal, client_addr) => {
|
||||||
|
|||||||
@@ -276,11 +276,6 @@ impl Instance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(&mut self) -> Result<(), Error> {
|
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
|
self.listener_manager
|
||||||
.lock()
|
.lock()
|
||||||
.await
|
.await
|
||||||
@@ -297,7 +292,11 @@ impl Instance {
|
|||||||
)?);
|
)?);
|
||||||
self.ip_proxy.as_ref().unwrap().start().await?;
|
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?;
|
self.udp_hole_puncher.lock().await.run().await?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user