@multiformats/multiaddr
Advanced tools
Comparing version 10.4.0 to 10.4.1
@@ -10,6 +10,2 @@ import * as codec from './codec.js'; | ||
const inspect = Symbol.for('nodejs.util.inspect.custom'); | ||
const IP_CODES = [ | ||
getProtocol('ip4').code, | ||
getProtocol('ip6').code | ||
]; | ||
const DNS_CODES = [ | ||
@@ -25,6 +21,2 @@ getProtocol('dns').code, | ||
]; | ||
const TCP_UDP_CODES = [ | ||
getProtocol('tcp').code, | ||
getProtocol('udp').code | ||
]; | ||
const resolvers = new Map(); | ||
@@ -427,25 +419,10 @@ const symbol = Symbol.for('@multiformats/js-multiaddr/multiaddr'); | ||
nodeAddress() { | ||
const codes = this.protoCodes(); | ||
const names = this.protoNames(); | ||
const parts = this.toString().split('/').slice(1); | ||
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]) && P2P_CODES.includes(codes[1])) { | ||
protocol = getProtocol('tcp').code; | ||
port = 443; | ||
const options = this.toOptions(); | ||
if (options.transport !== 'tcp' && options.transport !== 'udp') { | ||
throw new Error(`multiaddr must have a valid format - no protocol with name: "${options.transport}". Must have a valid transport protocol: "{tcp, udp}"`); | ||
} | ||
if (parts.length < 4) { | ||
throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".'); | ||
} | ||
else if (!IP_CODES.includes(codes[0]) && !DNS_CODES.includes(codes[0])) { | ||
throw new Error(`no protocol with name: "'${names[0]}'". Must have a valid family name: "{ip4, ip6, dns, dns4, dns6, dnsaddr}".`); | ||
} | ||
else if (!TCP_UDP_CODES.includes(protocol)) { | ||
throw new Error(`no protocol with name: "'${names[1]}'". Must have a valid transport protocol: "{tcp, udp}".`); | ||
} | ||
return { | ||
family: (codes[0] === 41 || codes[0] === 55) ? 6 : 4, | ||
address: parts[1], | ||
port // tcp or udp port | ||
family: options.family, | ||
address: options.host, | ||
port: options.port | ||
}; | ||
@@ -452,0 +429,0 @@ } |
{ | ||
"name": "@multiformats/multiaddr", | ||
"version": "10.4.0", | ||
"version": "10.4.1", | ||
"description": "multiaddr implementation (binary + string representation of network addresses)", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT", |
@@ -12,6 +12,2 @@ import * as codec from './codec.js' | ||
const IP_CODES = [ | ||
getProtocol('ip4').code, | ||
getProtocol('ip6').code | ||
] | ||
const DNS_CODES = [ | ||
@@ -29,7 +25,2 @@ getProtocol('dns').code, | ||
const TCP_UDP_CODES = [ | ||
getProtocol('tcp').code, | ||
getProtocol('udp').code | ||
] | ||
export interface Protocol { | ||
@@ -490,26 +481,12 @@ code: number | ||
nodeAddress (): NodeAddress { | ||
const codes = this.protoCodes() | ||
const names = this.protoNames() | ||
const parts = this.toString().split('/').slice(1) | ||
let protocol = getProtocol(parts[2]).code | ||
let port = parseInt(parts[3]) | ||
const options = this.toOptions() | ||
// default to https when protocol & port are omitted from DNS addrs | ||
if (DNS_CODES.includes(codes[0]) && P2P_CODES.includes(codes[1])) { | ||
protocol = getProtocol('tcp').code | ||
port = 443 | ||
if (options.transport !== 'tcp' && options.transport !== 'udp') { | ||
throw new Error(`multiaddr must have a valid format - no protocol with name: "${options.transport}". Must have a valid transport protocol: "{tcp, udp}"`) | ||
} | ||
if (parts.length < 4) { | ||
throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".') | ||
} else if (!IP_CODES.includes(codes[0]) && !DNS_CODES.includes(codes[0])) { | ||
throw new Error(`no protocol with name: "'${names[0]}'". Must have a valid family name: "{ip4, ip6, dns, dns4, dns6, dnsaddr}".`) | ||
} else if (!TCP_UDP_CODES.includes(protocol)) { | ||
throw new Error(`no protocol with name: "'${names[1]}'". Must have a valid transport protocol: "{tcp, udp}".`) | ||
} | ||
return { | ||
family: (codes[0] === 41 || codes[0] === 55) ? 6 : 4, | ||
address: parts[1], | ||
port // tcp or udp port | ||
family: options.family, | ||
address: options.host, | ||
port: options.port | ||
} | ||
@@ -516,0 +493,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
132824
2704