@multiformats/multiaddr
Advanced tools
Comparing version 10.3.1 to 10.3.2
@@ -20,2 +20,10 @@ import * as codec from './codec.js'; | ||
]; | ||
const P2P_CODES = [ | ||
getProtocol('p2p').code, | ||
getProtocol('ipfs').code | ||
]; | ||
const TCP_UDP_CODES = [ | ||
getProtocol('tcp').code, | ||
getProtocol('udp').code | ||
]; | ||
const resolvers = new Map(); | ||
@@ -400,7 +408,7 @@ const symbol = Symbol.for('@multiformats/js-multiaddr/multiaddr'); | ||
const parts = this.toString().split('/').slice(1); | ||
let protocol = parts[2]; | ||
let protocol = getProtocol(parts[2]).code; | ||
let port = parseInt(parts[3]); | ||
// default to https when protocol & port are omitted from DNS addrs | ||
if (DNS_CODES.includes(codes[0]) && protocol === 'p2p') { | ||
protocol = 'tcp'; | ||
if (DNS_CODES.includes(codes[0]) && P2P_CODES.includes(codes[1])) { | ||
protocol = getProtocol('tcp').code; | ||
port = 443; | ||
@@ -414,3 +422,3 @@ } | ||
} | ||
else if (protocol !== 'tcp' && protocol !== 'udp') { | ||
else if (!TCP_UDP_CODES.includes(protocol)) { | ||
throw new Error(`no protocol with name: "'${names[1]}'". Must have a valid transport protocol: "{tcp, udp}".`); | ||
@@ -417,0 +425,0 @@ } |
{ | ||
"name": "@multiformats/multiaddr", | ||
"version": "10.3.1", | ||
"version": "10.3.2", | ||
"description": "multiaddr implementation (binary + string representation of network addresses)", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT", |
@@ -23,2 +23,12 @@ import * as codec from './codec.js' | ||
const P2P_CODES = [ | ||
getProtocol('p2p').code, | ||
getProtocol('ipfs').code | ||
] | ||
const TCP_UDP_CODES = [ | ||
getProtocol('tcp').code, | ||
getProtocol('udp').code | ||
] | ||
export interface Protocol { | ||
@@ -463,8 +473,8 @@ code: number | ||
const parts = this.toString().split('/').slice(1) | ||
let protocol = parts[2] | ||
let protocol = getProtocol(parts[2]).code | ||
let port = parseInt(parts[3]) | ||
// default to https when protocol & port are omitted from DNS addrs | ||
if (DNS_CODES.includes(codes[0]) && protocol === 'p2p') { | ||
protocol = 'tcp' | ||
if (DNS_CODES.includes(codes[0]) && P2P_CODES.includes(codes[1])) { | ||
protocol = getProtocol('tcp').code | ||
port = 443 | ||
@@ -477,3 +487,3 @@ } | ||
throw new Error(`no protocol with name: "'${names[0]}'". Must have a valid family name: "{ip4, ip6, dns, dns4, dns6, dnsaddr}".`) | ||
} else if (protocol !== 'tcp' && protocol !== 'udp') { | ||
} else if (!TCP_UDP_CODES.includes(protocol)) { | ||
throw new Error(`no protocol with name: "'${names[1]}'". Must have a valid transport protocol: "{tcp, udp}".`) | ||
@@ -480,0 +490,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
131161
2657