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

feat: Add SNI support #312

Merged
merged 1 commit into from
Mar 6, 2023
Merged
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
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