Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
fix: creating a proper peerId instead of using a simple buffer or string
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte authored and daviddias committed Mar 14, 2018
1 parent 364e155 commit d061cda
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/circuit/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const EE = require('events').EventEmitter
const Connection = require('interface-connection').Connection
const utilsFactory = require('./utils')
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const proto = require('../protocol')
const series = require('async/series')

Expand Down Expand Up @@ -33,7 +34,7 @@ class Stop extends EE {
return log(err)
}

const peerInfo = new PeerInfo(message.srcPeer.id)
const peerInfo = new PeerInfo(peerIdFromId(message.srcPeer.id))
message.srcPeer.addrs.forEach((addr) => peerInfo.multiaddrs.add(addr))
const newConn = new Connection(streamHandler.rest())
newConn.setPeerInfo(peerInfo)
Expand All @@ -44,3 +45,11 @@ class Stop extends EE {
}

module.exports = Stop

function peerIdFromId (id) {
if (typeof id === 'string') {
return PeerId.createFromB58String(id)
}

return PeerId.createFromBytes(id)
}

0 comments on commit d061cda

Please sign in to comment.