import type { PromiseCancellable } from '@matrixai/async-cancellable'; import type { ContextTimedInput } from '@matrixai/contexts'; import type { Address, Host, Hostname, Port } from './types.js'; import type { NodeAddress } from '../nodes/types.js'; import type { JSONValue } from '../types.js'; /** * Is it an IPv4 address? */ declare function isIPv4(host: any): host is Host; /** * Is it an IPv6 address? * This considers IPv4 mapped IPv6 addresses to also be IPv6 addresses. */ declare function isIPv6(host: any): host is Host; /** * There are 2 kinds of IPv4 mapped IPv6 addresses. * 1. ::ffff:127.0.0.1 - dotted decimal version * 2. ::ffff:7f00:1 - hex version * Both are accepted by Node's dgram module. */ declare function isIPv4MappedIPv6(host: any): host is Host; declare function isIPv4MappedIPv6Hex(host: any): host is Host; declare function isIPv4MappedIPv6Dec(host: any): host is Host; /** * Extracts the IPv4 portion out of the IPv4 mapped IPv6 address. * Can handle both the dotted decimal and hex variants. * 1. ::ffff:7f00:1 * 2. ::ffff:127.0.0.1 * Always returns the dotted decimal variant. */ declare function fromIPv4MappedIPv6(host: unknown): Host; /** * Validates that a provided host address is a valid IPv4 or IPv6 address. */ declare function isHost(host: any): host is Host; declare function isHostWildcard(host: any): boolean; /** * Validates hostname as per RFC 1123 */ declare function isHostname(hostname: any): hostname is Hostname; /** * Ports must be numbers between 0 and 65535 inclusive * If connect is true, then port must be a number between 1 and 65535 inclusive */ declare function isPort(port: any, connect?: boolean): port is Port; declare function parseHost(data: any): Host; declare function parseHostname(data: any): Hostname; declare function parseHostOrHostname(data: any): Host | Hostname; /** * Parses number into a Port * Data can be a string-number */ declare function parsePort(data: any, connect?: boolean): Port; /** * Canonicalizes an IP address into a consistent format. * This will: * - Remove leading 0s from IPv4 addresses and IPv6 addresses * - Expand :: into 0s for IPv6 addresses * - Extract IPv4 decimal notation from IPv4 mapped IPv6 addresses * - Lowercase all hex characters in IPv6 addresses */ declare function toCanonicalHost(host: string): Host; declare function toCanonicalHostname(hostname: string): Hostname; /** * Given host and port, create an address string. */ declare function buildAddress(host: Host, port?: Port): Address; /** * Parse an address string into host and port */ declare function parseAddress(address: string): [Host, Port]; /** * Checks if error is software error. * These error codes would mean there's something broken with DNS. */ declare function isDNSError(e: { code: string; }): boolean; /** * Resolve a hostname to all IPv4 and IPv6 hosts. * It does an iterative BFS over any CNAME records. * This performs proper DNS lookup, it does not use the operating system's * resolver. However the default set of DNS servers is inherited from the * operating system configuration. * The default time limit is practically infinity. * This means if the DNS server doesn't respond, this function could take * a very long time. */ declare function resolveHostname(hostname: Hostname, servers?: Array, ctx?: Partial): PromiseCancellable>; /** * Zero IPs should be resolved to localhost when used as the target * This is usually done automatically, but utp-native doesn't do this */ declare function resolvesZeroIP(ip: Host): Host; /** * Takes an array of host or hostnames and resolves them to the host addresses. * It will also filter out any duplicates. * @param addresses * @param existingAddresses * @param servers * @param ctx */ declare function resolveHostnames(addresses: Array, existingAddresses?: Set, servers?: Array, ctx?: Partial): Promise>; declare function fromError(error: any): any; declare function toError(errorData: JSONValue, clientMetadata: Record, top?: boolean): any; export { isIPv4, isIPv6, isIPv4MappedIPv6, isIPv4MappedIPv6Hex, isIPv4MappedIPv6Dec, fromIPv4MappedIPv6, isHost, isHostWildcard, isHostname, isPort, parseHost, parseHostname, parseHostOrHostname, parsePort, toCanonicalHost, toCanonicalHostname, buildAddress, parseAddress, isDNSError, resolveHostname, resolvesZeroIP, resolveHostnames, fromError, toError, };