open-trade лет назад: 5
Родитель
Сommit
2ee99e6140
3 измененных файлов с 22 добавлено и 17 удалено
  1. 3 3
      Cargo.lock
  2. 1 1
      libs/hbb_common
  3. 18 13
      src/rendezvous_server.rs

+ 3 - 3
Cargo.lock

@@ -141,7 +141,7 @@ dependencies = [
141 141
 [[package]]
142 142
 name = "confy"
143 143
 version = "0.4.0"
144
-source = "registry+https://github.com/rust-lang/crates.io-index"
144
+source = "git+https://github.com/open-trade/confy#a95119c82d1e4e3f1d4b46bd668990eff5dce2c8"
145 145
 dependencies = [
146 146
  "directories 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
147 147
  "serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -465,7 +465,7 @@ version = "0.1.0"
465 465
 dependencies = [
466 466
  "anyhow 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
467 467
  "bytes 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
468
- "confy 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
468
+ "confy 0.4.0 (git+https://github.com/open-trade/confy)",
469 469
  "copypasta 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
470 470
  "directories-next 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
471 471
  "dirs-next 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1722,7 +1722,7 @@ dependencies = [
1722 1722
 "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
1723 1723
 "checksum clipboard-win 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e3a093d6fed558e5fe24c3dfc85a68bb68f1c824f440d3ba5aca189e2998786b"
1724 1724
 "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
1725
-"checksum confy 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2913470204e9e8498a0f31f17f90a0de801ae92c8c5ac18c49af4819e6786697"
1725
+"checksum confy 0.4.0 (git+https://github.com/open-trade/confy)" = "<none>"
1726 1726
 "checksum constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
1727 1727
 "checksum copypasta 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "865e9675691e2a7dfc806b16ef2dd5dd536e26ea9b8046519767d79be03aeb6a"
1728 1728
 "checksum core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171"

+ 1 - 1
libs/hbb_common

@@ -1 +1 @@
1
-Subproject commit 3ac832109bb75284a1d195a47300498e3bddc277
1
+Subproject commit dc39de26981c2916c053762eef6961f6b659fb0c

+ 18 - 13
src/rendezvous_server.rs

@@ -27,6 +27,7 @@ use std::{
27 27
 struct Peer {
28 28
     socket_addr: SocketAddr,
29 29
     last_reg_time: Instant,
30
+    uuid: Vec<u8>,
30 31
     pk: Vec<u8>,
31 32
 }
32 33
 
@@ -37,6 +38,7 @@ impl Default for Peer {
37 38
             last_reg_time: Instant::now()
38 39
                 .checked_sub(std::time::Duration::from_secs(3600))
39 40
                 .unwrap(),
41
+            uuid: Vec::new(),
40 42
             pk: Vec::new(),
41 43
         }
42 44
     }
@@ -47,6 +49,8 @@ struct PeerSerde {
47 49
     #[serde(default)]
48 50
     ip: String,
49 51
     #[serde(default)]
52
+    uuid: Vec<u8>,
53
+    #[serde(default)]
50 54
     pk: Vec<u8>,
51 55
 }
52 56
 
@@ -65,18 +69,19 @@ impl PeerMap {
65 69
     }
66 70
 
67 71
     #[inline]
68
-    fn update_pk(&mut self, id: String, socket_addr: SocketAddr, pk: Vec<u8>) {
72
+    fn update_pk(&mut self, id: String, socket_addr: SocketAddr, uuid: Vec<u8>, pk: Vec<u8>) {
69 73
         let mut lock = self.map.write().unwrap();
70 74
         lock.insert(
71 75
             id.clone(),
72 76
             Peer {
73 77
                 socket_addr,
74 78
                 last_reg_time: Instant::now(),
79
+                uuid: uuid.clone(),
75 80
                 pk: pk.clone(),
76 81
             },
77 82
         );
78 83
         let ip = socket_addr.ip().to_string();
79
-        self.db.insert(id, PeerSerde { ip, pk });
84
+        self.db.insert(id, PeerSerde { ip, uuid, pk });
80 85
     }
81 86
 
82 87
     #[inline]
@@ -91,6 +96,7 @@ impl PeerMap {
91 96
                 self.map.write().unwrap().insert(
92 97
                     id,
93 98
                     Peer {
99
+                        uuid: v.uuid,
94 100
                         pk: v.pk,
95 101
                         ..Default::default()
96 102
                     },
@@ -189,16 +195,14 @@ impl RendezvousServer {
189 195
                     let id = rk.id;
190 196
                     let mut res = register_pk_response::Result::OK;
191 197
                     if let Some(peer) = self.pm.get(&id).await {
192
-                        if peer.pk.is_empty() {
193
-                            self.pm.update_pk(id, addr, rk.pk);
194
-                        } else {
195
-                            if peer.pk != rk.pk {
196
-                                log::warn!("Peer {} pk mismatch: {:?} vs {:?}", id, rk.pk, peer.pk);
197
-                                res = register_pk_response::Result::PK_MISMATCH;
198
-                            }
198
+                        if peer.uuid != rk.uuid {
199
+                            log::warn!("Peer {} pk mismatch: {:?} vs {:?}", id, rk.uuid, peer.uuid);
200
+                            res = register_pk_response::Result::UUID_MISMATCH;
201
+                        } else if peer.pk != rk.pk {
202
+                            self.pm.update_pk(id, addr, rk.uuid, rk.pk);
199 203
                         }
200 204
                     } else {
201
-                        self.pm.update_pk(id, addr, rk.pk);
205
+                        self.pm.update_pk(id, addr, rk.uuid, rk.pk);
202 206
                     }
203 207
                     let mut msg_out = RendezvousMessage::new();
204 208
                     msg_out.set_register_pk_response(RegisterPkResponse {
@@ -260,11 +264,11 @@ impl RendezvousServer {
260 264
             let tx = self.tx.clone();
261 265
             tokio::spawn(async move {
262 266
                 let v = pm.db.get(id.clone()).await;
263
-                let pk = {
267
+                let (uuid, pk) = {
264 268
                     if let Some(v) = super::SledAsync::deserialize::<PeerSerde>(&v) {
265
-                        v.pk
269
+                        (v.uuid, v.pk)
266 270
                     } else {
267
-                        Vec::new()
271
+                        (Vec::new(), Vec::new())
268 272
                     }
269 273
                 };
270 274
                 let mut msg_out = RendezvousMessage::new();
@@ -278,6 +282,7 @@ impl RendezvousServer {
278 282
                     Peer {
279 283
                         socket_addr,
280 284
                         last_reg_time,
285
+                        uuid,
281 286
                         pk,
282 287
                     },
283 288
                 );