From c1fdaa3d99b0b99e3b875380824d9fc900fe785c Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sun, 2 Apr 2017 15:54:08 -0700 Subject: [PATCH 1/3] feat: filter IPFS addrs correctly --- src/index.js | 6 +----- test/index.spec.js | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index 3e8e91d..e131280 100644 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,6 @@ const net = require('net') const toPull = require('stream-to-pull-stream') const mafmt = require('mafmt') -const includes = require('lodash.includes') const isFunction = require('lodash.isfunction') const Connection = require('interface-connection').Connection const once = require('once') @@ -68,10 +67,7 @@ class TCP { multiaddrs = [multiaddrs] } return multiaddrs.filter((ma) => { - if (includes(ma.protoNames(), 'ipfs')) { - ma = ma.decapsulate('ipfs') - } - return mafmt.TCP.matches(ma) + return mafmt.TCP.matches(ma) || mafmt.TCP_IPFS.matches(ma) }) } } diff --git a/test/index.spec.js b/test/index.spec.js index bbff5cc..36d43fe 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -273,8 +273,9 @@ 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 valid = tcp.filter([mh1, mh2, mh3, mh4]) + const valid = tcp.filter([mh1, mh2, mh3, mh4, mh5]) expect(valid.length).to.equal(2) expect(valid[0]).to.deep.equal(mh1) expect(valid[1]).to.deep.equal(mh4) From 56525912f649477e73cf87af9fa196ec17fdc007 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 29 Aug 2017 16:51:33 -0600 Subject: [PATCH 2/3] feat: mafmt addrs now support /ipfs no need for ad-hoc filtering --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index e131280..d80128c 100644 --- a/src/index.js +++ b/src/index.js @@ -67,7 +67,7 @@ class TCP { multiaddrs = [multiaddrs] } return multiaddrs.filter((ma) => { - return mafmt.TCP.matches(ma) || mafmt.TCP_IPFS.matches(ma) + return mafmt.TCP.matches(ma) }) } } From 23a7cbe723f5adc7e8ef40e66c6c7482f98d91ba Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Thu, 14 Sep 2017 12:30:44 -0600 Subject: [PATCH 3/3] feat: skip p2p-circuit addresses --- package.json | 2 +- src/index.js | 10 ++++++++++ test/index.spec.js | 6 +++++- 3 files changed, 16 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 d80128c..91f3c27 100644 --- a/src/index.js +++ b/src/index.js @@ -3,6 +3,7 @@ const net = require('net') const toPull = require('stream-to-pull-stream') const mafmt = require('mafmt') +const includes = require('lodash.includes') const isFunction = require('lodash.isfunction') const Connection = require('interface-connection').Connection const once = require('once') @@ -66,7 +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 36d43fe..732d89c 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -274,8 +274,10 @@ describe('filter addrs', () => { 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, mh5]) + 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) @@ -350,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() @@ -376,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) => {