diff --git a/packages/cli/README.md b/packages/cli/README.md index 6ae0a786..46f864e3 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -30,12 +30,13 @@ A basic CLI to pass messages between peers using `stdin`/`stdout` ```bash # In packages/peer - yarn relay-node --port [LISTEN_PORT] --peer-id-file [PEER_ID_FILE_PATH] --relay-peers [RELAY_PEERS_FILE_PATH] + yarn relay-node --host [LISTEN_HOST] --port [LISTEN_PORT] --peer-id-file [PEER_ID_FILE_PATH] --relay-peers [RELAY_PEERS_FILE_PATH] ``` - * `port`: Port to start listening on (default: `9090`) - * `peer-id-file`: file path for peer id to be used (json) - * `relay-peers`: file path for relay peer multiaddr(s) to dial on startup (json) + * `host (h)`: Host to bind to (default: `127.0.0.1`) + * `port (p)`: Port to start listening on (default: `9090`) + * `peer-id-file (f)`: file path for peer id to be used (json) + * `relay-peers (r)`: file path for relay peer multiaddr(s) to dial on startup (json) * Start the node: diff --git a/packages/peer/src/relay.ts b/packages/peer/src/relay.ts index 0b93263d..657289f5 100644 --- a/packages/peer/src/relay.ts +++ b/packages/peer/src/relay.ts @@ -25,10 +25,8 @@ import { PeerHearbeatChecker } from './peer-heartbeat-checker.js'; const log = debug('laconic:relay'); -const DEFAULT_HOST = '0.0.0.0'; -const DEFAULT_PORT = 9090; - interface Arguments { + host: string; port: number; peerIdFile: string; relayPeers: string; @@ -49,8 +47,7 @@ async function main (): Promise { console.log('Creating a new peer id'); } - const listenPort = argv.port ? argv.port : DEFAULT_PORT; - const listenMultiaddr = `/ip4/${DEFAULT_HOST}/tcp/${listenPort}/http/p2p-webrtc-direct`; + const listenMultiaddr = `/ip4/${argv.host}/tcp/${argv.port}/http/p2p-webrtc-direct`; const node = await createLibp2p({ peerId, @@ -135,16 +132,26 @@ function _getArgv (): any { return yargs(hideBin(process.argv)).parserConfiguration({ 'parse-numbers': false }).options({ + host: { + type: 'string', + alias: 'h', + default: '127.0.0.1', + describe: 'Host to bind to' + }, port: { type: 'number', + alias: 'p', + default: '9090', describe: 'Port to start listening on' }, peerIdFile: { type: 'string', + alias: 'f', describe: 'Relay Peer Id file path (json)' }, relayPeers: { type: 'string', + alias: 'r', describe: 'Relay peer multiaddr(s) list file path (json)' } }).argv;