mirror of https://github.com/vacp2p/nim-libp2p.git
Fix examples for new PeerID.
This commit is contained in:
parent
1e6c8b2171
commit
53467d028f
|
@ -1,5 +1,6 @@
|
||||||
import chronos, nimcrypto, strutils
|
import chronos, nimcrypto, strutils
|
||||||
import ../libp2p/daemon/daemonapi, ../libp2p/[base58, multicodec, multiaddress]
|
import ../libp2p/daemon/daemonapi
|
||||||
|
import ../libp2p/[base58, multicodec, multiaddress, peer]
|
||||||
import hexdump
|
import hexdump
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -9,28 +10,26 @@ proc dumpSubscribedPeers(api: DaemonAPI) {.async.} =
|
||||||
var peers = await api.pubsubListPeers(PubSubTopic)
|
var peers = await api.pubsubListPeers(PubSubTopic)
|
||||||
echo "= List of connected and subscribed peers:"
|
echo "= List of connected and subscribed peers:"
|
||||||
for item in peers:
|
for item in peers:
|
||||||
echo Base58.encode(item)
|
echo item.pretty()
|
||||||
|
|
||||||
proc main() {.async.} =
|
proc main() {.async.} =
|
||||||
echo "= Starting P2P bootnode"
|
echo "= Starting P2P bootnode"
|
||||||
var api = await newDaemonApi({DHTFull, PSGossipSub})
|
var api = await newDaemonApi({DHTFull, PSGossipSub})
|
||||||
var id = await api.identity()
|
var id = await api.identity()
|
||||||
let tpeerid = Base58.encode(id.peer)
|
echo "= P2P bootnode ", id.peer.pretty(), " started."
|
||||||
echo "= P2P bootnode ", tpeerid, " started."
|
|
||||||
let mcip4 = multiCodec("ip4")
|
let mcip4 = multiCodec("ip4")
|
||||||
let mcip6 = multiCodec("ip6")
|
let mcip6 = multiCodec("ip6")
|
||||||
echo "= You can use one of this addresses to bootstrap your nodes:"
|
echo "= You can use one of this addresses to bootstrap your nodes:"
|
||||||
for item in id.addresses:
|
for item in id.addresses:
|
||||||
if item.protoCode() == mcip4 or item.protoCode() == mcip6:
|
if item.protoCode() == mcip4 or item.protoCode() == mcip6:
|
||||||
echo $item & "/ipfs/" & tpeerid
|
echo $item & "/ipfs/" & id.peer.pretty()
|
||||||
|
|
||||||
proc pubsubLogger(api: DaemonAPI,
|
proc pubsubLogger(api: DaemonAPI,
|
||||||
ticket: PubsubTicket,
|
ticket: PubsubTicket,
|
||||||
message: PubSubMessage): Future[bool] {.async.} =
|
message: PubSubMessage): Future[bool] {.async.} =
|
||||||
let bpeer = Base58.encode(message.peer)
|
|
||||||
let msglen = len(message.data)
|
let msglen = len(message.data)
|
||||||
echo "= Recieved pubsub message wit length ", msglen,
|
echo "= Recieved pubsub message wit length ", msglen,
|
||||||
" bytes from peer ", bpeer
|
" bytes from peer ", message.peer.pretty()
|
||||||
echo dumpHex(message.data)
|
echo dumpHex(message.data)
|
||||||
await api.dumpSubscribedPeers()
|
await api.dumpSubscribedPeers()
|
||||||
result = true
|
result = true
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import chronos, nimcrypto, strutils, os
|
import chronos, nimcrypto, strutils, os
|
||||||
import ../libp2p/daemon/daemonapi, ../libp2p/[base58, multiaddress]
|
import ../libp2p/daemon/daemonapi, ../libp2p/[base58, multiaddress, peer]
|
||||||
|
|
||||||
proc main(bn: string) {.async.} =
|
proc main(bn: string) {.async.} =
|
||||||
echo "= Starting P2P node"
|
echo "= Starting P2P node"
|
||||||
|
@ -8,17 +8,16 @@ proc main(bn: string) {.async.} =
|
||||||
bootstrapNodes = bootnodes,
|
bootstrapNodes = bootnodes,
|
||||||
peersRequired = 1)
|
peersRequired = 1)
|
||||||
var id = await api.identity()
|
var id = await api.identity()
|
||||||
echo "= P2P node ", Base58.encode(id.peer), " started:"
|
echo "= P2P node ", id.peer.pretty(), " started:"
|
||||||
for item in id.addresses:
|
for item in id.addresses:
|
||||||
echo item
|
echo item
|
||||||
|
|
||||||
proc pubsubLogger(api: DaemonAPI,
|
proc pubsubLogger(api: DaemonAPI,
|
||||||
ticket: PubsubTicket,
|
ticket: PubsubTicket,
|
||||||
message: PubSubMessage): Future[bool] {.async.} =
|
message: PubSubMessage): Future[bool] {.async.} =
|
||||||
let bpeer = Base58.encode(message.peer)
|
|
||||||
let msglen = len(message.data)
|
let msglen = len(message.data)
|
||||||
echo "= Recieved pubsub message wit length ", msglen,
|
echo "= Recieved pubsub message wit length ", msglen,
|
||||||
" bytes from peer ", bpeer
|
" bytes from peer ", message.peer.pretty()
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
var ticket = await api.pubsubSubscribe("test-net", pubsubLogger)
|
var ticket = await api.pubsubSubscribe("test-net", pubsubLogger)
|
||||||
|
|
Loading…
Reference in New Issue