@waku/core 0.0.34-c43cec2.0 → 0.0.34-caeafce.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.
Files changed (64) hide show
  1. package/bundle/{base_protocol-DxFKDXX2.js → base_protocol-Bp5a9PNG.js} +19 -20
  2. package/bundle/{index-yLOEQnIE.js → index-G1eRBjeI.js} +115 -84
  3. package/bundle/index.js +1828 -153
  4. package/bundle/lib/base_protocol.js +2 -2
  5. package/bundle/lib/message/version_0.js +2 -2
  6. package/bundle/{version_0-Che4t3mN.js → version_0-DJZG2fB2.js} +163 -42
  7. package/dist/.tsbuildinfo +1 -1
  8. package/dist/index.d.ts +0 -1
  9. package/dist/index.js +0 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/lib/base_protocol.d.ts +2 -2
  12. package/dist/lib/base_protocol.js +2 -2
  13. package/dist/lib/base_protocol.js.map +1 -1
  14. package/dist/lib/connection_manager/connection_manager.d.ts +56 -3
  15. package/dist/lib/connection_manager/connection_manager.js +96 -13
  16. package/dist/lib/connection_manager/connection_manager.js.map +1 -1
  17. package/dist/lib/filter/filter.d.ts +18 -0
  18. package/dist/lib/filter/filter.js +209 -0
  19. package/dist/lib/filter/filter.js.map +1 -0
  20. package/dist/lib/filter/index.d.ts +1 -18
  21. package/dist/lib/filter/index.js +1 -208
  22. package/dist/lib/filter/index.js.map +1 -1
  23. package/dist/lib/light_push/index.d.ts +1 -15
  24. package/dist/lib/light_push/index.js +1 -144
  25. package/dist/lib/light_push/index.js.map +1 -1
  26. package/dist/lib/light_push/light_push.d.ts +15 -0
  27. package/dist/lib/light_push/light_push.js +144 -0
  28. package/dist/lib/light_push/light_push.js.map +1 -0
  29. package/dist/lib/light_push/utils.d.ts +0 -2
  30. package/dist/lib/light_push/utils.js +9 -17
  31. package/dist/lib/light_push/utils.js.map +1 -1
  32. package/dist/lib/metadata/index.d.ts +1 -3
  33. package/dist/lib/metadata/index.js +1 -118
  34. package/dist/lib/metadata/index.js.map +1 -1
  35. package/dist/lib/metadata/metadata.d.ts +3 -0
  36. package/dist/lib/metadata/metadata.js +119 -0
  37. package/dist/lib/metadata/metadata.js.map +1 -0
  38. package/dist/lib/store/index.d.ts +1 -9
  39. package/dist/lib/store/index.js +1 -82
  40. package/dist/lib/store/index.js.map +1 -1
  41. package/dist/lib/store/store.d.ts +9 -0
  42. package/dist/lib/store/store.js +83 -0
  43. package/dist/lib/store/store.js.map +1 -0
  44. package/dist/lib/stream_manager/stream_manager.d.ts +2 -2
  45. package/dist/lib/stream_manager/stream_manager.js +16 -17
  46. package/dist/lib/stream_manager/stream_manager.js.map +1 -1
  47. package/package.json +1 -1
  48. package/src/index.ts +0 -2
  49. package/src/lib/base_protocol.ts +3 -3
  50. package/src/lib/connection_manager/connection_manager.ts +114 -20
  51. package/src/lib/filter/filter.ts +315 -0
  52. package/src/lib/filter/index.ts +1 -315
  53. package/src/lib/light_push/index.ts +1 -189
  54. package/src/lib/light_push/light_push.ts +188 -0
  55. package/src/lib/light_push/utils.ts +13 -21
  56. package/src/lib/metadata/index.ts +1 -182
  57. package/src/lib/metadata/metadata.ts +182 -0
  58. package/src/lib/store/index.ts +1 -136
  59. package/src/lib/store/store.ts +136 -0
  60. package/src/lib/stream_manager/stream_manager.ts +16 -18
  61. package/dist/lib/health_manager.d.ts +0 -14
  62. package/dist/lib/health_manager.js +0 -70
  63. package/dist/lib/health_manager.js.map +0 -1
  64. package/src/lib/health_manager.ts +0 -90
@@ -21,39 +21,38 @@ export class StreamManager {
21
21
  this.addEventListener("peer:update", this.handlePeerUpdateStreamPool);
22
22
  }
23
23
 
24
- public async getStream(peer: Peer): Promise<Stream> {
25
- const peerId = peer.id.toString();
26
-
27
- const scheduledStream = this.streamPool.get(peerId);
24
+ public async getStream(peerId: PeerId): Promise<Stream> {
25
+ const peerIdStr = peerId.toString();
26
+ const scheduledStream = this.streamPool.get(peerIdStr);
28
27
 
29
28
  if (scheduledStream) {
30
- this.streamPool.delete(peerId);
29
+ this.streamPool.delete(peerIdStr);
31
30
  await scheduledStream;
32
31
  }
33
32
 
34
- let stream = this.getOpenStreamForCodec(peer.id);
33
+ let stream = this.getOpenStreamForCodec(peerId);
35
34
 
36
35
  if (stream) {
37
36
  this.log.info(
38
- `Found existing stream peerId=${peer.id.toString()} multicodec=${this.multicodec}`
37
+ `Found existing stream peerId=${peerIdStr} multicodec=${this.multicodec}`
39
38
  );
40
- this.lockStream(peer.id.toString(), stream);
39
+ this.lockStream(peerIdStr, stream);
41
40
  return stream;
42
41
  }
43
42
 
44
- stream = await this.createStream(peer);
45
- this.lockStream(peer.id.toString(), stream);
43
+ stream = await this.createStream(peerId);
44
+ this.lockStream(peerIdStr, stream);
46
45
 
47
46
  return stream;
48
47
  }
49
48
 
50
- private async createStream(peer: Peer, retries = 0): Promise<Stream> {
51
- const connections = this.getConnections(peer.id);
49
+ private async createStream(peerId: PeerId, retries = 0): Promise<Stream> {
50
+ const connections = this.getConnections(peerId);
52
51
  const connection = selectOpenConnection(connections);
53
52
 
54
53
  if (!connection) {
55
54
  throw new Error(
56
- `Failed to get a connection to the peer peerId=${peer.id.toString()} multicodec=${this.multicodec}`
55
+ `Failed to get a connection to the peer peerId=${peerId.toString()} multicodec=${this.multicodec}`
57
56
  );
58
57
  }
59
58
 
@@ -63,11 +62,11 @@ export class StreamManager {
63
62
  for (let i = 0; i < retries + 1; i++) {
64
63
  try {
65
64
  this.log.info(
66
- `Attempting to create a stream for peerId=${peer.id.toString()} multicodec=${this.multicodec}`
65
+ `Attempting to create a stream for peerId=${peerId.toString()} multicodec=${this.multicodec}`
67
66
  );
68
67
  stream = await connection.newStream(this.multicodec);
69
68
  this.log.info(
70
- `Created stream for peerId=${peer.id.toString()} multicodec=${this.multicodec}`
69
+ `Created stream for peerId=${peerId.toString()} multicodec=${this.multicodec}`
71
70
  );
72
71
  break;
73
72
  } catch (error) {
@@ -77,8 +76,7 @@ export class StreamManager {
77
76
 
78
77
  if (!stream) {
79
78
  throw new Error(
80
- `Failed to create a new stream for ${peer.id.toString()} -- ` +
81
- lastError
79
+ `Failed to create a new stream for ${peerId.toString()} -- ` + lastError
82
80
  );
83
81
  }
84
82
 
@@ -97,7 +95,7 @@ export class StreamManager {
97
95
 
98
96
  try {
99
97
  this.ongoingCreation.add(peerId);
100
- await this.createStream(peer);
98
+ await this.createStream(peer.id);
101
99
  } catch (error) {
102
100
  this.log.error(`Failed to createStreamWithLock:`, error);
103
101
  } finally {
@@ -1,14 +0,0 @@
1
- import { HealthStatus, type IHealthManager, type ProtocolHealth, Protocols } from "@waku/interfaces";
2
- declare class HealthManager implements IHealthManager {
3
- static instance: HealthManager;
4
- private readonly health;
5
- private constructor();
6
- static getInstance(): HealthManager;
7
- getHealthStatus(): HealthStatus;
8
- getProtocolStatus(protocol: Protocols): ProtocolHealth | undefined;
9
- updateProtocolHealth(multicodec: string, connectedPeers: number): void;
10
- private getNameFromMulticodec;
11
- private updateOverallHealth;
12
- }
13
- export declare const getHealthManager: () => HealthManager;
14
- export {};
@@ -1,70 +0,0 @@
1
- import { HealthStatus, Protocols } from "@waku/interfaces";
2
- class HealthManager {
3
- static instance;
4
- health;
5
- constructor() {
6
- this.health = {
7
- overallStatus: HealthStatus.Unhealthy,
8
- protocolStatuses: new Map()
9
- };
10
- }
11
- static getInstance() {
12
- if (!HealthManager.instance) {
13
- HealthManager.instance = new HealthManager();
14
- }
15
- return HealthManager.instance;
16
- }
17
- getHealthStatus() {
18
- return this.health.overallStatus;
19
- }
20
- getProtocolStatus(protocol) {
21
- return this.health.protocolStatuses.get(protocol);
22
- }
23
- updateProtocolHealth(multicodec, connectedPeers) {
24
- const protocol = this.getNameFromMulticodec(multicodec);
25
- let status = HealthStatus.Unhealthy;
26
- if (connectedPeers == 1) {
27
- status = HealthStatus.MinimallyHealthy;
28
- }
29
- else if (connectedPeers >= 2) {
30
- status = HealthStatus.SufficientlyHealthy;
31
- }
32
- this.health.protocolStatuses.set(protocol, {
33
- name: protocol,
34
- status: status,
35
- lastUpdate: new Date()
36
- });
37
- this.updateOverallHealth();
38
- }
39
- getNameFromMulticodec(multicodec) {
40
- let name;
41
- if (multicodec.includes("filter")) {
42
- name = Protocols.Filter;
43
- }
44
- else if (multicodec.includes("lightpush")) {
45
- name = Protocols.LightPush;
46
- }
47
- else if (multicodec.includes("store")) {
48
- name = Protocols.Store;
49
- }
50
- else {
51
- throw new Error(`Unknown protocol: ${multicodec}`);
52
- }
53
- return name;
54
- }
55
- updateOverallHealth() {
56
- const relevantProtocols = [Protocols.LightPush, Protocols.Filter];
57
- const statuses = relevantProtocols.map((p) => this.getProtocolStatus(p)?.status);
58
- if (statuses.some((status) => status === HealthStatus.Unhealthy)) {
59
- this.health.overallStatus = HealthStatus.Unhealthy;
60
- }
61
- else if (statuses.some((status) => status === HealthStatus.MinimallyHealthy)) {
62
- this.health.overallStatus = HealthStatus.MinimallyHealthy;
63
- }
64
- else {
65
- this.health.overallStatus = HealthStatus.SufficientlyHealthy;
66
- }
67
- }
68
- }
69
- export const getHealthManager = () => HealthManager.getInstance();
70
- //# sourceMappingURL=health_manager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"health_manager.js","sourceRoot":"","sources":["../../src/lib/health_manager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAIZ,SAAS,EACV,MAAM,kBAAkB,CAAC;AAE1B,MAAM,aAAa;IACV,MAAM,CAAC,QAAQ,CAAgB;IACrB,MAAM,CAAa;IAEpC;QACE,IAAI,CAAC,MAAM,GAAG;YACZ,aAAa,EAAE,YAAY,CAAC,SAAS;YACrC,gBAAgB,EAAE,IAAI,GAAG,EAAE;SAC5B,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC5B,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAChC,CAAC;I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AU,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,mBAAmB;QACzB,MAAM,iBAAiB,GAAG,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QAClE,MAAM,QAAQ,GAAG,iBAAiB,CAAC,GAAG,CACpC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,MAAM,CACzC,CAAC;QAEF,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC;YACjE,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,YAAY,CAAC,SAAS,CAAC;QACrD,CAAC;aAAM,IACL,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,YAAY,CAAC,gBAAgB,CAAC,EACnE,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,YAAY,CAAC,gBAAgB,CAAC;QAC5D,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,YAAY,CAAC,mBAAmB,CAAC;QAC/D,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAkB,EAAE,CAClD,aAAa,CAAC,WAAW,EAAE,CAAC"}
@@ -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();