Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

feat: use new connection emitters #19

Merged
merged 6 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
sudo: false
language: node_js
cache: npm
stages:
- check
- test
- cov

matrix:
include:
- node_js: 8
env: CXX=g++-4.8
node_js:
- '10'

os:
- linux
- osx
- windows

script:
- npm run test
script: npx nyc -s npm run test:node -- --bail
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov

jobs:
include:
- stage: check
script:
- npx aegir build --bundlesize
- npx aegir commitlint --travis
- npm run lint

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
notifications:
email: false
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# libp2p-connection-manager

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![](https://coveralls.io/repos/github/libp2p/js-libp2p-connection-manager/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-connection-manager?branch=master)
[![](https://travis-ci.org/libp2p/js-libp2p-connection-manager.svg?branch=master)](https://travis-ci.org/libp2p/js-libp2p-connection-manager)
[![](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
[![](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-connection-manager.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-connection-manager)
[![](https://img.shields.io/travis/libp2p/js-libp2p-connection-manager.svg?style=flat-square)](https://travis-ci.com/libp2p/js-libp2p-connection-manager)
[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-connection-manager.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-connection-manager)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
![](https://img.shields.io/badge/npm-%3E%3D6.0.0-orange.svg?style=flat-square)
![](https://img.shields.io/badge/Node.js-%3E%3D10.0.0-orange.svg?style=flat-square)

> JavaScript connection manager for libp2p

Expand Down
41 changes: 18 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
"description": "JS Libp2p Connection Manager",
"leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>",
"main": "src/index.js",
"files": [
"dist",
"src"
],
"scripts": {
"lint": "aegir lint",
"test": "aegir test -t node",
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser",
"release": "aegir release -t node -t node",
"release-minor": "aegir release --type minor -t node -t node",
"release-major": "aegir release --type major -t node -t node",
"coverage": "aegir coverage",
"coverage-publish": "aegir coverage --provider coveralls"
"release": "aegir release -t node",
"release-minor": "aegir release --type minor -t node",
"release-major": "aegir release --type major -t node"
},
"keywords": [
"ipfs",
Expand All @@ -22,31 +24,24 @@
],
"license": "MIT",
"pre-push": [
"lint",
"test"
"lint"
],
"devDependencies": {
"aegir": "^13.0.7",
"aegir": "^18.2.1",
"async": "^2.6.0",
"chai": "^4.1.2",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"ipfs-repo": "^0.19.0",
"libp2p": "^0.20.2",
"libp2p-multiplex": "^0.5.1",
"libp2p-secio": "^0.10.0",
"libp2p-tcp": "^0.12.0",
"libp2p": "~0.24.4",
"libp2p-mplex": "~0.8.5",
"libp2p-secio": "~0.11.1",
"libp2p-tcp": "~0.13.0",
"lodash": "^4.17.10",
"multihashing-async": "^0.4.8",
"ncp": "^2.0.0",
"os": "^0.1.1",
"peer-id": "^0.10.7",
"peer-info": "^0.14.1",
"rimraf": "^2.6.2",
"uuid": "^3.2.1"
"peer-id": "~0.12.2",
"peer-info": "~0.15.1"
},
"dependencies": {
"debug": "^3.1.0",
"latency-monitor": "^0.2.1"
"debug": "^4.1.1",
"latency-monitor": "~0.2.1"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class ConnectionManager extends EventEmitter {

start () {
this._stats.on('update', this._onStatsUpdate)
this._libp2p.on('peer:connect', this._onPeerConnect)
this._libp2p.on('peer:disconnect', this._onPeerDisconnect)
this._libp2p.on('connection:start', this._onPeerConnect)
this._libp2p.on('connection:end', this._onPeerDisconnect)
// latency monitor
this._latencyMonitor = new LatencyMonitor({
dataEmitIntervalMs: this._options.pollInterval
Expand All @@ -59,8 +59,8 @@ class ConnectionManager extends EventEmitter {

stop () {
this._stats.removeListener('update', this._onStatsUpdate)
this._libp2p.removeListener('peer:connect', this._onPeerConnect)
this._libp2p.removeListener('peer:disconnect', this._onPeerDisconnect)
this._libp2p.removeListener('connection:start', this._onPeerConnect)
this._libp2p.removeListener('connection:end', this._onPeerDisconnect)
this._latencyMonitor.removeListener('data', this._onLatencyMeasure)
}

Expand Down Expand Up @@ -137,8 +137,8 @@ class ConnectionManager extends EventEmitter {
}

_checkLimit (name, value) {
debug('checking limit. current value of %s is %d', name, value)
const limit = this._options[name]
debug('checking limit of %s. current value: %d of %d', name, value, limit)
if (value > limit) {
debug('%s: limit exceeded: %s, %d', this._peerId, name, value)
this.emit('limit:exceeded', name, value)
Expand Down
88 changes: 0 additions & 88 deletions test/fixtures/repo/config

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/repo/version

This file was deleted.

Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions test/max-data.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('maxData', function () {
manager.on('disconnected', () => {
disconnects++
expect(disconnects).to.be.most(PEER_COUNT - 2)
manager.removeAllListeners('disconnected')
done()
})

Expand Down
1 change: 1 addition & 0 deletions test/max-event-loop-delay.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('maxEventLoopDelay', function () {
manager.on('disconnected', () => {
disconnects++
expect(disconnects).to.be.most(PEER_COUNT - 2)
manager.removeAllListeners('disconnected')
stopped = true
done()
})
Expand Down
1 change: 1 addition & 0 deletions test/max-peer-per-protocol.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('maxPeers', function () {
manager.on('disconnected', () => {
disconnects++
expect(disconnects).to.be.most(PEER_COUNT - 2)
manager.removeAllListeners('disconnected')
done()
})

Expand Down
1 change: 1 addition & 0 deletions test/max-peers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('maxPeers', function () {
manager.on('disconnected', () => {
disconnects++
expect(disconnects).to.be.most(PEER_COUNT - 2)
manager.removeAllListeners('disconnected')
done()
})

Expand Down
1 change: 1 addition & 0 deletions test/max-received-data.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('maxReceivedData', function () {
manager.on('disconnected', () => {
disconnects++
expect(disconnects).to.be.most(PEER_COUNT - 2)
manager.removeAllListeners('disconnected')
done()
})

Expand Down
1 change: 1 addition & 0 deletions test/max-sent-data.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('maxSentData', function () {
manager.on('disconnected', () => {
disconnects++
expect(disconnects).to.be.most(PEER_COUNT - 2)
manager.removeAllListeners('disconnected')
done()
})

Expand Down
3 changes: 1 addition & 2 deletions test/set-peer-value.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ describe('setPeerValue', function () {
after(prepare.after)

it('kicks out lower valued peer first', function (done) {
this.timeout(10000)

let disconnects = 0
let firstConnectedPeer
const manager = prepare.connManagers()[0]
Expand All @@ -35,6 +33,7 @@ describe('setPeerValue', function () {
disconnects++
expect(disconnects).to.be.most(PEER_COUNT - 2)
expect(peerId).to.not.be.equal(firstConnectedPeer)
manager.removeAllListeners('disconnected')
done()
})

Expand Down
2 changes: 1 addition & 1 deletion test/utils/connect-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = (nodes, callback) => {
(node, cb) => {
eachSeries(
without(nodes, node),
(otherNode, cb) => node.libp2pNode.dial(otherNode.libp2pNode.peerInfo, cb),
(otherNode, cb) => node.dial(otherNode.peerInfo, cb),
cb
)
},
Expand Down
26 changes: 0 additions & 26 deletions test/utils/create-bitswap.js

This file was deleted.

Loading