rustdesk-server/mod.rs

46 lines
1.1 KiB
Rust
Raw Normal View History

2021-03-19 17:25:58 +08:00
mod src;
pub use src::*;
2021-03-19 17:29:08 +08:00
use hbb_common::{allow_err, log};
use std::sync::{Arc, Mutex};
lazy_static::lazy_static! {
static ref STOP: Arc<Mutex<bool>> = Arc::new(Mutex::new(true));
}
2021-04-03 22:32:14 +08:00
pub fn bootstrap(key: &str, host: &str) {
2021-03-19 17:29:08 +08:00
let port = rendezvous_server::DEFAULT_PORT;
let addr = format!("0.0.0.0:{}", port);
let addr2 = format!("0.0.0.0:{}", port.parse::<i32>().unwrap_or(0) - 1);
2021-03-22 17:46:13 +08:00
let relay_servers: Vec<String> = vec![format!("{}:{}", host, relay_server::DEFAULT_PORT)];
2021-04-03 22:32:14 +08:00
let tmp_key = key.to_owned();
2021-03-19 17:29:08 +08:00
std::thread::spawn(move || {
allow_err!(rendezvous_server::RendezvousServer::start(
&addr,
&addr2,
relay_servers,
0,
Default::default(),
Default::default(),
2021-04-03 22:32:14 +08:00
&tmp_key,
2021-03-19 17:29:08 +08:00
STOP.clone(),
));
});
2021-04-03 22:32:14 +08:00
let tmp_key = key.to_owned();
2021-03-22 17:46:13 +08:00
std::thread::spawn(move || {
2021-03-19 17:29:08 +08:00
allow_err!(relay_server::start(
relay_server::DEFAULT_PORT,
2021-04-03 22:32:14 +08:00
&tmp_key,
2021-03-19 17:29:08 +08:00
STOP.clone()
));
});
}
pub fn stop() {
*STOP.lock().unwrap() = true;
}
2021-03-25 18:46:52 +08:00
pub fn start() {
*STOP.lock().unwrap() = false;
}