@waku/core 0.0.34-c43cec2.0 → 0.0.34-caeafce.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-DxFKDXX2.js → base_protocol-Bp5a9PNG.js} +19 -20
- package/bundle/{index-yLOEQnIE.js → index-G1eRBjeI.js} +115 -84
- package/bundle/index.js +1828 -153
- package/bundle/lib/base_protocol.js +2 -2
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/{version_0-Che4t3mN.js → version_0-DJZG2fB2.js} +163 -42
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +2 -2
- package/dist/lib/base_protocol.js +2 -2
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager/connection_manager.d.ts +56 -3
- package/dist/lib/connection_manager/connection_manager.js +96 -13
- package/dist/lib/connection_manager/connection_manager.js.map +1 -1
- package/dist/lib/filter/filter.d.ts +18 -0
- package/dist/lib/filter/filter.js +209 -0
- package/dist/lib/filter/filter.js.map +1 -0
- package/dist/lib/filter/index.d.ts +1 -18
- package/dist/lib/filter/index.js +1 -208
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/light_push/index.d.ts +1 -15
- package/dist/lib/light_push/index.js +1 -144
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/light_push.d.ts +15 -0
- package/dist/lib/light_push/light_push.js +144 -0
- package/dist/lib/light_push/light_push.js.map +1 -0
- package/dist/lib/light_push/utils.d.ts +0 -2
- package/dist/lib/light_push/utils.js +9 -17
- package/dist/lib/light_push/utils.js.map +1 -1
- package/dist/lib/metadata/index.d.ts +1 -3
- package/dist/lib/metadata/index.js +1 -118
- package/dist/lib/metadata/index.js.map +1 -1
- package/dist/lib/metadata/metadata.d.ts +3 -0
- package/dist/lib/metadata/metadata.js +119 -0
- package/dist/lib/metadata/metadata.js.map +1 -0
- package/dist/lib/store/index.d.ts +1 -9
- package/dist/lib/store/index.js +1 -82
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/store/store.d.ts +9 -0
- package/dist/lib/store/store.js +83 -0
- package/dist/lib/store/store.js.map +1 -0
- package/dist/lib/stream_manager/stream_manager.d.ts +2 -2
- package/dist/lib/stream_manager/stream_manager.js +16 -17
- package/dist/lib/stream_manager/stream_manager.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -2
- package/src/lib/base_protocol.ts +3 -3
- package/src/lib/connection_manager/connection_manager.ts +114 -20
- package/src/lib/filter/filter.ts +315 -0
- package/src/lib/filter/index.ts +1 -315
- package/src/lib/light_push/index.ts +1 -189
- package/src/lib/light_push/light_push.ts +188 -0
- package/src/lib/light_push/utils.ts +13 -21
- package/src/lib/metadata/index.ts +1 -182
- package/src/lib/metadata/metadata.ts +182 -0
- package/src/lib/store/index.ts +1 -136
- package/src/lib/store/store.ts +136 -0
- package/src/lib/stream_manager/stream_manager.ts +16 -18
- package/dist/lib/health_manager.d.ts +0 -14
- package/dist/lib/health_manager.js +0 -70
- package/dist/lib/health_manager.js.map +0 -1
- package/src/lib/health_manager.ts +0 -90
@@ -1,4 +1,4 @@
|
|
1
|
-
import { L as Logger } from './index-
|
1
|
+
import { L as Logger } from './index-G1eRBjeI.js';
|
2
2
|
|
3
3
|
function selectOpenConnection(connections) {
|
4
4
|
return connections
|
@@ -22,36 +22,36 @@ class StreamManager {
|
|
22
22
|
this.log = new Logger(`stream-manager:${multicodec}`);
|
23
23
|
this.addEventListener("peer:update", this.handlePeerUpdateStreamPool);
|
24
24
|
}
|
25
|
-
async getStream(
|
26
|
-
const
|
27
|
-
const scheduledStream = this.streamPool.get(
|
25
|
+
async getStream(peerId) {
|
26
|
+
const peerIdStr = peerId.toString();
|
27
|
+
const scheduledStream = this.streamPool.get(peerIdStr);
|
28
28
|
if (scheduledStream) {
|
29
|
-
this.streamPool.delete(
|
29
|
+
this.streamPool.delete(peerIdStr);
|
30
30
|
await scheduledStream;
|
31
31
|
}
|
32
|
-
let stream = this.getOpenStreamForCodec(
|
32
|
+
let stream = this.getOpenStreamForCodec(peerId);
|
33
33
|
if (stream) {
|
34
|
-
this.log.info(`Found existing stream peerId=${
|
35
|
-
this.lockStream(
|
34
|
+
this.log.info(`Found existing stream peerId=${peerIdStr} multicodec=${this.multicodec}`);
|
35
|
+
this.lockStream(peerIdStr, stream);
|
36
36
|
return stream;
|
37
37
|
}
|
38
|
-
stream = await this.createStream(
|
39
|
-
this.lockStream(
|
38
|
+
stream = await this.createStream(peerId);
|
39
|
+
this.lockStream(peerIdStr, stream);
|
40
40
|
return stream;
|
41
41
|
}
|
42
|
-
async createStream(
|
43
|
-
const connections = this.getConnections(
|
42
|
+
async createStream(peerId, retries = 0) {
|
43
|
+
const connections = this.getConnections(peerId);
|
44
44
|
const connection = selectOpenConnection(connections);
|
45
45
|
if (!connection) {
|
46
|
-
throw new Error(`Failed to get a connection to the peer peerId=${
|
46
|
+
throw new Error(`Failed to get a connection to the peer peerId=${peerId.toString()} multicodec=${this.multicodec}`);
|
47
47
|
}
|
48
48
|
let lastError;
|
49
49
|
let stream;
|
50
50
|
for (let i = 0; i < retries + 1; i++) {
|
51
51
|
try {
|
52
|
-
this.log.info(`Attempting to create a stream for peerId=${
|
52
|
+
this.log.info(`Attempting to create a stream for peerId=${peerId.toString()} multicodec=${this.multicodec}`);
|
53
53
|
stream = await connection.newStream(this.multicodec);
|
54
|
-
this.log.info(`Created stream for peerId=${
|
54
|
+
this.log.info(`Created stream for peerId=${peerId.toString()} multicodec=${this.multicodec}`);
|
55
55
|
break;
|
56
56
|
}
|
57
57
|
catch (error) {
|
@@ -59,8 +59,7 @@ class StreamManager {
|
|
59
59
|
}
|
60
60
|
}
|
61
61
|
if (!stream) {
|
62
|
-
throw new Error(`Failed to create a new stream for ${
|
63
|
-
lastError);
|
62
|
+
throw new Error(`Failed to create a new stream for ${peerId.toString()} -- ` + lastError);
|
64
63
|
}
|
65
64
|
return stream;
|
66
65
|
}
|
@@ -72,7 +71,7 @@ class StreamManager {
|
|
72
71
|
}
|
73
72
|
try {
|
74
73
|
this.ongoingCreation.add(peerId);
|
75
|
-
await this.createStream(peer);
|
74
|
+
await this.createStream(peer.id);
|
76
75
|
}
|
77
76
|
catch (error) {
|
78
77
|
this.log.error(`Failed to createStreamWithLock:`, error);
|
@@ -145,8 +144,8 @@ class BaseProtocol {
|
|
145
144
|
this.removeLibp2pEventListener = components.events.removeEventListener.bind(components.events);
|
146
145
|
this.streamManager = new StreamManager(multicodec, components.connectionManager.getConnections.bind(components.connectionManager), this.addLibp2pEventListener);
|
147
146
|
}
|
148
|
-
async getStream(
|
149
|
-
return this.streamManager.getStream(
|
147
|
+
async getStream(peerId) {
|
148
|
+
return this.streamManager.getStream(peerId);
|
150
149
|
}
|
151
150
|
}
|
152
151
|
|
@@ -1,3 +1,16 @@
|
|
1
|
+
function equals(aa, bb) {
|
2
|
+
if (aa === bb)
|
3
|
+
return true;
|
4
|
+
if (aa.byteLength !== bb.byteLength) {
|
5
|
+
return false;
|
6
|
+
}
|
7
|
+
for (let ii = 0; ii < aa.byteLength; ii++) {
|
8
|
+
if (aa[ii] !== bb[ii]) {
|
9
|
+
return false;
|
10
|
+
}
|
11
|
+
}
|
12
|
+
return true;
|
13
|
+
}
|
1
14
|
function coerce(o) {
|
2
15
|
if (o instanceof Uint8Array && o.constructor.name === 'Uint8Array')
|
3
16
|
return o;
|
@@ -641,43 +654,24 @@ var Protocols;
|
|
641
654
|
})(Protocols || (Protocols = {}));
|
642
655
|
var ProtocolError;
|
643
656
|
(function (ProtocolError) {
|
644
|
-
|
657
|
+
//
|
658
|
+
// GENERAL ERRORS SECTION
|
659
|
+
//
|
660
|
+
/**
|
661
|
+
* Could not determine the origin of the fault. Best to check connectivity and try again
|
662
|
+
* */
|
645
663
|
ProtocolError["GENERIC_FAIL"] = "Generic error";
|
646
664
|
/**
|
647
|
-
*
|
648
|
-
*
|
665
|
+
* The remote peer rejected the message. Information provided by the remote peer
|
666
|
+
* is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
|
667
|
+
* or `DECODE_FAILED` can be used.
|
649
668
|
*/
|
650
|
-
ProtocolError["
|
669
|
+
ProtocolError["REMOTE_PEER_REJECTED"] = "Remote peer rejected";
|
651
670
|
/**
|
652
671
|
* Failure to protobuf decode the message. May be due to a remote peer issue,
|
653
672
|
* ensuring that messages are sent via several peer enable mitigation of this error.
|
654
673
|
*/
|
655
674
|
ProtocolError["DECODE_FAILED"] = "Failed to decode";
|
656
|
-
/**
|
657
|
-
* The message payload is empty, making the message invalid. Ensure that a non-empty
|
658
|
-
* payload is set on the outgoing message.
|
659
|
-
*/
|
660
|
-
ProtocolError["EMPTY_PAYLOAD"] = "Payload is empty";
|
661
|
-
/**
|
662
|
-
* The message size is above the maximum message size allowed on the Waku Network.
|
663
|
-
* Compressing the message or using an alternative strategy for large messages is recommended.
|
664
|
-
*/
|
665
|
-
ProtocolError["SIZE_TOO_BIG"] = "Size is too big";
|
666
|
-
/**
|
667
|
-
* The PubsubTopic passed to the send function is not configured on the Waku node.
|
668
|
-
* Please ensure that the PubsubTopic is used when initializing the Waku node.
|
669
|
-
*/
|
670
|
-
ProtocolError["TOPIC_NOT_CONFIGURED"] = "Topic not configured";
|
671
|
-
/**
|
672
|
-
* The pubsub topic configured on the decoder does not match the pubsub topic setup on the protocol.
|
673
|
-
* Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
|
674
|
-
*/
|
675
|
-
ProtocolError["TOPIC_DECODER_MISMATCH"] = "Topic decoder mismatch";
|
676
|
-
/**
|
677
|
-
* The topics passed in the decoders do not match each other, or don't exist at all.
|
678
|
-
* Ensure that all the pubsub topics used in the decoders are valid and match each other.
|
679
|
-
*/
|
680
|
-
ProtocolError["INVALID_DECODER_TOPICS"] = "Invalid decoder topics";
|
681
675
|
/**
|
682
676
|
* Failure to find a peer with suitable protocols. This may due to a connection issue.
|
683
677
|
* Mitigation can be: retrying after a given time period, display connectivity issue
|
@@ -695,37 +689,51 @@ var ProtocolError;
|
|
695
689
|
* or `DECODE_FAILED` can be used.
|
696
690
|
*/
|
697
691
|
ProtocolError["NO_RESPONSE"] = "No response received";
|
692
|
+
//
|
693
|
+
// SEND ERRORS SECTION
|
694
|
+
//
|
698
695
|
/**
|
699
|
-
*
|
700
|
-
*
|
701
|
-
* or `DECODE_FAILED` can be used.
|
696
|
+
* Failure to protobuf encode the message. This is not recoverable and needs
|
697
|
+
* further investigation.
|
702
698
|
*/
|
703
|
-
ProtocolError["
|
699
|
+
ProtocolError["ENCODE_FAILED"] = "Failed to encode";
|
704
700
|
/**
|
705
|
-
* The
|
706
|
-
*
|
701
|
+
* The message payload is empty, making the message invalid. Ensure that a non-empty
|
702
|
+
* payload is set on the outgoing message.
|
707
703
|
*/
|
708
|
-
ProtocolError["
|
704
|
+
ProtocolError["EMPTY_PAYLOAD"] = "Payload is empty";
|
709
705
|
/**
|
710
|
-
*
|
711
|
-
*
|
706
|
+
* The message size is above the maximum message size allowed on the Waku Network.
|
707
|
+
* Compressing the message or using an alternative strategy for large messages is recommended.
|
712
708
|
*/
|
713
|
-
ProtocolError["
|
709
|
+
ProtocolError["SIZE_TOO_BIG"] = "Size is too big";
|
714
710
|
/**
|
715
|
-
*
|
716
|
-
*
|
711
|
+
* The PubsubTopic passed to the send function is not configured on the Waku node.
|
712
|
+
* Please ensure that the PubsubTopic is used when initializing the Waku node.
|
717
713
|
*/
|
718
|
-
ProtocolError["
|
714
|
+
ProtocolError["TOPIC_NOT_CONFIGURED"] = "Topic not configured";
|
719
715
|
/**
|
720
|
-
*
|
721
|
-
* nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L190
|
716
|
+
* Fails when
|
722
717
|
*/
|
723
|
-
ProtocolError["
|
718
|
+
ProtocolError["STREAM_ABORTED"] = "Stream aborted";
|
724
719
|
/**
|
725
720
|
* General proof generation error message.
|
726
721
|
* nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L201C19-L201C42
|
727
722
|
*/
|
728
723
|
ProtocolError["RLN_PROOF_GENERATION"] = "Proof generation failed";
|
724
|
+
//
|
725
|
+
// RECEIVE ERRORS SECTION
|
726
|
+
//
|
727
|
+
/**
|
728
|
+
* The pubsub topic configured on the decoder does not match the pubsub topic setup on the protocol.
|
729
|
+
* Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
|
730
|
+
*/
|
731
|
+
ProtocolError["TOPIC_DECODER_MISMATCH"] = "Topic decoder mismatch";
|
732
|
+
/**
|
733
|
+
* The topics passed in the decoders do not match each other, or don't exist at all.
|
734
|
+
* Ensure that all the pubsub topics used in the decoders are valid and match each other.
|
735
|
+
*/
|
736
|
+
ProtocolError["INVALID_DECODER_TOPICS"] = "Invalid decoder topics";
|
729
737
|
})(ProtocolError || (ProtocolError = {}));
|
730
738
|
|
731
739
|
var Tags;
|
@@ -746,6 +754,10 @@ var EConnectionStateEvents;
|
|
746
754
|
EConnectionStateEvents["CONNECTION_STATUS"] = "waku:connection";
|
747
755
|
})(EConnectionStateEvents || (EConnectionStateEvents = {}));
|
748
756
|
|
757
|
+
var HealthStatusChangeEvents;
|
758
|
+
(function (HealthStatusChangeEvents) {
|
759
|
+
HealthStatusChangeEvents["StatusChange"] = "health:change";
|
760
|
+
})(HealthStatusChangeEvents || (HealthStatusChangeEvents = {}));
|
749
761
|
var HealthStatus;
|
750
762
|
(function (HealthStatus) {
|
751
763
|
HealthStatus["Unhealthy"] = "Unhealthy";
|
@@ -1097,24 +1109,62 @@ function setup(env) {
|
|
1097
1109
|
createDebug.names = [];
|
1098
1110
|
createDebug.skips = [];
|
1099
1111
|
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1112
|
+
const split = (typeof namespaces === 'string' ? namespaces : '')
|
1113
|
+
.trim()
|
1114
|
+
.replace(' ', ',')
|
1115
|
+
.split(',')
|
1116
|
+
.filter(Boolean);
|
1103
1117
|
|
1104
|
-
for (
|
1105
|
-
if (
|
1106
|
-
|
1107
|
-
|
1118
|
+
for (const ns of split) {
|
1119
|
+
if (ns[0] === '-') {
|
1120
|
+
createDebug.skips.push(ns.slice(1));
|
1121
|
+
} else {
|
1122
|
+
createDebug.names.push(ns);
|
1108
1123
|
}
|
1124
|
+
}
|
1125
|
+
}
|
1109
1126
|
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1127
|
+
/**
|
1128
|
+
* Checks if the given string matches a namespace template, honoring
|
1129
|
+
* asterisks as wildcards.
|
1130
|
+
*
|
1131
|
+
* @param {String} search
|
1132
|
+
* @param {String} template
|
1133
|
+
* @return {Boolean}
|
1134
|
+
*/
|
1135
|
+
function matchesTemplate(search, template) {
|
1136
|
+
let searchIndex = 0;
|
1137
|
+
let templateIndex = 0;
|
1138
|
+
let starIndex = -1;
|
1139
|
+
let matchIndex = 0;
|
1140
|
+
|
1141
|
+
while (searchIndex < search.length) {
|
1142
|
+
if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
|
1143
|
+
// Match character or proceed with wildcard
|
1144
|
+
if (template[templateIndex] === '*') {
|
1145
|
+
starIndex = templateIndex;
|
1146
|
+
matchIndex = searchIndex;
|
1147
|
+
templateIndex++; // Skip the '*'
|
1148
|
+
} else {
|
1149
|
+
searchIndex++;
|
1150
|
+
templateIndex++;
|
1151
|
+
}
|
1152
|
+
} else if (starIndex !== -1) { // eslint-disable-line no-negated-condition
|
1153
|
+
// Backtrack to the last '*' and try to match more characters
|
1154
|
+
templateIndex = starIndex + 1;
|
1155
|
+
matchIndex++;
|
1156
|
+
searchIndex = matchIndex;
|
1114
1157
|
} else {
|
1115
|
-
|
1158
|
+
return false; // No match
|
1116
1159
|
}
|
1117
1160
|
}
|
1161
|
+
|
1162
|
+
// Handle trailing '*' in template
|
1163
|
+
while (templateIndex < template.length && template[templateIndex] === '*') {
|
1164
|
+
templateIndex++;
|
1165
|
+
}
|
1166
|
+
|
1167
|
+
return templateIndex === template.length;
|
1118
1168
|
}
|
1119
1169
|
|
1120
1170
|
/**
|
@@ -1125,8 +1175,8 @@ function setup(env) {
|
|
1125
1175
|
*/
|
1126
1176
|
function disable() {
|
1127
1177
|
const namespaces = [
|
1128
|
-
...createDebug.names
|
1129
|
-
...createDebug.skips.map(
|
1178
|
+
...createDebug.names,
|
1179
|
+
...createDebug.skips.map(namespace => '-' + namespace)
|
1130
1180
|
].join(',');
|
1131
1181
|
createDebug.enable('');
|
1132
1182
|
return namespaces;
|
@@ -1140,21 +1190,14 @@ function setup(env) {
|
|
1140
1190
|
* @api public
|
1141
1191
|
*/
|
1142
1192
|
function enabled(name) {
|
1143
|
-
|
1144
|
-
|
1145
|
-
}
|
1146
|
-
|
1147
|
-
let i;
|
1148
|
-
let len;
|
1149
|
-
|
1150
|
-
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
1151
|
-
if (createDebug.skips[i].test(name)) {
|
1193
|
+
for (const skip of createDebug.skips) {
|
1194
|
+
if (matchesTemplate(name, skip)) {
|
1152
1195
|
return false;
|
1153
1196
|
}
|
1154
1197
|
}
|
1155
1198
|
|
1156
|
-
for (
|
1157
|
-
if (
|
1199
|
+
for (const ns of createDebug.names) {
|
1200
|
+
if (matchesTemplate(name, ns)) {
|
1158
1201
|
return true;
|
1159
1202
|
}
|
1160
1203
|
}
|
@@ -1162,19 +1205,6 @@ function setup(env) {
|
|
1162
1205
|
return false;
|
1163
1206
|
}
|
1164
1207
|
|
1165
|
-
/**
|
1166
|
-
* Convert regexp to namespace
|
1167
|
-
*
|
1168
|
-
* @param {RegExp} regxep
|
1169
|
-
* @return {String} namespace
|
1170
|
-
* @api private
|
1171
|
-
*/
|
1172
|
-
function toNamespace(regexp) {
|
1173
|
-
return regexp.toString()
|
1174
|
-
.substring(2, regexp.toString().length - 2)
|
1175
|
-
.replace(/\.\*\?$/, '*');
|
1176
|
-
}
|
1177
|
-
|
1178
1208
|
/**
|
1179
1209
|
* Coerce `val`.
|
1180
1210
|
*
|
@@ -1336,6 +1366,7 @@ var common = setup;
|
|
1336
1366
|
|
1337
1367
|
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
1338
1368
|
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
1369
|
+
// eslint-disable-next-line no-return-assign
|
1339
1370
|
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
1340
1371
|
// Is firebug? http://stackoverflow.com/a/398120/376773
|
1341
1372
|
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
@@ -1509,4 +1540,4 @@ class Logger {
|
|
1509
1540
|
}
|
1510
1541
|
}
|
1511
1542
|
|
1512
|
-
export { EPeersByDiscoveryEvents as E,
|
1543
|
+
export { EPeersByDiscoveryEvents as E, Logger as L, ProtocolError as P, Tags as T, base32 as a, base36 as b, coerce as c, base58btc as d, equals as e, EConnectionStateEvents as f, base2$1 as g, base8$1 as h, identityBase as i, base10$1 as j, base16$1 as k, base32$1 as l, base36$1 as m, base58 as n, base64$1 as o, base256emoji$1 as p };
|