Compare commits

..

79 Commits

Author SHA1 Message Date
Derrick Hammer e2a71f6851
fix: add stream setKeepAlive for rpc connections 2023-07-23 15:03:35 -04:00
Derrick Hammer 05c0004623
dep: update @lumeweb/relay-cfg 2023-07-07 10:15:38 -04:00
Derrick Hammer 84d440276f
dep: update @lumeweb/relay-cfg 2023-07-07 10:09:43 -04:00
Derrick Hammer f40f0a553f
dep: update @lumeweb/relay-cfg 2023-07-07 10:00:36 -04:00
Derrick Hammer 2cd980abf1
dep: update @lumeweb/relay-cfg 2023-07-07 09:54:00 -04:00
Derrick Hammer d9abdfd0d9
Merge remote-tracking branch 'origin/develop' into develop 2023-07-07 09:38:30 -04:00
Derrick Hammer f5511a93b3
ci: delete circleci config 2023-07-07 09:38:16 -04:00
Derrick Hammer 34ddaf59e7
dep: update @lumeweb/relay-cfg 2023-07-07 09:22:51 -04:00
Derrick Hammer 5a63df0f50
fix: add typecasts 2023-07-07 09:11:16 -04:00
Derrick Hammer 641db83b42
fix: update import 2023-07-07 09:08:16 -04:00
Derrick Hammer 6d31f50579
fix: add patch for @lumeweb/interface-relay 2023-07-07 09:06:51 -04:00
Derrick Hammer d0c80f36f6
dep: update @lumeweb/interface-relay 2023-07-07 09:05:14 -04:00
Derrick Hammer 1976659633
fix: use exports from package 2023-07-07 08:38:56 -04:00
Derrick Hammer 4ac844d509
ci: change moduleResolution to nodenext 2023-07-07 08:34:34 -04:00
Derrick Hammer 5b7dc6cf00
fix: update import 2023-07-07 08:21:13 -04:00
Derrick Hammer b7f76970f7
dep: update @lumeweb/cfg and @lumeweb/interface-relay 2023-07-07 08:19:04 -04:00
semantic-release-bot 1c752bb964 chore(release): 0.1.0-develop.2 [skip ci]
# [0.1.0-develop.2](https://git.lumeweb.com/LumeWeb/relay/compare/v0.1.0-develop.1...v0.1.0-develop.2) (2023-07-06)

### Bug Fixes

* fastify needs register to be awaited, connection binaryType set to nodebuffer after hyper setup, and no http2 ([d1c79ac](d1c79acd72))
* need to pass the dht property to dht-relay ([7cb443f](7cb443f62b))
2023-07-06 17:27:52 +00:00
Derrick Hammer f0e724e8dc
dep: update protomux-rpc 2023-07-06 13:25:57 -04:00
Derrick Hammer 7cb443f62b
fix: need to pass the dht property to dht-relay 2023-07-06 13:25:33 -04:00
Derrick Hammer d1c79acd72
fix: fastify needs register to be awaited, connection binaryType set to nodebuffer after hyper setup, and no http2 2023-07-04 00:52:35 -04:00
Derrick Hammer 7e17b477bd
refactor: add new setting core.relayPort to override core.port for reverse proxies. core.port will be used by plugins, but core.relayPort may be used by core 2023-07-04 00:51:39 -04:00
Derrick Hammer ca7ba89dd7
dep: update fastify 2023-07-04 00:49:47 -04:00
Derrick Hammer 2825edf12f
build: move to new circle-ci-publish repo 2023-04-23 18:13:10 -04:00
Derrick Hammer 7b85edd263
ci: fix cloudsmith commands, include focal and jammy 2023-04-23 09:29:40 -04:00
semantic-release-bot 33f0b4c6d0 chore(release): 0.1.0-develop.1 [skip ci]
# [0.1.0-develop.1](https://git.lumeweb.com/LumeWeb/relay/compare/v0.0.1...v0.1.0-develop.1) (2023-04-23)

### Bug Fixes

* change ed25519-keygen import ([7ec8bb7](7ec8bb79db))
* update import ([c7f0dd5](c7f0dd586d))

### Features

* We are triggering a dummy feature commit for all past breaking changes and prototyping ([23f9e0f](23f9e0f6bd))

### Reverts

* Revert "*Need to use dynamic import" ([d288685](d28868508b))
* Revert "*Need to return dynamic function and execute it" ([485fa98](485fa98f0e))
* Revert "*Temp disable steps, debug" ([d83af7b](d83af7bf1a))
2023-04-23 13:16:29 +00:00
Derrick Hammer 062f5c9899
ci: need to install python pip and access as pip2 2023-04-23 09:13:27 -04:00
Derrick Hammer 47f768b20b
ci: need sudo on go install, chmod it, then access it directly 2023-04-23 09:10:31 -04:00
Derrick Hammer c08e130e97
ci: ci already has yq 2023-04-23 09:02:44 -04:00
Derrick Hammer ec43f49562
ci: update publish script to install golang if needed 2023-04-23 08:46:12 -04:00
Derrick Hammer 93c110c755
ci: move setup job to be steps under the setup in node/run 2023-04-23 08:35:53 -04:00
Derrick Hammer a0d33d3880
ci: add context 2023-04-23 08:30:07 -04:00
Derrick Hammer 382761e484
ci: add credijusto/ssh orb to setup git server in known hosts 2023-04-23 08:28:18 -04:00
Derrick Hammer 188f7986b6
ci: remove github actions 2023-04-23 08:15:40 -04:00
Derrick Hammer e317a3209d
build: switch to fork for cjs 2023-04-23 08:09:37 -04:00
Derrick Hammer f1ca174022
ci: need to use patch-package to remove the files element from sodium-native so pkg does not choke 2023-04-23 07:57:34 -04:00
Derrick Hammer f7ba77e04f
ci: set job names and have release depend on build 2023-04-23 07:26:43 -04:00
Derrick Hammer e933cbe918
ci: update fingerprint 2023-04-23 07:23:32 -04:00
Derrick Hammer 20543a0612
ci: switch to cimg/node:lts 2023-04-23 07:22:19 -04:00
Derrick Hammer 52c209dbb9
ci: rewrite ci 2023-04-23 07:10:48 -04:00
Derrick Hammer 4f920d6958
ci: setup circle ci 2023-04-23 06:30:32 -04:00
Derrick Hammer 69e999aef5
ci: debug 2023-04-21 22:34:44 -04:00
Derrick Hammer 533e741c15
Revert "ci: try switching to building node"
This reverts commit 9f07b21566.
2023-04-21 21:03:39 -04:00
Derrick Hammer 9f07b21566
ci: try switching to building node 2023-04-21 20:16:55 -04:00
Derrick Hammer d5f78e4d27
build: fix compile script 2023-04-21 19:35:44 -04:00
Derrick Hammer 6c9fe8208a
ci: add exec plugin and call new publish script to deploy deb to package repo 2023-04-21 19:31:57 -04:00
Derrick Hammer 23f9e0f6bd
feat: We are triggering a dummy feature commit for all past breaking changes and prototyping 2023-04-21 18:42:49 -04:00
Derrick Hammer b39d0dd7e7
ci: change repo url to be the ssh version so that semantic-version properly handles it 2023-04-21 04:01:50 -04:00
Derrick Hammer 00837eb143
ci: add build step 2023-04-21 04:01:08 -04:00
Derrick Hammer 2dafa592ed
ci: remove unneeded env vars 2023-04-21 04:00:58 -04:00
Derrick Hammer 7b78e882d8
ci: add @semantic-release/git 2023-04-20 05:32:15 -04:00
Derrick Hammer 1350929bca
ci: update git remote command 2023-04-20 03:53:15 -04:00
Derrick Hammer 3d64870f17
cleanup: remove unused imports 2023-04-19 23:31:36 -04:00
Derrick Hammer a2055079d1
refactor: use p-defer 2023-04-19 23:29:49 -04:00
Derrick Hammer 6964c6bed2
Merge remote-tracking branch 'origin/wip' into develop 2023-04-19 23:26:50 -04:00
Derrick Hammer c1e474e025
build: setup semantic release and switch to github actions 2023-04-19 23:21:15 -04:00
Derrick Hammer 0ebd876c67
chore: remove unneeded deps 2023-04-19 23:08:26 -04:00
Derrick Hammer c7e0e23950
style: use casing in option names for readability 2023-04-19 18:42:23 -04:00
Derrick Hammer b6a6bdc97f
build: we don't need any assets added anymore for now 2023-04-19 18:40:49 -04:00
Derrick Hammer d06575e9ee
refactor: use fork of ed25519-keygen 2023-04-19 18:40:27 -04:00
Derrick Hammer ddc93ba71e
build: switch back to npm 2023-04-19 18:39:50 -04:00
Derrick Hammer 7ec8bb79db
fix: change ed25519-keygen import 2023-04-19 18:39:11 -04:00
Derrick Hammer 1bd466cc20
build: add micro-packed fork that uses cjs 2023-04-19 06:01:25 -04:00
Derrick Hammer 2e3fe286f9
chore: remove packageManager 2023-04-19 05:59:22 -04:00
Derrick Hammer 3facaddae8
chore: remove resolutions 2023-04-19 05:58:36 -04:00
Derrick Hammer abafc1c715
build: update build scripts 2023-04-19 05:33:42 -04:00
Derrick Hammer 6621f25b5e
build: add more packages to hoist 2023-04-19 05:32:57 -04:00
Derrick Hammer 6d2cffd869
build: add .npmrc 2023-04-19 05:27:29 -04:00
Derrick Hammer b3fb59d283
chore: update deps 2023-04-19 05:23:16 -04:00
Derrick Hammer c7f0dd586d
fix: update import 2023-04-19 05:16:20 -04:00
Derrick Hammer c6d4ea5a8e
refactor: switch to @lumeweb/interface-relay 2023-04-19 05:15:58 -04:00
Derrick Hammer c25bf102fe
refactor: switch to ed25519-keygen 2023-04-19 05:10:36 -04:00
Derrick Hammer 79f981d789
chore: clean up package.json 2023-04-19 05:01:00 -04:00
Derrick Hammer 0736469296
refactor: removing rpc methods that require caching 2023-04-19 04:47:48 -04:00
Derrick Hammer 2b12150d71
*Backwards compat fix to ensure Protomux is stored on the stream 2023-04-07 20:52:49 -04:00
Derrick Hammer 556373c5bc
*Ensure we use Protomux pair for the RPC service 2023-04-07 20:52:23 -04:00
Derrick Hammer a003da1606
*Remove debug logging 2023-03-29 17:16:13 -04:00
Derrick Hammer 58e95806d0
*hook on core.pluginsLoaded to ensure that we don't answer until all plugins are loaded 2023-03-29 16:23:56 -04:00
Derrick Hammer 3600fbfdcf
*await on plugin loading 2023-03-29 16:23:17 -04:00
Derrick Hammer 2d30390fa2
*fix listener callback 2023-03-18 15:07:52 -04:00
23 changed files with 11548 additions and 4797 deletions

4
.npmrc Normal file
View File

@ -0,0 +1,4 @@
public-hoist-pattern[]=udx-native
public-hoist-pattern[]=sodium-native
public-hoist-pattern[]=@hyperswarm/dht
public-hoist-pattern[]=hypercore-crypto

38
.releaserc Normal file
View File

@ -0,0 +1,38 @@
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
[
"@semantic-release/exec",
{
"publishCmd": "git clone https://git.lumeweb.com/LumeWeb/circle-ci-publish.git ci; ./ci/publish.sh \"${nextRelease.version}\""
}
],
[
"@semantic-release/npm",
{
"npmPublish": false
}
],
[
"@semantic-release/git",
{
"assets": [
"package.json"
]
}
]
],
"branches": [
"master",
{
name: "develop",
prerelease: true
},
{
name: "develop-*",
prerelease: true
},
]
}

View File

@ -1,49 +0,0 @@
pipeline:
build:
image: git.lumeweb.com/lumeweb/ci-node
commands:
- corepack enable
- corepack prepare yarn@stable --activate
- yarn
- yarn build
package:
image: ghcr.io/goreleaser/nfpm
commands:
- nfpm pkg --packager deb
publish_focal:
image: git.lumeweb.com/lumeweb/aptly-publisher
settings:
apt_username:
from_secret: APT_USERNAME
apt_password:
from_secret: APT_PASSWORD
repo: apt.web3relay.io
folder: ubuntu
distro: focal
gpg_password:
from_secret: GPG_PASSWORD
publish_jammy:
image: git.lumeweb.com/lumeweb/aptly-publisher
settings:
apt_username:
from_secret: APT_USERNAME
apt_password:
from_secret: APT_PASSWORD
repo: apt.web3relay.io
folder: ubuntu
distro: jammy
gpg_password:
from_secret: GPG_PASSWORD
purge_do_cdn:
image: git.lumeweb.com/lumeweb/do-cdn-purge
settings:
DIGITALOCEAN_ACCESS_TOKEN:
from_secret: digitalocean_access_token
DIGITALOCEAN_CDN_ID:
from_secret: digitalocean_cdn_id
purge_cf_cdn:
image: git.lumeweb.com/lumeweb/cf-cdn-purge
settings:
CLOUDFLARE_ACCESS_TOKEN:
from_secret: cloudflare_access_token
DOMAIN: web3relay.io

View File

@ -1,18 +0,0 @@
diff --git a/index.js b/index.js
index dc628dab1a201e6679a1716b3d51b56e4723b49d..9daeb44298586d51d7bb6e859a1dd696846e0078 100644
--- a/index.js
+++ b/index.js
@@ -115,11 +115,11 @@ class HDKey {
});
}
sign(message) {
- message = ensureBytes(message, 32);
+ message = ensureBytes(message);
return ed25519.sync.sign(message, this.privateKey);
}
verify(message, signature) {
- message = ensureBytes(message, 32);
+ message = ensureBytes(message);
signature = ensureBytes(signature, 64);
return ed25519.sync.verify(signature, message, this.publicKeyRaw);
}

View File

@ -1 +0,0 @@
nodeLinker: node-modules

11363
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,79 +1,75 @@
{ {
"name": "@lumeweb/relay", "name": "@lumeweb/relay",
"type": "commonjs", "type": "commonjs",
"version": "0.1.0", "version": "0.1.0-develop.2",
"description": "", "description": "",
"main": "build/index.js", "main": "build/index.js",
"types": "src/types.ts", "repository": {
"url": "gitea@git.lumeweb.com:LumeWeb/relay.git"
},
"author": { "author": {
"name": "Derrick Hammer", "name": "Derrick Hammer",
"email": "contact@lumeweb.com" "email": "contact@lumeweb.com"
}, },
"scripts": { "scripts": {
"compile": "yarn tsc", "semantic-release": "semantic-release",
"compile": "tsc",
"prebuild": "bash prebuild.sh", "prebuild": "bash prebuild.sh",
"package": "yarn pkg -c pkg.json build/index.js -t linux --public --no-native-build -C gzip", "package": "pkg -c pkg.json build/index.js -t linux --public --no-native-build -C gzip",
"package-debug": "yarn pkg -c pkg.json build/index.js -b -t linux --no-bytecode --public", "build": "npm run compile && npm run prebuild && npm run package",
"build": "yarn run compile && npm run prebuild && npm run package", "postinstall": "patch-package"
"barebuild": "yarn run compile && npm run package"
}, },
"dependencies": { "dependencies": {
"@fastify/websocket": "^7.1.1", "@fastify/websocket": "^8.1.0",
"@hyperswarm/dht-relay": "^0.3.0", "@hyperswarm/dht-relay": "^0.4.0",
"@lumeweb/cfg": "https://git.lumeweb.com/LumeWeb/cfg.git", "@lumeweb/interface-relay": "^0.0.2-develop.3",
"@lumeweb/dht-cache": "https://git.lumeweb.com/LumeWeb/dht-cache.git", "@lumeweb/relay-cfg": "^0.1.15",
"@scure/bip39": "^1.1.0", "@scure/bip39": "^1.2.0",
"@types/acme-client": "^3.3.0", "@types/node": "^18.15.11",
"@types/node": "^18.0.0", "@types/ws": "^8.5.4",
"@types/node-cron": "^3.0.2",
"@types/ws": "^8.5.3",
"ajv": "^8.11.0",
"async-mutex": "^0.3.2", "async-mutex": "^0.3.2",
"b4a": "^1.6.1", "b4a": "^1.6.3",
"compact-encoding": "^2.11.0", "compact-encoding": "^2.11.0",
"date-fns": "^2.28.0", "dotenv": "^16.0.3",
"dotenv": "^16.0.1", "ed25519-keygen": "github:LumeWeb/ed25519-keygen",
"ethers": "^5.6.9", "ethers": "^5.7.2",
"eventemitter2": "^6.4.9", "eventemitter2": "^6.4.9",
"fastify": "^4.10.2", "fastify": "^4.19.2",
"fetch-blob": "https://github.com/LumeWeb/fetch-blob.git", "fetch-blob": "github:LumeWeb/fetch-blob",
"hyperswarm": "^4.3.5", "hyperswarm": "^4.4.0",
"json-stable-stringify": "^1.0.1", "json-stable-stringify": "^1.0.2",
"json-stringify-deterministic": "^1.0.7", "json-stringify-deterministic": "^1.0.8",
"loady": "https://github.com/LumeWeb/loady.git", "loady": "github:LumeWeb/loady",
"micro-ed25519-hdkey": "patch:micro-ed25519-hdkey@npm%3A0.1.2#~/.yarn/patches/micro-ed25519-hdkey-npm-0.1.2-5d1d767d1d.patch", "msgpackr": "^1.8.5",
"msgpackr": "^1.6.1",
"node-cache": "^5.1.2", "node-cache": "^5.1.2",
"node-cron": "^3.0.1", "node-fetch": "^2.6.9",
"node-fetch": "2", "p-defer": "git+https://git.lumeweb.com/LumeWeb/p-defer.git",
"p-timeout": "https://git.lumeweb.com/LumeWeb/p-timeout.git", "p-timeout": "git+https://git.lumeweb.com/LumeWeb/p-timeout.git",
"pino": "^8.8.0", "pino": "^8.11.0",
"pino-pretty": "^9.1.1", "pino-pretty": "^9.4.0",
"promise-retry": "^2.0.1", "promise-retry": "^2.0.1",
"protomux": "^3.4.0", "protomux": "^3.4.1",
"protomux-rpc": "^1.3.0", "protomux-rpc": "^1.4.1",
"random-access-memory": "^4.1.0",
"random-key": "^0.3.2", "random-key": "^0.3.2",
"slugify": "^1.6.5", "slugify": "^1.6.6",
"sodium-universal": "^3.1.0" "sodium-universal": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@lumeweb/relay-types": "https://git.lumeweb.com/LumeWeb/relay-types.git", "@semantic-release/changelog": "^6.0.3",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@types/b4a": "^1.6.0", "@types/b4a": "^1.6.0",
"@types/minimatch": "^3.0.5", "@types/minimatch": "^3.0.5",
"@types/node-fetch": "^2.6.2", "@types/node-fetch": "^2.6.3",
"cli-progress": "^3.11.2", "cli-progress": "^3.12.0",
"hyper-typings": "^1.0.0", "hyper-typings": "^1.0.0",
"node-gyp": "^9.1.0", "node-gyp": "^9.3.1",
"pkg": "^5.8.0", "patch-package": "^6.5.1",
"pkg": "^5.8.1",
"prebuildify": "^5.0.1", "prebuildify": "^5.0.1",
"prettier": "^2.7.1", "prettier": "^2.8.7",
"rollup": "^2.77.0", "semantic-release": "21",
"supports-color": "https://github.com/LumeWeb/supports-color.git", "supports-color": "github:LumeWeb/supports-color",
"typescript": "^4.9.4" "typescript": "^4.9.5"
},
"packageManager": "yarn@4.0.0-rc.33",
"resolutions": {
"micro-ed25519-hdkey@npm:^0.1.2": "patch:micro-ed25519-hdkey@npm%3A0.1.2#~/.yarn/patches/micro-ed25519-hdkey-npm-0.1.2-5d1d767d1d.patch"
} }
} }

View File

@ -0,0 +1,12 @@
diff --git a/node_modules/@lumeweb/interface-relay/package.json b/node_modules/@lumeweb/interface-relay/package.json
index 0bfaba0..c503d91 100644
--- a/node_modules/@lumeweb/interface-relay/package.json
+++ b/node_modules/@lumeweb/interface-relay/package.json
@@ -2,7 +2,6 @@
"name": "@lumeweb/interface-relay",
"version": "0.0.2-develop.3",
"main": "lib/index.js",
- "type": "module",
"types": "lib/index.d.ts",
"module": "lib/index.mjs",
"exports": {

View File

@ -0,0 +1,20 @@
diff --git a/node_modules/sodium-native/package.json b/node_modules/sodium-native/package.json
index bda9dd4..3a5541a 100644
--- a/node_modules/sodium-native/package.json
+++ b/node_modules/sodium-native/package.json
@@ -3,15 +3,6 @@
"version": "4.0.1",
"description": "Low level bindings for libsodium",
"main": "index.js",
- "files": [
- "index.js",
- "deps/**",
- "modules/**",
- "binding.c",
- "binding.gyp",
- "macros.h",
- "prebuilds/**"
- ],
"dependencies": {
"node-gyp-build": "^4.3.0"
},

View File

@ -1,9 +1,5 @@
{ {
"assets": [ "assets": [
"node_modules/*/build/Release/*.node",
"node_modules/libskynet",
"node_modules/libskynetnode",
"node_modules/@lumeweb"
], ],
"outputPath": "dist" "outputPath": "dist"
} }

View File

@ -1,11 +1,11 @@
// @ts-ignore // @ts-ignore
import Config from "@lumeweb/cfg"; import { Config } from "@lumeweb/relay-cfg";
import * as os from "os"; import * as os from "os";
import * as fs from "fs"; import * as fs from "fs";
import path from "path"; import path from "path";
import log from "./log.js"; import log from "./log.js";
const config = new Config("lumeweb-relay", "core.confdir"); const config = new Config("lumeweb-relay", "core.confDir");
let configDir; let configDir;
@ -26,6 +26,7 @@ switch (os.platform()) {
config.inject({ config.inject({
"core.confDir": configDir, "core.confDir": configDir,
"core.port": 8080, "core.port": 8080,
"core.relayPort": 0,
"core.appPort": 80, "core.appPort": 80,
"core.logLevel": "info", "core.logLevel": "info",
"core.pluginDir": path.resolve(configDir, "..", "plugins"), "core.pluginDir": path.resolve(configDir, "..", "plugins"),
@ -33,7 +34,7 @@ config.inject({
config.load(); config.load();
configDir = config.str("core.confdir"); configDir = config.str("core.confDir") as string;
if (fs.existsSync(configDir)) { if (fs.existsSync(configDir)) {
try { try {

View File

@ -1,4 +1,4 @@
import { HDKey } from "micro-ed25519-hdkey"; import { HDKey } from "ed25519-keygen/hdkey";
import config from "../config"; import config from "../config";
import * as bip39 from "@scure/bip39"; import * as bip39 from "@scure/bip39";
import { wordlist } from "@scure/bip39/wordlists/english"; import { wordlist } from "@scure/bip39/wordlists/english";
@ -8,7 +8,7 @@ import b4a from "b4a";
const BIP44_PATH = "m/44'/1627'/0'/0'/0'"; const BIP44_PATH = "m/44'/1627'/0'/0'/0'";
export function getSeed() { export function getSeed() {
const seed = config.str("core.seed"); const seed = config.str("core.seed") as string;
let valid = bip39.validateMnemonic(seed, wordlist); let valid = bip39.validateMnemonic(seed, wordlist);
if (!valid) { if (!valid) {

View File

@ -20,7 +20,10 @@ export async function start() {
await getPluginAPI().emitAsync("core.appServer.buildRoutes"); await getPluginAPI().emitAsync("core.appServer.buildRoutes");
await app.listen({ port: config.uint("core.appport"), host: "0.0.0.0" }); await app.listen({
port: config.uint("core.appPort") as number,
host: "0.0.0.0",
});
getPluginAPI().emit("core.appServer.started"); getPluginAPI().emit("core.appServer.started");
} }

View File

@ -1,14 +1,14 @@
import config from "../config.js"; import config from "../config.js";
import type { RPCServer } from "./rpc/server.js"; import type { RPCServer } from "./rpc/server.js";
import { getRpcServer } from "./rpc/server.js"; import { getRpcServer } from "./rpc/server.js";
import type { Plugin, RPCMethod } from "@lumeweb/relay-types"; import type { Plugin, RPCMethod } from "@lumeweb/interface-relay";
import slugify from "slugify"; import slugify from "slugify";
import * as fs from "fs"; import * as fs from "fs";
import path from "path"; 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 type Config from "@lumeweb/cfg"; import type { Config } from "@lumeweb/relay-cfg";
import EventEmitter2 from "eventemitter2"; import EventEmitter2 from "eventemitter2";
import log from "../log.js"; import log from "../log.js";
import { import {
@ -17,7 +17,7 @@ import {
ProtocolManager, ProtocolManager,
} from "./swarm.js"; } from "./swarm.js";
import { get as getApp } from "./app.js"; import { get as getApp } from "./app.js";
import type { HDKey } from "micro-ed25519-hdkey"; import type { HDKey } from "ed25519-keygen/hdkey";
import corePlugins from "../plugins"; import corePlugins from "../plugins";
import Util from "./plugin/util"; import Util from "./plugin/util";
@ -250,7 +250,9 @@ export async function loadPlugins() {
await apiManager.loadPluginInstance(plugin); await apiManager.loadPluginInstance(plugin);
} }
for (const plugin of [...new Set(config.array("core.plugins", []))] as []) { for (const plugin of [
...new Set(config.array("core.plugins", [] as any)),
] as []) {
await apiManager.loadPlugin(plugin); await apiManager.loadPlugin(plugin);
} }

View File

@ -16,18 +16,24 @@ import * as http2 from "http2";
import websocket from "@fastify/websocket"; import websocket from "@fastify/websocket";
export async function start() { export async function start() {
const dht = getSwarm(); const swarm = getSwarm();
let relayServer = fastify({ let relayServer = fastify({
http2: true,
logger: log.child({ module: "relay-server" }), logger: log.child({ module: "relay-server" }),
}); });
relayServer.register(websocket); await relayServer.register(websocket);
relayServer.get("/", { websocket: true }, (connection) => { relayServer.get("/", { websocket: true }, (connection) => {
relay(dht, new Stream(false, connection.socket)); relay(swarm.dht, new Stream(false, connection.socket));
connection.socket.binaryType = "nodebuffer";
}); });
await relayServer.listen({ port: config.uint("core.port"), host: "0.0.0.0" }); let port = config.uint("core.relayPort");
if (!port) {
port = config.uint("core.port") as number;
}
await relayServer.listen({ port, host: "0.0.0.0" });
} }

View File

@ -7,16 +7,24 @@ 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) => {
getRpcServer().setup(stream) Protomux.from(stream).pair(
); { 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) {
@ -30,15 +38,16 @@ export async function getRpcByPeer(peer: Buffer | string) {
} }
return new Promise((resolve) => { return new Promise((resolve) => {
const listener = () => {}; const listener = (peer: any, info: any) => {
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

@ -3,7 +3,7 @@ import {
RPCMethod, RPCMethod,
RPCRequest, RPCRequest,
RPCResponse, RPCResponse,
} from "@lumeweb/relay-types"; } from "@lumeweb/interface-relay";
import EventEmitter from "events"; import EventEmitter from "events";
// @ts-ignore // @ts-ignore
import ProtomuxRPC from "protomux-rpc"; import ProtomuxRPC from "protomux-rpc";
@ -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;
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 const RPC_PROTOCOL_SYMBOL = Symbol.for(RPC_PROTOCOL_ID.toString());
export function getRpcServer(): RPCServer { export function getRpcServer(): RPCServer {
@ -43,6 +43,8 @@ export function setupStream(stream: SecretStream) {
valueEncoding: c.json, valueEncoding: c.json,
}); });
stream.setKeepAlive(5000);
return stream[RPC_PROTOCOL_SYMBOL]; return stream[RPC_PROTOCOL_SYMBOL];
} }

View File

@ -69,6 +69,9 @@ 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,8 +1,15 @@
import { Plugin, PluginAPI } from "@lumeweb/relay-types"; 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> {
@ -13,6 +20,8 @@ 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();
}, },
}); });

View File

@ -1,4 +1,4 @@
import { Plugin, PluginAPI } from "@lumeweb/relay-types"; import { Plugin, PluginAPI } from "@lumeweb/interface-relay";
import b4a from "b4a"; import b4a from "b4a";
const plugin: Plugin = { const plugin: Plugin = {

View File

@ -3,12 +3,11 @@ import {
PluginAPI, PluginAPI,
RPCBroadcastRequest, RPCBroadcastRequest,
RPCBroadcastResponse, RPCBroadcastResponse,
RPCCacheItem,
RPCRequest, RPCRequest,
RPCResponse, RPCResponse,
} from "@lumeweb/relay-types"; } from "@lumeweb/interface-relay";
import { getRpcByPeer } from "../modules/rpc"; import { getRpcByPeer } from "../modules/rpc";
import { get as getSwarm, LUMEWEB_TOPIC_HASH } from "../modules/swarm"; import { get as getSwarm } from "../modules/swarm";
import b4a from "b4a"; import b4a from "b4a";
import pTimeout, { ClearablePromise } from "p-timeout"; import pTimeout, { ClearablePromise } from "p-timeout";
@ -50,91 +49,6 @@ const plugin: Plugin = {
name: "rpc", name: "rpc",
async plugin(_api: PluginAPI): Promise<void> { async plugin(_api: PluginAPI): Promise<void> {
api = _api; api = _api;
if (api.config.bool("cache")) {
api.registerMethod("get_cached_item", {
cacheable: false,
async handler(req: string): Promise<RPCResponse> {
if (typeof req !== "string") {
throw new Error("item must be a string");
}
const cache = api.rpcServer.cache?.data;
if (!cache?.has(req)) {
throw new Error("item does not exist");
}
return {
data: true,
...cache.get<RPCCacheItem>(req)?.value,
signature: cache.get<RPCCacheItem>(req)?.signature,
};
},
});
api.registerMethod("clear_cached_item", {
cacheable: false,
async handler(req: string): Promise<void> {
if (typeof req !== "string") {
throw new Error("item must be a string");
}
try {
api.rpcServer.cache.deleteItem(req);
} catch (e: any) {
throw e;
}
},
});
api.registerMethod("get_peers", {
cacheable: false,
async handler(): Promise<string[]> {
const pubkey = b4a.from(api.identity.publicKeyRaw).toString("hex");
const online = api.rpcServer.cache?.dhtCache.online || new Set();
if (online.has(pubkey)) {
online.delete(pubkey);
}
return [...online];
},
});
if (api.logger.level === "debug") {
api.registerMethod("get_direct_peers", {
cacheable: false,
async handler(): Promise<string[]> {
const online = api.rpcServer.cache.dhtCache.online;
const pubkey = b4a
.from(api.swarm.keyPair.publicKeyRaw())
.toString("hex");
if (online.has(pubkey)) {
online.delete(pubkey);
}
const topic = LUMEWEB_TOPIC_HASH.toString("hex");
return [...api.swarm.peers.values()]
.filter((item: any) =>
[...item._seenTopics.keys()].includes(topic)
)
.map((item: any) => item.publicKey.toString("hex"))
.filter((item: any) => online.has(item));
},
});
api.registerMethod("get_bootstrap_info", {
cacheable: false,
async handler(): Promise<string[]> {
// @ts-ignore
return api.rpcServer.cache.dhtCache._getBootstrapInfo();
},
});
api.registerMethod("get_connected_peers", {
cacheable: false,
async handler(): Promise<string[]> {
// @ts-ignore
return [...api.rpcServer.cache.dhtCache.connectedTo];
},
});
}
}
api.registerMethod("broadcast_request", { api.registerMethod("broadcast_request", {
cacheable: false, cacheable: false,
async handler(req: RPCBroadcastRequest): Promise<RPCBroadcastResponse> { async handler(req: RPCBroadcastRequest): Promise<RPCBroadcastResponse> {

View File

@ -2,7 +2,7 @@
"compilerOptions": { "compilerOptions": {
"target": "es2020", "target": "es2020",
"module": "commonjs", "module": "commonjs",
"moduleResolution": "node", "moduleResolution": "nodenext",
"rootDir": "src", "rootDir": "src",
"outDir": "build", "outDir": "build",
"esModuleInterop": true, "esModuleInterop": true,

4559
yarn.lock

File diff suppressed because it is too large Load Diff