fix: connection emits (#352)

* fix: add connection tracking events

* chore: update dependencies
This commit is contained in:
Jacob Heun
2019-04-11 13:49:31 +02:00
committed by GitHub
parent 01aa44724e
commit 313b1eae20
3 changed files with 24 additions and 4 deletions

View File

@ -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][]

View File

@ -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",

View File

@ -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