relay-plugin-handshake/src/index.ts

34 lines
813 B
TypeScript
Raw Normal View History

2022-12-07 09:24:42 +00:00
import type { Plugin, PluginAPI } from "@lumeweb/relay-types";
2022-08-28 17:07:45 +00:00
// @ts-ignore
import rand from "random-key";
// @ts-ignore
import FullNode from "hsd/lib/node/fullnode.js";
import { MultiSocketProxy } from "@lumeweb/libhyperproxy";
2022-08-28 17:07:45 +00:00
let server: FullNode;
let api: PluginAPI;
const PROTOCOL = "lumeweb.proxy.handshake";
2022-08-28 17:07:45 +00:00
const plugin: Plugin = {
name: "handshake",
async plugin(_api: PluginAPI): Promise<void> {
api = _api;
const proxy = new MultiSocketProxy({
swarm: api.swarm,
protocol: PROTOCOL,
allowedPorts: [44806, 12038],
server: true,
});
api.swarm.join(api.util.crypto.createHash(PROTOCOL));
api.protocols.register(PROTOCOL, (peer: any, muxer: any) => {
proxy.handlePeer({
peer,
muxer,
});
2022-08-28 17:07:45 +00:00
});
},
};
export default plugin;