From 6bf17104775636d1bbd9a03fc5fb10170df586df Mon Sep 17 00:00:00 2001 From: rustdesk Date: Thu, 29 Dec 2022 11:18:03 +0800 Subject: [PATCH] add --connect to cli --- src/cli.rs | 23 +++++++++++++++++++++-- src/main.rs | 7 +++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index e16c20f74..b4f552d5f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -4,9 +4,9 @@ use hbb_common::{ log, message_proto::*, protobuf::Message as _, + rendezvous_proto::ConnType, tokio::{self, sync::mpsc}, Stream, - rendezvous_proto::ConnType, }; use std::sync::{Arc, RwLock}; @@ -44,7 +44,7 @@ impl Interface for Session { fn get_login_config_handler(&self) -> Arc> { return self.lc.clone(); } - + fn msgbox(&self, msgtype: &str, title: &str, text: &str, link: &str) { if msgtype == "input-password" { self.sender @@ -86,6 +86,25 @@ impl Interface for Session { } } +#[tokio::main(flavor = "current_thread")] +pub async fn connect_test( + id: &str, + key: String, + token: String, +) { + let (sender, mut receiver) = mpsc::unbounded_channel::(); + let handler = Session::new(&id, sender); + if let Err(err) = crate::client::Client::start( + id, + &key, + &token, + ConnType::PORT_FORWARD, + handler, + ).await { + log::error!("Failed to connect {}: {}", &id, err); + } +} + #[tokio::main(flavor = "current_thread")] pub async fn start_one_port_forward( id: String, diff --git a/src/main.rs b/src/main.rs index dfb64a7ca..ca0bc2234 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,6 +36,7 @@ fn main() { use hbb_common::log; let args = format!( "-p, --port-forward=[PORT-FORWARD-OPTIONS] 'Format: remote-id:local-port:remote-port[:remote-host]' + -c, --connect=[REMOTE_ID] 'test only' -k, --key=[KEY] '' -s, --server... 'Start server'", ); @@ -83,6 +84,12 @@ fn main() { key, token, ); + } else if let Some(p) = matches.value_of("connect") { + common::test_rendezvous_server(); + common::test_nat_type(); + let key = matches.value_of("key").unwrap_or("").to_owned(); + let token = LocalConfig::get_option("access_token"); + cli::connect_test(p, key, token); } else if let Some(p) = matches.value_of("server") { crate::start_server(true); }