js-libp2p/src/config.js

70 lines
1.4 KiB
JavaScript
Raw Normal View History

'use strict'
const mergeOptions = require('merge-options')
const Constants = require('./constants')
const { FaultTolerance } = require('./transport-manager')
const DefaultConfig = {
addresses: {
2020-04-18 23:26:46 +02:00
listen: [],
announce: [],
noAnnounce: []
},
connectionManager: {
minConnections: 25
},
transportManager: {
faultTolerance: FaultTolerance.FATAL_ALL
},
dialer: {
maxParallelDials: Constants.MAX_PARALLEL_DIALS,
maxDialsPerPeer: Constants.MAX_PER_PEER_DIALS,
dialTimeout: Constants.DIAL_TIMEOUT
},
metrics: {
enabled: false
},
2020-04-23 14:08:34 +02:00
peerStore: {
persistence: false,
threshold: 5
2020-04-23 14:08:34 +02:00
},
config: {
dht: {
enabled: false,
kBucketSize: 20,
randomWalk: {
enabled: false, // disabled waiting for https://github.com/libp2p/js-libp2p-kad-dht/issues/86
queriesPerPeriod: 1,
interval: 300e3,
timeout: 10e3
}
},
peerDiscovery: {
autoDial: true
},
pubsub: {
enabled: true,
emitSelf: true,
signMessages: true,
strictSigning: true
},
relay: {
enabled: true,
hop: {
enabled: false,
active: false
}
},
transport: {}
}
}
module.exports.validate = (opts) => {
opts = mergeOptions(DefaultConfig, opts)
if (opts.modules.transport.length < 1) throw new Error("'options.modules.transport' must contain at least 1 transport")
return opts
}