Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
feat: no need anymore to append ipfs/Qmhash to webrtc-star multiaddrs
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Mar 15, 2017
1 parent cd906cd commit a77ae3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 3 additions & 8 deletions src/core/components/id.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const promisify = require('promisify-es6')
const mafmt = require('mafmt')

module.exports = function id (self) {
return promisify((opts, callback) => {
Expand All @@ -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'
}))
Expand Down
10 changes: 9 additions & 1 deletion src/core/components/pre-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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()
Expand Down

0 comments on commit a77ae3c

Please sign in to comment.