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

Commit b9bdb79

Browse files
committed
feat: filter IPFS addrs correctly
1 parent ef45cc9 commit b9bdb79

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/index.js

+1-5
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,10 +67,7 @@ class TCP {
6867
multiaddrs = [multiaddrs]
6968
}
7069
return multiaddrs.filter((ma) => {
71-
if (includes(ma.protoNames(), 'ipfs')) {
72-
ma = ma.decapsulate('ipfs')
73-
}
74-
return mafmt.TCP.matches(ma)
70+
return mafmt.TCP.matches(ma) || mafmt.TCP_IPFS.matches(ma)
7571
})
7672
}
7773
}

test/index.spec.js

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