test: initial peer_exchange tester

This commit is contained in:
DarshanBPatel 2024-07-29 13:46:41 +05:30
parent 71946b911f
commit eae7e23d7c
6 changed files with 40 additions and 2 deletions

View File

@ -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 ##

View File

View File

@ -0,0 +1,4 @@
-d:chronicles_line_numbers
-d:chronicles_runtime_filtering:on
-d:discv5_protocol_id:d5waku
path = "../.."

View File

@ -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()

View File

@ -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/"

View File

@ -203,4 +203,4 @@ proc new*(
let wpx = WakuPeerExchange(peerManager: peerManager, cluster: cluster)
wpx.initProtocolHandler()
asyncSpawn wpx.updatePxEnrCache()
return wpx
return wpx