Skip to content

Commit

Permalink
fix: connection emits (#352)
Browse files Browse the repository at this point in the history
* fix: add connection tracking events

* chore: update dependencies
  • Loading branch information
jacobheun authored Apr 11, 2019
1 parent 01aa447 commit 313b1ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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][]

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 313b1ea

Please sign in to comment.