Compare commits
No commits in common. "be22b771f54daf51861320e1a0bfd8c43dc39047" and "90ef9e33867908fdb28cfd41cecc2665a4ff09dc" have entirely different histories.
be22b771f5
...
90ef9e3386
|
@ -13,11 +13,7 @@ import pluginCore from "./plugins/core";
|
|||
import type Config from "@lumeweb/cfg";
|
||||
import EventEmitter2 from "eventemitter2";
|
||||
import log from "../log.js";
|
||||
import {
|
||||
get as getSwarm,
|
||||
getProtocolManager,
|
||||
ProtocolManager,
|
||||
} from "./swarm.js";
|
||||
import { get as getSwarm } from "./swarm.js";
|
||||
import { get as getSSl, SSLManager } from "./ssl.js";
|
||||
import type { HDKey } from "micro-ed25519-hdkey";
|
||||
|
||||
|
@ -90,10 +86,6 @@ class PluginAPI extends EventEmitter2 {
|
|||
return getSSl();
|
||||
}
|
||||
|
||||
get protocols(): ProtocolManager {
|
||||
return getProtocolManager();
|
||||
}
|
||||
|
||||
public loadPlugin(
|
||||
moduleName: string
|
||||
): (moduleName: string) => Promise<Plugin> {
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
import Hyperswarm from "hyperswarm";
|
||||
// @ts-ignore
|
||||
import DHT from "@hyperswarm/dht";
|
||||
// @ts-ignore
|
||||
import Protomux from "protomux";
|
||||
|
||||
// @ts-ignore
|
||||
import sodium from "sodium-universal";
|
||||
|
@ -22,7 +20,6 @@ sodium.crypto_generichash(LUMEWEB_TOPIC_HASH, LUMEWEB);
|
|||
export type SecretStream = any;
|
||||
|
||||
let node: Hyperswarm;
|
||||
let protocolManager: ProtocolManager;
|
||||
|
||||
export async function start() {
|
||||
const keyPair = getKeyPair();
|
||||
|
@ -54,44 +51,3 @@ export async function start() {
|
|||
export function get(): Hyperswarm {
|
||||
return node;
|
||||
}
|
||||
|
||||
export class ProtocolManager {
|
||||
private _protocols: Map<string, Function> = new Map<string, Function>();
|
||||
private _swarm;
|
||||
|
||||
constructor(swarm: any) {
|
||||
this._swarm = swarm;
|
||||
|
||||
this._swarm.on("connection", (peer: any) => {
|
||||
for (const protocol of this._protocols) {
|
||||
Protomux.from(peer).pair(
|
||||
protocol[0],
|
||||
this.handler.bind(this, protocol[0], peer)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private handler(protocol: string, peer: any) {
|
||||
if (this._protocols.has(protocol)) {
|
||||
this._protocols.get(protocol)?.(peer, Protomux.from(peer));
|
||||
}
|
||||
}
|
||||
|
||||
public register(name: string, handler: Function): boolean {
|
||||
if (this._protocols.has(name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._protocols.set(name, handler);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export function getProtocolManager(): ProtocolManager {
|
||||
if (!protocolManager) {
|
||||
protocolManager = new ProtocolManager(get());
|
||||
}
|
||||
|
||||
return protocolManager;
|
||||
}
|
||||
|
|
|
@ -650,13 +650,13 @@ __metadata:
|
|||
|
||||
"@lumeweb/dht-flood@https://git.lumeweb.com/LumeWeb/dht-flood.git":
|
||||
version: 0.1.0
|
||||
resolution: "@lumeweb/dht-flood@https://git.lumeweb.com/LumeWeb/dht-flood.git#commit=9cd5e798d91bfb5ffe9665894421e22372852f8f"
|
||||
resolution: "@lumeweb/dht-flood@https://git.lumeweb.com/LumeWeb/dht-flood.git#commit=993eff5398ce3018dc52f281d71750676d4cb700"
|
||||
dependencies:
|
||||
compact-encoding: "npm:^2.11.0"
|
||||
lru: "npm:^3.1.0"
|
||||
protocol-buffers-encodings: "npm:^1.2.0"
|
||||
protomux-rpc: "npm:^1.3.0"
|
||||
checksum: de53558a9e91bcade4136c1566b5ee913b03b5086e91cce64fdff2c5e2e09726e33829d42da6294ad324f8b7ee184fba5e0121efacbb314522a4d928f2705bf5
|
||||
checksum: 181d25e531c54185a4db2d6adfdd0b2d506aceee3e7fc9af5217c0038f1e6e291e5b093a45d570febce85210bdb58aa701fda6fa27004dcfb685608c215a0883
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
|
Loading…
Reference in New Issue