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 type { Logger } from "pino";
|
||||||
|
|
||||||
import { getHDKey, getSeed } from "../lib/seed.js";
|
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 type Config from "@lumeweb/cfg";
|
||||||
import EventEmitter2 from "eventemitter2";
|
import EventEmitter2 from "eventemitter2";
|
||||||
import log from "../log.js";
|
import log from "../log.js";
|
||||||
|
@ -18,8 +21,6 @@ import {
|
||||||
} from "./swarm.js";
|
} from "./swarm.js";
|
||||||
import { get as getSSl, SSLManager } from "./ssl.js";
|
import { get as getSSl, SSLManager } from "./ssl.js";
|
||||||
import type { HDKey } from "micro-ed25519-hdkey";
|
import type { HDKey } from "micro-ed25519-hdkey";
|
||||||
import corePlugins from "../plugins";
|
|
||||||
import Util from "./plugin/util";
|
|
||||||
|
|
||||||
let pluginAPIManager: PluginAPIManager;
|
let pluginAPIManager: PluginAPIManager;
|
||||||
let pluginAPI: PluginAPI;
|
let pluginAPI: PluginAPI;
|
||||||
|
@ -52,12 +53,6 @@ class PluginAPI extends EventEmitter2 {
|
||||||
this._swarm = swarm;
|
this._swarm = swarm;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _util: Util = new Util();
|
|
||||||
|
|
||||||
get util(): Util {
|
|
||||||
return this._util;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _swarm: any;
|
private _swarm: any;
|
||||||
|
|
||||||
get swarm(): any {
|
get swarm(): any {
|
||||||
|
@ -233,9 +228,9 @@ export function getPluginAPIManager(): PluginAPIManager {
|
||||||
export async function loadPlugins() {
|
export async function loadPlugins() {
|
||||||
const apiManager = getPluginAPIManager();
|
const apiManager = getPluginAPIManager();
|
||||||
|
|
||||||
for (const plugin of corePlugins) {
|
apiManager.loadPluginInstance(pluginCore);
|
||||||
await apiManager.loadPluginInstance(plugin);
|
apiManager.loadPluginInstance(pluginRpc);
|
||||||
}
|
apiManager.loadPluginInstance(pluginDht);
|
||||||
|
|
||||||
for (const plugin of [...new Set(config.array("plugins", []))] as []) {
|
for (const plugin of [...new Set(config.array("plugins", []))] as []) {
|
||||||
await apiManager.loadPlugin(plugin);
|
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 { Plugin, PluginAPI } from "@lumeweb/relay-types";
|
||||||
|
import { getRpcServer } from "../rpc/server";
|
||||||
|
|
||||||
const plugin: Plugin = {
|
const plugin: Plugin = {
|
||||||
name: "core",
|
name: "core",
|
|
@ -1,4 +1,5 @@
|
||||||
import { Plugin, PluginAPI } from "@lumeweb/relay-types";
|
import { Plugin, PluginAPI } from "@lumeweb/relay-types";
|
||||||
|
import { getRpcServer } from "../rpc/server";
|
||||||
import b4a from "b4a";
|
import b4a from "b4a";
|
||||||
|
|
||||||
const plugin: Plugin = {
|
const plugin: Plugin = {
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { getRpcServer } from "../rpc/server";
|
||||||
import {
|
import {
|
||||||
Plugin,
|
Plugin,
|
||||||
PluginAPI,
|
PluginAPI,
|
||||||
|
@ -7,13 +8,11 @@ import {
|
||||||
RPCRequest,
|
RPCRequest,
|
||||||
RPCResponse,
|
RPCResponse,
|
||||||
} from "@lumeweb/relay-types";
|
} from "@lumeweb/relay-types";
|
||||||
import { getRpcByPeer } from "../modules/rpc";
|
import { getRpcByPeer } from "../rpc";
|
||||||
import { get as getSwarm, LUMEWEB_TOPIC_HASH } from "../modules/swarm";
|
import { get as getSwarm, LUMEWEB_TOPIC_HASH } from "../swarm";
|
||||||
import b4a from "b4a";
|
import b4a from "b4a";
|
||||||
import pTimeout, { ClearablePromise } from "p-timeout";
|
import pTimeout, { ClearablePromise } from "p-timeout";
|
||||||
|
|
||||||
let api: PluginAPI;
|
|
||||||
|
|
||||||
async function broadcastRequest(
|
async function broadcastRequest(
|
||||||
request: RPCRequest,
|
request: RPCRequest,
|
||||||
relays: string[],
|
relays: string[],
|
||||||
|
@ -29,7 +28,7 @@ async function broadcastRequest(
|
||||||
for (const relay of relays) {
|
for (const relay of relays) {
|
||||||
let req;
|
let req;
|
||||||
if (b4a.equals(b4a.from(relay, "hex"), getSwarm().keyPair.publicKey)) {
|
if (b4a.equals(b4a.from(relay, "hex"), getSwarm().keyPair.publicKey)) {
|
||||||
req = api.rpcServer.handleRequest(request);
|
req = getRpcServer().handleRequest(request);
|
||||||
} else {
|
} else {
|
||||||
req = makeRequest(relay);
|
req = makeRequest(relay);
|
||||||
}
|
}
|
||||||
|
@ -48,8 +47,7 @@ async function broadcastRequest(
|
||||||
|
|
||||||
const plugin: Plugin = {
|
const plugin: Plugin = {
|
||||||
name: "rpc",
|
name: "rpc",
|
||||||
async plugin(_api: PluginAPI): Promise<void> {
|
async plugin(api: PluginAPI): Promise<void> {
|
||||||
api = _api;
|
|
||||||
if (api.config.bool("cache")) {
|
if (api.config.bool("cache")) {
|
||||||
api.registerMethod("get_cached_item", {
|
api.registerMethod("get_cached_item", {
|
||||||
cacheable: false,
|
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":
|
"@lumeweb/relay-types@https://git.lumeweb.com/LumeWeb/relay-types.git":
|
||||||
version: 0.1.0
|
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:
|
dependencies:
|
||||||
"@lumeweb/dht-cache": "https://git.lumeweb.com/LumeWeb/dht-cache.git"
|
"@lumeweb/dht-cache": "https://git.lumeweb.com/LumeWeb/dht-cache.git"
|
||||||
"@types/eventemitter2": "npm:^4.1.0"
|
"@types/eventemitter2": "npm:^4.1.0"
|
||||||
|
@ -670,7 +670,7 @@ __metadata:
|
||||||
eventemitter2: "npm:^6.4.9"
|
eventemitter2: "npm:^6.4.9"
|
||||||
micro-ed25519-hdkey: "npm:^0.1.2"
|
micro-ed25519-hdkey: "npm:^0.1.2"
|
||||||
pino: "npm:^8.8.0"
|
pino: "npm:^8.8.0"
|
||||||
checksum: 85dc1fd5e15d84c219b220891204e3639f9ef544c61d05ce6dec3a0b542237b22c9f364b47b92c2be8bdc3159d5a3faddb46733dbdabc0c9823c018fa6f2bb4c
|
checksum: b66513fa0735920f5df8d1f5c2325756293c68d63a7252ee7daf3740b3511c8981825c11e6bd345517769b28741f50045c3136a6e1aa1de2adbb408a12f37085
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue