@waku/core 0.0.24 → 0.0.25
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 +25 -0
- package/bundle/{base_protocol-2a0c882e.js → base_protocol-4bcf7514.js} +19 -11
- package/bundle/index-27b91e3b.js +31 -0
- package/bundle/index.js +199 -167
- package/bundle/lib/base_protocol.js +2 -1
- package/bundle/lib/message/version_0.js +2 -1
- package/bundle/lib/predefined_bootstrap_nodes.js +2 -0
- package/bundle/{version_0-f4afd324.js → version_0-2f1176e3.js} +4 -4
- package/dist/.tsbuildinfo +1 -1
- package/dist/lib/connection_manager.d.ts +2 -1
- package/dist/lib/connection_manager.js +35 -27
- package/dist/lib/connection_manager.js.map +1 -1
- package/dist/lib/filter/index.js +28 -17
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/keep_alive_manager.js +8 -8
- package/dist/lib/keep_alive_manager.js.map +1 -1
- package/dist/lib/light_push/index.js +16 -12
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/message/version_0.js +3 -4
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/store/index.js +7 -8
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/stream_manager.js +4 -4
- package/dist/lib/stream_manager.js.map +1 -1
- package/dist/lib/wait_for_remote_peer.js +3 -4
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/dist/lib/waku.js +8 -8
- package/dist/lib/waku.js.map +1 -1
- package/package.json +6 -6
- package/src/lib/connection_manager.ts +46 -28
- package/src/lib/filter/index.ts +40 -17
- package/src/lib/keep_alive_manager.ts +8 -8
- package/src/lib/light_push/index.ts +23 -12
- package/src/lib/message/version_0.ts +3 -4
- package/src/lib/store/index.ts +7 -9
- package/src/lib/stream_manager.ts +7 -5
- package/src/lib/wait_for_remote_peer.ts +3 -4
- package/src/lib/waku.ts +8 -8
package/bundle/index.js
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
import { c as coerce$1, e as equals$2, b as base32, a as base58btc, d as allocUnsafe, f as asUint8Array, t as toString$1, g as bases, h as fromString, u as utf8ToBytes$1, T as Tags, E as EPeersByDiscoveryEvents, P as Protocols, i as alloc, B as BaseProtocol, S as SendError, j as concat$1 } from './base_protocol-
|
2
|
-
export { k as StreamManager } from './base_protocol-
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
|
1
|
+
import { c as coerce$1, e as equals$2, b as base32, a as base58btc, d as allocUnsafe, f as asUint8Array, t as toString$1, g as bases, h as fromString, u as utf8ToBytes$1, T as Tags, E as EPeersByDiscoveryEvents, P as Protocols, i as alloc, B as BaseProtocol, S as SendError, j as concat$1 } from './base_protocol-4bcf7514.js';
|
2
|
+
export { k as StreamManager } from './base_protocol-4bcf7514.js';
|
3
|
+
import { L as Logger } from './index-27b91e3b.js';
|
4
|
+
import { c as commonjsGlobal, g as getAugmentedNamespace, a as getDefaultExportFromCjs } from './browser-90197c87.js';
|
5
|
+
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, D as DefaultPubSubTopic, P as PushRpc$1, f as PushResponse, H as HistoryRpc$1, g as PagingInfo, h as HistoryResponse } from './version_0-2f1176e3.js';
|
6
|
+
export { i as createDecoder } from './version_0-2f1176e3.js';
|
6
7
|
|
7
8
|
const symbol$2 = Symbol.for('@libp2p/peer-id');
|
8
9
|
function isPeerId(other) {
|
@@ -2099,6 +2100,100 @@ function multiaddr(addr) {
|
|
2099
2100
|
return new DefaultMultiaddr(addr);
|
2100
2101
|
}
|
2101
2102
|
|
2103
|
+
function isDefined(value) {
|
2104
|
+
return Boolean(value);
|
2105
|
+
}
|
2106
|
+
|
2107
|
+
function groupByContentTopic(values) {
|
2108
|
+
const groupedDecoders = new Map();
|
2109
|
+
values.forEach((value) => {
|
2110
|
+
let decs = groupedDecoders.get(value.contentTopic);
|
2111
|
+
if (!decs) {
|
2112
|
+
groupedDecoders.set(value.contentTopic, []);
|
2113
|
+
decs = groupedDecoders.get(value.contentTopic);
|
2114
|
+
}
|
2115
|
+
decs.push(value);
|
2116
|
+
});
|
2117
|
+
return groupedDecoders;
|
2118
|
+
}
|
2119
|
+
|
2120
|
+
const FRAME_RATE = 60;
|
2121
|
+
/**
|
2122
|
+
* Function that transforms IReceiver subscription to iterable stream of data.
|
2123
|
+
* @param receiver - object that allows to be subscribed to;
|
2124
|
+
* @param decoder - parameter to be passed to receiver for subscription;
|
2125
|
+
* @param options - options for receiver for subscription;
|
2126
|
+
* @param iteratorOptions - optional configuration for iterator;
|
2127
|
+
* @returns iterator and stop function to terminate it.
|
2128
|
+
*/
|
2129
|
+
async function toAsyncIterator(receiver, decoder, iteratorOptions) {
|
2130
|
+
const iteratorDelay = iteratorOptions?.iteratorDelay ?? FRAME_RATE;
|
2131
|
+
const messages = [];
|
2132
|
+
let unsubscribe;
|
2133
|
+
unsubscribe = await receiver.subscribe(decoder, (message) => {
|
2134
|
+
messages.push(message);
|
2135
|
+
});
|
2136
|
+
const isWithTimeout = Number.isInteger(iteratorOptions?.timeoutMs);
|
2137
|
+
const timeoutMs = iteratorOptions?.timeoutMs ?? 0;
|
2138
|
+
const startTime = Date.now();
|
2139
|
+
async function* iterator() {
|
2140
|
+
while (true) {
|
2141
|
+
if (isWithTimeout && Date.now() - startTime >= timeoutMs) {
|
2142
|
+
return;
|
2143
|
+
}
|
2144
|
+
await wait(iteratorDelay);
|
2145
|
+
const message = messages.shift();
|
2146
|
+
if (!unsubscribe && messages.length === 0) {
|
2147
|
+
return message;
|
2148
|
+
}
|
2149
|
+
if (!message && unsubscribe) {
|
2150
|
+
continue;
|
2151
|
+
}
|
2152
|
+
yield message;
|
2153
|
+
}
|
2154
|
+
}
|
2155
|
+
return {
|
2156
|
+
iterator: iterator(),
|
2157
|
+
async stop() {
|
2158
|
+
if (unsubscribe) {
|
2159
|
+
await unsubscribe();
|
2160
|
+
unsubscribe = undefined;
|
2161
|
+
}
|
2162
|
+
}
|
2163
|
+
};
|
2164
|
+
}
|
2165
|
+
function wait(ms) {
|
2166
|
+
return new Promise((resolve) => {
|
2167
|
+
setTimeout(resolve, ms);
|
2168
|
+
});
|
2169
|
+
}
|
2170
|
+
|
2171
|
+
const MB = 1024 ** 2;
|
2172
|
+
const SIZE_CAP_IN_MB = 1;
|
2173
|
+
/**
|
2174
|
+
* Return whether the size of the message is under the upper limit for the network.
|
2175
|
+
* This performs a protobuf encoding! If you have access to the fully encoded message,
|
2176
|
+
* use {@link isSizeUnderCapBuf} instead.
|
2177
|
+
* @param message
|
2178
|
+
* @param encoder
|
2179
|
+
*/
|
2180
|
+
async function isMessageSizeUnderCap(encoder, message) {
|
2181
|
+
const buf = await encoder.toWire(message);
|
2182
|
+
if (!buf)
|
2183
|
+
return false;
|
2184
|
+
return isWireSizeUnderCap(buf);
|
2185
|
+
}
|
2186
|
+
const isWireSizeUnderCap = (buf) => buf.length / MB <= SIZE_CAP_IN_MB;
|
2187
|
+
|
2188
|
+
const shardInfoToPubSubTopics = (shardInfo) => {
|
2189
|
+
return shardInfo.indexList.map((index) => `/waku/2/rs/${shardInfo.cluster}/${index}`);
|
2190
|
+
};
|
2191
|
+
function ensurePubsubTopicIsConfigured(pubsubTopic, configuredTopics) {
|
2192
|
+
if (!configuredTopics.includes(pubsubTopic)) {
|
2193
|
+
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.`);
|
2194
|
+
}
|
2195
|
+
}
|
2196
|
+
|
2102
2197
|
/**
|
2103
2198
|
* Adds types to the EventTarget class. Hopefully this won't be necessary forever.
|
2104
2199
|
*
|
@@ -19848,7 +19943,7 @@ const decodeRelayShard = (bytes) => {
|
|
19848
19943
|
return { cluster, indexList };
|
19849
19944
|
};
|
19850
19945
|
|
19851
|
-
|
19946
|
+
new Logger("enr");
|
19852
19947
|
var TransportProtocol;
|
19853
19948
|
(function (TransportProtocol) {
|
19854
19949
|
TransportProtocol["TCP"] = "tcp";
|
@@ -19862,94 +19957,10 @@ var TransportProtocolPerIpVersion;
|
|
19862
19957
|
TransportProtocolPerIpVersion["UDP6"] = "udp6";
|
19863
19958
|
})(TransportProtocolPerIpVersion || (TransportProtocolPerIpVersion = {}));
|
19864
19959
|
|
19865
|
-
|
19866
|
-
return Boolean(value);
|
19867
|
-
}
|
19868
|
-
|
19869
|
-
function groupByContentTopic(values) {
|
19870
|
-
const groupedDecoders = new Map();
|
19871
|
-
values.forEach((value) => {
|
19872
|
-
let decs = groupedDecoders.get(value.contentTopic);
|
19873
|
-
if (!decs) {
|
19874
|
-
groupedDecoders.set(value.contentTopic, []);
|
19875
|
-
decs = groupedDecoders.get(value.contentTopic);
|
19876
|
-
}
|
19877
|
-
decs.push(value);
|
19878
|
-
});
|
19879
|
-
return groupedDecoders;
|
19880
|
-
}
|
19881
|
-
|
19882
|
-
const FRAME_RATE = 60;
|
19883
|
-
/**
|
19884
|
-
* Function that transforms IReceiver subscription to iterable stream of data.
|
19885
|
-
* @param receiver - object that allows to be subscribed to;
|
19886
|
-
* @param decoder - parameter to be passed to receiver for subscription;
|
19887
|
-
* @param options - options for receiver for subscription;
|
19888
|
-
* @param iteratorOptions - optional configuration for iterator;
|
19889
|
-
* @returns iterator and stop function to terminate it.
|
19890
|
-
*/
|
19891
|
-
async function toAsyncIterator(receiver, decoder, iteratorOptions) {
|
19892
|
-
const iteratorDelay = iteratorOptions?.iteratorDelay ?? FRAME_RATE;
|
19893
|
-
const messages = [];
|
19894
|
-
let unsubscribe;
|
19895
|
-
unsubscribe = await receiver.subscribe(decoder, (message) => {
|
19896
|
-
messages.push(message);
|
19897
|
-
});
|
19898
|
-
const isWithTimeout = Number.isInteger(iteratorOptions?.timeoutMs);
|
19899
|
-
const timeoutMs = iteratorOptions?.timeoutMs ?? 0;
|
19900
|
-
const startTime = Date.now();
|
19901
|
-
async function* iterator() {
|
19902
|
-
while (true) {
|
19903
|
-
if (isWithTimeout && Date.now() - startTime >= timeoutMs) {
|
19904
|
-
return;
|
19905
|
-
}
|
19906
|
-
await wait(iteratorDelay);
|
19907
|
-
const message = messages.shift();
|
19908
|
-
if (!unsubscribe && messages.length === 0) {
|
19909
|
-
return message;
|
19910
|
-
}
|
19911
|
-
if (!message && unsubscribe) {
|
19912
|
-
continue;
|
19913
|
-
}
|
19914
|
-
yield message;
|
19915
|
-
}
|
19916
|
-
}
|
19917
|
-
return {
|
19918
|
-
iterator: iterator(),
|
19919
|
-
async stop() {
|
19920
|
-
if (unsubscribe) {
|
19921
|
-
await unsubscribe();
|
19922
|
-
unsubscribe = undefined;
|
19923
|
-
}
|
19924
|
-
}
|
19925
|
-
};
|
19926
|
-
}
|
19927
|
-
function wait(ms) {
|
19928
|
-
return new Promise((resolve) => {
|
19929
|
-
setTimeout(resolve, ms);
|
19930
|
-
});
|
19931
|
-
}
|
19932
|
-
|
19933
|
-
const MB = 1024 ** 2;
|
19934
|
-
const SIZE_CAP = 1; // 1 MB
|
19935
|
-
const isSizeValid = (payload) => {
|
19936
|
-
if (payload.length / MB > SIZE_CAP) {
|
19937
|
-
return false;
|
19938
|
-
}
|
19939
|
-
return true;
|
19940
|
-
};
|
19941
|
-
|
19942
|
-
const shardInfoToPubSubTopics = (shardInfo) => {
|
19943
|
-
return shardInfo.indexList.map((index) => `/waku/2/rs/${shardInfo.cluster}/${index}`);
|
19944
|
-
};
|
19945
|
-
function ensurePubsubTopicIsConfigured(pubsubTopic, configuredTopics) {
|
19946
|
-
if (!configuredTopics.includes(pubsubTopic)) {
|
19947
|
-
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.`);
|
19948
|
-
}
|
19949
|
-
}
|
19960
|
+
new Logger("enr:decoder");
|
19950
19961
|
|
19951
19962
|
const RelayPingContentTopic = "/relay-ping/1/ping/null";
|
19952
|
-
const log$6 =
|
19963
|
+
const log$6 = new Logger("keep-alive");
|
19953
19964
|
class KeepAliveManager {
|
19954
19965
|
pingKeepAliveTimers;
|
19955
19966
|
relayKeepAliveTimers;
|
@@ -19977,10 +19988,10 @@ class KeepAliveManager {
|
|
19977
19988
|
// also update the peer store with the latency
|
19978
19989
|
try {
|
19979
19990
|
ping = await libp2pPing.ping(peerId);
|
19980
|
-
log$6(`Ping succeeded (${peerIdStr})`, ping);
|
19991
|
+
log$6.info(`Ping succeeded (${peerIdStr})`, ping);
|
19981
19992
|
}
|
19982
19993
|
catch (error) {
|
19983
|
-
log$6(`Ping failed for peer (${peerIdStr}).
|
19994
|
+
log$6.error(`Ping failed for peer (${peerIdStr}).
|
19984
19995
|
Next ping will be attempted in ${pingPeriodSecs} seconds.
|
19985
19996
|
`);
|
19986
19997
|
return;
|
@@ -19993,11 +20004,11 @@ class KeepAliveManager {
|
|
19993
20004
|
});
|
19994
20005
|
}
|
19995
20006
|
catch (e) {
|
19996
|
-
log$6("Failed to update ping", e);
|
20007
|
+
log$6.error("Failed to update ping", e);
|
19997
20008
|
}
|
19998
20009
|
}
|
19999
20010
|
catch (e) {
|
20000
|
-
log$6(`Ping failed (${peerIdStr})`, e);
|
20011
|
+
log$6.error(`Ping failed (${peerIdStr})`, e);
|
20001
20012
|
}
|
20002
20013
|
})();
|
20003
20014
|
}, pingPeriodSecs * 1000);
|
@@ -20043,10 +20054,10 @@ class KeepAliveManager {
|
|
20043
20054
|
ephemeral: true
|
20044
20055
|
});
|
20045
20056
|
const interval = setInterval(() => {
|
20046
|
-
log$6("Sending Waku Relay ping message");
|
20057
|
+
log$6.info("Sending Waku Relay ping message");
|
20047
20058
|
relay
|
20048
20059
|
.send(encoder, { payload: new Uint8Array([1]) })
|
20049
|
-
.catch((e) => log$6("Failed to send relay ping", e));
|
20060
|
+
.catch((e) => log$6.error("Failed to send relay ping", e));
|
20050
20061
|
}, relayPeriodSecs * 1000);
|
20051
20062
|
intervals.push(interval);
|
20052
20063
|
}
|
@@ -20054,7 +20065,7 @@ class KeepAliveManager {
|
|
20054
20065
|
}
|
20055
20066
|
}
|
20056
20067
|
|
20057
|
-
const log$5 =
|
20068
|
+
const log$5 = new Logger("connection-manager");
|
20058
20069
|
const DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED = 1;
|
20059
20070
|
const DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER = 3;
|
20060
20071
|
const DEFAULT_MAX_PARALLEL_DIALS = 3;
|
@@ -20066,7 +20077,7 @@ class ConnectionManager extends EventEmitter {
|
|
20066
20077
|
libp2p;
|
20067
20078
|
dialAttemptsForPeer = new Map();
|
20068
20079
|
dialErrorsForPeer = new Map();
|
20069
|
-
|
20080
|
+
currentActiveParallelDialCount = 0;
|
20070
20081
|
pendingPeerDialQueue = [];
|
20071
20082
|
static create(peerId, libp2p, keepAliveOptions, pubsubTopics, relay, options) {
|
20072
20083
|
let instance = ConnectionManager.instances.get(peerId);
|
@@ -20128,12 +20139,12 @@ class ConnectionManager extends EventEmitter {
|
|
20128
20139
|
};
|
20129
20140
|
this.keepAliveManager = new KeepAliveManager(keepAliveOptions, relay);
|
20130
20141
|
this.run()
|
20131
|
-
.then(() => log$5(`Connection Manager is now running`))
|
20132
|
-
.catch((error) => log$5(`Unexpected error while running service`, error));
|
20142
|
+
.then(() => log$5.info(`Connection Manager is now running`))
|
20143
|
+
.catch((error) => log$5.error(`Unexpected error while running service`, error));
|
20133
20144
|
// libp2p emits `peer:discovery` events during its initialization
|
20134
20145
|
// which means that before the ConnectionManager is initialized, some peers may have been discovered
|
20135
20146
|
// we will dial the peers in peerStore ONCE before we start to listen to the `peer:discovery` events within the ConnectionManager
|
20136
|
-
this.dialPeerStorePeers().catch((error) => log$5(`Unexpected error while dialing peer store peers`, error));
|
20147
|
+
this.dialPeerStorePeers().catch((error) => log$5.error(`Unexpected error while dialing peer store peers`, error));
|
20137
20148
|
}
|
20138
20149
|
async dialPeerStorePeers() {
|
20139
20150
|
const peerInfos = await this.libp2p.peerStore.all();
|
@@ -20147,7 +20158,7 @@ class ConnectionManager extends EventEmitter {
|
|
20147
20158
|
await Promise.all(dialPromises);
|
20148
20159
|
}
|
20149
20160
|
catch (error) {
|
20150
|
-
log$5(`Unexpected error while dialing peer store peers`, error);
|
20161
|
+
log$5.error(`Unexpected error while dialing peer store peers`, error);
|
20151
20162
|
}
|
20152
20163
|
}
|
20153
20164
|
async run() {
|
@@ -20163,11 +20174,11 @@ class ConnectionManager extends EventEmitter {
|
|
20163
20174
|
this.libp2p.removeEventListener("peer:discovery", this.onEventHandlers["peer:discovery"]);
|
20164
20175
|
}
|
20165
20176
|
async dialPeer(peerId) {
|
20166
|
-
this.
|
20177
|
+
this.currentActiveParallelDialCount += 1;
|
20167
20178
|
let dialAttempt = 0;
|
20168
20179
|
while (dialAttempt < this.options.maxDialAttemptsForPeer) {
|
20169
20180
|
try {
|
20170
|
-
log$5(`Dialing peer ${peerId.toString()} on attempt ${dialAttempt + 1}`);
|
20181
|
+
log$5.info(`Dialing peer ${peerId.toString()} on attempt ${dialAttempt + 1}`);
|
20171
20182
|
await this.libp2p.dial(peerId);
|
20172
20183
|
const tags = await this.getTagNamesForPeer(peerId);
|
20173
20184
|
// add tag to connection describing discovery mechanism
|
@@ -20175,18 +20186,20 @@ class ConnectionManager extends EventEmitter {
|
|
20175
20186
|
this.libp2p.getConnections(peerId).forEach((conn) => {
|
20176
20187
|
conn.tags = Array.from(new Set([...conn.tags, ...tags]));
|
20177
20188
|
});
|
20178
|
-
|
20189
|
+
// instead of deleting the peer from the peer store, we set the dial attempt to -1
|
20190
|
+
// this helps us keep track of peers that have been dialed before
|
20191
|
+
this.dialAttemptsForPeer.set(peerId.toString(), -1);
|
20179
20192
|
// Dialing succeeded, break the loop
|
20180
20193
|
break;
|
20181
20194
|
}
|
20182
20195
|
catch (error) {
|
20183
20196
|
if (error instanceof AggregateError) {
|
20184
20197
|
// Handle AggregateError
|
20185
|
-
log$5(`Error dialing peer ${peerId.toString()} - ${error.errors}`);
|
20198
|
+
log$5.error(`Error dialing peer ${peerId.toString()} - ${error.errors}`);
|
20186
20199
|
}
|
20187
20200
|
else {
|
20188
20201
|
// Handle generic error
|
20189
|
-
log$5(`Error dialing peer ${peerId.toString()} - ${error.message}`);
|
20202
|
+
log$5.error(`Error dialing peer ${peerId.toString()} - ${error.message}`);
|
20190
20203
|
}
|
20191
20204
|
this.dialErrorsForPeer.set(peerId.toString(), error);
|
20192
20205
|
dialAttempt++;
|
@@ -20194,7 +20207,7 @@ class ConnectionManager extends EventEmitter {
|
|
20194
20207
|
}
|
20195
20208
|
}
|
20196
20209
|
// Always decrease the active dial count and process the dial queue
|
20197
|
-
this.
|
20210
|
+
this.currentActiveParallelDialCount--;
|
20198
20211
|
this.processDialQueue();
|
20199
20212
|
// If max dial attempts reached and dialing failed, delete the peer
|
20200
20213
|
if (dialAttempt === this.options.maxDialAttemptsForPeer) {
|
@@ -20204,10 +20217,10 @@ class ConnectionManager extends EventEmitter {
|
|
20204
20217
|
let errorMessage;
|
20205
20218
|
if (error instanceof AggregateError) {
|
20206
20219
|
if (!error.errors) {
|
20207
|
-
log$5(`No errors array found for AggregateError`);
|
20220
|
+
log$5.warn(`No errors array found for AggregateError`);
|
20208
20221
|
}
|
20209
20222
|
else if (error.errors.length === 0) {
|
20210
|
-
log$5(`Errors array is empty for AggregateError`);
|
20223
|
+
log$5.warn(`Errors array is empty for AggregateError`);
|
20211
20224
|
}
|
20212
20225
|
else {
|
20213
20226
|
errorMessage = JSON.stringify(error.errors[0]);
|
@@ -20216,7 +20229,7 @@ class ConnectionManager extends EventEmitter {
|
|
20216
20229
|
else {
|
20217
20230
|
errorMessage = error.message;
|
20218
20231
|
}
|
20219
|
-
log$5(`Deleting undialable peer ${peerId.toString()} from peer store.
|
20232
|
+
log$5.info(`Deleting undialable peer ${peerId.toString()} from peer store. Reason: ${errorMessage}`);
|
20220
20233
|
}
|
20221
20234
|
this.dialErrorsForPeer.delete(peerId.toString());
|
20222
20235
|
await this.libp2p.peerStore.delete(peerId);
|
@@ -20230,20 +20243,20 @@ class ConnectionManager extends EventEmitter {
|
|
20230
20243
|
try {
|
20231
20244
|
this.keepAliveManager.stop(peerId);
|
20232
20245
|
await this.libp2p.hangUp(peerId);
|
20233
|
-
log$5(`Dropped connection with peer ${peerId.toString()}`);
|
20246
|
+
log$5.info(`Dropped connection with peer ${peerId.toString()}`);
|
20234
20247
|
}
|
20235
20248
|
catch (error) {
|
20236
|
-
log$5(`Error dropping connection with peer ${peerId.toString()} - ${error}`);
|
20249
|
+
log$5.error(`Error dropping connection with peer ${peerId.toString()} - ${error}`);
|
20237
20250
|
}
|
20238
20251
|
}
|
20239
20252
|
processDialQueue() {
|
20240
20253
|
if (this.pendingPeerDialQueue.length > 0 &&
|
20241
|
-
this.
|
20254
|
+
this.currentActiveParallelDialCount < this.options.maxParallelDials) {
|
20242
20255
|
const peerId = this.pendingPeerDialQueue.shift();
|
20243
20256
|
if (!peerId)
|
20244
20257
|
return;
|
20245
20258
|
this.attemptDial(peerId).catch((error) => {
|
20246
|
-
log$5(error);
|
20259
|
+
log$5.error(error);
|
20247
20260
|
});
|
20248
20261
|
}
|
20249
20262
|
}
|
@@ -20271,12 +20284,12 @@ class ConnectionManager extends EventEmitter {
|
|
20271
20284
|
async attemptDial(peerId) {
|
20272
20285
|
if (!(await this.shouldDialPeer(peerId)))
|
20273
20286
|
return;
|
20274
|
-
if (this.
|
20287
|
+
if (this.currentActiveParallelDialCount >= this.options.maxParallelDials) {
|
20275
20288
|
this.pendingPeerDialQueue.push(peerId);
|
20276
20289
|
return;
|
20277
20290
|
}
|
20278
20291
|
this.dialPeer(peerId).catch((err) => {
|
20279
|
-
log$5(`Error dialing peer ${peerId.toString()} : ${err}`);
|
20292
|
+
log$5.error(`Error dialing peer ${peerId.toString()} : ${err}`);
|
20280
20293
|
});
|
20281
20294
|
}
|
20282
20295
|
onEventHandlers = {
|
@@ -20288,7 +20301,7 @@ class ConnectionManager extends EventEmitter {
|
|
20288
20301
|
await this.attemptDial(peerId);
|
20289
20302
|
}
|
20290
20303
|
catch (error) {
|
20291
|
-
log$5(`Error dialing peer ${peerId.toString()} : ${error}`);
|
20304
|
+
log$5.error(`Error dialing peer ${peerId.toString()} : ${error}`);
|
20292
20305
|
}
|
20293
20306
|
})();
|
20294
20307
|
},
|
@@ -20329,25 +20342,31 @@ class ConnectionManager extends EventEmitter {
|
|
20329
20342
|
* 1. If the peer is already connected, don't dial
|
20330
20343
|
* 2. If the peer is not part of any of the configured pubsub topics, don't dial
|
20331
20344
|
* 3. If the peer is not dialable based on bootstrap status, don't dial
|
20345
|
+
* 4. If the peer is already has an active dial attempt, or has been dialed before, don't dial it
|
20332
20346
|
* @returns true if the peer should be dialed, false otherwise
|
20333
20347
|
*/
|
20334
20348
|
async shouldDialPeer(peerId) {
|
20335
20349
|
// if we're already connected to the peer, don't dial
|
20336
20350
|
const isConnected = this.libp2p.getConnections(peerId).length > 0;
|
20337
20351
|
if (isConnected) {
|
20338
|
-
log$5(`Already connected to peer ${peerId.toString()}. Not dialing.`);
|
20352
|
+
log$5.warn(`Already connected to peer ${peerId.toString()}. Not dialing.`);
|
20339
20353
|
return false;
|
20340
20354
|
}
|
20341
20355
|
// if the peer is not part of any of the configured pubsub topics, don't dial
|
20342
20356
|
if (!(await this.isPeerTopicConfigured(peerId))) {
|
20343
20357
|
const shardInfo = await this.getPeerShardInfo(peerId, this.libp2p.peerStore);
|
20344
|
-
log$5(`Discovered peer ${peerId.toString()} with ShardInfo ${shardInfo} is not part of any of the configured pubsub topics (${this.configuredPubSubTopics}).
|
20358
|
+
log$5.warn(`Discovered peer ${peerId.toString()} with ShardInfo ${shardInfo} is not part of any of the configured pubsub topics (${this.configuredPubSubTopics}).
|
20345
20359
|
Not dialing.`);
|
20346
20360
|
return false;
|
20347
20361
|
}
|
20348
20362
|
// if the peer is not dialable based on bootstrap status, don't dial
|
20349
20363
|
if (!(await this.isPeerDialableBasedOnBootstrapStatus(peerId))) {
|
20350
|
-
log$5(`Peer ${peerId.toString()} is not dialable based on bootstrap status. Not dialing.`);
|
20364
|
+
log$5.warn(`Peer ${peerId.toString()} is not dialable based on bootstrap status. Not dialing.`);
|
20365
|
+
return false;
|
20366
|
+
}
|
20367
|
+
// If the peer is already already has an active dial attempt, or has been dialed before, don't dial it
|
20368
|
+
if (this.dialAttemptsForPeer.has(peerId.toString())) {
|
20369
|
+
log$5.warn(`Peer ${peerId.toString()} has already been attempted dial before, or already has a dial attempt in progress, skipping dial`);
|
20351
20370
|
return false;
|
20352
20371
|
}
|
20353
20372
|
return true;
|
@@ -20391,7 +20410,7 @@ class ConnectionManager extends EventEmitter {
|
|
20391
20410
|
return Array.from(peer.tags.keys());
|
20392
20411
|
}
|
20393
20412
|
catch (error) {
|
20394
|
-
log$5(`Failed to get peer ${peerId}, error: ${error}`);
|
20413
|
+
log$5.error(`Failed to get peer ${peerId}, error: ${error}`);
|
20395
20414
|
return [];
|
20396
20415
|
}
|
20397
20416
|
}
|
@@ -20416,7 +20435,7 @@ class ConnectionManager extends EventEmitter {
|
|
20416
20435
|
const DefaultPingKeepAliveValueSecs = 5 * 60;
|
20417
20436
|
const DefaultRelayKeepAliveValueSecs = 5 * 60;
|
20418
20437
|
const DefaultUserAgent = "js-waku";
|
20419
|
-
const log$4 =
|
20438
|
+
const log$4 = new Logger("waku");
|
20420
20439
|
class WakuNode {
|
20421
20440
|
pubsubTopics;
|
20422
20441
|
libp2p;
|
@@ -20446,7 +20465,7 @@ class WakuNode {
|
|
20446
20465
|
: 0;
|
20447
20466
|
const peerId = this.libp2p.peerId.toString();
|
20448
20467
|
this.connectionManager = ConnectionManager.create(peerId, libp2p, { pingKeepAlive, relayKeepAlive }, pubsubTopics, this.relay);
|
20449
|
-
log$4("Waku node created", peerId, `relay: ${!!this.relay}, store: ${!!this.store}, light push: ${!!this
|
20468
|
+
log$4.info("Waku node created", peerId, `relay: ${!!this.relay}, store: ${!!this.store}, light push: ${!!this
|
20450
20469
|
.lightPush}, filter: ${!!this.filter}`);
|
20451
20470
|
}
|
20452
20471
|
/**
|
@@ -20470,7 +20489,7 @@ class WakuNode {
|
|
20470
20489
|
this.relay.gossipSub.multicodecs.forEach((codec) => codecs.push(codec));
|
20471
20490
|
}
|
20472
20491
|
else {
|
20473
|
-
log$4("Relay codec not included in dial codec: protocol not mounted locally");
|
20492
|
+
log$4.error("Relay codec not included in dial codec: protocol not mounted locally");
|
20474
20493
|
}
|
20475
20494
|
}
|
20476
20495
|
if (_protocols.includes(Protocols.Store)) {
|
@@ -20478,7 +20497,7 @@ class WakuNode {
|
|
20478
20497
|
codecs.push(this.store.multicodec);
|
20479
20498
|
}
|
20480
20499
|
else {
|
20481
|
-
log$4("Store codec not included in dial codec: protocol not mounted locally");
|
20500
|
+
log$4.error("Store codec not included in dial codec: protocol not mounted locally");
|
20482
20501
|
}
|
20483
20502
|
}
|
20484
20503
|
if (_protocols.includes(Protocols.LightPush)) {
|
@@ -20486,7 +20505,7 @@ class WakuNode {
|
|
20486
20505
|
codecs.push(this.lightPush.multicodec);
|
20487
20506
|
}
|
20488
20507
|
else {
|
20489
|
-
log$4("Light Push codec not included in dial codec: protocol not mounted locally");
|
20508
|
+
log$4.error("Light Push codec not included in dial codec: protocol not mounted locally");
|
20490
20509
|
}
|
20491
20510
|
}
|
20492
20511
|
if (_protocols.includes(Protocols.Filter)) {
|
@@ -20494,10 +20513,10 @@ class WakuNode {
|
|
20494
20513
|
codecs.push(this.filter.multicodec);
|
20495
20514
|
}
|
20496
20515
|
else {
|
20497
|
-
log$4("Filter codec not included in dial codec: protocol not mounted locally");
|
20516
|
+
log$4.error("Filter codec not included in dial codec: protocol not mounted locally");
|
20498
20517
|
}
|
20499
20518
|
}
|
20500
|
-
log$4(`Dialing to ${peerId.toString()} with protocols ${_protocols}`);
|
20519
|
+
log$4.info(`Dialing to ${peerId.toString()} with protocols ${_protocols}`);
|
20501
20520
|
return this.libp2p.dialProtocol(peerId, codecs);
|
20502
20521
|
}
|
20503
20522
|
async start() {
|
@@ -21919,7 +21938,7 @@ class FilterSubscribeResponse {
|
|
21919
21938
|
}
|
21920
21939
|
}
|
21921
21940
|
|
21922
|
-
const log$3 =
|
21941
|
+
const log$3 = new Logger("filter:v2");
|
21923
21942
|
const FilterCodecs = {
|
21924
21943
|
SUBSCRIBE: "/vac/waku/filter-subscribe/2.0.0-beta1",
|
21925
21944
|
PUSH: "/vac/waku/filter-push/2.0.0-beta1"
|
@@ -21937,6 +21956,12 @@ class Subscription {
|
|
21937
21956
|
}
|
21938
21957
|
async subscribe(decoders, callback) {
|
21939
21958
|
const decodersArray = Array.isArray(decoders) ? decoders : [decoders];
|
21959
|
+
// check that all decoders are configured for the same pubsub topic as this subscription
|
21960
|
+
decodersArray.forEach((decoder) => {
|
21961
|
+
if (decoder.pubsubTopic !== this.pubsubTopic) {
|
21962
|
+
throw new Error(`Pubsub topic not configured: decoder is configured for pubsub topic ${decoder.pubsubTopic} but this subscription is for pubsub topic ${this.pubsubTopic}. Please create a new Subscription for the different pubsub topic.`);
|
21963
|
+
}
|
21964
|
+
});
|
21940
21965
|
const decodersGroupedByCT = groupByContentTopic(decodersArray);
|
21941
21966
|
const contentTopics = Array.from(decodersGroupedByCT.keys());
|
21942
21967
|
const stream = await this.newStream(this.peer);
|
@@ -21950,7 +21975,7 @@ class Subscription {
|
|
21950
21975
|
if (statusCode < 200 || statusCode >= 300) {
|
21951
21976
|
throw new Error(`Filter subscribe request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
21952
21977
|
}
|
21953
|
-
log$3("Subscribed to peer ", this.peer.id.toString(), "for content topics", contentTopics);
|
21978
|
+
log$3.info("Subscribed to peer ", this.peer.id.toString(), "for content topics", contentTopics);
|
21954
21979
|
}
|
21955
21980
|
catch (e) {
|
21956
21981
|
throw new Error("Error subscribing to peer: " +
|
@@ -21993,14 +22018,17 @@ class Subscription {
|
|
21993
22018
|
const request = FilterSubscribeRpc.createSubscriberPingRequest();
|
21994
22019
|
try {
|
21995
22020
|
const res = await pipe([request.encode()], encode, stream, decode, async (source) => await all(source));
|
22021
|
+
if (!res || !res.length) {
|
22022
|
+
throw Error(`No response received for request ${request.requestId}: ${res}`);
|
22023
|
+
}
|
21996
22024
|
const { statusCode, requestId, statusDesc } = FilterSubscribeResponse.decode(res[0].slice());
|
21997
22025
|
if (statusCode < 200 || statusCode >= 300) {
|
21998
22026
|
throw new Error(`Filter ping request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
21999
22027
|
}
|
22000
|
-
log$3("Ping successful");
|
22028
|
+
log$3.info("Ping successful");
|
22001
22029
|
}
|
22002
22030
|
catch (error) {
|
22003
|
-
log$3("Error pinging: ", error);
|
22031
|
+
log$3.error("Error pinging: ", error);
|
22004
22032
|
throw new Error("Error pinging: " + error);
|
22005
22033
|
}
|
22006
22034
|
}
|
@@ -22009,12 +22037,15 @@ class Subscription {
|
|
22009
22037
|
const request = FilterSubscribeRpc.createUnsubscribeAllRequest(this.pubsubTopic);
|
22010
22038
|
try {
|
22011
22039
|
const res = await pipe([request.encode()], encode, stream, decode, async (source) => await all(source));
|
22040
|
+
if (!res || !res.length) {
|
22041
|
+
throw Error(`No response received for request ${request.requestId}: ${res}`);
|
22042
|
+
}
|
22012
22043
|
const { statusCode, requestId, statusDesc } = FilterSubscribeResponse.decode(res[0].slice());
|
22013
22044
|
if (statusCode < 200 || statusCode >= 300) {
|
22014
22045
|
throw new Error(`Filter unsubscribe all request ${requestId} failed with status code ${statusCode}: ${statusDesc}`);
|
22015
22046
|
}
|
22016
22047
|
this.subscriptionCallbacks.clear();
|
22017
|
-
log$3("Unsubscribed from all content topics");
|
22048
|
+
log$3.info("Unsubscribed from all content topics");
|
22018
22049
|
}
|
22019
22050
|
catch (error) {
|
22020
22051
|
throw new Error("Error unsubscribing from all content topics: " + error);
|
@@ -22024,7 +22055,7 @@ class Subscription {
|
|
22024
22055
|
const contentTopic = message.contentTopic;
|
22025
22056
|
const subscriptionCallback = this.subscriptionCallbacks.get(contentTopic);
|
22026
22057
|
if (!subscriptionCallback) {
|
22027
|
-
log$3("No subscription callback available for ", contentTopic);
|
22058
|
+
log$3.error("No subscription callback available for ", contentTopic);
|
22028
22059
|
return;
|
22029
22060
|
}
|
22030
22061
|
await pushMessage(subscriptionCallback, this.pubsubTopic, message);
|
@@ -22045,7 +22076,7 @@ class Filter extends BaseProtocol {
|
|
22045
22076
|
super(FilterCodecs.SUBSCRIBE, libp2p.components);
|
22046
22077
|
this.pubsubTopics = options?.pubsubTopics || [DefaultPubSubTopic];
|
22047
22078
|
libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this)).catch((e) => {
|
22048
|
-
log$3("Failed to register ", FilterCodecs.PUSH, e);
|
22079
|
+
log$3.error("Failed to register ", FilterCodecs.PUSH, e);
|
22049
22080
|
});
|
22050
22081
|
this.activeSubscriptions = new Map();
|
22051
22082
|
}
|
@@ -22088,36 +22119,35 @@ class Filter extends BaseProtocol {
|
|
22088
22119
|
};
|
22089
22120
|
}
|
22090
22121
|
onRequest(streamData) {
|
22091
|
-
log$3("Receiving message push");
|
22092
22122
|
try {
|
22093
22123
|
pipe(streamData.stream, decode, async (source) => {
|
22094
22124
|
for await (const bytes of source) {
|
22095
22125
|
const response = FilterPushRpc.decode(bytes.slice());
|
22096
22126
|
const { pubsubTopic, wakuMessage } = response;
|
22097
22127
|
if (!wakuMessage) {
|
22098
|
-
log$3("Received empty message");
|
22128
|
+
log$3.error("Received empty message");
|
22099
22129
|
return;
|
22100
22130
|
}
|
22101
22131
|
if (!pubsubTopic) {
|
22102
|
-
log$3("PubSub topic missing from push message");
|
22132
|
+
log$3.error("PubSub topic missing from push message");
|
22103
22133
|
return;
|
22104
22134
|
}
|
22105
22135
|
const peerIdStr = streamData.connection.remotePeer.toString();
|
22106
22136
|
const subscription = this.getActiveSubscription(pubsubTopic, peerIdStr);
|
22107
22137
|
if (!subscription) {
|
22108
|
-
log$3(`No subscription locally registered for topic ${pubsubTopic}`);
|
22138
|
+
log$3.error(`No subscription locally registered for topic ${pubsubTopic}`);
|
22109
22139
|
return;
|
22110
22140
|
}
|
22111
22141
|
await subscription.processMessage(wakuMessage);
|
22112
22142
|
}
|
22113
22143
|
}).then(() => {
|
22114
|
-
log$3("Receiving pipe closed.");
|
22144
|
+
log$3.info("Receiving pipe closed.");
|
22115
22145
|
}, (e) => {
|
22116
|
-
log$3("Error with receiving pipe", e);
|
22146
|
+
log$3.error("Error with receiving pipe", e);
|
22117
22147
|
});
|
22118
22148
|
}
|
22119
22149
|
catch (e) {
|
22120
|
-
log$3("Error decoding message", e);
|
22150
|
+
log$3.error("Error decoding message", e);
|
22121
22151
|
}
|
22122
22152
|
}
|
22123
22153
|
}
|
@@ -22128,7 +22158,7 @@ async function pushMessage(subscriptionCallback, pubsubTopic, message) {
|
|
22128
22158
|
const { decoders, callback } = subscriptionCallback;
|
22129
22159
|
const { contentTopic } = message;
|
22130
22160
|
if (!contentTopic) {
|
22131
|
-
log$3("Message has no content topic, skipping");
|
22161
|
+
log$3.warn("Message has no content topic, skipping");
|
22132
22162
|
return;
|
22133
22163
|
}
|
22134
22164
|
try {
|
@@ -22139,7 +22169,7 @@ async function pushMessage(subscriptionCallback, pubsubTopic, message) {
|
|
22139
22169
|
await callback(decodedMessage);
|
22140
22170
|
}
|
22141
22171
|
catch (e) {
|
22142
|
-
log$3("Error decoding message", e);
|
22172
|
+
log$3.error("Error decoding message", e);
|
22143
22173
|
}
|
22144
22174
|
}
|
22145
22175
|
|
@@ -22179,7 +22209,7 @@ class PushRpc {
|
|
22179
22209
|
}
|
22180
22210
|
}
|
22181
22211
|
|
22182
|
-
const log$2 =
|
22212
|
+
const log$2 = new Logger("light-push");
|
22183
22213
|
const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
22184
22214
|
/**
|
22185
22215
|
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
@@ -22193,13 +22223,17 @@ class LightPush extends BaseProtocol {
|
|
22193
22223
|
}
|
22194
22224
|
async preparePushMessage(encoder, message, pubsubTopic) {
|
22195
22225
|
try {
|
22196
|
-
if (!
|
22197
|
-
log$2("Failed to send waku light push:
|
22226
|
+
if (!message.payload || message.payload.length === 0) {
|
22227
|
+
log$2.error("Failed to send waku light push: payload is empty");
|
22228
|
+
return { query: null, error: SendError.EMPTY_PAYLOAD };
|
22229
|
+
}
|
22230
|
+
if (!(await isMessageSizeUnderCap(encoder, message))) {
|
22231
|
+
log$2.error("Failed to send waku light push: message is bigger than 1MB");
|
22198
22232
|
return { query: null, error: SendError.SIZE_TOO_BIG };
|
22199
22233
|
}
|
22200
22234
|
const protoMessage = await encoder.toProtoObj(message);
|
22201
22235
|
if (!protoMessage) {
|
22202
|
-
log$2("Failed to encode to protoMessage, aborting push");
|
22236
|
+
log$2.error("Failed to encode to protoMessage, aborting push");
|
22203
22237
|
return {
|
22204
22238
|
query: null,
|
22205
22239
|
error: SendError.ENCODE_FAILED
|
@@ -22209,7 +22243,7 @@ class LightPush extends BaseProtocol {
|
|
22209
22243
|
return { query, error: null };
|
22210
22244
|
}
|
22211
22245
|
catch (error) {
|
22212
|
-
log$2("Failed to prepare push message", error);
|
22246
|
+
log$2.error("Failed to prepare push message", error);
|
22213
22247
|
return {
|
22214
22248
|
query: null,
|
22215
22249
|
error: SendError.GENERIC_FAIL
|
@@ -22244,7 +22278,7 @@ class LightPush extends BaseProtocol {
|
|
22244
22278
|
stream = await this.getStream(peer);
|
22245
22279
|
}
|
22246
22280
|
catch (err) {
|
22247
|
-
log$2(`Failed to get a stream for remote peer${peer.id.toString()}`, err);
|
22281
|
+
log$2.error(`Failed to get a stream for remote peer${peer.id.toString()}`, err);
|
22248
22282
|
return { recipients, error: SendError.REMOTE_PEER_FAULT };
|
22249
22283
|
}
|
22250
22284
|
let res;
|
@@ -22252,7 +22286,7 @@ class LightPush extends BaseProtocol {
|
|
22252
22286
|
res = await pipe([query.encode()], encode, stream, decode, async (source) => await all(source));
|
22253
22287
|
}
|
22254
22288
|
catch (err) {
|
22255
|
-
log$2("Failed to send waku light push request", err);
|
22289
|
+
log$2.error("Failed to send waku light push request", err);
|
22256
22290
|
return { recipients, error: SendError.GENERIC_FAIL };
|
22257
22291
|
}
|
22258
22292
|
const bytes = new Uint8ArrayList();
|
@@ -22264,15 +22298,15 @@ class LightPush extends BaseProtocol {
|
|
22264
22298
|
response = PushRpc.decode(bytes).response;
|
22265
22299
|
}
|
22266
22300
|
catch (err) {
|
22267
|
-
log$2("Failed to decode push reply", err);
|
22301
|
+
log$2.error("Failed to decode push reply", err);
|
22268
22302
|
return { recipients, error: SendError.DECODE_FAILED };
|
22269
22303
|
}
|
22270
22304
|
if (!response) {
|
22271
|
-
log$2("Remote peer fault: No response in PushRPC");
|
22305
|
+
log$2.error("Remote peer fault: No response in PushRPC");
|
22272
22306
|
return { recipients, error: SendError.REMOTE_PEER_FAULT };
|
22273
22307
|
}
|
22274
22308
|
if (!response.isSuccess) {
|
22275
|
-
log$2("Remote peer rejected the message: ", response.info);
|
22309
|
+
log$2.error("Remote peer rejected the message: ", response.info);
|
22276
22310
|
return { recipients, error: SendError.REMOTE_PEER_REJECTED };
|
22277
22311
|
}
|
22278
22312
|
recipients.some((recipient) => recipient.equals(peer.id)) ||
|
@@ -22678,7 +22712,7 @@ function directionToProto(pageDirection) {
|
|
22678
22712
|
}
|
22679
22713
|
|
22680
22714
|
var HistoryError = HistoryResponse.HistoryError;
|
22681
|
-
const log$1 =
|
22715
|
+
const log$1 = new Logger("store");
|
22682
22716
|
const StoreCodec = "/vac/waku/store/2.0.0-beta4";
|
22683
22717
|
const DefaultPageSize = 10;
|
22684
22718
|
/**
|
@@ -22841,7 +22875,6 @@ class Store extends BaseProtocol {
|
|
22841
22875
|
pageDirection: PageDirection.BACKWARD,
|
22842
22876
|
pageSize: DefaultPageSize
|
22843
22877
|
}, options, { contentTopics, startTime, endTime });
|
22844
|
-
log$1("Querying history with the following options", options);
|
22845
22878
|
const peer = (await this.getPeers({
|
22846
22879
|
numPeers: this.NUM_PEERS_PROTOCOL,
|
22847
22880
|
maxBootstrapPeers: 1
|
@@ -22860,7 +22893,7 @@ async function* paginate(streamFactory, queryOpts, decoders, cursor) {
|
|
22860
22893
|
while (true) {
|
22861
22894
|
queryOpts.cursor = currentCursor;
|
22862
22895
|
const historyRpcQuery = HistoryRpc.createQuery(queryOpts);
|
22863
|
-
log$1("Querying store peer", `for (${queryOpts.pubsubTopic})`, queryOpts.contentTopics);
|
22896
|
+
log$1.info("Querying store peer", `for (${queryOpts.pubsubTopic})`, queryOpts.contentTopics);
|
22864
22897
|
const stream = await streamFactory();
|
22865
22898
|
const res = await pipe([historyRpcQuery.encode()], encode, stream, decode, async (source) => await all(source));
|
22866
22899
|
const bytes = new Uint8ArrayList();
|
@@ -22869,7 +22902,7 @@ async function* paginate(streamFactory, queryOpts, decoders, cursor) {
|
|
22869
22902
|
});
|
22870
22903
|
const reply = historyRpcQuery.decode(bytes);
|
22871
22904
|
if (!reply.response) {
|
22872
|
-
log$1("Stopping pagination due to store `response` field missing");
|
22905
|
+
log$1.warn("Stopping pagination due to store `response` field missing");
|
22873
22906
|
break;
|
22874
22907
|
}
|
22875
22908
|
const response = reply.response;
|
@@ -22877,10 +22910,10 @@ async function* paginate(streamFactory, queryOpts, decoders, cursor) {
|
|
22877
22910
|
throw "History response contains an Error: " + response.error;
|
22878
22911
|
}
|
22879
22912
|
if (!response.messages || !response.messages.length) {
|
22880
|
-
log$1("Stopping pagination due to store `response.messages` field missing or empty");
|
22913
|
+
log$1.warn("Stopping pagination due to store `response.messages` field missing or empty");
|
22881
22914
|
break;
|
22882
22915
|
}
|
22883
|
-
log$1(`${response.messages.length} messages retrieved from store`);
|
22916
|
+
log$1.error(`${response.messages.length} messages retrieved from store`);
|
22884
22917
|
yield response.messages.map((protoMsg) => {
|
22885
22918
|
const contentTopic = protoMsg.contentTopic;
|
22886
22919
|
if (typeof contentTopic !== "undefined") {
|
@@ -22895,7 +22928,7 @@ async function* paginate(streamFactory, queryOpts, decoders, cursor) {
|
|
22895
22928
|
if (typeof nextCursor === "undefined") {
|
22896
22929
|
// If the server does not return cursor then there is an issue,
|
22897
22930
|
// Need to abort, or we end up in an infinite loop
|
22898
|
-
log$1("Stopping pagination due to `response.pagingInfo.cursor` missing from store response");
|
22931
|
+
log$1.warn("Stopping pagination due to `response.pagingInfo.cursor` missing from store response");
|
22899
22932
|
break;
|
22900
22933
|
}
|
22901
22934
|
currentCursor = nextCursor;
|
@@ -23172,7 +23205,7 @@ function pEvent(emitter, event, options) {
|
|
23172
23205
|
return promise;
|
23173
23206
|
}
|
23174
23207
|
|
23175
|
-
const log =
|
23208
|
+
const log = new Logger("wait-for-remote-peer");
|
23176
23209
|
/**
|
23177
23210
|
* Wait for a remote peer to be ready given the passed protocols.
|
23178
23211
|
* Must be used after attempting to connect to nodes, using
|
@@ -23231,13 +23264,12 @@ async function waitForConnectedPeer(protocol) {
|
|
23231
23264
|
const codec = protocol.multicodec;
|
23232
23265
|
const peers = await protocol.peers();
|
23233
23266
|
if (peers.length) {
|
23234
|
-
log(`${codec} peer found: `, peers[0].id.toString());
|
23267
|
+
log.info(`${codec} peer found: `, peers[0].id.toString());
|
23235
23268
|
return;
|
23236
23269
|
}
|
23237
23270
|
await new Promise((resolve) => {
|
23238
23271
|
const cb = (evt) => {
|
23239
23272
|
if (evt.detail?.protocols?.includes(codec)) {
|
23240
|
-
log("Resolving for", codec, evt.detail.protocols);
|
23241
23273
|
protocol.removeLibp2pEventListener("peer:identify", cb);
|
23242
23274
|
resolve();
|
23243
23275
|
}
|