diff --git a/src/core/components/id.js b/src/core/components/id.js index 9c113015b7..cf30c619ea 100644 --- a/src/core/components/id.js +++ b/src/core/components/id.js @@ -1,7 +1,6 @@ 'use strict' const promisify = require('promisify-es6') -const mafmt = require('mafmt') module.exports = function id (self) { return promisify((opts, callback) => { @@ -13,13 +12,9 @@ module.exports = function id (self) { 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(), + addresses: self._peerInfo.multiaddrs + .map((ma) => ma.toString()) + .sort(), agentVersion: 'js-ipfs', protocolVersion: '9000' })) diff --git a/src/core/components/pre-start.js b/src/core/components/pre-start.js index f16ffeff0b..2c4dc90ea0 100644 --- a/src/core/components/pre-start.js +++ b/src/core/components/pre-start.js @@ -4,6 +4,7 @@ const peerId = require('peer-id') const PeerInfo = require('peer-info') const multiaddr = require('multiaddr') const waterfall = require('async/waterfall') +const mafmt = require('mafmt') const utils = require('../utils') @@ -26,7 +27,14 @@ module.exports = function preStart (self) { self._peerInfo = new PeerInfo(id) config.Addresses.Swarm.forEach((addr) => { - self._peerInfo.multiaddr.add(multiaddr(addr)) + let ma = multiaddr(addr) + + if (!mafmt.IPFS.matches(ma)) { + ma = ma.encapsulate('/ipfs/' + + self._peerInfo.id.toB58String()) + } + + self._peerInfo.multiaddr.add(ma) }) cb()