open-trade лет назад: 5
Родитель
Сommit
ba9862cd7f
4 измененных файлов с 82 добавлено и 4 удалено
  1. 52 0
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 22 2
      src/main.rs
  4. 7 2
      src/rendezvous_server.rs

+ 52 - 0
Cargo.lock

@@ -21,6 +21,14 @@ dependencies = [
21 21
  "xml-rs 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
22 22
 ]
23 23
 
24
+[[package]]
25
+name = "ansi_term"
26
+version = "0.11.0"
27
+source = "registry+https://github.com/rust-lang/crates.io-index"
28
+dependencies = [
29
+ "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
30
+]
31
+
24 32
 [[package]]
25 33
 name = "anyhow"
26 34
 version = "1.0.32"
@@ -122,6 +130,20 @@ name = "cfg-if"
122 130
 version = "0.1.10"
123 131
 source = "registry+https://github.com/rust-lang/crates.io-index"
124 132
 
133
+[[package]]
134
+name = "clap"
135
+version = "2.33.3"
136
+source = "registry+https://github.com/rust-lang/crates.io-index"
137
+dependencies = [
138
+ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
139
+ "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
140
+ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
141
+ "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
142
+ "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
143
+ "unicode-width 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
144
+ "vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
145
+]
146
+
125 147
 [[package]]
126 148
 name = "clipboard-win"
127 149
 version = "2.2.0"
@@ -496,6 +518,7 @@ dependencies = [
496 518
 name = "hbbs"
497 519
 version = "0.1.0"
498 520
 dependencies = [
521
+ "clap 2.33.3 (registry+https://github.com/rust-lang/crates.io-index)",
499 522
  "hbb_common 0.1.0",
500 523
  "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
501 524
  "serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1320,6 +1343,11 @@ dependencies = [
1320 1343
  "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
1321 1344
 ]
1322 1345
 
1346
+[[package]]
1347
+name = "strsim"
1348
+version = "0.8.0"
1349
+source = "registry+https://github.com/rust-lang/crates.io-index"
1350
+
1323 1351
 [[package]]
1324 1352
 name = "syn"
1325 1353
 version = "1.0.39"
@@ -1349,6 +1377,14 @@ dependencies = [
1349 1377
  "winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
1350 1378
 ]
1351 1379
 
1380
+[[package]]
1381
+name = "textwrap"
1382
+version = "0.11.0"
1383
+source = "registry+https://github.com/rust-lang/crates.io-index"
1384
+dependencies = [
1385
+ "unicode-width 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
1386
+]
1387
+
1352 1388
 [[package]]
1353 1389
 name = "thread_local"
1354 1390
 version = "1.0.1"
@@ -1440,6 +1476,11 @@ dependencies = [
1440 1476
  "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
1441 1477
 ]
1442 1478
 
1479
+[[package]]
1480
+name = "unicode-width"
1481
+version = "0.1.8"
1482
+source = "registry+https://github.com/rust-lang/crates.io-index"
1483
+
1443 1484
 [[package]]
1444 1485
 name = "unicode-xid"
1445 1486
 version = "0.1.0"
@@ -1455,6 +1496,11 @@ name = "untrusted"
1455 1496
 version = "0.7.1"
1456 1497
 source = "registry+https://github.com/rust-lang/crates.io-index"
1457 1498
 
1499
+[[package]]
1500
+name = "vec_map"
1501
+version = "0.8.2"
1502
+source = "registry+https://github.com/rust-lang/crates.io-index"
1503
+
1458 1504
 [[package]]
1459 1505
 name = "version_check"
1460 1506
 version = "0.9.2"
@@ -1704,6 +1750,7 @@ dependencies = [
1704 1750
 [metadata]
1705 1751
 "checksum aho-corasick 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)" = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86"
1706 1752
 "checksum andrew 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9b7f09f89872c2b6b29e319377b1fbe91c6f5947df19a25596e121cf19a7b35e"
1753
+"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
1707 1754
 "checksum anyhow 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b"
1708 1755
 "checksum approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3"
1709 1756
 "checksum arc-swap 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034"
@@ -1721,6 +1768,7 @@ dependencies = [
1721 1768
 "checksum bytes 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
1722 1769
 "checksum cc 1.0.59 (registry+https://github.com/rust-lang/crates.io-index)" = "66120af515773fb005778dc07c261bd201ec8ce50bd6e7144c927753fe013381"
1723 1770
 "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
1771
+"checksum clap 2.33.3 (registry+https://github.com/rust-lang/crates.io-index)" = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
1724 1772
 "checksum clipboard-win 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e3a093d6fed558e5fe24c3dfc85a68bb68f1c824f440d3ba5aca189e2998786b"
1725 1773
 "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
1726 1774
 "checksum confy 0.4.0 (git+https://github.com/open-trade/confy)" = "<none>"
@@ -1853,9 +1901,11 @@ dependencies = [
1853 1901
 "checksum sodiumoxide 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7038b67c941e23501573cb7242ffb08709abe9b11eb74bceff875bbda024a6a8"
1854 1902
 "checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
1855 1903
 "checksum stb_truetype 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f77b6b07e862c66a9f3e62a07588fee67cd90a9135a2b942409f195507b4fb51"
1904
+"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
1856 1905
 "checksum syn 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "891d8d6567fe7c7f8835a3a98af4208f3846fba258c1bc3c31d6e506239f11f9"
1857 1906
 "checksum synstructure 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701"
1858 1907
 "checksum termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
1908
+"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
1859 1909
 "checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
1860 1910
 "checksum tokio 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd"
1861 1911
 "checksum tokio-macros 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389"
@@ -1864,9 +1914,11 @@ dependencies = [
1864 1914
 "checksum tracing 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c"
1865 1915
 "checksum tracing-attributes 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada"
1866 1916
 "checksum tracing-core 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "4f0e00789804e99b20f12bc7003ca416309d28a6f495d6af58d1e2c2842461b5"
1917
+"checksum unicode-width 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
1867 1918
 "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
1868 1919
 "checksum unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
1869 1920
 "checksum untrusted 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
1921
+"checksum vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
1870 1922
 "checksum version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
1871 1923
 "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
1872 1924
 "checksum walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d"

+ 1 - 0
Cargo.toml

@@ -17,6 +17,7 @@ serde_derive = "1.0"
17 17
 serde = "1.0"
18 18
 serde_json = "1.0"
19 19
 lazy_static = "1.4"
20
+clap = "2.33"
20 21
 
21 22
 [workspace]
22 23
 members = ["libs/hbb_common"]

+ 22 - 2
src/main.rs

@@ -1,14 +1,34 @@
1 1
 // https://tools.ietf.org/rfc/rfc5128.txt
2 2
 // https://blog.csdn.net/bytxl/article/details/44344855
3 3
 
4
+use clap::App;
4 5
 use hbb_common::{env_logger::*, log, tokio, ResultType};
5 6
 use hbbs::*;
7
+const DEFAULT_PORT: &'static str = "21116";
6 8
 
7 9
 #[tokio::main]
8 10
 async fn main() -> ResultType<()> {
9 11
     init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info"));
10
-    let addr = "0.0.0.0:21116";
12
+    let args = format!(
13
+        "-p, --port=[default={}] 'Sets the listening port'
14
+    -r, --relay-server=[] 'Sets the default relay server'",
15
+        DEFAULT_PORT
16
+    );
17
+    let matches = App::new("hbbs")
18
+        .version("1.0")
19
+        .author("Zhou Huabing <info@rustdesk.com>")
20
+        .about("RustDesk Rendezvous Server")
21
+        .args_from_usage(&args)
22
+        .get_matches();
23
+    let addr = format!(
24
+        "0.0.0.0:{}",
25
+        matches.value_of("port").unwrap_or(DEFAULT_PORT)
26
+    );
11 27
     log::info!("Listening on {}", addr);
12
-    RendezvousServer::start(&addr).await?;
28
+    RendezvousServer::start(
29
+        &addr,
30
+        matches.value_of("relay-server").unwrap_or("").to_owned(),
31
+    )
32
+    .await?;
13 33
     Ok(())
14 34
 }

+ 7 - 2
src/rendezvous_server.rs

@@ -125,16 +125,18 @@ pub struct RendezvousServer {
125 125
     tcp_punch: Arc<Mutex<HashMap<SocketAddr, Sink>>>,
126 126
     pm: PeerMap,
127 127
     tx: Sender,
128
+    relay_server: String,
128 129
 }
129 130
 
130 131
 impl RendezvousServer {
131
-    pub async fn start(addr: &str) -> ResultType<()> {
132
+    pub async fn start(addr: &str, relay_server: String) -> ResultType<()> {
132 133
         let mut socket = FramedSocket::new(addr).await?;
133 134
         let (tx, mut rx) = mpsc::unbounded_channel::<(RendezvousMessage, SocketAddr)>();
134 135
         let mut rs = Self {
135 136
             tcp_punch: Arc::new(Mutex::new(HashMap::new())),
136 137
             pm: PeerMap::new()?,
137 138
             tx: tx.clone(),
139
+            relay_server,
138 140
         };
139 141
         let mut listener = new_listener(addr, true).await?;
140 142
         loop {
@@ -347,7 +349,10 @@ impl RendezvousServer {
347 349
             Some(peer) => peer.pk,
348 350
             _ => Vec::new(),
349 351
         };
350
-        let relay_server = phs.relay_server;
352
+        let mut relay_server = phs.relay_server;
353
+        if relay_server.is_empty() {
354
+            relay_server = self.relay_server.clone();
355
+        }
351 356
         msg_out.set_punch_hole_response(PunchHoleResponse {
352 357
             socket_addr: AddrMangle::encode(addr),
353 358
             pk,