Skip to content

Commit

Permalink
fix: make the config less restrictive (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun authored Feb 25, 2019
1 parent dfe8f63 commit 5f92acd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"debug": "^4.1.0",
"err-code": "^1.1.2",
"fsm-event": "^2.1.0",
"kind-of": "^6.0.2",
"libp2p-connection-manager": "~0.0.2",
"libp2p-floodsub": "~0.15.7",
"libp2p-ping": "~0.8.5",
Expand Down
30 changes: 9 additions & 21 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
'use strict'

const { struct, superstruct } = require('superstruct')
const kind = require('kind-of')
const { optional, list } = struct

const transports = ['tcp', 'utp', 'webrtcstar', 'webrtcdirect', 'websockets', 'websocketstar']
// Define custom types
const s = superstruct({
types: {
tcp: v => kind(v) === 'tcp',
utp: v => kind(v) === 'utp',
webrtcstar: v => kind(v) === 'webrtcstar',
webrtcdirect: v => kind(v) === 'webrtcdirect',
websockets: v => kind(v) === 'websockets',
websocketstar: v => kind(v) === 'websocketstar',
transport: value => {
const [error] = list([s.union([ ...transports, 'function' ])]).validate(value)
if (error) return error.message

return value.length > 0
? true
: 'You need to provide at least one transport.'
}
}
})
const s = superstruct()
const transport = s.union([
s.interface({
createListener: 'function',
dial: 'function'
}),
'function'
])

const optionsSchema = s(
{
Expand All @@ -41,7 +29,7 @@ const optionsSchema = s(
peerDiscovery: optional(list([s('object|function')])),
peerRouting: optional(list(['object'])),
streamMuxer: optional(list([s('object|function')])),
transport: 'transport'
transport: list([transport])
}),
config: s({
peerDiscovery: 'object?',
Expand Down

0 comments on commit 5f92acd

Please sign in to comment.