@waku/core 0.0.34-c43cec2.0 → 0.0.34-c86e056.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-CCK9RCtH.js} +19 -20
- package/bundle/{index-yLOEQnIE.js → index-Db7LxDrL.js} +75 -39
- package/bundle/index.js +1815 -133
- 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-ANFNAdFD.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/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/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-Db7LxDrL.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;
|
@@ -746,6 +759,10 @@ var EConnectionStateEvents;
|
|
746
759
|
EConnectionStateEvents["CONNECTION_STATUS"] = "waku:connection";
|
747
760
|
})(EConnectionStateEvents || (EConnectionStateEvents = {}));
|
748
761
|
|
762
|
+
var HealthStatusChangeEvents;
|
763
|
+
(function (HealthStatusChangeEvents) {
|
764
|
+
HealthStatusChangeEvents["StatusChange"] = "health:change";
|
765
|
+
})(HealthStatusChangeEvents || (HealthStatusChangeEvents = {}));
|
749
766
|
var HealthStatus;
|
750
767
|
(function (HealthStatus) {
|
751
768
|
HealthStatus["Unhealthy"] = "Unhealthy";
|
@@ -1097,24 +1114,62 @@ function setup(env) {
|
|
1097
1114
|
createDebug.names = [];
|
1098
1115
|
createDebug.skips = [];
|
1099
1116
|
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1117
|
+
const split = (typeof namespaces === 'string' ? namespaces : '')
|
1118
|
+
.trim()
|
1119
|
+
.replace(' ', ',')
|
1120
|
+
.split(',')
|
1121
|
+
.filter(Boolean);
|
1103
1122
|
|
1104
|
-
for (
|
1105
|
-
if (
|
1106
|
-
|
1107
|
-
|
1123
|
+
for (const ns of split) {
|
1124
|
+
if (ns[0] === '-') {
|
1125
|
+
createDebug.skips.push(ns.slice(1));
|
1126
|
+
} else {
|
1127
|
+
createDebug.names.push(ns);
|
1108
1128
|
}
|
1129
|
+
}
|
1130
|
+
}
|
1109
1131
|
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1132
|
+
/**
|
1133
|
+
* Checks if the given string matches a namespace template, honoring
|
1134
|
+
* asterisks as wildcards.
|
1135
|
+
*
|
1136
|
+
* @param {String} search
|
1137
|
+
* @param {String} template
|
1138
|
+
* @return {Boolean}
|
1139
|
+
*/
|
1140
|
+
function matchesTemplate(search, template) {
|
1141
|
+
let searchIndex = 0;
|
1142
|
+
let templateIndex = 0;
|
1143
|
+
let starIndex = -1;
|
1144
|
+
let matchIndex = 0;
|
1145
|
+
|
1146
|
+
while (searchIndex < search.length) {
|
1147
|
+
if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
|
1148
|
+
// Match character or proceed with wildcard
|
1149
|
+
if (template[templateIndex] === '*') {
|
1150
|
+
starIndex = templateIndex;
|
1151
|
+
matchIndex = searchIndex;
|
1152
|
+
templateIndex++; // Skip the '*'
|
1153
|
+
} else {
|
1154
|
+
searchIndex++;
|
1155
|
+
templateIndex++;
|
1156
|
+
}
|
1157
|
+
} else if (starIndex !== -1) { // eslint-disable-line no-negated-condition
|
1158
|
+
// Backtrack to the last '*' and try to match more characters
|
1159
|
+
templateIndex = starIndex + 1;
|
1160
|
+
matchIndex++;
|
1161
|
+
searchIndex = matchIndex;
|
1114
1162
|
} else {
|
1115
|
-
|
1163
|
+
return false; // No match
|
1116
1164
|
}
|
1117
1165
|
}
|
1166
|
+
|
1167
|
+
// Handle trailing '*' in template
|
1168
|
+
while (templateIndex < template.length && template[templateIndex] === '*') {
|
1169
|
+
templateIndex++;
|
1170
|
+
}
|
1171
|
+
|
1172
|
+
return templateIndex === template.length;
|
1118
1173
|
}
|
1119
1174
|
|
1120
1175
|
/**
|
@@ -1125,8 +1180,8 @@ function setup(env) {
|
|
1125
1180
|
*/
|
1126
1181
|
function disable() {
|
1127
1182
|
const namespaces = [
|
1128
|
-
...createDebug.names
|
1129
|
-
...createDebug.skips.map(
|
1183
|
+
...createDebug.names,
|
1184
|
+
...createDebug.skips.map(namespace => '-' + namespace)
|
1130
1185
|
].join(',');
|
1131
1186
|
createDebug.enable('');
|
1132
1187
|
return namespaces;
|
@@ -1140,21 +1195,14 @@ function setup(env) {
|
|
1140
1195
|
* @api public
|
1141
1196
|
*/
|
1142
1197
|
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)) {
|
1198
|
+
for (const skip of createDebug.skips) {
|
1199
|
+
if (matchesTemplate(name, skip)) {
|
1152
1200
|
return false;
|
1153
1201
|
}
|
1154
1202
|
}
|
1155
1203
|
|
1156
|
-
for (
|
1157
|
-
if (
|
1204
|
+
for (const ns of createDebug.names) {
|
1205
|
+
if (matchesTemplate(name, ns)) {
|
1158
1206
|
return true;
|
1159
1207
|
}
|
1160
1208
|
}
|
@@ -1162,19 +1210,6 @@ function setup(env) {
|
|
1162
1210
|
return false;
|
1163
1211
|
}
|
1164
1212
|
|
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
1213
|
/**
|
1179
1214
|
* Coerce `val`.
|
1180
1215
|
*
|
@@ -1336,6 +1371,7 @@ var common = setup;
|
|
1336
1371
|
|
1337
1372
|
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
1338
1373
|
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
1374
|
+
// eslint-disable-next-line no-return-assign
|
1339
1375
|
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
1340
1376
|
// Is firebug? http://stackoverflow.com/a/398120/376773
|
1341
1377
|
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
@@ -1509,4 +1545,4 @@ class Logger {
|
|
1509
1545
|
}
|
1510
1546
|
}
|
1511
1547
|
|
1512
|
-
export { EPeersByDiscoveryEvents as E,
|
1548
|
+
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 };
|