Skip to content

Commit

Permalink
Changed websocket [secure] to endpoint selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorropo committed Jul 10, 2019
1 parent 811b343 commit 5fcdfad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Convert.toString = function convertToString (proto, buf) {
case 55: // dns6
case 56: // dnsaddr
case 400: // unix
case 477: // websocket
case 478: // websocket secure
return buf2str(buf)

case 421: // ipfs
Expand Down Expand Up @@ -68,6 +70,8 @@ Convert.toBuffer = function convertToBuffer (proto, str) {
case 55: // dns6
case 56: // dnsaddr
case 400: // unix
case 477: // websocket
case 478: // websocket secure
return str2buf(str)

case 421: // ipfs
Expand Down
4 changes: 2 additions & 2 deletions src/protocols-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ Protocols.table = [
[445, 296, 'onion3'],
[446, V, 'garlic64'],
[460, 0, 'quic'],
[477, 0, 'ws'],
[478, 0, 'wss'],
[477, V, 'ws'],
[478, V, 'wss'],
[479, 0, 'p2p-websocket-star'],
[480, 0, 'http']
]
Expand Down
16 changes: 8 additions & 8 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('manipulation', () => {
const ipfsAddr = multiaddr('/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC')
const ip6Addr = multiaddr('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095')
const tcpAddr = multiaddr('/tcp/8000')
const webAddr = multiaddr('/ws')
const webAddr = multiaddr('/ws/libp2pEndpoint')

expect(
multiaddr('/')
Expand Down Expand Up @@ -301,28 +301,28 @@ describe('variants', () => {
})

it('ip4 + tcp + websockets', () => {
const str = '/ip4/127.0.0.1/tcp/8000/ws'
const str = '/ip4/127.0.0.1/tcp/8000/ws/libp2pEndpoint'
const addr = multiaddr(str)
expect(addr).to.have.property('buffer')
expect(addr.toString()).to.equal(str)
})

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

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

it('p2p-webrtc-star', () => {
const str = '/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
const str = '/ip4/127.0.0.1/tcp/9090/ws/meetPoint/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
const addr = multiaddr(str)
expect(addr).to.have.property('buffer')
expect(addr.toString()).to.equal(str.replace('/p2p/', '/ipfs/'))
})

it('p2p-webrtc-star ipfs', () => {
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/meetPoint/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
const addr = multiaddr(str)
expect(addr).to.have.property('buffer')
expect(addr.toString()).to.equal(str)
Expand All @@ -450,7 +450,7 @@ describe('variants', () => {
})

it('p2p-websocket-star', () => {
const str = '/ip4/127.0.0.1/tcp/9090/ws/p2p-websocket-star'
const str = '/ip4/127.0.0.1/tcp/9090/ws/meetPoint/p2p-websocket-star'
const addr = multiaddr(str)
expect(addr).to.have.property('buffer')
expect(addr.toString()).to.equal(str)
Expand Down

0 comments on commit 5fcdfad

Please sign in to comment.