fix: listen with multiaddr7

License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
This commit is contained in:
Jacob Heun 2019-09-24 14:36:48 +02:00
parent bf532d181a
commit ba0346cbb6
No known key found for this signature in database
GPG Key ID: CA5A94C15809879F
2 changed files with 17 additions and 1 deletions

View File

@ -84,7 +84,10 @@ module.exports = (handler) => {
listener.listen = (ma, callback) => {
listeningAddr = ma
if (includes(ma.protoNames(), 'ipfs')) {
if (typeof ma.decapsulateCode === 'function') {
ipfsId = getIpfsId(ma)
listeningAddr = ma.decapsulateCode(IPFS_CODE)
} else if (includes(ma.protoNames(), 'ipfs')) {
ipfsId = getIpfsId(ma)
listeningAddr = ma.decapsulate('ipfs')
}

View File

@ -127,6 +127,19 @@ describe('listen', () => {
})
})
})
it('getAddrs preserves IPFS Id (multiaddr 7)', (done) => {
const mh = multiaddr7('/ip4/127.0.0.1/tcp/9090/p2p/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
const listener = tcp.createListener((conn) => {})
listener.listen(mh, () => {
listener.getAddrs((err, multiaddrs) => {
expect(err).to.not.exist()
expect(multiaddrs.length).to.equal(1)
expect(multiaddrs[0]).to.deep.equal(mh)
listener.close(done)
})
})
})
})
describe('dial', () => {