add --connect to cli
This commit is contained in:
parent
7dc0c07578
commit
6bf1710477
21
src/cli.rs
21
src/cli.rs
@ -4,9 +4,9 @@ use hbb_common::{
|
|||||||
log,
|
log,
|
||||||
message_proto::*,
|
message_proto::*,
|
||||||
protobuf::Message as _,
|
protobuf::Message as _,
|
||||||
|
rendezvous_proto::ConnType,
|
||||||
tokio::{self, sync::mpsc},
|
tokio::{self, sync::mpsc},
|
||||||
Stream,
|
Stream,
|
||||||
rendezvous_proto::ConnType,
|
|
||||||
};
|
};
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
@ -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::<Data>();
|
||||||
|
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")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
pub async fn start_one_port_forward(
|
pub async fn start_one_port_forward(
|
||||||
id: String,
|
id: String,
|
||||||
|
@ -36,6 +36,7 @@ fn main() {
|
|||||||
use hbb_common::log;
|
use hbb_common::log;
|
||||||
let args = format!(
|
let args = format!(
|
||||||
"-p, --port-forward=[PORT-FORWARD-OPTIONS] 'Format: remote-id:local-port:remote-port[:remote-host]'
|
"-p, --port-forward=[PORT-FORWARD-OPTIONS] 'Format: remote-id:local-port:remote-port[:remote-host]'
|
||||||
|
-c, --connect=[REMOTE_ID] 'test only'
|
||||||
-k, --key=[KEY] ''
|
-k, --key=[KEY] ''
|
||||||
-s, --server... 'Start server'",
|
-s, --server... 'Start server'",
|
||||||
);
|
);
|
||||||
@ -83,6 +84,12 @@ fn main() {
|
|||||||
key,
|
key,
|
||||||
token,
|
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") {
|
} else if let Some(p) = matches.value_of("server") {
|
||||||
crate::start_server(true);
|
crate::start_server(true);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user