mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-04-20 21:51:14 +00:00
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:
parent
0d22915d59
commit
b91f904f14
@ -30,12 +30,13 @@ A basic CLI to pass messages between peers using `stdin`/`stdout`
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# In packages/peer
|
# 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`)
|
* `host (h)`: Host to bind to (default: `127.0.0.1`)
|
||||||
* `peer-id-file`: file path for peer id to be used (json)
|
* `port (p)`: Port to start listening on (default: `9090`)
|
||||||
* `relay-peers`: file path for relay peer multiaddr(s) to dial on startup (json)
|
* `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:
|
* Start the node:
|
||||||
|
|
||||||
|
@ -25,10 +25,8 @@ import { PeerHearbeatChecker } from './peer-heartbeat-checker.js';
|
|||||||
|
|
||||||
const log = debug('laconic:relay');
|
const log = debug('laconic:relay');
|
||||||
|
|
||||||
const DEFAULT_HOST = '0.0.0.0';
|
|
||||||
const DEFAULT_PORT = 9090;
|
|
||||||
|
|
||||||
interface Arguments {
|
interface Arguments {
|
||||||
|
host: string;
|
||||||
port: number;
|
port: number;
|
||||||
peerIdFile: string;
|
peerIdFile: string;
|
||||||
relayPeers: string;
|
relayPeers: string;
|
||||||
@ -49,8 +47,7 @@ async function main (): Promise<void> {
|
|||||||
console.log('Creating a new peer id');
|
console.log('Creating a new peer id');
|
||||||
}
|
}
|
||||||
|
|
||||||
const listenPort = argv.port ? argv.port : DEFAULT_PORT;
|
const listenMultiaddr = `/ip4/${argv.host}/tcp/${argv.port}/http/p2p-webrtc-direct`;
|
||||||
const listenMultiaddr = `/ip4/${DEFAULT_HOST}/tcp/${listenPort}/http/p2p-webrtc-direct`;
|
|
||||||
|
|
||||||
const node = await createLibp2p({
|
const node = await createLibp2p({
|
||||||
peerId,
|
peerId,
|
||||||
@ -135,16 +132,26 @@ function _getArgv (): any {
|
|||||||
return yargs(hideBin(process.argv)).parserConfiguration({
|
return yargs(hideBin(process.argv)).parserConfiguration({
|
||||||
'parse-numbers': false
|
'parse-numbers': false
|
||||||
}).options({
|
}).options({
|
||||||
|
host: {
|
||||||
|
type: 'string',
|
||||||
|
alias: 'h',
|
||||||
|
default: '127.0.0.1',
|
||||||
|
describe: 'Host to bind to'
|
||||||
|
},
|
||||||
port: {
|
port: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
alias: 'p',
|
||||||
|
default: '9090',
|
||||||
describe: 'Port to start listening on'
|
describe: 'Port to start listening on'
|
||||||
},
|
},
|
||||||
peerIdFile: {
|
peerIdFile: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
alias: 'f',
|
||||||
describe: 'Relay Peer Id file path (json)'
|
describe: 'Relay Peer Id file path (json)'
|
||||||
},
|
},
|
||||||
relayPeers: {
|
relayPeers: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
alias: 'r',
|
||||||
describe: 'Relay peer multiaddr(s) list file path (json)'
|
describe: 'Relay peer multiaddr(s) list file path (json)'
|
||||||
}
|
}
|
||||||
}).argv;
|
}).argv;
|
||||||
|
Loading…
Reference in New Issue
Block a user