From 6050cdef7e266bdfd061bc80fbdbadb14d1f0da3 Mon Sep 17 00:00:00 2001 From: diegomrsantos Date: Thu, 25 May 2023 15:47:00 +0200 Subject: [PATCH] Refinement of Hole Punching Service (#892) --- .pinned | 2 +- libp2p/multiaddress.nim | 14 +- .../protocols/connectivity/dcutr/client.nim | 4 +- libp2p/protocols/connectivity/dcutr/core.nim | 2 +- .../protocols/connectivity/dcutr/server.nim | 2 +- libp2p/services/hpservice.nim | 8 +- libp2p/wire.nim | 6 +- tests/testdcutr.nim | 30 ++-- tests/testhpservice.nim | 15 +- tests/testwire.nim | 151 ++++++++++++++++++ 10 files changed, 197 insertions(+), 37 deletions(-) create mode 100644 tests/testwire.nim diff --git a/.pinned b/.pinned index 465e3da70..e89bfaea4 100644 --- a/.pinned +++ b/.pinned @@ -9,7 +9,7 @@ metrics;https://github.com/status-im/nim-metrics@#abf3acc7f06cee9ee2c287d2f31413 nimcrypto;https://github.com/cheatfate/nimcrypto@#4014ef939b51e02053c2e16dd3481d47bc9267dd secp256k1;https://github.com/status-im/nim-secp256k1@#fd173fdff863ce2e211cf64c9a03bc7539fe40b0 serialization;https://github.com/status-im/nim-serialization@#5b7cea55efeb074daa8abd8146a03a34adb4521a -stew;https://github.com/status-im/nim-stew@#8caa9771995b266e10b2e7c0de6cbfa698902e68 +stew;https://github.com/status-im/nim-stew@#003fe9f0c83c2b0b2ccbd37087e6d1ccd30a3234 testutils;https://github.com/status-im/nim-testutils@#dfc4c1b39f9ded9baf6365014de2b4bfb4dafc34 unittest2;https://github.com/status-im/nim-unittest2@#883c7a50ad3b82158e64d074c5578fe33ab3c452 websock;https://github.com/status-im/nim-websock@#fea05cde8b123b38d1a0a8524b77efbc84daa848 diff --git a/libp2p/multiaddress.nim b/libp2p/multiaddress.nim index 7ed76682d..2c5d09995 100644 --- a/libp2p/multiaddress.nim +++ b/libp2p/multiaddress.nim @@ -470,13 +470,23 @@ const DNS* = mapOr(DNSANY, DNS4, DNS6, DNSADDR) IP* = mapOr(IP4, IP6) DNS_OR_IP* = mapOr(DNS, IP) - TCP* = mapOr(mapAnd(DNS, mapEq("tcp")), mapAnd(IP, mapEq("tcp"))) - UDP* = mapOr(mapAnd(DNS, mapEq("udp")), mapAnd(IP, mapEq("udp"))) + TCP_DNS* = mapAnd(DNS, mapEq("tcp")) + TCP_IP* =mapAnd(IP, mapEq("tcp")) + TCP* = mapOr(TCP_DNS, TCP_IP) + UDP_DNS* = mapAnd(DNS, mapEq("udp")) + UDP_IP* = mapAnd(IP, mapEq("udp")) + UDP* = mapOr(UDP_DNS, UDP_IP) UTP* = mapAnd(UDP, mapEq("utp")) QUIC* = mapAnd(UDP, mapEq("quic")) UNIX* = mapEq("unix") + WS_DNS* = mapAnd(TCP_DNS, mapEq("ws")) + WS_IP* = mapAnd(TCP_IP, mapEq("ws")) WS* = mapAnd(TCP, mapEq("ws")) + WSS_DNS* = mapAnd(TCP_DNS, mapEq("wss")) + WSS_IP* = mapAnd(TCP_IP, mapEq("wss")) WSS* = mapAnd(TCP, mapEq("wss")) + WebSockets_DNS* = mapOr(WS_DNS, WSS_DNS) + WebSockets_IP* = mapOr(WS_IP, WSS_IP) WebSockets* = mapOr(WS, WSS) Onion3* = mapEq("onion3") TcpOnion3* = mapAnd(TCP, Onion3) diff --git a/libp2p/protocols/connectivity/dcutr/client.nim b/libp2p/protocols/connectivity/dcutr/client.nim index 220b6cdb5..1aafeb160 100644 --- a/libp2p/protocols/connectivity/dcutr/client.nim +++ b/libp2p/protocols/connectivity/dcutr/client.nim @@ -63,13 +63,13 @@ proc startSync*(self: DcutrClient, switch: Switch, remotePeerId: PeerId, addrs: let rttEnd = Moment.now() debug "Dcutr initiator has received a Connect message back.", connectAnswer let halfRtt = (rttEnd - rttStart) div 2'i64 - await stream.send(MsgType.Sync, addrs) + await stream.send(MsgType.Sync, @[]) debug "Dcutr initiator has sent a Sync message." await sleepAsync(halfRtt) if peerDialableAddrs.len > self.maxDialableAddrs: peerDialableAddrs = peerDialableAddrs[0.. maxDialableAddrs: peerDialableAddrs = peerDialableAddrs[0..