Compare commits

...

3 Commits

Author SHA1 Message Date
Derrick Hammer a8dd1d2c20
*Update dist 2023-02-17 19:29:29 -05:00
Derrick Hammer 79c2b167ae
*Reformat 2023-02-17 19:29:13 -05:00
Derrick Hammer aefa2712db
*make joining the topic optional 2023-02-17 19:28:33 -05:00
3 changed files with 36 additions and 15 deletions

4
dist/index.d.ts vendored
View File

@ -1,8 +1,10 @@
import { Proxy } from "@lumeweb/libhyperproxy"; import { Proxy } from "@lumeweb/libhyperproxy";
export default class HandshakeProxy extends Proxy { export default class HandshakeProxy extends Proxy {
constructor({ swarm, listen }: { private _join;
constructor({ swarm, listen, join, }: {
swarm: any; swarm: any;
listen?: boolean; listen?: boolean;
join?: boolean;
}); });
private _node?; private _node?;
get node(): any; get node(): any;

5
dist/index.js vendored
View File

@ -13,7 +13,7 @@ const b4a_1 = __importDefault(require("b4a"));
const PROTOCOL = "lumeweb.proxy.handshake"; const PROTOCOL = "lumeweb.proxy.handshake";
const libhyperproxy_1 = require("@lumeweb/libhyperproxy"); const libhyperproxy_1 = require("@lumeweb/libhyperproxy");
class HandshakeProxy extends libhyperproxy_1.Proxy { class HandshakeProxy extends libhyperproxy_1.Proxy {
constructor({ swarm, listen = false }) { constructor({ swarm, listen = false, join = false, }) {
super({ super({
swarm, swarm,
listen, listen,
@ -39,6 +39,7 @@ class HandshakeProxy extends libhyperproxy_1.Proxy {
}, },
}); });
const self = this; const self = this;
this._join = join;
} }
get node() { get node() {
return this._node; return this._node;
@ -64,10 +65,12 @@ class HandshakeProxy extends libhyperproxy_1.Proxy {
await this._node.open(); await this._node.open();
this._node.pool.connected = true; this._node.pool.connected = true;
this._node.startSync(); this._node.startSync();
if (this._join) {
const topic = b4a_1.default.from(PROTOCOL); const topic = b4a_1.default.from(PROTOCOL);
const topicHash = b4a_1.default.allocUnsafe(32); const topicHash = b4a_1.default.allocUnsafe(32);
sodium_universal_1.default.crypto_generichash(topicHash, topic); sodium_universal_1.default.crypto_generichash(topicHash, topic);
this.swarm.join(topicHash); this.swarm.join(topicHash);
} }
} }
}
exports.default = HandshakeProxy; exports.default = HandshakeProxy;

View File

@ -9,6 +9,7 @@ import sodium from "sodium-universal";
import b4a from "b4a"; import b4a from "b4a";
// @ts-ignore // @ts-ignore
import c from "compact-encoding"; import c from "compact-encoding";
const PROTOCOL = "lumeweb.proxy.handshake"; const PROTOCOL = "lumeweb.proxy.handshake";
import { import {
@ -19,7 +20,17 @@ import {
} from "@lumeweb/libhyperproxy"; } from "@lumeweb/libhyperproxy";
export default class HandshakeProxy extends Proxy { export default class HandshakeProxy extends Proxy {
constructor({ swarm, listen = false }: { swarm: any; listen?: boolean }) { private _join: boolean;
constructor({
swarm,
listen = false,
join = false,
}: {
swarm: any;
listen?: boolean;
join?: boolean;
}) {
super({ super({
swarm, swarm,
listen, listen,
@ -49,6 +60,7 @@ export default class HandshakeProxy extends Proxy {
}, },
}); });
const self = this; const self = this;
this._join = join;
} }
private _node?: any; private _node?: any;
@ -74,18 +86,22 @@ export default class HandshakeProxy extends Proxy {
}); });
if (this?._node?.http?.http?.listen) { if (this?._node?.http?.http?.listen) {
this._node.http.http.listen = (port: number, host: string, cb: Function) => this._node.http.http.listen = (
cb(); port: number,
host: string,
cb: Function
) => cb();
} }
await this._node.open(); await this._node.open();
this._node.pool.connected = true; this._node.pool.connected = true;
this._node.startSync(); this._node.startSync();
if (this._join) {
const topic = b4a.from(PROTOCOL); const topic = b4a.from(PROTOCOL);
const topicHash = b4a.allocUnsafe(32); const topicHash = b4a.allocUnsafe(32);
sodium.crypto_generichash(topicHash, topic); sodium.crypto_generichash(topicHash, topic);
this.swarm.join(topicHash); this.swarm.join(topicHash);
} }
} }
}