forked from libp2p/js-libp2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.aegir.js
87 lines (79 loc) · 1.9 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'use strict'
const pull = require('pull-stream')
const parallel = require('async/parallel')
const WebSocketStarRendezvous = require('libp2p-websocket-star-rendezvous')
const sigServer = require('libp2p-webrtc-star/src/sig-server')
const Node = require('./test/utils/bundle-nodejs.js')
const {
getPeerRelay,
WRTC_RENDEZVOUS_MULTIADDR,
WS_RENDEZVOUS_MULTIADDR
} = require('./test/utils/constants')
let wrtcRendezvous
let wsRendezvous
let node
const before = (done) => {
parallel([
(cb) => {
sigServer.start({
port: WRTC_RENDEZVOUS_MULTIADDR.nodeAddress().port
// cryptoChallenge: true TODO: needs https://github.com/libp2p/js-libp2p-webrtc-star/issues/128
}, (err, server) => {
if (err) {
return cb(err)
}
wrtcRendezvous = server
cb()
})
},
(cb) => {
WebSocketStarRendezvous.start({
port: WS_RENDEZVOUS_MULTIADDR.nodeAddress().port,
refreshPeerListIntervalMS: 1000,
strictMultiaddr: false,
cryptoChallenge: true
}, (err, _server) => {
if (err) {
return cb(err)
}
wsRendezvous = _server
cb()
})
},
(cb) => {
getPeerRelay((err, peerInfo) => {
if (err) {
return done(err)
}
node = new Node({
peerInfo,
config: {
relay: {
enabled: true,
hop: {
enabled: true,
active: true
}
}
}
})
node.handle('/echo/1.0.0', (protocol, conn) => pull(conn, conn))
node.start(cb)
})
}
], done)
}
const after = (done) => {
setTimeout(() =>
parallel(
[node, wrtcRendezvous, wsRendezvous].map((s) => (cb) => s.stop(cb)),
done),
2000)
}
module.exports = {
bundlesize: { maxSize: '215kB' },
hooks: {
pre: before,
post: after
}
}