Skip to content

Commit

Permalink
node: accept --no-dns configuration option to disable NS and RS
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Feb 5, 2021
1 parent a94ce87 commit c5f7901
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 44 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,12 @@

## unreleased

### Node changes

- `FullNode` and `SPVNode` accept configuration parameter `--no-dns` (or `no-dns: true` in
`hsd.conf`) which launches the node without either DNS server (the root authoritative
server and the recursive resolver). This avoids some port collisions with other HNS resolvers like hnsd running locally, and generally separates and reduces security concerns around running unneeded servers when a node is just used for transactions and blocks.

### Wallet API changes

- Adds new wallet HTTP endpoint `/wallet/:id/auction` based on `POST /wallet/:id/bid`.
Expand Down
56 changes: 34 additions & 22 deletions lib/node/fullnode.js
Expand Up @@ -38,6 +38,9 @@ class FullNode extends Node {

this.opened = false;

// Operate without DNS resolvers (just wallet and node)
this.noDNS = this.config.bool('no-dns', false);

// SPV flag.
this.spv = false;

Expand Down Expand Up @@ -147,24 +150,26 @@ class FullNode extends Node {
cors: this.config.bool('cors')
});

this.ns = new RootServer({
logger: this.logger,
key: this.identityKey,
host: this.config.str('ns-host'),
port: this.config.uint('ns-port', this.network.nsPort),
lookup: key => this.chain.db.tree.get(key),
publicHost: this.config.str('public-host')
});

this.rs = new RecursiveServer({
logger: this.logger,
key: this.identityKey,
host: this.config.str('rs-host'),
port: this.config.uint('rs-port', this.network.rsPort),
stubHost: this.ns.host,
stubPort: this.ns.port,
noUnbound: this.config.bool('rs-no-unbound')
});
if (!this.noDNS) {
this.ns = new RootServer({
logger: this.logger,
key: this.identityKey,
host: this.config.str('ns-host'),
port: this.config.uint('ns-port', this.network.nsPort),
lookup: key => this.chain.db.tree.get(key),
publicHost: this.config.str('public-host')
});

this.rs = new RecursiveServer({
logger: this.logger,
key: this.identityKey,
host: this.config.str('rs-host'),
port: this.config.uint('rs-port', this.network.rsPort),
stubHost: this.ns.host,
stubPort: this.ns.port,
noUnbound: this.config.bool('rs-no-unbound')
});
}

this.init();
}
Expand Down Expand Up @@ -259,8 +264,12 @@ class FullNode extends Node {
await this.openPlugins();

await this.http.open();
await this.ns.open();
await this.rs.open();

if (!this.noDNS) {
await this.ns.open();
await this.rs.open();
}

await this.handleOpen();

if (this.has('walletdb')) {
Expand All @@ -286,8 +295,11 @@ class FullNode extends Node {

await this.handlePreclose();
await this.http.close();
await this.rs.close();
await this.ns.close();

if (!this.noDNS) {
await this.rs.close();
await this.ns.close();
}

await this.closePlugins();

Expand Down
56 changes: 34 additions & 22 deletions lib/node/spvnode.js
Expand Up @@ -40,6 +40,9 @@ class SPVNode extends Node {

this.opened = false;

// Operate without DNS resolvers (just wallet and node)
this.noDNS = this.config.bool('no-dns', false);

// SPV flag.
this.spv = true;

Expand Down Expand Up @@ -93,24 +96,26 @@ class SPVNode extends Node {
cors: this.config.bool('cors')
});

this.ns = new RootServer({
logger: this.logger,
key: this.identityKey,
host: this.config.str('ns-host'),
port: this.config.uint('ns-port', this.network.nsPort),
lookup: key => this.pool.resolve(key),
publicHost: this.config.str('public-host')
});

this.rs = new RecursiveServer({
logger: this.logger,
key: this.identityKey,
host: this.config.str('rs-host'),
port: this.config.uint('rs-port', this.network.rsPort),
stubHost: this.ns.host,
stubPort: this.ns.port,
noUnbound: this.config.bool('rs-no-unbound')
});
if (!this.noDNS) {
this.ns = new RootServer({
logger: this.logger,
key: this.identityKey,
host: this.config.str('ns-host'),
port: this.config.uint('ns-port', this.network.nsPort),
lookup: key => this.pool.resolve(key),
publicHost: this.config.str('public-host')
});

this.rs = new RecursiveServer({
logger: this.logger,
key: this.identityKey,
host: this.config.str('rs-host'),
port: this.config.uint('rs-port', this.network.rsPort),
stubHost: this.ns.host,
stubPort: this.ns.port,
noUnbound: this.config.bool('rs-no-unbound')
});
}

this.init();
}
Expand Down Expand Up @@ -172,8 +177,12 @@ class SPVNode extends Node {
await this.openPlugins();

await this.http.open();
await this.ns.open();
await this.rs.open();

if (!this.noDNS) {
await this.ns.open();
await this.rs.open();
}

await this.handleOpen();

this.logger.info('Node is loaded.');
Expand All @@ -190,8 +199,11 @@ class SPVNode extends Node {

await this.handlePreclose();
await this.http.close();
await this.rs.close();
await this.ns.close();

if (!this.noDNS) {
await this.rs.close();
await this.ns.close();
}

await this.closePlugins();

Expand Down

0 comments on commit c5f7901

Please sign in to comment.