Compare commits

..

No commits in common. "a2055079d181f1238654bbbc6e1a35d61e2eba4b" and "c1e474e02551c23630bed9f49db2b2885e8c7f45" have entirely different histories.

6 changed files with 57 additions and 41 deletions

62
package-lock.json generated
View File

@ -30,14 +30,15 @@
"loady": "github:LumeWeb/loady", "loady": "github:LumeWeb/loady",
"msgpackr": "^1.8.5", "msgpackr": "^1.8.5",
"node-cache": "^5.1.2", "node-cache": "^5.1.2",
"node-cron": "^3.0.2",
"node-fetch": "^2.6.9", "node-fetch": "^2.6.9",
"p-defer": "^4.0.0",
"p-timeout": "git+https://git.lumeweb.com/LumeWeb/p-timeout.git", "p-timeout": "git+https://git.lumeweb.com/LumeWeb/p-timeout.git",
"pino": "^8.11.0", "pino": "^8.11.0",
"pino-pretty": "^9.4.0", "pino-pretty": "^9.4.0",
"promise-retry": "^2.0.1", "promise-retry": "^2.0.1",
"protomux": "^3.4.1", "protomux": "^3.4.1",
"protomux-rpc": "^1.3.0", "protomux-rpc": "^1.3.0",
"random-access-memory": "^4.1.0",
"random-key": "^0.3.2", "random-key": "^0.3.2",
"slugify": "^1.6.6", "slugify": "^1.6.6",
"sodium-universal": "^4.0.0" "sodium-universal": "^4.0.0"
@ -4335,6 +4336,14 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/is-options": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/is-options/-/is-options-1.0.2.tgz",
"integrity": "sha512-u+Ai74c8Q74aS8BuHwPdI1jptGOT1FQXgCq8/zv0xRuE+wRgSMEJLj8lVO8Zp9BeGb29BXY6AsNPinfqjkr7Fg==",
"dependencies": {
"b4a": "^1.1.1"
}
},
"node_modules/is-plain-obj": { "node_modules/is-plain-obj": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz", "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz",
@ -5396,6 +5405,17 @@
"node": ">= 8.0.0" "node": ">= 8.0.0"
} }
}, },
"node_modules/node-cron": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.2.tgz",
"integrity": "sha512-iP8l0yGlNpE0e6q1o185yOApANRe47UPbLf4YxfbiNHt/RU5eBcGB/e0oudruheSf+LQeDMezqC5BVAb5wwRcQ==",
"dependencies": {
"uuid": "8.3.2"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/node-domexception": { "node_modules/node-domexception": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
@ -8622,17 +8642,6 @@
"resolved": "https://registry.npmjs.org/ordered-object/-/ordered-object-0.2.3.tgz", "resolved": "https://registry.npmjs.org/ordered-object/-/ordered-object-0.2.3.tgz",
"integrity": "sha512-UKBtJiO7PsKqAAenewZ/moHQIRbcjZ4HE0J/+RyzgnpCTIn5ZLe3N2izno1kViTCXtHB4xuewjPgYLEiuS6t5A==" "integrity": "sha512-UKBtJiO7PsKqAAenewZ/moHQIRbcjZ4HE0J/+RyzgnpCTIn5ZLe3N2izno1kViTCXtHB4xuewjPgYLEiuS6t5A=="
}, },
"node_modules/p-defer": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/p-defer/-/p-defer-4.0.0.tgz",
"integrity": "sha512-Vb3QRvQ0Y5XnF40ZUWW7JfLogicVh/EnA5gBIvKDJoYpeI82+1E3AlB9yOcKFS0AhHrWVnAQO39fbR0G99IVEQ==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/p-each-series": { "node_modules/p-each-series": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/p-each-series/-/p-each-series-3.0.0.tgz", "resolved": "https://registry.npmjs.org/p-each-series/-/p-each-series-3.0.0.tgz",
@ -9353,6 +9362,27 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/random-access-memory": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/random-access-memory/-/random-access-memory-4.1.0.tgz",
"integrity": "sha512-vVt75UQpWcaZWlysSmk7isqdhiV10WCovxuKZmBKg5zSsiEXIclJmAlIsMr8usYqfFmXzOGIonWOAyR5u3jhXQ==",
"dependencies": {
"b4a": "^1.1.0",
"inherits": "^2.0.3",
"is-options": "^1.0.1",
"random-access-storage": "^1.1.1"
}
},
"node_modules/random-access-storage": {
"version": "1.4.3",
"resolved": "https://registry.npmjs.org/random-access-storage/-/random-access-storage-1.4.3.tgz",
"integrity": "sha512-D5e2iIC5dNENWyBxsjhEnNOMCwZZ64TARK6dyMN+3g4OTC4MJxyjh9hKLjTGoNhDOPrgjI+YlFEHFnrp/cSnzQ==",
"dependencies": {
"events": "^3.3.0",
"inherits": "^2.0.3",
"queue-tick": "^1.0.0"
}
},
"node_modules/random-key": { "node_modules/random-key": {
"version": "0.3.2", "version": "0.3.2",
"resolved": "https://registry.npmjs.org/random-key/-/random-key-0.3.2.tgz", "resolved": "https://registry.npmjs.org/random-key/-/random-key-0.3.2.tgz",
@ -10925,6 +10955,14 @@
"integrity": "sha512-mLs5zAK+ctllYBj+iAQvlDCwoxU/WDOUaJkcFudeiAX6OajC6BKXJUa9a+tbtkC11dz2Ufb7h0lyvIOVn4LADA==", "integrity": "sha512-mLs5zAK+ctllYBj+iAQvlDCwoxU/WDOUaJkcFudeiAX6OajC6BKXJUa9a+tbtkC11dz2Ufb7h0lyvIOVn4LADA==",
"dev": true "dev": true
}, },
"node_modules/uuid": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
"bin": {
"uuid": "dist/bin/uuid"
}
},
"node_modules/validate-npm-package-license": { "node_modules/validate-npm-package-license": {
"version": "3.0.4", "version": "3.0.4",
"resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz",

View File

@ -42,7 +42,6 @@
"msgpackr": "^1.8.5", "msgpackr": "^1.8.5",
"node-cache": "^5.1.2", "node-cache": "^5.1.2",
"node-fetch": "^2.6.9", "node-fetch": "^2.6.9",
"p-defer": "^4.0.0",
"p-timeout": "git+https://git.lumeweb.com/LumeWeb/p-timeout.git", "p-timeout": "git+https://git.lumeweb.com/LumeWeb/p-timeout.git",
"pino": "^8.11.0", "pino": "^8.11.0",
"pino-pretty": "^9.4.0", "pino-pretty": "^9.4.0",

View File

@ -7,24 +7,16 @@ import { errorExit } from "../lib/error.js";
import stringify from "json-stable-stringify"; import stringify from "json-stable-stringify";
import { import {
getRpcServer, getRpcServer,
RPC_PROTOCOL_ID,
RPC_PROTOCOL_SYMBOL, RPC_PROTOCOL_SYMBOL,
setupStream, setupStream,
} from "./rpc/server.js"; } from "./rpc/server.js";
import { get as getSwarm, SecretStream } from "./swarm.js"; import { get as getSwarm, SecretStream } from "./swarm.js";
import b4a from "b4a"; import b4a from "b4a";
// @ts-ignore
import Protomux from "protomux";
export async function start() { export async function start() {
getSwarm().on("connection", (stream: SecretStream) => { getSwarm().on("connection", (stream: SecretStream) =>
Protomux.from(stream).pair( getRpcServer().setup(stream)
{ protocol: "protomux-rpc", id: RPC_PROTOCOL_ID }, );
async () => {
getRpcServer().setup(stream);
}
);
});
} }
export async function getRpcByPeer(peer: Buffer | string) { export async function getRpcByPeer(peer: Buffer | string) {
@ -38,16 +30,15 @@ export async function getRpcByPeer(peer: Buffer | string) {
} }
return new Promise((resolve) => { return new Promise((resolve) => {
const listener = (peer: any, info: any) => { const listener = () => {};
swarm.on("connection", (peer: any, info: any) => {
if (info.publicKey.toString("hex") !== peer.toString("hex")) { if (info.publicKey.toString("hex") !== peer.toString("hex")) {
return; return;
} }
swarm.removeListener("connection", listener); swarm.removeListener("connection", listener);
resolve(setupStream(peer)); resolve(setupStream(peer));
}; });
swarm.on("connection", listener);
swarm.joinPeer(peer); swarm.joinPeer(peer);
}); });

View File

@ -21,7 +21,7 @@ import jsonStringify from "json-stringify-deterministic";
const sodium = require("sodium-universal"); const sodium = require("sodium-universal");
let server: RPCServer; let server: RPCServer;
export const RPC_PROTOCOL_ID = b4a.from("lumeweb"); const RPC_PROTOCOL_ID = b4a.from("lumeweb");
export const RPC_PROTOCOL_SYMBOL = Symbol.for(RPC_PROTOCOL_ID.toString()); export const RPC_PROTOCOL_SYMBOL = Symbol.for(RPC_PROTOCOL_ID.toString());
export function getRpcServer(): RPCServer { export function getRpcServer(): RPCServer {

View File

@ -69,9 +69,6 @@ export class ProtocolManager {
this._swarm = swarm; this._swarm = swarm;
this._swarm.on("connection", (peer: any) => { this._swarm.on("connection", (peer: any) => {
if (!peer.userData) {
peer.userData = null;
}
for (const protocol of this._protocols) { for (const protocol of this._protocols) {
Protomux.from(peer).pair( Protomux.from(peer).pair(
{ protocol: protocol[0] }, { protocol: protocol[0] },

View File

@ -1,15 +1,8 @@
import { Plugin, PluginAPI } from "@lumeweb/interface-relay"; import { Plugin, PluginAPI } from "@lumeweb/interface-relay";
import defer from "p-defer";
const plugin: Plugin = { const plugin: Plugin = {
name: "core", name: "core",
async plugin(api: PluginAPI): Promise<void> { async plugin(api: PluginAPI): Promise<void> {
const pluginsLoaded = defer();
api.once("core.pluginsLoaded", () => {
pluginsLoaded.resolve();
});
api.registerMethod("ping", { api.registerMethod("ping", {
cacheable: false, cacheable: false,
async handler(): Promise<any> { async handler(): Promise<any> {
@ -20,8 +13,6 @@ const plugin: Plugin = {
api.registerMethod("get_methods", { api.registerMethod("get_methods", {
cacheable: false, cacheable: false,
async handler(): Promise<any> { async handler(): Promise<any> {
await pluginsLoaded.promise;
return api.rpcServer.getMethods(); return api.rpcServer.getMethods();
}, },
}); });