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

Commit 5429c40

Browse files
committed
fix: support multiaddr7 addr filtering
License: MIT Signed-off-by: Jacob Heun <[email protected]>
1 parent 49c7f33 commit 5429c40

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"chai": "^4.2.0",
4040
"dirty-chai": "^2.0.1",
4141
"interface-transport": "~0.3.6",
42-
"pull-stream": "^3.6.14"
42+
"pull-stream": "^3.6.14",
43+
"multiaddr7": "npm:multiaddr@^7.0.0"
4344
},
4445
"dependencies": {
4546
"class-is": "^1.1.0",

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ class TCP {
7373
return false
7474
}
7575

76-
if (includes(ma.protoNames(), 'ipfs')) {
76+
if (typeof ma.decapsulateCode === 'function') {
77+
ma = ma.decapsulateCode(421) // multiaddr 7
78+
} else if (includes(ma.protoNames(), 'ipfs')) {
7779
ma = ma.decapsulate('ipfs')
7880
}
7981

test/filter.spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const expect = chai.expect
77
chai.use(dirtyChai)
88
const TCP = require('../src')
99
const multiaddr = require('multiaddr')
10+
const multiaddr7 = require('multiaddr7')
1011

1112
describe('filter addrs', () => {
1213
const base = '/ip4/127.0.0.1'
@@ -27,11 +28,13 @@ describe('filter addrs', () => {
2728
const ma6 = multiaddr('/ip4/127.0.0.1/tcp/9090/p2p-circuit' + ipfs)
2829
const ma7 = multiaddr('/dns4/libp2p.io/tcp/9090')
2930
const ma8 = multiaddr('/dnsaddr/libp2p.io/tcp/9090')
31+
const ma9 = multiaddr7(base + '/tcp/9090/p2p/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
3032

31-
const valid = tcp.filter([ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8])
32-
expect(valid.length).to.equal(4)
33+
const valid = tcp.filter([ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8, ma9])
34+
expect(valid.length).to.equal(5)
3335
expect(valid[0]).to.deep.equal(ma1)
3436
expect(valid[1]).to.deep.equal(ma4)
37+
expect(valid[4]).to.deep.equal(ma9)
3538
})
3639

3740
it('filter a single addr for this transport', () => {

0 commit comments

Comments
 (0)