From 11c4f451f43b5c36b930d111a42aab133238a51a Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 13 Oct 2017 08:13:28 -0700 Subject: [PATCH] feat: relay filtering * feat: filter IPFS addrs correctly * feat: mafmt addrs now support /ipfs no need for ad-hoc filtering * feat: skip p2p-circuit addresses --- package.json | 2 +- src/index.js | 6 ++++++ test/index.spec.js | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d8432e6..1925486 100644 --- a/package.json +++ b/package.json @@ -62,4 +62,4 @@ "Richard Littauer ", "Stephen Whitmore " ] -} \ No newline at end of file +} diff --git a/src/index.js b/src/index.js index 3e8e91d..91f3c27 100644 --- a/src/index.js +++ b/src/index.js @@ -67,10 +67,16 @@ class TCP { if (!Array.isArray(multiaddrs)) { multiaddrs = [multiaddrs] } + return multiaddrs.filter((ma) => { + if (includes(ma.protoNames(), 'p2p-circuit')) { + return false + } + if (includes(ma.protoNames(), 'ipfs')) { ma = ma.decapsulate('ipfs') } + return mafmt.TCP.matches(ma) }) } diff --git a/test/index.spec.js b/test/index.spec.js index bbff5cc..732d89c 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -273,8 +273,11 @@ describe('filter addrs', () => { const mh2 = multiaddr('/ip4/127.0.0.1/udp/9090') const mh3 = multiaddr('/ip4/127.0.0.1/tcp/9090/http') const mh4 = multiaddr('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') + const mh5 = multiaddr('/ip4/127.0.0.1/tcp/9090/http/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') + const mh6 = multiaddr('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw' + + '/p2p-circuit/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw') - const valid = tcp.filter([mh1, mh2, mh3, mh4]) + const valid = tcp.filter([mh1, mh2, mh3, mh4, mh5, mh6]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(mh1) expect(valid[1]).to.deep.equal(mh4) @@ -349,6 +352,7 @@ describe('valid Connection', () => { const conn = tcp.dial(ma) pull(conn, pull.onEnd(endHandler)) + function endHandler () { conn.getPeerInfo((err, peerInfo) => { expect(err).to.exist() @@ -375,6 +379,7 @@ describe('valid Connection', () => { const conn = tcp.dial(ma) pull(conn, pull.onEnd(endHandler)) + function endHandler () { conn.setPeerInfo('arroz') conn.getPeerInfo((err, peerInfo) => {