Browse Source

prepare sled

open-trade 5 years ago
parent
commit
b06f9d22ac
4 changed files with 191 additions and 17 deletions
  1. 152 0
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 1 1
      libs/hbb_common
  4. 37 16
      src/rendezvous_server.rs

+ 152 - 0
Cargo.lock

@@ -28,6 +28,11 @@ dependencies = [
28 28
  "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
29 29
 ]
30 30
 
31
+[[package]]
32
+name = "autocfg"
33
+version = "1.0.0"
34
+source = "registry+https://github.com/rust-lang/crates.io-index"
35
+
31 36
 [[package]]
32 37
 name = "base64"
33 38
 version = "0.11.0"
@@ -43,6 +48,11 @@ name = "bumpalo"
43 48
 version = "3.2.1"
44 49
 source = "registry+https://github.com/rust-lang/crates.io-index"
45 50
 
51
+[[package]]
52
+name = "byteorder"
53
+version = "1.3.4"
54
+source = "registry+https://github.com/rust-lang/crates.io-index"
55
+
46 56
 [[package]]
47 57
 name = "bytes"
48 58
 version = "0.5.4"
@@ -61,6 +71,14 @@ name = "cfg-if"
61 71
 version = "0.1.10"
62 72
 source = "registry+https://github.com/rust-lang/crates.io-index"
63 73
 
74
+[[package]]
75
+name = "cloudabi"
76
+version = "0.0.3"
77
+source = "registry+https://github.com/rust-lang/crates.io-index"
78
+dependencies = [
79
+ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
80
+]
81
+
64 82
 [[package]]
65 83
 name = "core-foundation"
66 84
 version = "0.7.0"
@@ -75,6 +93,38 @@ name = "core-foundation-sys"
75 93
 version = "0.7.0"
76 94
 source = "registry+https://github.com/rust-lang/crates.io-index"
77 95
 
96
+[[package]]
97
+name = "crc32fast"
98
+version = "1.2.0"
99
+source = "registry+https://github.com/rust-lang/crates.io-index"
100
+dependencies = [
101
+ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
102
+]
103
+
104
+[[package]]
105
+name = "crossbeam-epoch"
106
+version = "0.8.2"
107
+source = "registry+https://github.com/rust-lang/crates.io-index"
108
+dependencies = [
109
+ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
110
+ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
111
+ "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
112
+ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
113
+ "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
114
+ "memoffset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
115
+ "scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
116
+]
117
+
118
+[[package]]
119
+name = "crossbeam-utils"
120
+version = "0.7.2"
121
+source = "registry+https://github.com/rust-lang/crates.io-index"
122
+dependencies = [
123
+ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
124
+ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
125
+ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
126
+]
127
+
78 128
 [[package]]
79 129
 name = "ct-logs"
80 130
 version = "0.6.0"
@@ -113,6 +163,15 @@ name = "fnv"
113 163
 version = "1.0.6"
114 164
 source = "registry+https://github.com/rust-lang/crates.io-index"
115 165
 
166
+[[package]]
167
+name = "fs2"
168
+version = "0.4.3"
169
+source = "registry+https://github.com/rust-lang/crates.io-index"
170
+dependencies = [
171
+ "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)",
172
+ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
173
+]
174
+
116 175
 [[package]]
117 176
 name = "fuchsia-zircon"
118 177
 version = "0.3.3"
@@ -213,6 +272,14 @@ dependencies = [
213 272
  "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
214 273
 ]
215 274
 
275
+[[package]]
276
+name = "fxhash"
277
+version = "0.2.1"
278
+source = "registry+https://github.com/rust-lang/crates.io-index"
279
+dependencies = [
280
+ "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
281
+]
282
+
216 283
 [[package]]
217 284
 name = "getrandom"
218 285
 version = "0.1.14"
@@ -252,6 +319,7 @@ name = "hbbs"
252 319
 version = "0.1.0"
253 320
 dependencies = [
254 321
  "hbb_common 0.1.0",
322
+ "sled 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)",
255 323
 ]
256 324
 
257 325
 [[package]]
@@ -313,6 +381,14 @@ name = "libc"
313 381
 version = "0.2.69"
314 382
 source = "registry+https://github.com/rust-lang/crates.io-index"
315 383
 
384
+[[package]]
385
+name = "lock_api"
386
+version = "0.3.4"
387
+source = "registry+https://github.com/rust-lang/crates.io-index"
388
+dependencies = [
389
+ "scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
390
+]
391
+
316 392
 [[package]]
317 393
 name = "log"
318 394
 version = "0.4.8"
@@ -321,11 +397,24 @@ dependencies = [
321 397
  "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
322 398
 ]
323 399
 
400
+[[package]]
401
+name = "maybe-uninit"
402
+version = "2.0.0"
403
+source = "registry+https://github.com/rust-lang/crates.io-index"
404
+
324 405
 [[package]]
325 406
 name = "memchr"
326 407
 version = "2.3.3"
327 408
 source = "registry+https://github.com/rust-lang/crates.io-index"
328 409
 
410
+[[package]]
411
+name = "memoffset"
412
+version = "0.5.4"
413
+source = "registry+https://github.com/rust-lang/crates.io-index"
414
+dependencies = [
415
+ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
416
+]
417
+
329 418
 [[package]]
330 419
 name = "mio"
331 420
 version = "0.6.22"
@@ -414,6 +503,28 @@ name = "openssl-probe"
414 503
 version = "0.1.2"
415 504
 source = "registry+https://github.com/rust-lang/crates.io-index"
416 505
 
506
+[[package]]
507
+name = "parking_lot"
508
+version = "0.10.2"
509
+source = "registry+https://github.com/rust-lang/crates.io-index"
510
+dependencies = [
511
+ "lock_api 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
512
+ "parking_lot_core 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
513
+]
514
+
515
+[[package]]
516
+name = "parking_lot_core"
517
+version = "0.7.2"
518
+source = "registry+https://github.com/rust-lang/crates.io-index"
519
+dependencies = [
520
+ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
521
+ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
522
+ "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)",
523
+ "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
524
+ "smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
525
+ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
526
+]
527
+
417 528
 [[package]]
418 529
 name = "pin-project"
419 530
 version = "0.4.16"
@@ -672,6 +783,11 @@ dependencies = [
672 783
  "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
673 784
 ]
674 785
 
786
+[[package]]
787
+name = "scopeguard"
788
+version = "1.1.0"
789
+source = "registry+https://github.com/rust-lang/crates.io-index"
790
+
675 791
 [[package]]
676 792
 name = "sct"
677 793
 version = "0.6.0"
@@ -716,6 +832,26 @@ name = "slab"
716 832
 version = "0.4.2"
717 833
 source = "registry+https://github.com/rust-lang/crates.io-index"
718 834
 
835
+[[package]]
836
+name = "sled"
837
+version = "0.31.0"
838
+source = "registry+https://github.com/rust-lang/crates.io-index"
839
+dependencies = [
840
+ "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
841
+ "crossbeam-epoch 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
842
+ "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
843
+ "fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
844
+ "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
845
+ "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)",
846
+ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
847
+ "parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
848
+]
849
+
850
+[[package]]
851
+name = "smallvec"
852
+version = "1.4.0"
853
+source = "registry+https://github.com/rust-lang/crates.io-index"
854
+
719 855
 [[package]]
720 856
 name = "socket2"
721 857
 version = "0.3.12"
@@ -1018,18 +1154,25 @@ dependencies = [
1018 1154
 "checksum anyhow 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "d9a60d744a80c30fcb657dfe2c1b22bcb3e814c1a1e3674f32bf5820b570fbff"
1019 1155
 "checksum arc-swap 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b585a98a234c46fc563103e9278c9391fde1f4e6850334da895d27edb9580f62"
1020 1156
 "checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
1157
+"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
1021 1158
 "checksum base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
1022 1159
 "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
1023 1160
 "checksum bumpalo 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "12ae9db68ad7fac5fe51304d20f016c911539251075a214f8e663babefa35187"
1161
+"checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
1024 1162
 "checksum bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1"
1025 1163
 "checksum cc 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)" = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d"
1026 1164
 "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
1165
+"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
1027 1166
 "checksum core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171"
1028 1167
 "checksum core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac"
1168
+"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1"
1169
+"checksum crossbeam-epoch 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace"
1170
+"checksum crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
1029 1171
 "checksum ct-logs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4d3686f5fa27dbc1d76c751300376e167c5a43387f44bb451fd1c24776e49113"
1030 1172
 "checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
1031 1173
 "checksum err-derive 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "22deed3a8124cff5fa835713fa105621e43bbdc46690c3a6b68328a012d350d4"
1032 1174
 "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
1175
+"checksum fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213"
1033 1176
 "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
1034 1177
 "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
1035 1178
 "checksum futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1e05b85ec287aac0dc34db7d4a569323df697f9c55b99b15d6b4ef8cde49f613"
@@ -1041,6 +1184,7 @@ dependencies = [
1041 1184
 "checksum futures-sink 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc"
1042 1185
 "checksum futures-task 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626"
1043 1186
 "checksum futures-util 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6"
1187
+"checksum fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
1044 1188
 "checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
1045 1189
 "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
1046 1190
 "checksum hermit-abi 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4"
@@ -1051,8 +1195,11 @@ dependencies = [
1051 1195
 "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
1052 1196
 "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
1053 1197
 "checksum libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)" = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
1198
+"checksum lock_api 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75"
1054 1199
 "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
1200
+"checksum maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
1055 1201
 "checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
1202
+"checksum memoffset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b4fc2c02a7e374099d4ee95a193111f72d2110197fe200272371758f6c3643d8"
1056 1203
 "checksum mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)" = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430"
1057 1204
 "checksum mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3"
1058 1205
 "checksum mio-uds 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0"
@@ -1062,6 +1209,8 @@ dependencies = [
1062 1209
 "checksum num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
1063 1210
 "checksum once_cell 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b"
1064 1211
 "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
1212
+"checksum parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e"
1213
+"checksum parking_lot_core 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3"
1065 1214
 "checksum pin-project 0.4.16 (registry+https://github.com/rust-lang/crates.io-index)" = "81d480cb4e89522ccda96d0eed9af94180b7a5f93fb28f66e1fd7d68431663d1"
1066 1215
 "checksum pin-project-internal 0.4.16 (registry+https://github.com/rust-lang/crates.io-index)" = "a82996f11efccb19b685b14b5df818de31c1edcee3daa256ab5775dd98e72feb"
1067 1216
 "checksum pin-project-lite 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f7505eeebd78492e0f6108f7171c4948dbb120ee8119d9d77d0afa5469bef67f"
@@ -1091,11 +1240,14 @@ dependencies = [
1091 1240
 "checksum rustls-native-certs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a75ffeb84a6bd9d014713119542ce415db3a3e4748f0bfce1e1416cd224a23a5"
1092 1241
 "checksum rustversion 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bba175698996010c4f6dce5e7f173b6eb781fce25d2cfc45e27091ce0b79f6"
1093 1242
 "checksum schannel 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75"
1243
+"checksum scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
1094 1244
 "checksum sct 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c"
1095 1245
 "checksum security-framework 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535"
1096 1246
 "checksum security-framework-sys 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405"
1097 1247
 "checksum signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41"
1098 1248
 "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
1249
+"checksum sled 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8fb6824dde66ad33bf20c6e8476f5b82b871bc8bc3c129a10ea2f7dae5060fa3"
1250
+"checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4"
1099 1251
 "checksum socket2 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)" = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918"
1100 1252
 "checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
1101 1253
 "checksum syn 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "e8e5aa70697bb26ee62214ae3288465ecec0000f05182f039b477001f08f5ae7"

+ 1 - 0
Cargo.toml

@@ -8,6 +8,7 @@ edition = "2018"
8 8
 
9 9
 [dependencies]
10 10
 hbb_common = { path = "libs/hbb_common" }
11
+sled = "0.31"
11 12
 
12 13
 [workspace]
13 14
 members = ["libs/hbb_common"]

+ 1 - 1
libs/hbb_common

@@ -1 +1 @@
1
-Subproject commit 56827464aa46ec0ecb83944d7b783fb95a93f74c
1
+Subproject commit 9223a153ae04d415ca88cae7866833c39ba5e604

+ 37 - 16
src/rendezvous_server.rs

@@ -23,35 +23,57 @@ use std::{
23 23
     time::Instant,
24 24
 };
25 25
 
26
-pub struct Peer {
26
+struct Peer {
27 27
     socket_addr: SocketAddr,
28 28
     last_reg_time: Instant,
29 29
 }
30 30
 
31
-type PeerMap = HashMap<String, Peer>;
31
+struct PeerMap {
32
+    map: HashMap<String, Peer>,
33
+    db: sled::Db,
34
+}
35
+
36
+impl PeerMap {
37
+    fn new() -> ResultType<Self> {
38
+        Ok(Self {
39
+            map: HashMap::new(),
40
+            db: sled::open("./sled.db")?,
41
+        })
42
+    }
43
+
44
+    fn insert(&mut self, key: String, peer: Peer) {
45
+        self.map.insert(key, peer);
46
+    }
47
+
48
+    fn get(&self, key: &str) -> Option<&Peer> {
49
+        self.map.get(key)
50
+    }
51
+}
52
+
32 53
 const REG_TIMEOUT: i32 = 30_000;
54
+type Sink = SplitSink<Framed<TcpStream, BytesCodec>, Bytes>;
33 55
 
56
+#[derive(Clone)]
34 57
 pub struct RendezvousServer {
35
-    peer_map: PeerMap,
36
-    tcp_punch: Arc<Mutex<HashMap<SocketAddr, SplitSink<Framed<TcpStream, BytesCodec>, Bytes>>>>,
58
+    tcp_punch: Arc<Mutex<HashMap<SocketAddr, Sink>>>,
37 59
 }
38 60
 
39 61
 impl RendezvousServer {
40 62
     pub async fn start(addr: &str) -> ResultType<()> {
63
+        let mut pm = PeerMap::new()?;
41 64
         let mut socket = FramedSocket::new(addr).await?;
42 65
         let mut rs = Self {
43
-            peer_map: PeerMap::new(),
44 66
             tcp_punch: Arc::new(Mutex::new(HashMap::new())),
45 67
         };
46 68
         let (tx, mut rx) = mpsc::unbounded_channel::<(SocketAddr, String)>();
47
-        let mut listener = new_listener(addr, true).await.unwrap();
69
+        let mut listener = new_listener(addr, true).await?;
48 70
         loop {
49 71
             tokio::select! {
50 72
                 Some((addr, id)) = rx.recv() => {
51
-                    allow_err!(rs.handle_punch_hole_request(addr, &id, &mut socket, true).await);
73
+                    allow_err!(rs.handle_punch_hole_request(addr, &id, &mut socket, true, &pm).await);
52 74
                 }
53 75
                 Some(Ok((bytes, addr))) = socket.next() => {
54
-                    allow_err!(rs.handle_msg(&bytes, addr, &mut socket).await);
76
+                    allow_err!(rs.handle_msg(&bytes, addr, &mut socket, &mut pm).await);
55 77
                 }
56 78
                 Ok((stream, addr)) = listener.accept() => {
57 79
                     log::debug!("Tcp connection from {:?}", addr);
@@ -59,10 +81,7 @@ impl RendezvousServer {
59 81
                     let tcp_punch = rs.tcp_punch.clone();
60 82
                     tcp_punch.lock().unwrap().insert(addr, a);
61 83
                     let tx = tx.clone();
62
-                    let mut rs = Self {
63
-                        peer_map: PeerMap::new(),
64
-                        tcp_punch: tcp_punch,
65
-                    };
84
+                    let mut rs = rs.clone();
66 85
                     tokio::spawn(async move {
67 86
                         while let Some(Ok(bytes)) = b.next().await {
68 87
                             if let Ok(msg_in) = parse_from_bytes::<RendezvousMessage>(&bytes) {
@@ -90,11 +109,12 @@ impl RendezvousServer {
90 109
         }
91 110
     }
92 111
 
93
-    pub async fn handle_msg(
112
+    async fn handle_msg(
94 113
         &mut self,
95 114
         bytes: &BytesMut,
96 115
         addr: SocketAddr,
97 116
         socket: &mut FramedSocket,
117
+        pm: &mut PeerMap,
98 118
     ) -> ResultType<()> {
99 119
         if let Ok(msg_in) = parse_from_bytes::<RendezvousMessage>(&bytes) {
100 120
             match msg_in.union {
@@ -102,7 +122,7 @@ impl RendezvousServer {
102 122
                     // B registered
103 123
                     if rp.id.len() > 0 {
104 124
                         log::debug!("New peer registered: {:?} {:?}", &rp.id, &addr);
105
-                        self.peer_map.insert(
125
+                        pm.insert(
106 126
                             rp.id,
107 127
                             Peer {
108 128
                                 socket_addr: addr,
@@ -115,7 +135,7 @@ impl RendezvousServer {
115 135
                     }
116 136
                 }
117 137
                 Some(rendezvous_message::Union::punch_hole_request(ph)) => {
118
-                    self.handle_punch_hole_request(addr, &ph.id, socket, false)
138
+                    self.handle_punch_hole_request(addr, &ph.id, socket, false, &pm)
119 139
                         .await?;
120 140
                 }
121 141
                 Some(rendezvous_message::Union::punch_hole_sent(phs)) => {
@@ -190,13 +210,14 @@ impl RendezvousServer {
190 210
         id: &str,
191 211
         socket: &mut FramedSocket,
192 212
         is_tcp: bool,
213
+        pm: &PeerMap,
193 214
     ) -> ResultType<()> {
194 215
         // punch hole request from A, forward to B,
195 216
         // check if in same intranet first,
196 217
         // fetch local addrs if in same intranet.
197 218
         // because punch hole won't work if in the same intranet,
198 219
         // all routers will drop such self-connections.
199
-        if let Some(peer) = self.peer_map.get(id) {
220
+        if let Some(peer) = pm.get(id) {
200 221
             if peer.last_reg_time.elapsed().as_millis() as i32 >= REG_TIMEOUT {
201 222
                 let mut msg_out = RendezvousMessage::new();
202 223
                 msg_out.set_punch_hole_response(PunchHoleResponse {