open-trade лет назад: 5
Родитель
Сommit
1695b5e357
11 измененных файлов с 1045 добавлено и 10 удалено
  1. 0 3
      .gitmodules
  2. 604 0
      Cargo.lock
  3. 9 3
      Cargo.toml
  4. 10 0
      build.rs
  5. 0 1
      libs/p2p
  6. 9 0
      protos/message.proto
  7. 2 0
      protos/mod.rs
  8. 5 0
      src/lib.rs
  9. 12 3
      src/main.rs
  10. 301 0
      src/protos/message.rs
  11. 93 0
      src/rendezvous_server.rs

+ 0 - 3
.gitmodules

@@ -1,3 +0,0 @@
1
-[submodule "libs/p2p"]
2
-	path = libs/p2p
3
-	url = https://github.com/open-trade/p2p

+ 604 - 0
Cargo.lock

@@ -0,0 +1,604 @@
1
+# This file is automatically @generated by Cargo.
2
+# It is not intended for manual editing.
3
+[[package]]
4
+name = "aho-corasick"
5
+version = "0.7.9"
6
+source = "registry+https://github.com/rust-lang/crates.io-index"
7
+dependencies = [
8
+ "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
9
+]
10
+
11
+[[package]]
12
+name = "arc-swap"
13
+version = "0.4.4"
14
+source = "registry+https://github.com/rust-lang/crates.io-index"
15
+
16
+[[package]]
17
+name = "atty"
18
+version = "0.2.14"
19
+source = "registry+https://github.com/rust-lang/crates.io-index"
20
+dependencies = [
21
+ "hermit-abi 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
22
+ "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
23
+ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
24
+]
25
+
26
+[[package]]
27
+name = "bitflags"
28
+version = "1.2.1"
29
+source = "registry+https://github.com/rust-lang/crates.io-index"
30
+
31
+[[package]]
32
+name = "bytes"
33
+version = "0.5.4"
34
+source = "registry+https://github.com/rust-lang/crates.io-index"
35
+
36
+[[package]]
37
+name = "cfg-if"
38
+version = "0.1.10"
39
+source = "registry+https://github.com/rust-lang/crates.io-index"
40
+
41
+[[package]]
42
+name = "env_logger"
43
+version = "0.7.1"
44
+source = "registry+https://github.com/rust-lang/crates.io-index"
45
+dependencies = [
46
+ "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
47
+ "humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
48
+ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
49
+ "regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
50
+ "termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
51
+]
52
+
53
+[[package]]
54
+name = "fnv"
55
+version = "1.0.6"
56
+source = "registry+https://github.com/rust-lang/crates.io-index"
57
+
58
+[[package]]
59
+name = "fuchsia-zircon"
60
+version = "0.3.3"
61
+source = "registry+https://github.com/rust-lang/crates.io-index"
62
+dependencies = [
63
+ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
64
+ "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
65
+]
66
+
67
+[[package]]
68
+name = "fuchsia-zircon-sys"
69
+version = "0.3.3"
70
+source = "registry+https://github.com/rust-lang/crates.io-index"
71
+
72
+[[package]]
73
+name = "futures"
74
+version = "0.3.4"
75
+source = "registry+https://github.com/rust-lang/crates.io-index"
76
+dependencies = [
77
+ "futures-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
78
+ "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
79
+ "futures-executor 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
80
+ "futures-io 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
81
+ "futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
82
+ "futures-task 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
83
+ "futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
84
+]
85
+
86
+[[package]]
87
+name = "futures-channel"
88
+version = "0.3.4"
89
+source = "registry+https://github.com/rust-lang/crates.io-index"
90
+dependencies = [
91
+ "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
92
+ "futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
93
+]
94
+
95
+[[package]]
96
+name = "futures-core"
97
+version = "0.3.4"
98
+source = "registry+https://github.com/rust-lang/crates.io-index"
99
+
100
+[[package]]
101
+name = "futures-executor"
102
+version = "0.3.4"
103
+source = "registry+https://github.com/rust-lang/crates.io-index"
104
+dependencies = [
105
+ "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
106
+ "futures-task 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
107
+ "futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
108
+]
109
+
110
+[[package]]
111
+name = "futures-io"
112
+version = "0.3.4"
113
+source = "registry+https://github.com/rust-lang/crates.io-index"
114
+
115
+[[package]]
116
+name = "futures-macro"
117
+version = "0.3.4"
118
+source = "registry+https://github.com/rust-lang/crates.io-index"
119
+dependencies = [
120
+ "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)",
121
+ "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
122
+ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
123
+ "syn 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)",
124
+]
125
+
126
+[[package]]
127
+name = "futures-sink"
128
+version = "0.3.4"
129
+source = "registry+https://github.com/rust-lang/crates.io-index"
130
+
131
+[[package]]
132
+name = "futures-task"
133
+version = "0.3.4"
134
+source = "registry+https://github.com/rust-lang/crates.io-index"
135
+
136
+[[package]]
137
+name = "futures-util"
138
+version = "0.3.4"
139
+source = "registry+https://github.com/rust-lang/crates.io-index"
140
+dependencies = [
141
+ "futures-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
142
+ "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
143
+ "futures-io 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
144
+ "futures-macro 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
145
+ "futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
146
+ "futures-task 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
147
+ "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
148
+ "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)",
149
+ "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)",
150
+ "proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
151
+ "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
152
+]
153
+
154
+[[package]]
155
+name = "hbbs"
156
+version = "0.1.0"
157
+dependencies = [
158
+ "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
159
+ "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
160
+ "futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
161
+ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
162
+ "protobuf 2.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
163
+ "protobuf-codegen-pure 2.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
164
+ "tokio 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
165
+ "tokio-util 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
166
+]
167
+
168
+[[package]]
169
+name = "hermit-abi"
170
+version = "0.1.8"
171
+source = "registry+https://github.com/rust-lang/crates.io-index"
172
+dependencies = [
173
+ "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
174
+]
175
+
176
+[[package]]
177
+name = "humantime"
178
+version = "1.3.0"
179
+source = "registry+https://github.com/rust-lang/crates.io-index"
180
+dependencies = [
181
+ "quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
182
+]
183
+
184
+[[package]]
185
+name = "iovec"
186
+version = "0.1.4"
187
+source = "registry+https://github.com/rust-lang/crates.io-index"
188
+dependencies = [
189
+ "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
190
+]
191
+
192
+[[package]]
193
+name = "kernel32-sys"
194
+version = "0.2.2"
195
+source = "registry+https://github.com/rust-lang/crates.io-index"
196
+dependencies = [
197
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
198
+ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
199
+]
200
+
201
+[[package]]
202
+name = "lazy_static"
203
+version = "1.4.0"
204
+source = "registry+https://github.com/rust-lang/crates.io-index"
205
+
206
+[[package]]
207
+name = "libc"
208
+version = "0.2.67"
209
+source = "registry+https://github.com/rust-lang/crates.io-index"
210
+
211
+[[package]]
212
+name = "log"
213
+version = "0.4.8"
214
+source = "registry+https://github.com/rust-lang/crates.io-index"
215
+dependencies = [
216
+ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
217
+]
218
+
219
+[[package]]
220
+name = "memchr"
221
+version = "2.3.3"
222
+source = "registry+https://github.com/rust-lang/crates.io-index"
223
+
224
+[[package]]
225
+name = "mio"
226
+version = "0.6.21"
227
+source = "registry+https://github.com/rust-lang/crates.io-index"
228
+dependencies = [
229
+ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
230
+ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
231
+ "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
232
+ "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
233
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
234
+ "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
235
+ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
236
+ "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
237
+ "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
238
+ "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
239
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
240
+]
241
+
242
+[[package]]
243
+name = "mio-named-pipes"
244
+version = "0.1.6"
245
+source = "registry+https://github.com/rust-lang/crates.io-index"
246
+dependencies = [
247
+ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
248
+ "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)",
249
+ "miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
250
+ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
251
+]
252
+
253
+[[package]]
254
+name = "mio-uds"
255
+version = "0.6.7"
256
+source = "registry+https://github.com/rust-lang/crates.io-index"
257
+dependencies = [
258
+ "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
259
+ "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
260
+ "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)",
261
+]
262
+
263
+[[package]]
264
+name = "miow"
265
+version = "0.2.1"
266
+source = "registry+https://github.com/rust-lang/crates.io-index"
267
+dependencies = [
268
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
269
+ "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
270
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
271
+ "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
272
+]
273
+
274
+[[package]]
275
+name = "miow"
276
+version = "0.3.3"
277
+source = "registry+https://github.com/rust-lang/crates.io-index"
278
+dependencies = [
279
+ "socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
280
+ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
281
+]
282
+
283
+[[package]]
284
+name = "net2"
285
+version = "0.2.33"
286
+source = "registry+https://github.com/rust-lang/crates.io-index"
287
+dependencies = [
288
+ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
289
+ "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
290
+ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
291
+]
292
+
293
+[[package]]
294
+name = "num_cpus"
295
+version = "1.12.0"
296
+source = "registry+https://github.com/rust-lang/crates.io-index"
297
+dependencies = [
298
+ "hermit-abi 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
299
+ "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
300
+]
301
+
302
+[[package]]
303
+name = "pin-project-lite"
304
+version = "0.1.4"
305
+source = "registry+https://github.com/rust-lang/crates.io-index"
306
+
307
+[[package]]
308
+name = "pin-utils"
309
+version = "0.1.0-alpha.4"
310
+source = "registry+https://github.com/rust-lang/crates.io-index"
311
+
312
+[[package]]
313
+name = "proc-macro-hack"
314
+version = "0.5.11"
315
+source = "registry+https://github.com/rust-lang/crates.io-index"
316
+dependencies = [
317
+ "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
318
+ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
319
+ "syn 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)",
320
+]
321
+
322
+[[package]]
323
+name = "proc-macro-nested"
324
+version = "0.1.3"
325
+source = "registry+https://github.com/rust-lang/crates.io-index"
326
+
327
+[[package]]
328
+name = "proc-macro2"
329
+version = "1.0.9"
330
+source = "registry+https://github.com/rust-lang/crates.io-index"
331
+dependencies = [
332
+ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
333
+]
334
+
335
+[[package]]
336
+name = "protobuf"
337
+version = "2.10.2"
338
+source = "registry+https://github.com/rust-lang/crates.io-index"
339
+
340
+[[package]]
341
+name = "protobuf-codegen"
342
+version = "2.10.2"
343
+source = "registry+https://github.com/rust-lang/crates.io-index"
344
+dependencies = [
345
+ "protobuf 2.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
346
+]
347
+
348
+[[package]]
349
+name = "protobuf-codegen-pure"
350
+version = "2.10.2"
351
+source = "registry+https://github.com/rust-lang/crates.io-index"
352
+dependencies = [
353
+ "protobuf 2.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
354
+ "protobuf-codegen 2.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
355
+]
356
+
357
+[[package]]
358
+name = "quick-error"
359
+version = "1.2.3"
360
+source = "registry+https://github.com/rust-lang/crates.io-index"
361
+
362
+[[package]]
363
+name = "quote"
364
+version = "1.0.2"
365
+source = "registry+https://github.com/rust-lang/crates.io-index"
366
+dependencies = [
367
+ "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
368
+]
369
+
370
+[[package]]
371
+name = "redox_syscall"
372
+version = "0.1.56"
373
+source = "registry+https://github.com/rust-lang/crates.io-index"
374
+
375
+[[package]]
376
+name = "regex"
377
+version = "1.3.4"
378
+source = "registry+https://github.com/rust-lang/crates.io-index"
379
+dependencies = [
380
+ "aho-corasick 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)",
381
+ "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
382
+ "regex-syntax 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)",
383
+ "thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
384
+]
385
+
386
+[[package]]
387
+name = "regex-syntax"
388
+version = "0.6.16"
389
+source = "registry+https://github.com/rust-lang/crates.io-index"
390
+
391
+[[package]]
392
+name = "signal-hook-registry"
393
+version = "1.2.0"
394
+source = "registry+https://github.com/rust-lang/crates.io-index"
395
+dependencies = [
396
+ "arc-swap 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
397
+ "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
398
+]
399
+
400
+[[package]]
401
+name = "slab"
402
+version = "0.4.2"
403
+source = "registry+https://github.com/rust-lang/crates.io-index"
404
+
405
+[[package]]
406
+name = "socket2"
407
+version = "0.3.11"
408
+source = "registry+https://github.com/rust-lang/crates.io-index"
409
+dependencies = [
410
+ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
411
+ "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
412
+ "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
413
+ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
414
+]
415
+
416
+[[package]]
417
+name = "syn"
418
+version = "1.0.16"
419
+source = "registry+https://github.com/rust-lang/crates.io-index"
420
+dependencies = [
421
+ "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
422
+ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
423
+ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
424
+]
425
+
426
+[[package]]
427
+name = "termcolor"
428
+version = "1.1.0"
429
+source = "registry+https://github.com/rust-lang/crates.io-index"
430
+dependencies = [
431
+ "winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
432
+]
433
+
434
+[[package]]
435
+name = "thread_local"
436
+version = "1.0.1"
437
+source = "registry+https://github.com/rust-lang/crates.io-index"
438
+dependencies = [
439
+ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
440
+]
441
+
442
+[[package]]
443
+name = "tokio"
444
+version = "0.2.13"
445
+source = "registry+https://github.com/rust-lang/crates.io-index"
446
+dependencies = [
447
+ "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
448
+ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
449
+ "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
450
+ "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
451
+ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
452
+ "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
453
+ "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
454
+ "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)",
455
+ "mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
456
+ "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
457
+ "num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
458
+ "pin-project-lite 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
459
+ "signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
460
+ "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
461
+ "tokio-macros 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
462
+ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
463
+]
464
+
465
+[[package]]
466
+name = "tokio-macros"
467
+version = "0.2.5"
468
+source = "registry+https://github.com/rust-lang/crates.io-index"
469
+dependencies = [
470
+ "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
471
+ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
472
+ "syn 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)",
473
+]
474
+
475
+[[package]]
476
+name = "tokio-util"
477
+version = "0.3.0"
478
+source = "registry+https://github.com/rust-lang/crates.io-index"
479
+dependencies = [
480
+ "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
481
+ "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
482
+ "futures-io 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
483
+ "futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
484
+ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
485
+ "pin-project-lite 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
486
+ "tokio 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
487
+]
488
+
489
+[[package]]
490
+name = "unicode-xid"
491
+version = "0.2.0"
492
+source = "registry+https://github.com/rust-lang/crates.io-index"
493
+
494
+[[package]]
495
+name = "winapi"
496
+version = "0.2.8"
497
+source = "registry+https://github.com/rust-lang/crates.io-index"
498
+
499
+[[package]]
500
+name = "winapi"
501
+version = "0.3.8"
502
+source = "registry+https://github.com/rust-lang/crates.io-index"
503
+dependencies = [
504
+ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
505
+ "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
506
+]
507
+
508
+[[package]]
509
+name = "winapi-build"
510
+version = "0.1.1"
511
+source = "registry+https://github.com/rust-lang/crates.io-index"
512
+
513
+[[package]]
514
+name = "winapi-i686-pc-windows-gnu"
515
+version = "0.4.0"
516
+source = "registry+https://github.com/rust-lang/crates.io-index"
517
+
518
+[[package]]
519
+name = "winapi-util"
520
+version = "0.1.3"
521
+source = "registry+https://github.com/rust-lang/crates.io-index"
522
+dependencies = [
523
+ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
524
+]
525
+
526
+[[package]]
527
+name = "winapi-x86_64-pc-windows-gnu"
528
+version = "0.4.0"
529
+source = "registry+https://github.com/rust-lang/crates.io-index"
530
+
531
+[[package]]
532
+name = "ws2_32-sys"
533
+version = "0.2.1"
534
+source = "registry+https://github.com/rust-lang/crates.io-index"
535
+dependencies = [
536
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
537
+ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
538
+]
539
+
540
+[metadata]
541
+"checksum aho-corasick 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "d5e63fd144e18ba274ae7095c0197a870a7b9468abc801dd62f190d80817d2ec"
542
+"checksum arc-swap 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff"
543
+"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
544
+"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
545
+"checksum bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1"
546
+"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
547
+"checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
548
+"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
549
+"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
550
+"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
551
+"checksum futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5c329ae8753502fb44ae4fc2b622fa2a94652c41e795143765ba0927f92ab780"
552
+"checksum futures-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c77d04ce8edd9cb903932b608268b3fffec4163dc053b3b402bf47eac1f1a8"
553
+"checksum futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f25592f769825e89b92358db00d26f965761e094951ac44d3663ef25b7ac464a"
554
+"checksum futures-executor 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f674f3e1bcb15b37284a90cedf55afdba482ab061c407a9c0ebbd0f3109741ba"
555
+"checksum futures-io 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a638959aa96152c7a4cddf50fcb1e3fede0583b27157c26e67d6f99904090dc6"
556
+"checksum futures-macro 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9a5081aa3de1f7542a794a397cde100ed903b0630152d0973479018fd85423a7"
557
+"checksum futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3466821b4bc114d95b087b850a724c6f83115e929bc88f1fa98a3304a944c8a6"
558
+"checksum futures-task 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27"
559
+"checksum futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5"
560
+"checksum hermit-abi 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1010591b26bbfe835e9faeabeb11866061cc7dcebffd56ad7d0942d0e61aefd8"
561
+"checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
562
+"checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
563
+"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
564
+"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
565
+"checksum libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)" = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018"
566
+"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
567
+"checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
568
+"checksum mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)" = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f"
569
+"checksum mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3"
570
+"checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125"
571
+"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
572
+"checksum miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226"
573
+"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
574
+"checksum num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6"
575
+"checksum pin-project-lite 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae"
576
+"checksum pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587"
577
+"checksum proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5"
578
+"checksum proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e"
579
+"checksum proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435"
580
+"checksum protobuf 2.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "37a5325d019a4d837d3abde0a836920f959e33d350f77b5f1e289e061e774942"
581
+"checksum protobuf-codegen 2.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "64dd3a6192e0c6c1b0dae8f125b7f6b201c39fc487ebda0ee717d7a87fc47dc2"
582
+"checksum protobuf-codegen-pure 2.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "037fa49710ee83b3be232ed53c5fce0bdb1b64c6aa6b1143a86640969c3e4b1d"
583
+"checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
584
+"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
585
+"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
586
+"checksum regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "322cf97724bea3ee221b78fe25ac9c46114ebb51747ad5babd51a2fc6a8235a8"
587
+"checksum regex-syntax 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "1132f845907680735a84409c3bebc64d1364a5683ffbce899550cd09d5eaefc1"
588
+"checksum signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41"
589
+"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
590
+"checksum socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85"
591
+"checksum syn 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)" = "123bd9499cfb380418d509322d7a6d52e5315f064fe4b3ad18a53d6b92c07859"
592
+"checksum termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
593
+"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
594
+"checksum tokio 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "0fa5e81d6bc4e67fe889d5783bd2a128ab2e0cfa487e0be16b6a8d177b101616"
595
+"checksum tokio-macros 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389"
596
+"checksum tokio-util 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "af67cdce2b40f8dffb0ee04c853a24217b5d0d3e358f0f5ccc0b5332174ed9a8"
597
+"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
598
+"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
599
+"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
600
+"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
601
+"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
602
+"checksum winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80"
603
+"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
604
+"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"

+ 9 - 3
Cargo.toml

@@ -7,7 +7,13 @@ edition = "2018"
7
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8
 
8
 
9
 [dependencies]
9
 [dependencies]
10
-p2p = { path = "libs/p2p" }
10
+tokio = { version = "0.2", features = ["full"] }
11
+protobuf = "2.10"
12
+tokio-util = { version = "0.3", features = ["full"] }
13
+log = "0.4"
14
+env_logger = "0.7"
15
+futures = "0.3"
16
+bytes = "0.5"
11
 
17
 
12
-[workspace]
13
-members = ["libs/p2p"]
18
+[build-dependencies]
19
+protobuf-codegen-pure = "2.10"

+ 10 - 0
build.rs

@@ -0,0 +1,10 @@
1
+fn main() {
2
+    protobuf_codegen_pure::run(protobuf_codegen_pure::Args {
3
+        out_dir: "src/protos",
4
+        input: &["protos/message.proto"],
5
+        includes: &["protos"],
6
+        customize: protobuf_codegen_pure::Customize {
7
+            ..Default::default()
8
+        },
9
+    }).unwrap();
10
+}

+ 0 - 1
libs/p2p

@@ -1 +0,0 @@
1
-Subproject commit 24cffa9777c7984a4e78e933e78507e63e5527d2

+ 9 - 0
protos/message.proto

@@ -0,0 +1,9 @@
1
+syntax = "proto3";
2
+package hbb;
3
+
4
+message Message {
5
+  string addr = 1; // hbb address
6
+  oneof union {
7
+    bytes socket_addr = 6;
8
+  }
9
+}

+ 2 - 0
protos/mod.rs

@@ -0,0 +1,2 @@
1
+mod message;
2
+pub use message::*;

+ 5 - 0
src/lib.rs

@@ -0,0 +1,5 @@
1
+mod rendezvous_server;
2
+pub use rendezvous_server::*;
3
+#[path = "./protos/message.rs"]
4
+mod message_proto;
5
+pub use message_proto::*;

+ 12 - 3
src/main.rs

@@ -1,3 +1,12 @@
1
-fn main() {
2
-    println!("Hello, world!");
3
-}
1
+// https://tools.ietf.org/rfc/rfc5128.txt
2
+// https://blog.csdn.net/bytxl/article/details/44344855
3
+
4
+use hbbs::*;
5
+use std::error::Error;
6
+
7
+#[tokio::main]
8
+async fn main() -> Result<(), Box<dyn Error>> {
9
+    env_logger::init();
10
+    RendezvousServer::start("0.0.0.0:21116").await?;
11
+    Ok(())
12
+}

+ 301 - 0
src/protos/message.rs

@@ -0,0 +1,301 @@
1
+// This file is generated by rust-protobuf 2.10.2. Do not edit
2
+// @generated
3
+
4
+// https://github.com/rust-lang/rust-clippy/issues/702
5
+#![allow(unknown_lints)]
6
+#![allow(clippy::all)]
7
+
8
+#![cfg_attr(rustfmt, rustfmt_skip)]
9
+
10
+#![allow(box_pointers)]
11
+#![allow(dead_code)]
12
+#![allow(missing_docs)]
13
+#![allow(non_camel_case_types)]
14
+#![allow(non_snake_case)]
15
+#![allow(non_upper_case_globals)]
16
+#![allow(trivial_casts)]
17
+#![allow(unsafe_code)]
18
+#![allow(unused_imports)]
19
+#![allow(unused_results)]
20
+//! Generated file from `message.proto`
21
+
22
+use protobuf::Message as Message_imported_for_functions;
23
+use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions;
24
+
25
+/// Generated files are compatible only with the same version
26
+/// of protobuf runtime.
27
+// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_10_2;
28
+
29
+#[derive(PartialEq,Clone,Default)]
30
+pub struct Message {
31
+    // message fields
32
+    pub addr: ::std::string::String,
33
+    // message oneof groups
34
+    pub union: ::std::option::Option<Message_oneof_union>,
35
+    // special fields
36
+    pub unknown_fields: ::protobuf::UnknownFields,
37
+    pub cached_size: ::protobuf::CachedSize,
38
+}
39
+
40
+impl<'a> ::std::default::Default for &'a Message {
41
+    fn default() -> &'a Message {
42
+        <Message as ::protobuf::Message>::default_instance()
43
+    }
44
+}
45
+
46
+#[derive(Clone,PartialEq,Debug)]
47
+pub enum Message_oneof_union {
48
+    socket_addr(::std::vec::Vec<u8>),
49
+}
50
+
51
+impl Message {
52
+    pub fn new() -> Message {
53
+        ::std::default::Default::default()
54
+    }
55
+
56
+    // string addr = 1;
57
+
58
+
59
+    pub fn get_addr(&self) -> &str {
60
+        &self.addr
61
+    }
62
+    pub fn clear_addr(&mut self) {
63
+        self.addr.clear();
64
+    }
65
+
66
+    // Param is passed by value, moved
67
+    pub fn set_addr(&mut self, v: ::std::string::String) {
68
+        self.addr = v;
69
+    }
70
+
71
+    // Mutable pointer to the field.
72
+    // If field is not initialized, it is initialized with default value first.
73
+    pub fn mut_addr(&mut self) -> &mut ::std::string::String {
74
+        &mut self.addr
75
+    }
76
+
77
+    // Take field
78
+    pub fn take_addr(&mut self) -> ::std::string::String {
79
+        ::std::mem::replace(&mut self.addr, ::std::string::String::new())
80
+    }
81
+
82
+    // bytes socket_addr = 6;
83
+
84
+
85
+    pub fn get_socket_addr(&self) -> &[u8] {
86
+        match self.union {
87
+            ::std::option::Option::Some(Message_oneof_union::socket_addr(ref v)) => v,
88
+            _ => &[],
89
+        }
90
+    }
91
+    pub fn clear_socket_addr(&mut self) {
92
+        self.union = ::std::option::Option::None;
93
+    }
94
+
95
+    pub fn has_socket_addr(&self) -> bool {
96
+        match self.union {
97
+            ::std::option::Option::Some(Message_oneof_union::socket_addr(..)) => true,
98
+            _ => false,
99
+        }
100
+    }
101
+
102
+    // Param is passed by value, moved
103
+    pub fn set_socket_addr(&mut self, v: ::std::vec::Vec<u8>) {
104
+        self.union = ::std::option::Option::Some(Message_oneof_union::socket_addr(v))
105
+    }
106
+
107
+    // Mutable pointer to the field.
108
+    pub fn mut_socket_addr(&mut self) -> &mut ::std::vec::Vec<u8> {
109
+        if let ::std::option::Option::Some(Message_oneof_union::socket_addr(_)) = self.union {
110
+        } else {
111
+            self.union = ::std::option::Option::Some(Message_oneof_union::socket_addr(::std::vec::Vec::new()));
112
+        }
113
+        match self.union {
114
+            ::std::option::Option::Some(Message_oneof_union::socket_addr(ref mut v)) => v,
115
+            _ => panic!(),
116
+        }
117
+    }
118
+
119
+    // Take field
120
+    pub fn take_socket_addr(&mut self) -> ::std::vec::Vec<u8> {
121
+        if self.has_socket_addr() {
122
+            match self.union.take() {
123
+                ::std::option::Option::Some(Message_oneof_union::socket_addr(v)) => v,
124
+                _ => panic!(),
125
+            }
126
+        } else {
127
+            ::std::vec::Vec::new()
128
+        }
129
+    }
130
+}
131
+
132
+impl ::protobuf::Message for Message {
133
+    fn is_initialized(&self) -> bool {
134
+        true
135
+    }
136
+
137
+    fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> {
138
+        while !is.eof()? {
139
+            let (field_number, wire_type) = is.read_tag_unpack()?;
140
+            match field_number {
141
+                1 => {
142
+                    ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.addr)?;
143
+                },
144
+                6 => {
145
+                    if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited {
146
+                        return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));
147
+                    }
148
+                    self.union = ::std::option::Option::Some(Message_oneof_union::socket_addr(is.read_bytes()?));
149
+                },
150
+                _ => {
151
+                    ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
152
+                },
153
+            };
154
+        }
155
+        ::std::result::Result::Ok(())
156
+    }
157
+
158
+    // Compute sizes of nested messages
159
+    #[allow(unused_variables)]
160
+    fn compute_size(&self) -> u32 {
161
+        let mut my_size = 0;
162
+        if !self.addr.is_empty() {
163
+            my_size += ::protobuf::rt::string_size(1, &self.addr);
164
+        }
165
+        if let ::std::option::Option::Some(ref v) = self.union {
166
+            match v {
167
+                &Message_oneof_union::socket_addr(ref v) => {
168
+                    my_size += ::protobuf::rt::bytes_size(6, &v);
169
+                },
170
+            };
171
+        }
172
+        my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
173
+        self.cached_size.set(my_size);
174
+        my_size
175
+    }
176
+
177
+    fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> {
178
+        if !self.addr.is_empty() {
179
+            os.write_string(1, &self.addr)?;
180
+        }
181
+        if let ::std::option::Option::Some(ref v) = self.union {
182
+            match v {
183
+                &Message_oneof_union::socket_addr(ref v) => {
184
+                    os.write_bytes(6, v)?;
185
+                },
186
+            };
187
+        }
188
+        os.write_unknown_fields(self.get_unknown_fields())?;
189
+        ::std::result::Result::Ok(())
190
+    }
191
+
192
+    fn get_cached_size(&self) -> u32 {
193
+        self.cached_size.get()
194
+    }
195
+
196
+    fn get_unknown_fields(&self) -> &::protobuf::UnknownFields {
197
+        &self.unknown_fields
198
+    }
199
+
200
+    fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields {
201
+        &mut self.unknown_fields
202
+    }
203
+
204
+    fn as_any(&self) -> &dyn (::std::any::Any) {
205
+        self as &dyn (::std::any::Any)
206
+    }
207
+    fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
208
+        self as &mut dyn (::std::any::Any)
209
+    }
210
+    fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
211
+        self
212
+    }
213
+
214
+    fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
215
+        Self::descriptor_static()
216
+    }
217
+
218
+    fn new() -> Message {
219
+        Message::new()
220
+    }
221
+
222
+    fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
223
+        static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy {
224
+            lock: ::protobuf::lazy::ONCE_INIT,
225
+            ptr: 0 as *const ::protobuf::reflect::MessageDescriptor,
226
+        };
227
+        unsafe {
228
+            descriptor.get(|| {
229
+                let mut fields = ::std::vec::Vec::new();
230
+                fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
231
+                    "addr",
232
+                    |m: &Message| { &m.addr },
233
+                    |m: &mut Message| { &mut m.addr },
234
+                ));
235
+                fields.push(::protobuf::reflect::accessor::make_singular_bytes_accessor::<_>(
236
+                    "socket_addr",
237
+                    Message::has_socket_addr,
238
+                    Message::get_socket_addr,
239
+                ));
240
+                ::protobuf::reflect::MessageDescriptor::new::<Message>(
241
+                    "Message",
242
+                    fields,
243
+                    file_descriptor_proto()
244
+                )
245
+            })
246
+        }
247
+    }
248
+
249
+    fn default_instance() -> &'static Message {
250
+        static mut instance: ::protobuf::lazy::Lazy<Message> = ::protobuf::lazy::Lazy {
251
+            lock: ::protobuf::lazy::ONCE_INIT,
252
+            ptr: 0 as *const Message,
253
+        };
254
+        unsafe {
255
+            instance.get(Message::new)
256
+        }
257
+    }
258
+}
259
+
260
+impl ::protobuf::Clear for Message {
261
+    fn clear(&mut self) {
262
+        self.addr.clear();
263
+        self.union = ::std::option::Option::None;
264
+        self.unknown_fields.clear();
265
+    }
266
+}
267
+
268
+impl ::std::fmt::Debug for Message {
269
+    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
270
+        ::protobuf::text_format::fmt(self, f)
271
+    }
272
+}
273
+
274
+impl ::protobuf::reflect::ProtobufValue for Message {
275
+    fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef {
276
+        ::protobuf::reflect::ProtobufValueRef::Message(self)
277
+    }
278
+}
279
+
280
+static file_descriptor_proto_data: &'static [u8] = b"\
281
+    \n\rmessage.proto\x12\x03hbb\"=\n\x07Message\x12\x0e\n\x04addr\x18\x01\
282
+    \x20\x01(\tB\0\x12\x17\n\x0bsocket_addr\x18\x06\x20\x01(\x0cH\0B\0B\x07\
283
+    \n\x05union:\0B\0b\x06proto3\
284
+";
285
+
286
+static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy {
287
+    lock: ::protobuf::lazy::ONCE_INIT,
288
+    ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto,
289
+};
290
+
291
+fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto {
292
+    ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap()
293
+}
294
+
295
+pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto {
296
+    unsafe {
297
+        file_descriptor_proto_lazy.get(|| {
298
+            parse_descriptor_proto()
299
+        })
300
+    }
301
+}

+ 93 - 0
src/rendezvous_server.rs

@@ -0,0 +1,93 @@
1
+use super::message_proto::Message;
2
+use bytes::Bytes;
3
+use futures::{FutureExt, SinkExt};
4
+use protobuf::{parse_from_bytes, Message as _};
5
+use std::{
6
+    collections::HashMap,
7
+    error::Error,
8
+    net::{Ipv4Addr, SocketAddr, SocketAddrV4},
9
+    time::{SystemTime, UNIX_EPOCH},
10
+};
11
+use tokio::net::UdpSocket;
12
+use tokio::stream::StreamExt;
13
+use tokio_util::{codec::BytesCodec, udp::UdpFramed};
14
+
15
+/// Certain router and firewalls scan the packet and if they
16
+/// find an IP address belonging to their pool that they use to do the NAT mapping/translation, so here we mangle the ip address
17
+
18
+pub struct V4AddrMangle(Vec<u8>);
19
+
20
+impl V4AddrMangle {
21
+    pub fn encode(addr: SocketAddrV4) -> Self {
22
+        let tm = (SystemTime::now()
23
+            .duration_since(UNIX_EPOCH)
24
+            .unwrap()
25
+            .as_micros() as u32) as u128;
26
+        let ip = u32::from_ne_bytes(addr.ip().octets()) as u128;
27
+        let port = addr.port() as u128;
28
+        let v = ((ip + tm) << 49) | (tm << 17) | (port + (tm & 0xFFFF));
29
+        let bytes = v.to_ne_bytes();
30
+        let mut n_padding = 0;
31
+        for i in bytes.iter().rev() {
32
+            if i == &0u8 {
33
+                n_padding += 1;
34
+            } else {
35
+                break;
36
+            }
37
+        }
38
+        Self(bytes[..(16 - n_padding)].to_vec())
39
+    }
40
+
41
+    pub fn decode(&self) -> SocketAddrV4 {
42
+        let mut padded = [0u8; 16];
43
+        padded[..self.0.len()].copy_from_slice(&self.0);
44
+        let number = u128::from_ne_bytes(padded);
45
+        let tm = (number >> 17) & (u32::max_value() as u128);
46
+        let ip = (((number >> 49) - tm) as u32).to_ne_bytes();
47
+        let port = (number & 0xFFFFFF) - (tm & 0xFFFF);
48
+        SocketAddrV4::new(Ipv4Addr::new(ip[0], ip[1], ip[2], ip[3]), port as u16)
49
+    }
50
+}
51
+
52
+pub struct Peer {
53
+    socket_addr: SocketAddr,
54
+}
55
+
56
+type PeerMap = HashMap<String, Peer>;
57
+
58
+pub struct RendezvousServer {
59
+    peer_map: PeerMap,
60
+}
61
+
62
+impl RendezvousServer {
63
+    pub async fn start(addr: &str) -> Result<Self, Box<dyn Error>> {
64
+        let socket = UdpSocket::bind(addr).await?;
65
+        let mut socket = UdpFramed::new(socket, BytesCodec::new());
66
+
67
+        let rs = Self {
68
+            peer_map: PeerMap::new(),
69
+        };
70
+        while let Some(Ok((bytes, addr))) = socket.next().await {
71
+            if let SocketAddr::V4(addr_v4) = addr {
72
+                if let Ok(msg_in) = parse_from_bytes::<Message>(&bytes) {
73
+                    let msg_out = Message::new();
74
+                    socket
75
+                        .send((Bytes::from(msg_out.write_to_bytes().unwrap()), addr))
76
+                        .await?;
77
+                }
78
+            }
79
+        }
80
+        Ok(rs)
81
+    }
82
+}
83
+
84
+#[cfg(test)]
85
+mod tests {
86
+    use super::*;
87
+    #[test]
88
+    fn test_mangle() {
89
+        let addr = SocketAddrV4::new(Ipv4Addr::new(192, 168, 16, 32), 21116);
90
+        assert_eq!(addr, V4AddrMangle::encode(addr).decode());
91
+        println!("{:?}", V4AddrMangle::encode(addr).0);
92
+    }
93
+}