@waku/core 0.0.31-1887f4f.0 → 0.0.31-409642d.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-WTp5jKZK.js → base_protocol-Dge5_tvU.js} +3 -7
- package/bundle/{index-COT0phC8.js → index-Gts2Ddu_.js} +38 -52
- package/bundle/index.js +214 -193
- package/bundle/lib/base_protocol.js +2 -2
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/{version_0-SMRUXDNR.js → version_0-CNRKFufI.js} +154 -308
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +2 -3
- package/dist/lib/base_protocol.js +3 -7
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager.d.ts +1 -1
- package/dist/lib/connection_manager.js.map +1 -1
- package/dist/lib/filter/index.d.ts +3 -2
- package/dist/lib/filter/index.js +4 -2
- 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/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/metadata/index.d.ts +2 -2
- package/dist/lib/metadata/index.js +9 -9
- 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/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/lib/base_protocol.ts +3 -7
- package/src/lib/connection_manager.ts +1 -1
- package/src/lib/filter/index.ts +3 -10
- package/src/lib/health_manager.ts +90 -0
- package/src/lib/light_push/index.ts +6 -9
- package/src/lib/metadata/index.ts +11 -12
- package/src/lib/store/index.ts +53 -93
- package/src/lib/store/rpc.ts +92 -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/src/lib/store/history_rpc.ts +0 -93
package/bundle/index.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { v as version_0, e as encodingLength, a as encode$1, d as decode$1, M as MessagePush, F as FilterSubscribeRequest, b as FilterSubscribeResponse$1, P as PushRpc$1, c as PushResponse,
|
2
|
-
export {
|
3
|
-
import { a as allocUnsafe, b as alloc,
|
4
|
-
import { B as BaseProtocol, d as decodeRelayShard, e as encodeRelayShard } from './base_protocol-
|
5
|
-
export { S as StreamManager } from './base_protocol-
|
1
|
+
import { v as version_0, e as encodingLength, a as encode$1, d as decode$1, M as MessagePush, F as FilterSubscribeRequest, b as FilterSubscribeResponse$1, P as PushRpc$1, c as PushResponse, S as StoreQueryRequest$1, f as StoreQueryResponse$1, g as createEncoder, W as WakuMetadataRequest, h as WakuMetadataResponse } from './version_0-CNRKFufI.js';
|
2
|
+
export { i as createDecoder } from './version_0-CNRKFufI.js';
|
3
|
+
import { a as allocUnsafe, b as alloc, L as Logger, P as ProtocolError, c as Protocols, u as utf8ToBytes, p as pubsubTopicToSingleShardInfo, E as EConnectionStateEvents, T as Tags, d as EPeersByDiscoveryEvents, s as shardInfoToPubsubTopics, H as HealthStatus, e as pubsubTopicsToShardInfo } from './index-Gts2Ddu_.js';
|
4
|
+
import { B as BaseProtocol, d as decodeRelayShard, e as encodeRelayShard } from './base_protocol-Dge5_tvU.js';
|
5
|
+
export { S as StreamManager } from './base_protocol-Dge5_tvU.js';
|
6
6
|
|
7
7
|
const MB = 1024 ** 2;
|
8
8
|
const SIZE_CAP_IN_MB = 1;
|
@@ -743,74 +743,35 @@ encode.single = (chunk, options) => {
|
|
743
743
|
};
|
744
744
|
|
745
745
|
/**
|
746
|
-
*
|
747
|
-
* @typedef {Error} Err
|
748
|
-
* @property {string} message
|
746
|
+
* The reported length of the next data message was not a positive integer
|
749
747
|
*/
|
750
|
-
|
748
|
+
class InvalidMessageLengthError extends Error {
|
749
|
+
name = 'InvalidMessageLengthError';
|
750
|
+
code = 'ERR_INVALID_MSG_LENGTH';
|
751
|
+
}
|
751
752
|
/**
|
752
|
-
*
|
753
|
-
*
|
754
|
-
* @param {Extensions} props
|
755
|
-
* @returns {Error & Extensions}
|
753
|
+
* The reported length of the next data message was larger than the configured
|
754
|
+
* max allowable value
|
756
755
|
*/
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
value: props[key],
|
761
|
-
enumerable: true,
|
762
|
-
configurable: true,
|
763
|
-
});
|
764
|
-
}
|
765
|
-
|
766
|
-
return obj;
|
756
|
+
class InvalidDataLengthError extends Error {
|
757
|
+
name = 'InvalidDataLengthError';
|
758
|
+
code = 'ERR_MSG_DATA_TOO_LONG';
|
767
759
|
}
|
768
|
-
|
769
760
|
/**
|
770
|
-
*
|
771
|
-
*
|
772
|
-
* @param {string|Extensions} code - A string code or props to set on the error
|
773
|
-
* @param {Extensions} [props] - Props to set on the error
|
774
|
-
* @returns {Error & Extensions}
|
761
|
+
* The varint used to specify the length of the next data message contained more
|
762
|
+
* bytes than the configured max allowable value
|
775
763
|
*/
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
props = code;
|
787
|
-
code = '';
|
788
|
-
}
|
789
|
-
|
790
|
-
if (code) {
|
791
|
-
props.code = code;
|
792
|
-
}
|
793
|
-
|
794
|
-
try {
|
795
|
-
return assign(err, props);
|
796
|
-
} catch (_) {
|
797
|
-
props.message = err.message;
|
798
|
-
props.stack = err.stack;
|
799
|
-
|
800
|
-
const ErrClass = function () {};
|
801
|
-
|
802
|
-
ErrClass.prototype = Object.create(Object.getPrototypeOf(err));
|
803
|
-
|
804
|
-
// @ts-ignore
|
805
|
-
const output = assign(new ErrClass(), props);
|
806
|
-
|
807
|
-
return output;
|
808
|
-
}
|
764
|
+
class InvalidDataLengthLengthError extends Error {
|
765
|
+
name = 'InvalidDataLengthLengthError';
|
766
|
+
code = 'ERR_MSG_LENGTH_TOO_LONG';
|
767
|
+
}
|
768
|
+
/**
|
769
|
+
* The incoming stream ended before the expected number of bytes were read
|
770
|
+
*/
|
771
|
+
class UnexpectedEOFError extends Error {
|
772
|
+
name = 'UnexpectedEOFError';
|
773
|
+
code = 'ERR_UNEXPECTED_EOF';
|
809
774
|
}
|
810
|
-
|
811
|
-
var errCode = createError;
|
812
|
-
|
813
|
-
var errCode$1 = /*@__PURE__*/getDefaultExportFromCjs(errCode);
|
814
775
|
|
815
776
|
/* eslint max-depth: ["error", 6] */
|
816
777
|
// Maximum length of the length section of the message
|
@@ -842,10 +803,10 @@ function decode(source, options) {
|
|
842
803
|
try {
|
843
804
|
dataLength = lengthDecoder(buffer);
|
844
805
|
if (dataLength < 0) {
|
845
|
-
throw
|
806
|
+
throw new InvalidMessageLengthError('Invalid message length');
|
846
807
|
}
|
847
808
|
if (dataLength > maxDataLength) {
|
848
|
-
throw
|
809
|
+
throw new InvalidDataLengthError('Message length too long');
|
849
810
|
}
|
850
811
|
const dataLengthLength = lengthDecoder.bytes;
|
851
812
|
buffer.consume(dataLengthLength);
|
@@ -857,7 +818,7 @@ function decode(source, options) {
|
|
857
818
|
catch (err) {
|
858
819
|
if (err instanceof RangeError) {
|
859
820
|
if (buffer.byteLength > maxLengthLength) {
|
860
|
-
throw
|
821
|
+
throw new InvalidDataLengthLengthError('Message length length too long');
|
861
822
|
}
|
862
823
|
break;
|
863
824
|
}
|
@@ -886,7 +847,7 @@ function decode(source, options) {
|
|
886
847
|
yield* maybeYield();
|
887
848
|
}
|
888
849
|
if (buffer.byteLength > 0) {
|
889
|
-
throw
|
850
|
+
throw new UnexpectedEOFError('Unexpected end of input');
|
890
851
|
}
|
891
852
|
})();
|
892
853
|
}
|
@@ -896,7 +857,7 @@ function decode(source, options) {
|
|
896
857
|
yield* maybeYield();
|
897
858
|
}
|
898
859
|
if (buffer.byteLength > 0) {
|
899
|
-
throw
|
860
|
+
throw new UnexpectedEOFError('Unexpected end of input');
|
900
861
|
}
|
901
862
|
})();
|
902
863
|
}
|
@@ -1484,16 +1445,6 @@ function v4(options, buf, offset) {
|
|
1484
1445
|
rnds[6] = rnds[6] & 0x0f | 0x40;
|
1485
1446
|
rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
|
1486
1447
|
|
1487
|
-
if (buf) {
|
1488
|
-
offset = offset || 0;
|
1489
|
-
|
1490
|
-
for (let i = 0; i < 16; ++i) {
|
1491
|
-
buf[offset + i] = rnds[i];
|
1492
|
-
}
|
1493
|
-
|
1494
|
-
return buf;
|
1495
|
-
}
|
1496
|
-
|
1497
1448
|
return unsafeStringify(rnds);
|
1498
1449
|
}
|
1499
1450
|
|
@@ -1611,9 +1562,11 @@ const FilterCodecs = {
|
|
1611
1562
|
};
|
1612
1563
|
class FilterCore extends BaseProtocol {
|
1613
1564
|
handleIncomingMessage;
|
1614
|
-
|
1615
|
-
|
1565
|
+
pubsubTopics;
|
1566
|
+
constructor(handleIncomingMessage, pubsubTopics, libp2p) {
|
1567
|
+
super(FilterCodecs.SUBSCRIBE, libp2p.components, log$6, pubsubTopics);
|
1616
1568
|
this.handleIncomingMessage = handleIncomingMessage;
|
1569
|
+
this.pubsubTopics = pubsubTopics;
|
1617
1570
|
libp2p
|
1618
1571
|
.handle(FilterCodecs.PUSH, this.onRequest.bind(this), {
|
1619
1572
|
maxInboundStreams: 100
|
@@ -1846,8 +1799,10 @@ const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
|
1846
1799
|
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
1847
1800
|
*/
|
1848
1801
|
class LightPushCore extends BaseProtocol {
|
1849
|
-
|
1850
|
-
|
1802
|
+
pubsubTopics;
|
1803
|
+
constructor(pubsubTopics, libp2p) {
|
1804
|
+
super(LightPushCodec, libp2p.components, log$5, pubsubTopics);
|
1805
|
+
this.pubsubTopics = pubsubTopics;
|
1851
1806
|
}
|
1852
1807
|
async preparePushMessage(encoder, message) {
|
1853
1808
|
try {
|
@@ -1979,97 +1934,97 @@ function toProtoMessage(wire) {
|
|
1979
1934
|
return { ...EmptyMessage, ...wire };
|
1980
1935
|
}
|
1981
1936
|
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
})(PageDirection || (PageDirection = {}));
|
1988
|
-
class HistoryRpc {
|
1937
|
+
// https://github.com/waku-org/nwaku/blob/7205f95cff9f49ca0bb762e8fd0bf56a6a7f3b3b/waku/waku_store/common.nim#L12
|
1938
|
+
const DEFAULT_PAGE_SIZE = 20;
|
1939
|
+
const MAX_PAGE_SIZE = 100;
|
1940
|
+
const ONE_MILLION = 1_000000;
|
1941
|
+
class StoreQueryRequest {
|
1989
1942
|
proto;
|
1990
1943
|
constructor(proto) {
|
1991
1944
|
this.proto = proto;
|
1992
1945
|
}
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
1946
|
+
static create(params) {
|
1947
|
+
const request = new StoreQueryRequest({
|
1948
|
+
...params,
|
1949
|
+
requestId: v4(),
|
1950
|
+
timeStart: params.timeStart
|
1951
|
+
? BigInt(params.timeStart.getTime() * ONE_MILLION)
|
1952
|
+
: undefined,
|
1953
|
+
timeEnd: params.timeEnd
|
1954
|
+
? BigInt(params.timeEnd.getTime() * ONE_MILLION)
|
1955
|
+
: undefined,
|
1956
|
+
messageHashes: params.messageHashes || [],
|
1957
|
+
paginationLimit: params.paginationLimit
|
1958
|
+
? BigInt(params.paginationLimit)
|
1959
|
+
: undefined
|
2005
1960
|
});
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
direction
|
2011
|
-
};
|
2012
|
-
let startTime, endTime;
|
2013
|
-
if (params.startTime) {
|
2014
|
-
// milliseconds 10^-3 to nanoseconds 10^-9
|
2015
|
-
startTime = BigInt(params.startTime.valueOf()) * OneMillion;
|
1961
|
+
// Validate request parameters based on RFC
|
1962
|
+
if ((params.pubsubTopic && !params.contentTopics) ||
|
1963
|
+
(!params.pubsubTopic && params.contentTopics)) {
|
1964
|
+
throw new Error("Both pubsubTopic and contentTopics must be set or unset");
|
2016
1965
|
}
|
2017
|
-
if (params.
|
2018
|
-
|
2019
|
-
|
1966
|
+
if (params.messageHashes &&
|
1967
|
+
(params.pubsubTopic ||
|
1968
|
+
params.contentTopics ||
|
1969
|
+
params.timeStart ||
|
1970
|
+
params.timeEnd)) {
|
1971
|
+
throw new Error("Message hash lookup queries cannot include content filter criteria");
|
2020
1972
|
}
|
2021
|
-
return
|
2022
|
-
requestId: v4(),
|
2023
|
-
query: {
|
2024
|
-
pubsubTopic: params.pubsubTopic,
|
2025
|
-
contentFilters,
|
2026
|
-
pagingInfo,
|
2027
|
-
startTime,
|
2028
|
-
endTime
|
2029
|
-
},
|
2030
|
-
response: undefined
|
2031
|
-
});
|
1973
|
+
return request;
|
2032
1974
|
}
|
2033
|
-
decode(bytes) {
|
2034
|
-
const res =
|
2035
|
-
return new
|
1975
|
+
static decode(bytes) {
|
1976
|
+
const res = StoreQueryRequest$1.decode(bytes);
|
1977
|
+
return new StoreQueryRequest(res);
|
2036
1978
|
}
|
2037
1979
|
encode() {
|
2038
|
-
return
|
1980
|
+
return StoreQueryRequest$1.encode(this.proto);
|
2039
1981
|
}
|
2040
1982
|
}
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
1983
|
+
class StoreQueryResponse {
|
1984
|
+
proto;
|
1985
|
+
constructor(proto) {
|
1986
|
+
this.proto = proto;
|
1987
|
+
}
|
1988
|
+
static decode(bytes) {
|
1989
|
+
const res = StoreQueryResponse$1.decode(bytes);
|
1990
|
+
return new StoreQueryResponse(res);
|
1991
|
+
}
|
1992
|
+
encode() {
|
1993
|
+
return StoreQueryResponse$1.encode(this.proto);
|
1994
|
+
}
|
1995
|
+
get statusCode() {
|
1996
|
+
return this.proto.statusCode;
|
1997
|
+
}
|
1998
|
+
get statusDesc() {
|
1999
|
+
return this.proto.statusDesc;
|
2000
|
+
}
|
2001
|
+
get messages() {
|
2002
|
+
return this.proto.messages;
|
2003
|
+
}
|
2004
|
+
get paginationCursor() {
|
2005
|
+
return this.proto.paginationCursor;
|
2049
2006
|
}
|
2050
2007
|
}
|
2051
2008
|
|
2052
|
-
var HistoryError = HistoryResponse.HistoryError;
|
2053
2009
|
const log$4 = new Logger("store");
|
2054
|
-
const StoreCodec = "/vac/waku/store/
|
2055
|
-
/**
|
2056
|
-
* Implements the [Waku v2 Store protocol](https://rfc.vac.dev/spec/13/).
|
2057
|
-
*
|
2058
|
-
* The Waku Store protocol can be used to retrieved historical messages.
|
2059
|
-
*/
|
2010
|
+
const StoreCodec = "/vac/waku/store-query/3.0.0";
|
2060
2011
|
class StoreCore extends BaseProtocol {
|
2061
|
-
|
2062
|
-
|
2012
|
+
pubsubTopics;
|
2013
|
+
constructor(pubsubTopics, libp2p) {
|
2014
|
+
super(StoreCodec, libp2p.components, log$4, pubsubTopics);
|
2015
|
+
this.pubsubTopics = pubsubTopics;
|
2063
2016
|
}
|
2064
2017
|
async *queryPerPage(queryOpts, decoders, peer) {
|
2065
2018
|
if (queryOpts.contentTopics.toString() !==
|
2066
2019
|
Array.from(decoders.keys()).toString()) {
|
2067
2020
|
throw new Error("Internal error, the decoders should match the query's content topics");
|
2068
2021
|
}
|
2069
|
-
let currentCursor = queryOpts.
|
2022
|
+
let currentCursor = queryOpts.paginationCursor;
|
2070
2023
|
while (true) {
|
2071
|
-
|
2072
|
-
|
2024
|
+
const storeQueryRequest = StoreQueryRequest.create({
|
2025
|
+
...queryOpts,
|
2026
|
+
paginationCursor: currentCursor
|
2027
|
+
});
|
2073
2028
|
let stream;
|
2074
2029
|
try {
|
2075
2030
|
stream = await this.getStream(peer);
|
@@ -2078,50 +2033,48 @@ class StoreCore extends BaseProtocol {
|
|
2078
2033
|
log$4.error("Failed to get stream", e);
|
2079
2034
|
break;
|
2080
2035
|
}
|
2081
|
-
const res = await pipe([
|
2036
|
+
const res = await pipe([storeQueryRequest.encode()], encode, stream, decode, async (source) => await all(source));
|
2082
2037
|
const bytes = new Uint8ArrayList();
|
2083
2038
|
res.forEach((chunk) => {
|
2084
2039
|
bytes.append(chunk);
|
2085
2040
|
});
|
2086
|
-
const
|
2087
|
-
if (!
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
if (!response.messages || !response.messages.length) {
|
2096
|
-
log$4.warn("Stopping pagination due to store `response.messages` field missing or empty");
|
2041
|
+
const storeQueryResponse = StoreQueryResponse.decode(bytes);
|
2042
|
+
if (!storeQueryResponse.statusCode ||
|
2043
|
+
storeQueryResponse.statusCode >= 300) {
|
2044
|
+
const errorMessage = `Store query failed with status code: ${storeQueryResponse.statusCode}, description: ${storeQueryResponse.statusDesc}`;
|
2045
|
+
log$4.error(errorMessage);
|
2046
|
+
throw new Error(errorMessage);
|
2047
|
+
}
|
2048
|
+
if (!storeQueryResponse.messages || !storeQueryResponse.messages.length) {
|
2049
|
+
log$4.warn("Stopping pagination due to empty messages in response");
|
2097
2050
|
break;
|
2098
2051
|
}
|
2099
|
-
log$4.
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2052
|
+
log$4.info(`${storeQueryResponse.messages.length} messages retrieved from store`);
|
2053
|
+
const decodedMessages = storeQueryResponse.messages.map((protoMsg) => {
|
2054
|
+
if (!protoMsg.message) {
|
2055
|
+
return Promise.resolve(undefined);
|
2056
|
+
}
|
2057
|
+
const contentTopic = protoMsg.message.contentTopic;
|
2058
|
+
if (contentTopic) {
|
2103
2059
|
const decoder = decoders.get(contentTopic);
|
2104
2060
|
if (decoder) {
|
2105
|
-
return decoder.fromProtoObj(
|
2061
|
+
return decoder.fromProtoObj(protoMsg.pubsubTopic || "", toProtoMessage(protoMsg.message));
|
2106
2062
|
}
|
2107
2063
|
}
|
2108
2064
|
return Promise.resolve(undefined);
|
2109
2065
|
});
|
2110
|
-
|
2111
|
-
if (
|
2112
|
-
|
2113
|
-
|
2114
|
-
|
2115
|
-
|
2066
|
+
yield decodedMessages;
|
2067
|
+
if (queryOpts.paginationForward) {
|
2068
|
+
currentCursor =
|
2069
|
+
storeQueryResponse.messages[storeQueryResponse.messages.length - 1]
|
2070
|
+
.messageHash;
|
2071
|
+
}
|
2072
|
+
else {
|
2073
|
+
currentCursor = storeQueryResponse.messages[0].messageHash;
|
2116
2074
|
}
|
2117
|
-
|
2118
|
-
|
2119
|
-
|
2120
|
-
if (
|
2121
|
-
// Response page size smaller than query, meaning this is the last page
|
2122
|
-
responsePageSize &&
|
2123
|
-
queryPageSize &&
|
2124
|
-
responsePageSize < queryPageSize) {
|
2075
|
+
if (storeQueryResponse.messages.length > MAX_PAGE_SIZE &&
|
2076
|
+
storeQueryResponse.messages.length <
|
2077
|
+
(queryOpts.paginationLimit || DEFAULT_PAGE_SIZE)) {
|
2125
2078
|
break;
|
2126
2079
|
}
|
2127
2080
|
}
|
@@ -2130,7 +2083,6 @@ class StoreCore extends BaseProtocol {
|
|
2130
2083
|
|
2131
2084
|
var index = /*#__PURE__*/Object.freeze({
|
2132
2085
|
__proto__: null,
|
2133
|
-
get PageDirection () { return PageDirection; },
|
2134
2086
|
StoreCodec: StoreCodec,
|
2135
2087
|
StoreCore: StoreCore
|
2136
2088
|
});
|
@@ -3098,15 +3050,84 @@ class ConnectionManager extends TypedEventEmitter {
|
|
3098
3050
|
}
|
3099
3051
|
}
|
3100
3052
|
|
3053
|
+
class HealthManager {
|
3054
|
+
static instance;
|
3055
|
+
health;
|
3056
|
+
constructor() {
|
3057
|
+
this.health = {
|
3058
|
+
overallStatus: HealthStatus.Unhealthy,
|
3059
|
+
protocolStatuses: new Map()
|
3060
|
+
};
|
3061
|
+
}
|
3062
|
+
static getInstance() {
|
3063
|
+
if (!HealthManager.instance) {
|
3064
|
+
HealthManager.instance = new HealthManager();
|
3065
|
+
}
|
3066
|
+
return HealthManager.instance;
|
3067
|
+
}
|
3068
|
+
getHealthStatus() {
|
3069
|
+
return this.health.overallStatus;
|
3070
|
+
}
|
3071
|
+
getProtocolStatus(protocol) {
|
3072
|
+
return this.health.protocolStatuses.get(protocol);
|
3073
|
+
}
|
3074
|
+
updateProtocolHealth(multicodec, connectedPeers) {
|
3075
|
+
const protocol = this.getNameFromMulticodec(multicodec);
|
3076
|
+
let status = HealthStatus.Unhealthy;
|
3077
|
+
if (connectedPeers == 1) {
|
3078
|
+
status = HealthStatus.MinimallyHealthy;
|
3079
|
+
}
|
3080
|
+
else if (connectedPeers >= 2) {
|
3081
|
+
status = HealthStatus.SufficientlyHealthy;
|
3082
|
+
}
|
3083
|
+
this.health.protocolStatuses.set(protocol, {
|
3084
|
+
name: protocol,
|
3085
|
+
status: status,
|
3086
|
+
lastUpdate: new Date()
|
3087
|
+
});
|
3088
|
+
this.updateOverallHealth();
|
3089
|
+
}
|
3090
|
+
getNameFromMulticodec(multicodec) {
|
3091
|
+
let name;
|
3092
|
+
if (multicodec.includes("filter")) {
|
3093
|
+
name = Protocols.Filter;
|
3094
|
+
}
|
3095
|
+
else if (multicodec.includes("lightpush")) {
|
3096
|
+
name = Protocols.LightPush;
|
3097
|
+
}
|
3098
|
+
else if (multicodec.includes("store")) {
|
3099
|
+
name = Protocols.Store;
|
3100
|
+
}
|
3101
|
+
else {
|
3102
|
+
throw new Error(`Unknown protocol: ${multicodec}`);
|
3103
|
+
}
|
3104
|
+
return name;
|
3105
|
+
}
|
3106
|
+
updateOverallHealth() {
|
3107
|
+
const relevantProtocols = [Protocols.LightPush, Protocols.Filter];
|
3108
|
+
const statuses = relevantProtocols.map((p) => this.getProtocolStatus(p)?.status);
|
3109
|
+
if (statuses.some((status) => status === HealthStatus.Unhealthy)) {
|
3110
|
+
this.health.overallStatus = HealthStatus.Unhealthy;
|
3111
|
+
}
|
3112
|
+
else if (statuses.some((status) => status === HealthStatus.MinimallyHealthy)) {
|
3113
|
+
this.health.overallStatus = HealthStatus.MinimallyHealthy;
|
3114
|
+
}
|
3115
|
+
else {
|
3116
|
+
this.health.overallStatus = HealthStatus.SufficientlyHealthy;
|
3117
|
+
}
|
3118
|
+
}
|
3119
|
+
}
|
3120
|
+
const getHealthManager = () => HealthManager.getInstance();
|
3121
|
+
|
3101
3122
|
const log = new Logger("metadata");
|
3102
3123
|
const MetadataCodec = "/vac/waku/metadata/1.0.0";
|
3103
3124
|
class Metadata extends BaseProtocol {
|
3104
|
-
|
3125
|
+
pubsubTopics;
|
3105
3126
|
libp2pComponents;
|
3106
3127
|
handshakesConfirmed = new Map();
|
3107
|
-
constructor(
|
3108
|
-
super(MetadataCodec, libp2p.components, log,
|
3109
|
-
this.
|
3128
|
+
constructor(pubsubTopics, libp2p) {
|
3129
|
+
super(MetadataCodec, libp2p.components, log, pubsubTopics);
|
3130
|
+
this.pubsubTopics = pubsubTopics;
|
3110
3131
|
this.libp2pComponents = libp2p;
|
3111
3132
|
void libp2p.registrar.handle(MetadataCodec, (streamData) => {
|
3112
3133
|
void this.onRequest(streamData);
|
@@ -3116,7 +3137,7 @@ class Metadata extends BaseProtocol {
|
|
3116
3137
|
* Make a metadata query to a peer
|
3117
3138
|
*/
|
3118
3139
|
async query(peerId) {
|
3119
|
-
const request = WakuMetadataRequest.encode(this.
|
3140
|
+
const request = WakuMetadataRequest.encode(pubsubTopicsToShardInfo(this.pubsubTopics));
|
3120
3141
|
const peer = await this.peerStore.get(peerId);
|
3121
3142
|
if (!peer) {
|
3122
3143
|
return {
|
@@ -3165,7 +3186,7 @@ class Metadata extends BaseProtocol {
|
|
3165
3186
|
async onRequest(streamData) {
|
3166
3187
|
try {
|
3167
3188
|
const { stream, connection } = streamData;
|
3168
|
-
const encodedShardInfo = WakuMetadataResponse.encode(this.
|
3189
|
+
const encodedShardInfo = WakuMetadataResponse.encode(pubsubTopicsToShardInfo(this.pubsubTopics));
|
3169
3190
|
const encodedResponse = await pipe([encodedShardInfo], encode, stream, decode, async (source) => await all(source));
|
3170
3191
|
const { error, shardInfo } = this.decodeMetadataResponse(encodedResponse);
|
3171
3192
|
if (error) {
|
@@ -3205,8 +3226,8 @@ class Metadata extends BaseProtocol {
|
|
3205
3226
|
this.handshakesConfirmed.set(peerId.toString(), shardInfo);
|
3206
3227
|
}
|
3207
3228
|
}
|
3208
|
-
function wakuMetadata(
|
3209
|
-
return (components) => new Metadata(
|
3229
|
+
function wakuMetadata(pubsubTopics) {
|
3230
|
+
return (components) => new Metadata(pubsubTopics, components);
|
3210
3231
|
}
|
3211
3232
|
|
3212
|
-
export { ConnectionManager, FilterCodecs, FilterCore, KeepAliveManager, LightPushCodec, LightPushCore, MetadataCodec,
|
3233
|
+
export { ConnectionManager, FilterCodecs, FilterCore, KeepAliveManager, LightPushCodec, LightPushCore, MetadataCodec, StoreCore, createEncoder, getHealthManager, index$3 as message, waitForRemotePeer, wakuMetadata, index$2 as waku_filter, index$1 as waku_light_push, index as waku_store };
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import '../index-
|
2
|
-
export { B as BaseProtocol } from '../base_protocol-
|
1
|
+
import '../index-Gts2Ddu_.js';
|
2
|
+
export { B as BaseProtocol } from '../base_protocol-Dge5_tvU.js';
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export { D as DecodedMessage,
|
2
|
-
import '../../index-
|
1
|
+
export { D as DecodedMessage, j as Decoder, E as Encoder, V as Version, i as createDecoder, g as createEncoder, m as proto } from '../../version_0-CNRKFufI.js';
|
2
|
+
import '../../index-Gts2Ddu_.js';
|