Compare commits
8 Commits
c1e474e025
...
a2055079d1
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | a2055079d1 | |
Derrick Hammer | 6964c6bed2 | |
Derrick Hammer | 2b12150d71 | |
Derrick Hammer | 556373c5bc | |
Derrick Hammer | a003da1606 | |
Derrick Hammer | 58e95806d0 | |
Derrick Hammer | 3600fbfdcf | |
Derrick Hammer | 2d30390fa2 |
|
@ -30,15 +30,14 @@
|
|||
"loady": "github:LumeWeb/loady",
|
||||
"msgpackr": "^1.8.5",
|
||||
"node-cache": "^5.1.2",
|
||||
"node-cron": "^3.0.2",
|
||||
"node-fetch": "^2.6.9",
|
||||
"p-defer": "^4.0.0",
|
||||
"p-timeout": "git+https://git.lumeweb.com/LumeWeb/p-timeout.git",
|
||||
"pino": "^8.11.0",
|
||||
"pino-pretty": "^9.4.0",
|
||||
"promise-retry": "^2.0.1",
|
||||
"protomux": "^3.4.1",
|
||||
"protomux-rpc": "^1.3.0",
|
||||
"random-access-memory": "^4.1.0",
|
||||
"random-key": "^0.3.2",
|
||||
"slugify": "^1.6.6",
|
||||
"sodium-universal": "^4.0.0"
|
||||
|
@ -4336,14 +4335,6 @@
|
|||
"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": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz",
|
||||
|
@ -5405,17 +5396,6 @@
|
|||
"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": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
|
||||
|
@ -8642,6 +8622,17 @@
|
|||
"resolved": "https://registry.npmjs.org/ordered-object/-/ordered-object-0.2.3.tgz",
|
||||
"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": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-each-series/-/p-each-series-3.0.0.tgz",
|
||||
|
@ -9362,27 +9353,6 @@
|
|||
"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": {
|
||||
"version": "0.3.2",
|
||||
"resolved": "https://registry.npmjs.org/random-key/-/random-key-0.3.2.tgz",
|
||||
|
@ -10955,14 +10925,6 @@
|
|||
"integrity": "sha512-mLs5zAK+ctllYBj+iAQvlDCwoxU/WDOUaJkcFudeiAX6OajC6BKXJUa9a+tbtkC11dz2Ufb7h0lyvIOVn4LADA==",
|
||||
"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": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz",
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
"msgpackr": "^1.8.5",
|
||||
"node-cache": "^5.1.2",
|
||||
"node-fetch": "^2.6.9",
|
||||
"p-defer": "^4.0.0",
|
||||
"p-timeout": "git+https://git.lumeweb.com/LumeWeb/p-timeout.git",
|
||||
"pino": "^8.11.0",
|
||||
"pino-pretty": "^9.4.0",
|
||||
|
|
|
@ -7,16 +7,24 @@ import { errorExit } from "../lib/error.js";
|
|||
import stringify from "json-stable-stringify";
|
||||
import {
|
||||
getRpcServer,
|
||||
RPC_PROTOCOL_ID,
|
||||
RPC_PROTOCOL_SYMBOL,
|
||||
setupStream,
|
||||
} from "./rpc/server.js";
|
||||
import { get as getSwarm, SecretStream } from "./swarm.js";
|
||||
import b4a from "b4a";
|
||||
// @ts-ignore
|
||||
import Protomux from "protomux";
|
||||
|
||||
export async function start() {
|
||||
getSwarm().on("connection", (stream: SecretStream) =>
|
||||
getRpcServer().setup(stream)
|
||||
);
|
||||
getSwarm().on("connection", (stream: SecretStream) => {
|
||||
Protomux.from(stream).pair(
|
||||
{ protocol: "protomux-rpc", id: RPC_PROTOCOL_ID },
|
||||
async () => {
|
||||
getRpcServer().setup(stream);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export async function getRpcByPeer(peer: Buffer | string) {
|
||||
|
@ -30,15 +38,16 @@ export async function getRpcByPeer(peer: Buffer | string) {
|
|||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const listener = () => {};
|
||||
swarm.on("connection", (peer: any, info: any) => {
|
||||
const listener = (peer: any, info: any) => {
|
||||
if (info.publicKey.toString("hex") !== peer.toString("hex")) {
|
||||
return;
|
||||
}
|
||||
swarm.removeListener("connection", listener);
|
||||
|
||||
resolve(setupStream(peer));
|
||||
});
|
||||
};
|
||||
|
||||
swarm.on("connection", listener);
|
||||
|
||||
swarm.joinPeer(peer);
|
||||
});
|
||||
|
|
|
@ -21,7 +21,7 @@ import jsonStringify from "json-stringify-deterministic";
|
|||
const sodium = require("sodium-universal");
|
||||
let server: RPCServer;
|
||||
|
||||
const RPC_PROTOCOL_ID = b4a.from("lumeweb");
|
||||
export const RPC_PROTOCOL_ID = b4a.from("lumeweb");
|
||||
export const RPC_PROTOCOL_SYMBOL = Symbol.for(RPC_PROTOCOL_ID.toString());
|
||||
|
||||
export function getRpcServer(): RPCServer {
|
||||
|
|
|
@ -69,6 +69,9 @@ export class ProtocolManager {
|
|||
this._swarm = swarm;
|
||||
|
||||
this._swarm.on("connection", (peer: any) => {
|
||||
if (!peer.userData) {
|
||||
peer.userData = null;
|
||||
}
|
||||
for (const protocol of this._protocols) {
|
||||
Protomux.from(peer).pair(
|
||||
{ protocol: protocol[0] },
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
import { Plugin, PluginAPI } from "@lumeweb/interface-relay";
|
||||
|
||||
import defer from "p-defer";
|
||||
|
||||
const plugin: Plugin = {
|
||||
name: "core",
|
||||
async plugin(api: PluginAPI): Promise<void> {
|
||||
const pluginsLoaded = defer();
|
||||
api.once("core.pluginsLoaded", () => {
|
||||
pluginsLoaded.resolve();
|
||||
});
|
||||
|
||||
api.registerMethod("ping", {
|
||||
cacheable: false,
|
||||
async handler(): Promise<any> {
|
||||
|
@ -13,6 +20,8 @@ const plugin: Plugin = {
|
|||
api.registerMethod("get_methods", {
|
||||
cacheable: false,
|
||||
async handler(): Promise<any> {
|
||||
await pluginsLoaded.promise;
|
||||
|
||||
return api.rpcServer.getMethods();
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue