From 475f7fb038dfaf6a134fd9e84b765e94f5d0543a Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Mon, 29 Jul 2024 13:46:41 +0530 Subject: [PATCH 01/16] test: initial peer_exchange tester --- Makefile | 5 +++- apps/peer_exchange_tester/README.md | 0 apps/peer_exchange_tester/nim.cfg | 4 +++ .../peer_exchange_tester.nim | 27 +++++++++++++++++++ waku.nimble | 4 +++ waku/waku_peer_exchange/protocol.nim | 2 +- 6 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 apps/peer_exchange_tester/README.md create mode 100644 apps/peer_exchange_tester/nim.cfg create mode 100644 apps/peer_exchange_tester/peer_exchange_tester.nim diff --git a/Makefile b/Makefile index eeb44c71a5..6f53fc7eec 100644 --- a/Makefile +++ b/Makefile @@ -229,7 +229,7 @@ test/%: | build deps librln ################ ## Waku tools ## ################ -.PHONY: tools wakucanary networkmonitor +.PHONY: tools wakucanary networkmonitor peerexchangetester 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..efc0e0ab26 --- /dev/null +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -0,0 +1,27 @@ +import + std/[options, sequtils, random], + chronos, chronicles, stew/byteutils + +import + waku/[waku_peer_exchange, node/peer_manager] + +# import chronicles, chronos, stew/byteutils, results +# import waku/[common/logging, node/peer_manager, waku_core, waku_filter_v2/client] + +proc main() {.async.} = + let switch = newStandardSwitch() + let peerManager = PeerManager.new(switch) + let wakuPx = WakuPeerExchange(peerManager: peerManager) + + # Request peers and check if they are live + let res = await wakuPx.request(5) + if res.isOk: + let peers = res.get().peerInfos.mapIt(it.enr) + for peer in peers: + echo "Peer ENR: ", peer + # Add your logic to dial and check if the peer is live + else: + echo "Error requesting peers: ", res.error + +when isMainModule: + waitFor main() \ No newline at end of file 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/" diff --git a/waku/waku_peer_exchange/protocol.nim b/waku/waku_peer_exchange/protocol.nim index 689c8fddab..202c40a9d1 100644 --- a/waku/waku_peer_exchange/protocol.nim +++ b/waku/waku_peer_exchange/protocol.nim @@ -203,4 +203,4 @@ proc new*( let wpx = WakuPeerExchange(peerManager: peerManager, cluster: cluster) wpx.initProtocolHandler() asyncSpawn wpx.updatePxEnrCache() - return wpx + return wpx \ No newline at end of file From d9f755d536bb7d722730e8dc63c4dfd760c682c0 Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Tue, 30 Jul 2024 16:15:14 +0530 Subject: [PATCH 02/16] test: connect remote peers --- Makefile | 2 +- .../peer_exchange_tester.nim | 29 ++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 6f53fc7eec..ec28da1f91 100644 --- a/Makefile +++ b/Makefile @@ -229,7 +229,7 @@ test/%: | build deps librln ################ ## Waku tools ## ################ -.PHONY: tools wakucanary networkmonitor peerexchangetester +.PHONY: tools wakucanary networkmonitor peer_exchange_tester tools: networkmonitor wakucanary diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim index efc0e0ab26..ff2d9998e0 100644 --- a/apps/peer_exchange_tester/peer_exchange_tester.nim +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -1,15 +1,24 @@ -import - std/[options, sequtils, random], - chronos, chronicles, stew/byteutils - -import - waku/[waku_peer_exchange, node/peer_manager] +# import random, strutils, asyncdispatch, chronos, chronicles, stew/byteutils, waku/[waku_peer_exchange, node/peer_manager], tests/testlib/wakucore +import random, chronos, chronicles, stew/byteutils +import waku/[waku_peer_exchange, node/peer_manager] +import tests/testlib/wakucore +import asyncdispatch as asyncd -# import chronicles, chronos, stew/byteutils, results -# import waku/[common/logging, node/peer_manager, waku_core, waku_filter_v2/client] +proc createSwitch(): Switch = + let addrs = MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() + newStandardSwitch(addrs = addrs) + +proc connectToPeer(sw: Switch, peerAddr: string) {.async.} = + let ma = MultiAddress.init(peerAddr).tryGet() + let str = "16Uiu2HAm2uZtDK3T4zgseP16uGB6s2q2i8zpviLBmXyukjU5BPVT" + let peerIdData = str.mapIt(cast[byte](it)) + let peerId = PeerId(data: peerIdData) + let connection = await sw.dial(peerId, @[ma], @["defaultProto"]) proc main() {.async.} = - let switch = newStandardSwitch() + let addrs = "/ip4/139.99.173.27/tcp/30304" + let switch = createSwitch() + await switch.connectToPeer(addrs) let peerManager = PeerManager.new(switch) let wakuPx = WakuPeerExchange(peerManager: peerManager) @@ -24,4 +33,4 @@ proc main() {.async.} = echo "Error requesting peers: ", res.error when isMainModule: - waitFor main() \ No newline at end of file + asyncMain(main) From 319db54721aa5410ea64373c89e79311c1312c8d Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Tue, 30 Jul 2024 17:49:09 +0530 Subject: [PATCH 03/16] fix: update according to nph --- waku/waku_peer_exchange/protocol.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/waku/waku_peer_exchange/protocol.nim b/waku/waku_peer_exchange/protocol.nim index 202c40a9d1..689c8fddab 100644 --- a/waku/waku_peer_exchange/protocol.nim +++ b/waku/waku_peer_exchange/protocol.nim @@ -203,4 +203,4 @@ proc new*( let wpx = WakuPeerExchange(peerManager: peerManager, cluster: cluster) wpx.initProtocolHandler() asyncSpawn wpx.updatePxEnrCache() - return wpx \ No newline at end of file + return wpx From 3e9c32de7b271243246bc69688983c8264e31a76 Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Wed, 7 Aug 2024 14:44:43 +0530 Subject: [PATCH 04/16] chore: update the PR --- .../peer_exchange_tester.nim | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim index ff2d9998e0..6ce1524ca8 100644 --- a/apps/peer_exchange_tester/peer_exchange_tester.nim +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -1,8 +1,8 @@ # import random, strutils, asyncdispatch, chronos, chronicles, stew/byteutils, waku/[waku_peer_exchange, node/peer_manager], tests/testlib/wakucore -import random, chronos, chronicles, stew/byteutils +import random, chronicles, stew/byteutils import waku/[waku_peer_exchange, node/peer_manager] import tests/testlib/wakucore -import asyncdispatch as asyncd +import asyncdispatch proc createSwitch(): Switch = let addrs = MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() @@ -10,27 +10,20 @@ proc createSwitch(): Switch = proc connectToPeer(sw: Switch, peerAddr: string) {.async.} = let ma = MultiAddress.init(peerAddr).tryGet() - let str = "16Uiu2HAm2uZtDK3T4zgseP16uGB6s2q2i8zpviLBmXyukjU5BPVT" - let peerIdData = str.mapIt(cast[byte](it)) + let str = "16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W" + let peerIdData = cast[seq[byte]](str) let peerId = PeerId(data: peerIdData) - let connection = await sw.dial(peerId, @[ma], @["defaultProto"]) + # sw.dial(peerId, @[ma], @["/vac/waku/peer-exchange/2.0.0-alpha1"]) proc main() {.async.} = - let addrs = "/ip4/139.99.173.27/tcp/30304" + let addrs = "/dns4/node-01.do-ams3.waku.test.status.im/tcp/30303/p2p" let switch = createSwitch() await switch.connectToPeer(addrs) let peerManager = PeerManager.new(switch) let wakuPx = WakuPeerExchange(peerManager: peerManager) - # Request peers and check if they are live - let res = await wakuPx.request(5) - if res.isOk: - let peers = res.get().peerInfos.mapIt(it.enr) - for peer in peers: - echo "Peer ENR: ", peer - # Add your logic to dial and check if the peer is live - else: - echo "Error requesting peers: ", res.error - when isMainModule: asyncMain(main) + +# addrs :- /dns4/node-01.do-ams3.waku.test.status.im/tcp/30303/p2p/ +# 16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W \ No newline at end of file From 1d1bfbf6895d8cef6ecbfde8ce8aa42bea3d9228 Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Wed, 7 Aug 2024 14:46:36 +0530 Subject: [PATCH 05/16] chore: remove ci error --- apps/peer_exchange_tester/peer_exchange_tester.nim | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim index 6ce1524ca8..c04ad642d2 100644 --- a/apps/peer_exchange_tester/peer_exchange_tester.nim +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -24,6 +24,3 @@ proc main() {.async.} = when isMainModule: asyncMain(main) - -# addrs :- /dns4/node-01.do-ams3.waku.test.status.im/tcp/30303/p2p/ -# 16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W \ No newline at end of file From 5191f604ec7098b1fd43ef024d614a977f12ec63 Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Thu, 8 Aug 2024 02:33:11 +0530 Subject: [PATCH 06/16] chore: update PR --- apps/peer_exchange_tester/peer_exchange_tester.nim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim index c04ad642d2..84c662e35e 100644 --- a/apps/peer_exchange_tester/peer_exchange_tester.nim +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -6,21 +6,25 @@ import asyncdispatch proc createSwitch(): Switch = let addrs = MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() - newStandardSwitch(addrs = addrs) + return newStandardSwitch(addrs = addrs) proc connectToPeer(sw: Switch, peerAddr: string) {.async.} = let ma = MultiAddress.init(peerAddr).tryGet() let str = "16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W" let peerIdData = cast[seq[byte]](str) let peerId = PeerId(data: peerIdData) - # sw.dial(peerId, @[ma], @["/vac/waku/peer-exchange/2.0.0-alpha1"]) + await sw.connect(peerId, @[ma]) + echo "Connected to peer with address: ", peerAddr proc main() {.async.} = let addrs = "/dns4/node-01.do-ams3.waku.test.status.im/tcp/30303/p2p" let switch = createSwitch() - await switch.connectToPeer(addrs) + await connectToPeer(switch, addrs) + let connectedPeers = switch.connectedPeers() + if connectedPeers > 0: + echo "Successfully connected with Waku test fleet" let peerManager = PeerManager.new(switch) let wakuPx = WakuPeerExchange(peerManager: peerManager) when isMainModule: - asyncMain(main) + waitFor main() \ No newline at end of file From 8a1de5307343263cba01a377e34b12b499a8fcb5 Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Thu, 8 Aug 2024 02:36:35 +0530 Subject: [PATCH 07/16] chore: update PR --- apps/peer_exchange_tester/peer_exchange_tester.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim index 84c662e35e..95f7614590 100644 --- a/apps/peer_exchange_tester/peer_exchange_tester.nim +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -27,4 +27,4 @@ proc main() {.async.} = let wakuPx = WakuPeerExchange(peerManager: peerManager) when isMainModule: - waitFor main() \ No newline at end of file + waitFor main() From d0dba029e74908912b5d723930bc1f8b354407e3 Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Thu, 8 Aug 2024 03:33:22 +0530 Subject: [PATCH 08/16] chore: finally successfully build app --- .../peer_exchange_tester.nim | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim index 95f7614590..5150801285 100644 --- a/apps/peer_exchange_tester/peer_exchange_tester.nim +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -1,10 +1,10 @@ # import random, strutils, asyncdispatch, chronos, chronicles, stew/byteutils, waku/[waku_peer_exchange, node/peer_manager], tests/testlib/wakucore -import random, chronicles, stew/byteutils +import random, chronos, chronicles, stew/byteutils, os import waku/[waku_peer_exchange, node/peer_manager] import tests/testlib/wakucore -import asyncdispatch proc createSwitch(): Switch = + echo "switch created" let addrs = MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() return newStandardSwitch(addrs = addrs) @@ -13,18 +13,27 @@ proc connectToPeer(sw: Switch, peerAddr: string) {.async.} = let str = "16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W" let peerIdData = cast[seq[byte]](str) let peerId = PeerId(data: peerIdData) - await sw.connect(peerId, @[ma]) + echo "trying to connect with peer" + # await sw.connect(peerId, @[ma]) + # discard sw.dial(peerId, "/vac/waku/peer-exchange/2.0.0-alpha1") echo "Connected to peer with address: ", peerAddr proc main() {.async.} = - let addrs = "/dns4/node-01.do-ams3.waku.test.status.im/tcp/30303/p2p" + echo "main started" + let addrs = "/ip4/178.128.141.171/tcp/30303" let switch = createSwitch() await connectToPeer(switch, addrs) - let connectedPeers = switch.connectedPeers() - if connectedPeers > 0: - echo "Successfully connected with Waku test fleet" + if len(switch.connectedPeers(Direction.Out)) > 0: + sleep(10000) + echo "Successfully out connected with Waku test fleet" + elif len(switch.connectedPeers(Direction.In)) > 0: + sleep(10000) + echo "Successfully in connected with Waku test fleet" + else: + sleep(10000) + echo "Not connected to any peers" let peerManager = PeerManager.new(switch) let wakuPx = WakuPeerExchange(peerManager: peerManager) when isMainModule: - waitFor main() + waitFor main() \ No newline at end of file From c2ac6bb6fe9cdcfccd84fda14fc47c41524e4179 Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Thu, 8 Aug 2024 14:32:56 +0530 Subject: [PATCH 09/16] chore: update the PR --- .../peer_exchange_tester.nim | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim index 5150801285..77d2250622 100644 --- a/apps/peer_exchange_tester/peer_exchange_tester.nim +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -1,39 +1,39 @@ -# import random, strutils, asyncdispatch, chronos, chronicles, stew/byteutils, waku/[waku_peer_exchange, node/peer_manager], tests/testlib/wakucore import random, chronos, chronicles, stew/byteutils, os import waku/[waku_peer_exchange, node/peer_manager] import tests/testlib/wakucore -proc createSwitch(): Switch = - echo "switch created" - let addrs = MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() - return newStandardSwitch(addrs = addrs) - proc connectToPeer(sw: Switch, peerAddr: string) {.async.} = let ma = MultiAddress.init(peerAddr).tryGet() let str = "16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W" let peerIdData = cast[seq[byte]](str) let peerId = PeerId(data: peerIdData) - echo "trying to connect with peer" - # await sw.connect(peerId, @[ma]) - # discard sw.dial(peerId, "/vac/waku/peer-exchange/2.0.0-alpha1") + echo "2) ---------------> trying to connect with peer" + await sw.connect(peerId, @[ma]) + # discard sw.dial(peerId, @[ma], "/vac/waku/peer-exchange/2.0.0-alpha1") echo "Connected to peer with address: ", peerAddr proc main() {.async.} = echo "main started" - let addrs = "/ip4/178.128.141.171/tcp/30303" - let switch = createSwitch() + let addrs = + "/ip4/178.128.141.171/tcp/30303/16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W" + let switch = newStandardSwitch() + discard switch.start() + await connectToPeer(switch, addrs) if len(switch.connectedPeers(Direction.Out)) > 0: - sleep(10000) echo "Successfully out connected with Waku test fleet" elif len(switch.connectedPeers(Direction.In)) > 0: - sleep(10000) echo "Successfully in connected with Waku test fleet" else: - sleep(10000) echo "Not connected to any peers" + let peerManager = PeerManager.new(switch) let wakuPx = WakuPeerExchange(peerManager: peerManager) + for i in 1 .. 20: + sleep(1000000) + let response = await wakuPx.request(5) + # check how many peerid arn't stale + when isMainModule: - waitFor main() \ No newline at end of file + waitFor main() From ef1458089a0e22b5b04a3191e402f6707dabd7e8 Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Fri, 9 Aug 2024 01:50:00 +0530 Subject: [PATCH 10/16] chore: initial analsys start --- .../peer_exchange_tester.nim | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim index 77d2250622..07774f4cc4 100644 --- a/apps/peer_exchange_tester/peer_exchange_tester.nim +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -1,24 +1,23 @@ import random, chronos, chronicles, stew/byteutils, os +import libp2p/peerId import waku/[waku_peer_exchange, node/peer_manager] import tests/testlib/wakucore proc connectToPeer(sw: Switch, peerAddr: string) {.async.} = let ma = MultiAddress.init(peerAddr).tryGet() let str = "16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W" - let peerIdData = cast[seq[byte]](str) - let peerId = PeerId(data: peerIdData) - echo "2) ---------------> trying to connect with peer" + # let peerIdData = cast[seq[byte]](str) + let peerId = PeerId.init(str).tryGet() await sw.connect(peerId, @[ma]) - # discard sw.dial(peerId, @[ma], "/vac/waku/peer-exchange/2.0.0-alpha1") + discard sw.dial(peerId, @[ma], "/vac/waku/peer-exchange/2.0.0-alpha1") echo "Connected to peer with address: ", peerAddr proc main() {.async.} = echo "main started" - let addrs = - "/ip4/178.128.141.171/tcp/30303/16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W" + let addrs = "/ip4/178.128.141.171/tcp/30303/" let switch = newStandardSwitch() discard switch.start() - + echo "\n ---------------------------------- switch started ----------------------------------------- \n" await connectToPeer(switch, addrs) if len(switch.connectedPeers(Direction.Out)) > 0: echo "Successfully out connected with Waku test fleet" @@ -26,14 +25,31 @@ proc main() {.async.} = echo "Successfully in connected with Waku test fleet" else: echo "Not connected to any peers" + + echo "\n ---------------------------------- connection completed -------------------------------- \n" let peerManager = PeerManager.new(switch) let wakuPx = WakuPeerExchange(peerManager: peerManager) - + + echo "----------------------------------------------------------------------------------------------" for i in 1 .. 20: - sleep(1000000) - let response = await wakuPx.request(5) - # check how many peerid arn't stale - + echo "Seq No :- " & $i & " ---> " + echo $wakuPx.enrCache + sleep(120000) + # let res1 = await wakuPx.request(1) + # echo "\n -------------------------------- response -------------------------------------\n" + # if res1.isOk: + # echo "response count :- " & $res1.get().peerInfos.len + # echo "\n -------------- requested 4 peer through px protocol ------------------------------------\n" + # echo res1 + # for i in 1 .. 20: + # echo "Request no :- " & $i & " ------> " + # let res1 = await wakuPx.request(5) + # if res1.get().peerInfos.len == 5: + # echo "It's 5 peers" + # else: + # echo "it isn't 5 peers" + # sleep(300000) + echo "---------------------------- Done ------------------------------- " when isMainModule: waitFor main() From 6b8b19648429e9d5f6df797264a3811d386d4b71 Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Tue, 13 Aug 2024 18:50:56 +0530 Subject: [PATCH 11/16] chore: update the PR --- .../peer_exchange_tester.nim | 61 ++++++++++--------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim index 07774f4cc4..660b938291 100644 --- a/apps/peer_exchange_tester/peer_exchange_tester.nim +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -1,55 +1,60 @@ import random, chronos, chronicles, stew/byteutils, os import libp2p/peerId +import + waku/[ + waku_peer_exchange, + node/peer_manager, + node/peer_manager/peer_store/waku_peer_storage, + node/peer_manager/peer_manager, + ] import waku/[waku_peer_exchange, node/peer_manager] import tests/testlib/wakucore -proc connectToPeer(sw: Switch, peerAddr: string) {.async.} = +proc connectToPeer(sw: Switch, peerAddr: string, peerId: string) {.async.} = let ma = MultiAddress.init(peerAddr).tryGet() - let str = "16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W" - # let peerIdData = cast[seq[byte]](str) - let peerId = PeerId.init(str).tryGet() + let peerId = PeerId.init(peerId).tryGet() await sw.connect(peerId, @[ma]) - discard sw.dial(peerId, @[ma], "/vac/waku/peer-exchange/2.0.0-alpha1") - echo "Connected to peer with address: ", peerAddr + let conn = await sw.dial(peerId, @[ma], "/vac/waku/peer-exchange/2.0.0-alpha1") + if conn.isNil: + echo "--------> Connection failed: No connection returned." + else: + echo "--------> Connection successful: " proc main() {.async.} = echo "main started" let addrs = "/ip4/178.128.141.171/tcp/30303/" + let id = "16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W" let switch = newStandardSwitch() discard switch.start() - echo "\n ---------------------------------- switch started ----------------------------------------- \n" - await connectToPeer(switch, addrs) + + await connectToPeer(switch, addrs, id) if len(switch.connectedPeers(Direction.Out)) > 0: echo "Successfully out connected with Waku test fleet" elif len(switch.connectedPeers(Direction.In)) > 0: echo "Successfully in connected with Waku test fleet" else: echo "Not connected to any peers" - + echo "\n ---------------------------------- connection completed -------------------------------- \n" - let peerManager = PeerManager.new(switch) + let database = SqliteDatabase.new(":memory:").tryGet() + let storage = WakuPeerStorage.new(database).tryGet() + let peerManager = PeerManager.new(switch = switch, storage = storage) let wakuPx = WakuPeerExchange(peerManager: peerManager) - - echo "----------------------------------------------------------------------------------------------" + for i in 1 .. 20: echo "Seq No :- " & $i & " ---> " - echo $wakuPx.enrCache + echo $wakuPx.enrCache + + let res1 = await wakuPx.request(1) + if res1.isOk: + echo "response count :- " & $res1.get().peerInfos.len + else: + echo "request isn't ok" + sleep(120000) - # let res1 = await wakuPx.request(1) - # echo "\n -------------------------------- response -------------------------------------\n" - # if res1.isOk: - # echo "response count :- " & $res1.get().peerInfos.len - # echo "\n -------------- requested 4 peer through px protocol ------------------------------------\n" - # echo res1 - # for i in 1 .. 20: - # echo "Request no :- " & $i & " ------> " - # let res1 = await wakuPx.request(5) - # if res1.get().peerInfos.len == 5: - # echo "It's 5 peers" - # else: - # echo "it isn't 5 peers" - # sleep(300000) - echo "---------------------------- Done ------------------------------- " + + echo "---------------------------- Done ------------------------------- " + when isMainModule: waitFor main() From 5fa4f6d9d8b1e9ee768525db719f0000345d36d1 Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Wed, 21 Aug 2024 19:49:25 +0530 Subject: [PATCH 12/16] chore: working px tools --- .../peer_exchange_tester.nim | 126 ++++++++++++------ 1 file changed, 83 insertions(+), 43 deletions(-) diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim index 660b938291..14a91fe51b 100644 --- a/apps/peer_exchange_tester/peer_exchange_tester.nim +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -1,58 +1,98 @@ -import random, chronos, chronicles, stew/byteutils, os +import random, chronos, chronicles, stew/byteutils, os, osproc, strutils +import strutils, options, nimcrypto +import options, nimcrypto import libp2p/peerId import waku/[ + waku_node, waku_peer_exchange, node/peer_manager, node/peer_manager/peer_store/waku_peer_storage, node/peer_manager/peer_manager, + node/peer_manager, + factory/waku, + factory/external_config, + common/logging, ] -import waku/[waku_peer_exchange, node/peer_manager] -import tests/testlib/wakucore - -proc connectToPeer(sw: Switch, peerAddr: string, peerId: string) {.async.} = - let ma = MultiAddress.init(peerAddr).tryGet() - let peerId = PeerId.init(peerId).tryGet() - await sw.connect(peerId, @[ma]) - let conn = await sw.dial(peerId, @[ma], "/vac/waku/peer-exchange/2.0.0-alpha1") - if conn.isNil: - echo "--------> Connection failed: No connection returned." - else: - echo "--------> Connection successful: " proc main() {.async.} = - echo "main started" + 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) + + echo "--------------------------------------------------------------------------------" + let addrs = "/ip4/178.128.141.171/tcp/30303/" let id = "16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W" - let switch = newStandardSwitch() - discard switch.start() - - await connectToPeer(switch, addrs, id) - if len(switch.connectedPeers(Direction.Out)) > 0: - echo "Successfully out connected with Waku test fleet" - elif len(switch.connectedPeers(Direction.In)) > 0: - echo "Successfully in connected with Waku test fleet" - else: - echo "Not connected to any peers" - - echo "\n ---------------------------------- connection completed -------------------------------- \n" - - let database = SqliteDatabase.new(":memory:").tryGet() - let storage = WakuPeerStorage.new(database).tryGet() - let peerManager = PeerManager.new(switch = switch, storage = storage) - let wakuPx = WakuPeerExchange(peerManager: peerManager) - - for i in 1 .. 20: - echo "Seq No :- " & $i & " ---> " - echo $wakuPx.enrCache - - let res1 = await wakuPx.request(1) - if res1.isOk: - echo "response count :- " & $res1.get().peerInfos.len - else: - echo "request isn't ok" - - sleep(120000) + let ma = MultiAddress.init(addrs).tryGet() + let peerId = PeerId.init(id).tryGet() + let peer_info = RemotePeerInfo.init(peerId, @[ma]) + + let response = await wakuApp.node.wakuPeerExchange.request(2, peer_info) + + # echo $response + echo $response.get().peerInfos + + let pxInfo = response.get().peerInfos + + for info in pxInfo: + # echo info.enr.Record() + let info_str = cast[string](info.enr) + + echo info_str + echo "------------------" + echo info + echo "------------------" + # enr = info_str + # let ip = enr["ip4"] + # let port = enr["tcp"] + + # let pubkey = enr["secp256k1"] + # let peerId = PeerId.initFromPubKey(pubkey).get() + + # let addrs = fmt"/ip4/{ip}/tcp/{port}" + # let ma = MultiAddress.init(addrs).tryGet() + + # let peerInfo = RemotePeerInfo.init(peerId, @[ma]) + + # echo peerInfo + + if response.isOk: + echo "--------------------------- peer exchange succesfully -------------------------" + + # let wakuPx = WakuPeerExchange(peerManager: peerManager) + + # for i in 1 .. 20: + # echo "Seq No :- " & $i & " ---> " + # echo $wakuPx.enrCache + + # let res1 = await wakuPx.request(1) + # if res1.isOk: + # echo "response count :- " & $res1.get().peerInfos.len + # else: + # echo "request isn't ok" + + # sleep(120000) echo "---------------------------- Done ------------------------------- " From 518976204fd5da048f6359a6eec401a274ff639a Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Thu, 22 Aug 2024 14:49:48 +0530 Subject: [PATCH 13/16] final draft --- .../peer_exchange_tester.nim | 79 +++++++------------ 1 file changed, 29 insertions(+), 50 deletions(-) diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim index 14a91fe51b..0ec6db32df 100644 --- a/apps/peer_exchange_tester/peer_exchange_tester.nim +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -1,13 +1,11 @@ -import random, chronos, chronicles, stew/byteutils, os, osproc, strutils -import strutils, options, nimcrypto -import options, nimcrypto +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_store/waku_peer_storage, node/peer_manager/peer_manager, node/peer_manager, factory/waku, @@ -40,7 +38,8 @@ proc main() {.async.} = error "Starting waku failed", error = error quit(QuitFailure) - echo "--------------------------------------------------------------------------------" + let switch = newStandardSwitch() + discard switch.start() let addrs = "/ip4/178.128.141.171/tcp/30303/" let id = "16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W" @@ -48,51 +47,31 @@ proc main() {.async.} = let peerId = PeerId.init(id).tryGet() let peer_info = RemotePeerInfo.init(peerId, @[ma]) - let response = await wakuApp.node.wakuPeerExchange.request(2, peer_info) - - # echo $response - echo $response.get().peerInfos - - let pxInfo = response.get().peerInfos - - for info in pxInfo: - # echo info.enr.Record() - let info_str = cast[string](info.enr) - - echo info_str - echo "------------------" - echo info - echo "------------------" - # enr = info_str - # let ip = enr["ip4"] - # let port = enr["tcp"] - - # let pubkey = enr["secp256k1"] - # let peerId = PeerId.initFromPubKey(pubkey).get() - - # let addrs = fmt"/ip4/{ip}/tcp/{port}" - # let ma = MultiAddress.init(addrs).tryGet() - - # let peerInfo = RemotePeerInfo.init(peerId, @[ma]) - - # echo peerInfo - - if response.isOk: - echo "--------------------------- peer exchange succesfully -------------------------" - - # let wakuPx = WakuPeerExchange(peerManager: peerManager) - - # for i in 1 .. 20: - # echo "Seq No :- " & $i & " ---> " - # echo $wakuPx.enrCache - - # let res1 = await wakuPx.request(1) - # if res1.isOk: - # echo "response count :- " & $res1.get().peerInfos.len - # else: - # echo "request isn't ok" - - # sleep(120000) + var iter = 0 + var success = 0 + for i in 1 .. 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 + let conn = await switch.dial(peerId, ma, "/vac/waku/metadata/1.0.0") + success += len(switch.connectedPeers(Direction.Out)) + echo $success & " out of " & $iter & " operation successful" + # echo $switch.connectedPeers(Direction.Out) & " -- " & $switch.connectedPeers(Direction.In) + else: + echo " ------------ response isn't not ok ------------------" + + sleep(120000) echo "---------------------------- Done ------------------------------- " From 0dc9e473aa8430df71b2a43675c647584c5b9cde Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Thu, 22 Aug 2024 16:20:37 +0530 Subject: [PATCH 14/16] exception handling in the PR --- .../peer_exchange_tester.nim | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim index 0ec6db32df..0d2cb65c4d 100644 --- a/apps/peer_exchange_tester/peer_exchange_tester.nim +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -49,7 +49,7 @@ proc main() {.async.} = var iter = 0 var success = 0 - for i in 1 .. 60: + for i in 0 .. 60: echo "Seq No :- " & $i & " ---> " let response = await wakuApp.node.wakuPeerExchange.request(5, peer_info) @@ -64,15 +64,22 @@ proc main() {.async.} = let ma = peer_info.addrs echo $iter & ") -----> " & $ma[0] & " -- " & $peerId iter += 1 - let conn = await switch.dial(peerId, ma, "/vac/waku/metadata/1.0.0") + 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" - # echo $switch.connectedPeers(Direction.Out) & " -- " & $switch.connectedPeers(Direction.In) + discard switch.disconnect(peerId) else: echo " ------------ response isn't not ok ------------------" - sleep(120000) - echo "---------------------------- Done ------------------------------- " when isMainModule: From eb519e0c4acd8919099e19b4f73c7ba71fb5d71a Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Thu, 22 Aug 2024 20:12:13 +0530 Subject: [PATCH 15/16] little more update --- apps/peer_exchange_tester/peer_exchange_tester.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim index 0d2cb65c4d..ace02cc6fe 100644 --- a/apps/peer_exchange_tester/peer_exchange_tester.nim +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -52,7 +52,7 @@ proc main() {.async.} = for i in 0 .. 60: echo "Seq No :- " & $i & " ---> " let response = await wakuApp.node.wakuPeerExchange.request(5, peer_info) - + iter += 5 if response.isOk: var validPeers = 0 let peers = response.get().peerInfos @@ -63,7 +63,7 @@ proc main() {.async.} = 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 From 382edddc89091633ae6e81be0443ef431944e446 Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Thu, 22 Aug 2024 22:06:02 +0530 Subject: [PATCH 16/16] chore: update PR --- apps/peer_exchange_tester/peer_exchange_tester.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/peer_exchange_tester/peer_exchange_tester.nim b/apps/peer_exchange_tester/peer_exchange_tester.nim index ace02cc6fe..4b229e6e97 100644 --- a/apps/peer_exchange_tester/peer_exchange_tester.nim +++ b/apps/peer_exchange_tester/peer_exchange_tester.nim @@ -52,7 +52,6 @@ proc main() {.async.} = for i in 0 .. 60: echo "Seq No :- " & $i & " ---> " let response = await wakuApp.node.wakuPeerExchange.request(5, peer_info) - iter += 5 if response.isOk: var validPeers = 0 let peers = response.get().peerInfos @@ -63,7 +62,7 @@ proc main() {.async.} = 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 @@ -80,6 +79,8 @@ proc main() {.async.} = else: echo " ------------ response isn't not ok ------------------" sleep(120000) + while iter mod 5 == 0: + iter += 1 echo "---------------------------- Done ------------------------------- " when isMainModule: