mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-03 10:51:35 +00:00
swarm: Fix self.handles data structure
This commit is contained in:
@ -20,7 +20,7 @@ function Swarm () {
|
||||
|
||||
self.port = parseInt(process.env.IPFS_SWARM_PORT, 10) || 4001
|
||||
self.connections = {} // {peerIdB58: {conn: <>, socket: <>}
|
||||
self.handles = []
|
||||
self.handles = {}
|
||||
|
||||
// set the listener
|
||||
|
||||
@ -140,7 +140,7 @@ function Swarm () {
|
||||
if (self.handles[protocol]) {
|
||||
return handlerFunc(new Error('Handle for protocol already exists', protocol))
|
||||
}
|
||||
self.handles.push({ protocol: protocol, func: handlerFunc })
|
||||
self.handles[protocol] = handlerFunc
|
||||
log.info('Registered handler for protocol:', protocol)
|
||||
}
|
||||
|
||||
@ -165,8 +165,8 @@ function Swarm () {
|
||||
errorUp(self, stream)
|
||||
var msH = new Select()
|
||||
msH.handle(stream)
|
||||
self.handles.forEach(function (handle) {
|
||||
msH.addHandler(handle.protocol, handle.func)
|
||||
Object.keys(self.handles).forEach(function (protocol) {
|
||||
msH.addHandler(protocol, self.handles[protocol])
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user