Compare commits
No commits in common. "da14bac9b2163add9b0781ca5ccf1de65537e149" and "5dee9aeed4a3c62b7662cf6a1bfac9cf74066b25" have entirely different histories.
da14bac9b2
...
5dee9aeed4
|
@ -8,6 +8,9 @@ import path from "path";
|
|||
import type { Logger } from "pino";
|
||||
|
||||
import { getHDKey, getSeed } from "../lib/seed.js";
|
||||
import pluginRpc from "./plugins/rpc";
|
||||
import pluginCore from "./plugins/core";
|
||||
import pluginDht from "./plugins/dht";
|
||||
import type Config from "@lumeweb/cfg";
|
||||
import EventEmitter2 from "eventemitter2";
|
||||
import log from "../log.js";
|
||||
|
@ -18,8 +21,6 @@ import {
|
|||
} from "./swarm.js";
|
||||
import { get as getSSl, SSLManager } from "./ssl.js";
|
||||
import type { HDKey } from "micro-ed25519-hdkey";
|
||||
import corePlugins from "../plugins";
|
||||
import Util from "./plugin/util";
|
||||
|
||||
let pluginAPIManager: PluginAPIManager;
|
||||
let pluginAPI: PluginAPI;
|
||||
|
@ -52,12 +53,6 @@ class PluginAPI extends EventEmitter2 {
|
|||
this._swarm = swarm;
|
||||
}
|
||||
|
||||
private _util: Util = new Util();
|
||||
|
||||
get util(): Util {
|
||||
return this._util;
|
||||
}
|
||||
|
||||
private _swarm: any;
|
||||
|
||||
get swarm(): any {
|
||||
|
@ -233,9 +228,9 @@ export function getPluginAPIManager(): PluginAPIManager {
|
|||
export async function loadPlugins() {
|
||||
const apiManager = getPluginAPIManager();
|
||||
|
||||
for (const plugin of corePlugins) {
|
||||
await apiManager.loadPluginInstance(plugin);
|
||||
}
|
||||
apiManager.loadPluginInstance(pluginCore);
|
||||
apiManager.loadPluginInstance(pluginRpc);
|
||||
apiManager.loadPluginInstance(pluginDht);
|
||||
|
||||
for (const plugin of [...new Set(config.array("plugins", []))] as []) {
|
||||
await apiManager.loadPlugin(plugin);
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
import Crypto from "./util/crypto";
|
||||
import b4a from "b4a";
|
||||
// @ts-ignore
|
||||
import c from "compact-encoding";
|
||||
|
||||
export default class Util {
|
||||
private _crypto: Crypto = new Crypto();
|
||||
|
||||
get crypto(): Crypto {
|
||||
return this._crypto;
|
||||
}
|
||||
get bufferEncoding(): typeof b4a {
|
||||
return b4a;
|
||||
}
|
||||
|
||||
get binaryEncoding(): typeof c {
|
||||
return c;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
// @ts-ignore
|
||||
import sodium from "sodium-universal";
|
||||
import { getPluginAPI } from "../../plugin";
|
||||
|
||||
export default class Crypto {
|
||||
createHash(data: string): Buffer {
|
||||
const b4a = getPluginAPI().util.bufferEncoding;
|
||||
const buffer = b4a.from(data);
|
||||
let hash = b4a.allocUnsafe(32) as Buffer;
|
||||
sodium.crypto_generichash(hash, buffer);
|
||||
|
||||
return hash;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import { Plugin, PluginAPI } from "@lumeweb/relay-types";
|
||||
import { getRpcServer } from "../rpc/server";
|
||||
|
||||
const plugin: Plugin = {
|
||||
name: "core",
|
|
@ -1,4 +1,5 @@
|
|||
import { Plugin, PluginAPI } from "@lumeweb/relay-types";
|
||||
import { getRpcServer } from "../rpc/server";
|
||||
import b4a from "b4a";
|
||||
|
||||
const plugin: Plugin = {
|
|
@ -1,3 +1,4 @@
|
|||
import { getRpcServer } from "../rpc/server";
|
||||
import {
|
||||
Plugin,
|
||||
PluginAPI,
|
||||
|
@ -7,13 +8,11 @@ import {
|
|||
RPCRequest,
|
||||
RPCResponse,
|
||||
} from "@lumeweb/relay-types";
|
||||
import { getRpcByPeer } from "../modules/rpc";
|
||||
import { get as getSwarm, LUMEWEB_TOPIC_HASH } from "../modules/swarm";
|
||||
import { getRpcByPeer } from "../rpc";
|
||||
import { get as getSwarm, LUMEWEB_TOPIC_HASH } from "../swarm";
|
||||
import b4a from "b4a";
|
||||
import pTimeout, { ClearablePromise } from "p-timeout";
|
||||
|
||||
let api: PluginAPI;
|
||||
|
||||
async function broadcastRequest(
|
||||
request: RPCRequest,
|
||||
relays: string[],
|
||||
|
@ -29,7 +28,7 @@ async function broadcastRequest(
|
|||
for (const relay of relays) {
|
||||
let req;
|
||||
if (b4a.equals(b4a.from(relay, "hex"), getSwarm().keyPair.publicKey)) {
|
||||
req = api.rpcServer.handleRequest(request);
|
||||
req = getRpcServer().handleRequest(request);
|
||||
} else {
|
||||
req = makeRequest(relay);
|
||||
}
|
||||
|
@ -48,8 +47,7 @@ async function broadcastRequest(
|
|||
|
||||
const plugin: Plugin = {
|
||||
name: "rpc",
|
||||
async plugin(_api: PluginAPI): Promise<void> {
|
||||
api = _api;
|
||||
async plugin(api: PluginAPI): Promise<void> {
|
||||
if (api.config.bool("cache")) {
|
||||
api.registerMethod("get_cached_item", {
|
||||
cacheable: false,
|
|
@ -1,7 +0,0 @@
|
|||
import core from "./core";
|
||||
import rpc from "./rpc";
|
||||
import dht from "./dht";
|
||||
|
||||
const corePlugins = [core, dht, rpc];
|
||||
|
||||
export default corePlugins;
|
|
@ -662,7 +662,7 @@ __metadata:
|
|||
|
||||
"@lumeweb/relay-types@https://git.lumeweb.com/LumeWeb/relay-types.git":
|
||||
version: 0.1.0
|
||||
resolution: "@lumeweb/relay-types@https://git.lumeweb.com/LumeWeb/relay-types.git#commit=4e460a182d93f6faf04f0d6bdd1c0a48c2eb0c71"
|
||||
resolution: "@lumeweb/relay-types@https://git.lumeweb.com/LumeWeb/relay-types.git#commit=0d6219837a743543f97eaf391895a6608e0fb7d5"
|
||||
dependencies:
|
||||
"@lumeweb/dht-cache": "https://git.lumeweb.com/LumeWeb/dht-cache.git"
|
||||
"@types/eventemitter2": "npm:^4.1.0"
|
||||
|
@ -670,7 +670,7 @@ __metadata:
|
|||
eventemitter2: "npm:^6.4.9"
|
||||
micro-ed25519-hdkey: "npm:^0.1.2"
|
||||
pino: "npm:^8.8.0"
|
||||
checksum: 85dc1fd5e15d84c219b220891204e3639f9ef544c61d05ce6dec3a0b542237b22c9f364b47b92c2be8bdc3159d5a3faddb46733dbdabc0c9823c018fa6f2bb4c
|
||||
checksum: b66513fa0735920f5df8d1f5c2325756293c68d63a7252ee7daf3740b3511c8981825c11e6bd345517769b28741f50045c3136a6e1aa1de2adbb408a12f37085
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
|
Loading…
Reference in New Issue