Skip to content

Commit 9c0139e

Browse files
jacobheunvmx
authored andcommitted
feat: add p2p protocol support (#76)
1 parent 594e133 commit 9c0139e

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/protocols-table.js

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Protocols.table = [
3737
// all of the below use varint for size
3838
[302, 0, 'utp'],
3939
[421, Protocols.lengthPrefixedVarSize, 'ipfs'],
40+
// preferred name for 421 (added below ipfs, p2p takes precedence during table population)
41+
[421, Protocols.lengthPrefixedVarSize, 'p2p'],
4042
[480, 0, 'http'],
4143
[443, 0, 'https'],
4244
[460, 0, 'quic'],

test/index.spec.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,15 @@ describe('variants', () => {
211211
expect(addr.toString()).to.equal(str)
212212
})
213213

214-
it('ip4 + ipfs', () => {
215-
const str = '/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234'
214+
it('ip4 + p2p', () => {
215+
const str = '/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234'
216216
const addr = multiaddr(str)
217217
expect(addr).to.have.property('buffer')
218218
expect(addr.toString()).to.equal(str)
219219
})
220220

221-
it('ip6 + ipfs', () => {
222-
const str = '/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234'
221+
it('ip6 + p2p', () => {
222+
const str = '/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234'
223223
const addr = multiaddr(str)
224224
expect(addr).to.have.property('buffer')
225225
expect(addr.toString()).to.equal(str)
@@ -288,43 +288,43 @@ describe('variants', () => {
288288
expect(addr.toString()).to.equal(str)
289289
})
290290

291-
it('ip6 + tcp + websockets + ipfs', () => {
292-
const str = '/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/8000/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
291+
it('ip6 + tcp + websockets + p2p', () => {
292+
const str = '/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/8000/ws/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
293293
const addr = multiaddr(str)
294294
expect(addr).to.have.property('buffer')
295295
expect(addr.toString()).to.equal(str)
296296
})
297297

298-
it('ip6 + udp + quic + ipfs', () => {
299-
const str = '/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/udp/4001/quic/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
298+
it('ip6 + udp + quic + p2p', () => {
299+
const str = '/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/udp/4001/quic/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
300300
const addr = multiaddr(str)
301301
expect(addr).to.have.property('buffer')
302302
expect(addr.toString()).to.equal(str)
303303
})
304304

305-
it('ipfs', () => {
306-
const str = '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
305+
it('p2p', () => {
306+
const str = '/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
307307
const addr = multiaddr(str)
308308
expect(addr).to.have.property('buffer')
309309
expect(addr.toString()).to.equal(str)
310310
})
311311

312312
it('p2p-circuit', () => {
313-
const str = '/p2p-circuit/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
313+
const str = '/p2p-circuit/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
314314
const addr = multiaddr(str)
315315
expect(addr).to.have.property('buffer')
316316
expect(addr.toString()).to.equal(str)
317317
})
318318

319-
it('p2p-circuit ipfs', () => {
320-
const str = '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/p2p-circuit'
319+
it('p2p-circuit p2p', () => {
320+
const str = '/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/p2p-circuit'
321321
const addr = multiaddr(str)
322322
expect(addr).to.have.property('buffer')
323323
expect(addr.toString()).to.equal(str)
324324
})
325325

326326
it('p2p-webrtc-star', () => {
327-
const str = '/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
327+
const str = '/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
328328
const addr = multiaddr(str)
329329
expect(addr).to.have.property('buffer')
330330
expect(addr.toString()).to.equal(str)
@@ -381,7 +381,7 @@ describe('helpers', () => {
381381
}])
382382
})
383383

384-
it('works with ipfs', () => {
384+
it('works with ipfs/p2p', () => {
385385
expect(
386386
multiaddr('/ip4/0.0.0.0/utp/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC').protos()
387387
).to.be.eql([{
@@ -396,7 +396,7 @@ describe('helpers', () => {
396396
resolvable: false
397397
}, {
398398
code: 421,
399-
name: 'ipfs',
399+
name: 'p2p',
400400
size: -1,
401401
resolvable: false
402402
}])
@@ -588,7 +588,7 @@ describe('helpers', () => {
588588
describe('.getPeerId should parse id from multiaddr', () => {
589589
it('parses extracts the peer Id from a multiaddr', () => {
590590
expect(
591-
multiaddr('/p2p-circuit/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC').getPeerId()
591+
multiaddr('/p2p-circuit/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC').getPeerId()
592592
).to.equal('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC')
593593
})
594594
})

0 commit comments

Comments
 (0)