Browse Source

change-id option

opentrade 4 years ago
parent
commit
92bd9c3250
3 changed files with 11 additions and 2 deletions
  1. 1 1
      libs/hbb_common
  2. 3 0
      src/main.rs
  3. 7 1
      src/rendezvous_server.rs

+ 1 - 1
libs/hbb_common

@@ -1 +1 @@
1
-Subproject commit 4d5b935f16abe33e106b13f30877edb2960f53e9
1
+Subproject commit 20bea85903acbd701aed45d195e9206f2ea09edf

+ 3 - 0
src/main.rs

@@ -16,6 +16,7 @@ fn main() -> ResultType<()> {
16
         -R, --rendezvous-servers=[HOSTS] 'Sets rendezvous servers, seperated by colon'
16
         -R, --rendezvous-servers=[HOSTS] 'Sets rendezvous servers, seperated by colon'
17
         -u, --software-url=[URL] 'Sets download url of RustDesk software of newest version'
17
         -u, --software-url=[URL] 'Sets download url of RustDesk software of newest version'
18
         -r, --relay-servers=[HOST] 'Sets the default relay servers, seperated by colon'
18
         -r, --relay-servers=[HOST] 'Sets the default relay servers, seperated by colon'
19
+        -C, --change-id=[BOOL(default=Y)] 'Sets if support to change id'
19
         -k, --key=[KEY] 'Only allow the client with the same key'",
20
         -k, --key=[KEY] 'Only allow the client with the same key'",
20
         DEFAULT_PORT,
21
         DEFAULT_PORT,
21
     );
22
     );
@@ -50,6 +51,7 @@ fn main() -> ResultType<()> {
50
         .map(|x| x.to_owned())
51
         .map(|x| x.to_owned())
51
         .collect();
52
         .collect();
52
     let serial: i32 = get_arg("serial", "").parse().unwrap_or(0);
53
     let serial: i32 = get_arg("serial", "").parse().unwrap_or(0);
54
+    let id_change_support: bool = get_arg("change-id", "Y").to_uppercase() == "Y";
53
     let rendezvous_servers: Vec<String> = get_arg("rendezvous-servers", "")
55
     let rendezvous_servers: Vec<String> = get_arg("rendezvous-servers", "")
54
         .split(",")
56
         .split(",")
55
         .filter(|x| !x.is_empty() && test_if_valid_server(x, "rendezvous-server").is_ok())
57
         .filter(|x| !x.is_empty() && test_if_valid_server(x, "rendezvous-server").is_ok())
@@ -69,6 +71,7 @@ fn main() -> ResultType<()> {
69
         get_arg("software-url", ""),
71
         get_arg("software-url", ""),
70
         &get_arg("key", ""),
72
         &get_arg("key", ""),
71
         stop,
73
         stop,
74
+        id_change_support,
72
     )?;
75
     )?;
73
     Ok(())
76
     Ok(())
74
 }
77
 }

+ 7 - 1
src/rendezvous_server.rs

@@ -164,6 +164,7 @@ impl RendezvousServer {
164
         software_url: String,
164
         software_url: String,
165
         key: &str,
165
         key: &str,
166
         stop: Arc<Mutex<bool>>,
166
         stop: Arc<Mutex<bool>>,
167
+        id_change_support: bool,
167
     ) -> ResultType<()> {
168
     ) -> ResultType<()> {
168
         if !key.is_empty() {
169
         if !key.is_empty() {
169
             log::info!("Key: {}", key);
170
             log::info!("Key: {}", key);
@@ -171,6 +172,7 @@ impl RendezvousServer {
171
         log::info!("Listening on tcp/udp {}", addr);
172
         log::info!("Listening on tcp/udp {}", addr);
172
         log::info!("Listening on tcp {}, extra port for NAT test", addr2);
173
         log::info!("Listening on tcp {}, extra port for NAT test", addr2);
173
         log::info!("relay-servers={:?}", relay_servers);
174
         log::info!("relay-servers={:?}", relay_servers);
175
+        log::info!("change-id={:?}", id_change_support);
174
         let mut socket = FramedSocket::new(addr).await?;
176
         let mut socket = FramedSocket::new(addr).await?;
175
         let (tx, mut rx) = mpsc::unbounded_channel::<(RendezvousMessage, SocketAddr)>();
177
         let (tx, mut rx) = mpsc::unbounded_channel::<(RendezvousMessage, SocketAddr)>();
176
         let version = hbb_common::get_version_from_url(&software_url);
178
         let version = hbb_common::get_version_from_url(&software_url);
@@ -202,6 +204,7 @@ impl RendezvousServer {
202
                 &mut socket,
204
                 &mut socket,
203
                 key,
205
                 key,
204
                 stop.clone(),
206
                 stop.clone(),
207
+                id_change_support,
205
             )
208
             )
206
             .await;
209
             .await;
207
         }
210
         }
@@ -215,6 +218,7 @@ impl RendezvousServer {
215
         socket: &mut FramedSocket,
218
         socket: &mut FramedSocket,
216
         key: &str,
219
         key: &str,
217
         stop: Arc<Mutex<bool>>,
220
         stop: Arc<Mutex<bool>>,
221
+        id_change_support: bool,
218
     ) {
222
     ) {
219
         let mut timer = interval(Duration::from_millis(100));
223
         let mut timer = interval(Duration::from_millis(100));
220
         loop {
224
         loop {
@@ -326,7 +330,9 @@ impl RendezvousServer {
326
                                             break;
330
                                             break;
327
                                         }
331
                                         }
328
                                         let mut res = register_pk_response::Result::OK;
332
                                         let mut res = register_pk_response::Result::OK;
329
-                                        if let Some(peer) = rs.pm.get(&rk.id).await {
333
+                                        if !id_change_support {
334
+                                            res = register_pk_response::Result::NOT_SUPPORT;
335
+                                        } else if let Some(peer) = rs.pm.get(&rk.id).await {
330
                                             if peer.uuid != rk.uuid {
336
                                             if peer.uuid != rk.uuid {
331
                                                 res = register_pk_response::Result::ID_EXISTS;
337
                                                 res = register_pk_response::Result::ID_EXISTS;
332
                                             }
338
                                             }