@waku/core 0.0.34-1c0c5ee.0 → 0.0.34-3670e82.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-Bp5a9PNG.js +152 -0
- package/bundle/{index-BIW3qNYx.js → index-G1eRBjeI.js} +118 -204
- package/bundle/index.js +1895 -178
- package/bundle/lib/base_protocol.js +2 -2
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/{version_0-CdmZMfkQ.js → version_0-DJZG2fB2.js} +283 -45
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +3 -23
- package/dist/lib/base_protocol.js +3 -47
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager/connection_manager.d.ts +118 -0
- package/dist/lib/{connection_manager.js → connection_manager/connection_manager.js} +136 -36
- package/dist/lib/connection_manager/connection_manager.js.map +1 -0
- package/dist/lib/connection_manager/index.d.ts +1 -0
- package/dist/lib/connection_manager/index.js +2 -0
- package/dist/lib/connection_manager/index.js.map +1 -0
- package/dist/lib/{keep_alive_manager.d.ts → connection_manager/keep_alive_manager.d.ts} +4 -2
- package/dist/lib/{keep_alive_manager.js → connection_manager/keep_alive_manager.js} +2 -2
- package/dist/lib/connection_manager/keep_alive_manager.js.map +1 -0
- package/dist/lib/connection_manager/utils.d.ts +7 -0
- package/dist/lib/connection_manager/utils.js +22 -0
- package/dist/lib/connection_manager/utils.js.map +1 -0
- package/dist/lib/filter/filter.d.ts +18 -0
- package/dist/lib/filter/filter.js +209 -0
- package/dist/lib/filter/filter.js.map +1 -0
- package/dist/lib/filter/index.d.ts +1 -18
- package/dist/lib/filter/index.js +1 -208
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/light_push/index.d.ts +1 -15
- package/dist/lib/light_push/index.js +1 -143
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/light_push.d.ts +15 -0
- package/dist/lib/light_push/light_push.js +144 -0
- package/dist/lib/light_push/light_push.js.map +1 -0
- package/dist/lib/light_push/utils.d.ts +0 -2
- package/dist/lib/light_push/utils.js +9 -17
- package/dist/lib/light_push/utils.js.map +1 -1
- package/dist/lib/metadata/index.d.ts +1 -3
- package/dist/lib/metadata/index.js +1 -118
- package/dist/lib/metadata/index.js.map +1 -1
- package/dist/lib/metadata/metadata.d.ts +3 -0
- package/dist/lib/metadata/metadata.js +119 -0
- package/dist/lib/metadata/metadata.js.map +1 -0
- package/dist/lib/store/index.d.ts +1 -9
- package/dist/lib/store/index.js +1 -82
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/store/store.d.ts +9 -0
- package/dist/lib/store/store.js +83 -0
- package/dist/lib/store/store.js.map +1 -0
- package/dist/lib/stream_manager/stream_manager.d.ts +2 -2
- package/dist/lib/stream_manager/stream_manager.js +16 -17
- package/dist/lib/stream_manager/stream_manager.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -4
- package/src/lib/base_protocol.ts +3 -76
- package/src/lib/{connection_manager.ts → connection_manager/connection_manager.ts} +168 -63
- package/src/lib/connection_manager/index.ts +1 -0
- package/src/lib/{keep_alive_manager.ts → connection_manager/keep_alive_manager.ts} +7 -3
- package/src/lib/connection_manager/utils.ts +25 -0
- package/src/lib/filter/filter.ts +315 -0
- package/src/lib/filter/index.ts +1 -315
- package/src/lib/light_push/index.ts +1 -188
- package/src/lib/light_push/light_push.ts +188 -0
- package/src/lib/light_push/utils.ts +13 -21
- package/src/lib/metadata/index.ts +1 -182
- package/src/lib/metadata/metadata.ts +182 -0
- package/src/lib/store/index.ts +1 -136
- package/src/lib/store/store.ts +136 -0
- package/src/lib/stream_manager/stream_manager.ts +16 -18
- package/bundle/base_protocol-Dzv-QHPR.js +0 -275
- package/dist/lib/connection_manager.d.ts +0 -62
- package/dist/lib/connection_manager.js.map +0 -1
- package/dist/lib/filterPeers.d.ts +0 -13
- package/dist/lib/filterPeers.js +0 -38
- package/dist/lib/filterPeers.js.map +0 -1
- package/dist/lib/health_manager.d.ts +0 -14
- package/dist/lib/health_manager.js +0 -70
- package/dist/lib/health_manager.js.map +0 -1
- package/dist/lib/keep_alive_manager.js.map +0 -1
- package/src/lib/filterPeers.ts +0 -51
- package/src/lib/health_manager.ts +0 -90
package/src/lib/filterPeers.ts
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
import { Peer } from "@libp2p/interface";
|
2
|
-
import { Tags } from "@waku/interfaces";
|
3
|
-
|
4
|
-
/**
|
5
|
-
* Retrieves a list of peers based on the specified criteria:
|
6
|
-
* 1. If numPeers is 0, return all peers
|
7
|
-
* 2. Bootstrap peers are prioritized
|
8
|
-
* 3. Non-bootstrap peers are randomly selected to fill up to numPeers
|
9
|
-
*
|
10
|
-
* @param peers - The list of peers to filter from.
|
11
|
-
* @param numPeers - The total number of peers to retrieve. If 0, all peers are returned, irrespective of `maxBootstrapPeers`.
|
12
|
-
* @param maxBootstrapPeers - The maximum number of bootstrap peers to retrieve.
|
13
|
-
* @returns An array of peers based on the specified criteria.
|
14
|
-
*/
|
15
|
-
export function filterPeersByDiscovery(
|
16
|
-
peers: Peer[],
|
17
|
-
numPeers: number,
|
18
|
-
maxBootstrapPeers: number
|
19
|
-
): Peer[] {
|
20
|
-
// Collect the bootstrap peers up to the specified maximum
|
21
|
-
let bootstrapPeers = peers
|
22
|
-
.filter((peer) => peer.tags.has(Tags.BOOTSTRAP))
|
23
|
-
.slice(0, maxBootstrapPeers);
|
24
|
-
|
25
|
-
// If numPeers is less than the number of bootstrap peers, adjust the bootstrapPeers array
|
26
|
-
if (numPeers > 0 && numPeers < bootstrapPeers.length) {
|
27
|
-
bootstrapPeers = bootstrapPeers.slice(0, numPeers);
|
28
|
-
}
|
29
|
-
|
30
|
-
// Collect non-bootstrap peers
|
31
|
-
const nonBootstrapPeers = peers.filter(
|
32
|
-
(peer) => !peer.tags.has(Tags.BOOTSTRAP)
|
33
|
-
);
|
34
|
-
|
35
|
-
// If numPeers is 0, return all peers
|
36
|
-
if (numPeers === 0) {
|
37
|
-
return [...bootstrapPeers, ...nonBootstrapPeers];
|
38
|
-
}
|
39
|
-
|
40
|
-
// Initialize the list of selected peers with the bootstrap peers
|
41
|
-
const selectedPeers: Peer[] = [...bootstrapPeers];
|
42
|
-
|
43
|
-
// Fill up to numPeers with remaining random peers if needed
|
44
|
-
while (selectedPeers.length < numPeers && nonBootstrapPeers.length > 0) {
|
45
|
-
const randomIndex = Math.floor(Math.random() * nonBootstrapPeers.length);
|
46
|
-
const randomPeer = nonBootstrapPeers.splice(randomIndex, 1)[0];
|
47
|
-
selectedPeers.push(randomPeer);
|
48
|
-
}
|
49
|
-
|
50
|
-
return selectedPeers;
|
51
|
-
}
|
@@ -1,90 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
HealthStatus,
|
3
|
-
type IHealthManager,
|
4
|
-
NodeHealth,
|
5
|
-
type ProtocolHealth,
|
6
|
-
Protocols
|
7
|
-
} from "@waku/interfaces";
|
8
|
-
|
9
|
-
class HealthManager implements IHealthManager {
|
10
|
-
public static instance: HealthManager;
|
11
|
-
private readonly health: NodeHealth;
|
12
|
-
|
13
|
-
private constructor() {
|
14
|
-
this.health = {
|
15
|
-
overallStatus: HealthStatus.Unhealthy,
|
16
|
-
protocolStatuses: new Map()
|
17
|
-
};
|
18
|
-
}
|
19
|
-
|
20
|
-
public static getInstance(): HealthManager {
|
21
|
-
if (!HealthManager.instance) {
|
22
|
-
HealthManager.instance = new HealthManager();
|
23
|
-
}
|
24
|
-
return HealthManager.instance;
|
25
|
-
}
|
26
|
-
|
27
|
-
public getHealthStatus(): HealthStatus {
|
28
|
-
return this.health.overallStatus;
|
29
|
-
}
|
30
|
-
|
31
|
-
public getProtocolStatus(protocol: Protocols): ProtocolHealth | undefined {
|
32
|
-
return this.health.protocolStatuses.get(protocol);
|
33
|
-
}
|
34
|
-
|
35
|
-
public updateProtocolHealth(
|
36
|
-
multicodec: string,
|
37
|
-
connectedPeers: number
|
38
|
-
): void {
|
39
|
-
const protocol = this.getNameFromMulticodec(multicodec);
|
40
|
-
|
41
|
-
let status: HealthStatus = HealthStatus.Unhealthy;
|
42
|
-
if (connectedPeers == 1) {
|
43
|
-
status = HealthStatus.MinimallyHealthy;
|
44
|
-
} else if (connectedPeers >= 2) {
|
45
|
-
status = HealthStatus.SufficientlyHealthy;
|
46
|
-
}
|
47
|
-
|
48
|
-
this.health.protocolStatuses.set(protocol, {
|
49
|
-
name: protocol,
|
50
|
-
status: status,
|
51
|
-
lastUpdate: new Date()
|
52
|
-
});
|
53
|
-
|
54
|
-
this.updateOverallHealth();
|
55
|
-
}
|
56
|
-
|
57
|
-
private getNameFromMulticodec(multicodec: string): Protocols {
|
58
|
-
let name: Protocols;
|
59
|
-
if (multicodec.includes("filter")) {
|
60
|
-
name = Protocols.Filter;
|
61
|
-
} else if (multicodec.includes("lightpush")) {
|
62
|
-
name = Protocols.LightPush;
|
63
|
-
} else if (multicodec.includes("store")) {
|
64
|
-
name = Protocols.Store;
|
65
|
-
} else {
|
66
|
-
throw new Error(`Unknown protocol: ${multicodec}`);
|
67
|
-
}
|
68
|
-
return name;
|
69
|
-
}
|
70
|
-
|
71
|
-
private updateOverallHealth(): void {
|
72
|
-
const relevantProtocols = [Protocols.LightPush, Protocols.Filter];
|
73
|
-
const statuses = relevantProtocols.map(
|
74
|
-
(p) => this.getProtocolStatus(p)?.status
|
75
|
-
);
|
76
|
-
|
77
|
-
if (statuses.some((status) => status === HealthStatus.Unhealthy)) {
|
78
|
-
this.health.overallStatus = HealthStatus.Unhealthy;
|
79
|
-
} else if (
|
80
|
-
statuses.some((status) => status === HealthStatus.MinimallyHealthy)
|
81
|
-
) {
|
82
|
-
this.health.overallStatus = HealthStatus.MinimallyHealthy;
|
83
|
-
} else {
|
84
|
-
this.health.overallStatus = HealthStatus.SufficientlyHealthy;
|
85
|
-
}
|
86
|
-
}
|
87
|
-
}
|
88
|
-
|
89
|
-
export const getHealthManager = (): HealthManager =>
|
90
|
-
HealthManager.getInstance();
|