@waku/core 0.0.26-7eb3375.0 → 0.0.26
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 +30 -0
- package/bundle/{base_protocol-46017f51.js → base_protocol-pDODy0G6.js} +22 -230
- package/bundle/{browser-9a6558bb.js → browser-mTOOnVZp.js} +80 -1
- package/bundle/index-cmONXM-V.js +595 -0
- package/bundle/index.js +358 -425
- package/bundle/lib/base_protocol.js +3 -3
- package/bundle/lib/message/version_0.js +3 -3
- package/bundle/lib/predefined_bootstrap_nodes.js +1 -1
- package/bundle/{version_0-7190df43.js → version_0-LQTFNC7k.js} +118 -11
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +3 -2
- package/dist/lib/base_protocol.js +12 -6
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager.js.map +1 -1
- package/dist/lib/filter/index.js +7 -4
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/filterPeers.js.map +1 -1
- package/dist/lib/keep_alive_manager.js +2 -2
- package/dist/lib/keep_alive_manager.js.map +1 -1
- package/dist/lib/light_push/index.js +1 -2
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/message/version_0.d.ts +3 -3
- package/dist/lib/message/version_0.js +5 -6
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/metadata/index.d.ts +3 -0
- package/dist/lib/metadata/index.js +67 -0
- package/dist/lib/metadata/index.js.map +1 -0
- package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
- package/dist/lib/store/history_rpc.js.map +1 -1
- package/dist/lib/store/index.js +1 -2
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/stream_manager.js.map +1 -1
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/dist/lib/waku.d.ts +3 -3
- package/dist/lib/waku.js +12 -6
- package/dist/lib/waku.js.map +1 -1
- package/package.json +127 -1
- package/src/index.ts +3 -1
- package/src/lib/base_protocol.ts +29 -7
- package/src/lib/filter/index.ts +10 -3
- package/src/lib/keep_alive_manager.ts +2 -2
- package/src/lib/light_push/index.ts +1 -2
- package/src/lib/message/version_0.ts +16 -8
- package/src/lib/metadata/index.ts +110 -0
- package/src/lib/store/index.ts +1 -2
- package/src/lib/waku.ts +14 -4
- package/bundle/index-7581d519.js +0 -31
- package/dist/lib/constants.d.ts +0 -4
- package/dist/lib/constants.js +0 -5
- package/dist/lib/constants.js.map +0 -1
- package/src/lib/constants.ts +0 -4
package/dist/lib/waku.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"waku.js","sourceRoot":"","sources":["../../src/lib/waku.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAU,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAA6B,MAAM,yBAAyB,CAAC;
|
1
|
+
{"version":3,"file":"waku.js","sourceRoot":"","sources":["../../src/lib/waku.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAU,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAA6B,MAAM,yBAAyB,CAAC;AAW/E,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,GAAG,EAAE,CAAC;AACpD,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,GAAG,EAAE,CAAC;AACrD,MAAM,CAAC,MAAM,gBAAgB,GAAG,SAAS,CAAC;AAE1C,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;AAwB/B,MAAM,OAAO,QAAQ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AAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC;QAC9B,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACH,uBAAuB;QACrB,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM;aAC/B,aAAa,EAAE;aACf,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;QACzD,IAAI,CAAC,cAAc,IAAI,cAAc,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC;YACxD,MAAM,4BAA4B,CAAC;QACrC,CAAC;QACD,OAAO,cAAc,GAAG,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAClE,CAAC;CACF;AACD,SAAS,sBAAsB,CAC7B,MAA+B;IAE/B,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AACvD,CAAC"}
|
package/package.json
CHANGED
@@ -1 +1,127 @@
|
|
1
|
-
{
|
1
|
+
{
|
2
|
+
"name": "@waku/core",
|
3
|
+
"version": "0.0.26",
|
4
|
+
"description": "TypeScript implementation of the Waku v2 protocol",
|
5
|
+
"types": "./dist/index.d.ts",
|
6
|
+
"module": "./dist/index.js",
|
7
|
+
"exports": {
|
8
|
+
".": {
|
9
|
+
"types": "./dist/index.d.ts",
|
10
|
+
"import": "./dist/index.js"
|
11
|
+
},
|
12
|
+
"./lib/predefined_bootstrap_nodes": {
|
13
|
+
"types": "./dist/lib/predefined_bootstrap_nodes.d.ts",
|
14
|
+
"import": "./dist/lib/predefined_bootstrap_nodes.js"
|
15
|
+
},
|
16
|
+
"./lib/message/version_0": {
|
17
|
+
"types": "./dist/lib/message/version_0.d.ts",
|
18
|
+
"import": "./dist/lib/message/version_0.js"
|
19
|
+
},
|
20
|
+
"./lib/base_protocol": {
|
21
|
+
"types": "./dist/lib/base_protocol.d.ts",
|
22
|
+
"import": "./dist/lib/base_protocol.js"
|
23
|
+
}
|
24
|
+
},
|
25
|
+
"typesVersions": {
|
26
|
+
"*": {
|
27
|
+
"lib/*": [
|
28
|
+
"dist/lib/*"
|
29
|
+
],
|
30
|
+
"constants/*": [
|
31
|
+
"dist/constants/*"
|
32
|
+
]
|
33
|
+
}
|
34
|
+
},
|
35
|
+
"type": "module",
|
36
|
+
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/core#readme",
|
37
|
+
"repository": {
|
38
|
+
"type": "git",
|
39
|
+
"url": "https://github.com/waku-org/js-waku.git"
|
40
|
+
},
|
41
|
+
"bugs": {
|
42
|
+
"url": "https://github.com/waku-org/js-waku/issues"
|
43
|
+
},
|
44
|
+
"license": "MIT OR Apache-2.0",
|
45
|
+
"keywords": [
|
46
|
+
"waku",
|
47
|
+
"decentralised",
|
48
|
+
"communication",
|
49
|
+
"web3",
|
50
|
+
"ethereum",
|
51
|
+
"dapps"
|
52
|
+
],
|
53
|
+
"scripts": {
|
54
|
+
"build": "run-s build:**",
|
55
|
+
"build:esm": "tsc",
|
56
|
+
"build:bundle": "rollup --config rollup.config.js",
|
57
|
+
"fix": "run-s fix:*",
|
58
|
+
"fix:lint": "eslint src *.js --fix",
|
59
|
+
"check": "run-s check:*",
|
60
|
+
"check:tsc": "tsc -p tsconfig.dev.json",
|
61
|
+
"check:lint": "eslint src *.js",
|
62
|
+
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
|
63
|
+
"test": "NODE_ENV=test run-s test:*",
|
64
|
+
"test:node": "NODE_ENV=test TS_NODE_PROJECT=./tsconfig.dev.json mocha",
|
65
|
+
"test:browser": "NODE_ENV=test karma start karma.conf.cjs",
|
66
|
+
"watch:build": "tsc -p tsconfig.json -w",
|
67
|
+
"watch:test": "mocha --watch",
|
68
|
+
"prepublish": "npm run build",
|
69
|
+
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
|
70
|
+
},
|
71
|
+
"engines": {
|
72
|
+
"node": ">=18"
|
73
|
+
},
|
74
|
+
"dependencies": {
|
75
|
+
"@noble/hashes": "^1.3.2",
|
76
|
+
"@waku/enr": "^0.0.20",
|
77
|
+
"@waku/interfaces": "0.0.21",
|
78
|
+
"@waku/proto": "0.0.6",
|
79
|
+
"@waku/utils": "0.0.14",
|
80
|
+
"debug": "^4.3.4",
|
81
|
+
"it-all": "^3.0.4",
|
82
|
+
"it-length-prefixed": "^9.0.1",
|
83
|
+
"it-pipe": "^3.0.1",
|
84
|
+
"p-event": "^6.0.0",
|
85
|
+
"uint8arraylist": "^2.4.3",
|
86
|
+
"uuid": "^9.0.0"
|
87
|
+
},
|
88
|
+
"devDependencies": {
|
89
|
+
"@multiformats/multiaddr": "^12.0.0",
|
90
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
91
|
+
"@rollup/plugin-json": "^6.0.0",
|
92
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
93
|
+
"@types/chai": "^4.3.11",
|
94
|
+
"@types/debug": "^4.1.12",
|
95
|
+
"@types/mocha": "^10.0.1",
|
96
|
+
"@types/uuid": "^9.0.7",
|
97
|
+
"@waku/build-utils": "*",
|
98
|
+
"chai": "^4.3.10",
|
99
|
+
"cspell": "^7.3.2",
|
100
|
+
"fast-check": "^3.14.0",
|
101
|
+
"ignore-loader": "^0.1.2",
|
102
|
+
"isomorphic-fetch": "^3.0.0",
|
103
|
+
"mocha": "^10.2.0",
|
104
|
+
"npm-run-all": "^4.1.5",
|
105
|
+
"process": "^0.11.10",
|
106
|
+
"rollup": "^4.6.0"
|
107
|
+
},
|
108
|
+
"peerDependencies": {
|
109
|
+
"@multiformats/multiaddr": "^12.0.0",
|
110
|
+
"libp2p": "^0.46.3"
|
111
|
+
},
|
112
|
+
"peerDependenciesMeta": {
|
113
|
+
"@multiformats/multiaddr": {
|
114
|
+
"optional": true
|
115
|
+
}
|
116
|
+
},
|
117
|
+
"files": [
|
118
|
+
"dist",
|
119
|
+
"bundle",
|
120
|
+
"src/**/*.ts",
|
121
|
+
"!**/*.spec.*",
|
122
|
+
"!**/*.json",
|
123
|
+
"CHANGELOG.md",
|
124
|
+
"LICENSE",
|
125
|
+
"README.md"
|
126
|
+
]
|
127
|
+
}
|
package/src/index.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
export { DefaultUserAgent } from "./lib/waku.js";
|
2
|
-
export { DefaultPubsubTopic } from "./lib/constants.js";
|
3
2
|
export { createEncoder, createDecoder } from "./lib/message/version_0.js";
|
4
3
|
export type {
|
5
4
|
Encoder,
|
@@ -15,6 +14,7 @@ export * as waku_filter from "./lib/filter/index.js";
|
|
15
14
|
export { wakuFilter, FilterCodecs } from "./lib/filter/index.js";
|
16
15
|
|
17
16
|
export * as waku_light_push from "./lib/light_push/index.js";
|
17
|
+
export { LightPushCodec } from "./lib/light_push/index.js";
|
18
18
|
export { wakuLightPush } from "./lib/light_push/index.js";
|
19
19
|
|
20
20
|
export * as waku_store from "./lib/store/index.js";
|
@@ -27,3 +27,5 @@ export { ConnectionManager } from "./lib/connection_manager.js";
|
|
27
27
|
|
28
28
|
export { KeepAliveManager } from "./lib/keep_alive_manager.js";
|
29
29
|
export { StreamManager } from "./lib/stream_manager.js";
|
30
|
+
|
31
|
+
export { MetadataCodec, wakuMetadata } from "./lib/metadata/index.js";
|
package/src/lib/base_protocol.ts
CHANGED
@@ -2,8 +2,19 @@ import type { Libp2p } from "@libp2p/interface";
|
|
2
2
|
import type { Stream } from "@libp2p/interface/connection";
|
3
3
|
import type { PeerId } from "@libp2p/interface/peer-id";
|
4
4
|
import { Peer, PeerStore } from "@libp2p/interface/peer-store";
|
5
|
-
import type {
|
6
|
-
|
5
|
+
import type {
|
6
|
+
IBaseProtocol,
|
7
|
+
Libp2pComponents,
|
8
|
+
ProtocolCreateOptions,
|
9
|
+
PubsubTopic
|
10
|
+
} from "@waku/interfaces";
|
11
|
+
import { DefaultPubsubTopic } from "@waku/interfaces";
|
12
|
+
import { shardInfoToPubsubTopics } from "@waku/utils";
|
13
|
+
import {
|
14
|
+
getConnectedPeersForProtocol,
|
15
|
+
getPeersForProtocol,
|
16
|
+
selectPeerForProtocol
|
17
|
+
} from "@waku/utils/libp2p";
|
7
18
|
|
8
19
|
import { filterPeers } from "./filterPeers.js";
|
9
20
|
import { StreamManager } from "./stream_manager.js";
|
@@ -63,7 +74,7 @@ export class BaseProtocol implements IBaseProtocol {
|
|
63
74
|
}
|
64
75
|
|
65
76
|
/**
|
66
|
-
* Retrieves a list of peers based on the specified criteria.
|
77
|
+
* Retrieves a list of connected peers based on the specified criteria.
|
67
78
|
*
|
68
79
|
* @param numPeers - The total number of peers to retrieve. If 0, all peers are returned.
|
69
80
|
* @param maxBootstrapPeers - The maximum number of bootstrap peers to retrieve.
|
@@ -81,12 +92,23 @@ export class BaseProtocol implements IBaseProtocol {
|
|
81
92
|
numPeers: 0
|
82
93
|
}
|
83
94
|
): Promise<Peer[]> {
|
84
|
-
// Retrieve all peers that support the protocol
|
85
|
-
const allPeersForProtocol = await
|
86
|
-
this.
|
87
|
-
|
95
|
+
// Retrieve all connected peers that support the protocol
|
96
|
+
const allPeersForProtocol = await getConnectedPeersForProtocol(
|
97
|
+
this.components.connectionManager.getConnections(),
|
98
|
+
this.peerStore,
|
99
|
+
[this.multicodec]
|
100
|
+
);
|
88
101
|
|
89
102
|
// Filter the peers based on the specified criteria
|
90
103
|
return filterPeers(allPeersForProtocol, numPeers, maxBootstrapPeers);
|
91
104
|
}
|
105
|
+
|
106
|
+
initializePubsubTopic(options?: ProtocolCreateOptions): PubsubTopic[] {
|
107
|
+
return (
|
108
|
+
options?.pubsubTopics ??
|
109
|
+
(options?.shardInfo
|
110
|
+
? shardInfoToPubsubTopics(options.shardInfo)
|
111
|
+
: [DefaultPubsubTopic])
|
112
|
+
);
|
113
|
+
}
|
92
114
|
}
|
package/src/lib/filter/index.ts
CHANGED
@@ -14,12 +14,15 @@ import type {
|
|
14
14
|
PeerIdStr,
|
15
15
|
ProtocolCreateOptions,
|
16
16
|
PubsubTopic,
|
17
|
+
SingleShardInfo,
|
17
18
|
Unsubscribe
|
18
19
|
} from "@waku/interfaces";
|
20
|
+
import { DefaultPubsubTopic } from "@waku/interfaces";
|
19
21
|
import { WakuMessage } from "@waku/proto";
|
20
22
|
import {
|
21
23
|
ensurePubsubTopicIsConfigured,
|
22
24
|
groupByContentTopic,
|
25
|
+
singleShardInfoToPubsubTopic,
|
23
26
|
toAsyncIterator
|
24
27
|
} from "@waku/utils";
|
25
28
|
import { Logger } from "@waku/utils";
|
@@ -28,7 +31,6 @@ import * as lp from "it-length-prefixed";
|
|
28
31
|
import { pipe } from "it-pipe";
|
29
32
|
|
30
33
|
import { BaseProtocol } from "../base_protocol.js";
|
31
|
-
import { DefaultPubsubTopic } from "../constants.js";
|
32
34
|
|
33
35
|
import {
|
34
36
|
FilterPushRpc,
|
@@ -279,7 +281,7 @@ class Filter extends BaseProtocol implements IReceiver {
|
|
279
281
|
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
|
280
282
|
super(FilterCodecs.SUBSCRIBE, libp2p.components);
|
281
283
|
|
282
|
-
this.pubsubTopics = options
|
284
|
+
this.pubsubTopics = this.initializePubsubTopic(options);
|
283
285
|
|
284
286
|
libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this)).catch((e) => {
|
285
287
|
log.error("Failed to register ", FilterCodecs.PUSH, e);
|
@@ -289,8 +291,13 @@ class Filter extends BaseProtocol implements IReceiver {
|
|
289
291
|
}
|
290
292
|
|
291
293
|
async createSubscription(
|
292
|
-
|
294
|
+
pubsubTopicShardInfo: SingleShardInfo | PubsubTopic = DefaultPubsubTopic
|
293
295
|
): Promise<Subscription> {
|
296
|
+
const pubsubTopic =
|
297
|
+
typeof pubsubTopicShardInfo == "string"
|
298
|
+
? pubsubTopicShardInfo
|
299
|
+
: singleShardInfoToPubsubTopic(pubsubTopicShardInfo);
|
300
|
+
|
294
301
|
ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics);
|
295
302
|
|
296
303
|
//TODO: get a relevant peer for the topic/shard
|
@@ -2,7 +2,7 @@ import type { PeerId } from "@libp2p/interface/peer-id";
|
|
2
2
|
import type { PeerStore } from "@libp2p/interface/peer-store";
|
3
3
|
import type { IRelay, PeerIdStr } from "@waku/interfaces";
|
4
4
|
import type { KeepAliveOptions } from "@waku/interfaces";
|
5
|
-
import { Logger } from "@waku/utils";
|
5
|
+
import { Logger, pubsubTopicToSingleShardInfo } from "@waku/utils";
|
6
6
|
import { utf8ToBytes } from "@waku/utils/bytes";
|
7
7
|
import type { PingService } from "libp2p/ping";
|
8
8
|
|
@@ -129,7 +129,7 @@ export class KeepAliveManager {
|
|
129
129
|
if (!meshPeers.includes(peerIdStr)) continue;
|
130
130
|
|
131
131
|
const encoder = createEncoder({
|
132
|
-
|
132
|
+
pubsubTopicShardInfo: pubsubTopicToSingleShardInfo(topic),
|
133
133
|
contentTopic: RelayPingContentTopic,
|
134
134
|
ephemeral: true
|
135
135
|
});
|
@@ -22,7 +22,6 @@ import { pipe } from "it-pipe";
|
|
22
22
|
import { Uint8ArrayList } from "uint8arraylist";
|
23
23
|
|
24
24
|
import { BaseProtocol } from "../base_protocol.js";
|
25
|
-
import { DefaultPubsubTopic } from "../constants.js";
|
26
25
|
|
27
26
|
import { PushRpc } from "./push_rpc.js";
|
28
27
|
|
@@ -50,7 +49,7 @@ class LightPush extends BaseProtocol implements ILightPush {
|
|
50
49
|
|
51
50
|
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
|
52
51
|
super(LightPushCodec, libp2p.components);
|
53
|
-
this.pubsubTopics = options
|
52
|
+
this.pubsubTopics = this.initializePubsubTopic(options);
|
54
53
|
}
|
55
54
|
|
56
55
|
private async preparePushMessage(
|
@@ -7,12 +7,11 @@ import type {
|
|
7
7
|
IMetaSetter,
|
8
8
|
IProtoMessage,
|
9
9
|
IRateLimitProof,
|
10
|
-
PubsubTopic
|
10
|
+
PubsubTopic,
|
11
|
+
SingleShardInfo
|
11
12
|
} from "@waku/interfaces";
|
12
13
|
import { proto_message as proto } from "@waku/proto";
|
13
|
-
import { Logger } from "@waku/utils";
|
14
|
-
|
15
|
-
import { DefaultPubsubTopic } from "../constants.js";
|
14
|
+
import { determinePubsubTopic, Logger } from "@waku/utils";
|
16
15
|
|
17
16
|
const log = new Logger("message:version-0");
|
18
17
|
const OneMillion = BigInt(1_000_000);
|
@@ -119,12 +118,18 @@ export class Encoder implements IEncoder {
|
|
119
118
|
* messages.
|
120
119
|
*/
|
121
120
|
export function createEncoder({
|
122
|
-
pubsubTopic
|
121
|
+
pubsubTopic,
|
122
|
+
pubsubTopicShardInfo,
|
123
123
|
contentTopic,
|
124
124
|
ephemeral,
|
125
125
|
metaSetter
|
126
126
|
}: EncoderOptions): Encoder {
|
127
|
-
return new Encoder(
|
127
|
+
return new Encoder(
|
128
|
+
contentTopic,
|
129
|
+
ephemeral,
|
130
|
+
determinePubsubTopic(contentTopic, pubsubTopic ?? pubsubTopicShardInfo),
|
131
|
+
metaSetter
|
132
|
+
);
|
128
133
|
}
|
129
134
|
|
130
135
|
export class Decoder implements IDecoder<DecodedMessage> {
|
@@ -182,7 +187,10 @@ export class Decoder implements IDecoder<DecodedMessage> {
|
|
182
187
|
*/
|
183
188
|
export function createDecoder(
|
184
189
|
contentTopic: string,
|
185
|
-
|
190
|
+
pubsubTopicShardInfo?: SingleShardInfo | PubsubTopic
|
186
191
|
): Decoder {
|
187
|
-
return new Decoder(
|
192
|
+
return new Decoder(
|
193
|
+
determinePubsubTopic(contentTopic, pubsubTopicShardInfo),
|
194
|
+
contentTopic
|
195
|
+
);
|
188
196
|
}
|
@@ -0,0 +1,110 @@
|
|
1
|
+
import type { PeerId } from "@libp2p/interface/peer-id";
|
2
|
+
import { IncomingStreamData } from "@libp2p/interface/stream-handler";
|
3
|
+
import { encodeRelayShard } from "@waku/enr";
|
4
|
+
import type {
|
5
|
+
IMetadata,
|
6
|
+
Libp2pComponents,
|
7
|
+
ShardInfo,
|
8
|
+
ShardingParams
|
9
|
+
} from "@waku/interfaces";
|
10
|
+
import { proto_metadata } from "@waku/proto";
|
11
|
+
import { Logger } from "@waku/utils";
|
12
|
+
import all from "it-all";
|
13
|
+
import * as lp from "it-length-prefixed";
|
14
|
+
import { pipe } from "it-pipe";
|
15
|
+
import { Uint8ArrayList } from "uint8arraylist";
|
16
|
+
|
17
|
+
import { BaseProtocol } from "../base_protocol.js";
|
18
|
+
|
19
|
+
const log = new Logger("metadata");
|
20
|
+
|
21
|
+
export const MetadataCodec = "/vac/waku/metadata/1.0.0";
|
22
|
+
|
23
|
+
class Metadata extends BaseProtocol {
|
24
|
+
private readonly shardInfo: ShardingParams;
|
25
|
+
private libp2pComponents: Libp2pComponents;
|
26
|
+
constructor(shardInfo: ShardingParams, libp2p: Libp2pComponents) {
|
27
|
+
super(MetadataCodec, libp2p.components);
|
28
|
+
this.libp2pComponents = libp2p;
|
29
|
+
this.shardInfo = shardInfo;
|
30
|
+
void libp2p.registrar.handle(MetadataCodec, (streamData) => {
|
31
|
+
void this.onRequest(streamData);
|
32
|
+
});
|
33
|
+
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Handle an incoming metadata request
|
37
|
+
*/
|
38
|
+
private async onRequest(streamData: IncomingStreamData): Promise<void> {
|
39
|
+
try {
|
40
|
+
const { stream, connection } = streamData;
|
41
|
+
const encodedShardInfo = proto_metadata.WakuMetadataResponse.encode(
|
42
|
+
this.shardInfo
|
43
|
+
);
|
44
|
+
|
45
|
+
const encodedResponse = await pipe(
|
46
|
+
[encodedShardInfo],
|
47
|
+
lp.encode,
|
48
|
+
stream,
|
49
|
+
lp.decode,
|
50
|
+
async (source) => await all(source)
|
51
|
+
);
|
52
|
+
|
53
|
+
const remoteShardInfoResponse =
|
54
|
+
this.decodeMetadataResponse(encodedResponse);
|
55
|
+
|
56
|
+
// add or update the shardInfo to peer store
|
57
|
+
await this.libp2pComponents.peerStore.merge(connection.remotePeer, {
|
58
|
+
metadata: {
|
59
|
+
shardInfo: encodeRelayShard(remoteShardInfoResponse)
|
60
|
+
}
|
61
|
+
});
|
62
|
+
} catch (error) {
|
63
|
+
log.error("Error handling metadata request", error);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Make a metadata query to a peer
|
69
|
+
*/
|
70
|
+
async query(peerId: PeerId): Promise<ShardInfo> {
|
71
|
+
const request = proto_metadata.WakuMetadataRequest.encode(this.shardInfo);
|
72
|
+
|
73
|
+
const peer = await this.getPeer(peerId);
|
74
|
+
|
75
|
+
const stream = await this.getStream(peer);
|
76
|
+
|
77
|
+
const encodedResponse = await pipe(
|
78
|
+
[request],
|
79
|
+
lp.encode,
|
80
|
+
stream,
|
81
|
+
lp.decode,
|
82
|
+
async (source) => await all(source)
|
83
|
+
);
|
84
|
+
|
85
|
+
const decodedResponse = this.decodeMetadataResponse(encodedResponse);
|
86
|
+
|
87
|
+
return decodedResponse;
|
88
|
+
}
|
89
|
+
|
90
|
+
private decodeMetadataResponse(encodedResponse: Uint8ArrayList[]): ShardInfo {
|
91
|
+
const bytes = new Uint8ArrayList();
|
92
|
+
|
93
|
+
encodedResponse.forEach((chunk) => {
|
94
|
+
bytes.append(chunk);
|
95
|
+
});
|
96
|
+
const response = proto_metadata.WakuMetadataResponse.decode(
|
97
|
+
bytes
|
98
|
+
) as ShardInfo;
|
99
|
+
|
100
|
+
if (!response) log.error("Error decoding metadata response");
|
101
|
+
|
102
|
+
return response;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
export function wakuMetadata(
|
107
|
+
shardInfo: ShardingParams
|
108
|
+
): (components: Libp2pComponents) => IMetadata {
|
109
|
+
return (components: Libp2pComponents) => new Metadata(shardInfo, components);
|
110
|
+
}
|
package/src/lib/store/index.ts
CHANGED
@@ -19,7 +19,6 @@ import { pipe } from "it-pipe";
|
|
19
19
|
import { Uint8ArrayList } from "uint8arraylist";
|
20
20
|
|
21
21
|
import { BaseProtocol } from "../base_protocol.js";
|
22
|
-
import { DefaultPubsubTopic } from "../constants.js";
|
23
22
|
import { toProtoMessage } from "../to_proto_message.js";
|
24
23
|
|
25
24
|
import { HistoryRpc, PageDirection, Params } from "./history_rpc.js";
|
@@ -80,7 +79,7 @@ class Store extends BaseProtocol implements IStore {
|
|
80
79
|
|
81
80
|
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
|
82
81
|
super(StoreCodec, libp2p.components);
|
83
|
-
this.pubsubTopics = options
|
82
|
+
this.pubsubTopics = this.initializePubsubTopic(options);
|
84
83
|
}
|
85
84
|
|
86
85
|
/**
|
package/src/lib/waku.ts
CHANGED
@@ -8,10 +8,11 @@ import type {
|
|
8
8
|
IStore,
|
9
9
|
Libp2p,
|
10
10
|
PubsubTopic,
|
11
|
+
ShardingParams,
|
11
12
|
Waku
|
12
13
|
} from "@waku/interfaces";
|
13
|
-
import { Protocols } from "@waku/interfaces";
|
14
|
-
import { Logger } from "@waku/utils";
|
14
|
+
import { DefaultPubsubTopic, Protocols } from "@waku/interfaces";
|
15
|
+
import { Logger, shardInfoToPubsubTopics } from "@waku/utils";
|
15
16
|
|
16
17
|
import { ConnectionManager } from "./connection_manager.js";
|
17
18
|
|
@@ -50,16 +51,25 @@ export class WakuNode implements Waku {
|
|
50
51
|
public filter?: IFilter;
|
51
52
|
public lightPush?: ILightPush;
|
52
53
|
public connectionManager: ConnectionManager;
|
54
|
+
public readonly pubsubTopics: PubsubTopic[];
|
53
55
|
|
54
56
|
constructor(
|
55
57
|
options: WakuOptions,
|
56
|
-
|
58
|
+
pubsubTopics: PubsubTopic[] = [],
|
57
59
|
libp2p: Libp2p,
|
60
|
+
pubsubShardInfo?: ShardingParams,
|
58
61
|
store?: (libp2p: Libp2p) => IStore,
|
59
62
|
lightPush?: (libp2p: Libp2p) => ILightPush,
|
60
63
|
filter?: (libp2p: Libp2p) => IFilter,
|
61
64
|
relay?: (libp2p: Libp2p) => IRelay
|
62
65
|
) {
|
66
|
+
if (!pubsubShardInfo) {
|
67
|
+
this.pubsubTopics =
|
68
|
+
pubsubTopics.length > 0 ? pubsubTopics : [DefaultPubsubTopic];
|
69
|
+
} else {
|
70
|
+
this.pubsubTopics = shardInfoToPubsubTopics(pubsubShardInfo);
|
71
|
+
}
|
72
|
+
|
63
73
|
this.libp2p = libp2p;
|
64
74
|
|
65
75
|
if (store) {
|
@@ -88,7 +98,7 @@ export class WakuNode implements Waku {
|
|
88
98
|
peerId,
|
89
99
|
libp2p,
|
90
100
|
{ pingKeepAlive, relayKeepAlive },
|
91
|
-
pubsubTopics,
|
101
|
+
this.pubsubTopics,
|
92
102
|
this.relay
|
93
103
|
);
|
94
104
|
|
package/bundle/index-7581d519.js
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
import { r as debug } from './browser-9a6558bb.js';
|
2
|
-
|
3
|
-
const APP_NAME = "waku";
|
4
|
-
class Logger {
|
5
|
-
_info;
|
6
|
-
_warn;
|
7
|
-
_error;
|
8
|
-
static createDebugNamespace(level, prefix) {
|
9
|
-
return prefix ? `${APP_NAME}:${level}:${prefix}` : `${APP_NAME}:${level}`;
|
10
|
-
}
|
11
|
-
constructor(prefix) {
|
12
|
-
this._info = debug(Logger.createDebugNamespace("info", prefix));
|
13
|
-
this._warn = debug(Logger.createDebugNamespace("warn", prefix));
|
14
|
-
this._error = debug(Logger.createDebugNamespace("error", prefix));
|
15
|
-
}
|
16
|
-
get info() {
|
17
|
-
return this._info;
|
18
|
-
}
|
19
|
-
get warn() {
|
20
|
-
return this._warn;
|
21
|
-
}
|
22
|
-
get error() {
|
23
|
-
return this._error;
|
24
|
-
}
|
25
|
-
log(level, ...args) {
|
26
|
-
const logger = this[level];
|
27
|
-
logger(...args);
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
export { Logger as L };
|
package/dist/lib/constants.d.ts
DELETED
package/dist/lib/constants.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,4BAA4B,CAAC"}
|
package/src/lib/constants.ts
DELETED