Skip to content

Commit

Permalink
feat: add p2p protocol support (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun authored and vmx committed Dec 17, 2018
1 parent 594e133 commit 9c0139e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/protocols-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Protocols.table = [
// all of the below use varint for size
[302, 0, 'utp'],
[421, Protocols.lengthPrefixedVarSize, 'ipfs'],
// preferred name for 421 (added below ipfs, p2p takes precedence during table population)
[421, Protocols.lengthPrefixedVarSize, 'p2p'],
[480, 0, 'http'],
[443, 0, 'https'],
[460, 0, 'quic'],
Expand Down
34 changes: 17 additions & 17 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,15 @@ describe('variants', () => {
expect(addr.toString()).to.equal(str)
})

it('ip4 + ipfs', () => {
const str = '/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234'
it('ip4 + p2p', () => {
const str = '/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234'
const addr = multiaddr(str)
expect(addr).to.have.property('buffer')
expect(addr.toString()).to.equal(str)
})

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

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

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

it('ipfs', () => {
const str = '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
it('p2p', () => {
const str = '/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
const addr = multiaddr(str)
expect(addr).to.have.property('buffer')
expect(addr.toString()).to.equal(str)
})

it('p2p-circuit', () => {
const str = '/p2p-circuit/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
const str = '/p2p-circuit/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
const addr = multiaddr(str)
expect(addr).to.have.property('buffer')
expect(addr.toString()).to.equal(str)
})

it('p2p-circuit ipfs', () => {
const str = '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/p2p-circuit'
it('p2p-circuit p2p', () => {
const str = '/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/p2p-circuit'
const addr = multiaddr(str)
expect(addr).to.have.property('buffer')
expect(addr.toString()).to.equal(str)
})

it('p2p-webrtc-star', () => {
const str = '/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
const str = '/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
const addr = multiaddr(str)
expect(addr).to.have.property('buffer')
expect(addr.toString()).to.equal(str)
Expand Down Expand Up @@ -381,7 +381,7 @@ describe('helpers', () => {
}])
})

it('works with ipfs', () => {
it('works with ipfs/p2p', () => {
expect(
multiaddr('/ip4/0.0.0.0/utp/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC').protos()
).to.be.eql([{
Expand All @@ -396,7 +396,7 @@ describe('helpers', () => {
resolvable: false
}, {
code: 421,
name: 'ipfs',
name: 'p2p',
size: -1,
resolvable: false
}])
Expand Down Expand Up @@ -588,7 +588,7 @@ describe('helpers', () => {
describe('.getPeerId should parse id from multiaddr', () => {
it('parses extracts the peer Id from a multiaddr', () => {
expect(
multiaddr('/p2p-circuit/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC').getPeerId()
multiaddr('/p2p-circuit/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC').getPeerId()
).to.equal('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC')
})
})
Expand Down

0 comments on commit 9c0139e

Please sign in to comment.