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

Commit 11c4f45

Browse files
dryajovdaviddias
authored andcommitted
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
1 parent 7572279 commit 11c4f45

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

package.json

+1-1
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

+6
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,16 @@ class TCP {
6767
if (!Array.isArray(multiaddrs)) {
6868
multiaddrs = [multiaddrs]
6969
}
70+
7071
return multiaddrs.filter((ma) => {
72+
if (includes(ma.protoNames(), 'p2p-circuit')) {
73+
return false
74+
}
75+
7176
if (includes(ma.protoNames(), 'ipfs')) {
7277
ma = ma.decapsulate('ipfs')
7378
}
79+
7480
return mafmt.TCP.matches(ma)
7581
})
7682
}

test/index.spec.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,11 @@ describe('filter addrs', () => {
273273
const mh2 = multiaddr('/ip4/127.0.0.1/udp/9090')
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')
276+
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')
276279

277-
const valid = tcp.filter([mh1, mh2, mh3, mh4])
280+
const valid = tcp.filter([mh1, mh2, mh3, mh4, mh5, mh6])
278281
expect(valid.length).to.equal(2)
279282
expect(valid[0]).to.deep.equal(mh1)
280283
expect(valid[1]).to.deep.equal(mh4)
@@ -349,6 +352,7 @@ describe('valid Connection', () => {
349352
const conn = tcp.dial(ma)
350353

351354
pull(conn, pull.onEnd(endHandler))
355+
352356
function endHandler () {
353357
conn.getPeerInfo((err, peerInfo) => {
354358
expect(err).to.exist()
@@ -375,6 +379,7 @@ describe('valid Connection', () => {
375379
const conn = tcp.dial(ma)
376380

377381
pull(conn, pull.onEnd(endHandler))
382+
378383
function endHandler () {
379384
conn.setPeerInfo('arroz')
380385
conn.getPeerInfo((err, peerInfo) => {

0 commit comments

Comments
 (0)