Compare commits
No commits in common. "d2a019066a8a6fd36e54c0da2e1f52b2691de0d2" and "fb729e6a1dcdedf9159bef3d6ce20f53ac1bbf42" have entirely different histories.
d2a019066a
...
fb729e6a1d
10
package.json
10
package.json
|
@ -8,15 +8,15 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-commonjs": "^23.0.7",
|
"@rollup/plugin-commonjs": "^23.0.7",
|
||||||
"@rollup/plugin-json": "^5.0.2",
|
"@rollup/plugin-json": "^5.0.2",
|
||||||
"@rollup/plugin-node-resolve": "^15.0.2",
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
||||||
"@rollup/plugin-typescript": "^10.0.1",
|
"@rollup/plugin-typescript": "^10.0.1",
|
||||||
"@types/node": "^18.15.11",
|
"@types/node": "^18.13.0",
|
||||||
"esbuild": "^0.15.18",
|
"esbuild": "^0.15.18",
|
||||||
"prettier": "^2.8.7",
|
"prettier": "^2.8.4",
|
||||||
"rollup": "^3.20.3",
|
"rollup": "^3.15.0",
|
||||||
"tslib": "^2.5.0",
|
"tslib": "^2.5.0",
|
||||||
"typescript": "^4.9.5",
|
"typescript": "^4.9.5",
|
||||||
"vite": "^4.2.1"
|
"vite": "^4.1.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lumeweb/libhyperproxy": "git+https://git.lumeweb.com/LumeWeb/libhyperproxy.git",
|
"@lumeweb/libhyperproxy": "git+https://git.lumeweb.com/LumeWeb/libhyperproxy.git",
|
||||||
|
|
67
src/index.ts
67
src/index.ts
|
@ -3,28 +3,87 @@ import type { Plugin, PluginAPI } from "@lumeweb/relay-types";
|
||||||
import rand from "random-key";
|
import rand from "random-key";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import FullNode from "hsd/lib/node/fullnode.js";
|
import FullNode from "hsd/lib/node/fullnode.js";
|
||||||
import { MultiSocketProxy } from "@lumeweb/libhyperproxy";
|
import { Proxy, Socket } from "@lumeweb/libhyperproxy";
|
||||||
|
|
||||||
let server: FullNode;
|
let server: FullNode;
|
||||||
let api: PluginAPI;
|
let api: PluginAPI;
|
||||||
|
|
||||||
const PROTOCOL = "lumeweb.proxy.handshake";
|
const PROTOCOL = "lumeweb.proxy.handshake";
|
||||||
|
|
||||||
|
async function abort(err: any) {
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
api.logger.error("Shutdown is taking a long time. Exiting.");
|
||||||
|
process.exit(3);
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
timeout.unref();
|
||||||
|
|
||||||
|
try {
|
||||||
|
api.logger.error("Shutting down...");
|
||||||
|
await server.close();
|
||||||
|
clearTimeout(timeout);
|
||||||
|
api.logger.error((err as Error).stack);
|
||||||
|
process.exit(2);
|
||||||
|
} catch (e: any) {
|
||||||
|
api.logger.error(`Error occurred during shutdown: ${(e as Error).message}`);
|
||||||
|
process.exit(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function boot(api: PluginAPI) {
|
||||||
|
const { pluginConfig: config } = api;
|
||||||
|
|
||||||
|
const apiKey = rand.generate();
|
||||||
|
|
||||||
|
if (!config.bool("external")) {
|
||||||
|
server = new FullNode({
|
||||||
|
config: false,
|
||||||
|
argv: false,
|
||||||
|
env: true,
|
||||||
|
noDns: false,
|
||||||
|
memory: false,
|
||||||
|
httpHost: "127.0.0.1",
|
||||||
|
apiKey,
|
||||||
|
logFile: true,
|
||||||
|
logConsole: true,
|
||||||
|
logLevel: "info",
|
||||||
|
workers: false,
|
||||||
|
network: "main",
|
||||||
|
bip37: true,
|
||||||
|
});
|
||||||
|
server.on("abort", abort);
|
||||||
|
|
||||||
|
api.logger.info("API Key %s", apiKey);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await server.ensure();
|
||||||
|
await server.open();
|
||||||
|
await server.connect();
|
||||||
|
|
||||||
|
server.startSync();
|
||||||
|
} catch (e: any) {
|
||||||
|
api.logger.error((e as Error).stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const plugin: Plugin = {
|
const plugin: Plugin = {
|
||||||
name: "handshake",
|
name: "handshake",
|
||||||
async plugin(_api: PluginAPI): Promise<void> {
|
async plugin(_api: PluginAPI): Promise<void> {
|
||||||
api = _api;
|
api = _api;
|
||||||
const proxy = new MultiSocketProxy({
|
boot(api);
|
||||||
|
const proxy = new Proxy({
|
||||||
swarm: api.swarm,
|
swarm: api.swarm,
|
||||||
protocol: PROTOCOL,
|
protocol: PROTOCOL,
|
||||||
allowedPorts: [44806, 12038],
|
|
||||||
server: true,
|
|
||||||
});
|
});
|
||||||
api.swarm.join(api.util.crypto.createHash(PROTOCOL));
|
api.swarm.join(api.util.crypto.createHash(PROTOCOL));
|
||||||
api.protocols.register(PROTOCOL, (peer: any, muxer: any) => {
|
api.protocols.register(PROTOCOL, (peer: any, muxer: any) => {
|
||||||
proxy.handlePeer({
|
proxy.handlePeer({
|
||||||
peer,
|
peer,
|
||||||
muxer,
|
muxer,
|
||||||
|
onopen(socket: Socket) {
|
||||||
|
server.pool.server.emit("connection", socket);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue