-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09af224
commit faa79f8
Showing
1 changed file
with
15 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
waitFor main() |