diff --git a/README.md b/README.md index 6b326150..93d3af71 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 7fa3da62..99026d2d 100644 --- a/package.json +++ b/package.json @@ -42,10 +42,10 @@ "debug": "^4.1.1", "err-code": "^1.1.2", "fsm-event": "^2.1.0", - "libp2p-connection-manager": "~0.0.2", + "libp2p-connection-manager": "~0.1.0", "libp2p-floodsub": "~0.15.8", "libp2p-ping": "~0.8.5", - "libp2p-switch": "~0.42.8", + "libp2p-switch": "~0.42.9", "libp2p-websockets": "~0.12.2", "mafmt": "^6.0.7", "multiaddr": "^6.0.6", diff --git a/src/index.js b/src/index.js index 73f1aec5..67fb84aa 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