Add an option for host address when running relay node (#319)

* Add an option for host address when running relay node

* Set default host and port values in yargs
This commit is contained in:
prathamesh0 2023-02-14 14:02:45 +05:30 committed by GitHub
parent 0d22915d59
commit b91f904f14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 9 deletions

View File

@ -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:

View File

@ -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<void> {
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;