From bd95e8607d46fdd121b7b74403fd7753accad399 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Wed, 10 Apr 2019 13:02:26 +0200 Subject: [PATCH] fix: add connection tracking events --- README.md | 16 ++++++++++++++-- package.json | 2 +- src/index.js | 8 ++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6b32615005..93d3af71e2 100644 --- a/README.md +++ b/README.md @@ -313,13 +313,25 @@ unless they are performing a specific action. See [peer discovery and auto dial] ##### `libp2p.on('peer:connect', (peer) => {})` -> We connected to a new peer +> We have a new muxed connection to a peer - `peer`: instance of [PeerInfo][] ##### `libp2p.on('peer:disconnect', (peer) => {})` -> We disconnected from Peer +> We have closed a connection to a peer + +- `peer`: instance of [PeerInfo][] + +##### `libp2p.on('connection:start', (peer) => {})` + +> We created a new connection to a peer + +- `peer`: instance of [PeerInfo][] + +##### `libp2p.on('connection:end', (peer) => {})` + +> We closed a connection to a peer - `peer`: instance of [PeerInfo][] diff --git a/package.json b/package.json index 7fa3da6268..2dff87cea1 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "debug": "^4.1.1", "err-code": "^1.1.2", "fsm-event": "^2.1.0", - "libp2p-connection-manager": "~0.0.2", + "libp2p-connection-manager": "github:libp2p/js-libp2p-connection-manager#fix/connection-events", "libp2p-floodsub": "~0.15.8", "libp2p-ping": "~0.8.5", "libp2p-switch": "~0.42.8", diff --git a/src/index.js b/src/index.js index 73f1aec5cd..67fb84aa33 100644 --- a/src/index.js +++ b/src/index.js @@ -85,6 +85,14 @@ class Node extends EventEmitter { }) } + // Events for anytime connections are created/removed + this._switch.on('connection:start', (peerInfo) => { + this.emit('connection:start', peerInfo) + }) + this._switch.on('connection:end', (peerInfo) => { + this.emit('connection:end', peerInfo) + }) + // Attach crypto channels if (this._modules.connEncryption) { let cryptos = this._modules.connEncryption