@serfab/cadre-core 0.6.0 → 0.8.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.
- package/README.md +9 -8
- package/dist/authority-key.d.ts +41 -0
- package/dist/authority-key.js +52 -0
- package/dist/authority-key.js.map +1 -0
- package/dist/cadre-node.d.ts +777 -11
- package/dist/cadre-node.js +1912 -82
- package/dist/cadre-node.js.map +1 -1
- package/dist/canonical-datetime.d.ts +33 -0
- package/dist/canonical-datetime.js +38 -0
- package/dist/canonical-datetime.js.map +1 -0
- package/dist/canonical-json.d.ts +12 -0
- package/dist/canonical-json.js +33 -0
- package/dist/canonical-json.js.map +1 -0
- package/dist/control-cohort.d.ts +63 -0
- package/dist/control-cohort.js +80 -0
- package/dist/control-cohort.js.map +1 -0
- package/dist/control-database.d.ts +259 -5
- package/dist/control-database.js +541 -128
- package/dist/control-database.js.map +1 -1
- package/dist/control-formation-recorder.d.ts +89 -0
- package/dist/control-formation-recorder.js +139 -0
- package/dist/control-formation-recorder.js.map +1 -0
- package/dist/control-schema.d.ts +12 -0
- package/dist/control-schema.js +199 -0
- package/dist/control-schema.js.map +1 -0
- package/dist/control-stream.d.ts +54 -0
- package/dist/control-stream.js +104 -0
- package/dist/control-stream.js.map +1 -0
- package/dist/device-token.d.ts +50 -0
- package/dist/device-token.js +66 -0
- package/dist/device-token.js.map +1 -0
- package/dist/diagnostics/connection-path.d.ts +118 -0
- package/dist/diagnostics/connection-path.js +204 -0
- package/dist/diagnostics/connection-path.js.map +1 -0
- package/dist/diagnostics/webrtc-turn-tracker.d.ts +50 -0
- package/dist/diagnostics/webrtc-turn-tracker.js +196 -0
- package/dist/diagnostics/webrtc-turn-tracker.js.map +1 -0
- package/dist/hibernation-manager.d.ts +79 -0
- package/dist/hibernation-manager.js +173 -23
- package/dist/hibernation-manager.js.map +1 -1
- package/dist/index.d.ts +25 -4
- package/dist/index.js +59 -4
- package/dist/index.js.map +1 -1
- package/dist/key-store-file.d.ts +52 -0
- package/dist/key-store-file.js +194 -0
- package/dist/key-store-file.js.map +1 -0
- package/dist/key-store.d.ts +75 -0
- package/dist/key-store.js +66 -0
- package/dist/key-store.js.map +1 -0
- package/dist/peer-authorization.d.ts +26 -0
- package/dist/peer-authorization.js +40 -0
- package/dist/peer-authorization.js.map +1 -0
- package/dist/peer-record.d.ts +89 -0
- package/dist/peer-record.js +117 -0
- package/dist/peer-record.js.map +1 -0
- package/dist/push-credentials.d.ts +34 -0
- package/dist/push-credentials.js +81 -0
- package/dist/push-credentials.js.map +1 -0
- package/dist/push-fanout.d.ts +137 -0
- package/dist/push-fanout.js +197 -0
- package/dist/push-fanout.js.map +1 -0
- package/dist/push-notifier-apns.d.ts +53 -0
- package/dist/push-notifier-apns.js +195 -0
- package/dist/push-notifier-apns.js.map +1 -0
- package/dist/push-notifier-fcm.d.ts +38 -0
- package/dist/push-notifier-fcm.js +183 -0
- package/dist/push-notifier-fcm.js.map +1 -0
- package/dist/push-notifier-shared.d.ts +18 -0
- package/dist/push-notifier-shared.js +25 -0
- package/dist/push-notifier-shared.js.map +1 -0
- package/dist/push-notifier.d.ts +71 -0
- package/dist/push-notifier.js +50 -0
- package/dist/push-notifier.js.map +1 -0
- package/dist/schema-verification.d.ts +11 -2
- package/dist/schema-verification.js +15 -4
- package/dist/schema-verification.js.map +1 -1
- package/dist/seed-bootstrap.d.ts +210 -7
- package/dist/seed-bootstrap.js +429 -131
- package/dist/seed-bootstrap.js.map +1 -1
- package/dist/seed-trust-policy.d.ts +63 -0
- package/dist/seed-trust-policy.js +56 -0
- package/dist/seed-trust-policy.js.map +1 -0
- package/dist/strand-addr-protocol.d.ts +132 -0
- package/dist/strand-addr-protocol.js +313 -0
- package/dist/strand-addr-protocol.js.map +1 -0
- package/dist/strand-cohort.d.ts +54 -0
- package/dist/strand-cohort.js +38 -0
- package/dist/strand-cohort.js.map +1 -0
- package/dist/strand-database.d.ts +54 -6
- package/dist/strand-database.js +88 -89
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-formation-manager.d.ts +79 -19
- package/dist/strand-formation-manager.js +196 -104
- package/dist/strand-formation-manager.js.map +1 -1
- package/dist/strand-formation-protocol.d.ts +162 -0
- package/dist/strand-formation-protocol.js +279 -0
- package/dist/strand-formation-protocol.js.map +1 -0
- package/dist/strand-instance-manager.d.ts +73 -4
- package/dist/strand-instance-manager.js +167 -41
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-member-key.d.ts +29 -0
- package/dist/strand-member-key.js +38 -0
- package/dist/strand-member-key.js.map +1 -0
- package/dist/strand-member-registry.d.ts +98 -0
- package/dist/strand-member-registry.js +129 -0
- package/dist/strand-member-registry.js.map +1 -0
- package/dist/strand-membership-writer.d.ts +361 -0
- package/dist/strand-membership-writer.js +449 -0
- package/dist/strand-membership-writer.js.map +1 -0
- package/dist/strand-solicitation.d.ts +77 -2
- package/dist/strand-solicitation.js +25 -4
- package/dist/strand-solicitation.js.map +1 -1
- package/dist/strand-wake-payload.d.ts +30 -0
- package/dist/strand-wake-payload.js +20 -0
- package/dist/strand-wake-payload.js.map +1 -0
- package/dist/strand-wake-protocol.d.ts +114 -0
- package/dist/strand-wake-protocol.js +257 -0
- package/dist/strand-wake-protocol.js.map +1 -0
- package/dist/strand-watcher.d.ts +6 -2
- package/dist/strand-watcher.js +57 -17
- package/dist/strand-watcher.js.map +1 -1
- package/dist/types.d.ts +413 -23
- package/dist/types.js +22 -5
- package/dist/types.js.map +1 -1
- package/package.json +14 -8
- package/src/authority-key.ts +68 -0
- package/src/cadre-node.ts +2937 -929
- package/src/canonical-datetime.ts +39 -0
- package/src/canonical-json.ts +30 -0
- package/src/control-cohort.ts +103 -0
- package/src/control-database.ts +931 -383
- package/src/control-formation-recorder.ts +151 -0
- package/src/control-schema.ts +198 -0
- package/src/control-stream.ts +128 -0
- package/src/device-token.ts +89 -0
- package/src/diagnostics/connection-path.ts +277 -0
- package/src/diagnostics/webrtc-turn-tracker.ts +222 -0
- package/src/hibernation-manager.ts +197 -28
- package/src/index.ts +273 -79
- package/src/key-store-file.ts +203 -0
- package/src/key-store.ts +99 -0
- package/src/peer-authorization.ts +53 -0
- package/src/peer-record.ts +146 -0
- package/src/push-credentials.ts +84 -0
- package/src/push-fanout.ts +272 -0
- package/src/push-notifier-apns.ts +243 -0
- package/src/push-notifier-fcm.ts +221 -0
- package/src/push-notifier-shared.ts +28 -0
- package/src/push-notifier.ts +93 -0
- package/src/schema-verification.ts +18 -4
- package/src/seed-bootstrap.ts +504 -171
- package/src/seed-trust-policy.ts +107 -0
- package/src/strand-addr-protocol.ts +410 -0
- package/src/strand-cohort.ts +77 -0
- package/src/strand-database.ts +113 -126
- package/src/strand-formation-manager.ts +233 -142
- package/src/strand-formation-protocol.ts +391 -0
- package/src/strand-instance-manager.ts +207 -56
- package/src/strand-member-key.ts +39 -0
- package/src/strand-member-registry.ts +177 -0
- package/src/strand-membership-writer.ts +640 -0
- package/src/strand-solicitation.ts +93 -4
- package/src/strand-wake-payload.ts +32 -0
- package/src/strand-wake-protocol.ts +331 -0
- package/src/strand-watcher.ts +61 -17
- package/src/types.ts +1012 -575
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* webrtc-turn-tracker.ts — observe whether ICE selected a TURN relay candidate
|
|
3
|
+
* for each WebRTC session, so a TURN-relayed `/webrtc` connection can be
|
|
4
|
+
* reclassified `relayed`/`webrtc-turn` instead of silently counted `direct`.
|
|
5
|
+
*
|
|
6
|
+
* `@libp2p/webrtc` keeps the underlying `RTCPeerConnection` private and never
|
|
7
|
+
* surfaces it on the libp2p `Connection`, so the multiaddr classifier
|
|
8
|
+
* (`connection-path.ts`) cannot see the ICE candidate types. This tracker hooks
|
|
9
|
+
* `globalThis.RTCPeerConnection` at install time: every connection that reaches
|
|
10
|
+
* `connectionState === 'connected'` is inspected via `getStats()`, and the
|
|
11
|
+
* relay/not-relay verdict for the selected candidate pair is pushed onto a FIFO
|
|
12
|
+
* queue. {@link CadreNode} drains that queue on each `connection:open` to tag the
|
|
13
|
+
* matching peer (see {@link consume}).
|
|
14
|
+
*
|
|
15
|
+
* The correlation between a queued settlement and a `connection:open` is
|
|
16
|
+
* timing-based and best-effort — it degrades gracefully (unknown → treated as not
|
|
17
|
+
* relayed, a safe default that never produces a false `relayed`). It is inert on
|
|
18
|
+
* Node.js / any runtime with no `RTCPeerConnection`.
|
|
19
|
+
*/
|
|
20
|
+
import debug from 'debug';
|
|
21
|
+
const log = debug('sereus:cadre:turn-tracker');
|
|
22
|
+
/**
|
|
23
|
+
* Hard cap on the FIFO queue. In steady state every settlement is consumed by a
|
|
24
|
+
* `connection:open`, so the queue stays tiny; the cap only bounds a pathological
|
|
25
|
+
* leak (settlements that never get a matching consume).
|
|
26
|
+
*/
|
|
27
|
+
const MAX_QUEUE = 64;
|
|
28
|
+
export class TurnRelayTracker {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.queue = [];
|
|
31
|
+
/** One settlement record per connection; guards against repeated `connected` events. */
|
|
32
|
+
this.observed = new WeakSet();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Wrap `globalThis.RTCPeerConnection` with a subclass that records each
|
|
36
|
+
* connection's TURN-relay verdict when it settles. Idempotent. A NOP when no
|
|
37
|
+
* `RTCPeerConnection` exists (Node.js / no WebRTC polyfill) — the tracker stays
|
|
38
|
+
* inert and {@link consume} always returns `null`.
|
|
39
|
+
*/
|
|
40
|
+
install() {
|
|
41
|
+
if (this.OriginalRTCPeerConnection) {
|
|
42
|
+
return; // already installed
|
|
43
|
+
}
|
|
44
|
+
const Original = globalThis.RTCPeerConnection;
|
|
45
|
+
if (typeof Original !== 'function') {
|
|
46
|
+
log('install: no globalThis.RTCPeerConnection — tracker inert (Node.js / no polyfill)');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.OriginalRTCPeerConnection = Original;
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
51
|
+
const tracker = this;
|
|
52
|
+
class TrackedRTCPeerConnection extends Original {
|
|
53
|
+
constructor(...args) {
|
|
54
|
+
super(...args);
|
|
55
|
+
try {
|
|
56
|
+
this.addEventListener('connectionstatechange', () => {
|
|
57
|
+
try {
|
|
58
|
+
if (this.connectionState === 'connected' && !tracker.observed.has(this)) {
|
|
59
|
+
tracker.observed.add(this);
|
|
60
|
+
void tracker.recordSettlement(this);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
log('connectionstatechange handler failed: %o', error);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
log('install: failed to attach connectionstatechange listener: %o', error);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
globalThis.RTCPeerConnection = TrackedRTCPeerConnection;
|
|
74
|
+
log('install: wrapped globalThis.RTCPeerConnection');
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Pop the most recent settled entry within `windowMs` ms of now, returning its
|
|
78
|
+
* relay verdict (`true`/`false`); `null` when the queue has no matching entry.
|
|
79
|
+
* Also prunes entries older than the window (they can never match a later
|
|
80
|
+
* consume). Synchronous and safe to call from a `connection:open` handler.
|
|
81
|
+
*/
|
|
82
|
+
consume(windowMs) {
|
|
83
|
+
const now = Date.now();
|
|
84
|
+
let result = null;
|
|
85
|
+
// Walk newest → oldest; the most recent in-window settlement is the best
|
|
86
|
+
// correlation for a just-opened connection.
|
|
87
|
+
for (let i = this.queue.length - 1; i >= 0; i--) {
|
|
88
|
+
if (now - this.queue[i].settledAtMs <= windowMs) {
|
|
89
|
+
result = this.queue[i].isRelay;
|
|
90
|
+
this.queue.splice(i, 1);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
this.pruneOlderThan(now - windowMs);
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
/** Restore the original `RTCPeerConnection` and clear the queue. Idempotent. */
|
|
98
|
+
dispose() {
|
|
99
|
+
if (this.OriginalRTCPeerConnection) {
|
|
100
|
+
globalThis.RTCPeerConnection = this.OriginalRTCPeerConnection;
|
|
101
|
+
this.OriginalRTCPeerConnection = undefined;
|
|
102
|
+
}
|
|
103
|
+
this.queue.length = 0;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Inspect a settled connection's stats and queue its TURN-relay verdict. Any
|
|
107
|
+
* failure (stats API absent, rejected promise, malformed report) is caught and
|
|
108
|
+
* recorded as `isRelay: false` — the safe default (unknown → not relayed) keeps
|
|
109
|
+
* the connection counted rather than dropping it.
|
|
110
|
+
*/
|
|
111
|
+
async recordSettlement(pc) {
|
|
112
|
+
// Defaults to not-relayed (the safe "unknown" verdict); only the success path
|
|
113
|
+
// below overrides it, so a getStats failure leaves it false.
|
|
114
|
+
let isRelay = false;
|
|
115
|
+
try {
|
|
116
|
+
const report = await pc.getStats();
|
|
117
|
+
isRelay = selectedCandidatePairIsRelay(statsToMap(report));
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
log('recordSettlement: getStats failed, keeping not-relayed default: %o', error);
|
|
121
|
+
}
|
|
122
|
+
this.queue.push({ settledAtMs: Date.now(), isRelay });
|
|
123
|
+
if (this.queue.length > MAX_QUEUE) {
|
|
124
|
+
this.queue.shift();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Drop queued entries settled before `cutoffMs` (the queue is in push order). */
|
|
128
|
+
pruneOlderThan(cutoffMs) {
|
|
129
|
+
while (this.queue.length > 0 && this.queue[0].settledAtMs < cutoffMs) {
|
|
130
|
+
this.queue.shift();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** Materialise an `RTCStatsReport` into a plain map keyed by stats id. */
|
|
135
|
+
function statsToMap(report) {
|
|
136
|
+
const map = new Map();
|
|
137
|
+
report.forEach((value, key) => {
|
|
138
|
+
map.set(key, value);
|
|
139
|
+
});
|
|
140
|
+
return map;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Whether the selected ICE candidate pair used a TURN relay candidate on either
|
|
144
|
+
* end. The pair is the transport's `selectedCandidatePairId` when present, else
|
|
145
|
+
* the nominated succeeded pair, else any succeeded pair.
|
|
146
|
+
*/
|
|
147
|
+
function selectedCandidatePairIsRelay(stats) {
|
|
148
|
+
const pair = findSelectedPair(stats);
|
|
149
|
+
if (!pair) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
const local = pair.localCandidateId ? stats.get(pair.localCandidateId) : undefined;
|
|
153
|
+
const remote = pair.remoteCandidateId ? stats.get(pair.remoteCandidateId) : undefined;
|
|
154
|
+
return isRelayCandidate(local) || isRelayCandidate(remote);
|
|
155
|
+
}
|
|
156
|
+
function isRelayCandidate(stat) {
|
|
157
|
+
return stat?.type === 'local-candidate' || stat?.type === 'remote-candidate'
|
|
158
|
+
? stat.candidateType === 'relay'
|
|
159
|
+
: false;
|
|
160
|
+
}
|
|
161
|
+
function findSelectedPair(stats) {
|
|
162
|
+
const selectedId = selectedPairIdFromTransport(stats);
|
|
163
|
+
if (selectedId) {
|
|
164
|
+
const stat = stats.get(selectedId);
|
|
165
|
+
if (stat?.type === 'candidate-pair') {
|
|
166
|
+
return stat;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
let succeeded;
|
|
170
|
+
for (const stat of stats.values()) {
|
|
171
|
+
if (stat.type !== 'candidate-pair') {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const pair = stat;
|
|
175
|
+
if (pair.state !== 'succeeded') {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (pair.nominated) {
|
|
179
|
+
return pair; // nominated succeeded pair wins outright
|
|
180
|
+
}
|
|
181
|
+
succeeded ?? (succeeded = pair);
|
|
182
|
+
}
|
|
183
|
+
return succeeded;
|
|
184
|
+
}
|
|
185
|
+
function selectedPairIdFromTransport(stats) {
|
|
186
|
+
for (const stat of stats.values()) {
|
|
187
|
+
if (stat.type === 'transport') {
|
|
188
|
+
const id = stat.selectedCandidatePairId;
|
|
189
|
+
if (typeof id === 'string') {
|
|
190
|
+
return id;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=webrtc-turn-tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webrtc-turn-tracker.js","sourceRoot":"","sources":["../../src/diagnostics/webrtc-turn-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,GAAG,GAAG,KAAK,CAAC,2BAA2B,CAAC,CAAC;AAQ/C;;;;GAIG;AACH,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,MAAM,OAAO,gBAAgB;IAA7B;QACmB,UAAK,GAAsB,EAAE,CAAC;QAE/C,wFAAwF;QACvE,aAAQ,GAAG,IAAI,OAAO,EAAqB,CAAC;IAwG/D,CAAC;IAtGC;;;;;OAKG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,yBAAyB,EAAE,CAAC;YACnC,OAAO,CAAC,oBAAoB;QAC9B,CAAC;QACD,MAAM,QAAQ,GAAG,UAAU,CAAC,iBAAiB,CAAC;QAC9C,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;YACnC,GAAG,CAAC,kFAAkF,CAAC,CAAC;YACxF,OAAO;QACT,CAAC;QACD,IAAI,CAAC,yBAAyB,GAAG,QAAQ,CAAC;QAE1C,4DAA4D;QAC5D,MAAM,OAAO,GAAG,IAAI,CAAC;QACrB,MAAM,wBAAyB,SAAQ,QAAQ;YAC7C,YAAY,GAAG,IAAqD;gBAClE,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;gBACf,IAAI,CAAC;oBACH,IAAI,CAAC,gBAAgB,CAAC,uBAAuB,EAAE,GAA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ACpC,OAAO,IAAgC,CAAC;QAC1C,CAAC;IACH,CAAC;IACD,IAAI,SAA+C,CAAC;IACpD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;QAClC,IAAI,IAAI,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YACnC,SAAS;QACX,CAAC;QACD,MAAM,IAAI,GAAG,IAAgC,CAAC;QAC9C,IAAI,IAAI,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;YAC/B,SAAS;QACX,CAAC;QACD,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC,CAAC,yCAAyC;QACxD,CAAC;QACD,SAAS,KAAT,SAAS,GAAK,IAAI,EAAC;IACrB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,2BAA2B,CAAC,KAA4B;IAC/D,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;QAClC,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAC9B,MAAM,EAAE,GAAI,IAA0B,CAAC,uBAAuB,CAAC;YAC/D,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;gBAC3B,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -6,6 +6,17 @@ export interface HibernationCallbacks {
|
|
|
6
6
|
onIdle: (strandId: string) => Promise<void>;
|
|
7
7
|
onHibernate: (strandId: string) => Promise<void>;
|
|
8
8
|
onWake: (strandId: string) => Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Perform a real cohort check-in for a hibernating strand. The implementation
|
|
11
|
+
* (`CadreNode.handleStrandCheckIn`) resumes the strand, gives it a bounded
|
|
12
|
+
* window to connect to reachable cohort peers and surface pending activity,
|
|
13
|
+
* then re-hibernates if still idle. The manager AWAITS this before scheduling
|
|
14
|
+
* the next (longer-delayed) check-in, so a slow check-in never overlaps the
|
|
15
|
+
* next tick. After it resolves the manager inspects `instance.status`: a
|
|
16
|
+
* strand left non-`hibernating` is treated as woken (backoff resets on the
|
|
17
|
+
* next hibernation); a strand left `hibernating` escalates the backoff.
|
|
18
|
+
*/
|
|
19
|
+
onCheckIn: (strandId: string) => Promise<void>;
|
|
9
20
|
}
|
|
10
21
|
/**
|
|
11
22
|
* Manages strand hibernation state transitions based on activity.
|
|
@@ -20,7 +31,20 @@ export declare class HibernationManager {
|
|
|
20
31
|
private readonly config;
|
|
21
32
|
private readonly callbacks;
|
|
22
33
|
private readonly timers;
|
|
34
|
+
/**
|
|
35
|
+
* Pending check-in timers, one per hibernating strand. Unlike the old fixed
|
|
36
|
+
* `setInterval`, these are single-shot `setTimeout`s rescheduled by
|
|
37
|
+
* {@link runCheckIn} with an escalating delay — so a long-running `onCheckIn`
|
|
38
|
+
* can never overlap the next tick, and the period adapts to the backoff.
|
|
39
|
+
*/
|
|
23
40
|
private readonly checkInTimers;
|
|
41
|
+
/**
|
|
42
|
+
* In-flight wake promises keyed by strandId. Coalesces overlapping wake
|
|
43
|
+
* triggers (two near-simultaneous activities, or activity racing a force wake)
|
|
44
|
+
* so `onWake` — and the libp2p-node rebuild it drives — runs at most once per
|
|
45
|
+
* concurrent wake.
|
|
46
|
+
*/
|
|
47
|
+
private readonly wakePromises;
|
|
24
48
|
private running;
|
|
25
49
|
constructor(config: HibernationConfig, callbacks: HibernationCallbacks);
|
|
26
50
|
/**
|
|
@@ -35,6 +59,31 @@ export declare class HibernationManager {
|
|
|
35
59
|
* Stop managing hibernation
|
|
36
60
|
*/
|
|
37
61
|
stop(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Whether a strand with this instance's latency hint ever hibernates — `false`
|
|
64
|
+
* for realtime (Infinity idle timeout, see {@link HIBERNATION_TIMEOUTS}), also
|
|
65
|
+
* honouring any per-hint `customTimeouts` override. Imperative callers
|
|
66
|
+
* (`CadreNode.hibernateStrand` / `hibernateAll`) use this as the single source
|
|
67
|
+
* of truth for "skip realtime", consistent with {@link trackStrand} declining
|
|
68
|
+
* to track Infinity-timeout strands.
|
|
69
|
+
*/
|
|
70
|
+
hibernates(instance: StrandInstance): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Imperatively hibernate a tracked strand now, bypassing the idle/hibernate
|
|
73
|
+
* timers — the mobile background-entry path. Cancels the strand's pending
|
|
74
|
+
* idle/hibernate AND check-in timers so none can later re-fire `onHibernate`
|
|
75
|
+
* on the already-quiesced strand or resurrect one the caller means to keep
|
|
76
|
+
* down, then invokes `onHibernate` (quiesce + mark hibernating).
|
|
77
|
+
*
|
|
78
|
+
* Unlike the timer path ({@link handleHibernateTimeout}) it deliberately does
|
|
79
|
+
* NOT re-arm the check-in chain: a force-hibernate keeps the strand down until
|
|
80
|
+
* the caller drives the next wake on demand (push-delivered on mobile), so a
|
|
81
|
+
* stray check-in timer must not bring it back up.
|
|
82
|
+
*
|
|
83
|
+
* @returns `true` if the strand was hibernated, `false` (no-op) for a realtime
|
|
84
|
+
* strand that never hibernates.
|
|
85
|
+
*/
|
|
86
|
+
forceHibernate(instance: StrandInstance): Promise<boolean>;
|
|
38
87
|
/**
|
|
39
88
|
* Register a strand for hibernation management
|
|
40
89
|
*/
|
|
@@ -51,11 +100,41 @@ export declare class HibernationManager {
|
|
|
51
100
|
* Force wake a hibernating strand
|
|
52
101
|
*/
|
|
53
102
|
wakeStrand(strandId: string): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Begin a wake for a strand, or coalesce with one already in flight. Ensures
|
|
105
|
+
* `onWake` runs at most once per concurrent wake — the returned promise is
|
|
106
|
+
* shared by all overlapping callers and cleared once it settles. Force-wake
|
|
107
|
+
* callers await it; activity-driven callers fire-and-forget.
|
|
108
|
+
*/
|
|
109
|
+
private beginWake;
|
|
54
110
|
private scheduleIdleTransition;
|
|
55
111
|
private handleIdleTimeout;
|
|
56
112
|
private scheduleHibernateTransition;
|
|
57
113
|
private handleHibernateTimeout;
|
|
114
|
+
/**
|
|
115
|
+
* Arm the next check-in for a hibernating strand. Each call is a single-shot
|
|
116
|
+
* `setTimeout` (not a fixed `setInterval`) so the period escalates per
|
|
117
|
+
* {@link runCheckIn} and a slow `onCheckIn` never overlaps the next tick.
|
|
118
|
+
*
|
|
119
|
+
* `delay` is omitted by the chain start ({@link handleHibernateTimeout}),
|
|
120
|
+
* defaulting to the base `checkInInterval` — which is why backoff naturally
|
|
121
|
+
* resets to base each fresh hibernation cycle, with no per-strand counter to
|
|
122
|
+
* clear on wake. Subsequent ticks pass the escalated, capped delay.
|
|
123
|
+
*/
|
|
58
124
|
private scheduleCheckIn;
|
|
125
|
+
/**
|
|
126
|
+
* Run a single check-in tick: invoke `onCheckIn` (a real resume → bounded
|
|
127
|
+
* sync window → re-hibernate-if-idle cycle in `CadreNode`) and AWAIT it before
|
|
128
|
+
* deciding the next step.
|
|
129
|
+
*
|
|
130
|
+
* - If the strand woke during the check-in (`onCheckIn` left it non-
|
|
131
|
+
* `hibernating`), stop the chain — the activity path has re-armed the
|
|
132
|
+
* idle/hibernate timers, and the next hibernation restarts the chain at the
|
|
133
|
+
* base delay (backoff reset).
|
|
134
|
+
* - Otherwise escalate the delay by `checkInBackoffFactor`, capped at
|
|
135
|
+
* `checkInMaxInterval`, and reschedule.
|
|
136
|
+
*/
|
|
137
|
+
private runCheckIn;
|
|
59
138
|
private clearTimer;
|
|
60
139
|
private clearTimers;
|
|
61
140
|
/**
|
|
@@ -13,7 +13,20 @@ const log = debug('sereus:cadre:hibernation');
|
|
|
13
13
|
export class HibernationManager {
|
|
14
14
|
constructor(config, callbacks) {
|
|
15
15
|
this.timers = new Map();
|
|
16
|
+
/**
|
|
17
|
+
* Pending check-in timers, one per hibernating strand. Unlike the old fixed
|
|
18
|
+
* `setInterval`, these are single-shot `setTimeout`s rescheduled by
|
|
19
|
+
* {@link runCheckIn} with an escalating delay — so a long-running `onCheckIn`
|
|
20
|
+
* can never overlap the next tick, and the period adapts to the backoff.
|
|
21
|
+
*/
|
|
16
22
|
this.checkInTimers = new Map();
|
|
23
|
+
/**
|
|
24
|
+
* In-flight wake promises keyed by strandId. Coalesces overlapping wake
|
|
25
|
+
* triggers (two near-simultaneous activities, or activity racing a force wake)
|
|
26
|
+
* so `onWake` — and the libp2p-node rebuild it drives — runs at most once per
|
|
27
|
+
* concurrent wake.
|
|
28
|
+
*/
|
|
29
|
+
this.wakePromises = new Map();
|
|
17
30
|
this.running = false;
|
|
18
31
|
this.config = config;
|
|
19
32
|
this.callbacks = callbacks;
|
|
@@ -30,7 +43,9 @@ export class HibernationManager {
|
|
|
30
43
|
return {
|
|
31
44
|
idleTimeout: custom.idleTimeout ?? defaults.idleTimeout,
|
|
32
45
|
hibernateTimeout: custom.hibernateTimeout ?? defaults.hibernateTimeout,
|
|
33
|
-
checkInInterval: custom.checkInInterval ?? defaults.checkInInterval
|
|
46
|
+
checkInInterval: custom.checkInInterval ?? defaults.checkInInterval,
|
|
47
|
+
checkInBackoffFactor: custom.checkInBackoffFactor ?? defaults.checkInBackoffFactor,
|
|
48
|
+
checkInMaxInterval: custom.checkInMaxInterval ?? defaults.checkInMaxInterval
|
|
34
49
|
};
|
|
35
50
|
}
|
|
36
51
|
/**
|
|
@@ -55,11 +70,53 @@ export class HibernationManager {
|
|
|
55
70
|
}
|
|
56
71
|
this.timers.clear();
|
|
57
72
|
for (const timer of this.checkInTimers.values()) {
|
|
58
|
-
|
|
73
|
+
clearTimeout(timer);
|
|
59
74
|
}
|
|
60
75
|
this.checkInTimers.clear();
|
|
76
|
+
// In-flight wakes clean themselves up via their finally; drop the references
|
|
77
|
+
// so a fresh start coalesces cleanly.
|
|
78
|
+
this.wakePromises.clear();
|
|
61
79
|
log('HibernationManager stopped');
|
|
62
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Whether a strand with this instance's latency hint ever hibernates — `false`
|
|
83
|
+
* for realtime (Infinity idle timeout, see {@link HIBERNATION_TIMEOUTS}), also
|
|
84
|
+
* honouring any per-hint `customTimeouts` override. Imperative callers
|
|
85
|
+
* (`CadreNode.hibernateStrand` / `hibernateAll`) use this as the single source
|
|
86
|
+
* of truth for "skip realtime", consistent with {@link trackStrand} declining
|
|
87
|
+
* to track Infinity-timeout strands.
|
|
88
|
+
*/
|
|
89
|
+
hibernates(instance) {
|
|
90
|
+
return this.getTimeouts(instance.latencyHint).idleTimeout !== Infinity;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Imperatively hibernate a tracked strand now, bypassing the idle/hibernate
|
|
94
|
+
* timers — the mobile background-entry path. Cancels the strand's pending
|
|
95
|
+
* idle/hibernate AND check-in timers so none can later re-fire `onHibernate`
|
|
96
|
+
* on the already-quiesced strand or resurrect one the caller means to keep
|
|
97
|
+
* down, then invokes `onHibernate` (quiesce + mark hibernating).
|
|
98
|
+
*
|
|
99
|
+
* Unlike the timer path ({@link handleHibernateTimeout}) it deliberately does
|
|
100
|
+
* NOT re-arm the check-in chain: a force-hibernate keeps the strand down until
|
|
101
|
+
* the caller drives the next wake on demand (push-delivered on mobile), so a
|
|
102
|
+
* stray check-in timer must not bring it back up.
|
|
103
|
+
*
|
|
104
|
+
* @returns `true` if the strand was hibernated, `false` (no-op) for a realtime
|
|
105
|
+
* strand that never hibernates.
|
|
106
|
+
*/
|
|
107
|
+
async forceHibernate(instance) {
|
|
108
|
+
if (!this.hibernates(instance)) {
|
|
109
|
+
log('forceHibernate: strand %s is realtime; no-op', instance.strandId);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
// Cancel idle/hibernate + check-in timers BEFORE quiescing so nothing fights
|
|
113
|
+
// the imperative hibernate (a stale hibernate timer firing on the quiesced
|
|
114
|
+
// strand, or a check-in resuming a strand the caller wants kept down).
|
|
115
|
+
this.clearTimers(instance.strandId);
|
|
116
|
+
await this.callbacks.onHibernate(instance.strandId);
|
|
117
|
+
log('forceHibernate: strand %s hibernated (timers cancelled, not re-armed)', instance.strandId);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
63
120
|
/**
|
|
64
121
|
* Register a strand for hibernation management
|
|
65
122
|
*/
|
|
@@ -91,11 +148,31 @@ export class HibernationManager {
|
|
|
91
148
|
return;
|
|
92
149
|
const { strandId, status, latencyHint } = instance;
|
|
93
150
|
instance.lastActivity = new Date();
|
|
94
|
-
// If idle or hibernating, wake up
|
|
151
|
+
// If idle or hibernating, wake up. Coalesce so two near-simultaneous
|
|
152
|
+
// activities don't each fire onWake (which would rebuild two libp2p nodes).
|
|
95
153
|
if (status === 'idle' || status === 'hibernating') {
|
|
96
154
|
log('Activity on %s strand %s - waking', status, strandId);
|
|
97
155
|
this.clearTimers(strandId);
|
|
98
|
-
|
|
156
|
+
// Fire-and-forget; force-wake awaiters see errors, so swallow (and log)
|
|
157
|
+
// here to avoid an unhandled rejection on this best-effort path.
|
|
158
|
+
//
|
|
159
|
+
// Once the wake settles (CadreNode rebuilds the runtime and marks the
|
|
160
|
+
// strand `active`), re-arm the idle→hibernate→check-in cycle. Without this
|
|
161
|
+
// a strand that wakes then goes quiet stays `active` forever and never
|
|
162
|
+
// re-hibernates — so the check-in backoff could never restart at base.
|
|
163
|
+
// Guarded on `active` so a wake that did not transition (a coalesced
|
|
164
|
+
// no-op, or a still-mid-flight rebuild) never arms a stray timer.
|
|
165
|
+
void this.beginWake(strandId).then(() => {
|
|
166
|
+
if (this.running && instance.status === 'active') {
|
|
167
|
+
const timeouts = this.getTimeouts(instance.latencyHint);
|
|
168
|
+
if (timeouts.idleTimeout !== Infinity) {
|
|
169
|
+
this.scheduleIdleTransition(instance);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}).catch((err) => {
|
|
173
|
+
log('Activity-driven wake failed for strand %s: %o', strandId, err);
|
|
174
|
+
});
|
|
175
|
+
return;
|
|
99
176
|
}
|
|
100
177
|
// Reschedule idle transition if active
|
|
101
178
|
if (status === 'active') {
|
|
@@ -110,7 +187,29 @@ export class HibernationManager {
|
|
|
110
187
|
*/
|
|
111
188
|
async wakeStrand(strandId) {
|
|
112
189
|
this.clearTimers(strandId);
|
|
113
|
-
await this.
|
|
190
|
+
await this.beginWake(strandId);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Begin a wake for a strand, or coalesce with one already in flight. Ensures
|
|
194
|
+
* `onWake` runs at most once per concurrent wake — the returned promise is
|
|
195
|
+
* shared by all overlapping callers and cleared once it settles. Force-wake
|
|
196
|
+
* callers await it; activity-driven callers fire-and-forget.
|
|
197
|
+
*/
|
|
198
|
+
beginWake(strandId) {
|
|
199
|
+
const existing = this.wakePromises.get(strandId);
|
|
200
|
+
if (existing) {
|
|
201
|
+
return existing;
|
|
202
|
+
}
|
|
203
|
+
const wake = (async () => {
|
|
204
|
+
try {
|
|
205
|
+
await this.callbacks.onWake(strandId);
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
this.wakePromises.delete(strandId);
|
|
209
|
+
}
|
|
210
|
+
})();
|
|
211
|
+
this.wakePromises.set(strandId, wake);
|
|
212
|
+
return wake;
|
|
114
213
|
}
|
|
115
214
|
scheduleIdleTransition(instance) {
|
|
116
215
|
const { strandId, latencyHint } = instance;
|
|
@@ -128,13 +227,16 @@ export class HibernationManager {
|
|
|
128
227
|
if (!this.running)
|
|
129
228
|
return;
|
|
130
229
|
log('Idle timeout for strand %s', strandId);
|
|
131
|
-
// Transition to idle
|
|
230
|
+
// Transition to idle. The callback can reject (e.g. a future idle handler
|
|
231
|
+
// that releases resources); catch so the timer chain never unhandled-rejects.
|
|
132
232
|
void this.callbacks.onIdle(strandId).then(() => {
|
|
133
233
|
// Schedule hibernate transition
|
|
134
234
|
const timeouts = this.getTimeouts(latencyHint);
|
|
135
235
|
if (timeouts.hibernateTimeout !== Infinity) {
|
|
136
236
|
this.scheduleHibernateTransition(instance);
|
|
137
237
|
}
|
|
238
|
+
}).catch((err) => {
|
|
239
|
+
log('onIdle failed for strand %s: %o', strandId, err);
|
|
138
240
|
});
|
|
139
241
|
}
|
|
140
242
|
scheduleHibernateTransition(instance) {
|
|
@@ -153,36 +255,84 @@ export class HibernationManager {
|
|
|
153
255
|
if (!this.running)
|
|
154
256
|
return;
|
|
155
257
|
log('Hibernate timeout for strand %s', strandId);
|
|
156
|
-
// Transition to hibernating
|
|
258
|
+
// Transition to hibernating. onHibernate now releases strand-network
|
|
259
|
+
// resources (quiesce), so its close()/stop() can reject — catch so a failed
|
|
260
|
+
// hibernate logs instead of producing an unhandled rejection.
|
|
157
261
|
void this.callbacks.onHibernate(strandId).then(() => {
|
|
158
262
|
// Schedule periodic check-ins
|
|
159
263
|
const timeouts = this.getTimeouts(latencyHint);
|
|
160
264
|
if (timeouts.checkInInterval !== Infinity) {
|
|
161
265
|
this.scheduleCheckIn(instance);
|
|
162
266
|
}
|
|
267
|
+
}).catch((err) => {
|
|
268
|
+
log('onHibernate failed for strand %s: %o', strandId, err);
|
|
163
269
|
});
|
|
164
270
|
}
|
|
165
|
-
|
|
271
|
+
/**
|
|
272
|
+
* Arm the next check-in for a hibernating strand. Each call is a single-shot
|
|
273
|
+
* `setTimeout` (not a fixed `setInterval`) so the period escalates per
|
|
274
|
+
* {@link runCheckIn} and a slow `onCheckIn` never overlaps the next tick.
|
|
275
|
+
*
|
|
276
|
+
* `delay` is omitted by the chain start ({@link handleHibernateTimeout}),
|
|
277
|
+
* defaulting to the base `checkInInterval` — which is why backoff naturally
|
|
278
|
+
* resets to base each fresh hibernation cycle, with no per-strand counter to
|
|
279
|
+
* clear on wake. Subsequent ticks pass the escalated, capped delay.
|
|
280
|
+
*/
|
|
281
|
+
scheduleCheckIn(instance, delay) {
|
|
166
282
|
const { strandId, latencyHint } = instance;
|
|
167
283
|
const timeouts = this.getTimeouts(latencyHint);
|
|
168
|
-
|
|
284
|
+
const currentDelay = delay ?? timeouts.checkInInterval;
|
|
285
|
+
// Replace any existing check-in timer (no-op if the firing timer rescheduled us).
|
|
169
286
|
const existing = this.checkInTimers.get(strandId);
|
|
170
287
|
if (existing) {
|
|
171
|
-
|
|
288
|
+
clearTimeout(existing);
|
|
172
289
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
clearInterval(timer);
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
log('Check-in for hibernating strand %s', strandId);
|
|
180
|
-
instance.nextCheckIn = new Date(Date.now() + timeouts.checkInInterval);
|
|
181
|
-
// In a real implementation, this would query the cohort for pending activity
|
|
182
|
-
// For now, we just update the nextCheckIn timestamp
|
|
183
|
-
}, timeouts.checkInInterval);
|
|
290
|
+
const timer = setTimeout(() => {
|
|
291
|
+
void this.runCheckIn(instance, currentDelay);
|
|
292
|
+
}, currentDelay);
|
|
184
293
|
this.checkInTimers.set(strandId, timer);
|
|
185
|
-
instance.nextCheckIn = new Date(Date.now() +
|
|
294
|
+
instance.nextCheckIn = new Date(Date.now() + currentDelay);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Run a single check-in tick: invoke `onCheckIn` (a real resume → bounded
|
|
298
|
+
* sync window → re-hibernate-if-idle cycle in `CadreNode`) and AWAIT it before
|
|
299
|
+
* deciding the next step.
|
|
300
|
+
*
|
|
301
|
+
* - If the strand woke during the check-in (`onCheckIn` left it non-
|
|
302
|
+
* `hibernating`), stop the chain — the activity path has re-armed the
|
|
303
|
+
* idle/hibernate timers, and the next hibernation restarts the chain at the
|
|
304
|
+
* base delay (backoff reset).
|
|
305
|
+
* - Otherwise escalate the delay by `checkInBackoffFactor`, capped at
|
|
306
|
+
* `checkInMaxInterval`, and reschedule.
|
|
307
|
+
*/
|
|
308
|
+
async runCheckIn(instance, currentDelay) {
|
|
309
|
+
const { strandId, latencyHint } = instance;
|
|
310
|
+
if (!this.running)
|
|
311
|
+
return;
|
|
312
|
+
log('Check-in for hibernating strand %s (delay=%dms)', strandId, currentDelay);
|
|
313
|
+
try {
|
|
314
|
+
await this.callbacks.onCheckIn(strandId);
|
|
315
|
+
}
|
|
316
|
+
catch (err) {
|
|
317
|
+
// A failed check-in (e.g. resume threw) must not break the chain — log and
|
|
318
|
+
// fall through to reschedule the next, longer-delayed attempt.
|
|
319
|
+
log('onCheckIn failed for strand %s: %o', strandId, err);
|
|
320
|
+
}
|
|
321
|
+
if (!this.running)
|
|
322
|
+
return;
|
|
323
|
+
// The check-in either woke the strand (CadreNode left it active) or left it
|
|
324
|
+
// hibernating. Inspect the shared instance the callback just mutated.
|
|
325
|
+
if (instance.status !== 'hibernating') {
|
|
326
|
+
log('Check-in woke strand %s; backoff resets on next hibernation', strandId);
|
|
327
|
+
this.checkInTimers.delete(strandId);
|
|
328
|
+
// The chain is stopping; drop the now-stale next-check-in advertisement so
|
|
329
|
+
// `getStrand` doesn't report a phantom check-in for a strand that is awake.
|
|
330
|
+
instance.nextCheckIn = undefined;
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const timeouts = this.getTimeouts(latencyHint);
|
|
334
|
+
const nextDelay = Math.min(currentDelay * timeouts.checkInBackoffFactor, timeouts.checkInMaxInterval);
|
|
335
|
+
this.scheduleCheckIn(instance, nextDelay);
|
|
186
336
|
}
|
|
187
337
|
clearTimer(strandId) {
|
|
188
338
|
const timer = this.timers.get(strandId);
|
|
@@ -195,7 +345,7 @@ export class HibernationManager {
|
|
|
195
345
|
this.clearTimer(strandId);
|
|
196
346
|
const checkInTimer = this.checkInTimers.get(strandId);
|
|
197
347
|
if (checkInTimer) {
|
|
198
|
-
|
|
348
|
+
clearTimeout(checkInTimer);
|
|
199
349
|
this.checkInTimers.delete(strandId);
|
|
200
350
|
}
|
|
201
351
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hibernation-manager.js","sourceRoot":"","sources":["../src/hibernation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,GAAG,GAAG,KAAK,CAAC,0BAA0B,CAAC,CAA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