wire-mesh-core 4.1.5 → 4.2.1

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 (54) hide show
  1. package/README.md +2 -1
  2. package/dist/adapters/tls-transport.cjs +2 -0
  3. package/dist/adapters/tls-transport.mjs +2 -0
  4. package/dist/domain/async-queue.cjs +48 -12
  5. package/dist/domain/async-queue.d.cts +1 -1
  6. package/dist/domain/async-queue.d.mts +1 -1
  7. package/dist/domain/async-queue.mjs +48 -12
  8. package/dist/domain/bulk.cjs +50 -10
  9. package/dist/domain/bulk.d.cts +5 -1
  10. package/dist/domain/bulk.d.mts +5 -1
  11. package/dist/domain/bulk.mjs +50 -11
  12. package/dist/domain/capability-grant.d.cts +1 -1
  13. package/dist/domain/capability-grant.d.mts +1 -1
  14. package/dist/domain/capability-request.cjs +2 -5
  15. package/dist/domain/capability-request.d.cts +1 -1
  16. package/dist/domain/capability-request.d.mts +1 -1
  17. package/dist/domain/capability-request.mjs +1 -4
  18. package/dist/domain/consume-incoming.cjs +96 -0
  19. package/dist/domain/consume-incoming.d.cts +27 -0
  20. package/dist/domain/consume-incoming.d.mts +27 -0
  21. package/dist/domain/consume-incoming.mjs +93 -0
  22. package/dist/domain/direct-manage-request.cjs +25 -12
  23. package/dist/domain/direct-manage-request.d.cts +1 -1
  24. package/dist/domain/direct-manage-request.d.mts +1 -1
  25. package/dist/domain/direct-manage-request.mjs +25 -12
  26. package/dist/domain/fault-report.cjs +136 -0
  27. package/dist/domain/fault-report.d.cts +25 -0
  28. package/dist/domain/fault-report.d.mts +25 -0
  29. package/dist/domain/fault-report.mjs +129 -0
  30. package/dist/domain/gossip-expansion.cjs +1 -1
  31. package/dist/domain/gossip-expansion.d.cts +1 -1
  32. package/dist/domain/gossip-expansion.d.mts +1 -1
  33. package/dist/domain/gossip-expansion.mjs +1 -1
  34. package/dist/domain/grant-candidates.d.cts +1 -1
  35. package/dist/domain/grant-candidates.d.mts +1 -1
  36. package/dist/domain/mesh-session.cjs +373 -126
  37. package/dist/domain/mesh-session.d.cts +2 -162
  38. package/dist/domain/mesh-session.d.mts +2 -162
  39. package/dist/domain/mesh-session.mjs +373 -126
  40. package/dist/domain/path-trace.d.cts +1 -1
  41. package/dist/domain/path-trace.d.mts +1 -1
  42. package/dist/domain/ping-round-trips.cjs +21 -8
  43. package/dist/domain/ping-round-trips.mjs +21 -8
  44. package/dist/domain/room-rekey.d.cts +1 -1
  45. package/dist/domain/room-rekey.d.mts +1 -1
  46. package/dist/domain/topology.d.cts +1 -1
  47. package/dist/domain/topology.d.mts +1 -1
  48. package/dist/domain/webrtc-signaling.d.cts +1 -1
  49. package/dist/domain/webrtc-signaling.d.mts +1 -1
  50. package/dist/mesh-session-By06Mnu-.d.cts +174 -0
  51. package/dist/mesh-session-DzcZYdhe.d.mts +174 -0
  52. package/dist/timers-DTJNuBa8.cjs +12 -0
  53. package/dist/timers-Q1_kDTyY.mjs +7 -0
  54. package/package.json +11 -2
@@ -0,0 +1,129 @@
1
+ import { t as unrefIfSupported } from "../timers-Q1_kDTyY.mjs";
2
+ //#region src/domain/fault-report.ts
3
+ /** The shortest time between two reports for one source. */
4
+ const FAULT_REPORT_INTERVAL_MS = 1e3;
5
+ /** The most sources whose report windows are kept at once; past it the oldest window goes, its pending count delivered first if the budget allows. */
6
+ const MAX_TRACKED_FAULT_SOURCES = 1024;
7
+ /** The most reports delivered across all sources in one interval. A source beyond it is counted like one inside its own interval, so the total is bounded however many distinct sources a peer presents. */
8
+ const MAX_FAULT_REPORTS_PER_INTERVAL = 64;
9
+ /** The most characters of a fault's text that a log line or console report carries, since the text can come from what a peer sent. */
10
+ const MAX_FAULT_TEXT_CHARS = 256;
11
+ /** A fault as one bounded, quoted line of text: control characters are escaped, so it cannot start a new line, and it is cut to MAX_FAULT_TEXT_CHARS. */
12
+ function describeFault(error) {
13
+ return JSON.stringify(String(error).slice(0, 256));
14
+ }
15
+ /** Runs `deliver` so that nothing it does reaches the caller: a throw, or a returned promise that rejects, is reported once to the console and dropped. */
16
+ function deliverContained(deliver, suppressed) {
17
+ const report = (error) => {
18
+ console.error(`the fault callback failed: ${describeFault(error)}`);
19
+ };
20
+ try {
21
+ const result = deliver(suppressed);
22
+ if (typeof result === "object" && result !== null && "then" in result && typeof result.then === "function") Promise.resolve(result).catch(report);
23
+ } catch (error) {
24
+ report(error);
25
+ }
26
+ }
27
+ /** A clock that never steps backwards, which the interval arithmetic relies on. */
28
+ function monotonicNow() {
29
+ return performance.now();
30
+ }
31
+ /**
32
+ * Builds a reporter that delivers a source's first fault at once and then at most one more per FAULT_REPORT_INTERVAL_MS, with at most MAX_FAULT_REPORTS_PER_INTERVAL reports across all sources. A fault inside a source's interval is counted, and the most recent one is delivered when the interval ends, carrying the count of the others; a source that falls quiet is therefore still told. Each report's `suppressed` counts the faults of its source that were not reported before it, not the one it carries.
33
+ *
34
+ * A source forgotten to keep the number of tracked sources bounded loses nothing silently: the faults it still had pending are added to the count the next delivered report carries, from whichever source.
35
+ *
36
+ * `now` is the clock the intervals are read from; it must not step backwards.
37
+ */
38
+ function createFaultReporter(now = monotonicNow) {
39
+ const windows = /* @__PURE__ */ new Map();
40
+ const budget = {
41
+ since: Number.NEGATIVE_INFINITY,
42
+ used: 0
43
+ };
44
+ const forgotten = { count: 0 };
45
+ /** Takes one report from the interval's budget, if it has one left. */
46
+ function admit(at) {
47
+ if (at - budget.since >= 1e3) {
48
+ budget.since = at;
49
+ budget.used = 0;
50
+ }
51
+ if (budget.used >= 64) return false;
52
+ budget.used += 1;
53
+ return true;
54
+ }
55
+ /** What a delivered report adds for faults of sources that were forgotten, which it takes over. */
56
+ function takeForgotten() {
57
+ const count = forgotten.count;
58
+ forgotten.count = 0;
59
+ return count;
60
+ }
61
+ function arm(source) {
62
+ const window = windows.get(source);
63
+ if (window === void 0 || window.timer !== void 0) return;
64
+ const delay = Math.max(0, window.since + FAULT_REPORT_INTERVAL_MS - now());
65
+ const timer = setTimeout(() => {
66
+ flush(source);
67
+ }, delay);
68
+ unrefIfSupported(timer);
69
+ window.timer = timer;
70
+ }
71
+ /** Delivers a window's most recent pending fault at the end of its interval, or waits for the next interval when the budget is spent. */
72
+ function flush(source) {
73
+ const window = windows.get(source);
74
+ if (window === void 0) return;
75
+ window.timer = void 0;
76
+ const { latest } = window;
77
+ if (window.pending === 0 || latest === void 0) return;
78
+ const at = now();
79
+ window.since = at;
80
+ if (!admit(at)) {
81
+ arm(source);
82
+ return;
83
+ }
84
+ const others = window.pending - 1;
85
+ window.pending = 0;
86
+ window.latest = void 0;
87
+ deliverContained(latest, others + takeForgotten());
88
+ }
89
+ function forgetOldest() {
90
+ const oldest = windows.entries().next();
91
+ if (oldest.done === true) return;
92
+ const [source, window] = oldest.value;
93
+ clearTimeout(window.timer);
94
+ windows.delete(source);
95
+ forgotten.count += window.pending;
96
+ }
97
+ return (source, deliver) => {
98
+ const at = now();
99
+ const window = windows.get(source);
100
+ if (window !== void 0 && at - window.since < 1e3) {
101
+ window.pending += 1;
102
+ window.latest = deliver;
103
+ arm(source);
104
+ return;
105
+ }
106
+ const carried = window?.pending ?? 0;
107
+ clearTimeout(window?.timer);
108
+ windows.delete(source);
109
+ const next = {
110
+ since: at,
111
+ pending: carried,
112
+ latest: window?.latest,
113
+ timer: void 0
114
+ };
115
+ windows.set(source, next);
116
+ if (windows.size > 1024) forgetOldest();
117
+ if (!admit(at)) {
118
+ next.pending += 1;
119
+ next.latest = deliver;
120
+ arm(source);
121
+ return;
122
+ }
123
+ next.pending = 0;
124
+ next.latest = void 0;
125
+ deliverContained(deliver, carried + takeForgotten());
126
+ };
127
+ }
128
+ //#endregion
129
+ export { FAULT_REPORT_INTERVAL_MS, MAX_FAULT_REPORTS_PER_INTERVAL, MAX_FAULT_TEXT_CHARS, MAX_TRACKED_FAULT_SOURCES, createFaultReporter, deliverContained, describeFault };
@@ -43,7 +43,7 @@ function createGossipExpansion(options) {
43
43
  expand({
44
44
  device: advert.device,
45
45
  addresses: advert.addresses
46
- });
46
+ }).catch(() => void 0);
47
47
  } };
48
48
  }
49
49
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { D as DeviceId, et as PeerAdvert } from "../protocol-Cb3BnuTL.cjs";
2
- import { MeshSession } from "./mesh-session.cjs";
2
+ import { p as MeshSession } from "../mesh-session-By06Mnu-.cjs";
3
3
  //#region src/domain/gossip-expansion.d.ts
4
4
  /** One not-yet-considered device this session's gossip directory has surfaced, carrying only what a dial/trust decision needs: the device-id to decide identity, and the "host:port" addresses its own peer-advert claims are directly reachable at, in the order it advertised them. */
5
5
  export interface GossipExpansionCandidate {
@@ -1,5 +1,5 @@
1
1
  import { D as DeviceId, et as PeerAdvert } from "../protocol-Cb3BnuTL.mjs";
2
- import { MeshSession } from "./mesh-session.mjs";
2
+ import { p as MeshSession } from "../mesh-session-DzcZYdhe.mjs";
3
3
  //#region src/domain/gossip-expansion.d.ts
4
4
  /** One not-yet-considered device this session's gossip directory has surfaced, carrying only what a dial/trust decision needs: the device-id to decide identity, and the "host:port" addresses its own peer-advert claims are directly reachable at, in the order it advertised them. */
5
5
  export interface GossipExpansionCandidate {
@@ -42,7 +42,7 @@ function createGossipExpansion(options) {
42
42
  expand({
43
43
  device: advert.device,
44
44
  addresses: advert.addresses
45
- });
45
+ }).catch(() => void 0);
46
46
  } };
47
47
  }
48
48
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { D as DeviceId, f as CapabilityScope } from "../protocol-Cb3BnuTL.cjs";
2
- import { DirectoryEntry, MeshSession } from "./mesh-session.cjs";
2
+ import { a as DirectoryEntry, p as MeshSession } from "../mesh-session-By06Mnu-.cjs";
3
3
  import { z } from "zod";
4
4
  //#region src/domain/grant-candidates.d.ts
5
5
  declare const grantCandidateSchema: z.ZodObject<{
@@ -1,5 +1,5 @@
1
1
  import { D as DeviceId, f as CapabilityScope } from "../protocol-Cb3BnuTL.mjs";
2
- import { DirectoryEntry, MeshSession } from "./mesh-session.mjs";
2
+ import { a as DirectoryEntry, p as MeshSession } from "../mesh-session-DzcZYdhe.mjs";
3
3
  import { z } from "zod";
4
4
  //#region src/domain/grant-candidates.d.ts
5
5
  declare const grantCandidateSchema: z.ZodObject<{