@waku/core 0.0.30 → 0.0.31-04bd518.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/{base_protocol-C6HnrRx8.js → base_protocol-BM6GbS_d.js} +19 -18
- package/bundle/index.js +81 -83
- package/bundle/lib/base_protocol.js +1 -1
- package/bundle/lib/message/version_0.js +1 -1
- package/bundle/{version_0-DQ9xsSLk.js → version_0-WhJLc79v.js} +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +2 -2
- package/dist/lib/base_protocol.js +1 -1
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager.d.ts +1 -1
- package/dist/lib/connection_manager.js +21 -23
- package/dist/lib/connection_manager.js.map +1 -1
- package/dist/lib/filter/filter_rpc.js.map +1 -1
- package/dist/lib/filter/index.d.ts +2 -2
- package/dist/lib/filter/index.js +29 -29
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/keep_alive_manager.d.ts +13 -7
- package/dist/lib/keep_alive_manager.js +9 -9
- package/dist/lib/keep_alive_manager.js.map +1 -1
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/push_rpc.js.map +1 -1
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/metadata/index.js +18 -18
- package/dist/lib/metadata/index.js.map +1 -1
- package/dist/lib/store/history_rpc.js.map +1 -1
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/stream_manager/index.d.ts +1 -0
- package/dist/lib/stream_manager/index.js +2 -0
- package/dist/lib/stream_manager/index.js.map +1 -0
- package/dist/lib/{stream_manager.js → stream_manager/stream_manager.js} +1 -1
- package/dist/lib/stream_manager/stream_manager.js.map +1 -0
- package/dist/lib/stream_manager/utils.d.ts +2 -0
- package/dist/lib/stream_manager/utils.js +19 -0
- package/dist/lib/stream_manager/utils.js.map +1 -0
- package/package.json +1 -130
- package/src/index.ts +1 -1
- package/src/lib/base_protocol.ts +4 -3
- package/src/lib/connection_manager.ts +28 -29
- package/src/lib/filter/filter_rpc.ts +21 -19
- package/src/lib/filter/index.ts +47 -42
- package/src/lib/keep_alive_manager.ts +27 -18
- package/src/lib/light_push/index.ts +2 -2
- package/src/lib/light_push/push_rpc.ts +5 -5
- package/src/lib/message/version_0.ts +17 -15
- package/src/lib/metadata/index.ts +33 -33
- package/src/lib/store/history_rpc.ts +5 -5
- package/src/lib/store/index.ts +2 -2
- package/src/lib/stream_manager/index.ts +1 -0
- package/src/lib/{stream_manager.ts → stream_manager/stream_manager.ts} +3 -2
- package/src/lib/stream_manager/utils.ts +22 -0
- package/dist/lib/stream_manager.js.map +0 -1
- /package/dist/lib/{stream_manager.d.ts → stream_manager/stream_manager.d.ts} +0 -0
@@ -118,24 +118,6 @@ async function getConnectedPeersForProtocolAndShard(connections, peerStore, prot
|
|
118
118
|
const peersWithNulls = await Promise.all(peerPromises);
|
119
119
|
return peersWithNulls.filter((peer) => peer !== null);
|
120
120
|
}
|
121
|
-
function selectConnection(connections) {
|
122
|
-
if (!connections.length)
|
123
|
-
return;
|
124
|
-
if (connections.length === 1)
|
125
|
-
return connections[0];
|
126
|
-
let latestConnection;
|
127
|
-
connections.forEach((connection) => {
|
128
|
-
if (connection.status === "open") {
|
129
|
-
if (!latestConnection) {
|
130
|
-
latestConnection = connection;
|
131
|
-
}
|
132
|
-
else if (connection.timeline.open > latestConnection.timeline.open) {
|
133
|
-
latestConnection = connection;
|
134
|
-
}
|
135
|
-
}
|
136
|
-
});
|
137
|
-
return latestConnection;
|
138
|
-
}
|
139
121
|
|
140
122
|
/**
|
141
123
|
* Retrieves a list of peers based on the specified criteria:
|
@@ -174,6 +156,25 @@ function filterPeersByDiscovery(peers, numPeers, maxBootstrapPeers) {
|
|
174
156
|
return selectedPeers;
|
175
157
|
}
|
176
158
|
|
159
|
+
function selectConnection(connections) {
|
160
|
+
if (!connections.length)
|
161
|
+
return;
|
162
|
+
if (connections.length === 1)
|
163
|
+
return connections[0];
|
164
|
+
let latestConnection;
|
165
|
+
connections.forEach((connection) => {
|
166
|
+
if (connection.status === "open") {
|
167
|
+
if (!latestConnection) {
|
168
|
+
latestConnection = connection;
|
169
|
+
}
|
170
|
+
else if (connection.timeline.open > latestConnection.timeline.open) {
|
171
|
+
latestConnection = connection;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
});
|
175
|
+
return latestConnection;
|
176
|
+
}
|
177
|
+
|
177
178
|
const CONNECTION_TIMEOUT = 5_000;
|
178
179
|
const RETRY_BACKOFF_BASE = 1_000;
|
179
180
|
const MAX_RETRIES = 3;
|
package/bundle/index.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { v as version_0, e as encodingLength, a as encode$1, d as decode$1, M as MessagePush, F as FilterSubscribeRequest, b as FilterSubscribeResponse$1, P as PushRpc$1, c as PushResponse, H as HistoryRpc$1, f as PagingInfo, g as HistoryResponse, h as createEncoder, W as
|
2
|
-
export { j as createDecoder } from './version_0-
|
1
|
+
import { v as version_0, e as encodingLength, a as encode$1, d as decode$1, M as MessagePush, F as FilterSubscribeRequest, b as FilterSubscribeResponse$1, P as PushRpc$1, c as PushResponse, H as HistoryRpc$1, f as PagingInfo, g as HistoryResponse, h as createEncoder, W as WakuMetadataRequest, i as WakuMetadataResponse } from './version_0-WhJLc79v.js';
|
2
|
+
export { j as createDecoder } from './version_0-WhJLc79v.js';
|
3
3
|
import { a as allocUnsafe, b as alloc, g as getDefaultExportFromCjs, L as Logger, P as ProtocolError, c as Protocols, u as utf8ToBytes, p as pubsubTopicToSingleShardInfo, E as EConnectionStateEvents, T as Tags, d as EPeersByDiscoveryEvents, s as shardInfoToPubsubTopics } from './index-DnW8ifxc.js';
|
4
|
-
import { B as BaseProtocol, d as decodeRelayShard, e as encodeRelayShard } from './base_protocol-
|
5
|
-
export { S as StreamManager } from './base_protocol-
|
4
|
+
import { B as BaseProtocol, d as decodeRelayShard, e as encodeRelayShard } from './base_protocol-BM6GbS_d.js';
|
5
|
+
export { S as StreamManager } from './base_protocol-BM6GbS_d.js';
|
6
6
|
|
7
7
|
const MB = 1024 ** 2;
|
8
8
|
const SIZE_CAP_IN_MB = 1;
|
@@ -1622,35 +1622,6 @@ class FilterCore extends BaseProtocol {
|
|
1622
1622
|
log$6.error("Failed to register ", FilterCodecs.PUSH, e);
|
1623
1623
|
});
|
1624
1624
|
}
|
1625
|
-
onRequest(streamData) {
|
1626
|
-
const { connection, stream } = streamData;
|
1627
|
-
const { remotePeer } = connection;
|
1628
|
-
log$6.info(`Received message from ${remotePeer.toString()}`);
|
1629
|
-
try {
|
1630
|
-
pipe(stream, decode, async (source) => {
|
1631
|
-
for await (const bytes of source) {
|
1632
|
-
const response = FilterPushRpc.decode(bytes.slice());
|
1633
|
-
const { pubsubTopic, wakuMessage } = response;
|
1634
|
-
if (!wakuMessage) {
|
1635
|
-
log$6.error("Received empty message");
|
1636
|
-
return;
|
1637
|
-
}
|
1638
|
-
if (!pubsubTopic) {
|
1639
|
-
log$6.error("Pubsub topic missing from push message");
|
1640
|
-
return;
|
1641
|
-
}
|
1642
|
-
await this.handleIncomingMessage(pubsubTopic, wakuMessage);
|
1643
|
-
}
|
1644
|
-
}).then(() => {
|
1645
|
-
log$6.info("Receiving pipe closed.");
|
1646
|
-
}, (e) => {
|
1647
|
-
log$6.error("Error with receiving pipe", e);
|
1648
|
-
});
|
1649
|
-
}
|
1650
|
-
catch (e) {
|
1651
|
-
log$6.error("Error decoding message", e);
|
1652
|
-
}
|
1653
|
-
}
|
1654
1625
|
async subscribe(pubsubTopic, peer, contentTopics) {
|
1655
1626
|
const stream = await this.getStream(peer);
|
1656
1627
|
const request = FilterSubscribeRpc.createSubscribeRequest(pubsubTopic, contentTopics);
|
@@ -1802,6 +1773,35 @@ class FilterCore extends BaseProtocol {
|
|
1802
1773
|
failure: null
|
1803
1774
|
};
|
1804
1775
|
}
|
1776
|
+
onRequest(streamData) {
|
1777
|
+
const { connection, stream } = streamData;
|
1778
|
+
const { remotePeer } = connection;
|
1779
|
+
log$6.info(`Received message from ${remotePeer.toString()}`);
|
1780
|
+
try {
|
1781
|
+
pipe(stream, decode, async (source) => {
|
1782
|
+
for await (const bytes of source) {
|
1783
|
+
const response = FilterPushRpc.decode(bytes.slice());
|
1784
|
+
const { pubsubTopic, wakuMessage } = response;
|
1785
|
+
if (!wakuMessage) {
|
1786
|
+
log$6.error("Received empty message");
|
1787
|
+
return;
|
1788
|
+
}
|
1789
|
+
if (!pubsubTopic) {
|
1790
|
+
log$6.error("Pubsub topic missing from push message");
|
1791
|
+
return;
|
1792
|
+
}
|
1793
|
+
await this.handleIncomingMessage(pubsubTopic, wakuMessage, connection.remotePeer.toString());
|
1794
|
+
}
|
1795
|
+
}).then(() => {
|
1796
|
+
log$6.info("Receiving pipe closed.");
|
1797
|
+
}, (e) => {
|
1798
|
+
log$6.error("Error with receiving pipe", e);
|
1799
|
+
});
|
1800
|
+
}
|
1801
|
+
catch (e) {
|
1802
|
+
log$6.error("Error decoding message", e);
|
1803
|
+
}
|
1804
|
+
}
|
1805
1805
|
}
|
1806
1806
|
|
1807
1807
|
var index$2 = /*#__PURE__*/Object.freeze({
|
@@ -2594,17 +2594,17 @@ const CustomEvent = globalThis.CustomEvent ?? CustomEventPolyfill;
|
|
2594
2594
|
const RelayPingContentTopic = "/relay-ping/1/ping/null";
|
2595
2595
|
const log$2 = new Logger("keep-alive");
|
2596
2596
|
class KeepAliveManager {
|
2597
|
-
pingKeepAliveTimers;
|
2598
|
-
relayKeepAliveTimers;
|
2599
|
-
options;
|
2600
2597
|
relay;
|
2601
|
-
|
2602
|
-
|
2603
|
-
|
2598
|
+
libp2p;
|
2599
|
+
options;
|
2600
|
+
pingKeepAliveTimers = new Map();
|
2601
|
+
relayKeepAliveTimers = new Map();
|
2602
|
+
constructor({ options, relay, libp2p }) {
|
2604
2603
|
this.options = options;
|
2605
2604
|
this.relay = relay;
|
2605
|
+
this.libp2p = libp2p;
|
2606
2606
|
}
|
2607
|
-
start(peerId
|
2607
|
+
start(peerId) {
|
2608
2608
|
// Just in case a timer already exists for this peer
|
2609
2609
|
this.stop(peerId);
|
2610
2610
|
const { pingKeepAlive: pingPeriodSecs, relayKeepAlive: relayPeriodSecs } = this.options;
|
@@ -2619,7 +2619,7 @@ class KeepAliveManager {
|
|
2619
2619
|
// ping the peer for keep alive
|
2620
2620
|
// also update the peer store with the latency
|
2621
2621
|
try {
|
2622
|
-
ping = await
|
2622
|
+
ping = await this.libp2p.services.ping.ping(peerId);
|
2623
2623
|
log$2.info(`Ping succeeded (${peerIdStr})`, ping);
|
2624
2624
|
}
|
2625
2625
|
catch (error) {
|
@@ -2629,7 +2629,7 @@ class KeepAliveManager {
|
|
2629
2629
|
return;
|
2630
2630
|
}
|
2631
2631
|
try {
|
2632
|
-
await peerStore.merge(peerId, {
|
2632
|
+
await this.libp2p.peerStore.merge(peerId, {
|
2633
2633
|
metadata: {
|
2634
2634
|
ping: utf8ToBytes(ping.toString())
|
2635
2635
|
}
|
@@ -2818,7 +2818,11 @@ class ConnectionManager extends TypedEventEmitter {
|
|
2818
2818
|
maxParallelDials: DEFAULT_MAX_PARALLEL_DIALS,
|
2819
2819
|
...options
|
2820
2820
|
};
|
2821
|
-
this.keepAliveManager = new KeepAliveManager(
|
2821
|
+
this.keepAliveManager = new KeepAliveManager({
|
2822
|
+
relay,
|
2823
|
+
libp2p,
|
2824
|
+
options: keepAliveOptions
|
2825
|
+
});
|
2822
2826
|
this.run()
|
2823
2827
|
.then(() => log$1.info(`Connection Manager is now running`))
|
2824
2828
|
.catch((error) => log$1.error(`Unexpected error while running service`, error));
|
@@ -2865,6 +2869,7 @@ class ConnectionManager extends TypedEventEmitter {
|
|
2865
2869
|
// this helps us keep track of peers that have been dialed before
|
2866
2870
|
this.dialAttemptsForPeer.set(peerId.toString(), -1);
|
2867
2871
|
// Dialing succeeded, break the loop
|
2872
|
+
this.keepAliveManager.start(peerId);
|
2868
2873
|
break;
|
2869
2874
|
}
|
2870
2875
|
catch (error) {
|
@@ -2953,9 +2958,7 @@ class ConnectionManager extends TypedEventEmitter {
|
|
2953
2958
|
this.pendingPeerDialQueue.push(peerId);
|
2954
2959
|
return;
|
2955
2960
|
}
|
2956
|
-
this.dialPeer(peerId)
|
2957
|
-
log$1.error(`Error dialing peer ${peerId.toString()} : ${err}`);
|
2958
|
-
});
|
2961
|
+
await this.dialPeer(peerId);
|
2959
2962
|
}
|
2960
2963
|
onEventHandlers = {
|
2961
2964
|
"peer:discovery": (evt) => {
|
@@ -2974,7 +2977,7 @@ class ConnectionManager extends TypedEventEmitter {
|
|
2974
2977
|
void (async () => {
|
2975
2978
|
log$1.info(`Connected to peer ${evt.detail.toString()}`);
|
2976
2979
|
const peerId = evt.detail;
|
2977
|
-
this.keepAliveManager.start(peerId
|
2980
|
+
this.keepAliveManager.start(peerId);
|
2978
2981
|
const isBootstrap = (await this.getTagNamesForPeer(peerId)).includes(Tags.BOOTSTRAP);
|
2979
2982
|
if (isBootstrap) {
|
2980
2983
|
const bootstrapConnections = this.libp2p
|
@@ -3014,26 +3017,25 @@ class ConnectionManager extends TypedEventEmitter {
|
|
3014
3017
|
* @returns true if the peer should be dialed, false otherwise
|
3015
3018
|
*/
|
3016
3019
|
async shouldDialPeer(peerId) {
|
3017
|
-
// if we're already connected to the peer, don't dial
|
3018
3020
|
const isConnected = this.libp2p.getConnections(peerId).length > 0;
|
3019
3021
|
if (isConnected) {
|
3020
3022
|
log$1.warn(`Already connected to peer ${peerId.toString()}. Not dialing.`);
|
3021
3023
|
return false;
|
3022
3024
|
}
|
3023
|
-
|
3024
|
-
if (!
|
3025
|
+
const isSameShard = await this.isPeerTopicConfigured(peerId);
|
3026
|
+
if (!isSameShard) {
|
3025
3027
|
const shardInfo = await this.getPeerShardInfo(peerId, this.libp2p.peerStore);
|
3026
3028
|
log$1.warn(`Discovered peer ${peerId.toString()} with ShardInfo ${shardInfo} is not part of any of the configured pubsub topics (${this.configuredPubsubTopics}).
|
3027
3029
|
Not dialing.`);
|
3028
3030
|
return false;
|
3029
3031
|
}
|
3030
|
-
|
3031
|
-
if (!
|
3032
|
+
const isPreferredBasedOnBootstrap = await this.isPeerDialableBasedOnBootstrapStatus(peerId);
|
3033
|
+
if (!isPreferredBasedOnBootstrap) {
|
3032
3034
|
log$1.warn(`Peer ${peerId.toString()} is not dialable based on bootstrap status. Not dialing.`);
|
3033
3035
|
return false;
|
3034
3036
|
}
|
3035
|
-
|
3036
|
-
if (
|
3037
|
+
const hasBeenDialed = this.dialAttemptsForPeer.has(peerId.toString());
|
3038
|
+
if (hasBeenDialed) {
|
3037
3039
|
log$1.warn(`Peer ${peerId.toString()} has already been attempted dial before, or already has a dial attempt in progress, skipping dial`);
|
3038
3040
|
return false;
|
3039
3041
|
}
|
@@ -3047,19 +3049,15 @@ class ConnectionManager extends TypedEventEmitter {
|
|
3047
3049
|
async isPeerDialableBasedOnBootstrapStatus(peerId) {
|
3048
3050
|
const tagNames = await this.getTagNamesForPeer(peerId);
|
3049
3051
|
const isBootstrap = tagNames.some((tagName) => tagName === Tags.BOOTSTRAP);
|
3050
|
-
if (isBootstrap) {
|
3051
|
-
const currentBootstrapConnections = this.libp2p
|
3052
|
-
.getConnections()
|
3053
|
-
.filter((conn) => {
|
3054
|
-
return conn.tags.find((name) => name === Tags.BOOTSTRAP);
|
3055
|
-
}).length;
|
3056
|
-
if (currentBootstrapConnections < this.options.maxBootstrapPeersAllowed)
|
3057
|
-
return true;
|
3058
|
-
}
|
3059
|
-
else {
|
3052
|
+
if (!isBootstrap) {
|
3060
3053
|
return true;
|
3061
3054
|
}
|
3062
|
-
|
3055
|
+
const currentBootstrapConnections = this.libp2p
|
3056
|
+
.getConnections()
|
3057
|
+
.filter((conn) => {
|
3058
|
+
return conn.tags.find((name) => name === Tags.BOOTSTRAP);
|
3059
|
+
}).length;
|
3060
|
+
return currentBootstrapConnections < this.options.maxBootstrapPeersAllowed;
|
3063
3061
|
}
|
3064
3062
|
async dispatchDiscoveryEvent(peerId) {
|
3065
3063
|
const isBootstrap = (await this.getTagNamesForPeer(peerId)).includes(Tags.BOOTSTRAP);
|
@@ -3114,24 +3112,6 @@ class Metadata extends BaseProtocol {
|
|
3114
3112
|
void this.onRequest(streamData);
|
3115
3113
|
});
|
3116
3114
|
}
|
3117
|
-
/**
|
3118
|
-
* Handle an incoming metadata request
|
3119
|
-
*/
|
3120
|
-
async onRequest(streamData) {
|
3121
|
-
try {
|
3122
|
-
const { stream, connection } = streamData;
|
3123
|
-
const encodedShardInfo = WakuMetadataResponse.encode(this.shardInfo);
|
3124
|
-
const encodedResponse = await pipe([encodedShardInfo], encode, stream, decode, async (source) => await all(source));
|
3125
|
-
const { error, shardInfo } = this.decodeMetadataResponse(encodedResponse);
|
3126
|
-
if (error) {
|
3127
|
-
return;
|
3128
|
-
}
|
3129
|
-
await this.savePeerShardInfo(connection.remotePeer, shardInfo);
|
3130
|
-
}
|
3131
|
-
catch (error) {
|
3132
|
-
log.error("Error handling metadata request", error);
|
3133
|
-
}
|
3134
|
-
}
|
3135
3115
|
/**
|
3136
3116
|
* Make a metadata query to a peer
|
3137
3117
|
*/
|
@@ -3179,6 +3159,24 @@ class Metadata extends BaseProtocol {
|
|
3179
3159
|
}
|
3180
3160
|
return await this.query(peerId);
|
3181
3161
|
}
|
3162
|
+
/**
|
3163
|
+
* Handle an incoming metadata request
|
3164
|
+
*/
|
3165
|
+
async onRequest(streamData) {
|
3166
|
+
try {
|
3167
|
+
const { stream, connection } = streamData;
|
3168
|
+
const encodedShardInfo = WakuMetadataResponse.encode(this.shardInfo);
|
3169
|
+
const encodedResponse = await pipe([encodedShardInfo], encode, stream, decode, async (source) => await all(source));
|
3170
|
+
const { error, shardInfo } = this.decodeMetadataResponse(encodedResponse);
|
3171
|
+
if (error) {
|
3172
|
+
return;
|
3173
|
+
}
|
3174
|
+
await this.savePeerShardInfo(connection.remotePeer, shardInfo);
|
3175
|
+
}
|
3176
|
+
catch (error) {
|
3177
|
+
log.error("Error handling metadata request", error);
|
3178
|
+
}
|
3179
|
+
}
|
3182
3180
|
decodeMetadataResponse(encodedResponse) {
|
3183
3181
|
const bytes = new Uint8ArrayList();
|
3184
3182
|
encodedResponse.forEach((chunk) => {
|
@@ -1,2 +1,2 @@
|
|
1
1
|
import '../index-DnW8ifxc.js';
|
2
|
-
export { B as BaseProtocol } from '../base_protocol-
|
2
|
+
export { B as BaseProtocol } from '../base_protocol-BM6GbS_d.js';
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export { D as DecodedMessage, k as Decoder, E as Encoder, V as Version, j as createDecoder, h as createEncoder, m as proto } from '../../version_0-
|
1
|
+
export { D as DecodedMessage, k as Decoder, E as Encoder, V as Version, j as createDecoder, h as createEncoder, m as proto } from '../../version_0-WhJLc79v.js';
|
2
2
|
import '../../index-DnW8ifxc.js';
|
@@ -4056,4 +4056,4 @@ var version_0 = /*#__PURE__*/Object.freeze({
|
|
4056
4056
|
proto: message
|
4057
4057
|
});
|
4058
4058
|
|
4059
|
-
export { DecodedMessage as D, Encoder as E, FilterSubscribeRequest as F, HistoryRpc$1 as H, MessagePush as M, PushRpc$1 as P, Version as V,
|
4059
|
+
export { DecodedMessage as D, Encoder as E, FilterSubscribeRequest as F, HistoryRpc$1 as H, MessagePush as M, PushRpc$1 as P, Version as V, WakuMetadataRequest as W, encode as a, FilterSubscribeResponse$1 as b, PushResponse as c, decode as d, encodingLength as e, PagingInfo as f, HistoryResponse as g, createEncoder as h, WakuMetadataResponse as i, createDecoder as j, Decoder as k, message as m, version_0 as v };
|