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 9106d68 commit 190df09
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
12 changes: 1 addition & 11 deletions src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,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 => {
let buffer
try {
buffer = m.decapsulate('ipfs').buffer
} catch (_) {
buffer = m.buffer
}
return 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 @@ -240,6 +240,20 @@ class DaemonLibp2p extends Libp2p {
this.peerInfo.multiaddrs.add(addr)
})
}

// 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/core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('core features', () => {

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 190df09

Please sign in to comment.