Compare commits
No commits in common. "a8dd1d2c20283b380b52ba1e1c3404e8e86b9e70" and "0fb85e3e5b771f6b189613a0fa6b4a01aac2e48a" have entirely different histories.
a8dd1d2c20
...
0fb85e3e5b
|
@ -1,10 +1,8 @@
|
|||
import { Proxy } from "@lumeweb/libhyperproxy";
|
||||
export default class HandshakeProxy extends Proxy {
|
||||
private _join;
|
||||
constructor({ swarm, listen, join, }: {
|
||||
constructor({ swarm, listen }: {
|
||||
swarm: any;
|
||||
listen?: boolean;
|
||||
join?: boolean;
|
||||
});
|
||||
private _node?;
|
||||
get node(): any;
|
||||
|
|
|
@ -13,7 +13,7 @@ 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, join = false, }) {
|
||||
constructor({ swarm, listen = false }) {
|
||||
super({
|
||||
swarm,
|
||||
listen,
|
||||
|
@ -39,7 +39,6 @@ class HandshakeProxy extends libhyperproxy_1.Proxy {
|
|||
},
|
||||
});
|
||||
const self = this;
|
||||
this._join = join;
|
||||
}
|
||||
get node() {
|
||||
return this._node;
|
||||
|
@ -65,12 +64,10 @@ class HandshakeProxy extends libhyperproxy_1.Proxy {
|
|||
await this._node.open();
|
||||
this._node.pool.connected = true;
|
||||
this._node.startSync();
|
||||
if (this._join) {
|
||||
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;
|
||||
|
|
24
src/index.ts
24
src/index.ts
|
@ -9,7 +9,6 @@ import sodium from "sodium-universal";
|
|||
import b4a from "b4a";
|
||||
// @ts-ignore
|
||||
import c from "compact-encoding";
|
||||
|
||||
const PROTOCOL = "lumeweb.proxy.handshake";
|
||||
|
||||
import {
|
||||
|
@ -20,17 +19,7 @@ import {
|
|||
} from "@lumeweb/libhyperproxy";
|
||||
|
||||
export default class HandshakeProxy extends Proxy {
|
||||
private _join: boolean;
|
||||
|
||||
constructor({
|
||||
swarm,
|
||||
listen = false,
|
||||
join = false,
|
||||
}: {
|
||||
swarm: any;
|
||||
listen?: boolean;
|
||||
join?: boolean;
|
||||
}) {
|
||||
constructor({ swarm, listen = false }: { swarm: any; listen?: boolean }) {
|
||||
super({
|
||||
swarm,
|
||||
listen,
|
||||
|
@ -60,7 +49,6 @@ export default class HandshakeProxy extends Proxy {
|
|||
},
|
||||
});
|
||||
const self = this;
|
||||
this._join = join;
|
||||
}
|
||||
|
||||
private _node?: any;
|
||||
|
@ -86,22 +74,18 @@ export default class HandshakeProxy extends Proxy {
|
|||
});
|
||||
|
||||
if(this?._node?.http?.http?.listen){
|
||||
this._node.http.http.listen = (
|
||||
port: number,
|
||||
host: string,
|
||||
cb: Function
|
||||
) => cb();
|
||||
this._node.http.http.listen = (port: number, host: string, cb: Function) =>
|
||||
cb();
|
||||
}
|
||||
|
||||
|
||||
await this._node.open();
|
||||
this._node.pool.connected = true;
|
||||
this._node.startSync();
|
||||
|
||||
if (this._join) {
|
||||
const topic = b4a.from(PROTOCOL);
|
||||
const topicHash = b4a.allocUnsafe(32);
|
||||
sodium.crypto_generichash(topicHash, topic);
|
||||
this.swarm.join(topicHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue