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

Commit ea0dfc1

Browse files
committed
feat: filter IPFS addrs correctly
1 parent 3118442 commit ea0dfc1

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

src/index.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const net = require('net')
44
const toPull = require('stream-to-pull-stream')
55
const mafmt = require('mafmt')
6-
const includes = require('lodash.includes')
76
const isFunction = require('lodash.isfunction')
87
const Connection = require('interface-connection').Connection
98
const once = require('once')
@@ -68,12 +67,7 @@ class TCP {
6867
multiaddrs = [multiaddrs]
6968
}
7069
return multiaddrs.filter((ma) => {
71-
if (includes(ma.protoNames(), 'p2p-circuit')) {
72-
return false
73-
} else if (includes(ma.protoNames(), 'ipfs')) {
74-
ma = ma.decapsulate('ipfs')
75-
}
76-
return mafmt.TCP.matches(ma)
70+
return mafmt.TCP.matches(ma) || mafmt.TCP_IPFS.matches(ma)
7771
})
7872
}
7973
}

test/index.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,9 @@ 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')
276277

277-
const valid = tcp.filter([mh1, mh2, mh3, mh4])
278+
const valid = tcp.filter([mh1, mh2, mh3, mh4, mh5])
278279
expect(valid.length).to.equal(2)
279280
expect(valid[0]).to.deep.equal(mh1)
280281
expect(valid[1]).to.deep.equal(mh4)

0 commit comments

Comments
 (0)