Skip to content

Commit

Permalink
feat(raiden-resolver): add configuration option for listening interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl Ranna committed Jul 17, 2019
1 parent b9fd676 commit 46b1048
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions bin/xud
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion lib/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,6 +89,7 @@ class Config {
port: 8886,
};
this.http = {
host: 'localhost',
port: 8887,
};
this.webproxy = {
Expand Down
5 changes: 4 additions & 1 deletion lib/Xud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/http/HttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((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);
Expand Down
4 changes: 4 additions & 0 deletions sample-xud.conf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/unit/HttpServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 46b1048

Please sign in to comment.