diff --git a/src/dialer.js b/src/dialer.js index 34bc936..b3893f3 100644 --- a/src/dialer.js +++ b/src/dialer.js @@ -58,6 +58,9 @@ module.exports = (conn, expectedPeerInfo, callback) => { return callback(err) } + // Copy the protocols + peerInfo.protocols = new Set(input.protocols) + callback(null, peerInfo, observedAddr) }) }) diff --git a/src/listener.js b/src/listener.js index b578d05..8f1d47b 100644 --- a/src/listener.js +++ b/src/listener.js @@ -22,7 +22,8 @@ module.exports = (conn, pInfoSelf) => { agentVersion: 'na', publicKey: publicKey, listenAddrs: pInfoSelf.multiaddrs.toArray().map((ma) => ma.buffer), - observedAddr: observedAddrs ? observedAddrs.buffer : Buffer.from('') + observedAddr: observedAddrs ? observedAddrs.buffer : Buffer.from(''), + protocols: Array.from(pInfoSelf.protocols) }) pull( diff --git a/test/dialer.spec.js b/test/dialer.spec.js index c584543..921aad0 100644 --- a/test/dialer.spec.js +++ b/test/dialer.spec.js @@ -33,12 +33,16 @@ describe('identify.dialer', () => { it('works', (done) => { const p = pair() original.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/5002')) + original.protocols.add('/echo/1.0.0') + original.protocols.add('/ping/1.0.0') + const input = msg.encode({ protocolVersion: 'ipfs/0.1.0', agentVersion: 'na', publicKey: original.id.pubKey.bytes, listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/5002').buffer], - observedAddr: multiaddr('/ip4/127.0.0.1/tcp/5001').buffer + observedAddr: multiaddr('/ip4/127.0.0.1/tcp/5001').buffer, + protocols: Array.from(original.protocols) }) pull( @@ -58,6 +62,44 @@ describe('identify.dialer', () => { expect(observedAddrs) .to.eql([multiaddr('/ip4/127.0.0.1/tcp/5001')]) + expect(info.protocols).to.eql(original.protocols) + + done() + }) + }) + + it('should handle missing protocols', (done) => { + const p = pair() + original.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/5002')) + + const input = msg.encode({ + protocolVersion: 'ipfs/0.1.0', + agentVersion: 'na', + publicKey: original.id.pubKey.bytes, + listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/5002').buffer], + observedAddr: multiaddr('/ip4/127.0.0.1/tcp/5001').buffer, + protocols: Array.from(original.protocols) + }) + + pull( + values([input]), + lp.encode(), + p[0] + ) + + identify.dialer(p[1], (err, info, observedAddrs) => { + expect(err).to.not.exist() + expect(info.id.pubKey.bytes) + .to.eql(original.id.pubKey.bytes) + + expect(info.multiaddrs.toArray()) + .to.eql(original.multiaddrs.toArray()) + + expect(observedAddrs) + .to.eql([multiaddr('/ip4/127.0.0.1/tcp/5001')]) + + expect(Array.from(info.protocols)).to.eql([]) + done() }) }) diff --git a/test/listener.spec.js b/test/listener.spec.js index 33619f5..62de9cf 100644 --- a/test/listener.spec.js +++ b/test/listener.spec.js @@ -26,6 +26,9 @@ describe('identify.listener', () => { return done(err) } + _info.protocols.add('/echo/1.0.0') + _info.protocols.add('/chat/1.0.0') + info = _info done() }) @@ -51,7 +54,7 @@ describe('identify.listener', () => { publicKey: info.id.pubKey.bytes, listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/5002').buffer], observedAddr: multiaddr('/ip4/127.0.0.1/tcp/5001').buffer, - protocols: [] + protocols: ['/echo/1.0.0', '/chat/1.0.0'] }) done() })