*Add dist

This commit is contained in:
Derrick Hammer 2023-01-12 12:53:58 -05:00
parent d2ac85ae84
commit 27f7d8103f
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 78 additions and 0 deletions

9
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
import { Proxy } from "@lumeweb/libhyperproxy";
export default class HandshakeProxy extends Proxy {
private _node?;
constructor({ swarm, listen }: {
swarm: any;
listen?: boolean;
});
protected _init(): Promise<void>;
}

69
dist/index.js vendored Normal file
View File

@ -0,0 +1,69 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-ignore
const node_1 = require("hsd/lib/node");
// @ts-ignore
const net_1 = require("hsd/lib/net");
// @ts-ignore
const sodium_universal_1 = __importDefault(require("sodium-universal"));
const b4a_1 = __importDefault(require("b4a"));
const PROTOCOL = "lumeweb.proxy.handshake";
const libhyperproxy_1 = require("@lumeweb/libhyperproxy");
class HandshakeProxy extends libhyperproxy_1.Proxy {
constructor({ swarm, listen = false }) {
super({
swarm,
listen,
autostart: true,
protocol: PROTOCOL,
async onopen(socket) {
const peer = net_1.Peer.fromInbound(self._node.pool.options, socket);
peer.connected = false;
peer.outbound = true;
if (self._node.pool.peers.map.has(peer.hostname()) ||
self._node.pool.peers.ids.has(peer.id)) {
return { connect: false };
}
self._node.pool.bindPeer(peer);
const open = peer.tryOpen();
// @ts-ignore
socket.emit("connect");
await open;
self._node.pool.peers.add(peer);
self._node.pool.connectedGroups.add(peer.address.getGroup());
self._node.pool.emit("peer", peer);
return { connect: false };
// self._node.pool.server.emit("connection", socket);
},
});
const self = this;
}
async _init() {
this._node = new node_1.SPVNode({
config: false,
argv: false,
env: false,
noDns: true,
memory: true,
logFile: false,
logConsole: true,
logLevel: "info",
workers: true,
network: "main",
createServer: libhyperproxy_1.createServer,
createSocket: libhyperproxy_1.createSocket,
});
this._node.http.http.listen = (port, host, cb) => cb();
await this._node.open();
this._node.pool.connected = true;
this._node.startSync();
const topic = b4a_1.default.from(PROTOCOL);
const topicHash = b4a_1.default.allocUnsafe(32);
sodium_universal_1.default.crypto_generichash(topicHash, topic);
this.swarm.join(topicHash);
}
}
exports.default = HandshakeProxy;