Skip to content

Commit

Permalink
fix: decapsulate ipfs protocol on daemon startup (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored and jacobheun committed Mar 12, 2019
1 parent c131161 commit bb9713e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,7 @@ class Daemon {
enc.write(OkResponse({
identify: {
id: this.libp2p.peerInfo.id.toBytes(),
// temporary removal of "/ipfs/..." from multiaddrs
// this will be solved in: https://github.com/libp2p/js-libp2p/issues/323
addrs: this.libp2p.peerInfo.multiaddrs.toArray().map(m => m.decapsulate('ipfs').buffer)
addrs: this.libp2p.peerInfo.multiaddrs.toArray().map(m => m.buffer)
}
}))
break
Expand Down
14 changes: 14 additions & 0 deletions src/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,20 @@ class DaemonLibp2p extends Libp2p {
return new Promise((resolve, reject) => {
super.start((err) => {
if (err) return reject(err)

// temporary removal of "/ipfs/..." from multiaddrs
// this will be solved in: https://github.com/libp2p/js-libp2p/issues/323
this.peerInfo.multiaddrs.toArray().forEach(m => {
let ma
try {
ma = m.decapsulate('ipfs')
} catch (_) {
ma = m
}

this.peerInfo.multiaddrs.replace(m, ma)
})

resolve()
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/daemon.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('daemon', () => {

expect(response.identify).to.eql({
id: daemon.libp2p.peerInfo.id.toBytes(),
addrs: daemon.libp2p.peerInfo.multiaddrs.toArray().map(m => m.decapsulate('ipfs').buffer)
addrs: daemon.libp2p.peerInfo.multiaddrs.toArray().map(m => m.buffer)
})
stream.end()
})
Expand Down

0 comments on commit bb9713e

Please sign in to comment.