fix: remove use of assert module (#561)

* fix: remove use of assert module

The polyfill is big, we can simulate it by throwing an Error and it doesn't work under React Native.

* chore: fix linting

* chore: export invalid param code

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
This commit is contained in:
Alex Potsides
2020-02-14 13:42:23 +00:00
committed by GitHub
parent 0882dcea3b
commit a8984c6cd3
5 changed files with 53 additions and 20 deletions

View File

@ -1,11 +1,15 @@
'use strict'
const assert = require('assert')
const errcode = require('err-code')
const mergeOptions = require('merge-options')
const LatencyMonitor = require('latency-monitor').default
const debug = require('debug')('libp2p:connection-manager')
const retimer = require('retimer')
const {
ERR_INVALID_PARAMETERS
} = require('../errors')
const defaultOptions = {
maxConnections: Infinity,
minConnections: 0,
@ -38,10 +42,9 @@ class ConnectionManager {
this._registrar = libp2p.registrar
this._peerId = libp2p.peerInfo.id.toB58String()
this._options = mergeOptions.call({ ignoreUndefined: true }, defaultOptions, options)
assert(
this._options.maxConnections > this._options.minConnections,
'Connection Manager maxConnections must be greater than minConnections'
)
if (this._options.maxConnections < this._options.minConnections) {
throw errcode(new Error('Connection Manager maxConnections must be greater than minConnections'), ERR_INVALID_PARAMETERS)
}
debug('options: %j', this._options)