From 6943e3e90b6014d204e1172f5e43a1c9978263b9 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sun, 24 Apr 2016 18:29:29 +0200 Subject: [PATCH] fix(identify): convert all addresses to multiaddr Fixes #37 --- src/identify.js | 14 ++++++-------- test/01-transport-tcp.node.js | 18 +++++++++++++++--- test/03-transport-websockets.node.js | 12 ++++++++++-- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/identify.js b/src/identify.js index d4f758c9b7..7f6566a249 100644 --- a/src/identify.js +++ b/src/identify.js @@ -41,7 +41,7 @@ exports.exec = (rawConn, muxer, peerInfo, callback) => { pbs.on('identify', (msg) => { if (msg.observedAddr.length > 0) { - peerInfo.multiaddr.addSafe(msg.observedAddr) + peerInfo.multiaddr.addSafe(multiaddr(msg.observedAddr)) } const peerId = Id.createFromPubKey(msg.publicKey) @@ -59,7 +59,7 @@ exports.exec = (rawConn, muxer, peerInfo, callback) => { protocolVersion: 'na', agentVersion: 'na', publicKey: peerInfo.id.pubKey, - listenAddrs: peerInfo.multiaddrs.map((mh) => { return mh.buffer }), + listenAddrs: peerInfo.multiaddrs.map((mh) => mh.buffer), observedAddr: obsMultiaddr ? obsMultiaddr.buffer : new Buffer('') }) @@ -70,15 +70,15 @@ exports.exec = (rawConn, muxer, peerInfo, callback) => { } exports.handler = (peerInfo, swarm) => { - return function (conn) { + return (conn) => { // 1. receive incoming observed info about me // 2. update my own information (on peerInfo) // 3. send back what I see from the other (get from swarm.muxedConns[incPeerID].conn.getObservedAddrs() var pbs = pbStream() - pbs.on('identify', function (msg) { + pbs.on('identify', (msg) => { if (msg.observedAddr.length > 0) { - peerInfo.multiaddr.addSafe(msg.observedAddr) + peerInfo.multiaddr.addSafe(multiaddr(msg.observedAddr)) } const peerId = Id.createFromPubKey(msg.publicKey) @@ -89,9 +89,7 @@ exports.handler = (peerInfo, swarm) => { protocolVersion: 'na', agentVersion: 'na', publicKey: peerInfo.id.pubKey, - listenAddrs: peerInfo.multiaddrs.map(function (ma) { - return ma.buffer - }), + listenAddrs: peerInfo.multiaddrs.map((ma) => ma.buffer), observedAddr: obsMultiaddr ? obsMultiaddr.buffer : new Buffer('') }) pbs.finalize() diff --git a/test/01-transport-tcp.node.js b/test/01-transport-tcp.node.js index 3d020fad9d..3358210980 100644 --- a/test/01-transport-tcp.node.js +++ b/test/01-transport-tcp.node.js @@ -46,9 +46,17 @@ describe('transport - tcp', function () { function ready () { if (++count === 2) { expect(peerA.multiaddrs.length).to.equal(1) - expect(peerA.multiaddrs[0]).to.deep.equal(multiaddr('/ip4/127.0.0.1/tcp/9888')) + expect( + peerA.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9888')) + ).to.be.equal( + true + ) expect(peerB.multiaddrs.length).to.equal(1) - expect(peerB.multiaddrs[0]).to.deep.equal(multiaddr('/ip4/127.0.0.1/tcp/9999')) + expect( + peerB.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9999')) + ).to.be.equal( + true + ) done() } } @@ -124,7 +132,11 @@ describe('transport - tcp', function () { function ready () { expect(peer.multiaddrs.length).to.equal(1) - expect(peer.multiaddrs[0]).to.deep.equal(multiaddr('/ip4/0.0.0.0/tcp/9050')) + expect( + peer.multiaddrs[0].equals(multiaddr('/ip4/0.0.0.0/tcp/9050')) + ).to.be.equal( + true + ) swarm.close(done) } }) diff --git a/test/03-transport-websockets.node.js b/test/03-transport-websockets.node.js index ab4c11264b..926f4c7a3a 100644 --- a/test/03-transport-websockets.node.js +++ b/test/03-transport-websockets.node.js @@ -46,9 +46,17 @@ describe('transport - websockets', function () { function ready () { if (++count === 2) { expect(peerA.multiaddrs.length).to.equal(1) - expect(peerA.multiaddrs[0]).to.deep.equal(multiaddr('/ip4/127.0.0.1/tcp/9888/websockets')) + expect( + peerA.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9888/websockets')) + ).to.be.equal( + true + ) expect(peerB.multiaddrs.length).to.equal(1) - expect(peerB.multiaddrs[0]).to.deep.equal(multiaddr('/ip4/127.0.0.1/tcp/9999/websockets')) + expect( + peerB.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9999/websockets')) + ).to.equal( + true + ) done() } }