docs: update examples to 0.28.x api (#625)

* chore: update examples to 0.28 api

* chore: use libp2p-noise in examples

* chore: examples using multiaddrs property of libp2p

Co-authored-by: Jacob Heun <jacobheun@gmail.com>

* docs: update language around secio in crypto example

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
This commit is contained in:
Vasco Santos
2020-05-15 15:37:47 +02:00
committed by Jacob Heun
parent 56316b8c1e
commit 0fbb59748e
30 changed files with 298 additions and 249 deletions

View File

@ -3,21 +3,20 @@
const Libp2p = require('../../')
const TCP = require('libp2p-tcp')
const Mplex = require('libp2p-mplex')
const { NOISE } = require('libp2p-noise')
const SECIO = require('libp2p-secio')
const PeerInfo = require('peer-info')
const pipe = require('it-pipe')
const createNode = async () => {
const peerInfo = await PeerInfo.create()
peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0')
const node = await Libp2p.create({
peerInfo,
addresses: {
listen: ['/ip4/0.0.0.0/tcp/0']
},
modules: {
transport: [TCP],
streamMuxer: [Mplex],
connEncryption: [SECIO]
connEncryption: [NOISE, SECIO]
}
})
@ -32,6 +31,8 @@ const createNode = async () => {
createNode()
])
node1.peerStore.addressBook.set(node2.peerId, node2.multiaddrs)
node2.handle('/a-protocol', ({ stream }) => {
pipe(
stream,
@ -43,7 +44,7 @@ const createNode = async () => {
)
})
const { stream } = await node1.dialProtocol(node2.peerInfo, '/a-protocol')
const { stream } = await node1.dialProtocol(node2.peerId, '/a-protocol')
await pipe(
['This information is sent out encrypted to the other peer'],