From 7aaa2d7aeb2fc5ebda02b1466afcc1ccc5822a7a Mon Sep 17 00:00:00 2001 From: open-trade Date: Mon, 21 Sep 2020 22:56:38 +0800 Subject: [PATCH] software_url --- libs/hbb_common | 2 +- src/main.rs | 10 +++++++++- src/rendezvous_server.rs | 20 +++++++++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/libs/hbb_common b/libs/hbb_common index e4313f5..ce6dd55 160000 --- a/libs/hbb_common +++ b/libs/hbb_common @@ -1 +1 @@ -Subproject commit e4313f5f0f317fecfb0e8d2dbf2be62ae99edc90 +Subproject commit ce6dd559f2fb56314fdef1e2e435c0381632f1b3 diff --git a/src/main.rs b/src/main.rs index 00f04a0..c66bb9c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ async fn main() -> ResultType<()> { -p, --port=[NUMBER(default={})] 'Sets the listening port' -s, --serial=[NUMBER(default={0})] 'Sets configure update serial number' -R, --rendezvous-servers=[HOSTS] 'Sets rendezvous servers, seperated by colon' + -u, --software-url=[URL] 'Sets download url of RustDesk software of newest version' -r, --relay-server=[HOST] 'Sets the default relay server'", DEFAULT_PORT ); @@ -59,6 +60,13 @@ async fn main() -> ResultType<()> { log::info!("relay-server={}", relay_server); log::info!("serial={}", serial); log::info!("rendzvous-servers={:?}", rendezvous_servers); - RendezvousServer::start(&addr, relay_server, serial, rendezvous_servers).await?; + RendezvousServer::start( + &addr, + relay_server, + serial, + rendezvous_servers, + get_arg("software-url", ""), + ) + .await?; Ok(()) } diff --git a/src/rendezvous_server.rs b/src/rendezvous_server.rs index b649b81..e8fbff8 100644 --- a/src/rendezvous_server.rs +++ b/src/rendezvous_server.rs @@ -2,7 +2,6 @@ use hbb_common::{ allow_err, bytes::{Bytes, BytesMut}, bytes_codec::BytesCodec, - config::Config, futures_util::{ sink::SinkExt, stream::{SplitSink, StreamExt}, @@ -129,6 +128,8 @@ pub struct RendezvousServer { relay_server: String, serial: i32, rendezvous_servers: Vec, + version: String, + software_url: String, } impl RendezvousServer { @@ -137,6 +138,7 @@ impl RendezvousServer { relay_server: String, serial: i32, rendezvous_servers: Vec, + software_url: String, ) -> ResultType<()> { let mut socket = FramedSocket::new(addr).await?; let (tx, mut rx) = mpsc::unbounded_channel::<(RendezvousMessage, SocketAddr)>(); @@ -147,6 +149,8 @@ impl RendezvousServer { relay_server, serial, rendezvous_servers, + version: hbb_common::get_version_from_url(&software_url), + software_url, }; let mut listener = new_listener(addr, false).await?; loop { @@ -303,6 +307,16 @@ impl RendezvousServer { ); } } + Some(rendezvous_message::Union::software_update(su)) => { + if !self.version.is_empty() && su.url != self.version { + let mut msg_out = RendezvousMessage::new(); + msg_out.set_software_update(SoftwareUpdate { + url: self.software_url.clone(), + ..Default::default() + }); + socket.send(&msg_out, addr).await?; + } + } _ => {} } } @@ -561,8 +575,8 @@ impl RendezvousServer { pub fn test_if_valid_server(host: &str) -> ResultType { if host.contains(":") { - Config::to_socket_addr(host) + hbb_common::to_socket_addr(host) } else { - Config::to_socket_addr(&format!("{}:{}", host, 0)) + hbb_common::to_socket_addr(&format!("{}:{}", host, 0)) } }