@waku/core 0.0.32 → 0.0.33-338250a.0
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/bundle/{base_protocol-C47QkJ2o.js → base_protocol-CS0EDeEY.js} +16 -91
- package/bundle/{index-tdQNdKHx.js → index-BVysxsMu.js} +6 -444
- package/bundle/index.js +66 -9
- package/bundle/lib/base_protocol.js +2 -2
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/{version_0-BrbNEwD-.js → version_0-C5ObpJ_0.js} +445 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/lib/base_protocol.d.ts +5 -7
- package/dist/lib/base_protocol.js +15 -15
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/filter/index.d.ts +2 -1
- package/dist/lib/filter/index.js +6 -3
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/metadata/index.js +1 -1
- package/dist/lib/metadata/index.js.map +1 -1
- package/package.json +1 -126
- package/src/lib/base_protocol.ts +21 -29
- package/src/lib/filter/index.ts +13 -2
- package/src/lib/metadata/index.ts +1 -1
package/package.json
CHANGED
@@ -1,126 +1 @@
|
|
1
|
-
{
|
2
|
-
"name": "@waku/core",
|
3
|
-
"version": "0.0.32",
|
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/message/version_0": {
|
13
|
-
"types": "./dist/lib/message/version_0.d.ts",
|
14
|
-
"import": "./dist/lib/message/version_0.js"
|
15
|
-
},
|
16
|
-
"./lib/base_protocol": {
|
17
|
-
"types": "./dist/lib/base_protocol.d.ts",
|
18
|
-
"import": "./dist/lib/base_protocol.js"
|
19
|
-
}
|
20
|
-
},
|
21
|
-
"typesVersions": {
|
22
|
-
"*": {
|
23
|
-
"lib/*": [
|
24
|
-
"dist/lib/*"
|
25
|
-
],
|
26
|
-
"constants/*": [
|
27
|
-
"dist/constants/*"
|
28
|
-
]
|
29
|
-
}
|
30
|
-
},
|
31
|
-
"type": "module",
|
32
|
-
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/core#readme",
|
33
|
-
"repository": {
|
34
|
-
"type": "git",
|
35
|
-
"url": "https://github.com/waku-org/js-waku.git"
|
36
|
-
},
|
37
|
-
"bugs": {
|
38
|
-
"url": "https://github.com/waku-org/js-waku/issues"
|
39
|
-
},
|
40
|
-
"license": "MIT OR Apache-2.0",
|
41
|
-
"keywords": [
|
42
|
-
"waku",
|
43
|
-
"decentralised",
|
44
|
-
"communication",
|
45
|
-
"web3",
|
46
|
-
"ethereum",
|
47
|
-
"dapps"
|
48
|
-
],
|
49
|
-
"scripts": {
|
50
|
-
"build": "run-s build:**",
|
51
|
-
"build:esm": "tsc",
|
52
|
-
"build:bundle": "rollup --config rollup.config.js",
|
53
|
-
"fix": "run-s fix:*",
|
54
|
-
"fix:lint": "eslint src *.js --fix",
|
55
|
-
"check": "run-s check:*",
|
56
|
-
"check:tsc": "tsc -p tsconfig.dev.json",
|
57
|
-
"check:lint": "eslint src *.js",
|
58
|
-
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
|
59
|
-
"test": "NODE_ENV=test run-s test:*",
|
60
|
-
"test:node": "NODE_ENV=test TS_NODE_PROJECT=./tsconfig.dev.json mocha",
|
61
|
-
"test:browser": "NODE_ENV=test karma start karma.conf.cjs",
|
62
|
-
"watch:build": "tsc -p tsconfig.json -w",
|
63
|
-
"watch:test": "mocha --watch",
|
64
|
-
"prepublish": "npm run build",
|
65
|
-
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
|
66
|
-
},
|
67
|
-
"engines": {
|
68
|
-
"node": ">=20"
|
69
|
-
},
|
70
|
-
"dependencies": {
|
71
|
-
"@libp2p/ping": "^1.1.2",
|
72
|
-
"@waku/enr": "^0.0.26",
|
73
|
-
"@waku/interfaces": "0.0.27",
|
74
|
-
"@waku/proto": "0.0.8",
|
75
|
-
"@waku/utils": "0.0.20",
|
76
|
-
"debug": "^4.3.4",
|
77
|
-
"it-all": "^3.0.4",
|
78
|
-
"it-length-prefixed": "^9.0.4",
|
79
|
-
"it-pipe": "^3.0.1",
|
80
|
-
"p-event": "^6.0.1",
|
81
|
-
"uint8arraylist": "^2.4.3",
|
82
|
-
"uuid": "^9.0.0"
|
83
|
-
},
|
84
|
-
"devDependencies": {
|
85
|
-
"@multiformats/multiaddr": "^12.0.0",
|
86
|
-
"@rollup/plugin-commonjs": "^25.0.7",
|
87
|
-
"@rollup/plugin-json": "^6.0.0",
|
88
|
-
"@rollup/plugin-node-resolve": "^15.2.3",
|
89
|
-
"@types/chai": "^4.3.11",
|
90
|
-
"@types/debug": "^4.1.12",
|
91
|
-
"@types/mocha": "^10.0.6",
|
92
|
-
"@types/uuid": "^9.0.8",
|
93
|
-
"@waku/build-utils": "*",
|
94
|
-
"chai": "^4.3.10",
|
95
|
-
"cspell": "^8.6.1",
|
96
|
-
"fast-check": "^3.19.0",
|
97
|
-
"ignore-loader": "^0.1.2",
|
98
|
-
"isomorphic-fetch": "^3.0.0",
|
99
|
-
"mocha": "^10.3.0",
|
100
|
-
"npm-run-all": "^4.1.5",
|
101
|
-
"process": "^0.11.10",
|
102
|
-
"rollup": "^4.12.0"
|
103
|
-
},
|
104
|
-
"peerDependencies": {
|
105
|
-
"@multiformats/multiaddr": "^12.0.0",
|
106
|
-
"libp2p": "^1.8.1"
|
107
|
-
},
|
108
|
-
"peerDependenciesMeta": {
|
109
|
-
"@multiformats/multiaddr": {
|
110
|
-
"optional": true
|
111
|
-
},
|
112
|
-
"libp2p": {
|
113
|
-
"optional": true
|
114
|
-
}
|
115
|
-
},
|
116
|
-
"files": [
|
117
|
-
"dist",
|
118
|
-
"bundle",
|
119
|
-
"src/**/*.ts",
|
120
|
-
"!**/*.spec.*",
|
121
|
-
"!**/*.json",
|
122
|
-
"CHANGELOG.md",
|
123
|
-
"LICENSE",
|
124
|
-
"README.md"
|
125
|
-
]
|
126
|
-
}
|
1
|
+
{"name":"@waku/core","version":"0.0.33-338250a.0","description":"TypeScript implementation of the Waku v2 protocol","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./lib/message/version_0":{"types":"./dist/lib/message/version_0.d.ts","import":"./dist/lib/message/version_0.js"},"./lib/base_protocol":{"types":"./dist/lib/base_protocol.d.ts","import":"./dist/lib/base_protocol.js"}},"typesVersions":{"*":{"lib/*":["dist/lib/*"],"constants/*":["dist/constants/*"]}},"type":"module","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/core#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","check":"run-s check:*","check:tsc":"tsc -p tsconfig.dev.json","check:lint":"eslint src *.js","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","test":"NODE_ENV=test run-s test:*","test:node":"NODE_ENV=test TS_NODE_PROJECT=./tsconfig.dev.json mocha","test:browser":"NODE_ENV=test karma start karma.conf.cjs","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":">=20"},"dependencies":{"@libp2p/ping":"^1.1.2","@waku/enr":"0.0.27-338250a.0","@waku/interfaces":"0.0.28-338250a.0","@waku/proto":"0.0.9-338250a.0","@waku/utils":"0.0.21-338250a.0","debug":"^4.3.4","it-all":"^3.0.4","it-length-prefixed":"^9.0.4","it-pipe":"^3.0.1","p-event":"^6.0.1","uint8arraylist":"^2.4.3","uuid":"^9.0.0"},"devDependencies":{"@multiformats/multiaddr":"^12.0.0","@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.2.3","@types/chai":"^4.3.11","@types/debug":"^4.1.12","@types/mocha":"^10.0.6","@types/uuid":"^9.0.8","@waku/build-utils":"*","chai":"^4.3.10","cspell":"^8.6.1","fast-check":"^3.19.0","ignore-loader":"^0.1.2","isomorphic-fetch":"^3.0.0","mocha":"^10.3.0","npm-run-all":"^4.1.5","process":"^0.11.10","rollup":"^4.12.0"},"peerDependencies":{"@multiformats/multiaddr":"^12.0.0","libp2p":"^1.8.1"},"peerDependenciesMeta":{"@multiformats/multiaddr":{"optional":true},"libp2p":{"optional":true}},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"]}
|
package/src/lib/base_protocol.ts
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
import type { Libp2p } from "@libp2p/interface";
|
2
|
-
import type { Peer,
|
2
|
+
import type { Peer, Stream } from "@libp2p/interface";
|
3
3
|
import type {
|
4
4
|
IBaseProtocolCore,
|
5
5
|
Libp2pComponents,
|
6
6
|
PubsubTopic
|
7
7
|
} from "@waku/interfaces";
|
8
|
-
import { Logger
|
9
|
-
import {
|
10
|
-
getConnectedPeersForProtocolAndShard,
|
11
|
-
getPeersForProtocol,
|
12
|
-
sortPeersByLatency
|
13
|
-
} from "@waku/utils/libp2p";
|
8
|
+
import { Logger } from "@waku/utils";
|
9
|
+
import { getPeersForProtocol, sortPeersByLatency } from "@waku/utils/libp2p";
|
14
10
|
|
15
11
|
import { filterPeersByDiscovery } from "./filterPeers.js";
|
16
12
|
import { StreamManager } from "./stream_manager/index.js";
|
@@ -26,7 +22,7 @@ export class BaseProtocol implements IBaseProtocolCore {
|
|
26
22
|
|
27
23
|
protected constructor(
|
28
24
|
public multicodec: string,
|
29
|
-
|
25
|
+
protected components: Libp2pComponents,
|
30
26
|
private log: Logger,
|
31
27
|
public readonly pubsubTopics: PubsubTopic[]
|
32
28
|
) {
|
@@ -50,25 +46,28 @@ export class BaseProtocol implements IBaseProtocolCore {
|
|
50
46
|
return this.streamManager.getStream(peer);
|
51
47
|
}
|
52
48
|
|
53
|
-
|
54
|
-
return this.components.peerStore;
|
55
|
-
}
|
56
|
-
|
49
|
+
//TODO: move to SDK
|
57
50
|
/**
|
58
51
|
* Returns known peers from the address book (`libp2p.peerStore`) that support
|
59
52
|
* the class protocol. Waku may or may not be currently connected to these
|
60
53
|
* peers.
|
61
54
|
*/
|
62
55
|
public async allPeers(): Promise<Peer[]> {
|
63
|
-
return getPeersForProtocol(this.peerStore, [this.multicodec]);
|
56
|
+
return getPeersForProtocol(this.components.peerStore, [this.multicodec]);
|
64
57
|
}
|
65
58
|
|
66
|
-
public async connectedPeers(): Promise<Peer[]> {
|
59
|
+
public async connectedPeers(withOpenStreams = false): Promise<Peer[]> {
|
67
60
|
const peers = await this.allPeers();
|
68
61
|
return peers.filter((peer) => {
|
69
|
-
|
70
|
-
|
62
|
+
const connections = this.components.connectionManager.getConnections(
|
63
|
+
peer.id
|
71
64
|
);
|
65
|
+
if (withOpenStreams) {
|
66
|
+
return connections.some((c) =>
|
67
|
+
c.streams.some((s) => s.protocol === this.multicodec)
|
68
|
+
);
|
69
|
+
}
|
70
|
+
return connections.length > 0;
|
72
71
|
});
|
73
72
|
}
|
74
73
|
|
@@ -77,9 +76,8 @@ export class BaseProtocol implements IBaseProtocolCore {
|
|
77
76
|
*
|
78
77
|
* @param numPeers - The total number of peers to retrieve. If 0, all peers are returned.
|
79
78
|
* @param maxBootstrapPeers - The maximum number of bootstrap peers to retrieve.
|
80
|
-
|
81
|
-
|
82
|
-
*/
|
79
|
+
* @returns A list of peers that support the protocol sorted by latency. By default, returns all peers available, including bootstrap.
|
80
|
+
*/
|
83
81
|
public async getPeers(
|
84
82
|
{
|
85
83
|
numPeers,
|
@@ -88,29 +86,23 @@ export class BaseProtocol implements IBaseProtocolCore {
|
|
88
86
|
numPeers: number;
|
89
87
|
maxBootstrapPeers: number;
|
90
88
|
} = {
|
91
|
-
maxBootstrapPeers:
|
89
|
+
maxBootstrapPeers: 0,
|
92
90
|
numPeers: 0
|
93
91
|
}
|
94
92
|
): Promise<Peer[]> {
|
95
93
|
// Retrieve all connected peers that support the protocol & shard (if configured)
|
96
|
-
const
|
97
|
-
await getConnectedPeersForProtocolAndShard(
|
98
|
-
this.components.connectionManager.getConnections(),
|
99
|
-
this.peerStore,
|
100
|
-
[this.multicodec],
|
101
|
-
pubsubTopicsToShardInfo(this.pubsubTopics)
|
102
|
-
);
|
94
|
+
const allAvailableConnectedPeers = await this.connectedPeers();
|
103
95
|
|
104
96
|
// Filter the peers based on discovery & number of peers requested
|
105
97
|
const filteredPeers = filterPeersByDiscovery(
|
106
|
-
|
98
|
+
allAvailableConnectedPeers,
|
107
99
|
numPeers,
|
108
100
|
maxBootstrapPeers
|
109
101
|
);
|
110
102
|
|
111
103
|
// Sort the peers by latency
|
112
104
|
const sortedFilteredPeers = await sortPeersByLatency(
|
113
|
-
this.peerStore,
|
105
|
+
this.components.peerStore,
|
114
106
|
filteredPeers
|
115
107
|
);
|
116
108
|
|
package/src/lib/filter/index.ts
CHANGED
@@ -37,6 +37,7 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
|
37
37
|
wakuMessage: WakuMessage,
|
38
38
|
peerIdStr: string
|
39
39
|
) => Promise<void>,
|
40
|
+
private handleError: (error: Error) => Promise<void>,
|
40
41
|
public readonly pubsubTopics: PubsubTopic[],
|
41
42
|
libp2p: Libp2p
|
42
43
|
) {
|
@@ -301,8 +302,18 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
|
301
302
|
() => {
|
302
303
|
log.info("Receiving pipe closed.");
|
303
304
|
},
|
304
|
-
(e) => {
|
305
|
-
log.error(
|
305
|
+
async (e) => {
|
306
|
+
log.error(
|
307
|
+
"Error with receiving pipe",
|
308
|
+
e,
|
309
|
+
" -- ",
|
310
|
+
"on peer ",
|
311
|
+
connection.remotePeer.toString(),
|
312
|
+
" -- ",
|
313
|
+
"stream ",
|
314
|
+
stream
|
315
|
+
);
|
316
|
+
await this.handleError(e);
|
306
317
|
}
|
307
318
|
);
|
308
319
|
} catch (e) {
|
@@ -45,7 +45,7 @@ class Metadata extends BaseProtocol implements IMetadata {
|
|
45
45
|
pubsubTopicsToShardInfo(this.pubsubTopics)
|
46
46
|
);
|
47
47
|
|
48
|
-
const peer = await this.peerStore.get(peerId);
|
48
|
+
const peer = await this.libp2pComponents.peerStore.get(peerId);
|
49
49
|
if (!peer) {
|
50
50
|
return {
|
51
51
|
shardInfo: null,
|