mirror of
https://github.com/status-im/nim-libp2p.git
synced 2025-01-11 13:34:26 +00:00
b63e064b4a
* Merge master (#555) * Revisit Floodsub (#543) Fixes #525 add coverage to unsubscribeAll and testing * add mounted protos to identify message (#546) * add stable/unstable auto bumps * fix auto-bump CI * merge nbc auto bump with CI in order to bump only on CI success * put conditional locks on nbc bump (#549) * Fix minor exception issues (#550) Makes code compatible with https://github.com/status-im/nim-chronos/pull/166 without requiring it. * fix nimbus ref for auto-bump stable's PR * Split dialer (#542) * extracting dialing logic to dialer * exposing upgrade methods on transport * cleanup * fixing tests to use new interfaces * add comments * add base exception class and fix hierarchy * fix imports * `doAssert` is `ValueError` not `AssertionError`? * revert back to `AssertionError` Co-authored-by: Giovanni Petrantoni <7008900+sinkingsugar@users.noreply.github.com> Co-authored-by: Jacek Sieka <jacek@status.im> * Merge master (#555) * Revisit Floodsub (#543) Fixes #525 add coverage to unsubscribeAll and testing * add mounted protos to identify message (#546) * add stable/unstable auto bumps * fix auto-bump CI * merge nbc auto bump with CI in order to bump only on CI success * put conditional locks on nbc bump (#549) * Fix minor exception issues (#550) Makes code compatible with https://github.com/status-im/nim-chronos/pull/166 without requiring it. * fix nimbus ref for auto-bump stable's PR * Split dialer (#542) * extracting dialing logic to dialer * exposing upgrade methods on transport * cleanup * fixing tests to use new interfaces * add comments * add base exception class and fix hierarchy * fix imports * `doAssert` is `ValueError` not `AssertionError`? * revert back to `AssertionError` Co-authored-by: Giovanni Petrantoni <7008900+sinkingsugar@users.noreply.github.com> Co-authored-by: Jacek Sieka <jacek@status.im> * cleanup Co-authored-by: Giovanni Petrantoni <7008900+sinkingsugar@users.noreply.github.com> Co-authored-by: Jacek Sieka <jacek@status.im>
56 lines
1.6 KiB
Nim
56 lines
1.6 KiB
Nim
import chronos, nimcrypto, strutils
|
|
import ../../libp2p/daemon/daemonapi
|
|
import ../hexdump
|
|
|
|
const
|
|
PubSubTopic = "test-net"
|
|
|
|
proc dumpSubscribedPeers(api: DaemonAPI) {.async.} =
|
|
var peers = await api.pubsubListPeers(PubSubTopic)
|
|
echo "= List of connected and subscribed peers:"
|
|
for item in peers:
|
|
echo item.pretty()
|
|
|
|
proc dumpAllPeers(api: DaemonAPI) {.async.} =
|
|
var peers = await api.listPeers()
|
|
echo "Current connected peers count = ", len(peers)
|
|
for item in peers:
|
|
echo item.peer.pretty()
|
|
|
|
proc monitor(api: DaemonAPI) {.async.} =
|
|
while true:
|
|
echo "Dumping all peers"
|
|
await dumpAllPeers(api)
|
|
await sleepAsync(5000)
|
|
|
|
proc main() {.async.} =
|
|
echo "= Starting P2P bootnode"
|
|
var api = await newDaemonApi({DHTFull, PSGossipSub})
|
|
var id = await api.identity()
|
|
echo "= P2P bootnode ", id.peer.pretty(), " started."
|
|
let mcip4 = multiCodec("ip4")
|
|
let mcip6 = multiCodec("ip6")
|
|
echo "= You can use one of this addresses to bootstrap your nodes:"
|
|
for item in id.addresses:
|
|
if item.protoCode() == mcip4 or item.protoCode() == mcip6:
|
|
echo $item & "/ipfs/" & id.peer.pretty()
|
|
|
|
asyncSpawn monitor(api)
|
|
|
|
proc pubsubLogger(api: DaemonAPI,
|
|
ticket: PubsubTicket,
|
|
message: PubSubMessage): Future[bool] {.async.} =
|
|
let msglen = len(message.data)
|
|
echo "= Recieved pubsub message with length ", msglen,
|
|
" bytes from peer ", message.peer.pretty()
|
|
echo dumpHex(message.data)
|
|
await api.dumpSubscribedPeers()
|
|
result = true
|
|
|
|
var ticket = await api.pubsubSubscribe(PubSubTopic, pubsubLogger)
|
|
|
|
when isMainModule:
|
|
waitFor(main())
|
|
while true:
|
|
poll()
|