Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stricter rules for custom user agent #104

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
873e844
ns: introduce hesiod metadata resolver
pinheadmz Oct 20, 2022
a0e2524
dns: fix is_subdomain()
pinheadmz Oct 21, 2022
413e42b
hesiod: resolve "recursively"
pinheadmz Oct 21, 2022
6d64cc7
integration: use HS resolution to monitor hnsd chain height
pinheadmz Oct 24, 2022
1df22cc
chain: remove full-node concept of checkpoints
pinheadmz Sep 28, 2022
cc03c52
chain: declare log function earlier
pinheadmz Sep 29, 2022
0e6532f
src: auto-generate checkpoint file for mainnet height 136000
pinheadmz Sep 29, 2022
cec3a9e
constants: parse checkpoint file
pinheadmz Sep 29, 2022
ad45dba
store, chain: create general interface for checkpoint init
pinheadmz Sep 29, 2022
695c4a7
chain: make checkpoint sync optional --checkpoint or -t
pinheadmz Sep 29, 2022
c9de195
store: read/write checkpoint file from/to disk
pinheadmz Oct 3, 2022
557acdf
chain, daemon: -x, --prefix option to read/write checkpoints
pinheadmz Oct 3, 2022
868d1be
readme: add prefix
pinheadmz Oct 3, 2022
4d3e358
store: make checkpoint file writes atomic (on POSIX at least)
pinheadmz Oct 4, 2022
b637cef
daemon: uninit options to prevent memory leak
pinheadmz Oct 4, 2022
9c1c7ea
chain: do not flush checkpoint if option is not set
pinheadmz Oct 25, 2022
58a1286
pool: tolerate duplicate blocks
pinheadmz Oct 25, 2022
4647a0d
store: move HSK_STORE_CHECKPOINT_WINDOW to constants
pinheadmz Oct 25, 2022
747bddc
test: cover checkpoint re-sync and reorg
pinheadmz Oct 25, 2022
f0de898
test: use first locator
pinheadmz Oct 26, 2022
5c925c4
store: can not rename to existing filename on windows
pinheadmz Oct 26, 2022
8b7ca1e
pool: stricter rules for custom user agent
pinheadmz Oct 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ libhsk_la_SOURCES = src/addr.c \
src/error.c \
src/hash.c \
src/header.c \
src/hesiod.c \
src/map.c \
src/msg.c \
src/poly1305/poly1305.c \
Expand All @@ -52,6 +53,7 @@ libhsk_la_SOURCES = src/addr.c \
src/sha3.c \
src/sig0.c \
src/siphash.c \
src/store.c \
src/timedata.c \
src/utils.c \
src/secp256k1/secp256k1.c
Expand Down Expand Up @@ -79,6 +81,7 @@ noinst_PROGRAMS = test_hnsd

test_hnsd_SOURCES = test/hnsd-test.c \
test/base32-test.c \
test/dns-test.c \
test/resource-test.c

test_hnsd_LDFLAGS = -static
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,16 @@ and some of them are reqired to be installed manually.
$ hnsd [options]
```

**Reccomended usage:**

```sh
mkdir ~/.hnsd
hnsd -t -x ~/.hnsd
```

This will start hnsd sync from the hard-coded checkpoint and continue to save
its own checkpoints to disk to ensure rapid chain sync on future boots.

### Options

```
Expand Down Expand Up @@ -336,6 +346,15 @@ $ hnsd [options]
-l, --log-file <filename>
Redirect output to a log file.

-a, --user-agent <string>
Add supplemental user agent string in p2p version message.

-t, --checkpoint
Start chain sync from checkpoint.

-x, --prefix <directory name>
Write/read state to/from disk in given directory.

-d, --daemon
Fork and background the process.

Expand Down
1 change: 1 addition & 0 deletions integration/package-lock.json

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

2 changes: 2 additions & 0 deletions integration/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"name": "hnsd_integration_test",
"meta": "!! version must match hnsd version in Makefile.am !!",
"version": "1.0.0",
"scripts": {
"test": "bmocha --reporter spec test/*.js",
"test-file": "bmocha --reporter spec"
Expand Down
120 changes: 85 additions & 35 deletions integration/test-util.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@

'use strict';

const assert = require('bsert');
const {spawn} = require('child_process');
const path = require('path');
const {FullNode} = require('hsd');
const {FullNode, packets} = require('hsd');
const wire = require('bns/lib/wire');
const StubResolver = require('bns/lib/resolver/stub');

class TestUtil {
constructor() {
constructor(options) {
this.node = new FullNode({
memory: true,
network: 'regtest',
Expand All @@ -17,45 +19,76 @@ class TestUtil {
plugins: [require('hsd/lib/wallet/plugin')]
});

this.packets = {};
this.node.pool.on('packet', (packet) => {
const type = packets.typesByVal[packet.type];
if (!this.packets[type])
this.packets[type] = [packet];
else
this.packets[type].push(packet);
});

this.wallet = null;

this.resolver = new StubResolver();
this.resolver.setServers(['127.0.0.1:25349']);

this.hnsd = null;
this.hnsdHeight = 0;
this.hnsdArgsBase = ['-s', '127.0.0.1:10000'];
this.hnsdArgs = this.hnsdArgsBase;
}

extraArgs(args) {
assert(Array.isArray(args));
this.hnsdArgs = this.hnsdArgs.concat(args);
}

async open() {
await this.resolver.open();
await this.node.open();
await this.node.connect();

this.wallet = this.node.plugins.walletdb;

this.hnsd = spawn(
path.join(__dirname, '..', 'hnsd'),
['-s', '127.0.0.1:10000']
);

this.hnsd.stdout.on('data', (data) => {
// TODO: `data` is always 8192 bytes and output gets cut off, why?
const chunk = data.toString('ascii');
const lines = chunk.split(/\n/);

for (const line of lines) {
const words = line.split(/\s+/);
return this.openHNSD();
}

if (words[0] !== 'chain' || words.length < 2)
continue;
async close() {
this.closeHNSD();
await this.node.close();
}

this.hnsdHeight = parseInt(words[1].slice(1, -2));
}
async openHNSD() {
return new Promise((resolve, reject) => {
this.hnsd = spawn(
path.join(__dirname, '..', 'hnsd'),
this.hnsdArgs,
{stdio: 'ignore'} // pro tip: switch to 'inherit' to see hnsd output
);

this.hnsd.on('spawn', () => resolve(this.hnsd));
this.hnsd.on('error', e => reject(e));
});
}

async close() {
closeHNSD() {
if (!this.hnsd)
return;

this.hnsd.kill('SIGKILL');
await this.node.close();
this.hnsd = null;
}

async restartHNSD(args) {
this.closeHNSD();

if (args) {
assert(Array.isArray(args));
this.hnsdArgs = this.hnsdArgsBase.concat(args);
}

return this.openHNSD();
}

async getWalletAddress() {
Expand Down Expand Up @@ -88,21 +121,38 @@ class TestUtil {
await this.generate(12); // safe root
}

waitForSync() {
return new Promise((resolve, reject) => {
// Hack
setTimeout(() => {
resolve();
}, 5000);

// // TODO: Fix hnsd stdout parsing for chain height
// setTimeout(() => {
// reject(new Error('Timeout waiting for sync'));
// }, 5000);
// setInterval(() => {
// if (this.hnsdHeight === this.node.chain.height)
// resolve();
// }, 100);
async resolveHS(name) {
const qs = wire.Question.fromJSON({
name,
class: 'HS',
type: 'TXT'
});

const {answer} = await this.resolver.resolve(qs);
assert(answer && answer.length);
return answer[0].data.txt[0];
}

async getHeights() {
const hnsd = this.hnsd
? await this.resolveHS('height.tip.chain.hnsd.')
: 0;

return {
hnsd: parseInt(hnsd),
hsd: this.node.chain.height
};
}

async waitForSync() {
const {hsd, hnsd} = await this.getHeights();
if (hsd === hnsd)
return hnsd;

return new Promise(async (resolve) => {
setTimeout(async () => {
resolve(this.waitForSync());
}, 100);
});
}
}
Expand Down
Loading