docs: auto relay example (#795)

* chore: auto relay example

* chore: update examples to use process arguments

* chore: add test setup for node tests and test for auto-relay

* chore: apply suggestions from code review

* chore: do not use promise for multiaddrs event on example
This commit is contained in:
Vasco Santos
2020-11-20 15:18:15 +01:00
committed by Vasco Santos
parent 585ad52b4c
commit 4448de8432
11 changed files with 616 additions and 0 deletions

View File

@ -0,0 +1,29 @@
'use strict'
const Libp2p = require('libp2p')
const Websockets = require('libp2p-websockets')
const { NOISE } = require('libp2p-noise')
const MPLEX = require('libp2p-mplex')
async function main () {
const autoRelayNodeAddr = process.argv[2]
if (!autoRelayNodeAddr) {
throw new Error('the auto relay node address needs to be specified')
}
const node = await Libp2p.create({
modules: {
transport: [Websockets],
connEncryption: [NOISE],
streamMuxer: [MPLEX]
}
})
await node.start()
console.log(`Node started with id ${node.peerId.toB58String()}`)
const conn = await node.dial(autoRelayNodeAddr)
console.log(`Connected to the auto relay node via ${conn.remoteAddr.toString()}`)
}
main()