{"_id":"libp2p-connection-manager","_rev":"4647221","name":"libp2p-connection-manager","description":"JS Libp2p Connection Manager","dist-tags":{"latest":"0.1.0"},"maintainers":[{"name":"daviddias","email":"daviddias.p@gmail.com"},{"name":"pgte","email":"pedro.teixeira@gmail.com"}],"time":{"modified":"2026-04-10T20:21:36.000Z","created":"2018-04-23T08:42:00.165Z","0.1.0":"2019-04-11T09:15:38.174Z","0.0.2":"2018-04-23T08:42:00.165Z"},"users":{},"versions":{"0.1.0":{"name":"libp2p-connection-manager","version":"0.1.0","description":"JS Libp2p Connection Manager","leadMaintainer":"Vasco Santos <vasco.santos@moxy.studio>","main":"src/index.js","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","release-minor":"aegir release --type minor -t node","release-major":"aegir release --type major -t node"},"keywords":["ipfs","connection","resource"],"license":"MIT","pre-push":["lint"],"devDependencies":{"aegir":"^18.2.1","async":"^2.6.0","chai":"^4.2.0","dirty-chai":"^2.0.1","libp2p":"~0.24.4","libp2p-mplex":"~0.8.5","libp2p-secio":"~0.11.1","libp2p-tcp":"~0.13.0","lodash":"^4.17.10","peer-id":"~0.12.2","peer-info":"~0.15.1"},"dependencies":{"debug":"^4.1.1","latency-monitor":"~0.2.1"},"contributors":[{"name":"David Dias","email":"daviddias.p@gmail.com"},{"name":"Jacob Heun","email":"jacobheun@gmail.com"},{"name":"Pedro Teixeira","email":"i@pgte.me"},{"name":"Vasco Santos","email":"vasco.santos@ua.pt"}],"gitHead":"206bddb642e45e8b06011e982180706820da84fe","_id":"libp2p-connection-manager@0.1.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.1","_npmUser":{"name":"vascosantos","email":"vasco.santos@moxy.studio"},"dist":{"shasum":"1807d8dcdb27619d69899a38c43f842f66b25652","size":123731,"noattachment":false,"key":"/libp2p-connection-manager/-/libp2p-connection-manager-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/libp2p-connection-manager/download/libp2p-connection-manager-0.1.0.tgz"},"maintainers":[{"name":"daviddias","email":"daviddias.p@gmail.com"},{"name":"pgte","email":"pedro.teixeira@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/libp2p-connection-manager_0.1.0_1554974138034_0.4561392036215848"},"_hasShrinkwrap":false,"deprecated":"libp2p-connection-manager is now part of libp2p as of libp2p@0.26.1. This module should no longer be used standalone.","_cnpmcore_publish_time":"2021-12-23T09:54:55.044Z","publish_time":1554974138174,"_cnpm_publish_time":1554974138174},"0.0.2":{"name":"libp2p-connection-manager","version":"0.0.2","description":"JS Libp2p Connection Manager","main":"src/index.js","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"},"keywords":["ipfs","connection","resource"],"author":{"name":"Pedro Teixeira","email":"i@pgte.me"},"license":"MIT","pre-commit":["lint","test"],"devDependencies":{"aegir":"^13.0.7","async":"^2.6.0","chai":"^4.1.2","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","lodash.without":"^4.4.0","multihashing-async":"^0.4.8","ncp":"^2.0.0","os":"^0.1.1","peer-id":"^0.10.7","peer-info":"^0.14.1","pre-commit":"^1.2.2","rimraf":"^2.6.2","safe-buffer":"^5.1.1","uuid":"^3.2.1"},"dependencies":{"debug":"^3.1.0","latency-monitor":"^0.2.1"},"contributors":[{"name":"David Dias","email":"daviddias.p@gmail.com"},{"name":"Pedro Teixeira","email":"i@pgte.me"}],"gitHead":"6ed0a2314d021e9acc7f74bd710d1bfaace9b6d9","_id":"libp2p-connection-manager@0.0.2","_npmVersion":"5.8.0","_nodeVersion":"9.11.1","_npmUser":{"name":"daviddias","email":"daviddias.p@gmail.com"},"dist":{"shasum":"ea3db3efce8b7bb3c55af9002b8edbf65244fb1e","size":12869,"noattachment":false,"key":"/libp2p-connection-manager/-/libp2p-connection-manager-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/libp2p-connection-manager/download/libp2p-connection-manager-0.0.2.tgz"},"maintainers":[{"name":"daviddias","email":"daviddias.p@gmail.com"},{"name":"pgte","email":"pedro.teixeira@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/libp2p-connection-manager_0.0.2_1524472920114_0.3190569891354955"},"_hasShrinkwrap":false,"deprecated":"libp2p-connection-manager is now part of libp2p as of libp2p@0.26.1. This module should no longer be used standalone.","_cnpmcore_publish_time":"2021-12-23T09:54:54.943Z","publish_time":1524472920165,"_cnpm_publish_time":1524472920165}},"readme":"# libp2p-connection-manager\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)\n[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)\n[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)\n[![](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)\n[![](https://img.shields.io/travis/libp2p/js-libp2p-connection-manager.svg?style=flat-square)](https://travis-ci.com/libp2p/js-libp2p-connection-manager)\n[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-connection-manager.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-connection-manager)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n![](https://img.shields.io/badge/npm-%3E%3D6.0.0-orange.svg?style=flat-square)\n![](https://img.shields.io/badge/Node.js-%3E%3D10.0.0-orange.svg?style=flat-square)\n\n> JavaScript connection manager for libp2p\n\n## Lead Maintainer\n\n[Vasco Santos](https://github.com/vasco-santos).\n\n## Table of Contents\n\n- [Install](#install)\n  - [npm](#npm)\n  - [Use in Node.js, a browser with browserify, webpack or any other bundler](##use-in-nodejs-or-in-the-browser-with-browserify-webpack-or-any-other-bundler)\n- [Usage](#usage)\n- [API](#api)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n### npm\n\n```bash\n> npm install libp2p-connection-manager\n```\n\n### Use in Node.js or in the browser with browserify, webpack or any other bundler\n\n```js\nconst ConnManager = require('libp2p-connection-manager')\n```\n\n\n## API\n\nA connection manager manages the peers you're connected to. The application provides one or more limits that will trigger the disconnection of peers. These limits can be any of the following:\n\n* number of connected peers\n* maximum bandwidth (sent / received or both)\n* maximum event loop delay\n\nThe connection manager will disconnect peers (starting from the less important peers) until all the measures are withing the stated limits.\n\nA connection manager first disconnects the peers with the least value. By default all peers have the same importance (1), but the application can define otherwise. Once a peer disconnects the connection manager discards the peer importance. (If necessary, the application should redefine the peer state if the peer is again connected).\n\n\n### Create a ConnectionManager\n\n```js\nconst libp2p = // …\nconst options = {…}\nconst connManager = new ConnManager(libp2p, options)\n```\n\nOptions is an optional object with the following key-value pairs:\n\n* **`maxPeers`**: number identifying the maximum number of peers the current peer is willing to be connected to before is starts disconnecting. Defaults to `Infinity`\n* **`maxPeersPerProtocol`**: Object with key-value pairs, where a key is the protocol tag (case-insensitive) and the value is a number, representing the maximum number of peers allowing to connect for each protocol. Defaults to `{}`.\n* **`minPeers`**: number identifying the number of peers below which this node will not activate preemptive disconnections. Defaults to `0`.\n* **`maxData`**: sets the maximum data — in bytes per second -  (sent and received) this node is willing to endure before it starts disconnecting peers. Defaults to `Infinity`.\n* **`maxSentData`**: sets the maximum sent data — in bytes per second -  this node is willing to endure before it starts disconnecting peers. Defaults to `Infinity`.\n* **`maxReceivedData`**: sets the maximum received data — in bytes per second -  this node is willing to endure before it starts disconnecting peers. Defaults to `Infinity`.\n* **`maxEventLoopDelay`**: sets the maximum event loop delay (measured in miliseconds) this node is willing to endure before it starts disconnecting peers. Defaults to `Infinity`.\n* **`pollInterval`**: sets the poll interval (in miliseconds) for assessing the current state and determining if this peer needs to force a disconnect. Defaults to `2000` (2 seconds).\n* **`movingAverageInterval`**: the interval used to calculate moving averages (in miliseconds). Defaults to `60000` (1 minute).\n* **`defaultPeerValue`**: number between 0 and 1. Defaults to 1.\n\n\n### `connManager.start()`\n\nStarts the connection manager.\n\n### `connManager.stop()`\n\nStops the connection manager.\n\n\n### `connManager.setPeerValue(peerId, value)`\n\nSets the peer value for a given peer id. This is used to sort peers (in reverse order of value) to determine which to disconnect from first.\n\nArguments:\n\n* peerId: B58-encoded string or [`peer-id`](https://github.com/libp2p/js-peer-id) instance.\n* value: a number between 0 and 1, which represents a scale of how valuable this given peer id is to the application.\n\n### `connManager.peers()`\n\nReturns the peers this connection manager is connected to.\n\nReturns an array of [PeerInfo](https://github.com/libp2p/js-peer-info).\n\n### `connManager.emit('limit:exceeded', limitName, measured)`\n\nEmitted when a limit is exceeded. Limit names can be:\n\n* `maxPeers`\n* `minPeers`\n* `maxData`\n* `maxSentData`\n* `maxReceivedData`\n* `maxEventLoopDelay`\n* a protocol tag string (lower-cased)\n\n\n### `connManager.emit('disconnect:preemptive', peerId)`\n\nEmitted when a peer is about to be preemptively disconnected.\n\n### `connManager.emit('disconnected', peerId)`\n\nEmitted when a peer is disconnected (preemptively or note). If this peer reconnects, you will need to reset it's value, since the connection manager does not remember it.\n\n### `connManager.emit('connected', peerId: String)`\n\nEmitted when a peer connects. This is a good event to set the peer value, so you can get some control over who gets banned once a maximum number of peers is reached.\n\n\n## Contribute\n\nFeel free to join in. All welcome. Open an [issue](https://github.com/libp2p/js-libp2p-connection-manager/issues)!\n\nThis repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md)\n\n## License\n\n[MIT](LICENSE)\n","_attachments":{},"license":"MIT"}