@waku/core 0.0.22 → 0.0.24
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 +61 -0
- package/bundle/base_protocol-2a0c882e.js +1250 -0
- package/bundle/{browser-bde977a3.js → browser-90197c87.js} +26 -1
- package/bundle/index.js +20048 -3236
- package/bundle/lib/base_protocol.js +2 -116
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/lib/predefined_bootstrap_nodes.js +6 -6
- package/bundle/{version_0-86411fdf.js → version_0-f4afd324.js} +907 -814
- package/dist/.tsbuildinfo +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +18 -5
- package/dist/lib/base_protocol.js +25 -8
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager.d.ts +15 -3
- package/dist/lib/connection_manager.js +92 -34
- package/dist/lib/connection_manager.js.map +1 -1
- package/dist/lib/filter/filter_rpc.js +4 -4
- package/dist/lib/filter/index.d.ts +4 -0
- package/dist/lib/filter/index.js +38 -29
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/filterPeers.d.ts +10 -0
- package/dist/lib/filterPeers.js +31 -0
- package/dist/lib/filterPeers.js.map +1 -0
- package/dist/lib/keep_alive_manager.d.ts +4 -2
- package/dist/lib/keep_alive_manager.js +62 -19
- package/dist/lib/keep_alive_manager.js.map +1 -1
- package/dist/lib/light_push/index.js +85 -38
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/push_rpc.d.ts +1 -1
- package/dist/lib/light_push/push_rpc.js +3 -3
- package/dist/lib/message/version_0.d.ts +13 -13
- package/dist/lib/message/version_0.js +21 -18
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/predefined_bootstrap_nodes.js +6 -6
- package/dist/lib/store/history_rpc.d.ts +1 -1
- package/dist/lib/store/history_rpc.js +4 -4
- package/dist/lib/store/index.d.ts +1 -6
- package/dist/lib/store/index.js +91 -47
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/stream_manager.d.ts +15 -0
- package/dist/lib/stream_manager.js +56 -0
- package/dist/lib/stream_manager.js.map +1 -0
- package/dist/lib/to_proto_message.js +1 -1
- package/dist/lib/wait_for_remote_peer.d.ts +2 -2
- package/dist/lib/wait_for_remote_peer.js +10 -7
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/dist/lib/waku.d.ts +6 -5
- package/dist/lib/waku.js +6 -4
- package/dist/lib/waku.js.map +1 -1
- package/package.json +17 -33
- package/src/index.ts +6 -9
- package/src/lib/base_protocol.ts +49 -18
- package/src/lib/connection_manager.ts +132 -41
- package/src/lib/filter/filter_rpc.ts +4 -4
- package/src/lib/filter/index.ts +53 -41
- package/src/lib/filterPeers.ts +43 -0
- package/src/lib/keep_alive_manager.ts +79 -22
- package/src/lib/light_push/index.ts +132 -51
- package/src/lib/light_push/push_rpc.ts +3 -3
- package/src/lib/message/version_0.ts +27 -15
- package/src/lib/predefined_bootstrap_nodes.ts +7 -7
- package/src/lib/store/history_rpc.ts +6 -6
- package/src/lib/store/index.ts +121 -63
- package/src/lib/stream_manager.ts +72 -0
- package/src/lib/to_proto_message.ts +1 -1
- package/src/lib/wait_for_remote_peer.ts +11 -8
- package/src/lib/waku.ts +7 -4
- package/dist/lib/push_or_init_map.d.ts +0 -1
- package/dist/lib/push_or_init_map.js +0 -9
- package/dist/lib/push_or_init_map.js.map +0 -1
- package/src/lib/push_or_init_map.ts +0 -13
@@ -1,116 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const log = debug("waku:libp2p-utils");
|
4
|
-
/**
|
5
|
-
* Returns a pseudo-random peer that supports the given protocol.
|
6
|
-
* Useful for protocols such as store and light push
|
7
|
-
*/
|
8
|
-
function selectRandomPeer(peers) {
|
9
|
-
if (peers.length === 0)
|
10
|
-
return;
|
11
|
-
const index = Math.round(Math.random() * (peers.length - 1));
|
12
|
-
return peers[index];
|
13
|
-
}
|
14
|
-
/**
|
15
|
-
* Returns the list of peers that supports the given protocol.
|
16
|
-
*/
|
17
|
-
async function getPeersForProtocol(peerStore, protocols) {
|
18
|
-
const peers = [];
|
19
|
-
await peerStore.forEach((peer) => {
|
20
|
-
for (let i = 0; i < protocols.length; i++) {
|
21
|
-
if (peer.protocols.includes(protocols[i])) {
|
22
|
-
peers.push(peer);
|
23
|
-
break;
|
24
|
-
}
|
25
|
-
}
|
26
|
-
});
|
27
|
-
return peers;
|
28
|
-
}
|
29
|
-
async function selectPeerForProtocol(peerStore, protocols, peerId) {
|
30
|
-
let peer;
|
31
|
-
if (peerId) {
|
32
|
-
peer = await peerStore.get(peerId);
|
33
|
-
if (!peer) {
|
34
|
-
throw new Error(`Failed to retrieve connection details for provided peer in peer store: ${peerId.toString()}`);
|
35
|
-
}
|
36
|
-
}
|
37
|
-
else {
|
38
|
-
const peers = await getPeersForProtocol(peerStore, protocols);
|
39
|
-
peer = selectRandomPeer(peers);
|
40
|
-
if (!peer) {
|
41
|
-
throw new Error(`Failed to find known peer that registers protocols: ${protocols}`);
|
42
|
-
}
|
43
|
-
}
|
44
|
-
let protocol;
|
45
|
-
for (const codec of protocols) {
|
46
|
-
if (peer.protocols.includes(codec)) {
|
47
|
-
protocol = codec;
|
48
|
-
// Do not break as we want to keep the last value
|
49
|
-
}
|
50
|
-
}
|
51
|
-
log(`Using codec ${protocol}`);
|
52
|
-
if (!protocol) {
|
53
|
-
throw new Error(`Peer does not register required protocols (${peer.id.toString()}): ${protocols}`);
|
54
|
-
}
|
55
|
-
return { peer, protocol };
|
56
|
-
}
|
57
|
-
function selectConnection(connections) {
|
58
|
-
if (!connections.length)
|
59
|
-
return;
|
60
|
-
if (connections.length === 1)
|
61
|
-
return connections[0];
|
62
|
-
let latestConnection;
|
63
|
-
connections.forEach((connection) => {
|
64
|
-
if (connection.stat.status === "OPEN") {
|
65
|
-
if (!latestConnection) {
|
66
|
-
latestConnection = connection;
|
67
|
-
}
|
68
|
-
else if (connection.stat.timeline.open > latestConnection.stat.timeline.open) {
|
69
|
-
latestConnection = connection;
|
70
|
-
}
|
71
|
-
}
|
72
|
-
});
|
73
|
-
return latestConnection;
|
74
|
-
}
|
75
|
-
|
76
|
-
/**
|
77
|
-
* A class with predefined helpers, to be used as a base to implement Waku
|
78
|
-
* Protocols.
|
79
|
-
*/
|
80
|
-
class BaseProtocol {
|
81
|
-
multicodec;
|
82
|
-
components;
|
83
|
-
addLibp2pEventListener;
|
84
|
-
removeLibp2pEventListener;
|
85
|
-
constructor(multicodec, components) {
|
86
|
-
this.multicodec = multicodec;
|
87
|
-
this.components = components;
|
88
|
-
this.addLibp2pEventListener = components.events.addEventListener.bind(components.events);
|
89
|
-
this.removeLibp2pEventListener = components.events.removeEventListener.bind(components.events);
|
90
|
-
}
|
91
|
-
get peerStore() {
|
92
|
-
return this.components.peerStore;
|
93
|
-
}
|
94
|
-
/**
|
95
|
-
* Returns known peers from the address book (`libp2p.peerStore`) that support
|
96
|
-
* the class protocol. Waku may or may not be currently connected to these
|
97
|
-
* peers.
|
98
|
-
*/
|
99
|
-
async peers() {
|
100
|
-
return getPeersForProtocol(this.peerStore, [this.multicodec]);
|
101
|
-
}
|
102
|
-
async getPeer(peerId) {
|
103
|
-
const { peer } = await selectPeerForProtocol(this.peerStore, [this.multicodec], peerId);
|
104
|
-
return peer;
|
105
|
-
}
|
106
|
-
async newStream(peer) {
|
107
|
-
const connections = this.components.connectionManager.getConnections(peer.id);
|
108
|
-
const connection = selectConnection(connections);
|
109
|
-
if (!connection) {
|
110
|
-
throw new Error("Failed to get a connection to the peer");
|
111
|
-
}
|
112
|
-
return connection.newStream(this.multicodec);
|
113
|
-
}
|
114
|
-
}
|
115
|
-
|
116
|
-
export { BaseProtocol };
|
1
|
+
export { B as BaseProtocol } from '../base_protocol-2a0c882e.js';
|
2
|
+
import '../browser-90197c87.js';
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export {
|
2
|
-
import '../../browser-
|
1
|
+
export { k as DecodedMessage, l as Decoder, E as Encoder, V as Version, i as createDecoder, c as createEncoder, j as proto } from '../../version_0-f4afd324.js';
|
2
|
+
import '../../browser-90197c87.js';
|
@@ -63,17 +63,17 @@ const fleets = {
|
|
63
63
|
"waku-websocket": {
|
64
64
|
"node-01.ac-cn-hongkong-c.wakuv2.prod": "/dns4/node-01.ac-cn-hongkong-c.wakuv2.prod.statusim.net/tcp/8000/wss/p2p/16Uiu2HAm4v86W3bmT1BiH6oSPzcsSr24iDQpSN5Qa992BCjjwgrD",
|
65
65
|
"node-01.do-ams3.wakuv2.prod": "/dns4/node-01.do-ams3.wakuv2.prod.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmL5okWopX7NqZWBUKVqW8iUxCEmd5GMHLVPwCgzYzQv3e",
|
66
|
-
"node-01.gc-us-central1-a.wakuv2.prod": "/dns4/node-01.gc-us-central1-a.wakuv2.prod.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmVkKntsECaYfefR1V2yCR79CegLATuTPE6B9TxgxBiiiA"
|
67
|
-
}
|
66
|
+
"node-01.gc-us-central1-a.wakuv2.prod": "/dns4/node-01.gc-us-central1-a.wakuv2.prod.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmVkKntsECaYfefR1V2yCR79CegLATuTPE6B9TxgxBiiiA"
|
67
|
+
}
|
68
68
|
},
|
69
69
|
"wakuv2.test": {
|
70
70
|
"waku-websocket": {
|
71
71
|
"node-01.ac-cn-hongkong-c.wakuv2.test": "/dns4/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm",
|
72
72
|
"node-01.do-ams3.wakuv2.test": "/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ",
|
73
|
-
"node-01.gc-us-central1-a.wakuv2.test": "/dns4/node-01.gc-us-central1-a.wakuv2.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmJb2e28qLXxT5kZxVUUoJt72EMzNGXB47Rxx5hw3q4YjS"
|
74
|
-
}
|
75
|
-
}
|
76
|
-
}
|
73
|
+
"node-01.gc-us-central1-a.wakuv2.test": "/dns4/node-01.gc-us-central1-a.wakuv2.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmJb2e28qLXxT5kZxVUUoJt72EMzNGXB47Rxx5hw3q4YjS"
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
77
|
};
|
78
78
|
|
79
79
|
export { DefaultWantedNumber, Fleet, fleets, getPredefinedBootstrapNodes };
|