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

Conversation

darshankabariya
Copy link
Contributor

This tool helps analyze the peer exchange protocol.

Copy link

github-actions bot commented Jul 29, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2940

Built from ad15350

@darshankabariya darshankabariya changed the title tool: peer exchange testing tool test: peer exchange testing tool Jul 29, 2024
@darshankabariya darshankabariya marked this pull request as draft July 30, 2024 14:09
Copy link
Collaborator

@Ivansete-status Ivansete-status left a 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

Comment on lines 54 to 81
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 ------------------"
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)

.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 TimeoutError:
echo "Dialing peer " & $peerId & " timed out."
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()

discard switch.disconnect(peerId)
else:
echo " ------------ response isn't not ok ------------------"
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?

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

Comment on lines +44 to +45
let addrs = "/ip4/178.128.141.171/tcp/30303/"
let id = "16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W"
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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants