UNPKG

@libp2p/tcp

Version:
33 lines 1.11 kB
import os from 'os'; import path from 'path'; import { InvalidParametersError } from '@libp2p/interface'; import { getNetConfig } from '@libp2p/utils'; import { CODE_UNIX } from '@multiformats/multiaddr'; import { Unix } from '@multiformats/multiaddr-matcher'; export function multiaddrToNetConfig(addr, options = {}) { if (Unix.exactMatch(addr)) { const listenPath = addr.getComponents().find(c => c.code === CODE_UNIX)?.value; if (listenPath == null) { throw new InvalidParametersError(`Multiaddr ${addr} was not a Unix address`); } // unix socket listening if (os.platform() === 'win32') { // Use named pipes on Windows systems. return { path: path.join('\\\\.\\pipe\\', listenPath) }; } else { return { path: listenPath }; } } const config = getNetConfig(addr); const host = config.host; const port = config.port; // tcp listening return { host, port, ipv6Only: config.type === 'ip6', ...options }; } //# sourceMappingURL=utils.js.map