@aztec/p2p-bootstrap 0.0.0-test.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dest/index.d.ts +8 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +36 -0
- package/package.json +88 -0
- package/src/index.ts +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# P2P Bootstrap
|
|
2
|
+
|
|
3
|
+
This package provides an implementation of a 'Bootstrap' P2P node. It's purpose is to assist new network participants in acquiring peers.
|
|
4
|
+
|
|
5
|
+
To build the package simply type `yarn build`, to start the boot node, simply type `yarn start`.
|
|
6
|
+
|
|
7
|
+
The node will require a number of environment variables:
|
|
8
|
+
|
|
9
|
+
P2P_UDP_LISTEN_ADDR - The address on which to listen for connections.
|
|
10
|
+
PEER_ID_PRIVATE_KEY - The private key to be used by the peer for secure communications with other peers. This key will also be used to derive the Peer ID.
|
|
11
|
+
P2P_UDP_ANNOUNCE_ADDR - The address that other peers should use to connect to this node, this may be different to P2P_TCP_LISTEN_ADDR if e.g. the node is behind a NAT.
|
package/dest/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type BootnodeConfig } from '@aztec/p2p';
|
|
2
|
+
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
3
|
+
/**
|
|
4
|
+
* The application entry point.
|
|
5
|
+
*/
|
|
6
|
+
declare function main(config: BootnodeConfig, telemetryClient?: TelemetryClient, logger?: import("@aztec/foundation/log").Logger): Promise<void>;
|
|
7
|
+
export default main;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AASnF;;GAEG;AACH,iBAAe,IAAI,CACjB,MAAM,EAAE,cAAc,EACtB,eAAe,GAAE,eAAsC,EACvD,MAAM,yCAAc,iBA6BrB;AAED,eAAe,IAAI,CAAC"}
|
package/dest/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
3
|
+
import { BootstrapNode } from '@aztec/p2p';
|
|
4
|
+
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
5
|
+
import Koa from 'koa';
|
|
6
|
+
import Router from 'koa-router';
|
|
7
|
+
const debugLogger = createLogger('p2p-bootstrap:bootstrap_node');
|
|
8
|
+
const { HTTP_PORT } = process.env;
|
|
9
|
+
/**
|
|
10
|
+
* The application entry point.
|
|
11
|
+
*/ async function main(config, telemetryClient = getTelemetryClient(), logger = debugLogger) {
|
|
12
|
+
const store = await createStore('p2p-bootstrap', 1, config, logger);
|
|
13
|
+
const bootstrapNode = new BootstrapNode(store, telemetryClient, logger);
|
|
14
|
+
await bootstrapNode.start(config);
|
|
15
|
+
logger.info('DiscV5 Bootnode started');
|
|
16
|
+
const httpApp = new Koa();
|
|
17
|
+
const router = new Router();
|
|
18
|
+
router.get('/health', (ctx)=>{
|
|
19
|
+
ctx.status = 200;
|
|
20
|
+
});
|
|
21
|
+
httpApp.use(router.routes()).use(router.allowedMethods());
|
|
22
|
+
httpApp.listen(HTTP_PORT, ()=>{
|
|
23
|
+
logger.info(`HTTP server listening on port ${HTTP_PORT}`);
|
|
24
|
+
});
|
|
25
|
+
const stop = async ()=>{
|
|
26
|
+
logger.debug('Stopping bootstrap node...');
|
|
27
|
+
await bootstrapNode.stop();
|
|
28
|
+
logger.info('Node stopped');
|
|
29
|
+
process.exit(0);
|
|
30
|
+
};
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
32
|
+
process.on('SIGTERM', stop);
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
34
|
+
process.on('SIGINT', stop);
|
|
35
|
+
}
|
|
36
|
+
export default main;
|
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aztec/p2p-bootstrap",
|
|
3
|
+
"version": "0.0.0-test.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": "./dest/index.js",
|
|
6
|
+
"typedocOptions": {
|
|
7
|
+
"entryPoints": [
|
|
8
|
+
"./src/index.ts"
|
|
9
|
+
],
|
|
10
|
+
"name": "P2P Bootstrap",
|
|
11
|
+
"tsconfig": "./tsconfig.json"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "yarn clean && tsc -b",
|
|
15
|
+
"build:dev": "tsc -b --watch",
|
|
16
|
+
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
17
|
+
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
|
|
18
|
+
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
|
|
19
|
+
"start:dev": "tsc-watch -p tsconfig.json --onSuccess 'yarn start'",
|
|
20
|
+
"start": "node ./dest/index.js",
|
|
21
|
+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
22
|
+
},
|
|
23
|
+
"inherits": [
|
|
24
|
+
"../package.common.json"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@aztec/foundation": "0.0.0-test.0",
|
|
28
|
+
"@aztec/kv-store": "0.0.0-test.0",
|
|
29
|
+
"@aztec/p2p": "0.0.0-test.0",
|
|
30
|
+
"@aztec/telemetry-client": "0.0.0-test.0",
|
|
31
|
+
"dotenv": "^16.0.3",
|
|
32
|
+
"koa": "^2.15.3",
|
|
33
|
+
"koa-router": "^12.0.1",
|
|
34
|
+
"tslib": "^2.4.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@jest/globals": "^29.5.0",
|
|
38
|
+
"@types/jest": "^29.5.0",
|
|
39
|
+
"@types/koa": "^2.15.0",
|
|
40
|
+
"@types/koa-router": "^7.4.8",
|
|
41
|
+
"@types/node": "^18.14.6",
|
|
42
|
+
"jest": "^29.5.0",
|
|
43
|
+
"ts-node": "^10.9.1",
|
|
44
|
+
"typescript": "^5.0.4"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dest",
|
|
48
|
+
"src",
|
|
49
|
+
"!*.test.*"
|
|
50
|
+
],
|
|
51
|
+
"types": "./dest/index.d.ts",
|
|
52
|
+
"jest": {
|
|
53
|
+
"moduleNameMapper": {
|
|
54
|
+
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
|
|
55
|
+
},
|
|
56
|
+
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
|
|
57
|
+
"rootDir": "./src",
|
|
58
|
+
"transform": {
|
|
59
|
+
"^.+\\.tsx?$": [
|
|
60
|
+
"@swc/jest",
|
|
61
|
+
{
|
|
62
|
+
"jsc": {
|
|
63
|
+
"parser": {
|
|
64
|
+
"syntax": "typescript",
|
|
65
|
+
"decorators": true
|
|
66
|
+
},
|
|
67
|
+
"transform": {
|
|
68
|
+
"decoratorVersion": "2022-03"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"extensionsToTreatAsEsm": [
|
|
75
|
+
".ts"
|
|
76
|
+
],
|
|
77
|
+
"reporters": [
|
|
78
|
+
"default"
|
|
79
|
+
],
|
|
80
|
+
"testTimeout": 120000,
|
|
81
|
+
"setupFiles": [
|
|
82
|
+
"../../foundation/src/jest/setup.mjs"
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
"engines": {
|
|
86
|
+
"node": ">=18"
|
|
87
|
+
}
|
|
88
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
3
|
+
import { type BootnodeConfig, BootstrapNode } from '@aztec/p2p';
|
|
4
|
+
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
5
|
+
|
|
6
|
+
import Koa from 'koa';
|
|
7
|
+
import Router from 'koa-router';
|
|
8
|
+
|
|
9
|
+
const debugLogger = createLogger('p2p-bootstrap:bootstrap_node');
|
|
10
|
+
|
|
11
|
+
const { HTTP_PORT } = process.env;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The application entry point.
|
|
15
|
+
*/
|
|
16
|
+
async function main(
|
|
17
|
+
config: BootnodeConfig,
|
|
18
|
+
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
19
|
+
logger = debugLogger,
|
|
20
|
+
) {
|
|
21
|
+
const store = await createStore('p2p-bootstrap', 1, config, logger);
|
|
22
|
+
|
|
23
|
+
const bootstrapNode = new BootstrapNode(store, telemetryClient, logger);
|
|
24
|
+
await bootstrapNode.start(config);
|
|
25
|
+
logger.info('DiscV5 Bootnode started');
|
|
26
|
+
|
|
27
|
+
const httpApp = new Koa();
|
|
28
|
+
const router = new Router();
|
|
29
|
+
router.get('/health', (ctx: Koa.Context) => {
|
|
30
|
+
ctx.status = 200;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
httpApp.use(router.routes()).use(router.allowedMethods());
|
|
34
|
+
httpApp.listen(HTTP_PORT, () => {
|
|
35
|
+
logger.info(`HTTP server listening on port ${HTTP_PORT}`);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const stop = async () => {
|
|
39
|
+
logger.debug('Stopping bootstrap node...');
|
|
40
|
+
await bootstrapNode.stop();
|
|
41
|
+
logger.info('Node stopped');
|
|
42
|
+
process.exit(0);
|
|
43
|
+
};
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
45
|
+
process.on('SIGTERM', stop);
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
47
|
+
process.on('SIGINT', stop);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default main;
|