From 344492790206a1d285e9d56d4362145cb2d830a4 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 17 Jul 2019 09:25:20 +0100 Subject: [PATCH 1/2] fix: passed config validation Fixes validation for `config.Addresses.API` and `config.Addresses.Gateway` to allow array of multiaddr and adds missing `config.Swarm.ConnMgr` validation. License: MIT Signed-off-by: Alan Shaw --- src/core/config.js | 12 +++++++++--- test/core/config.spec.js | 12 ++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/core/config.js b/src/core/config.js index 2fb66bb558..3133eb9da5 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -54,8 +54,8 @@ const configSchema = s({ API: 'object?', Addresses: optional(s({ Swarm: optional(s(['multiaddr'])), - API: 'multiaddr?', - Gateway: 'multiaddr' + API: optional(union([s('multiaddr'), s(['multiaddr'])])), + Gateway: optional(union([s('multiaddr'), s(['multiaddr'])])) })), Discovery: optional(s({ MDNS: optional(s({ @@ -66,7 +66,13 @@ const configSchema = s({ Enabled: 'boolean?' })) })), - Bootstrap: optional(s(['multiaddr-ipfs'])) + Bootstrap: optional(s(['multiaddr-ipfs'])), + Swarm: optional(s({ + ConnMgr: optional(s({ + LowWater: 'number?', + HighWater: 'number?' + })) + })) })), ipld: 'object?', libp2p: optional(union(['function', 'object'])) // libp2p validates this diff --git a/test/core/config.spec.js b/test/core/config.spec.js index 4ce3ffab05..78ea700b8a 100644 --- a/test/core/config.spec.js +++ b/test/core/config.spec.js @@ -123,9 +123,11 @@ describe('config', () => { { config: { Addresses: { Swarm: undefined } } }, { config: { Addresses: { API: '/ip4/127.0.0.1/tcp/5002' } } }, + { config: { Addresses: { API: ['/ip4/127.0.0.1/tcp/5002', '/ip4/127.0.0.1/tcp/5003'] } } }, { config: { Addresses: { API: undefined } } }, { config: { Addresses: { Gateway: '/ip4/127.0.0.1/tcp/9090' } } }, + { config: { Addresses: { Gateway: ['/ip4/127.0.0.1/tcp/9090', '/ip4/127.0.0.1/tcp/9091'] } } }, { config: { Addresses: { Gateway: undefined } } }, { config: { Addresses: undefined } }, @@ -144,6 +146,11 @@ describe('config', () => { { config: { Bootstrap: ['/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'] } }, { config: { Bootstrap: [] } }, + { config: { Swarm: { ConnMgr: { LowWater: 200, HighWater: 500 } } } }, + { config: { Swarm: { ConnMgr: { LowWater: undefined, HighWater: undefined } } } }, + { config: { Swarm: { ConnMgr: undefined } } }, + { config: { Swarm: undefined } }, + { config: undefined } ] @@ -169,6 +176,11 @@ describe('config', () => { { config: { Bootstrap: ['/ip4/0.0.0.0/tcp/4002'] } }, { config: { Bootstrap: 138 } }, + { config: { Swarm: { ConnMgr: { LowWater: 200, HighWater: {} } } } }, + { config: { Swarm: { ConnMgr: { LowWater: {}, HighWater: 500 } } } }, + { config: { Swarm: { ConnMgr: 138 } } }, + { config: { Swarm: 138 } }, + { config: 138 } ] From 36585b5197b14e210ac47d30918936e3007864b6 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 17 Jul 2019 11:19:49 +0100 Subject: [PATCH 2/2] chore: appease linter --- test/core/config.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/config.spec.js b/test/core/config.spec.js index 81b3ebbac5..8f2e643e1c 100644 --- a/test/core/config.spec.js +++ b/test/core/config.spec.js @@ -129,7 +129,7 @@ describe('config', () => { { config: { Addresses: { Gateway: '/ip4/127.0.0.1/tcp/9090' } } }, { config: { Addresses: { Gateway: ['/ip4/127.0.0.1/tcp/9090', '/ip4/127.0.0.1/tcp/9091'] } } }, { config: { Addresses: { Gateway: undefined } } }, - + { config: { Addresses: { Delegates: ['/dns4/node0.preload.ipfs.io/tcp/443/https'] } } }, { config: { Addresses: { Delegates: [] } } }, { config: { Addresses: { Delegates: undefined } } },