-
Notifications
You must be signed in to change notification settings - Fork 54
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
base: master
Are you sure you want to change the base?
Conversation
You can find the image built from this PR at
Built from ad15350 |
9e6659a
to
0d87d71
Compare
0d87d71
to
ad1714c
Compare
20fe5da
to
ef14580
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great one! It looks interesting so far! 🙌
I've added some comments that I hope you find useful
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 ------------------" |
There was a problem hiding this comment.
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
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) | |
.dial(peerId, ma, "/vac/waku/metadata/1.0.0") | ||
.withTimeout(wait) | ||
except TimeoutError: | ||
echo "Dialing peer " & $peerId & " timed out." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo "Dialing peer " & $peerId & " timed out." | |
echo "Dialing peer " & $peerId & " timed out. exc: " & getCurrentExceptionMsg() |
except TimeoutError: | ||
echo "Dialing peer " & $peerId & " timed out." | ||
except: | ||
echo "An error occurred while dialing peer " & $peerId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo "An error occurred while dialing peer " & $peerId | |
echo "An error occurred while dialing peer " & $peerId & " exc: " & getCurrentExceptionMsg() |
discard switch.disconnect(peerId) | ||
else: | ||
echo " ------------ response isn't not ok ------------------" | ||
sleep(120000) |
There was a problem hiding this comment.
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?
var iter = 0 | ||
var success = 0 | ||
for i in 0 .. 60: | ||
echo "Seq No :- " & $i & " ---> " |
There was a problem hiding this comment.
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 addrs = "/ip4/178.128.141.171/tcp/30303/" | ||
let id = "16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W" |
There was a problem hiding this comment.
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.
@@ -0,0 +1,86 @@ | |||
import chronos, chronicles, options, os |
There was a problem hiding this comment.
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.
This tool helps analyze the peer exchange protocol.