@waku/core 0.0.26-7eb3375.0 → 0.0.26
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 +30 -0
- package/bundle/{base_protocol-46017f51.js → base_protocol-pDODy0G6.js} +22 -230
- package/bundle/{browser-9a6558bb.js → browser-mTOOnVZp.js} +80 -1
- package/bundle/index-cmONXM-V.js +595 -0
- package/bundle/index.js +358 -425
- package/bundle/lib/base_protocol.js +3 -3
- package/bundle/lib/message/version_0.js +3 -3
- package/bundle/lib/predefined_bootstrap_nodes.js +1 -1
- package/bundle/{version_0-7190df43.js → version_0-LQTFNC7k.js} +118 -11
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +3 -2
- package/dist/lib/base_protocol.js +12 -6
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager.js.map +1 -1
- package/dist/lib/filter/index.js +7 -4
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/filterPeers.js.map +1 -1
- package/dist/lib/keep_alive_manager.js +2 -2
- package/dist/lib/keep_alive_manager.js.map +1 -1
- package/dist/lib/light_push/index.js +1 -2
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/message/version_0.d.ts +3 -3
- package/dist/lib/message/version_0.js +5 -6
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/metadata/index.d.ts +3 -0
- package/dist/lib/metadata/index.js +67 -0
- package/dist/lib/metadata/index.js.map +1 -0
- package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
- package/dist/lib/store/history_rpc.js.map +1 -1
- package/dist/lib/store/index.js +1 -2
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/stream_manager.js.map +1 -1
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/dist/lib/waku.d.ts +3 -3
- package/dist/lib/waku.js +12 -6
- package/dist/lib/waku.js.map +1 -1
- package/package.json +127 -1
- package/src/index.ts +3 -1
- package/src/lib/base_protocol.ts +29 -7
- package/src/lib/filter/index.ts +10 -3
- package/src/lib/keep_alive_manager.ts +2 -2
- package/src/lib/light_push/index.ts +1 -2
- package/src/lib/message/version_0.ts +16 -8
- package/src/lib/metadata/index.ts +110 -0
- package/src/lib/store/index.ts +1 -2
- package/src/lib/waku.ts +14 -4
- package/bundle/index-7581d519.js +0 -31
- package/dist/lib/constants.d.ts +0 -4
- package/dist/lib/constants.js +0 -5
- package/dist/lib/constants.js.map +0 -1
- package/src/lib/constants.ts +0 -4
package/bundle/index.js
CHANGED
@@ -1,15 +1,54 @@
|
|
1
|
-
import { c as coerce, e as equals$2, b as base32, a as base58btc, d as commonjsGlobal, g as getAugmentedNamespace, f as getDefaultExportFromCjs } from './browser-
|
2
|
-
import { a as allocUnsafe, b as asUint8Array, t as toString$1, c as bases, f as fromString, u as utf8ToBytes
|
3
|
-
|
4
|
-
|
5
|
-
import {
|
6
|
-
export {
|
1
|
+
import { c as coerce, e as equals$2, b as base32, a as base58btc, d as commonjsGlobal, g as getAugmentedNamespace, E as EConnectionStateEvents, T as Tags, f as EPeersByDiscoveryEvents, P as Protocols, h as getDefaultExportFromCjs, S as SendError } from './browser-mTOOnVZp.js';
|
2
|
+
import { a as allocUnsafe, b as asUint8Array, t as toString$1, c as bases, f as fromString, L as Logger, u as utf8ToBytes, p as pubsubTopicToSingleShardInfo, s as shardInfoToPubsubTopics, D as DefaultPubsubTopic, d as alloc, e as singleShardInfoToPubsubTopic, g as ensurePubsubTopicIsConfigured, h as sha256$1, i as concat$1 } from './index-cmONXM-V.js';
|
3
|
+
import { e as enumeration, m as message, a as encodeMessage, d as decodeMessage, c as createEncoder, v as version_0, M as MessagePush, F as FilterSubscribeRequest, b as FilterSubscribeResponse$1, P as PushRpc$1, f as PushResponse, H as HistoryRpc$1, g as PagingInfo, h as HistoryResponse, W as WakuMetadataResponse, i as WakuMetadataRequest } from './version_0-LQTFNC7k.js';
|
4
|
+
export { j as createDecoder } from './version_0-LQTFNC7k.js';
|
5
|
+
import { B as BaseProtocol } from './base_protocol-pDODy0G6.js';
|
6
|
+
export { S as StreamManager } from './base_protocol-pDODy0G6.js';
|
7
7
|
|
8
8
|
const symbol$2 = Symbol.for('@libp2p/peer-id');
|
9
9
|
function isPeerId(other) {
|
10
10
|
return other != null && Boolean(other[symbol$2]);
|
11
11
|
}
|
12
12
|
|
13
|
+
/**
|
14
|
+
* On the producing side:
|
15
|
+
* * Build messages with the signature, key (from may be enough for certain inlineable public key types), from and seqno fields.
|
16
|
+
*
|
17
|
+
* On the consuming side:
|
18
|
+
* * Enforce the fields to be present, reject otherwise.
|
19
|
+
* * Propagate only if the fields are valid and signature can be verified, reject otherwise.
|
20
|
+
*/
|
21
|
+
var TopicValidatorResult$1;
|
22
|
+
(function (TopicValidatorResult) {
|
23
|
+
/**
|
24
|
+
* The message is considered valid, and it should be delivered and forwarded to the network
|
25
|
+
*/
|
26
|
+
TopicValidatorResult["Accept"] = "accept";
|
27
|
+
/**
|
28
|
+
* The message is neither delivered nor forwarded to the network
|
29
|
+
*/
|
30
|
+
TopicValidatorResult["Ignore"] = "ignore";
|
31
|
+
/**
|
32
|
+
* The message is considered invalid, and it should be rejected
|
33
|
+
*/
|
34
|
+
TopicValidatorResult["Reject"] = "reject";
|
35
|
+
})(TopicValidatorResult$1 || (TopicValidatorResult$1 = {}));
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Enum Transport Manager Fault Tolerance values
|
39
|
+
*/
|
40
|
+
var FaultTolerance$1;
|
41
|
+
(function (FaultTolerance) {
|
42
|
+
/**
|
43
|
+
* should be used for failing in any listen circumstance
|
44
|
+
*/
|
45
|
+
FaultTolerance[FaultTolerance["FATAL_ALL"] = 0] = "FATAL_ALL";
|
46
|
+
/**
|
47
|
+
* should be used for not failing when not listening
|
48
|
+
*/
|
49
|
+
FaultTolerance[FaultTolerance["NO_FATAL"] = 1] = "NO_FATAL";
|
50
|
+
})(FaultTolerance$1 || (FaultTolerance$1 = {}));
|
51
|
+
|
13
52
|
/**
|
14
53
|
* When this error is thrown it means an operation was aborted,
|
15
54
|
* usually in response to the `abort` event being emitted by an
|
@@ -1315,7 +1354,7 @@ const isV4 = isIPv4;
|
|
1315
1354
|
const isV6 = isIPv6;
|
1316
1355
|
// Copied from https://github.com/indutny/node-ip/blob/master/lib/ip.js#L7
|
1317
1356
|
// but with buf/offset args removed because we don't use them
|
1318
|
-
const toBytes
|
1357
|
+
const toBytes = function (ip) {
|
1319
1358
|
let offset = 0;
|
1320
1359
|
ip = ip.toString().trim();
|
1321
1360
|
if (isV4(ip)) {
|
@@ -1332,7 +1371,7 @@ const toBytes$1 = function (ip) {
|
|
1332
1371
|
const isv4 = isV4(sections[i]);
|
1333
1372
|
let v4Buffer;
|
1334
1373
|
if (isv4) {
|
1335
|
-
v4Buffer = toBytes
|
1374
|
+
v4Buffer = toBytes(sections[i]);
|
1336
1375
|
sections[i] = toString$1(v4Buffer.slice(0, 2), 'base16');
|
1337
1376
|
}
|
1338
1377
|
if (v4Buffer != null && ++i < 8) {
|
@@ -1570,7 +1609,7 @@ function ip2bytes(ipString) {
|
|
1570
1609
|
if (!isIP(ipString)) {
|
1571
1610
|
throw new Error('invalid ip address');
|
1572
1611
|
}
|
1573
|
-
return toBytes
|
1612
|
+
return toBytes(ipString);
|
1574
1613
|
}
|
1575
1614
|
function bytes2ip(ipBuff) {
|
1576
1615
|
const ipString = toString(ipBuff, 0, ipBuff.length);
|
@@ -1841,38 +1880,17 @@ function ParseError(str) {
|
|
1841
1880
|
* ```
|
1842
1881
|
*/
|
1843
1882
|
const inspect = Symbol.for('nodejs.util.inspect.custom');
|
1883
|
+
const symbol$1 = Symbol.for('@multiformats/js-multiaddr/multiaddr');
|
1844
1884
|
const DNS_CODES = [
|
1845
1885
|
getProtocol('dns').code,
|
1846
1886
|
getProtocol('dns4').code,
|
1847
1887
|
getProtocol('dns6').code,
|
1848
1888
|
getProtocol('dnsaddr').code
|
1849
1889
|
];
|
1850
|
-
/**
|
1851
|
-
* All configured {@link Resolver}s
|
1852
|
-
*/
|
1853
|
-
const resolvers = new Map();
|
1854
|
-
const symbol$1 = Symbol.for('@multiformats/js-multiaddr/multiaddr');
|
1855
|
-
/**
|
1856
|
-
* Check if object is a {@link Multiaddr} instance
|
1857
|
-
*
|
1858
|
-
* @example
|
1859
|
-
*
|
1860
|
-
* ```js
|
1861
|
-
* import { isMultiaddr, multiaddr } from '@multiformats/multiaddr'
|
1862
|
-
*
|
1863
|
-
* isMultiaddr(5)
|
1864
|
-
* // false
|
1865
|
-
* isMultiaddr(multiaddr('/ip4/127.0.0.1'))
|
1866
|
-
* // true
|
1867
|
-
* ```
|
1868
|
-
*/
|
1869
|
-
function isMultiaddr(value) {
|
1870
|
-
return Boolean(value?.[symbol$1]);
|
1871
|
-
}
|
1872
1890
|
/**
|
1873
1891
|
* Creates a {@link Multiaddr} from a {@link MultiaddrInput}
|
1874
1892
|
*/
|
1875
|
-
class
|
1893
|
+
class Multiaddr {
|
1876
1894
|
bytes;
|
1877
1895
|
#string;
|
1878
1896
|
#tuples;
|
@@ -1972,8 +1990,8 @@ class DefaultMultiaddr {
|
|
1972
1990
|
return this.#stringTuples;
|
1973
1991
|
}
|
1974
1992
|
encapsulate(addr) {
|
1975
|
-
addr = new
|
1976
|
-
return new
|
1993
|
+
addr = new Multiaddr(addr);
|
1994
|
+
return new Multiaddr(this.toString() + addr.toString());
|
1977
1995
|
}
|
1978
1996
|
decapsulate(addr) {
|
1979
1997
|
const addrString = addr.toString();
|
@@ -1982,13 +2000,13 @@ class DefaultMultiaddr {
|
|
1982
2000
|
if (i < 0) {
|
1983
2001
|
throw new Error(`Address ${this.toString()} does not contain subaddress: ${addr.toString()}`);
|
1984
2002
|
}
|
1985
|
-
return new
|
2003
|
+
return new Multiaddr(s.slice(0, i));
|
1986
2004
|
}
|
1987
2005
|
decapsulateCode(code) {
|
1988
2006
|
const tuples = this.tuples();
|
1989
2007
|
for (let i = tuples.length - 1; i >= 0; i--) {
|
1990
2008
|
if (tuples[i][0] === code) {
|
1991
|
-
return new
|
2009
|
+
return new Multiaddr(tuplesToBytes(tuples.slice(0, i)));
|
1992
2010
|
}
|
1993
2011
|
}
|
1994
2012
|
return this;
|
@@ -2041,7 +2059,7 @@ class DefaultMultiaddr {
|
|
2041
2059
|
throw new CodeError(`no available resolver for ${resolvableProto.name}`, 'ERR_NO_AVAILABLE_RESOLVER');
|
2042
2060
|
}
|
2043
2061
|
const addresses = await resolver(this, options);
|
2044
|
-
return addresses.map((a) => new
|
2062
|
+
return addresses.map((a) => new Multiaddr(a));
|
2045
2063
|
}
|
2046
2064
|
nodeAddress() {
|
2047
2065
|
const options = this.toOptions();
|
@@ -2083,6 +2101,93 @@ class DefaultMultiaddr {
|
|
2083
2101
|
return `Multiaddr(${this.#string})`;
|
2084
2102
|
}
|
2085
2103
|
}
|
2104
|
+
|
2105
|
+
/**
|
2106
|
+
* @packageDocumentation
|
2107
|
+
*
|
2108
|
+
* A standard way to represent addresses that
|
2109
|
+
*
|
2110
|
+
* - support any standard network protocol
|
2111
|
+
* - are self-describing
|
2112
|
+
* - have a binary packed format
|
2113
|
+
* - have a nice string representation
|
2114
|
+
* - encapsulate well
|
2115
|
+
*
|
2116
|
+
* @example
|
2117
|
+
*
|
2118
|
+
* ```js
|
2119
|
+
* import { multiaddr } from '@multiformats/multiaddr'
|
2120
|
+
* const addr = multiaddr("/ip4/127.0.0.1/udp/1234")
|
2121
|
+
* // Multiaddr(/ip4/127.0.0.1/udp/1234)
|
2122
|
+
*
|
2123
|
+
* const addr = multiaddr("/ip4/127.0.0.1/udp/1234")
|
2124
|
+
* // Multiaddr(/ip4/127.0.0.1/udp/1234)
|
2125
|
+
*
|
2126
|
+
* addr.bytes
|
2127
|
+
* // <Uint8Array 04 7f 00 00 01 11 04 d2>
|
2128
|
+
*
|
2129
|
+
* addr.toString()
|
2130
|
+
* // '/ip4/127.0.0.1/udp/1234'
|
2131
|
+
*
|
2132
|
+
* addr.protos()
|
2133
|
+
* // [
|
2134
|
+
* // {code: 4, name: 'ip4', size: 32},
|
2135
|
+
* // {code: 273, name: 'udp', size: 16}
|
2136
|
+
* // ]
|
2137
|
+
*
|
2138
|
+
* // gives you an object that is friendly with what Node.js core modules expect for addresses
|
2139
|
+
* addr.nodeAddress()
|
2140
|
+
* // {
|
2141
|
+
* // family: 4,
|
2142
|
+
* // port: 1234,
|
2143
|
+
* // address: "127.0.0.1"
|
2144
|
+
* // }
|
2145
|
+
*
|
2146
|
+
* addr.encapsulate('/sctp/5678')
|
2147
|
+
* // Multiaddr(/ip4/127.0.0.1/udp/1234/sctp/5678)
|
2148
|
+
* ```
|
2149
|
+
*
|
2150
|
+
* ## Resolvers
|
2151
|
+
*
|
2152
|
+
* `multiaddr` allows multiaddrs to be resolved when appropriate resolvers are provided. This module already has resolvers available, but you can also create your own. Resolvers should always be set in the same module that is calling `multiaddr.resolve()` to avoid conflicts if multiple versions of `multiaddr` are in your dependency tree.
|
2153
|
+
*
|
2154
|
+
* To provide multiaddr resolvers you can do:
|
2155
|
+
*
|
2156
|
+
* ```js
|
2157
|
+
* import { resolvers } from '@multiformats/multiaddr'
|
2158
|
+
*
|
2159
|
+
* resolvers.set('dnsaddr', resolvers.dnsaddrResolver)
|
2160
|
+
* ```
|
2161
|
+
*
|
2162
|
+
* The available resolvers are:
|
2163
|
+
*
|
2164
|
+
* | Name | type | Description |
|
2165
|
+
* | ----------------- | --------- | ----------------------------------- |
|
2166
|
+
* | `dnsaddrResolver` | `dnsaddr` | dnsaddr resolution with TXT Records |
|
2167
|
+
*
|
2168
|
+
* A resolver receives a `Multiaddr` as a parameter and returns a `Promise<Array<string>>`.
|
2169
|
+
*/
|
2170
|
+
/**
|
2171
|
+
* All configured {@link Resolver}s
|
2172
|
+
*/
|
2173
|
+
const resolvers = new Map();
|
2174
|
+
/**
|
2175
|
+
* Check if object is a {@link Multiaddr} instance
|
2176
|
+
*
|
2177
|
+
* @example
|
2178
|
+
*
|
2179
|
+
* ```js
|
2180
|
+
* import { isMultiaddr, multiaddr } from '@multiformats/multiaddr'
|
2181
|
+
*
|
2182
|
+
* isMultiaddr(5)
|
2183
|
+
* // false
|
2184
|
+
* isMultiaddr(multiaddr('/ip4/127.0.0.1'))
|
2185
|
+
* // true
|
2186
|
+
* ```
|
2187
|
+
*/
|
2188
|
+
function isMultiaddr(value) {
|
2189
|
+
return Boolean(value?.[symbol$1]);
|
2190
|
+
}
|
2086
2191
|
/**
|
2087
2192
|
* A function that takes a {@link MultiaddrInput} and returns a {@link Multiaddr}
|
2088
2193
|
*
|
@@ -2097,7 +2202,7 @@ class DefaultMultiaddr {
|
|
2097
2202
|
* @param {MultiaddrInput} [addr] - If String or Uint8Array, needs to adhere to the address format of a [multiaddr](https://github.com/multiformats/multiaddr#string-format)
|
2098
2203
|
*/
|
2099
2204
|
function multiaddr(addr) {
|
2100
|
-
return new
|
2205
|
+
return new Multiaddr(addr);
|
2101
2206
|
}
|
2102
2207
|
|
2103
2208
|
function isDefined(value) {
|
@@ -2185,308 +2290,6 @@ async function isMessageSizeUnderCap(encoder, message) {
|
|
2185
2290
|
}
|
2186
2291
|
const isWireSizeUnderCap = (buf) => buf.length / MB <= SIZE_CAP_IN_MB;
|
2187
2292
|
|
2188
|
-
function bytes(b, ...lengths) {
|
2189
|
-
if (!(b instanceof Uint8Array))
|
2190
|
-
throw new Error('Expected Uint8Array');
|
2191
|
-
if (lengths.length > 0 && !lengths.includes(b.length))
|
2192
|
-
throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
|
2193
|
-
}
|
2194
|
-
function exists(instance, checkFinished = true) {
|
2195
|
-
if (instance.destroyed)
|
2196
|
-
throw new Error('Hash instance has been destroyed');
|
2197
|
-
if (checkFinished && instance.finished)
|
2198
|
-
throw new Error('Hash#digest() has already been called');
|
2199
|
-
}
|
2200
|
-
function output(out, instance) {
|
2201
|
-
bytes(out);
|
2202
|
-
const min = instance.outputLen;
|
2203
|
-
if (out.length < min) {
|
2204
|
-
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
2205
|
-
}
|
2206
|
-
}
|
2207
|
-
|
2208
|
-
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
2209
|
-
// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
|
2210
|
-
// node.js versions earlier than v19 don't declare it in global scope.
|
2211
|
-
// For node.js, package.json#exports field mapping rewrites import
|
2212
|
-
// from `crypto` to `cryptoNode`, which imports native module.
|
2213
|
-
// Makes the utils un-importable in browsers without a bundler.
|
2214
|
-
// Once node.js 18 is deprecated, we can just drop the import.
|
2215
|
-
const u8a = (a) => a instanceof Uint8Array;
|
2216
|
-
// Cast array to view
|
2217
|
-
const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
2218
|
-
// The rotate right (circular right shift) operation for uint32
|
2219
|
-
const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
|
2220
|
-
// big-endian hardware is rare. Just in case someone still decides to run hashes:
|
2221
|
-
// early-throw an error because we don't support BE yet.
|
2222
|
-
const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
|
2223
|
-
if (!isLE)
|
2224
|
-
throw new Error('Non little-endian hardware is not supported');
|
2225
|
-
/**
|
2226
|
-
* @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
|
2227
|
-
*/
|
2228
|
-
function utf8ToBytes(str) {
|
2229
|
-
if (typeof str !== 'string')
|
2230
|
-
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
2231
|
-
return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
|
2232
|
-
}
|
2233
|
-
/**
|
2234
|
-
* Normalizes (non-hex) string or Uint8Array to Uint8Array.
|
2235
|
-
* Warning: when Uint8Array is passed, it would NOT get copied.
|
2236
|
-
* Keep in mind for future mutable operations.
|
2237
|
-
*/
|
2238
|
-
function toBytes(data) {
|
2239
|
-
if (typeof data === 'string')
|
2240
|
-
data = utf8ToBytes(data);
|
2241
|
-
if (!u8a(data))
|
2242
|
-
throw new Error(`expected Uint8Array, got ${typeof data}`);
|
2243
|
-
return data;
|
2244
|
-
}
|
2245
|
-
// For runtime check if class implements interface
|
2246
|
-
class Hash {
|
2247
|
-
// Safe version that clones internal state
|
2248
|
-
clone() {
|
2249
|
-
return this._cloneInto();
|
2250
|
-
}
|
2251
|
-
}
|
2252
|
-
function wrapConstructor(hashCons) {
|
2253
|
-
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
2254
|
-
const tmp = hashCons();
|
2255
|
-
hashC.outputLen = tmp.outputLen;
|
2256
|
-
hashC.blockLen = tmp.blockLen;
|
2257
|
-
hashC.create = () => hashCons();
|
2258
|
-
return hashC;
|
2259
|
-
}
|
2260
|
-
|
2261
|
-
// Polyfill for Safari 14
|
2262
|
-
function setBigUint64(view, byteOffset, value, isLE) {
|
2263
|
-
if (typeof view.setBigUint64 === 'function')
|
2264
|
-
return view.setBigUint64(byteOffset, value, isLE);
|
2265
|
-
const _32n = BigInt(32);
|
2266
|
-
const _u32_max = BigInt(0xffffffff);
|
2267
|
-
const wh = Number((value >> _32n) & _u32_max);
|
2268
|
-
const wl = Number(value & _u32_max);
|
2269
|
-
const h = isLE ? 4 : 0;
|
2270
|
-
const l = isLE ? 0 : 4;
|
2271
|
-
view.setUint32(byteOffset + h, wh, isLE);
|
2272
|
-
view.setUint32(byteOffset + l, wl, isLE);
|
2273
|
-
}
|
2274
|
-
// Base SHA2 class (RFC 6234)
|
2275
|
-
class SHA2 extends Hash {
|
2276
|
-
constructor(blockLen, outputLen, padOffset, isLE) {
|
2277
|
-
super();
|
2278
|
-
this.blockLen = blockLen;
|
2279
|
-
this.outputLen = outputLen;
|
2280
|
-
this.padOffset = padOffset;
|
2281
|
-
this.isLE = isLE;
|
2282
|
-
this.finished = false;
|
2283
|
-
this.length = 0;
|
2284
|
-
this.pos = 0;
|
2285
|
-
this.destroyed = false;
|
2286
|
-
this.buffer = new Uint8Array(blockLen);
|
2287
|
-
this.view = createView(this.buffer);
|
2288
|
-
}
|
2289
|
-
update(data) {
|
2290
|
-
exists(this);
|
2291
|
-
const { view, buffer, blockLen } = this;
|
2292
|
-
data = toBytes(data);
|
2293
|
-
const len = data.length;
|
2294
|
-
for (let pos = 0; pos < len;) {
|
2295
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
2296
|
-
// Fast path: we have at least one block in input, cast it to view and process
|
2297
|
-
if (take === blockLen) {
|
2298
|
-
const dataView = createView(data);
|
2299
|
-
for (; blockLen <= len - pos; pos += blockLen)
|
2300
|
-
this.process(dataView, pos);
|
2301
|
-
continue;
|
2302
|
-
}
|
2303
|
-
buffer.set(data.subarray(pos, pos + take), this.pos);
|
2304
|
-
this.pos += take;
|
2305
|
-
pos += take;
|
2306
|
-
if (this.pos === blockLen) {
|
2307
|
-
this.process(view, 0);
|
2308
|
-
this.pos = 0;
|
2309
|
-
}
|
2310
|
-
}
|
2311
|
-
this.length += data.length;
|
2312
|
-
this.roundClean();
|
2313
|
-
return this;
|
2314
|
-
}
|
2315
|
-
digestInto(out) {
|
2316
|
-
exists(this);
|
2317
|
-
output(out, this);
|
2318
|
-
this.finished = true;
|
2319
|
-
// Padding
|
2320
|
-
// We can avoid allocation of buffer for padding completely if it
|
2321
|
-
// was previously not allocated here. But it won't change performance.
|
2322
|
-
const { buffer, view, blockLen, isLE } = this;
|
2323
|
-
let { pos } = this;
|
2324
|
-
// append the bit '1' to the message
|
2325
|
-
buffer[pos++] = 0b10000000;
|
2326
|
-
this.buffer.subarray(pos).fill(0);
|
2327
|
-
// we have less than padOffset left in buffer, so we cannot put length in current block, need process it and pad again
|
2328
|
-
if (this.padOffset > blockLen - pos) {
|
2329
|
-
this.process(view, 0);
|
2330
|
-
pos = 0;
|
2331
|
-
}
|
2332
|
-
// Pad until full block byte with zeros
|
2333
|
-
for (let i = pos; i < blockLen; i++)
|
2334
|
-
buffer[i] = 0;
|
2335
|
-
// Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
|
2336
|
-
// You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
|
2337
|
-
// So we just write lowest 64 bits of that value.
|
2338
|
-
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
2339
|
-
this.process(view, 0);
|
2340
|
-
const oview = createView(out);
|
2341
|
-
const len = this.outputLen;
|
2342
|
-
// NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
|
2343
|
-
if (len % 4)
|
2344
|
-
throw new Error('_sha2: outputLen should be aligned to 32bit');
|
2345
|
-
const outLen = len / 4;
|
2346
|
-
const state = this.get();
|
2347
|
-
if (outLen > state.length)
|
2348
|
-
throw new Error('_sha2: outputLen bigger than state');
|
2349
|
-
for (let i = 0; i < outLen; i++)
|
2350
|
-
oview.setUint32(4 * i, state[i], isLE);
|
2351
|
-
}
|
2352
|
-
digest() {
|
2353
|
-
const { buffer, outputLen } = this;
|
2354
|
-
this.digestInto(buffer);
|
2355
|
-
const res = buffer.slice(0, outputLen);
|
2356
|
-
this.destroy();
|
2357
|
-
return res;
|
2358
|
-
}
|
2359
|
-
_cloneInto(to) {
|
2360
|
-
to || (to = new this.constructor());
|
2361
|
-
to.set(...this.get());
|
2362
|
-
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
2363
|
-
to.length = length;
|
2364
|
-
to.pos = pos;
|
2365
|
-
to.finished = finished;
|
2366
|
-
to.destroyed = destroyed;
|
2367
|
-
if (length % blockLen)
|
2368
|
-
to.buffer.set(buffer);
|
2369
|
-
return to;
|
2370
|
-
}
|
2371
|
-
}
|
2372
|
-
|
2373
|
-
// SHA2-256 need to try 2^128 hashes to execute birthday attack.
|
2374
|
-
// BTC network is doing 2^67 hashes/sec as per early 2023.
|
2375
|
-
// Choice: a ? b : c
|
2376
|
-
const Chi = (a, b, c) => (a & b) ^ (~a & c);
|
2377
|
-
// Majority function, true if any two inpust is true
|
2378
|
-
const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
|
2379
|
-
// Round constants:
|
2380
|
-
// first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
|
2381
|
-
// prettier-ignore
|
2382
|
-
const SHA256_K = /* @__PURE__ */ new Uint32Array([
|
2383
|
-
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
2384
|
-
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
2385
|
-
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
2386
|
-
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
2387
|
-
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
2388
|
-
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
2389
|
-
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
2390
|
-
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
2391
|
-
]);
|
2392
|
-
// Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
|
2393
|
-
// prettier-ignore
|
2394
|
-
const IV = /* @__PURE__ */ new Uint32Array([
|
2395
|
-
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
2396
|
-
]);
|
2397
|
-
// Temporary buffer, not used to store anything between runs
|
2398
|
-
// Named this way because it matches specification.
|
2399
|
-
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
2400
|
-
class SHA256 extends SHA2 {
|
2401
|
-
constructor() {
|
2402
|
-
super(64, 32, 8, false);
|
2403
|
-
// We cannot use array here since array allows indexing by variable
|
2404
|
-
// which means optimizer/compiler cannot use registers.
|
2405
|
-
this.A = IV[0] | 0;
|
2406
|
-
this.B = IV[1] | 0;
|
2407
|
-
this.C = IV[2] | 0;
|
2408
|
-
this.D = IV[3] | 0;
|
2409
|
-
this.E = IV[4] | 0;
|
2410
|
-
this.F = IV[5] | 0;
|
2411
|
-
this.G = IV[6] | 0;
|
2412
|
-
this.H = IV[7] | 0;
|
2413
|
-
}
|
2414
|
-
get() {
|
2415
|
-
const { A, B, C, D, E, F, G, H } = this;
|
2416
|
-
return [A, B, C, D, E, F, G, H];
|
2417
|
-
}
|
2418
|
-
// prettier-ignore
|
2419
|
-
set(A, B, C, D, E, F, G, H) {
|
2420
|
-
this.A = A | 0;
|
2421
|
-
this.B = B | 0;
|
2422
|
-
this.C = C | 0;
|
2423
|
-
this.D = D | 0;
|
2424
|
-
this.E = E | 0;
|
2425
|
-
this.F = F | 0;
|
2426
|
-
this.G = G | 0;
|
2427
|
-
this.H = H | 0;
|
2428
|
-
}
|
2429
|
-
process(view, offset) {
|
2430
|
-
// Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
|
2431
|
-
for (let i = 0; i < 16; i++, offset += 4)
|
2432
|
-
SHA256_W[i] = view.getUint32(offset, false);
|
2433
|
-
for (let i = 16; i < 64; i++) {
|
2434
|
-
const W15 = SHA256_W[i - 15];
|
2435
|
-
const W2 = SHA256_W[i - 2];
|
2436
|
-
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);
|
2437
|
-
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);
|
2438
|
-
SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
|
2439
|
-
}
|
2440
|
-
// Compression function main loop, 64 rounds
|
2441
|
-
let { A, B, C, D, E, F, G, H } = this;
|
2442
|
-
for (let i = 0; i < 64; i++) {
|
2443
|
-
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
2444
|
-
const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
|
2445
|
-
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
2446
|
-
const T2 = (sigma0 + Maj(A, B, C)) | 0;
|
2447
|
-
H = G;
|
2448
|
-
G = F;
|
2449
|
-
F = E;
|
2450
|
-
E = (D + T1) | 0;
|
2451
|
-
D = C;
|
2452
|
-
C = B;
|
2453
|
-
B = A;
|
2454
|
-
A = (T1 + T2) | 0;
|
2455
|
-
}
|
2456
|
-
// Add the compressed chunk to the current hash value
|
2457
|
-
A = (A + this.A) | 0;
|
2458
|
-
B = (B + this.B) | 0;
|
2459
|
-
C = (C + this.C) | 0;
|
2460
|
-
D = (D + this.D) | 0;
|
2461
|
-
E = (E + this.E) | 0;
|
2462
|
-
F = (F + this.F) | 0;
|
2463
|
-
G = (G + this.G) | 0;
|
2464
|
-
H = (H + this.H) | 0;
|
2465
|
-
this.set(A, B, C, D, E, F, G, H);
|
2466
|
-
}
|
2467
|
-
roundClean() {
|
2468
|
-
SHA256_W.fill(0);
|
2469
|
-
}
|
2470
|
-
destroy() {
|
2471
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
2472
|
-
this.buffer.fill(0);
|
2473
|
-
}
|
2474
|
-
}
|
2475
|
-
/**
|
2476
|
-
* SHA2-256 hash function
|
2477
|
-
* @param message - data that would be hashed
|
2478
|
-
*/
|
2479
|
-
const sha256$1 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
|
2480
|
-
|
2481
|
-
const shardInfoToPubsubTopics = (shardInfo) => {
|
2482
|
-
return shardInfo.indexList.map((index) => `/waku/2/rs/${shardInfo.cluster}/${index}`);
|
2483
|
-
};
|
2484
|
-
function ensurePubsubTopicIsConfigured(pubsubTopic, configuredTopics) {
|
2485
|
-
if (!configuredTopics.includes(pubsubTopic)) {
|
2486
|
-
throw new Error(`Pubsub topic ${pubsubTopic} has not been configured on this instance. Configured topics are: ${configuredTopics}. Please update your configuration by passing in the topic during Waku node instantiation.`);
|
2487
|
-
}
|
2488
|
-
}
|
2489
|
-
|
2490
2293
|
/**
|
2491
2294
|
* Adds types to the EventTarget class. Hopefully this won't be necessary forever.
|
2492
2295
|
*
|
@@ -18272,6 +18075,45 @@ function createPbkdf2Params(salt, countBytes, dkLen, prfAlgorithm) {
|
|
18272
18075
|
return params;
|
18273
18076
|
}
|
18274
18077
|
|
18078
|
+
/**
|
18079
|
+
* On the producing side:
|
18080
|
+
* * Build messages with the signature, key (from may be enough for certain inlineable public key types), from and seqno fields.
|
18081
|
+
*
|
18082
|
+
* On the consuming side:
|
18083
|
+
* * Enforce the fields to be present, reject otherwise.
|
18084
|
+
* * Propagate only if the fields are valid and signature can be verified, reject otherwise.
|
18085
|
+
*/
|
18086
|
+
var TopicValidatorResult;
|
18087
|
+
(function (TopicValidatorResult) {
|
18088
|
+
/**
|
18089
|
+
* The message is considered valid, and it should be delivered and forwarded to the network
|
18090
|
+
*/
|
18091
|
+
TopicValidatorResult["Accept"] = "accept";
|
18092
|
+
/**
|
18093
|
+
* The message is neither delivered nor forwarded to the network
|
18094
|
+
*/
|
18095
|
+
TopicValidatorResult["Ignore"] = "ignore";
|
18096
|
+
/**
|
18097
|
+
* The message is considered invalid, and it should be rejected
|
18098
|
+
*/
|
18099
|
+
TopicValidatorResult["Reject"] = "reject";
|
18100
|
+
})(TopicValidatorResult || (TopicValidatorResult = {}));
|
18101
|
+
|
18102
|
+
/**
|
18103
|
+
* Enum Transport Manager Fault Tolerance values
|
18104
|
+
*/
|
18105
|
+
var FaultTolerance;
|
18106
|
+
(function (FaultTolerance) {
|
18107
|
+
/**
|
18108
|
+
* should be used for failing in any listen circumstance
|
18109
|
+
*/
|
18110
|
+
FaultTolerance[FaultTolerance["FATAL_ALL"] = 0] = "FATAL_ALL";
|
18111
|
+
/**
|
18112
|
+
* should be used for not failing when not listening
|
18113
|
+
*/
|
18114
|
+
FaultTolerance[FaultTolerance["NO_FATAL"] = 1] = "NO_FATAL";
|
18115
|
+
})(FaultTolerance || (FaultTolerance = {}));
|
18116
|
+
|
18275
18117
|
/* eslint-disable import/export */
|
18276
18118
|
/* eslint-disable complexity */
|
18277
18119
|
/* eslint-disable @typescript-eslint/no-namespace */
|
@@ -18992,15 +18834,15 @@ const decodeRelayShard = (bytes) => {
|
|
18992
18834
|
if (bytes.length < 3)
|
18993
18835
|
throw new Error("Insufficient data");
|
18994
18836
|
const view = new DataView(bytes.buffer);
|
18995
|
-
const
|
18996
|
-
const
|
18837
|
+
const clusterId = view.getUint16(0);
|
18838
|
+
const shards = [];
|
18997
18839
|
if (bytes.length === 130) {
|
18998
18840
|
// rsv format (Bit Vector)
|
18999
18841
|
for (let i = 0; i < 1024; i++) {
|
19000
18842
|
const byteIndex = Math.floor(i / 8) + 2; // Adjusted for the 2-byte cluster field
|
19001
18843
|
const bitIndex = 7 - (i % 8);
|
19002
18844
|
if (view.getUint8(byteIndex) & (1 << bitIndex)) {
|
19003
|
-
|
18845
|
+
shards.push(i);
|
19004
18846
|
}
|
19005
18847
|
}
|
19006
18848
|
}
|
@@ -19010,10 +18852,33 @@ const decodeRelayShard = (bytes) => {
|
|
19010
18852
|
for (let i = 0, offset = 3; i < numIndices; i++, offset += 2) {
|
19011
18853
|
if (offset + 1 >= bytes.length)
|
19012
18854
|
throw new Error("Unexpected end of data");
|
19013
|
-
|
18855
|
+
shards.push(view.getUint16(offset));
|
18856
|
+
}
|
18857
|
+
}
|
18858
|
+
return { clusterId, shards };
|
18859
|
+
};
|
18860
|
+
const encodeRelayShard = (shardInfo) => {
|
18861
|
+
const { clusterId, shards } = shardInfo;
|
18862
|
+
const totalLength = shards.length >= 64 ? 130 : 3 + 2 * shards.length;
|
18863
|
+
const buffer = new ArrayBuffer(totalLength);
|
18864
|
+
const view = new DataView(buffer);
|
18865
|
+
view.setUint16(0, clusterId);
|
18866
|
+
if (shards.length >= 64) {
|
18867
|
+
// rsv format (Bit Vector)
|
18868
|
+
for (const index of shards) {
|
18869
|
+
const byteIndex = Math.floor(index / 8) + 2; // Adjusted for the 2-byte cluster field
|
18870
|
+
const bitIndex = 7 - (index % 8);
|
18871
|
+
view.setUint8(byteIndex, view.getUint8(byteIndex) | (1 << bitIndex));
|
18872
|
+
}
|
18873
|
+
}
|
18874
|
+
else {
|
18875
|
+
// rs format (Index List)
|
18876
|
+
view.setUint8(2, shards.length);
|
18877
|
+
for (let i = 0, offset = 3; i < shards.length; i++, offset += 2) {
|
18878
|
+
view.setUint16(offset, shards[i]);
|
19014
18879
|
}
|
19015
18880
|
}
|
19016
|
-
return
|
18881
|
+
return new Uint8Array(buffer);
|
19017
18882
|
};
|
19018
18883
|
|
19019
18884
|
new Logger("enr");
|
@@ -19033,7 +18898,7 @@ var TransportProtocolPerIpVersion;
|
|
19033
18898
|
new Logger("enr:decoder");
|
19034
18899
|
|
19035
18900
|
const RelayPingContentTopic = "/relay-ping/1/ping/null";
|
19036
|
-
const log$
|
18901
|
+
const log$7 = new Logger("keep-alive");
|
19037
18902
|
class KeepAliveManager {
|
19038
18903
|
pingKeepAliveTimers;
|
19039
18904
|
relayKeepAliveTimers;
|
@@ -19061,10 +18926,10 @@ class KeepAliveManager {
|
|
19061
18926
|
// also update the peer store with the latency
|
19062
18927
|
try {
|
19063
18928
|
ping = await libp2pPing.ping(peerId);
|
19064
|
-
log$
|
18929
|
+
log$7.info(`Ping succeeded (${peerIdStr})`, ping);
|
19065
18930
|
}
|
19066
18931
|
catch (error) {
|
19067
|
-
log$
|
18932
|
+
log$7.error(`Ping failed for peer (${peerIdStr}).
|
19068
18933
|
Next ping will be attempted in ${pingPeriodSecs} seconds.
|
19069
18934
|
`);
|
19070
18935
|
return;
|
@@ -19072,16 +18937,16 @@ class KeepAliveManager {
|
|
19072
18937
|
try {
|
19073
18938
|
await peerStore.patch(peerId, {
|
19074
18939
|
metadata: {
|
19075
|
-
ping: utf8ToBytes
|
18940
|
+
ping: utf8ToBytes(ping.toString())
|
19076
18941
|
}
|
19077
18942
|
});
|
19078
18943
|
}
|
19079
18944
|
catch (e) {
|
19080
|
-
log$
|
18945
|
+
log$7.error("Failed to update ping", e);
|
19081
18946
|
}
|
19082
18947
|
}
|
19083
18948
|
catch (e) {
|
19084
|
-
log$
|
18949
|
+
log$7.error(`Ping failed (${peerIdStr})`, e);
|
19085
18950
|
}
|
19086
18951
|
})();
|
19087
18952
|
}, pingPeriodSecs * 1000);
|
@@ -19125,15 +18990,15 @@ class KeepAliveManager {
|
|
19125
18990
|
if (!meshPeers.includes(peerIdStr))
|
19126
18991
|
continue;
|
19127
18992
|
const encoder = createEncoder({
|
19128
|
-
|
18993
|
+
pubsubTopicShardInfo: pubsubTopicToSingleShardInfo(topic),
|
19129
18994
|
contentTopic: RelayPingContentTopic,
|
19130
18995
|
ephemeral: true
|
19131
18996
|
});
|
19132
18997
|
const interval = setInterval(() => {
|
19133
|
-
log$
|
18998
|
+
log$7.info("Sending Waku Relay ping message");
|
19134
18999
|
relay
|
19135
19000
|
.send(encoder, { payload: new Uint8Array([1]) })
|
19136
|
-
.catch((e) => log$
|
19001
|
+
.catch((e) => log$7.error("Failed to send relay ping", e));
|
19137
19002
|
}, relayPeriodSecs * 1000);
|
19138
19003
|
intervals.push(interval);
|
19139
19004
|
}
|
@@ -19141,7 +19006,7 @@ class KeepAliveManager {
|
|
19141
19006
|
}
|
19142
19007
|
}
|
19143
19008
|
|
19144
|
-
const log$
|
19009
|
+
const log$6 = new Logger("connection-manager");
|
19145
19010
|
const DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED = 1;
|
19146
19011
|
const DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER = 3;
|
19147
19012
|
const DEFAULT_MAX_PARALLEL_DIALS = 3;
|
@@ -19235,12 +19100,12 @@ class ConnectionManager extends EventEmitter {
|
|
19235
19100
|
};
|
19236
19101
|
this.keepAliveManager = new KeepAliveManager(keepAliveOptions, relay);
|
19237
19102
|
this.run()
|
19238
|
-
.then(() => log$
|
19239
|
-
.catch((error) => log$
|
19103
|
+
.then(() => log$6.info(`Connection Manager is now running`))
|
19104
|
+
.catch((error) => log$6.error(`Unexpected error while running service`, error));
|
19240
19105
|
// libp2p emits `peer:discovery` events during its initialization
|
19241
19106
|
// which means that before the ConnectionManager is initialized, some peers may have been discovered
|
19242
19107
|
// we will dial the peers in peerStore ONCE before we start to listen to the `peer:discovery` events within the ConnectionManager
|
19243
|
-
this.dialPeerStorePeers().catch((error) => log$
|
19108
|
+
this.dialPeerStorePeers().catch((error) => log$6.error(`Unexpected error while dialing peer store peers`, error));
|
19244
19109
|
}
|
19245
19110
|
async dialPeerStorePeers() {
|
19246
19111
|
const peerInfos = await this.libp2p.peerStore.all();
|
@@ -19254,7 +19119,7 @@ class ConnectionManager extends EventEmitter {
|
|
19254
19119
|
await Promise.all(dialPromises);
|
19255
19120
|
}
|
19256
19121
|
catch (error) {
|
19257
|
-
log$
|
19122
|
+
log$6.error(`Unexpected error while dialing peer store peers`, error);
|
19258
19123
|
}
|
19259
19124
|
}
|
19260
19125
|
async run() {
|
@@ -19274,7 +19139,7 @@ class ConnectionManager extends EventEmitter {
|
|
19274
19139
|
let dialAttempt = 0;
|
19275
19140
|
while (dialAttempt < this.options.maxDialAttemptsForPeer) {
|
19276
19141
|
try {
|
19277
|
-
log$
|
19142
|
+
log$6.info(`Dialing peer ${peerId.toString()} on attempt ${dialAttempt + 1}`);
|
19278
19143
|
await this.libp2p.dial(peerId);
|
19279
19144
|
const tags = await this.getTagNamesForPeer(peerId);
|
19280
19145
|
// add tag to connection describing discovery mechanism
|
@@ -19291,11 +19156,11 @@ class ConnectionManager extends EventEmitter {
|
|
19291
19156
|
catch (error) {
|
19292
19157
|
if (error instanceof AggregateError) {
|
19293
19158
|
// Handle AggregateError
|
19294
|
-
log$
|
19159
|
+
log$6.error(`Error dialing peer ${peerId.toString()} - ${error.errors}`);
|
19295
19160
|
}
|
19296
19161
|
else {
|
19297
19162
|
// Handle generic error
|
19298
|
-
log$
|
19163
|
+
log$6.error(`Error dialing peer ${peerId.toString()} - ${error.message}`);
|
19299
19164
|
}
|
19300
19165
|
this.dialErrorsForPeer.set(peerId.toString(), error);
|
19301
19166
|
dialAttempt++;
|
@@ -19313,10 +19178,10 @@ class ConnectionManager extends EventEmitter {
|
|
19313
19178
|
let errorMessage;
|
19314
19179
|
if (error instanceof AggregateError) {
|
19315
19180
|
if (!error.errors) {
|
19316
|
-
log$
|
19181
|
+
log$6.warn(`No errors array found for AggregateError`);
|
19317
19182
|
}
|
19318
19183
|
else if (error.errors.length === 0) {
|
19319
|
-
log$
|
19184
|
+
log$6.warn(`Errors array is empty for AggregateError`);
|
19320
19185
|
}
|
19321
19186
|
else {
|
19322
19187
|
errorMessage = JSON.stringify(error.errors[0]);
|
@@ -19325,7 +19190,7 @@ class ConnectionManager extends EventEmitter {
|
|
19325
19190
|
else {
|
19326
19191
|
errorMessage = error.message;
|
19327
19192
|
}
|
19328
|
-
log$
|
19193
|
+
log$6.info(`Deleting undialable peer ${peerId.toString()} from peer store. Reason: ${errorMessage}`);
|
19329
19194
|
}
|
19330
19195
|
this.dialErrorsForPeer.delete(peerId.toString());
|
19331
19196
|
await this.libp2p.peerStore.delete(peerId);
|
@@ -19339,10 +19204,10 @@ class ConnectionManager extends EventEmitter {
|
|
19339
19204
|
try {
|
19340
19205
|
this.keepAliveManager.stop(peerId);
|
19341
19206
|
await this.libp2p.hangUp(peerId);
|
19342
|
-
log$
|
19207
|
+
log$6.info(`Dropped connection with peer ${peerId.toString()}`);
|
19343
19208
|
}
|
19344
19209
|
catch (error) {
|
19345
|
-
log$
|
19210
|
+
log$6.error(`Error dropping connection with peer ${peerId.toString()} - ${error}`);
|
19346
19211
|
}
|
19347
19212
|
}
|
19348
19213
|
processDialQueue() {
|
@@ -19352,7 +19217,7 @@ class ConnectionManager extends EventEmitter {
|
|
19352
19217
|
if (!peerId)
|
19353
19218
|
return;
|
19354
19219
|
this.attemptDial(peerId).catch((error) => {
|
19355
|
-
log$
|
19220
|
+
log$6.error(error);
|
19356
19221
|
});
|
19357
19222
|
}
|
19358
19223
|
}
|
@@ -19385,7 +19250,7 @@ class ConnectionManager extends EventEmitter {
|
|
19385
19250
|
return;
|
19386
19251
|
}
|
19387
19252
|
this.dialPeer(peerId).catch((err) => {
|
19388
|
-
log$
|
19253
|
+
log$6.error(`Error dialing peer ${peerId.toString()} : ${err}`);
|
19389
19254
|
});
|
19390
19255
|
}
|
19391
19256
|
onEventHandlers = {
|
@@ -19397,7 +19262,7 @@ class ConnectionManager extends EventEmitter {
|
|
19397
19262
|
await this.attemptDial(peerId);
|
19398
19263
|
}
|
19399
19264
|
catch (error) {
|
19400
|
-
log$
|
19265
|
+
log$6.error(`Error dialing peer ${peerId.toString()} : ${error}`);
|
19401
19266
|
}
|
19402
19267
|
})();
|
19403
19268
|
},
|
@@ -19447,24 +19312,24 @@ class ConnectionManager extends EventEmitter {
|
|
19447
19312
|
// if we're already connected to the peer, don't dial
|
19448
19313
|
const isConnected = this.libp2p.getConnections(peerId).length > 0;
|
19449
19314
|
if (isConnected) {
|
19450
|
-
log$
|
19315
|
+
log$6.warn(`Already connected to peer ${peerId.toString()}. Not dialing.`);
|
19451
19316
|
return false;
|
19452
19317
|
}
|
19453
19318
|
// if the peer is not part of any of the configured pubsub topics, don't dial
|
19454
19319
|
if (!(await this.isPeerTopicConfigured(peerId))) {
|
19455
19320
|
const shardInfo = await this.getPeerShardInfo(peerId, this.libp2p.peerStore);
|
19456
|
-
log$
|
19321
|
+
log$6.warn(`Discovered peer ${peerId.toString()} with ShardInfo ${shardInfo} is not part of any of the configured pubsub topics (${this.configuredPubsubTopics}).
|
19457
19322
|
Not dialing.`);
|
19458
19323
|
return false;
|
19459
19324
|
}
|
19460
19325
|
// if the peer is not dialable based on bootstrap status, don't dial
|
19461
19326
|
if (!(await this.isPeerDialableBasedOnBootstrapStatus(peerId))) {
|
19462
|
-
log$
|
19327
|
+
log$6.warn(`Peer ${peerId.toString()} is not dialable based on bootstrap status. Not dialing.`);
|
19463
19328
|
return false;
|
19464
19329
|
}
|
19465
19330
|
// If the peer is already already has an active dial attempt, or has been dialed before, don't dial it
|
19466
19331
|
if (this.dialAttemptsForPeer.has(peerId.toString())) {
|
19467
|
-
log$
|
19332
|
+
log$6.warn(`Peer ${peerId.toString()} has already been attempted dial before, or already has a dial attempt in progress, skipping dial`);
|
19468
19333
|
return false;
|
19469
19334
|
}
|
19470
19335
|
return true;
|
@@ -19508,7 +19373,7 @@ class ConnectionManager extends EventEmitter {
|
|
19508
19373
|
return Array.from(peer.tags.keys());
|
19509
19374
|
}
|
19510
19375
|
catch (error) {
|
19511
|
-
log$
|
19376
|
+
log$6.error(`Failed to get peer ${peerId}, error: ${error}`);
|
19512
19377
|
return [];
|
19513
19378
|
}
|
19514
19379
|
}
|
@@ -19533,17 +19398,23 @@ class ConnectionManager extends EventEmitter {
|
|
19533
19398
|
const DefaultPingKeepAliveValueSecs = 5 * 60;
|
19534
19399
|
const DefaultRelayKeepAliveValueSecs = 5 * 60;
|
19535
19400
|
const DefaultUserAgent = "js-waku";
|
19536
|
-
const log$
|
19401
|
+
const log$5 = new Logger("waku");
|
19537
19402
|
class WakuNode {
|
19538
|
-
pubsubTopics;
|
19539
19403
|
libp2p;
|
19540
19404
|
relay;
|
19541
19405
|
store;
|
19542
19406
|
filter;
|
19543
19407
|
lightPush;
|
19544
19408
|
connectionManager;
|
19545
|
-
|
19546
|
-
|
19409
|
+
pubsubTopics;
|
19410
|
+
constructor(options, pubsubTopics = [], libp2p, pubsubShardInfo, store, lightPush, filter, relay) {
|
19411
|
+
if (!pubsubShardInfo) {
|
19412
|
+
this.pubsubTopics =
|
19413
|
+
pubsubTopics.length > 0 ? pubsubTopics : [DefaultPubsubTopic];
|
19414
|
+
}
|
19415
|
+
else {
|
19416
|
+
this.pubsubTopics = shardInfoToPubsubTopics(pubsubShardInfo);
|
19417
|
+
}
|
19547
19418
|
this.libp2p = libp2p;
|
19548
19419
|
if (store) {
|
19549
19420
|
this.store = store(libp2p);
|
@@ -19562,8 +19433,8 @@ class WakuNode {
|
|
19562
19433
|
? options.relayKeepAlive || DefaultRelayKeepAliveValueSecs
|
19563
19434
|
: 0;
|
19564
19435
|
const peerId = this.libp2p.peerId.toString();
|
19565
|
-
this.connectionManager = ConnectionManager.create(peerId, libp2p, { pingKeepAlive, relayKeepAlive }, pubsubTopics, this.relay);
|
19566
|
-
log$
|
19436
|
+
this.connectionManager = ConnectionManager.create(peerId, libp2p, { pingKeepAlive, relayKeepAlive }, this.pubsubTopics, this.relay);
|
19437
|
+
log$5.info("Waku node created", peerId, `relay: ${!!this.relay}, store: ${!!this.store}, light push: ${!!this
|
19567
19438
|
.lightPush}, filter: ${!!this.filter}`);
|
19568
19439
|
}
|
19569
19440
|
/**
|
@@ -19587,7 +19458,7 @@ class WakuNode {
|
|
19587
19458
|
this.relay.gossipSub.multicodecs.forEach((codec) => codecs.push(codec));
|
19588
19459
|
}
|
19589
19460
|
else {
|
19590
|
-
log$
|
19461
|
+
log$5.error("Relay codec not included in dial codec: protocol not mounted locally");
|
19591
19462
|
}
|
19592
19463
|
}
|
19593
19464
|
if (_protocols.includes(Protocols.Store)) {
|
@@ -19595,7 +19466,7 @@ class WakuNode {
|
|
19595
19466
|
codecs.push(this.store.multicodec);
|
19596
19467
|
}
|
19597
19468
|
else {
|
19598
|
-
log$
|
19469
|
+
log$5.error("Store codec not included in dial codec: protocol not mounted locally");
|
19599
19470
|
}
|
19600
19471
|
}
|
19601
19472
|
if (_protocols.includes(Protocols.LightPush)) {
|
@@ -19603,7 +19474,7 @@ class WakuNode {
|
|
19603
19474
|
codecs.push(this.lightPush.multicodec);
|
19604
19475
|
}
|
19605
19476
|
else {
|
19606
|
-
log$
|
19477
|
+
log$5.error("Light Push codec not included in dial codec: protocol not mounted locally");
|
19607
19478
|
}
|
19608
19479
|
}
|
19609
19480
|
if (_protocols.includes(Protocols.Filter)) {
|
@@ -19611,10 +19482,10 @@ class WakuNode {
|
|
19611
19482
|
codecs.push(this.filter.multicodec);
|
19612
19483
|
}
|
19613
19484
|
else {
|
19614
|
-
log$
|
19485
|
+
log$5.error("Filter codec not included in dial codec: protocol not mounted locally");
|
19615
19486
|
}
|
19616
19487
|
}
|
19617
|
-
log$
|
19488
|
+
log$5.info(`Dialing to ${peerId.toString()} with protocols ${_protocols}`);
|
19618
19489
|
return this.libp2p.dialProtocol(peerId, codecs);
|
19619
19490
|
}
|
19620
19491
|
async start() {
|
@@ -21071,7 +20942,7 @@ class FilterSubscribeResponse {
|
|
21071
20942
|
}
|
21072
20943
|
}
|
21073
20944
|
|
21074
|
-
const log$
|
20945
|
+
const log$4 = new Logger("filter:v2");
|
21075
20946
|
const FilterCodecs = {
|
21076
20947
|
SUBSCRIBE: "/vac/waku/filter-subscribe/2.0.0-beta1",
|
21077
20948
|
PUSH: "/vac/waku/filter-push/2.0.0-beta1"
|
@@ -21108,7 +20979,7 @@ class Subscription {
|
|
21108
20979
|
if (statusCode < 200 || statusCode >= 300) {
|
21109
20980
|
throw new Error(`Filter subscribe request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
21110
20981
|
}
|
21111
|
-
log$
|
20982
|
+
log$4.info("Subscribed to peer ", this.peer.id.toString(), "for content topics", contentTopics);
|
21112
20983
|
}
|
21113
20984
|
catch (e) {
|
21114
20985
|
throw new Error("Error subscribing to peer: " +
|
@@ -21158,10 +21029,10 @@ class Subscription {
|
|
21158
21029
|
if (statusCode < 200 || statusCode >= 300) {
|
21159
21030
|
throw new Error(`Filter ping request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
21160
21031
|
}
|
21161
|
-
log$
|
21032
|
+
log$4.info("Ping successful");
|
21162
21033
|
}
|
21163
21034
|
catch (error) {
|
21164
|
-
log$
|
21035
|
+
log$4.error("Error pinging: ", error);
|
21165
21036
|
throw new Error("Error pinging: " + error);
|
21166
21037
|
}
|
21167
21038
|
}
|
@@ -21178,7 +21049,7 @@ class Subscription {
|
|
21178
21049
|
throw new Error(`Filter unsubscribe all request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
21179
21050
|
}
|
21180
21051
|
this.subscriptionCallbacks.clear();
|
21181
|
-
log$
|
21052
|
+
log$4.info("Unsubscribed from all content topics");
|
21182
21053
|
}
|
21183
21054
|
catch (error) {
|
21184
21055
|
throw new Error("Error unsubscribing from all content topics: " + error);
|
@@ -21188,7 +21059,7 @@ class Subscription {
|
|
21188
21059
|
const contentTopic = message.contentTopic;
|
21189
21060
|
const subscriptionCallback = this.subscriptionCallbacks.get(contentTopic);
|
21190
21061
|
if (!subscriptionCallback) {
|
21191
|
-
log$
|
21062
|
+
log$4.error("No subscription callback available for ", contentTopic);
|
21192
21063
|
return;
|
21193
21064
|
}
|
21194
21065
|
await pushMessage(subscriptionCallback, this.pubsubTopic, message);
|
@@ -21207,13 +21078,16 @@ class Filter extends BaseProtocol {
|
|
21207
21078
|
}
|
21208
21079
|
constructor(libp2p, options) {
|
21209
21080
|
super(FilterCodecs.SUBSCRIBE, libp2p.components);
|
21210
|
-
this.pubsubTopics = options
|
21081
|
+
this.pubsubTopics = this.initializePubsubTopic(options);
|
21211
21082
|
libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this)).catch((e) => {
|
21212
|
-
log$
|
21083
|
+
log$4.error("Failed to register ", FilterCodecs.PUSH, e);
|
21213
21084
|
});
|
21214
21085
|
this.activeSubscriptions = new Map();
|
21215
21086
|
}
|
21216
|
-
async createSubscription(
|
21087
|
+
async createSubscription(pubsubTopicShardInfo = DefaultPubsubTopic) {
|
21088
|
+
const pubsubTopic = typeof pubsubTopicShardInfo == "string"
|
21089
|
+
? pubsubTopicShardInfo
|
21090
|
+
: singleShardInfoToPubsubTopic(pubsubTopicShardInfo);
|
21217
21091
|
ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics);
|
21218
21092
|
//TODO: get a relevant peer for the topic/shard
|
21219
21093
|
// https://github.com/waku-org/js-waku/pull/1586#discussion_r1336428230
|
@@ -21258,29 +21132,29 @@ class Filter extends BaseProtocol {
|
|
21258
21132
|
const response = FilterPushRpc.decode(bytes.slice());
|
21259
21133
|
const { pubsubTopic, wakuMessage } = response;
|
21260
21134
|
if (!wakuMessage) {
|
21261
|
-
log$
|
21135
|
+
log$4.error("Received empty message");
|
21262
21136
|
return;
|
21263
21137
|
}
|
21264
21138
|
if (!pubsubTopic) {
|
21265
|
-
log$
|
21139
|
+
log$4.error("Pubsub topic missing from push message");
|
21266
21140
|
return;
|
21267
21141
|
}
|
21268
21142
|
const peerIdStr = streamData.connection.remotePeer.toString();
|
21269
21143
|
const subscription = this.getActiveSubscription(pubsubTopic, peerIdStr);
|
21270
21144
|
if (!subscription) {
|
21271
|
-
log$
|
21145
|
+
log$4.error(`No subscription locally registered for topic ${pubsubTopic}`);
|
21272
21146
|
return;
|
21273
21147
|
}
|
21274
21148
|
await subscription.processMessage(wakuMessage);
|
21275
21149
|
}
|
21276
21150
|
}).then(() => {
|
21277
|
-
log$
|
21151
|
+
log$4.info("Receiving pipe closed.");
|
21278
21152
|
}, (e) => {
|
21279
|
-
log$
|
21153
|
+
log$4.error("Error with receiving pipe", e);
|
21280
21154
|
});
|
21281
21155
|
}
|
21282
21156
|
catch (e) {
|
21283
|
-
log$
|
21157
|
+
log$4.error("Error decoding message", e);
|
21284
21158
|
}
|
21285
21159
|
}
|
21286
21160
|
}
|
@@ -21291,7 +21165,7 @@ async function pushMessage(subscriptionCallback, pubsubTopic, message) {
|
|
21291
21165
|
const { decoders, callback } = subscriptionCallback;
|
21292
21166
|
const { contentTopic } = message;
|
21293
21167
|
if (!contentTopic) {
|
21294
|
-
log$
|
21168
|
+
log$4.warn("Message has no content topic, skipping");
|
21295
21169
|
return;
|
21296
21170
|
}
|
21297
21171
|
try {
|
@@ -21302,7 +21176,7 @@ async function pushMessage(subscriptionCallback, pubsubTopic, message) {
|
|
21302
21176
|
await callback(decodedMessage);
|
21303
21177
|
}
|
21304
21178
|
catch (e) {
|
21305
|
-
log$
|
21179
|
+
log$4.error("Error decoding message", e);
|
21306
21180
|
}
|
21307
21181
|
}
|
21308
21182
|
|
@@ -21342,7 +21216,7 @@ class PushRpc {
|
|
21342
21216
|
}
|
21343
21217
|
}
|
21344
21218
|
|
21345
|
-
const log$
|
21219
|
+
const log$3 = new Logger("light-push");
|
21346
21220
|
const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
21347
21221
|
/**
|
21348
21222
|
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
@@ -21352,21 +21226,21 @@ class LightPush extends BaseProtocol {
|
|
21352
21226
|
NUM_PEERS_PROTOCOL = 1;
|
21353
21227
|
constructor(libp2p, options) {
|
21354
21228
|
super(LightPushCodec, libp2p.components);
|
21355
|
-
this.pubsubTopics = options
|
21229
|
+
this.pubsubTopics = this.initializePubsubTopic(options);
|
21356
21230
|
}
|
21357
21231
|
async preparePushMessage(encoder, message, pubsubTopic) {
|
21358
21232
|
try {
|
21359
21233
|
if (!message.payload || message.payload.length === 0) {
|
21360
|
-
log$
|
21234
|
+
log$3.error("Failed to send waku light push: payload is empty");
|
21361
21235
|
return { query: null, error: SendError.EMPTY_PAYLOAD };
|
21362
21236
|
}
|
21363
21237
|
if (!(await isMessageSizeUnderCap(encoder, message))) {
|
21364
|
-
log$
|
21238
|
+
log$3.error("Failed to send waku light push: message is bigger than 1MB");
|
21365
21239
|
return { query: null, error: SendError.SIZE_TOO_BIG };
|
21366
21240
|
}
|
21367
21241
|
const protoMessage = await encoder.toProtoObj(message);
|
21368
21242
|
if (!protoMessage) {
|
21369
|
-
log$
|
21243
|
+
log$3.error("Failed to encode to protoMessage, aborting push");
|
21370
21244
|
return {
|
21371
21245
|
query: null,
|
21372
21246
|
error: SendError.ENCODE_FAILED
|
@@ -21376,7 +21250,7 @@ class LightPush extends BaseProtocol {
|
|
21376
21250
|
return { query, error: null };
|
21377
21251
|
}
|
21378
21252
|
catch (error) {
|
21379
|
-
log$
|
21253
|
+
log$3.error("Failed to prepare push message", error);
|
21380
21254
|
return {
|
21381
21255
|
query: null,
|
21382
21256
|
error: SendError.GENERIC_FAIL
|
@@ -21411,7 +21285,7 @@ class LightPush extends BaseProtocol {
|
|
21411
21285
|
stream = await this.getStream(peer);
|
21412
21286
|
}
|
21413
21287
|
catch (err) {
|
21414
|
-
log$
|
21288
|
+
log$3.error(`Failed to get a stream for remote peer${peer.id.toString()}`, err);
|
21415
21289
|
return { recipients, error: SendError.REMOTE_PEER_FAULT };
|
21416
21290
|
}
|
21417
21291
|
let res;
|
@@ -21419,7 +21293,7 @@ class LightPush extends BaseProtocol {
|
|
21419
21293
|
res = await pipe([query.encode()], encode, stream, decode, async (source) => await all(source));
|
21420
21294
|
}
|
21421
21295
|
catch (err) {
|
21422
|
-
log$
|
21296
|
+
log$3.error("Failed to send waku light push request", err);
|
21423
21297
|
return { recipients, error: SendError.GENERIC_FAIL };
|
21424
21298
|
}
|
21425
21299
|
const bytes = new Uint8ArrayList();
|
@@ -21431,15 +21305,15 @@ class LightPush extends BaseProtocol {
|
|
21431
21305
|
response = PushRpc.decode(bytes).response;
|
21432
21306
|
}
|
21433
21307
|
catch (err) {
|
21434
|
-
log$
|
21308
|
+
log$3.error("Failed to decode push reply", err);
|
21435
21309
|
return { recipients, error: SendError.DECODE_FAILED };
|
21436
21310
|
}
|
21437
21311
|
if (!response) {
|
21438
|
-
log$
|
21312
|
+
log$3.error("Remote peer fault: No response in PushRPC");
|
21439
21313
|
return { recipients, error: SendError.REMOTE_PEER_FAULT };
|
21440
21314
|
}
|
21441
21315
|
if (!response.isSuccess) {
|
21442
|
-
log$
|
21316
|
+
log$3.error("Remote peer rejected the message: ", response.info);
|
21443
21317
|
return { recipients, error: SendError.REMOTE_PEER_REJECTED };
|
21444
21318
|
}
|
21445
21319
|
recipients.some((recipient) => recipient.equals(peer.id)) ||
|
@@ -21552,7 +21426,7 @@ function directionToProto(pageDirection) {
|
|
21552
21426
|
}
|
21553
21427
|
|
21554
21428
|
var HistoryError = HistoryResponse.HistoryError;
|
21555
|
-
const log$
|
21429
|
+
const log$2 = new Logger("store");
|
21556
21430
|
const StoreCodec = "/vac/waku/store/2.0.0-beta4";
|
21557
21431
|
const DefaultPageSize = 10;
|
21558
21432
|
/**
|
@@ -21565,7 +21439,7 @@ class Store extends BaseProtocol {
|
|
21565
21439
|
NUM_PEERS_PROTOCOL = 1;
|
21566
21440
|
constructor(libp2p, options) {
|
21567
21441
|
super(StoreCodec, libp2p.components);
|
21568
|
-
this.pubsubTopics = options
|
21442
|
+
this.pubsubTopics = this.initializePubsubTopic(options);
|
21569
21443
|
}
|
21570
21444
|
/**
|
21571
21445
|
* Processes messages based on the provided callback and options.
|
@@ -21733,7 +21607,7 @@ async function* paginate(streamFactory, queryOpts, decoders, cursor) {
|
|
21733
21607
|
while (true) {
|
21734
21608
|
queryOpts.cursor = currentCursor;
|
21735
21609
|
const historyRpcQuery = HistoryRpc.createQuery(queryOpts);
|
21736
|
-
log$
|
21610
|
+
log$2.info("Querying store peer", `for (${queryOpts.pubsubTopic})`, queryOpts.contentTopics);
|
21737
21611
|
const stream = await streamFactory();
|
21738
21612
|
const res = await pipe([historyRpcQuery.encode()], encode, stream, decode, async (source) => await all(source));
|
21739
21613
|
const bytes = new Uint8ArrayList();
|
@@ -21742,7 +21616,7 @@ async function* paginate(streamFactory, queryOpts, decoders, cursor) {
|
|
21742
21616
|
});
|
21743
21617
|
const reply = historyRpcQuery.decode(bytes);
|
21744
21618
|
if (!reply.response) {
|
21745
|
-
log$
|
21619
|
+
log$2.warn("Stopping pagination due to store `response` field missing");
|
21746
21620
|
break;
|
21747
21621
|
}
|
21748
21622
|
const response = reply.response;
|
@@ -21750,10 +21624,10 @@ async function* paginate(streamFactory, queryOpts, decoders, cursor) {
|
|
21750
21624
|
throw "History response contains an Error: " + response.error;
|
21751
21625
|
}
|
21752
21626
|
if (!response.messages || !response.messages.length) {
|
21753
|
-
log$
|
21627
|
+
log$2.warn("Stopping pagination due to store `response.messages` field missing or empty");
|
21754
21628
|
break;
|
21755
21629
|
}
|
21756
|
-
log$
|
21630
|
+
log$2.error(`${response.messages.length} messages retrieved from store`);
|
21757
21631
|
yield response.messages.map((protoMsg) => {
|
21758
21632
|
const contentTopic = protoMsg.contentTopic;
|
21759
21633
|
if (typeof contentTopic !== "undefined") {
|
@@ -21768,7 +21642,7 @@ async function* paginate(streamFactory, queryOpts, decoders, cursor) {
|
|
21768
21642
|
if (typeof nextCursor === "undefined") {
|
21769
21643
|
// If the server does not return cursor then there is an issue,
|
21770
21644
|
// Need to abort, or we end up in an infinite loop
|
21771
|
-
log$
|
21645
|
+
log$2.warn("Stopping pagination due to `response.pagingInfo.cursor` missing from store response");
|
21772
21646
|
break;
|
21773
21647
|
}
|
21774
21648
|
currentCursor = nextCursor;
|
@@ -21790,7 +21664,7 @@ async function createCursor(message) {
|
|
21790
21664
|
!message.contentTopic) {
|
21791
21665
|
throw new Error("Message is missing required fields");
|
21792
21666
|
}
|
21793
|
-
const contentTopicBytes = utf8ToBytes
|
21667
|
+
const contentTopicBytes = utf8ToBytes(message.contentTopic);
|
21794
21668
|
const digest = sha256$1(concat$1([contentTopicBytes, message.payload]));
|
21795
21669
|
const messageTime = BigInt(message.timestamp.getTime()) * BigInt(1000000);
|
21796
21670
|
return {
|
@@ -22045,7 +21919,7 @@ function pEvent(emitter, event, options) {
|
|
22045
21919
|
return promise;
|
22046
21920
|
}
|
22047
21921
|
|
22048
|
-
const log = new Logger("wait-for-remote-peer");
|
21922
|
+
const log$1 = new Logger("wait-for-remote-peer");
|
22049
21923
|
/**
|
22050
21924
|
* Wait for a remote peer to be ready given the passed protocols.
|
22051
21925
|
* Must be used after attempting to connect to nodes, using
|
@@ -22104,7 +21978,7 @@ async function waitForConnectedPeer(protocol) {
|
|
22104
21978
|
const codec = protocol.multicodec;
|
22105
21979
|
const peers = await protocol.peers();
|
22106
21980
|
if (peers.length) {
|
22107
|
-
log.info(`${codec} peer found: `, peers[0].id.toString());
|
21981
|
+
log$1.info(`${codec} peer found: `, peers[0].id.toString());
|
22108
21982
|
return;
|
22109
21983
|
}
|
22110
21984
|
await new Promise((resolve) => {
|
@@ -22152,4 +22026,63 @@ function getEnabledProtocols(waku) {
|
|
22152
22026
|
return protocols;
|
22153
22027
|
}
|
22154
22028
|
|
22155
|
-
|
22029
|
+
const log = new Logger("metadata");
|
22030
|
+
const MetadataCodec = "/vac/waku/metadata/1.0.0";
|
22031
|
+
class Metadata extends BaseProtocol {
|
22032
|
+
shardInfo;
|
22033
|
+
libp2pComponents;
|
22034
|
+
constructor(shardInfo, libp2p) {
|
22035
|
+
super(MetadataCodec, libp2p.components);
|
22036
|
+
this.libp2pComponents = libp2p;
|
22037
|
+
this.shardInfo = shardInfo;
|
22038
|
+
void libp2p.registrar.handle(MetadataCodec, (streamData) => {
|
22039
|
+
void this.onRequest(streamData);
|
22040
|
+
});
|
22041
|
+
}
|
22042
|
+
/**
|
22043
|
+
* Handle an incoming metadata request
|
22044
|
+
*/
|
22045
|
+
async onRequest(streamData) {
|
22046
|
+
try {
|
22047
|
+
const { stream, connection } = streamData;
|
22048
|
+
const encodedShardInfo = WakuMetadataResponse.encode(this.shardInfo);
|
22049
|
+
const encodedResponse = await pipe([encodedShardInfo], encode, stream, decode, async (source) => await all(source));
|
22050
|
+
const remoteShardInfoResponse = this.decodeMetadataResponse(encodedResponse);
|
22051
|
+
// add or update the shardInfo to peer store
|
22052
|
+
await this.libp2pComponents.peerStore.merge(connection.remotePeer, {
|
22053
|
+
metadata: {
|
22054
|
+
shardInfo: encodeRelayShard(remoteShardInfoResponse)
|
22055
|
+
}
|
22056
|
+
});
|
22057
|
+
}
|
22058
|
+
catch (error) {
|
22059
|
+
log.error("Error handling metadata request", error);
|
22060
|
+
}
|
22061
|
+
}
|
22062
|
+
/**
|
22063
|
+
* Make a metadata query to a peer
|
22064
|
+
*/
|
22065
|
+
async query(peerId) {
|
22066
|
+
const request = WakuMetadataRequest.encode(this.shardInfo);
|
22067
|
+
const peer = await this.getPeer(peerId);
|
22068
|
+
const stream = await this.getStream(peer);
|
22069
|
+
const encodedResponse = await pipe([request], encode, stream, decode, async (source) => await all(source));
|
22070
|
+
const decodedResponse = this.decodeMetadataResponse(encodedResponse);
|
22071
|
+
return decodedResponse;
|
22072
|
+
}
|
22073
|
+
decodeMetadataResponse(encodedResponse) {
|
22074
|
+
const bytes = new Uint8ArrayList();
|
22075
|
+
encodedResponse.forEach((chunk) => {
|
22076
|
+
bytes.append(chunk);
|
22077
|
+
});
|
22078
|
+
const response = WakuMetadataResponse.decode(bytes);
|
22079
|
+
if (!response)
|
22080
|
+
log.error("Error decoding metadata response");
|
22081
|
+
return response;
|
22082
|
+
}
|
22083
|
+
}
|
22084
|
+
function wakuMetadata(shardInfo) {
|
22085
|
+
return (components) => new Metadata(shardInfo, components);
|
22086
|
+
}
|
22087
|
+
|
22088
|
+
export { ConnectionManager, DefaultUserAgent, FilterCodecs, KeepAliveManager, LightPushCodec, MetadataCodec, PageDirection, WakuNode, createCursor, createEncoder, index$3 as message, waitForRemotePeer, waku, wakuFilter, wakuLightPush, wakuMetadata, wakuStore, index$2 as waku_filter, index$1 as waku_light_push, index as waku_store };
|