generated from libp2p/js-libp2p-example-fork-go-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
relay.js
37 lines (34 loc) · 1.09 KB
/
relay.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
/* eslint-disable no-console */
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { circuitRelayServer } from '@libp2p/circuit-relay-v2'
import { identify } from '@libp2p/identify'
import { webSockets } from '@libp2p/websockets'
import * as filters from '@libp2p/websockets/filters'
import { createLibp2p } from 'libp2p'
const server = await createLibp2p({
addresses: {
listen: ['/ip4/127.0.0.1/tcp/0/ws']
},
transports: [
webSockets({
filter: filters.all
})
],
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
services: {
identify: identify(),
relay: circuitRelayServer({
// disable max reservations limit for demo purposes. in production you
// should leave this set to the default of 15 to prevent abuse of your
// node by network peers
reservations: {
maxReservations: Infinity
}
})
}
})
console.info('The relay node is running and listening on the following multiaddrs:')
console.info('')
console.info(server.getMultiaddrs().map((ma) => ma.toString()).join('\n'))