more logic in cli connect

This commit is contained in:
rustdesk 2022-12-29 23:27:17 +08:00
parent 9859b4f27d
commit 07e399cf81

View File

@ -1,6 +1,8 @@
use crate::client::*; use crate::client::*;
use hbb_common::{ use hbb_common::{
config::PeerConfig, config::PeerConfig,
config::READ_TIMEOUT,
futures::{SinkExt, StreamExt},
log, log,
message_proto::*, message_proto::*,
protobuf::Message as _, protobuf::Message as _,
@ -87,23 +89,38 @@ impl Interface for Session {
} }
#[tokio::main(flavor = "current_thread")] #[tokio::main(flavor = "current_thread")]
pub async fn connect_test( pub async fn connect_test(id: &str, key: String, token: String) {
id: &str,
key: String,
token: String,
) {
let (sender, mut receiver) = mpsc::unbounded_channel::<Data>(); let (sender, mut receiver) = mpsc::unbounded_channel::<Data>();
let handler = Session::new(&id, sender); let handler = Session::new(&id, sender);
if let Err(err) = crate::client::Client::start( match crate::client::Client::start(id, &key, &token, ConnType::PORT_FORWARD, handler).await {
id, Err(err) => {
&key, log::error!("Failed to connect {}: {}", &id, err);
&token, }
ConnType::PORT_FORWARD, Ok((mut stream, direct)) => {
handler, log::info!("direct: {}", direct);
).await { // rpassword::prompt_password("Input anything to exit").ok();
log::error!("Failed to connect {}: {}", &id, err); loop {
} else { tokio::select! {
// rpassword::prompt_password("Input anything to exit").ok(); res = hbb_common::timeout(READ_TIMEOUT, stream.next()) => match res {
Err(_) => {
log::error!("Timeout");
break;
}
Ok(Some(Ok(bytes))) => {
let msg_in = Message::parse_from_bytes(&bytes).unwrap();
match msg_in.union {
Some(message::Union::Hash(hash)) => {
log::info!("Got hash");
break;
}
_ => {}
}
}
_ => {}
}
}
}
}
} }
} }