mirror of https://github.com/status-im/js-waku.git
feat!: @waku/relay (#1316)
* move constants & core's func to @waku/utils * setup @waku/relay * use @waku/relay for create * address: principal review * fix: size-limit * move all constants to @waku/core * move TopicOnlyDecoder to relay * merge: master * fix: tests * Move constants out of core (#1340) * update package.lock * change constants folder into a ts file * use dependency version as * instead of version number * add constants import from @waku/core * add empty changelog file for relay --------- Co-authored-by: fryorcraken.eth <110212804+fryorcraken@users.noreply.github.com>
This commit is contained in:
parent
f4e31019e1
commit
50c2c2540f
|
@ -30,7 +30,7 @@ module.exports = [
|
|||
},
|
||||
{
|
||||
name: "Privacy preserving protocols",
|
||||
path: "packages/core/bundle/index.js",
|
||||
path: "packages/relay/bundle/index.js",
|
||||
import: "{ wakuRelay }",
|
||||
},
|
||||
{
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -8,6 +8,7 @@
|
|||
"packages/proto",
|
||||
"packages/enr",
|
||||
"packages/core",
|
||||
"packages/relay",
|
||||
"packages/message-hash",
|
||||
"packages/peer-exchange",
|
||||
"packages/dns-discovery",
|
||||
|
|
|
@ -17,10 +17,6 @@
|
|||
"types": "./dist/lib/message/version_0.d.ts",
|
||||
"import": "./dist/lib/message/version_0.js"
|
||||
},
|
||||
"./lib/message/topic_only_message": {
|
||||
"types": "./dist/lib/message/topic_only_message.d.ts",
|
||||
"import": "./dist/lib/message/topic_only_message.js"
|
||||
},
|
||||
"./lib/base_protocol": {
|
||||
"types": "./dist/lib/base_protocol.d.ts",
|
||||
"import": "./dist/lib/base_protocol.js"
|
||||
|
@ -30,6 +26,9 @@
|
|||
"*": {
|
||||
"lib/*": [
|
||||
"dist/lib/*"
|
||||
],
|
||||
"constants/*": [
|
||||
"dist/constants/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -74,12 +73,10 @@
|
|||
"node": ">=16"
|
||||
},
|
||||
"dependencies": {
|
||||
"@chainsafe/libp2p-gossipsub": "^6.1.0",
|
||||
"@libp2p/interface-pubsub": "^3.0.7",
|
||||
"@noble/hashes": "^1.3.0",
|
||||
"@waku/interfaces": "0.0.12",
|
||||
"@waku/proto": "0.0.4",
|
||||
"@waku/utils": "0.0.5",
|
||||
"@waku/interfaces": "*",
|
||||
"@waku/proto": "*",
|
||||
"@waku/utils": "*",
|
||||
"debug": "^4.3.4",
|
||||
"it-all": "^3.0.1",
|
||||
"it-length-prefixed": "^9.0.1",
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
export { DefaultPubSubTopic } from "./lib/constants.js";
|
||||
export { DefaultUserAgent } from "./lib/waku.js";
|
||||
|
||||
export { DefaultPubSubTopic } from "./lib/constants.js";
|
||||
export { createEncoder, createDecoder } from "./lib/message/version_0.js";
|
||||
export type {
|
||||
Encoder,
|
||||
|
@ -18,13 +17,6 @@ export { wakuFilter } from "./lib/filter/index.js";
|
|||
export * as waku_light_push from "./lib/light_push/index.js";
|
||||
export { wakuLightPush, LightPushCodec } from "./lib/light_push/index.js";
|
||||
|
||||
export * as waku_relay from "./lib/relay/index.js";
|
||||
export {
|
||||
wakuRelay,
|
||||
RelayCreateOptions,
|
||||
wakuGossipSub,
|
||||
} from "./lib/relay/index.js";
|
||||
|
||||
export * as waku_store from "./lib/store/index.js";
|
||||
export {
|
||||
PageDirection,
|
||||
|
|
|
@ -12,6 +12,7 @@ import type {
|
|||
ProtocolOptions,
|
||||
} from "@waku/interfaces";
|
||||
import { WakuMessage as WakuMessageProto } from "@waku/proto";
|
||||
import { groupByContentTopic } from "@waku/utils";
|
||||
import { toAsyncIterator } from "@waku/utils";
|
||||
import debug from "debug";
|
||||
import all from "it-all";
|
||||
|
@ -20,7 +21,6 @@ import { pipe } from "it-pipe";
|
|||
|
||||
import { BaseProtocol } from "../base_protocol.js";
|
||||
import { DefaultPubSubTopic } from "../constants.js";
|
||||
import { groupByContentTopic } from "../group_by.js";
|
||||
import { toProtoMessage } from "../to_proto_message.js";
|
||||
|
||||
import { ContentFilter, FilterRpc } from "./filter_rpc.js";
|
||||
|
|
|
@ -5,8 +5,7 @@ import type { Libp2p } from "libp2p";
|
|||
|
||||
import { createEncoder } from "../index.js";
|
||||
|
||||
import { RelayPingContentTopic } from "./relay/constants.js";
|
||||
|
||||
export const RelayPingContentTopic = "/relay-ping/1/ping/null";
|
||||
const log = debug("waku:keep-alive");
|
||||
|
||||
export interface KeepAliveOptions {
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
export * as version_0 from "./version_0.js";
|
||||
export * as topic_only_message from "./topic_only_message.js";
|
||||
|
|
|
@ -51,8 +51,9 @@
|
|||
"@chainsafe/libp2p-noise": "^11.0.0",
|
||||
"@libp2p/mplex": "^7.1.1",
|
||||
"@libp2p/websockets": "^5.0.3",
|
||||
"@waku/core": "0.0.17",
|
||||
"@waku/dns-discovery": "0.0.11",
|
||||
"@waku/relay": "*",
|
||||
"@waku/core": "*",
|
||||
"@waku/dns-discovery": "*",
|
||||
"libp2p": "^0.42.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -76,7 +77,7 @@
|
|||
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
||||
"@typescript-eslint/parser": "^5.51.0",
|
||||
"@waku/build-utils": "*",
|
||||
"@waku/interfaces": "0.0.12",
|
||||
"@waku/interfaces": "*",
|
||||
"cspell": "^6.31.1",
|
||||
"eslint": "^8.35.0",
|
||||
"eslint-config-prettier": "^8.6.0",
|
||||
|
|
|
@ -7,13 +7,10 @@ import { webSockets } from "@libp2p/websockets";
|
|||
import { all as filterAll } from "@libp2p/websockets/filters";
|
||||
import {
|
||||
DefaultUserAgent,
|
||||
RelayCreateOptions,
|
||||
wakuFilter,
|
||||
wakuGossipSub,
|
||||
wakuLightPush,
|
||||
WakuNode,
|
||||
WakuOptions,
|
||||
wakuRelay,
|
||||
wakuStore,
|
||||
} from "@waku/core";
|
||||
import { enrTree, wakuDnsDiscovery } from "@waku/dns-discovery";
|
||||
|
@ -23,6 +20,7 @@ import type {
|
|||
ProtocolCreateOptions,
|
||||
RelayNode,
|
||||
} from "@waku/interfaces";
|
||||
import { RelayCreateOptions, wakuGossipSub, wakuRelay } from "@waku/relay";
|
||||
import { createLibp2p, Libp2pOptions } from "libp2p";
|
||||
|
||||
import type { Libp2pComponents } from "./libp2p_components.js";
|
||||
|
|
|
@ -60,8 +60,8 @@
|
|||
"dependencies": {
|
||||
"@libp2p/interface-peer-discovery": "^1.0.5",
|
||||
"@libp2p/interfaces": "^3.3.1",
|
||||
"@waku/enr": "0.0.11",
|
||||
"@waku/utils": "0.0.5",
|
||||
"@waku/enr": "*",
|
||||
"@waku/utils": "*",
|
||||
"debug": "^4.3.4",
|
||||
"dns-query": "^0.11.2",
|
||||
"hi-base32": "^0.5.1",
|
||||
|
@ -80,7 +80,7 @@
|
|||
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
||||
"@typescript-eslint/parser": "^5.51.0",
|
||||
"@waku/build-utils": "*",
|
||||
"@waku/interfaces": "0.0.12",
|
||||
"@waku/interfaces": "*",
|
||||
"chai": "^4.3.7",
|
||||
"cspell": "^6.31.1",
|
||||
"eslint": "^8.35.0",
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
"@libp2p/peer-id": "^2.0.3",
|
||||
"@multiformats/multiaddr": "^12.0.0",
|
||||
"@noble/secp256k1": "^1.7.1",
|
||||
"@waku/utils": "0.0.5",
|
||||
"@waku/utils": "*",
|
||||
"debug": "^4.3.4",
|
||||
"js-sha3": "^0.8.0"
|
||||
},
|
||||
|
|
|
@ -72,10 +72,10 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@noble/secp256k1": "^1.7.1",
|
||||
"@waku/core": "0.0.17",
|
||||
"@waku/interfaces": "0.0.12",
|
||||
"@waku/proto": "0.0.4",
|
||||
"@waku/utils": "0.0.5",
|
||||
"@waku/core": "*",
|
||||
"@waku/interfaces": "*",
|
||||
"@waku/proto": "*",
|
||||
"@waku/utils": "*",
|
||||
"debug": "^4.3.4",
|
||||
"js-sha3": "^0.8.0"
|
||||
},
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@noble/hashes": "^1.2.0",
|
||||
"@waku/utils": "0.0.5"
|
||||
"@waku/utils": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^24.0.1",
|
||||
|
@ -65,7 +65,7 @@
|
|||
"@typescript-eslint/eslint-plugin": "^5.54.1",
|
||||
"@typescript-eslint/parser": "^5.51.0",
|
||||
"@waku/build-utils": "*",
|
||||
"@waku/interfaces": "0.0.12",
|
||||
"@waku/interfaces": "*",
|
||||
"chai": "^4.3.7",
|
||||
"cspell": "^6.28.0",
|
||||
"eslint": "^8.35.0",
|
||||
|
|
|
@ -50,10 +50,10 @@
|
|||
"dependencies": {
|
||||
"@libp2p/interface-peer-discovery": "^1.0.5",
|
||||
"@libp2p/interfaces": "^3.3.1",
|
||||
"@waku/core": "0.0.17",
|
||||
"@waku/enr": "0.0.11",
|
||||
"@waku/proto": "0.0.4",
|
||||
"@waku/utils": "0.0.5",
|
||||
"@waku/core": "*",
|
||||
"@waku/enr": "*",
|
||||
"@waku/proto": "*",
|
||||
"@waku/utils": "*",
|
||||
"debug": "^4.3.4",
|
||||
"it-all": "^3.0.1",
|
||||
"it-length-prefixed": "^9.0.1",
|
||||
|
@ -71,7 +71,7 @@
|
|||
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
||||
"@typescript-eslint/parser": "^5.51.0",
|
||||
"@waku/build-utils": "*",
|
||||
"@waku/interfaces": "0.0.12",
|
||||
"@waku/interfaces": "*",
|
||||
"chai": "^4.3.7",
|
||||
"cspell": "^6.31.1",
|
||||
"eslint": "^8.35.0",
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
parserOptions: {
|
||||
tsconfigRootDir: __dirname,
|
||||
project: "./tsconfig.dev.json",
|
||||
},
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"extension": ["ts"],
|
||||
"spec": "src/**/*.spec.ts",
|
||||
"require": ["ts-node/register", "isomorphic-fetch"],
|
||||
"loader": "ts-node/esm",
|
||||
"node-option": [
|
||||
"experimental-specifier-resolution=node",
|
||||
"loader=ts-node/esm"
|
||||
],
|
||||
"exit": true
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,93 @@
|
|||
{
|
||||
"name": "@waku/relay",
|
||||
"version": "0.0.1",
|
||||
"description": "Relay Protocol for Waku",
|
||||
"types": "./dist/index.d.ts",
|
||||
"module": "./dist/index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"lib/*": [
|
||||
"dist/lib/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "module",
|
||||
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/relay#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/waku-org/js-waku.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/waku-org/js-waku/issues"
|
||||
},
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"keywords": [
|
||||
"waku",
|
||||
"decentralised",
|
||||
"communication",
|
||||
"web3",
|
||||
"ethereum",
|
||||
"dapps"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "run-s build:**",
|
||||
"build:esm": "tsc",
|
||||
"build:bundle": "rollup --config rollup.config.js",
|
||||
"fix": "run-s fix:*",
|
||||
"fix:lint": "eslint src *.js --fix",
|
||||
"pretest": "run-s pretest:*",
|
||||
"check": "run-s check:*",
|
||||
"check:tsc": "tsc -p tsconfig.dev.json",
|
||||
"check:lint": "eslint src *.js",
|
||||
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
|
||||
"test": "run-s test:*",
|
||||
"test:node": "TS_NODE_PROJECT=./tsconfig.dev.json mocha",
|
||||
"watch:build": "tsc -p tsconfig.json -w",
|
||||
"watch:test": "mocha --watch",
|
||||
"prepublish": "npm run build",
|
||||
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"dependencies": {
|
||||
"@chainsafe/libp2p-gossipsub": "^6.1.0",
|
||||
"@noble/hashes": "^1.3.0",
|
||||
"@waku/build-utils": "*",
|
||||
"@waku/core": "*",
|
||||
"@waku/interfaces": "*",
|
||||
"@waku/proto": "*",
|
||||
"@waku/utils": "*",
|
||||
"chai": "^4.3.7",
|
||||
"debug": "^4.3.4",
|
||||
"fast-check": "^3.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^24.1.0",
|
||||
"@rollup/plugin-json": "^6.0.0",
|
||||
"@rollup/plugin-node-resolve": "^15.0.2",
|
||||
"rollup": "^3.15.0",
|
||||
"ts-loader": "^9.4.2",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
"typedoc": {
|
||||
"entryPoint": "./src/index.ts"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"bundle",
|
||||
"src/**/*.ts",
|
||||
"!**/*.spec.*",
|
||||
"!**/*.json",
|
||||
"CHANGELOG.md",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
import commonjs from "@rollup/plugin-commonjs";
|
||||
import json from "@rollup/plugin-json";
|
||||
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
||||
import { extractExports } from "@waku/build-utils";
|
||||
|
||||
import * as packageJson from "./package.json" assert { type: "json" };
|
||||
|
||||
const input = extractExports(packageJson);
|
||||
|
||||
export default {
|
||||
input,
|
||||
output: {
|
||||
dir: "bundle",
|
||||
format: "esm",
|
||||
},
|
||||
plugins: [
|
||||
commonjs(),
|
||||
json(),
|
||||
nodeResolve({
|
||||
browser: true,
|
||||
preferBuiltins: false,
|
||||
}),
|
||||
],
|
||||
};
|
|
@ -6,8 +6,6 @@ export const minute = 60 * second;
|
|||
*/
|
||||
export const RelayCodecs = ["/vac/waku/relay/2.0.0"];
|
||||
|
||||
export const RelayPingContentTopic = "/relay-ping/1/ping/null";
|
||||
|
||||
/**
|
||||
* RelayGossipFactor affects how many peers we will emit gossip to at each heartbeat.
|
||||
* We will send gossip to RelayGossipFactor * (total number of non-mesh peers), or
|
|
@ -9,6 +9,7 @@ import { SignaturePolicy } from "@chainsafe/libp2p-gossipsub/types";
|
|||
import type { Libp2p } from "@libp2p/interface-libp2p";
|
||||
import type { PubSub } from "@libp2p/interface-pubsub";
|
||||
import { sha256 } from "@noble/hashes/sha256";
|
||||
import { DefaultPubSubTopic } from "@waku/core";
|
||||
import type {
|
||||
ActiveSubscriptions,
|
||||
Callback,
|
||||
|
@ -22,15 +23,12 @@ import type {
|
|||
ProtocolOptions,
|
||||
SendResult,
|
||||
} from "@waku/interfaces";
|
||||
import { toAsyncIterator } from "@waku/utils";
|
||||
import { groupByContentTopic, toAsyncIterator } from "@waku/utils";
|
||||
import debug from "debug";
|
||||
|
||||
import { DefaultPubSubTopic } from "../constants.js";
|
||||
import { groupByContentTopic } from "../group_by.js";
|
||||
import { TopicOnlyDecoder } from "../message/topic_only_message.js";
|
||||
|
||||
import * as constants from "./constants.js";
|
||||
import { RelayCodecs } from "./constants.js";
|
||||
import { messageValidator } from "./message_validator.js";
|
||||
import { TopicOnlyDecoder } from "./topic_only_message.js";
|
||||
|
||||
const log = debug("waku:relay");
|
||||
|
||||
|
@ -50,7 +48,7 @@ class Relay implements IRelay {
|
|||
private readonly pubSubTopic: string;
|
||||
private defaultDecoder: IDecoder<IDecodedMessage>;
|
||||
|
||||
public static multicodec: string = constants.RelayCodecs[0];
|
||||
public static multicodec: string = RelayCodecs[0];
|
||||
public readonly gossipSub: GossipSub;
|
||||
|
||||
/**
|
||||
|
@ -245,7 +243,7 @@ export function wakuGossipSub(
|
|||
fallbackToFloodsub: false,
|
||||
};
|
||||
const pubsub = new GossipSub(components, init);
|
||||
pubsub.multicodecs = constants.RelayCodecs;
|
||||
pubsub.multicodecs = RelayCodecs;
|
||||
return pubsub;
|
||||
};
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
import { TopicValidatorResult } from "@libp2p/interface-pubsub";
|
||||
import type { UnsignedMessage } from "@libp2p/interface-pubsub";
|
||||
import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
|
||||
import { createEncoder } from "@waku/core";
|
||||
import { expect } from "chai";
|
||||
import fc from "fast-check";
|
||||
|
||||
import { createEncoder } from "../message/version_0.js";
|
||||
|
||||
import { messageValidator } from "./message_validator.js";
|
||||
|
||||
describe("Message Validator", () => {
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"extends": "../../tsconfig.dev"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"extends": "../../tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist/",
|
||||
"rootDir": "src",
|
||||
"tsBuildInfoFile": "dist/.tsbuildinfo"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["src/**/*.spec.ts", "src/test_utils"]
|
||||
}
|
|
@ -78,7 +78,7 @@
|
|||
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
||||
"@typescript-eslint/parser": "^5.51.0",
|
||||
"@waku/build-utils": "*",
|
||||
"@waku/interfaces": "0.0.12",
|
||||
"@waku/interfaces": "*",
|
||||
"cspell": "^6.31.1",
|
||||
"eslint": "^8.35.0",
|
||||
"eslint-config-prettier": "^8.6.0",
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
export * from "./is_defined.js";
|
||||
export * from "./random_subset.js";
|
||||
export * from "./group_by.js";
|
||||
export * from "./to_async_iterator.js";
|
||||
|
|
Loading…
Reference in New Issue