From 46b1048d63832a408b91d236a709f99e3752f4d3 Mon Sep 17 00:00:00 2001 From: Karl Ranna Date: Wed, 17 Jul 2019 07:43:21 +0000 Subject: [PATCH] feat(raiden-resolver): add configuration option for listening interface --- bin/xud | 4 ++++ lib/Config.ts | 3 ++- lib/Xud.ts | 5 ++++- lib/http/HttpServer.ts | 6 +++--- sample-xud.conf | 4 ++++ test/unit/HttpServer.spec.ts | 2 +- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/bin/xud b/bin/xud index 6cc32be29..4be687dcc 100755 --- a/bin/xud +++ b/bin/xud @@ -76,6 +76,10 @@ const { argv } = require('yargs') describe: 'Port to listen for http requests', type: 'number', }, + 'http.host': { + describe: 'Host of the http server', + type: 'string', + }, 'lnd.[currency].certpath': { describe: 'Path to the SSL certificate for lnd', type: 'string', diff --git a/lib/Config.ts b/lib/Config.ts index d6ad7771c..0c0a8f859 100644 --- a/lib/Config.ts +++ b/lib/Config.ts @@ -18,7 +18,7 @@ class Config { public logdateformat: string; public network: XuNetwork; public rpc: { disable: boolean, host: string, port: number }; - public http: { port: number }; + public http: { host: string, port: number }; public lnd: { [currency: string]: LndClientConfig | undefined } = {}; public raiden: RaidenClientConfig; public orderthresholds: OrderBookThresholds; @@ -89,6 +89,7 @@ class Config { port: 8886, }; this.http = { + host: 'localhost', port: 8887, }; this.webproxy = { diff --git a/lib/Xud.ts b/lib/Xud.ts index c89f8e069..fe693bb6f 100644 --- a/lib/Xud.ts +++ b/lib/Xud.ts @@ -145,7 +145,10 @@ class Xud extends EventEmitter { if (!this.swapClientManager.raidenClient.isDisabled()) { this.httpServer = new HttpServer(loggers.http, this.service); - await this.httpServer.listen(this.config.http.port); + await this.httpServer.listen( + this.config.http.port, + this.config.http.host, + ); } // start rpc server last diff --git a/lib/http/HttpServer.ts b/lib/http/HttpServer.ts index d104356e7..77648c287 100644 --- a/lib/http/HttpServer.ts +++ b/lib/http/HttpServer.ts @@ -83,14 +83,14 @@ class HttpServer { /** * Starts the server and begins listening on the provided port. */ - public listen = async (port: number) => { + public listen = async (port: number, host: string) => { return new Promise((resolve, reject) => { const listenErrHandler = (err: Error) => { reject(err); }; - this.server.listen(port, '127.0.0.1').once('listening', () => { - this.logger.info(`http server listening on 127.0.0.1:${port}`); + this.server.listen(port, host).once('listening', () => { + this.logger.info(`http server listening on ${host}:${port}`); this.server.removeListener('error', listenErrHandler); resolve(); }).on('error', listenErrHandler); diff --git a/sample-xud.conf b/sample-xud.conf index 0eccfbe25..0e75a4a60 100644 --- a/sample-xud.conf +++ b/sample-xud.conf @@ -39,6 +39,7 @@ nomatching = false nosanityswaps = true [http] +host = "localhost" port = 8887 [lnd.BTC] @@ -55,6 +56,9 @@ host = "localhost" nomacaroons = false port = 10010 +[orderthresholds] +minQuantity = 0 + [p2p] addresses = [] detectexternalip = false diff --git a/test/unit/HttpServer.spec.ts b/test/unit/HttpServer.spec.ts index b2b8efdaf..c3f3dcebe 100644 --- a/test/unit/HttpServer.spec.ts +++ b/test/unit/HttpServer.spec.ts @@ -34,7 +34,7 @@ describe('HttpServer', () => { before(async () => { port = await getUnusedPort(); - await httpServer.listen(port); + await httpServer.listen(port, 'localhost'); }); it('should receive and parse a raiden resolve request', (done) => {