mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-29 22:26:26 -04:00
Remove debug code
This commit is contained in:
parent
194aa44362
commit
9608c5154d
@ -10,7 +10,7 @@ use tokio::sync::{mpsc, oneshot, watch, RwLock};
|
|||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
|
|
||||||
pub(crate) struct VpnTaskContext {
|
pub(crate) struct VpnTaskContext {
|
||||||
vpn_handle: Arc<std::sync::RwLock<Option<Vpn>>>,
|
vpn_handle: Arc<RwLock<Option<Vpn>>>,
|
||||||
vpn_state_tx: Arc<watch::Sender<VpnState>>,
|
vpn_state_tx: Arc<watch::Sender<VpnState>>,
|
||||||
disconnect_rx: RwLock<Option<oneshot::Receiver<()>>>,
|
disconnect_rx: RwLock<Option<oneshot::Receiver<()>>>,
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ impl VpnTaskContext {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Save the VPN handle
|
// Save the VPN handle
|
||||||
vpn_handle.write().unwrap().replace(vpn);
|
vpn_handle.write().await.replace(vpn);
|
||||||
|
|
||||||
let vpn_state_tx = self.vpn_state_tx.clone();
|
let vpn_state_tx = self.vpn_state_tx.clone();
|
||||||
let connect_info = Box::new(info.clone());
|
let connect_info = Box::new(info.clone());
|
||||||
@ -57,30 +57,17 @@ impl VpnTaskContext {
|
|||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let vpn_state_tx_clone = vpn_state_tx.clone();
|
let vpn_state_tx_clone = vpn_state_tx.clone();
|
||||||
|
|
||||||
if let Err(err) = vpn_handle.read().map(|vpn| {
|
vpn_handle.blocking_read().as_ref().map(|vpn| {
|
||||||
vpn.as_ref().map(|vpn| {
|
|
||||||
vpn.connect(move || {
|
vpn.connect(move || {
|
||||||
let connect_info = Box::new(info.clone());
|
let connect_info = Box::new(info.clone());
|
||||||
vpn_state_tx.send(VpnState::Connected(connect_info)).ok();
|
vpn_state_tx.send(VpnState::Connected(connect_info)).ok();
|
||||||
})
|
})
|
||||||
})
|
});
|
||||||
}) {
|
|
||||||
info!("VPN connect failed: {:?}", err);
|
|
||||||
}
|
|
||||||
// .as_ref().map(|vpn| {
|
|
||||||
// vpn.connect(move || {
|
|
||||||
// let connect_info = Box::new(info.clone());
|
|
||||||
// vpn_state_tx.send(VpnState::Connected(connect_info)).ok();
|
|
||||||
// })
|
|
||||||
// });
|
|
||||||
|
|
||||||
// println!("VPN connect result: {:?}", ret);
|
|
||||||
|
|
||||||
// Notify the VPN is disconnected
|
// Notify the VPN is disconnected
|
||||||
vpn_state_tx_clone.send(VpnState::Disconnected).ok();
|
vpn_state_tx_clone.send(VpnState::Disconnected).ok();
|
||||||
// Remove the VPN handle
|
// Remove the VPN handle
|
||||||
// vpn_handle.blocking_write().take();
|
vpn_handle.blocking_write().take();
|
||||||
vpn_handle.write().unwrap().take();
|
|
||||||
|
|
||||||
disconnect_tx.send(()).ok();
|
disconnect_tx.send(()).ok();
|
||||||
});
|
});
|
||||||
@ -89,7 +76,7 @@ impl VpnTaskContext {
|
|||||||
pub async fn disconnect(&self) {
|
pub async fn disconnect(&self) {
|
||||||
if let Some(disconnect_rx) = self.disconnect_rx.write().await.take() {
|
if let Some(disconnect_rx) = self.disconnect_rx.write().await.take() {
|
||||||
info!("Disconnecting VPN...");
|
info!("Disconnecting VPN...");
|
||||||
if let Some(vpn) = self.vpn_handle.read().unwrap().as_ref() {
|
if let Some(vpn) = self.vpn_handle.read().await.as_ref() {
|
||||||
info!("VPN is connected, start disconnecting...");
|
info!("VPN is connected, start disconnecting...");
|
||||||
self.vpn_state_tx.send(VpnState::Disconnecting).ok();
|
self.vpn_state_tx.send(VpnState::Disconnecting).ok();
|
||||||
vpn.disconnect()
|
vpn.disconnect()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user