Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit 23a7cbe

Browse files
committed
feat: skip p2p-circuit addresses
1 parent 5652591 commit 23a7cbe

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@
6262
"Richard Littauer <[email protected]>",
6363
"Stephen Whitmore <[email protected]>"
6464
]
65-
}
65+
}

src/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const net = require('net')
44
const toPull = require('stream-to-pull-stream')
55
const mafmt = require('mafmt')
6+
const includes = require('lodash.includes')
67
const isFunction = require('lodash.isfunction')
78
const Connection = require('interface-connection').Connection
89
const once = require('once')
@@ -66,7 +67,16 @@ class TCP {
6667
if (!Array.isArray(multiaddrs)) {
6768
multiaddrs = [multiaddrs]
6869
}
70+
6971
return multiaddrs.filter((ma) => {
72+
if (includes(ma.protoNames(), 'p2p-circuit')) {
73+
return false
74+
}
75+
76+
if (includes(ma.protoNames(), 'ipfs')) {
77+
ma = ma.decapsulate('ipfs')
78+
}
79+
7080
return mafmt.TCP.matches(ma)
7181
})
7282
}

test/index.spec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,10 @@ describe('filter addrs', () => {
274274
const mh3 = multiaddr('/ip4/127.0.0.1/tcp/9090/http')
275275
const mh4 = multiaddr('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
276276
const mh5 = multiaddr('/ip4/127.0.0.1/tcp/9090/http/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
277+
const mh6 = multiaddr('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw' +
278+
'/p2p-circuit/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
277279

278-
const valid = tcp.filter([mh1, mh2, mh3, mh4, mh5])
280+
const valid = tcp.filter([mh1, mh2, mh3, mh4, mh5, mh6])
279281
expect(valid.length).to.equal(2)
280282
expect(valid[0]).to.deep.equal(mh1)
281283
expect(valid[1]).to.deep.equal(mh4)
@@ -350,6 +352,7 @@ describe('valid Connection', () => {
350352
const conn = tcp.dial(ma)
351353

352354
pull(conn, pull.onEnd(endHandler))
355+
353356
function endHandler () {
354357
conn.getPeerInfo((err, peerInfo) => {
355358
expect(err).to.exist()
@@ -376,6 +379,7 @@ describe('valid Connection', () => {
376379
const conn = tcp.dial(ma)
377380

378381
pull(conn, pull.onEnd(endHandler))
382+
379383
function endHandler () {
380384
conn.setPeerInfo('arroz')
381385
conn.getPeerInfo((err, peerInfo) => {

0 commit comments

Comments
 (0)