Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: peer exchange testing tool #2940

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ test/%: | build deps librln
################
## Waku tools ##
################
.PHONY: tools wakucanary networkmonitor
.PHONY: tools wakucanary networkmonitor peer_exchange_tester

tools: networkmonitor wakucanary

Expand All @@ -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 ##
Expand Down
Empty file.
4 changes: 4 additions & 0 deletions apps/peer_exchange_tester/nim.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-d:chronicles_line_numbers
-d:chronicles_runtime_filtering:on
-d:discv5_protocol_id:d5waku
path = "../.."
86 changes: 86 additions & 0 deletions apps/peer_exchange_tester/peer_exchange_tester.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import chronos, chronicles, options, os
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot add a comment in the README.md
The README.md should have content explaining the purpose of the tool and how to use it properly to get the maximum profit of it.

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"
Comment on lines +44 to +45
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having a hard-coded value, it should support that from a cli parameter. Nevertheless, let's leave it as is for now and optimize in the future if needed.

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 & " ---> "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to always use chronicles. e.g. `debug "Seq No", 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."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Dialing peer " & $peerId & " timed out."
echo "Dialing peer " & $peerId & " timed out. exc: " & getCurrentExceptionMsg()

except:
echo "An error occurred while dialing peer " & $peerId
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "An error occurred while dialing peer " & $peerId
echo "An error occurred while dialing peer " & $peerId & " exc: " & getCurrentExceptionMsg()


success += len(switch.connectedPeers(Direction.Out))
echo $success & " out of " & $iter & " operation successful"
discard switch.disconnect(peerId)
else:
echo " ------------ response isn't not ok ------------------"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we can use valueOr

Suggested change
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 ------------------"
let response = await wakuApp.node.wakuPeerExchange.request(5, peer_info).valueOr:
echo " ------------ response isn't not ok ------------------"
var validPeers = 0
let peers = response.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)

sleep(120000)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need to wait for so long?

echo "---------------------------- Done ------------------------------- "

when isMainModule:
waitFor main()
4 changes: 4 additions & 0 deletions waku.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
Loading