mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-09 09:23:14 +00:00
test: connect remote peers
This commit is contained in:
parent
eae7e23d7c
commit
12a61a022a
2
Makefile
2
Makefile
@ -229,7 +229,7 @@ test/%: | build deps librln
|
||||
################
|
||||
## Waku tools ##
|
||||
################
|
||||
.PHONY: tools wakucanary networkmonitor peerexchangetester
|
||||
.PHONY: tools wakucanary networkmonitor peer_exchange_tester
|
||||
|
||||
tools: networkmonitor wakucanary
|
||||
|
||||
|
||||
@ -1,15 +1,24 @@
|
||||
import
|
||||
std/[options, sequtils, random],
|
||||
chronos, chronicles, stew/byteutils
|
||||
|
||||
import
|
||||
waku/[waku_peer_exchange, node/peer_manager]
|
||||
# import random, strutils, asyncdispatch, chronos, chronicles, stew/byteutils, waku/[waku_peer_exchange, node/peer_manager], tests/testlib/wakucore
|
||||
import random, chronos, chronicles, stew/byteutils
|
||||
import waku/[waku_peer_exchange, node/peer_manager]
|
||||
import tests/testlib/wakucore
|
||||
import asyncdispatch as asyncd
|
||||
|
||||
# import chronicles, chronos, stew/byteutils, results
|
||||
# import waku/[common/logging, node/peer_manager, waku_core, waku_filter_v2/client]
|
||||
proc createSwitch(): Switch =
|
||||
let addrs = MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet()
|
||||
newStandardSwitch(addrs = addrs)
|
||||
|
||||
proc connectToPeer(sw: Switch, peerAddr: string) {.async.} =
|
||||
let ma = MultiAddress.init(peerAddr).tryGet()
|
||||
let str = "16Uiu2HAm2uZtDK3T4zgseP16uGB6s2q2i8zpviLBmXyukjU5BPVT"
|
||||
let peerIdData = str.mapIt(cast[byte](it))
|
||||
let peerId = PeerId(data: peerIdData)
|
||||
let connection = await sw.dial(peerId, @[ma], @["defaultProto"])
|
||||
|
||||
proc main() {.async.} =
|
||||
let switch = newStandardSwitch()
|
||||
let addrs = "/ip4/139.99.173.27/tcp/30304"
|
||||
let switch = createSwitch()
|
||||
await switch.connectToPeer(addrs)
|
||||
let peerManager = PeerManager.new(switch)
|
||||
let wakuPx = WakuPeerExchange(peerManager: peerManager)
|
||||
|
||||
@ -24,4 +33,4 @@ proc main() {.async.} =
|
||||
echo "Error requesting peers: ", res.error
|
||||
|
||||
when isMainModule:
|
||||
waitFor main()
|
||||
asyncMain(main)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user