1
0
mirror of https://github.com/fluencelabs/js-libp2p synced 2025-03-16 15:40:49 +00:00
Hugo Dias 9b13fe321a
fix: remove node global ()
* fix: use new libp2p-crypto

* fix: remove node globals and reduce size

- adds buffer require
- adds globalThis where needed
- streaming-iterables was remove and new utils created, this will be consolidated in `ipfs-utils` and backported here to normalize all these iterator helper functions
- latency-monitor was copied inside the repo
- iso-random-stream is now used instead of node crypto
- the test `should ignore self on discovery` was moved to node only

Size: 172.97KB
47.03KB below the 220KB limit.

`aegir build --node false` and `aegir test -t browser --node false` now work 🎉

* fix: fix require path

* fix: feedback

* fix: update deps and bundle size

* chore: bump interfaces

* chore: update size
2020-04-24 17:10:40 +02:00

54 lines
1.2 KiB
JavaScript

'use strict'
const Libp2p = require('./src')
const { MULTIADDRS_WEBSOCKETS } = require('./test/fixtures/browser')
const Peers = require('./test/fixtures/peers')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const WebSockets = require('libp2p-websockets')
const Muxer = require('libp2p-mplex')
const Crypto = require('libp2p-secio')
const pipe = require('it-pipe')
let libp2p
const before = async () => {
// Use the last peer
const peerId = await PeerId.createFromJSON(Peers[Peers.length - 1])
const peerInfo = new PeerInfo(peerId)
peerInfo.multiaddrs.add(MULTIADDRS_WEBSOCKETS[0])
libp2p = new Libp2p({
peerInfo,
modules: {
transport: [WebSockets],
streamMuxer: [Muxer],
connEncryption: [Crypto]
},
config: {
relay: {
enabled: true,
hop: {
enabled: true,
active: false
}
}
}
})
// Add the echo protocol
libp2p.handle('/echo/1.0.0', ({ stream }) => pipe(stream, stream))
await libp2p.start()
}
const after = async () => {
await libp2p.stop()
}
module.exports = {
bundlesize: { maxSize: '179kB' },
hooks: {
pre: before,
post: after
}
}