From d061cdac5a9993e0d8f1def06bef248ec11b44fa Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Mon, 12 Mar 2018 16:51:58 +0000 Subject: [PATCH] fix: creating a proper peerId instead of using a simple buffer or string --- src/circuit/stop.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/circuit/stop.js b/src/circuit/stop.js index 8906e5c..0b00902 100644 --- a/src/circuit/stop.js +++ b/src/circuit/stop.js @@ -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') @@ -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) @@ -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) +}