refactor: connection manager (#511)

* refactor: initial refactor of the connection manager

* fix: start/stop issues

* fix: add tests and resolve pruning issues

* chore: fix lint

* test: move conn manager tests to node only for now

* chore: apply suggestions from code review

Co-Authored-By: Vasco Santos <vasco.santos@moxy.studio>

* fix: assert min max connection options

* test: fix assertion check for browser

* docs: add api and config docs for conn manager
This commit is contained in:
Jacob Heun
2019-12-12 10:19:57 +01:00
parent af96dcc499
commit 45f47023d2
9 changed files with 370 additions and 252 deletions

View File

@ -33,9 +33,16 @@ describe('libp2p.metrics', () => {
})
it('should start/stop metrics on startup/shutdown when enabled', async () => {
const config = { ...baseOptions }
config.metrics = {
enabled: true
const config = {
...baseOptions,
connectionManager: {
movingAverageIntervals: [10]
},
metrics: {
enabled: true,
computeThrottleMaxQueueSize: 1, // compute after every message
movingAverageIntervals: [10]
}
}
;[libp2p] = await createPeer({ started: false, config })
@ -51,11 +58,16 @@ describe('libp2p.metrics', () => {
})
it('should record metrics on connections and streams when enabled', async () => {
const config = { ...baseOptions }
config.metrics = {
enabled: true,
computeThrottleMaxQueueSize: 1, // compute after every message
movingAverageIntervals: [10]
const config = {
...baseOptions,
connectionManager: {
movingAverageIntervals: [10]
},
metrics: {
enabled: true,
computeThrottleMaxQueueSize: 1, // compute after every message
movingAverageIntervals: [10]
}
}
let remoteLibp2p
;[libp2p, remoteLibp2p] = await createPeer({ number: 2, config })
@ -88,11 +100,16 @@ describe('libp2p.metrics', () => {
})
it('should move disconnected peers to the old peers list', async () => {
const config = { ...baseOptions }
config.metrics = {
enabled: true,
computeThrottleMaxQueueSize: 1, // compute after every message
movingAverageIntervals: [10]
const config = {
...baseOptions,
connectionManager: {
movingAverageIntervals: [10]
},
metrics: {
enabled: true,
computeThrottleMaxQueueSize: 1, // compute after every message
movingAverageIntervals: [10]
}
}
let remoteLibp2p
;[libp2p, remoteLibp2p] = await createPeer({ number: 2, config })