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

feat: filter IPFS addrs correctly #62

Merged
merged 18 commits into from
Oct 20, 2017
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ class WebSockets {
}

return multiaddrs.filter((ma) => {
if (includes(ma.protoNames(), 'p2p-circuit')) {
return false
}

if (includes(ma.protoNames(), 'ipfs')) {
ma = ma.decapsulate('ipfs')
}
return mafmt.WebSockets.matches(ma) || mafmt.WebSocketsSecure.matches(ma)

return mafmt.WebSockets.matches(ma) ||
mafmt.WebSocketsSecure.matches(ma)
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,10 @@ describe('filter addrs', () => {
const ma2 = multiaddr('/ip4/127.0.0.1/tcp/9090')
const ma3 = multiaddr('/ip4/127.0.0.1/udp/9090')
const ma4 = multiaddr('/dns6/ipfs.io/ws')
const mh5 = multiaddr('/ip4/127.0.0.1/tcp/9090/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw' +
'/p2p-circuit/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')

const valid = ws.filter([ma1, ma2, ma3, ma4])
const valid = ws.filter([ma1, ma2, ma3, ma4, mh5])
expect(valid.length).to.equal(2)
expect(valid[0]).to.deep.equal(ma1)
expect(valid[1]).to.deep.equal(ma4)
Expand Down