changed lib's run_sdlan

This commit is contained in:
asxalex 2024-07-14 19:42:10 +08:00
parent d26f9d6d43
commit 878d88836d
3 changed files with 15 additions and 10 deletions

View File

@ -10,8 +10,8 @@ use tokio::sync::oneshot;
async fn main() {
let _guard = log::init_log();
let (tx, rx) = oneshot::channel();
tokio::spawn(run_sdlan(
// let (tx, rx) = oneshot::channel();
let _ = run_sdlan(
CommandLine {
sn: "39.98.184.67:1265".to_owned(),
tcp: "39.98.184.67:18083".to_owned(),
@ -25,11 +25,8 @@ async fn main() {
token: "".to_owned(),
allow_p2p: true,
},
tx,
));
).await;
// waiting edge to be inited
let _ = rx.await;
let edge = get_edge();
edge.start("0".to_owned()).await;
@ -39,11 +36,15 @@ async fn main() {
edge.stop().await;
*/
/*
let mut stream =
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::user_defined1()).unwrap();
let mut started = true;
*/
loop {
tokio::time::sleep(Duration::from_secs(10)).await;
/*
let sig = stream.recv().await;
if started {
edge.stop().await;
@ -51,5 +52,6 @@ async fn main() {
edge.start("0".to_owned()).await;
}
started = !started;
*/
}
}

View File

@ -22,7 +22,7 @@ use sdlan_sn_rs::{
pub async fn run_sdlan(
args: CommandLine,
sender: tokio::sync::oneshot::Sender<bool>,
// sender: tokio::sync::oneshot::Sender<bool>,
// start_stop_sender: Sender<String>,
// start_stop_receiver: Receiver<String>,
) -> Result<()> {
@ -33,7 +33,7 @@ pub async fn run_sdlan(
if let Err(e) = init_edge(&args.token, node_conf, args.tos, start_stop_sender).await {
panic!("failed to init edge: {:?}", e);
}
let _ = sender.send(true);
// let _ = sender.send(true);
debug!("edge inited");
let cancel = CancellationToken::new();

View File

@ -85,13 +85,15 @@ impl ReadWriteActor {
let Ok(mut stream) = TcpStream::connect(&self.remote).await else {
self.connected.store(false, Ordering::Relaxed);
if keep_reconnect {
/*
tokio::select! {
_ = tokio::time::sleep(Duration::from_secs(3)) => {
continue;
}
}
// tokio::time::sleep(Duration::from_secs(3)).await;
// continue;
*/
tokio::time::sleep(Duration::from_secs(3)).await;
continue;
}
return;
};
@ -160,6 +162,7 @@ impl ReadWriteActor {
}
on_disconnected().await;
println!("connect retrying");
tokio::time::sleep(Duration::from_secs(1)).await;
// future::select(read_from_tcp, write_to_tcp).await;
}
}