Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 6ac17c8

Browse files
committed
feat: emit event on peer connected
1 parent 59d1a94 commit 6ac17c8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/network.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { EventEmitter } = require('events')
34
const pull = require('pull-stream')
45
const timeout = require('async/timeout')
56
const lp = require('pull-length-prefixed')
@@ -15,13 +16,14 @@ const utils = require('./utils')
1516
/**
1617
* Handle network operations for the dht
1718
*/
18-
class Network {
19+
class Network extends EventEmitter{
1920
/**
2021
* Create a new network.
2122
*
2223
* @param {KadDHT} self
2324
*/
2425
constructor (self) {
26+
super()
2527
this.dht = self
2628
this.readMessageTimeout = c.READ_MESSAGE_TIMEOUT
2729
this._log = utils.logger(this.dht.peerInfo.id, 'net')
@@ -122,6 +124,9 @@ class Network {
122124
return this._log.error('Failed to add to the routing table', err)
123125
}
124126

127+
console.log('kad emit')
128+
this.emit('peer', peer)
129+
125130
this._log('added to the routing table: %s', peer.id.toB58String())
126131
})
127132
})

0 commit comments

Comments
 (0)