diff --git a/Makefile b/Makefile index eeb44c71a5..ec28da1f91 100644 --- a/Makefile +++ b/Makefile @@ -229,7 +229,7 @@ test/%: | build deps librln ################ ## Waku tools ## ################ -.PHONY: tools wakucanary networkmonitor +.PHONY: tools wakucanary networkmonitor peer_exchange_tester tools: networkmonitor wakucanary @@ -241,6 +241,9 @@ networkmonitor: | build deps librln echo -e $(BUILD_MSG) "build/$@" && \ $(ENV_SCRIPT) nim networkmonitor $(NIM_PARAMS) waku.nims +peer_exchange_tester: | build deps librln + echo -e $(BUILD_MSG) "build/$@" && \ + $(ENV_SCRIPT) nim peer_exchange_tester $(NIM_PARAMS) waku.nims ################### ## Documentation ## diff --git a/apps/peer_exchange_tester/README.md b/apps/peer_exchange_tester/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/apps/peer_exchange_tester/nim.cfg b/apps/peer_exchange_tester/nim.cfg new file mode 100644 index 0000000000..2231f2ebed --- /dev/null +++ b/apps/peer_exchange_tester/nim.cfg @@ -0,0 +1,4 @@ +-d:chronicles_line_numbers +-d:chronicles_runtime_filtering:on +-d:discv5_protocol_id:d5waku +path = "../.." diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim new file mode 100644 index 0000000000..4b229e6e97 --- /dev/null +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -0,0 +1,87 @@ +import chronos, chronicles, options, os +import libp2p/peerId +import eth/p2p/discoveryv5/enr +import + waku/[ + waku_node, + waku_peer_exchange, + node/peer_manager, + node/peer_manager/peer_manager, + node/peer_manager, + factory/waku, + factory/external_config, + common/logging, + ] + +proc main() {.async.} = + echo "--------------- main started ---------------" + + var wakuConf: WakuNodeConf + wakuConf.logLevel = logging.LogLevel.DEBUG + wakuConf.logFormat = logging.LogFormat.TEXT + wakuConf.staticNodes = + @[ + "/ip4/178.128.141.171/tcp/30303/p2p/16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W" + ] + wakuConf.maxConnections = 100 + wakuConf.pubsubTopics = @["/waku/2/rs/0/0"] + wakuConf.clusterId = 1 + wakuConf.nat = "extip:117.99.49.10" + wakuConf.relayPeerExchange = true + wakuConf.peerExchange = true + + var wakuApp = Waku.init(wakuConf).valueOr: + error "Waku initialization failed", error = error + quit(QuitFailure) + + (waitFor startWaku(addr wakuApp)).isOkOr: + error "Starting waku failed", error = error + quit(QuitFailure) + + let switch = newStandardSwitch() + discard switch.start() + + let addrs = "/ip4/178.128.141.171/tcp/30303/" + let id = "16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W" + let ma = MultiAddress.init(addrs).tryGet() + let peerId = PeerId.init(id).tryGet() + let peer_info = RemotePeerInfo.init(peerId, @[ma]) + + var iter = 0 + var success = 0 + for i in 0 .. 60: + echo "Seq No :- " & $i & " ---> " + let response = await wakuApp.node.wakuPeerExchange.request(5, peer_info) + if response.isOk: + var validPeers = 0 + let peers = response.get().peerInfos + for pi in peers: + var record: enr.Record + if enr.fromBytes(record, pi.enr): + let peer_info = record.toRemotePeerInfo().get() + let peerId = peer_info.peerId + let ma = peer_info.addrs + echo $iter & ") -----> " & $ma[0] & " -- " & $peerId + iter += 1 + try: + let wait = 20000 + let conn = await switch + .dial(peerId, ma, "/vac/waku/metadata/1.0.0") + .withTimeout(wait) + except TimeoutError: + echo "Dialing peer " & $peerId & " timed out." + except: + echo "An error occurred while dialing peer " & $peerId + + success += len(switch.connectedPeers(Direction.Out)) + echo $success & " out of " & $iter & " operation successful" + discard switch.disconnect(peerId) + else: + echo " ------------ response isn't not ok ------------------" + sleep(120000) + while iter mod 5 == 0: + iter += 1 + echo "---------------------------- Done ------------------------------- " + +when isMainModule: + waitFor main() diff --git a/waku.nimble b/waku.nimble index e4d88a323d..11a5a5f919 100644 --- a/waku.nimble +++ b/waku.nimble @@ -111,6 +111,10 @@ task wakucanary, "Build waku-canary tool": let name = "wakucanary" buildBinary name, "apps/wakucanary/" +task peer_exchange_tester, "Build peer exchange tester tool": + let name = "peer_exchange_tester" + buildBinary name, "apps/peer_exchange_tester/" + task networkmonitor, "Build network monitor tool": let name = "networkmonitor" buildBinary name, "apps/networkmonitor/"