@waku/core 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -3
- package/bundle/index.js +31146 -26342
- package/bundle/lib/message/topic_only_message.js +33 -0
- package/bundle/lib/message/version_0.js +133 -0
- package/bundle/lib/predefined_bootstrap_nodes.js +24 -4
- package/bundle/{message-049c8b67.js → peer_exchange-53df2b11.js} +3579 -1007
- package/dist/index.d.ts +14 -13
- package/dist/index.js +11 -10
- package/dist/index.js.map +1 -1
- package/dist/lib/{waku_filter → filter}/filter_rpc.d.ts +1 -1
- package/dist/lib/{waku_filter → filter}/filter_rpc.js +1 -1
- package/dist/lib/filter/filter_rpc.js.map +1 -0
- package/dist/lib/filter/index.d.ts +25 -0
- package/dist/lib/{waku_filter → filter}/index.js +14 -9
- package/dist/lib/filter/index.js.map +1 -0
- package/dist/lib/light_push/index.d.ts +22 -0
- package/dist/lib/{waku_light_push → light_push}/index.js +14 -9
- package/dist/lib/light_push/index.js.map +1 -0
- package/dist/lib/{waku_light_push → light_push}/push_rpc.d.ts +1 -1
- package/dist/lib/{waku_light_push → light_push}/push_rpc.js +1 -1
- package/dist/lib/light_push/push_rpc.js.map +1 -0
- package/dist/lib/message/topic_only_message.d.ts +16 -0
- package/dist/lib/{waku_message → message}/topic_only_message.js +2 -1
- package/dist/lib/message/topic_only_message.js.map +1 -0
- package/dist/lib/message/version_0.d.ts +54 -0
- package/dist/lib/{waku_message → message}/version_0.js +41 -6
- package/dist/lib/message/version_0.js.map +1 -0
- package/dist/lib/predefined_bootstrap_nodes.d.ts +1 -2
- package/dist/lib/predefined_bootstrap_nodes.js +0 -2
- package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
- package/dist/lib/{waku_relay → relay}/constants.d.ts +0 -0
- package/dist/lib/{waku_relay → relay}/constants.js +0 -0
- package/dist/lib/relay/constants.js.map +1 -0
- package/dist/lib/relay/index.d.ts +24 -0
- package/dist/lib/{waku_relay → relay}/index.js +9 -6
- package/dist/lib/relay/index.js.map +1 -0
- package/dist/lib/{waku_store → store}/history_rpc.d.ts +1 -1
- package/dist/lib/{waku_store → store}/history_rpc.js +1 -1
- package/dist/lib/store/history_rpc.js.map +1 -0
- package/dist/lib/store/index.d.ts +68 -0
- package/dist/lib/{waku_store → store}/index.js +41 -16
- package/dist/lib/store/index.js.map +1 -0
- package/dist/lib/to_proto_message.d.ts +3 -3
- package/dist/lib/to_proto_message.js +1 -0
- package/dist/lib/to_proto_message.js.map +1 -1
- package/dist/lib/wait_for_remote_peer.js +14 -5
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/dist/lib/waku.d.ts +17 -15
- package/dist/lib/waku.js +49 -41
- package/dist/lib/waku.js.map +1 -1
- package/package.json +28 -31
- package/src/index.ts +25 -14
- package/src/lib/{waku_filter → filter}/filter_rpc.ts +1 -2
- package/src/lib/{waku_filter → filter}/index.ts +51 -30
- package/src/lib/{waku_light_push → light_push}/index.ts +38 -19
- package/src/lib/{waku_light_push → light_push}/push_rpc.ts +1 -2
- package/src/lib/{waku_message → message}/topic_only_message.ts +12 -7
- package/src/lib/{waku_message → message}/version_0.ts +59 -18
- package/src/lib/predefined_bootstrap_nodes.ts +2 -6
- package/src/lib/{waku_relay → relay}/constants.ts +0 -0
- package/src/lib/{waku_relay → relay}/index.ts +30 -26
- package/src/lib/{waku_store → store}/history_rpc.ts +1 -2
- package/src/lib/{waku_store → store}/index.ts +93 -28
- package/src/lib/to_proto_message.ts +5 -5
- package/src/lib/wait_for_remote_peer.ts +19 -7
- package/src/lib/waku.ts +78 -51
- package/bundle/browser-1e1a2f27.js +0 -722
- package/bundle/events-158407bb.js +0 -1929
- package/bundle/index-64ce43f0.js +0 -69
- package/bundle/index-8710041d.js +0 -2962
- package/bundle/index-a67d7136.js +0 -4059
- package/bundle/lib/peer_discovery_static_list.js +0 -89
- package/bundle/lib/wait_for_remote_peer.js +0 -326
- package/bundle/lib/waku_message/topic_only_message.js +0 -3
- package/bundle/lib/waku_message/version_0.js +0 -317
- package/bundle/random_subset-75d1c511.js +0 -26
- package/bundle/topic_only_message-5ad3a869.js +0 -82
- package/dist/lib/multiaddr_to_peer_info.d.ts +0 -3
- package/dist/lib/multiaddr_to_peer_info.js +0 -15
- package/dist/lib/multiaddr_to_peer_info.js.map +0 -1
- package/dist/lib/peer_discovery_static_list.d.ts +0 -44
- package/dist/lib/peer_discovery_static_list.js +0 -72
- package/dist/lib/peer_discovery_static_list.js.map +0 -1
- package/dist/lib/select_connection.d.ts +0 -2
- package/dist/lib/select_connection.js +0 -19
- package/dist/lib/select_connection.js.map +0 -1
- package/dist/lib/select_peer.d.ts +0 -15
- package/dist/lib/select_peer.js +0 -59
- package/dist/lib/select_peer.js.map +0 -1
- package/dist/lib/waku_filter/filter_rpc.js.map +0 -1
- package/dist/lib/waku_filter/index.d.ts +0 -50
- package/dist/lib/waku_filter/index.js.map +0 -1
- package/dist/lib/waku_light_push/index.d.ts +0 -38
- package/dist/lib/waku_light_push/index.js.map +0 -1
- package/dist/lib/waku_light_push/push_rpc.js.map +0 -1
- package/dist/lib/waku_message/topic_only_message.d.ts +0 -15
- package/dist/lib/waku_message/topic_only_message.js.map +0 -1
- package/dist/lib/waku_message/version_0.d.ts +0 -27
- package/dist/lib/waku_message/version_0.js.map +0 -1
- package/dist/lib/waku_relay/constants.js.map +0 -1
- package/dist/lib/waku_relay/index.d.ts +0 -66
- package/dist/lib/waku_relay/index.js.map +0 -1
- package/dist/lib/waku_store/history_rpc.js.map +0 -1
- package/dist/lib/waku_store/index.d.ts +0 -126
- package/dist/lib/waku_store/index.js.map +0 -1
- package/dist/proto/filter.d.ts +0 -65
- package/dist/proto/filter.js +0 -425
- package/dist/proto/filter.js.map +0 -1
- package/dist/proto/light_push.d.ts +0 -57
- package/dist/proto/light_push.js +0 -369
- package/dist/proto/light_push.js.map +0 -1
- package/dist/proto/message.d.ts +0 -29
- package/dist/proto/message.js +0 -215
- package/dist/proto/message.js.map +0 -1
- package/dist/proto/store.d.ts +0 -104
- package/dist/proto/store.js +0 -602
- package/dist/proto/store.js.map +0 -1
- package/dist/proto/topic_only_message.d.ts +0 -10
- package/dist/proto/topic_only_message.js +0 -46
- package/dist/proto/topic_only_message.js.map +0 -1
- package/src/lib/multiaddr_to_peer_info.ts +0 -17
- package/src/lib/peer_discovery_static_list.ts +0 -118
- package/src/lib/select_connection.ts +0 -24
- package/src/lib/select_peer.ts +0 -77
- package/src/proto/filter.ts +0 -602
- package/src/proto/light_push.ts +0 -526
- package/src/proto/message.ts +0 -304
- package/src/proto/store.ts +0 -844
- package/src/proto/topic_only_message.ts +0 -67
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@waku/core",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.7",
|
4
4
|
"description": "TypeScript implementation of the Waku v2 protocol",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"module": "./dist/index.js",
|
@@ -9,25 +9,17 @@
|
|
9
9
|
"types": "./dist/index.d.ts",
|
10
10
|
"import": "./dist/index.js"
|
11
11
|
},
|
12
|
-
"./lib/peer_discovery_static_list": {
|
13
|
-
"types": "./dist/lib/peer_discovery_static_list.d.ts",
|
14
|
-
"import": "./dist/lib/peer_discovery_static_list.js"
|
15
|
-
},
|
16
12
|
"./lib/predefined_bootstrap_nodes": {
|
17
13
|
"types": "./dist/lib/predefined_bootstrap_nodes.d.ts",
|
18
14
|
"import": "./dist/lib/predefined_bootstrap_nodes.js"
|
19
15
|
},
|
20
|
-
"./lib/
|
21
|
-
"types": "./dist/lib/
|
22
|
-
"import": "./dist/lib/
|
23
|
-
},
|
24
|
-
"./lib/waku_message/version_0": {
|
25
|
-
"types": "./dist/lib/waku_message/version_0.d.ts",
|
26
|
-
"import": "./dist/lib/waku_message/version_0.js"
|
16
|
+
"./lib/message/version_0": {
|
17
|
+
"types": "./dist/lib/message/version_0.d.ts",
|
18
|
+
"import": "./dist/lib/message/version_0.js"
|
27
19
|
},
|
28
|
-
"./lib/
|
29
|
-
"types": "./dist/lib/
|
30
|
-
"import": "./dist/lib/
|
20
|
+
"./lib/message/topic_only_message": {
|
21
|
+
"types": "./dist/lib/message/topic_only_message.d.ts",
|
22
|
+
"import": "./dist/lib/message/topic_only_message.js"
|
31
23
|
}
|
32
24
|
},
|
33
25
|
"typesVersions": {
|
@@ -57,7 +49,7 @@
|
|
57
49
|
],
|
58
50
|
"scripts": {
|
59
51
|
"build": "run-s build:**",
|
60
|
-
"build:esm": "tsc
|
52
|
+
"build:esm": "tsc",
|
61
53
|
"build:bundle": "rollup --config rollup.config.js",
|
62
54
|
"fix": "run-s fix:*",
|
63
55
|
"fix:prettier": "prettier . --write",
|
@@ -75,39 +67,38 @@
|
|
75
67
|
"test": "run-s test:*",
|
76
68
|
"test:node": "TS_NODE_PROJECT=./tsconfig.dev.json mocha",
|
77
69
|
"test:browser": "karma start karma.conf.cjs",
|
78
|
-
"proto": "rimraf src/proto/*.ts; protons src/proto/*.proto",
|
79
70
|
"watch:build": "tsc -p tsconfig.json -w",
|
80
71
|
"watch:test": "mocha --watch",
|
81
72
|
"prepublish": "npm run build",
|
82
|
-
"deploy": "node ci/deploy.js",
|
83
73
|
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
|
84
74
|
},
|
85
75
|
"engines": {
|
86
76
|
"node": ">=16"
|
87
77
|
},
|
88
78
|
"dependencies": {
|
89
|
-
"@
|
90
|
-
"@chainsafe/libp2p-gossipsub": "^4.1.1",
|
79
|
+
"@chainsafe/libp2p-gossipsub": "^5.2.1",
|
91
80
|
"@libp2p/interface-connection": "^3.0.3",
|
92
81
|
"@libp2p/interface-peer-discovery": "^1.0.0",
|
93
|
-
"@libp2p/interface-peer-id": "^1.0.
|
94
|
-
"@libp2p/interface-peer-info": "^1.0.
|
95
|
-
"@libp2p/interface-peer-store": "^1.
|
96
|
-
"@libp2p/interface-pubsub": "^
|
97
|
-
"@libp2p/
|
82
|
+
"@libp2p/interface-peer-id": "^1.0.6",
|
83
|
+
"@libp2p/interface-peer-info": "^1.0.4",
|
84
|
+
"@libp2p/interface-peer-store": "^1.2.3",
|
85
|
+
"@libp2p/interface-pubsub": "^3.0.1",
|
86
|
+
"@libp2p/interface-registrar": "^2.0.4",
|
87
|
+
"@libp2p/interfaces": "^3.0.4",
|
98
88
|
"@libp2p/peer-id": "^1.1.10",
|
99
89
|
"@multiformats/multiaddr": "^11.0.6",
|
90
|
+
"@noble/hashes": "^1.1.3",
|
91
|
+
"@waku/byte-utils": "*",
|
100
92
|
"@waku/interfaces": "*",
|
101
93
|
"debug": "^4.3.4",
|
102
94
|
"it-all": "^1.0.6",
|
103
95
|
"it-length-prefixed": "^8.0.2",
|
104
96
|
"it-pipe": "^2.0.4",
|
105
|
-
"libp2p": "0.
|
97
|
+
"libp2p": "0.40.0",
|
106
98
|
"p-event": "^5.0.1",
|
107
|
-
"protons-runtime": "^3.1.0",
|
108
99
|
"uint8arraylist": "^2.3.2",
|
109
100
|
"uint8arrays": "^4.0.2",
|
110
|
-
"uuid": "^
|
101
|
+
"uuid": "^9.0.0"
|
111
102
|
},
|
112
103
|
"devDependencies": {
|
113
104
|
"@rollup/plugin-commonjs": "^22.0.0",
|
@@ -124,7 +115,7 @@
|
|
124
115
|
"@typescript-eslint/parser": "^5.8.1",
|
125
116
|
"app-root-path": "^3.0.0",
|
126
117
|
"chai": "^4.3.4",
|
127
|
-
"cspell": "^
|
118
|
+
"cspell": "^6.17.0",
|
128
119
|
"eslint": "^8.6.0",
|
129
120
|
"eslint-config-prettier": "^8.3.0",
|
130
121
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
@@ -147,7 +138,6 @@
|
|
147
138
|
"portfinder": "^1.0.28",
|
148
139
|
"prettier": "^2.1.1",
|
149
140
|
"process": "^0.11.10",
|
150
|
-
"protons": "^5.1.0",
|
151
141
|
"puppeteer": "^13.0.1",
|
152
142
|
"rollup": "^2.75.0",
|
153
143
|
"tail": "^2.2.0",
|
@@ -155,6 +145,14 @@
|
|
155
145
|
"ts-node": "^10.9.1",
|
156
146
|
"typescript": "^4.6.3"
|
157
147
|
},
|
148
|
+
"peerDependencies": {
|
149
|
+
"@multiformats/multiaddr": "^11.0.6"
|
150
|
+
},
|
151
|
+
"peerDependenciesMeta": {
|
152
|
+
"@multiformats/multiaddr": {
|
153
|
+
"optional": true
|
154
|
+
}
|
155
|
+
},
|
158
156
|
"typedoc": {
|
159
157
|
"entryPoint": "./src/index.ts"
|
160
158
|
},
|
@@ -163,7 +161,6 @@
|
|
163
161
|
"bundle",
|
164
162
|
"src/*.ts",
|
165
163
|
"src/lib/**/*.ts",
|
166
|
-
"src/proto/**/*.ts",
|
167
164
|
"!**/*.spec.*",
|
168
165
|
"!**/*.json",
|
169
166
|
"CHANGELOG.md",
|
package/src/index.ts
CHANGED
@@ -1,23 +1,34 @@
|
|
1
|
-
export { DefaultPubSubTopic } from "./lib/constants";
|
1
|
+
export { DefaultPubSubTopic } from "./lib/constants.js";
|
2
|
+
export { DefaultUserAgent } from "./lib/waku.js";
|
2
3
|
|
3
|
-
export
|
4
|
-
|
4
|
+
export {
|
5
|
+
createEncoder,
|
6
|
+
createDecoder,
|
7
|
+
DecodedMessage,
|
8
|
+
} from "./lib/message/version_0.js";
|
5
9
|
|
6
|
-
export * as waku from "./lib/waku";
|
7
|
-
export { WakuNode } from "./lib/waku";
|
10
|
+
export * as waku from "./lib/waku.js";
|
11
|
+
export { WakuNode } from "./lib/waku.js";
|
8
12
|
|
9
|
-
export * as waku_filter from "./lib/
|
10
|
-
export {
|
13
|
+
export * as waku_filter from "./lib/filter/index.js";
|
14
|
+
export { wakuFilter } from "./lib/filter/index.js";
|
11
15
|
|
12
|
-
export * as waku_light_push from "./lib/
|
16
|
+
export * as waku_light_push from "./lib/light_push/index.js";
|
13
17
|
export {
|
14
|
-
|
18
|
+
wakuLightPush,
|
15
19
|
LightPushCodec,
|
16
20
|
PushResponse,
|
17
|
-
} from "./lib/
|
21
|
+
} from "./lib/light_push/index.js";
|
22
|
+
|
23
|
+
export * as waku_relay from "./lib/relay/index.js";
|
24
|
+
export { wakuRelay } from "./lib/relay/index.js";
|
18
25
|
|
19
|
-
export * as
|
20
|
-
export {
|
26
|
+
export * as waku_store from "./lib/store/index.js";
|
27
|
+
export {
|
28
|
+
PageDirection,
|
29
|
+
wakuStore,
|
30
|
+
StoreCodec,
|
31
|
+
createCursor,
|
32
|
+
} from "./lib/store/index.js";
|
21
33
|
|
22
|
-
export
|
23
|
-
export { PageDirection, WakuStore, StoreCodec } from "./lib/waku_store";
|
34
|
+
export { waitForRemotePeer } from "./lib/wait_for_remote_peer.js";
|
@@ -1,39 +1,48 @@
|
|
1
1
|
import type { Stream } from "@libp2p/interface-connection";
|
2
|
+
import type { ConnectionManager } from "@libp2p/interface-connection-manager";
|
2
3
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
4
|
+
import type { PeerStore } from "@libp2p/interface-peer-store";
|
3
5
|
import type { Peer } from "@libp2p/interface-peer-store";
|
4
6
|
import type { IncomingStreamData } from "@libp2p/interface-registrar";
|
7
|
+
import type { Registrar } from "@libp2p/interface-registrar";
|
5
8
|
import type {
|
6
9
|
Callback,
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
IDecodedMessage,
|
11
|
+
IDecoder,
|
12
|
+
IFilter,
|
13
|
+
IMessage,
|
11
14
|
ProtocolOptions,
|
12
15
|
} from "@waku/interfaces";
|
16
|
+
import {
|
17
|
+
getPeersForProtocol,
|
18
|
+
selectConnection,
|
19
|
+
selectPeerForProtocol,
|
20
|
+
selectRandomPeer,
|
21
|
+
} from "@waku/libp2p-utils";
|
22
|
+
import { WakuMessage as WakuMessageProto } from "@waku/proto";
|
13
23
|
import debug from "debug";
|
14
24
|
import all from "it-all";
|
15
25
|
import * as lp from "it-length-prefixed";
|
16
26
|
import { pipe } from "it-pipe";
|
17
|
-
import type { Libp2p } from "libp2p";
|
18
27
|
|
19
|
-
import {
|
20
|
-
import {
|
21
|
-
import {
|
22
|
-
|
23
|
-
import {
|
24
|
-
getPeersForProtocol,
|
25
|
-
selectPeerForProtocol,
|
26
|
-
selectRandomPeer,
|
27
|
-
} from "../select_peer";
|
28
|
-
import { toProtoMessage } from "../to_proto_message";
|
28
|
+
import { DefaultPubSubTopic } from "../constants.js";
|
29
|
+
import { groupByContentTopic } from "../group_by.js";
|
30
|
+
import { toProtoMessage } from "../to_proto_message.js";
|
31
|
+
|
32
|
+
import { ContentFilter, FilterRPC } from "./filter_rpc.js";
|
29
33
|
|
30
|
-
import { ContentFilter, FilterRPC } from "./filter_rpc";
|
31
34
|
export { ContentFilter };
|
32
35
|
|
33
36
|
export const FilterCodec = "/vac/waku/filter/2.0.0-beta1";
|
34
37
|
|
35
38
|
const log = debug("waku:filter");
|
36
39
|
|
40
|
+
export interface FilterComponents {
|
41
|
+
peerStore: PeerStore;
|
42
|
+
registrar: Registrar;
|
43
|
+
connectionManager: ConnectionManager;
|
44
|
+
}
|
45
|
+
|
37
46
|
export interface CreateOptions {
|
38
47
|
/**
|
39
48
|
* The PubSub Topic to use. Defaults to {@link DefaultPubSubTopic}.
|
@@ -55,19 +64,19 @@ export type UnsubscribeFunction = () => Promise<void>;
|
|
55
64
|
* - https://github.com/status-im/go-waku/issues/245
|
56
65
|
* - https://github.com/status-im/nwaku/issues/948
|
57
66
|
*/
|
58
|
-
|
67
|
+
class Filter implements IFilter {
|
59
68
|
pubSubTopic: string;
|
60
69
|
private subscriptions: Map<string, Callback<any>>;
|
61
70
|
private decoders: Map<
|
62
71
|
string, // content topic
|
63
|
-
Set<
|
72
|
+
Set<IDecoder<any>>
|
64
73
|
>;
|
65
74
|
|
66
|
-
constructor(public
|
75
|
+
constructor(public components: FilterComponents, options?: CreateOptions) {
|
67
76
|
this.subscriptions = new Map();
|
68
77
|
this.decoders = new Map();
|
69
78
|
this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
|
70
|
-
this.
|
79
|
+
this.components.registrar
|
71
80
|
.handle(FilterCodec, this.onRequest.bind(this))
|
72
81
|
.catch((e) => log("Failed to register filter protocol", e));
|
73
82
|
}
|
@@ -78,8 +87,8 @@ export class WakuFilter implements Filter {
|
|
78
87
|
* @param opts The FilterSubscriptionOpts used to narrow which messages are returned, and which peer to connect to.
|
79
88
|
* @returns Unsubscribe function that can be used to end the subscription.
|
80
89
|
*/
|
81
|
-
async subscribe<T extends
|
82
|
-
decoders:
|
90
|
+
async subscribe<T extends IDecodedMessage>(
|
91
|
+
decoders: IDecoder<T>[],
|
83
92
|
callback: Callback<T>,
|
84
93
|
opts?: ProtocolOptions
|
85
94
|
): Promise<UnsubscribeFunction> {
|
@@ -139,6 +148,10 @@ export class WakuFilter implements Filter {
|
|
139
148
|
};
|
140
149
|
}
|
141
150
|
|
151
|
+
get peerStore(): PeerStore {
|
152
|
+
return this.components.peerStore;
|
153
|
+
}
|
154
|
+
|
142
155
|
private onRequest(streamData: IncomingStreamData): void {
|
143
156
|
log("Receiving message push");
|
144
157
|
try {
|
@@ -185,7 +198,7 @@ export class WakuFilter implements Filter {
|
|
185
198
|
return;
|
186
199
|
}
|
187
200
|
|
188
|
-
let msg:
|
201
|
+
let msg: IMessage | undefined;
|
189
202
|
// We don't want to wait for decoding failure, just attempt to decode
|
190
203
|
// all messages and do the call back on the one that works
|
191
204
|
// noinspection ES6MissingAwait
|
@@ -212,8 +225,8 @@ export class WakuFilter implements Filter {
|
|
212
225
|
this.subscriptions.delete(requestId);
|
213
226
|
}
|
214
227
|
|
215
|
-
private addDecoders<T extends
|
216
|
-
decoders: Map<string, Array<
|
228
|
+
private addDecoders<T extends IDecodedMessage>(
|
229
|
+
decoders: Map<string, Array<IDecoder<T>>>
|
217
230
|
): void {
|
218
231
|
decoders.forEach((decoders, contentTopic) => {
|
219
232
|
const currDecs = this.decoders.get(contentTopic);
|
@@ -225,8 +238,8 @@ export class WakuFilter implements Filter {
|
|
225
238
|
});
|
226
239
|
}
|
227
240
|
|
228
|
-
private deleteDecoders<T extends
|
229
|
-
decoders: Map<string, Array<
|
241
|
+
private deleteDecoders<T extends IDecodedMessage>(
|
242
|
+
decoders: Map<string, Array<IDecoder<T>>>
|
230
243
|
): void {
|
231
244
|
decoders.forEach((decoders, contentTopic) => {
|
232
245
|
const currDecs = this.decoders.get(contentTopic);
|
@@ -261,7 +274,9 @@ export class WakuFilter implements Filter {
|
|
261
274
|
}
|
262
275
|
|
263
276
|
private async newStream(peer: Peer): Promise<Stream> {
|
264
|
-
const connections = this.
|
277
|
+
const connections = this.components.connectionManager.getConnections(
|
278
|
+
peer.id
|
279
|
+
);
|
265
280
|
const connection = selectConnection(connections);
|
266
281
|
if (!connection) {
|
267
282
|
throw new Error("Failed to get a connection to the peer");
|
@@ -272,7 +287,7 @@ export class WakuFilter implements Filter {
|
|
272
287
|
|
273
288
|
private async getPeer(peerId?: PeerId): Promise<Peer> {
|
274
289
|
const res = await selectPeerForProtocol(
|
275
|
-
this.
|
290
|
+
this.components.peerStore,
|
276
291
|
[FilterCodec],
|
277
292
|
peerId
|
278
293
|
);
|
@@ -283,10 +298,16 @@ export class WakuFilter implements Filter {
|
|
283
298
|
}
|
284
299
|
|
285
300
|
async peers(): Promise<Peer[]> {
|
286
|
-
return getPeersForProtocol(this.
|
301
|
+
return getPeersForProtocol(this.components.peerStore, [FilterCodec]);
|
287
302
|
}
|
288
303
|
|
289
304
|
async randomPeer(): Promise<Peer | undefined> {
|
290
305
|
return selectRandomPeer(await this.peers());
|
291
306
|
}
|
292
307
|
}
|
308
|
+
|
309
|
+
export function wakuFilter(
|
310
|
+
init: Partial<CreateOptions> = {}
|
311
|
+
): (components: FilterComponents) => IFilter {
|
312
|
+
return (components: FilterComponents) => new Filter(components, init);
|
313
|
+
}
|
@@ -1,34 +1,41 @@
|
|
1
|
+
import { ConnectionManager } from "@libp2p/interface-connection-manager";
|
1
2
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
2
3
|
import type { Peer } from "@libp2p/interface-peer-store";
|
4
|
+
import type { PeerStore } from "@libp2p/interface-peer-store";
|
3
5
|
import type {
|
4
|
-
|
5
|
-
|
6
|
+
IEncoder,
|
7
|
+
ILightPush,
|
8
|
+
IMessage,
|
6
9
|
ProtocolOptions,
|
7
10
|
SendResult,
|
8
11
|
} from "@waku/interfaces";
|
12
|
+
import {
|
13
|
+
getPeersForProtocol,
|
14
|
+
selectConnection,
|
15
|
+
selectPeerForProtocol,
|
16
|
+
selectRandomPeer,
|
17
|
+
} from "@waku/libp2p-utils";
|
18
|
+
import { PushResponse } from "@waku/proto";
|
9
19
|
import debug from "debug";
|
10
20
|
import all from "it-all";
|
11
21
|
import * as lp from "it-length-prefixed";
|
12
22
|
import { pipe } from "it-pipe";
|
13
|
-
import { Libp2p } from "libp2p";
|
14
23
|
import { Uint8ArrayList } from "uint8arraylist";
|
15
24
|
|
16
|
-
import {
|
17
|
-
import { DefaultPubSubTopic } from "../constants";
|
18
|
-
import { selectConnection } from "../select_connection";
|
19
|
-
import {
|
20
|
-
getPeersForProtocol,
|
21
|
-
selectPeerForProtocol,
|
22
|
-
selectRandomPeer,
|
23
|
-
} from "../select_peer";
|
25
|
+
import { DefaultPubSubTopic } from "../constants.js";
|
24
26
|
|
25
|
-
import { PushRPC } from "./push_rpc";
|
27
|
+
import { PushRPC } from "./push_rpc.js";
|
26
28
|
|
27
29
|
const log = debug("waku:light-push");
|
28
30
|
|
29
31
|
export const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
30
32
|
export { PushResponse };
|
31
33
|
|
34
|
+
export interface LightPushComponents {
|
35
|
+
peerStore: PeerStore;
|
36
|
+
connectionManager: ConnectionManager;
|
37
|
+
}
|
38
|
+
|
32
39
|
export interface CreateOptions {
|
33
40
|
/**
|
34
41
|
* The PubSub Topic to use. Defaults to {@link DefaultPubSubTopic}.
|
@@ -44,22 +51,22 @@ export interface CreateOptions {
|
|
44
51
|
/**
|
45
52
|
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
46
53
|
*/
|
47
|
-
|
54
|
+
class LightPush implements ILightPush {
|
48
55
|
pubSubTopic: string;
|
49
56
|
|
50
|
-
constructor(public
|
57
|
+
constructor(public components: LightPushComponents, options?: CreateOptions) {
|
51
58
|
this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
|
52
59
|
}
|
53
60
|
|
54
61
|
async push(
|
55
|
-
encoder:
|
56
|
-
message:
|
62
|
+
encoder: IEncoder,
|
63
|
+
message: IMessage,
|
57
64
|
opts?: ProtocolOptions
|
58
65
|
): Promise<SendResult> {
|
59
66
|
const pubSubTopic = opts?.pubSubTopic ? opts.pubSubTopic : this.pubSubTopic;
|
60
67
|
|
61
68
|
const res = await selectPeerForProtocol(
|
62
|
-
this.
|
69
|
+
this.components.peerStore,
|
63
70
|
[LightPushCodec],
|
64
71
|
opts?.peerId
|
65
72
|
);
|
@@ -69,7 +76,9 @@ export class WakuLightPush {
|
|
69
76
|
}
|
70
77
|
const { peer } = res;
|
71
78
|
|
72
|
-
const connections = this.
|
79
|
+
const connections = this.components.connectionManager.getConnections(
|
80
|
+
peer.id
|
81
|
+
);
|
73
82
|
const connection = selectConnection(connections);
|
74
83
|
|
75
84
|
if (!connection) throw "Failed to get a connection to the peer";
|
@@ -123,7 +132,7 @@ export class WakuLightPush {
|
|
123
132
|
* peers.
|
124
133
|
*/
|
125
134
|
async peers(): Promise<Peer[]> {
|
126
|
-
return getPeersForProtocol(this.
|
135
|
+
return getPeersForProtocol(this.components.peerStore, [LightPushCodec]);
|
127
136
|
}
|
128
137
|
|
129
138
|
/**
|
@@ -134,4 +143,14 @@ export class WakuLightPush {
|
|
134
143
|
async randomPeer(): Promise<Peer | undefined> {
|
135
144
|
return selectRandomPeer(await this.peers());
|
136
145
|
}
|
146
|
+
|
147
|
+
get peerStore(): PeerStore {
|
148
|
+
return this.components.peerStore;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
export function wakuLightPush(
|
153
|
+
init: Partial<CreateOptions> = {}
|
154
|
+
): (components: LightPushComponents) => ILightPush {
|
155
|
+
return (components: LightPushComponents) => new LightPush(components, init);
|
137
156
|
}
|
@@ -1,8 +1,7 @@
|
|
1
|
+
import { proto_lightpush as proto } from "@waku/proto";
|
1
2
|
import type { Uint8ArrayList } from "uint8arraylist";
|
2
3
|
import { v4 as uuid } from "uuid";
|
3
4
|
|
4
|
-
import * as proto from "../../proto/light_push";
|
5
|
-
|
6
5
|
export class PushRPC {
|
7
6
|
public constructor(public proto: proto.PushRPC) {}
|
8
7
|
|
@@ -1,14 +1,18 @@
|
|
1
|
-
import type {
|
1
|
+
import type {
|
2
|
+
IDecodedMessage,
|
3
|
+
IDecoder,
|
4
|
+
IProtoMessage,
|
5
|
+
} from "@waku/interfaces";
|
6
|
+
import { proto_topic_only_message as proto } from "@waku/proto";
|
2
7
|
import debug from "debug";
|
3
8
|
|
4
|
-
import * as proto from "../../proto/topic_only_message";
|
5
|
-
|
6
9
|
const log = debug("waku:message:topic-only");
|
7
10
|
|
8
|
-
export class TopicOnlyMessage implements
|
11
|
+
export class TopicOnlyMessage implements IDecodedMessage {
|
9
12
|
public payload: undefined;
|
10
13
|
public rateLimitProof: undefined;
|
11
14
|
public timestamp: undefined;
|
15
|
+
public ephemeral: undefined;
|
12
16
|
|
13
17
|
constructor(private proto: proto.TopicOnlyMessage) {}
|
14
18
|
|
@@ -17,10 +21,10 @@ export class TopicOnlyMessage implements Message {
|
|
17
21
|
}
|
18
22
|
}
|
19
23
|
|
20
|
-
export class TopicOnlyDecoder implements
|
24
|
+
export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
|
21
25
|
public contentTopic = "";
|
22
26
|
|
23
|
-
fromWireToProtoObj(bytes: Uint8Array): Promise<
|
27
|
+
fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> {
|
24
28
|
const protoMessage = proto.TopicOnlyMessage.decode(bytes);
|
25
29
|
log("Message decoded", protoMessage);
|
26
30
|
return Promise.resolve({
|
@@ -29,11 +33,12 @@ export class TopicOnlyDecoder implements Decoder<TopicOnlyMessage> {
|
|
29
33
|
rateLimitProof: undefined,
|
30
34
|
timestamp: undefined,
|
31
35
|
version: undefined,
|
36
|
+
ephemeral: undefined,
|
32
37
|
});
|
33
38
|
}
|
34
39
|
|
35
40
|
async fromProtoObj(
|
36
|
-
proto:
|
41
|
+
proto: IProtoMessage
|
37
42
|
): Promise<TopicOnlyMessage | undefined> {
|
38
43
|
return new TopicOnlyMessage(proto);
|
39
44
|
}
|