From 718394a1cd2d7553c860bc12588cc3c890de3b6b Mon Sep 17 00:00:00 2001 From: David Dias Date: Sat, 28 Jan 2017 14:36:12 +0000 Subject: [PATCH] fix: ipfs.id does not double append ipfs/ anymore (#732) --- src/core/components/id.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/core/components/id.js b/src/core/components/id.js index 8e8485eda0..9c113015b7 100644 --- a/src/core/components/id.js +++ b/src/core/components/id.js @@ -1,6 +1,7 @@ 'use strict' const promisify = require('promisify-es6') +const mafmt = require('mafmt') module.exports = function id (self) { return promisify((opts, callback) => { @@ -8,23 +9,19 @@ module.exports = function id (self) { callback = opts opts = {} } - if (!self._peerInfo) { // because of split second warmup - setTimeout(ready, 100) - } else { - ready() - } - function ready () { - callback(null, { - id: self._peerInfo.id.toB58String(), - publicKey: self._peerInfo.id.pubKey.bytes.toString('base64'), - addresses: self._peerInfo.multiaddrs.map((ma) => { - const addr = ma.toString() + '/ipfs/' + self._peerInfo.id.toB58String() - return addr - }).sort(), - agentVersion: 'js-ipfs', - protocolVersion: '9000' - }) - } + setImmediate(() => callback(null, { + id: self._peerInfo.id.toB58String(), + publicKey: self._peerInfo.id.pubKey.bytes.toString('base64'), + addresses: self._peerInfo.multiaddrs.map((ma) => { + if (mafmt.IPFS.matches(ma)) { + return ma.toString() + } else { + return ma.toString() + '/ipfs/' + self._peerInfo.id.toB58String() + } + }).sort(), + agentVersion: 'js-ipfs', + protocolVersion: '9000' + })) }) }