Skip to content

Commit

Permalink
feat: Add SNI support (#312)
Browse files Browse the repository at this point in the history
Adds the JS part of multiformats/multiaddr#138
  • Loading branch information
MarcoPolo authored Mar 6, 2023
1 parent 8e2f680 commit b44f608
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function convertToString (proto: number | string, buf: Uint8Array): strin
case 55: // dns6
case 56: // dnsaddr
case 400: // unix
case 449: // sni
case 777: // memory
return bytes2str(buf)

Expand Down Expand Up @@ -89,6 +90,7 @@ export function convertToBytes (proto: string | number, str: string): Uint8Array
case 55: // dns6
case 56: // dnsaddr
case 400: // unix
case 449: // sni
case 777: // memory
return str2bytes(str)

Expand Down
1 change: 1 addition & 0 deletions src/protocols-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const table: Array<[number, number, string, boolean?, boolean?]> = [
[445, 296, 'onion3'],
[446, V, 'garlic64'],
[448, 0, 'tls'],
[449, V, 'sni'],
[460, 0, 'quic'],
[461, 0, 'quic-v1'],
[465, 0, 'webtransport'],
Expand Down
7 changes: 7 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,13 @@ describe('variants', () => {
expect(addr.toString()).to.equal(str)
})

it('sni', () => {
const str = '/ip4/127.0.0.1/tcp/9090/tls/sni/example.com/ws'
const addr = multiaddr(str)
expect(addr).to.have.property('bytes')
expect(addr.toString()).to.equal(str)
})

it('onion', () => {
const str = '/onion/timaq4ygg2iegci7:1234'
const addr = multiaddr(str)
Expand Down

0 comments on commit b44f608

Please sign in to comment.