Skip to content

Commit 313b1ea

Browse files
authored
fix: connection emits (#352)
* fix: add connection tracking events * chore: update dependencies
1 parent 01aa447 commit 313b1ea

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

README.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,25 @@ unless they are performing a specific action. See [peer discovery and auto dial]
313313

314314
##### `libp2p.on('peer:connect', (peer) => {})`
315315

316-
> We connected to a new peer
316+
> We have a new muxed connection to a peer
317317
318318
- `peer`: instance of [PeerInfo][]
319319

320320
##### `libp2p.on('peer:disconnect', (peer) => {})`
321321

322-
> We disconnected from Peer
322+
> We have closed a connection to a peer
323+
324+
- `peer`: instance of [PeerInfo][]
325+
326+
##### `libp2p.on('connection:start', (peer) => {})`
327+
328+
> We created a new connection to a peer
329+
330+
- `peer`: instance of [PeerInfo][]
331+
332+
##### `libp2p.on('connection:end', (peer) => {})`
333+
334+
> We closed a connection to a peer
323335
324336
- `peer`: instance of [PeerInfo][]
325337

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
"debug": "^4.1.1",
4343
"err-code": "^1.1.2",
4444
"fsm-event": "^2.1.0",
45-
"libp2p-connection-manager": "~0.0.2",
45+
"libp2p-connection-manager": "~0.1.0",
4646
"libp2p-floodsub": "~0.15.8",
4747
"libp2p-ping": "~0.8.5",
48-
"libp2p-switch": "~0.42.8",
48+
"libp2p-switch": "~0.42.9",
4949
"libp2p-websockets": "~0.12.2",
5050
"mafmt": "^6.0.7",
5151
"multiaddr": "^6.0.6",

src/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ class Node extends EventEmitter {
8585
})
8686
}
8787

88+
// Events for anytime connections are created/removed
89+
this._switch.on('connection:start', (peerInfo) => {
90+
this.emit('connection:start', peerInfo)
91+
})
92+
this._switch.on('connection:end', (peerInfo) => {
93+
this.emit('connection:end', peerInfo)
94+
})
95+
8896
// Attach crypto channels
8997
if (this._modules.connEncryption) {
9098
let cryptos = this._modules.connEncryption

0 commit comments

Comments
 (0)