@waku/core 0.0.31-ce62600.0 → 0.0.31-f387f59.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-C6HnrRx8.js → base_protocol-Dge5_tvU.js} +22 -25
- package/bundle/{index-DnW8ifxc.js → index-Gts2Ddu_.js} +41 -56
- package/bundle/index.js +291 -288
- package/bundle/lib/base_protocol.js +2 -2
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/{version_0-DQ9xsSLk.js → version_0-CNRKFufI.js} +154 -308
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +3 -4
- package/dist/lib/base_protocol.js +4 -8
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager.d.ts +2 -2
- package/dist/lib/connection_manager.js +21 -23
- package/dist/lib/connection_manager.js.map +1 -1
- package/dist/lib/filter/filter_rpc.js.map +1 -1
- package/dist/lib/filter/index.d.ts +4 -3
- package/dist/lib/filter/index.js +33 -31
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/health_manager.d.ts +14 -0
- package/dist/lib/health_manager.js +70 -0
- package/dist/lib/health_manager.js.map +1 -0
- package/dist/lib/keep_alive_manager.d.ts +13 -7
- package/dist/lib/keep_alive_manager.js +9 -9
- package/dist/lib/keep_alive_manager.js.map +1 -1
- package/dist/lib/light_push/index.d.ts +3 -2
- package/dist/lib/light_push/index.js +4 -2
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/push_rpc.js.map +1 -1
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/metadata/index.d.ts +2 -2
- package/dist/lib/metadata/index.js +26 -26
- package/dist/lib/metadata/index.js.map +1 -1
- package/dist/lib/store/index.d.ts +5 -44
- package/dist/lib/store/index.js +39 -45
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/store/rpc.d.ts +22 -0
- package/dist/lib/store/rpc.js +74 -0
- package/dist/lib/store/rpc.js.map +1 -0
- package/dist/lib/stream_manager/index.d.ts +1 -0
- package/dist/lib/stream_manager/index.js +2 -0
- package/dist/lib/stream_manager/index.js.map +1 -0
- package/dist/lib/{stream_manager.js → stream_manager/stream_manager.js} +1 -1
- package/dist/lib/stream_manager/stream_manager.js.map +1 -0
- package/dist/lib/stream_manager/utils.d.ts +2 -0
- package/dist/lib/stream_manager/utils.js +19 -0
- package/dist/lib/stream_manager/utils.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +3 -3
- package/src/lib/base_protocol.ts +7 -10
- package/src/lib/connection_manager.ts +29 -30
- package/src/lib/filter/filter_rpc.ts +21 -19
- package/src/lib/filter/index.ts +50 -52
- package/src/lib/health_manager.ts +90 -0
- package/src/lib/keep_alive_manager.ts +27 -18
- package/src/lib/light_push/index.ts +7 -10
- package/src/lib/light_push/push_rpc.ts +5 -5
- package/src/lib/message/version_0.ts +17 -15
- package/src/lib/metadata/index.ts +43 -44
- package/src/lib/store/index.ts +54 -94
- package/src/lib/store/rpc.ts +92 -0
- package/src/lib/stream_manager/index.ts +1 -0
- package/src/lib/{stream_manager.ts → stream_manager/stream_manager.ts} +3 -2
- package/src/lib/stream_manager/utils.ts +22 -0
- package/dist/lib/store/history_rpc.d.ts +0 -27
- package/dist/lib/store/history_rpc.js +0 -72
- package/dist/lib/store/history_rpc.js.map +0 -1
- package/dist/lib/stream_manager.js.map +0 -1
- package/src/lib/store/history_rpc.ts +0 -93
- /package/dist/lib/{stream_manager.d.ts → stream_manager/stream_manager.d.ts} +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
import { h as bytesToUtf8, T as Tags, L as Logger,
|
1
|
+
import { h as bytesToUtf8, T as Tags, L as Logger, e as pubsubTopicsToShardInfo } from './index-Gts2Ddu_.js';
|
2
2
|
|
3
3
|
const decodeRelayShard = (bytes) => {
|
4
4
|
// explicitly converting to Uint8Array to avoid Buffer
|
@@ -118,24 +118,6 @@ async function getConnectedPeersForProtocolAndShard(connections, peerStore, prot
|
|
118
118
|
const peersWithNulls = await Promise.all(peerPromises);
|
119
119
|
return peersWithNulls.filter((peer) => peer !== null);
|
120
120
|
}
|
121
|
-
function selectConnection(connections) {
|
122
|
-
if (!connections.length)
|
123
|
-
return;
|
124
|
-
if (connections.length === 1)
|
125
|
-
return connections[0];
|
126
|
-
let latestConnection;
|
127
|
-
connections.forEach((connection) => {
|
128
|
-
if (connection.status === "open") {
|
129
|
-
if (!latestConnection) {
|
130
|
-
latestConnection = connection;
|
131
|
-
}
|
132
|
-
else if (connection.timeline.open > latestConnection.timeline.open) {
|
133
|
-
latestConnection = connection;
|
134
|
-
}
|
135
|
-
}
|
136
|
-
});
|
137
|
-
return latestConnection;
|
138
|
-
}
|
139
121
|
|
140
122
|
/**
|
141
123
|
* Retrieves a list of peers based on the specified criteria:
|
@@ -174,6 +156,25 @@ function filterPeersByDiscovery(peers, numPeers, maxBootstrapPeers) {
|
|
174
156
|
return selectedPeers;
|
175
157
|
}
|
176
158
|
|
159
|
+
function selectConnection(connections) {
|
160
|
+
if (!connections.length)
|
161
|
+
return;
|
162
|
+
if (connections.length === 1)
|
163
|
+
return connections[0];
|
164
|
+
let latestConnection;
|
165
|
+
connections.forEach((connection) => {
|
166
|
+
if (connection.status === "open") {
|
167
|
+
if (!latestConnection) {
|
168
|
+
latestConnection = connection;
|
169
|
+
}
|
170
|
+
else if (connection.timeline.open > latestConnection.timeline.open) {
|
171
|
+
latestConnection = connection;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
});
|
175
|
+
return latestConnection;
|
176
|
+
}
|
177
|
+
|
177
178
|
const CONNECTION_TIMEOUT = 5_000;
|
178
179
|
const RETRY_BACKOFF_BASE = 1_000;
|
179
180
|
const MAX_RETRIES = 3;
|
@@ -271,16 +272,14 @@ class BaseProtocol {
|
|
271
272
|
components;
|
272
273
|
log;
|
273
274
|
pubsubTopics;
|
274
|
-
options;
|
275
275
|
addLibp2pEventListener;
|
276
276
|
removeLibp2pEventListener;
|
277
277
|
streamManager;
|
278
|
-
constructor(multicodec, components, log, pubsubTopics
|
278
|
+
constructor(multicodec, components, log, pubsubTopics) {
|
279
279
|
this.multicodec = multicodec;
|
280
280
|
this.components = components;
|
281
281
|
this.log = log;
|
282
282
|
this.pubsubTopics = pubsubTopics;
|
283
|
-
this.options = options;
|
284
283
|
this.addLibp2pEventListener = components.events.addEventListener.bind(components.events);
|
285
284
|
this.removeLibp2pEventListener = components.events.removeEventListener.bind(components.events);
|
286
285
|
this.streamManager = new StreamManager(multicodec, components.connectionManager.getConnections.bind(components.connectionManager), this.addLibp2pEventListener);
|
@@ -318,9 +317,7 @@ class BaseProtocol {
|
|
318
317
|
numPeers: 0
|
319
318
|
}) {
|
320
319
|
// Retrieve all connected peers that support the protocol & shard (if configured)
|
321
|
-
const connectedPeersForProtocolAndShard = await getConnectedPeersForProtocolAndShard(this.components.connectionManager.getConnections(), this.peerStore, [this.multicodec], this.
|
322
|
-
? ensureShardingConfigured(this.options.shardInfo).shardInfo
|
323
|
-
: undefined);
|
320
|
+
const connectedPeersForProtocolAndShard = await getConnectedPeersForProtocolAndShard(this.components.connectionManager.getConnections(), this.peerStore, [this.multicodec], pubsubTopicsToShardInfo(this.pubsubTopics));
|
324
321
|
// Filter the peers based on discovery & number of peers requested
|
325
322
|
const filteredPeers = filterPeersByDiscovery(connectedPeersForProtocolAndShard, numPeers, maxBootstrapPeers);
|
326
323
|
// Sort the peers by latency
|
@@ -1037,6 +1037,11 @@ var ProtocolError;
|
|
1037
1037
|
* Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
|
1038
1038
|
*/
|
1039
1039
|
ProtocolError["TOPIC_DECODER_MISMATCH"] = "Topic decoder mismatch";
|
1040
|
+
/**
|
1041
|
+
* The topics passed in the decoders do not match each other, or don't exist at all.
|
1042
|
+
* Ensure that all the pubsub topics used in the decoders are valid and match each other.
|
1043
|
+
*/
|
1044
|
+
ProtocolError["INVALID_DECODER_TOPICS"] = "Invalid decoder topics";
|
1040
1045
|
/**
|
1041
1046
|
* Failure to find a peer with suitable protocols. This may due to a connection issue.
|
1042
1047
|
* Mitigation can be: retrying after a given time period, display connectivity issue
|
@@ -1067,12 +1072,6 @@ var ProtocolError;
|
|
1067
1072
|
ProtocolError["REQUEST_TIMEOUT"] = "Request timeout";
|
1068
1073
|
})(ProtocolError || (ProtocolError = {}));
|
1069
1074
|
|
1070
|
-
var PageDirection;
|
1071
|
-
(function (PageDirection) {
|
1072
|
-
PageDirection["BACKWARD"] = "backward";
|
1073
|
-
PageDirection["FORWARD"] = "forward";
|
1074
|
-
})(PageDirection || (PageDirection = {}));
|
1075
|
-
|
1076
1075
|
var Tags;
|
1077
1076
|
(function (Tags) {
|
1078
1077
|
Tags["BOOTSTRAP"] = "bootstrap";
|
@@ -1091,14 +1090,18 @@ var EConnectionStateEvents;
|
|
1091
1090
|
EConnectionStateEvents["CONNECTION_STATUS"] = "waku:connection";
|
1092
1091
|
})(EConnectionStateEvents || (EConnectionStateEvents = {}));
|
1093
1092
|
|
1094
|
-
/**
|
1095
|
-
* DefaultPubsubTopic is the default gossipsub topic to use for Waku.
|
1096
|
-
*/
|
1097
1093
|
/**
|
1098
1094
|
* The default cluster ID for The Waku Network
|
1099
1095
|
*/
|
1100
1096
|
const DEFAULT_CLUSTER_ID = 1;
|
1101
1097
|
|
1098
|
+
var HealthStatus;
|
1099
|
+
(function (HealthStatus) {
|
1100
|
+
HealthStatus["Unhealthy"] = "Unhealthy";
|
1101
|
+
HealthStatus["MinimallyHealthy"] = "MinimallyHealthy";
|
1102
|
+
HealthStatus["SufficientlyHealthy"] = "SufficientlyHealthy";
|
1103
|
+
})(HealthStatus || (HealthStatus = {}));
|
1104
|
+
|
1102
1105
|
/**
|
1103
1106
|
* Turns a `Uint8Array` into a string.
|
1104
1107
|
*
|
@@ -1127,7 +1130,7 @@ const utf8ToBytes = (s) => fromString(s, "utf8");
|
|
1127
1130
|
* Concatenate using Uint8Arrays as `Buffer` has a different behavior with `DataView`
|
1128
1131
|
*/
|
1129
1132
|
function concat(byteArrays, totalLength) {
|
1130
|
-
const len =
|
1133
|
+
const len = byteArrays.reduce((acc, curr) => acc + curr.length, 0);
|
1131
1134
|
const res = new Uint8Array(len);
|
1132
1135
|
let offset = 0;
|
1133
1136
|
for (const bytes of byteArrays) {
|
@@ -1179,6 +1182,27 @@ const pubsubTopicToSingleShardInfo = (pubsubTopics) => {
|
|
1179
1182
|
shard
|
1180
1183
|
};
|
1181
1184
|
};
|
1185
|
+
const pubsubTopicsToShardInfo = (pubsubTopics) => {
|
1186
|
+
const shardInfoSet = new Set();
|
1187
|
+
const clusterIds = new Set();
|
1188
|
+
for (const topic of pubsubTopics) {
|
1189
|
+
const { clusterId, shard } = pubsubTopicToSingleShardInfo(topic);
|
1190
|
+
shardInfoSet.add(`${clusterId}:${shard}`);
|
1191
|
+
clusterIds.add(clusterId);
|
1192
|
+
}
|
1193
|
+
if (shardInfoSet.size === 0) {
|
1194
|
+
throw new Error("No valid pubsub topics provided");
|
1195
|
+
}
|
1196
|
+
if (clusterIds.size > 1) {
|
1197
|
+
throw new Error("Pubsub topics from multiple cluster IDs are not supported");
|
1198
|
+
}
|
1199
|
+
const clusterId = clusterIds.values().next().value;
|
1200
|
+
const shards = Array.from(shardInfoSet).map((info) => parseInt(info.split(":")[1]));
|
1201
|
+
return {
|
1202
|
+
clusterId,
|
1203
|
+
shards
|
1204
|
+
};
|
1205
|
+
};
|
1182
1206
|
/**
|
1183
1207
|
* Given a string, will throw an error if it is not formatted as a valid content topic for autosharding based on https://rfc.vac.dev/spec/51/
|
1184
1208
|
* @param contentTopic String to validate
|
@@ -1246,7 +1270,9 @@ function contentTopicToPubsubTopic(contentTopic, clusterId = DEFAULT_CLUSTER_ID,
|
|
1246
1270
|
/**
|
1247
1271
|
* Used when creating encoders/decoders to determine which pubsub topic to use
|
1248
1272
|
*/
|
1249
|
-
function determinePubsubTopic(contentTopic,
|
1273
|
+
function determinePubsubTopic(contentTopic,
|
1274
|
+
// TODO: make it accept ShardInfo https://github.com/waku-org/js-waku/issues/2086
|
1275
|
+
pubsubTopicShardInfo) {
|
1250
1276
|
if (typeof pubsubTopicShardInfo == "string") {
|
1251
1277
|
return pubsubTopicShardInfo;
|
1252
1278
|
}
|
@@ -1254,49 +1280,6 @@ function determinePubsubTopic(contentTopic, pubsubTopicShardInfo) {
|
|
1254
1280
|
? singleShardInfoToPubsubTopic(pubsubTopicShardInfo)
|
1255
1281
|
: contentTopicToPubsubTopic(contentTopic, pubsubTopicShardInfo?.clusterId ?? DEFAULT_CLUSTER_ID);
|
1256
1282
|
}
|
1257
|
-
/**
|
1258
|
-
* Validates sharding configuration and sets defaults where possible.
|
1259
|
-
* @returns Validated sharding parameters, with any missing values set to defaults
|
1260
|
-
*/
|
1261
|
-
const ensureShardingConfigured = (shardInfo) => {
|
1262
|
-
const clusterId = shardInfo.clusterId ?? DEFAULT_CLUSTER_ID;
|
1263
|
-
const shards = "shards" in shardInfo ? shardInfo.shards : [];
|
1264
|
-
const contentTopics = "contentTopics" in shardInfo ? shardInfo.contentTopics : [];
|
1265
|
-
const [application, version] = "application" in shardInfo && "version" in shardInfo
|
1266
|
-
? [shardInfo.application, shardInfo.version]
|
1267
|
-
: [undefined, undefined];
|
1268
|
-
const isShardsConfigured = shards && shards.length > 0;
|
1269
|
-
const isContentTopicsConfigured = contentTopics && contentTopics.length > 0;
|
1270
|
-
const isApplicationVersionConfigured = application && version;
|
1271
|
-
if (isShardsConfigured) {
|
1272
|
-
return {
|
1273
|
-
shardingParams: { clusterId, shards },
|
1274
|
-
shardInfo: { clusterId, shards },
|
1275
|
-
pubsubTopics: shardInfoToPubsubTopics({ clusterId, shards })
|
1276
|
-
};
|
1277
|
-
}
|
1278
|
-
if (isContentTopicsConfigured) {
|
1279
|
-
const pubsubTopics = Array.from(new Set(contentTopics.map((topic) => contentTopicToPubsubTopic(topic, clusterId))));
|
1280
|
-
const shards = Array.from(new Set(contentTopics.map((topic) => contentTopicToShardIndex(topic))));
|
1281
|
-
return {
|
1282
|
-
shardingParams: { clusterId, contentTopics },
|
1283
|
-
shardInfo: { clusterId, shards },
|
1284
|
-
pubsubTopics
|
1285
|
-
};
|
1286
|
-
}
|
1287
|
-
if (isApplicationVersionConfigured) {
|
1288
|
-
const pubsubTopic = contentTopicToPubsubTopic(`/${application}/${version}/default/default`, clusterId);
|
1289
|
-
return {
|
1290
|
-
shardingParams: { clusterId, application, version },
|
1291
|
-
shardInfo: {
|
1292
|
-
clusterId,
|
1293
|
-
shards: [pubsubTopicToSingleShardInfo(pubsubTopic).shard]
|
1294
|
-
},
|
1295
|
-
pubsubTopics: [pubsubTopic]
|
1296
|
-
};
|
1297
|
-
}
|
1298
|
-
throw new Error("Missing minimum required configuration options for static sharding or autosharding.");
|
1299
|
-
};
|
1300
1283
|
|
1301
1284
|
function getDefaultExportFromCjs (x) {
|
1302
1285
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
@@ -1877,6 +1860,8 @@ var common = setup;
|
|
1877
1860
|
return false;
|
1878
1861
|
}
|
1879
1862
|
|
1863
|
+
let m;
|
1864
|
+
|
1880
1865
|
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
1881
1866
|
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
1882
1867
|
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
@@ -1884,7 +1869,7 @@ var common = setup;
|
|
1884
1869
|
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
1885
1870
|
// Is firefox >= v31?
|
1886
1871
|
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
1887
|
-
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(
|
1872
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
|
1888
1873
|
// Double check webkit in userAgent just in case we are in a worker
|
1889
1874
|
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
1890
1875
|
}
|
@@ -2052,4 +2037,4 @@ class Logger {
|
|
2052
2037
|
}
|
2053
2038
|
}
|
2054
2039
|
|
2055
|
-
export { EConnectionStateEvents as E, Logger as L, ProtocolError as P, Tags as T, allocUnsafe as a, alloc as b, Protocols as c, EPeersByDiscoveryEvents as d,
|
2040
|
+
export { EConnectionStateEvents as E, HealthStatus as H, Logger as L, ProtocolError as P, Tags as T, allocUnsafe as a, alloc as b, Protocols as c, EPeersByDiscoveryEvents as d, pubsubTopicsToShardInfo as e, fromString as f, determinePubsubTopic as g, bytesToUtf8 as h, pubsubTopicToSingleShardInfo as p, shardInfoToPubsubTopics as s, utf8ToBytes as u };
|