Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed websocket [secure] to endpoint selection. #90

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Hugo Dias <hugomrdias@gmail.com>",
"Jacob Heun <jacobheun@gmail.com>",
"Jorropo <jorropo.pgm@gmail.com>",
"Juan Batiz-Benet <juan@benet.ai>",
"Lars Gierth <lgierth@users.noreply.github.com>",
"Maciej Krüger <mkg20001@gmail.com>",
Expand Down
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
4 changes: 2 additions & 2 deletions test/convert.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('convert', () => {
describe('.toBuffer', () => {
it('defaults to hex conversion', () => {
expect(
convert.toBuffer('ws', 'c0a80001')
convert.toBuffer('p2p-webrtc-star', 'c0a80001')
).to.eql(
Buffer.from([192, 168, 0, 1])
)
Expand All @@ -78,7 +78,7 @@ describe('convert', () => {

it('defaults to hex conversion', () => {
expect(
convert.toString('ws', Buffer.from([192, 168, 0, 1]))
convert.toString('p2p-webrtc-star', Buffer.from([192, 168, 0, 1]))
).to.eql(
'c0a80001'
)
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