forked from libp2p/js-libp2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.aegir.js
63 lines (60 loc) · 1.77 KB
/
.aegir.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { WebSockets } from '@libp2p/websockets'
import { Mplex } from '@libp2p/mplex'
import { Noise } from '@chainsafe/libp2p-noise'
import { pipe } from 'it-pipe'
import { createFromJSON } from '@libp2p/peer-id-factory'
/** @type {import('aegir').PartialOptions} */
export default {
build: {
bundlesizeMax: '147kB'
},
test: {
before: async () => {
// use dynamic import because we only want to reference these files during the test run, e.g. after building
const { createLibp2p } = await import('./dist/src/index.js')
const { MULTIADDRS_WEBSOCKETS } = await import('./dist/test/fixtures/browser.js')
const { Plaintext } = await import('./dist/src/insecure/index.js')
const { default: Peers } = await import('./dist/test/fixtures/peers.js')
// Use the last peer
const peerId = await createFromJSON(Peers[Peers.length - 1])
const libp2p = await createLibp2p({
addresses: {
listen: [MULTIADDRS_WEBSOCKETS[0]]
},
peerId,
transports: [
new WebSockets()
],
streamMuxers: [
new Mplex()
],
connectionEncryption: [
new Noise(),
new Plaintext()
],
relay: {
enabled: true,
hop: {
enabled: true,
active: false
}
},
nat: {
enabled: false
}
})
// Add the echo protocol
await libp2p.handle('/echo/1.0.0', ({ stream }) => {
pipe(stream, stream)
.catch() // sometimes connections are closed before multistream-select finishes which causes an error
})
await libp2p.start()
return {
libp2p
}
},
after: async (_, before) => {
await before.libp2p.stop()
}
}
}