indigo-matter-bridge 0.5.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.
@@ -0,0 +1,433 @@
1
+ /**
2
+ * The persisted `UniqueID → endpoint number` map, and the drift detector built
3
+ * on it (PRD §4.3, BRIDGE_PROTOCOL §4.3/§3.10/§3.11).
4
+ *
5
+ * **Why this file exists at all.** matter.js persists endpoint numbers itself,
6
+ * keyed on the string `Endpoint.id`, and that is what actually holds identity
7
+ * together across a restart. This map does not allocate anything: it is the
8
+ * independent *witness* of what those numbers were last time, so that the one
9
+ * failure that silently duplicates every accessory in every paired ecosystem —
10
+ * matter.js's storage being lost, moved or reset underneath us — becomes a
11
+ * statement in the log instead of a mystery in someone's Home app. That is
12
+ * matterbridge's `checkEndpointNumbers()` pattern, and PRD §4.3 adopts it for
13
+ * the same reason: it is the only way to make "is it us or the controller?"
14
+ * falsifiable in the field.
15
+ *
16
+ * **It lives outside matter.js's storage context on purpose.** §3.10's factory
17
+ * reset wipes that context; a witness stored inside it would be wiped by the
18
+ * very event it exists to survive, so this file sits beside `identity.json` in
19
+ * the bridge storage dir root and is written through the same atomic write.
20
+ *
21
+ * **Drift is reported, never repaired.** §4.3 is explicit, and the reasoning is
22
+ * asymmetric: a wrong report costs a log line, while an auto-repair that pinned
23
+ * the "right" number would hide the storage loss that caused it and make the
24
+ * next occurrence invisible too. Nothing here mutates a drifted entry — the
25
+ * baseline stays, so the drift keeps being reported until a human resolves it
26
+ * with §3.11.
27
+ *
28
+ * Stdlib only — no matter.js import — which is what lets the whole detector be
29
+ * tested without a Matter stack. Callers hand in `{uniqueId, endpointNumber}`
30
+ * pairs; deriving `uniqueId` from an Indigo device id is `endpoints.ts`'s job.
31
+ */
32
+ import { copyFileSync, readFileSync, unlinkSync } from "node:fs";
33
+ import { join } from "node:path";
34
+ import { describeError, RefuseReason } from "./protocol.js";
35
+ import { writeJsonAtomic } from "./storage.js";
36
+ /**
37
+ * The PRD §7 refuse-to-start decision, as one pure function.
38
+ *
39
+ * Endpoint numbers only matter to somebody who is *paired*, and that asymmetry
40
+ * is the whole rule: on a bridge nothing has ever commissioned, a missing or
41
+ * unreadable map costs precisely nothing, so a fresh install must never be
42
+ * blocked by one. Two conditions remain fatal once a fabric has existed:
43
+ *
44
+ * * **a map that is there and cannot be read** — the numbers being served
45
+ * cannot be checked against a baseline we know exists, and silently
46
+ * re-recording them would bless whatever matter.js happens to hand out this
47
+ * boot as the truth over a file that says something else;
48
+ * * **the witness but no fabrics** — PRD §7's "storage missing but previously
49
+ * commissioned". matter.js's storage has gone, and its own `Endpoint.id →
50
+ * number` allocation went with it, so every accessory is about to be
51
+ * re-created in every ecosystem the user paired.
52
+ *
53
+ * **A commissioned bridge with no map at all is NOT one of them, and the first
54
+ * cut of E5 had that wrong.** Every bridge commissioned before E5 shipped is in
55
+ * exactly that state — fabrics, endpoints, no `endpoint-map.json`, because the
56
+ * file did not exist yet — so refusing would have taken every already-working
57
+ * export offline on upgrade. And the refusal buys nothing even in principle:
58
+ * **matter.js owns the numbers**, keyed on `Endpoint.id` in its own store, and
59
+ * this map is only the independent witness of what they were. A missing witness
60
+ * renumbers precisely nothing; it means we cannot yet *check*, which is what
61
+ * bootstrapping a baseline fixes and what refusing does not. The one thing a
62
+ * missing map must never do is silently paper over a *present* one, which is
63
+ * why `mapProblem` still refuses.
64
+ *
65
+ * Returns the reason to refuse, or `undefined` to serve normally.
66
+ */
67
+ export function refuseReasonFor(state) {
68
+ if (state.commissioned) {
69
+ return state.mapProblem === undefined ? undefined : RefuseReason.mapUnreadable;
70
+ }
71
+ return state.commissionedAt === undefined ? undefined : RefuseReason.fabricStorageLost;
72
+ }
73
+ /** Sibling of `identity.json` in the bridge storage dir. */
74
+ export const ENDPOINT_MAP_FILE = "endpoint-map.json";
75
+ /** Schema version of the persisted file. Bump only on an incompatible change. */
76
+ export const ENDPOINT_MAP_VERSION = 1;
77
+ /** Stable keys so a repeated failure replaces its warning rather than stacking. */
78
+ const WARN_PERSIST = "endpoint-map-persist";
79
+ const WARN_DELETE = "endpoint-map-delete";
80
+ function isEndpointMapFile(value) {
81
+ if (typeof value !== "object" || value === null) {
82
+ return false;
83
+ }
84
+ const candidate = value;
85
+ if (candidate.version !== ENDPOINT_MAP_VERSION) {
86
+ return false;
87
+ }
88
+ const { endpoints } = candidate;
89
+ if (typeof endpoints !== "object" || endpoints === null || Array.isArray(endpoints)) {
90
+ return false;
91
+ }
92
+ return Object.values(endpoints).every(number => typeof number === "number" && Number.isInteger(number) && number >= 0);
93
+ }
94
+ function isNotFound(error) {
95
+ return error?.code === "ENOENT";
96
+ }
97
+ /** Read `endpoint-map.json`. Never throws — the caller decides what a fault means. */
98
+ export function loadEndpointMap(storagePath) {
99
+ const file = join(storagePath, ENDPOINT_MAP_FILE);
100
+ try {
101
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
102
+ if (!isEndpointMapFile(parsed)) {
103
+ return {
104
+ numbers: new Map(),
105
+ present: true,
106
+ problem: `${file} is not a version ${ENDPOINT_MAP_VERSION} endpoint map`,
107
+ };
108
+ }
109
+ return { numbers: new Map(Object.entries(parsed.endpoints)), present: true };
110
+ }
111
+ catch (error) {
112
+ if (isNotFound(error)) {
113
+ return { numbers: new Map(), present: false };
114
+ }
115
+ return {
116
+ numbers: new Map(),
117
+ present: true,
118
+ problem: `${file} is unreadable (${describeError(error)})`,
119
+ };
120
+ }
121
+ }
122
+ /** Delete `endpoint-map.json`. Returns whether a file was actually removed. */
123
+ export function deleteEndpointMap(storagePath) {
124
+ try {
125
+ unlinkSync(join(storagePath, ENDPOINT_MAP_FILE));
126
+ return true;
127
+ }
128
+ catch (error) {
129
+ if (isNotFound(error)) {
130
+ return false;
131
+ }
132
+ throw error;
133
+ }
134
+ }
135
+ /**
136
+ * The map plus the operations §3.10/§3.11 and the drift detector need.
137
+ *
138
+ * One instance per node, constructed at startup and {@link load}ed before the
139
+ * Matter stack comes up, because whether the file is readable is what decides
140
+ * if the node serves endpoints at all.
141
+ */
142
+ export class EndpointMapStore {
143
+ storagePath;
144
+ log;
145
+ now;
146
+ #numbers = new Map();
147
+ #present = false;
148
+ #problem;
149
+ #checked = false;
150
+ /**
151
+ * True when the in-memory map holds something the disk does not.
152
+ *
153
+ * Set by a failed {@link persist}, cleared by a successful one. It is what
154
+ * stops {@link checked} claiming an all-clear over a baseline that exists
155
+ * only in RAM: a `driftChecked: true` there asserts that the numbers were
156
+ * verified against something durable, and the next restart would find no
157
+ * such thing, adopt whatever matter.js reallocates as the new truth, and
158
+ * report a permanently clean bridge across a real renumbering.
159
+ */
160
+ #dirty = false;
161
+ /** Persistence failures worth putting in `StatusReport.warnings` (§4.3). */
162
+ #warnings = new Map();
163
+ /**
164
+ * True once the file {@link load} found unusable has been copied aside.
165
+ *
166
+ * Both {@link rebuild} and {@link persist} quarantine before overwriting,
167
+ * and without this the two would each take a copy of the same bytes — which
168
+ * is worse than it sounds now that the copies are timestamped, because
169
+ * every one of them is a file a human has to look at and decide about.
170
+ */
171
+ #quarantined = false;
172
+ constructor(storagePath, log = () => { },
173
+ /** Injectable so the timestamped quarantine name is testable. */
174
+ now = () => new Date()) {
175
+ this.storagePath = storagePath;
176
+ this.log = log;
177
+ this.now = now;
178
+ }
179
+ /** Read the file into memory. Idempotent; the last read wins. */
180
+ load() {
181
+ const loaded = loadEndpointMap(this.storagePath);
182
+ this.#numbers = loaded.numbers;
183
+ this.#present = loaded.present;
184
+ this.#problem = loaded.problem;
185
+ this.#checked = false;
186
+ this.#dirty = false;
187
+ this.#quarantined = false;
188
+ this.#warnings.clear();
189
+ if (loaded.problem !== undefined) {
190
+ this.log(`Endpoint map unusable: ${loaded.problem}`);
191
+ }
192
+ else if (!loaded.present) {
193
+ this.log("No endpoint map yet; the first reconcile will record one");
194
+ }
195
+ else {
196
+ this.log(`Loaded endpoint map: ${loaded.numbers.size} endpoint number(s)`);
197
+ }
198
+ return loaded;
199
+ }
200
+ /** True once a file has been read or written — i.e. there is a baseline. */
201
+ get present() {
202
+ return this.#present && this.#problem === undefined;
203
+ }
204
+ /** Why the present file cannot be used, if it cannot. */
205
+ get problem() {
206
+ return this.#problem;
207
+ }
208
+ /**
209
+ * §4.3 `driftChecked` — whether an empty `drift` is an answer or an absence.
210
+ *
211
+ * False until {@link check} has actually run against a baseline. The two
212
+ * readings of `drift: []` are opposites ("checked, nothing moved" versus
213
+ * "there is nothing to check against yet"), and a client that cannot tell
214
+ * them apart reads a fresh install's silence as an all-clear.
215
+ */
216
+ get checked() {
217
+ return this.#checked && !this.#dirty;
218
+ }
219
+ /**
220
+ * §4.3 `warnings` — the persistence failures a client has to be told about.
221
+ *
222
+ * The node's log is stdout, and in this milestone the node is started **by
223
+ * hand**, so stdout is a terminal somebody closed. A map that cannot be
224
+ * written is exactly the fault this file exists to make visible, and it
225
+ * would otherwise be visible only there. `get_status` is polled, so this is
226
+ * the channel that actually reaches a user.
227
+ */
228
+ get warnings() {
229
+ return [...this.#warnings.values()];
230
+ }
231
+ /** The recorded number for a `UniqueID`, if there is one. */
232
+ numberFor(uniqueId) {
233
+ return this.#numbers.get(uniqueId);
234
+ }
235
+ get size() {
236
+ return this.#numbers.size;
237
+ }
238
+ /**
239
+ * Compare the live endpoint numbers against the map (PRD §4.3).
240
+ *
241
+ * Endpoints the map has never seen are *recorded*; endpoints whose number
242
+ * has moved are *reported* and left alone. Persisting only happens when
243
+ * something was actually added, so a steady state costs no disk write per
244
+ * reconcile.
245
+ *
246
+ * A device that is not currently live is not touched either way: §3.3
247
+ * retains the allocation so re-adding the same device restores the same
248
+ * number, and forgetting it here would throw away the very baseline that
249
+ * makes a re-add verifiable.
250
+ */
251
+ check(live) {
252
+ const drift = [];
253
+ let added = 0;
254
+ for (const { uniqueId, endpointNumber } of live) {
255
+ const expected = this.#numbers.get(uniqueId);
256
+ if (expected === undefined) {
257
+ this.#numbers.set(uniqueId, endpointNumber);
258
+ added += 1;
259
+ continue;
260
+ }
261
+ if (expected !== endpointNumber) {
262
+ drift.push({ uniqueId, expected, actual: endpointNumber });
263
+ }
264
+ }
265
+ // `#dirty` is the retry: a write that failed last time leaves the map
266
+ // owing the disk something even when this pass added nothing, and the
267
+ // steady state (`added === 0`, clean) still costs no I/O. Without it a
268
+ // full disk at the moment of the first check would never be revisited,
269
+ // and `checked` — see the `#dirty` field — would never come true again.
270
+ if (added > 0 || this.#dirty) {
271
+ this.persist(added > 0 ? `recorded ${added} new endpoint number(s)` : "retried after a failed write");
272
+ }
273
+ // An empty comparison compared nothing, so it cannot make `driftChecked`
274
+ // true — the same rule {@link seed} already applies. §4.3 says
275
+ // `driftChecked: true` means "checked, nothing moved", and a `check([])`
276
+ // (a reconcile that removed the last endpoint, a remove on a node that
277
+ // never attached) would otherwise turn "there was nothing to look at"
278
+ // into an all-clear. It only ever raises the flag: a real comparison
279
+ // that has already happened is not un-done by a later empty one.
280
+ if (live.length > 0) {
281
+ this.#checked = true;
282
+ }
283
+ return drift;
284
+ }
285
+ /**
286
+ * Adopt a baseline for a bridge that is already commissioned but has no map
287
+ * — the E5 upgrade path (PRD §7).
288
+ *
289
+ * Not a rebuild: there is nothing to discard. A pre-E5 install has fabrics,
290
+ * endpoints and numbers that matter.js has been persisting all along, and
291
+ * the only thing missing is our witness of them. Recording what is already
292
+ * true is the migration; refusing to serve until a human confirms a
293
+ * *rebuild* would take a working bridge offline to fix a file it never had.
294
+ *
295
+ * Returns whether the baseline reached disk.
296
+ */
297
+ seed(numbers, why) {
298
+ this.#numbers = new Map(numbers.map(({ uniqueId, endpointNumber }) => [uniqueId, endpointNumber]));
299
+ this.#problem = undefined;
300
+ this.#checked = numbers.length > 0;
301
+ return this.persist(`seeded with ${this.#numbers.size} endpoint number(s) — ${why}`);
302
+ }
303
+ /**
304
+ * §3.11 — throw the baseline away and adopt the live numbers as the truth.
305
+ *
306
+ * The recovery path out of `endpoint_map_invalid`, and the only operation
307
+ * here that discards a mapping. It does not renumber anything in matter.js:
308
+ * whatever duplication a lost map implies has already happened by the time a
309
+ * user is asked to confirm this, and what the rebuild does is stop refusing
310
+ * and start telling the truth about the numbers that now exist.
311
+ */
312
+ rebuild(live) {
313
+ // The unusable file is COPIED aside before it is overwritten. It is the
314
+ // only surviving record of what the numbers used to be, and the reason
315
+ // it is unusable may be a truncation or a bad byte that a human can
316
+ // repair — whereas the rebuild is about to replace it with the numbers
317
+ // that exist *now*, which is a different and irreversible answer.
318
+ this.quarantineUnusable();
319
+ if (live.length === 0) {
320
+ this.log("Rebuilding the endpoint map from ZERO live endpoints — the node refuses to " +
321
+ "create any while it is refusing to serve (§1.1 excludes attach), so this " +
322
+ "records an empty baseline and stops refusing; the numbers themselves are " +
323
+ "recorded by the reconcile that follows.");
324
+ }
325
+ this.#numbers = new Map(live.map(({ uniqueId, endpointNumber }) => [uniqueId, endpointNumber]));
326
+ this.#problem = undefined;
327
+ const persisted = this.persist(`rebuilt from ${this.#numbers.size} live endpoint(s)`);
328
+ // Same rule as `check`: a rebuild from zero live endpoints — which is
329
+ // the *normal* rebuild, since §1.1 keeps `attach` out of the recovery
330
+ // commands — has compared nothing, and the baseline it wrote is empty.
331
+ // Claiming `driftChecked` there says an all-clear about a comparison
332
+ // that never happened; the reconcile that follows is what records the
333
+ // real numbers and earns the flag.
334
+ this.#checked = persisted && live.length > 0;
335
+ return persisted;
336
+ }
337
+ /**
338
+ * Copy a present-but-unusable map to `<file>.corrupt-<stamp>` before it is
339
+ * lost.
340
+ *
341
+ * Timestamped like `identity.json.unreadable-<stamp>`, and for the same
342
+ * reason: a fixed name means the *second* thing to go wrong overwrites the
343
+ * evidence of the first, and these bytes are the only surviving record of
344
+ * what the endpoint numbers used to be.
345
+ */
346
+ quarantineUnusable() {
347
+ if (this.#problem === undefined || this.#quarantined) {
348
+ return;
349
+ }
350
+ this.#quarantined = true;
351
+ const file = join(this.storagePath, ENDPOINT_MAP_FILE);
352
+ const target = `${file}.corrupt-${this.now().toISOString().replace(/[:.]/g, "-")}`;
353
+ try {
354
+ copyFileSync(file, target);
355
+ this.log(`Unusable endpoint map copied to ${target} before it is overwritten`);
356
+ }
357
+ catch (error) {
358
+ this.log(`Could not copy the unusable endpoint map aside: ${describeError(error)}`);
359
+ }
360
+ }
361
+ /**
362
+ * §3.10 with `preserveEndpointNumbers: false` — delete the file and forget
363
+ * everything. The "explicit rebuild" of PRD §7, for when the map itself is
364
+ * what is corrupt.
365
+ */
366
+ discard() {
367
+ this.#numbers = new Map();
368
+ this.#problem = undefined;
369
+ this.#checked = false;
370
+ this.#dirty = false;
371
+ try {
372
+ const removed = deleteEndpointMap(this.storagePath);
373
+ this.#present = false;
374
+ this.#warnings.delete(WARN_DELETE);
375
+ this.#warnings.delete(WARN_PERSIST);
376
+ this.log(removed ? "Endpoint map discarded" : "No endpoint map to discard");
377
+ return true;
378
+ }
379
+ catch (error) {
380
+ // The in-memory map is already empty, so the node behaves as asked;
381
+ // what survives is a stale file that the next start would load as a
382
+ // baseline for numbers that no longer mean anything. Say so.
383
+ const message = `Could not delete the endpoint map: ${describeError(error)}`;
384
+ this.log(message);
385
+ this.#warnings.set(WARN_DELETE, message);
386
+ return false;
387
+ }
388
+ }
389
+ /**
390
+ * Write the current map, reporting whether it landed.
391
+ *
392
+ * Never throws — refusing to serve endpoints because a *witness* could not
393
+ * be written would take down a working bridge over a disk problem. But it
394
+ * is no longer silent to its callers either: an unwritten map means the
395
+ * next start has no baseline, and the two callers that must not report
396
+ * success over that (§3.11's rebuild and §4.3's `driftChecked`) both read
397
+ * the answer.
398
+ */
399
+ persist(why) {
400
+ // Not only `rebuild`'s job. `refuseReasonFor` deliberately does NOT
401
+ // refuse a corrupt map on a bridge that has never been commissioned —
402
+ // there is no accessory identity to protect — so the first `check` on
403
+ // such a bridge walks straight in here and writes over the unusable
404
+ // file. That file may be a truncation a human could have repaired, and
405
+ // once it is gone the numbers it held cannot be recovered; the same
406
+ // copy-first care `rebuild` takes costs nothing here.
407
+ this.quarantineUnusable();
408
+ const file = {
409
+ version: ENDPOINT_MAP_VERSION,
410
+ endpoints: Object.fromEntries(this.#numbers),
411
+ };
412
+ try {
413
+ writeJsonAtomic(join(this.storagePath, ENDPOINT_MAP_FILE), file);
414
+ this.#present = true;
415
+ this.#dirty = false;
416
+ // A write that succeeded is the definitive answer about the file's
417
+ // usability: whatever was wrong with the old one is gone with it.
418
+ this.#problem = undefined;
419
+ this.#warnings.delete(WARN_PERSIST);
420
+ this.log(`Endpoint map ${why}`);
421
+ return true;
422
+ }
423
+ catch (error) {
424
+ this.#dirty = true;
425
+ const message = `Could not write the endpoint map (${why}): ${describeError(error)}. ` +
426
+ "Endpoint-number drift will not be detectable after a restart.";
427
+ this.log(message);
428
+ this.#warnings.set(WARN_PERSIST, message);
429
+ return false;
430
+ }
431
+ }
432
+ }
433
+ //# sourceMappingURL=endpoint-map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-map.js","sourceRoot":"","sources":["../src/endpoint-map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAmB,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAmB/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,eAAe,CAAC,KAA4B;IACxD,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,aAAa,CAAC;IACnF,CAAC;IACD,OAAO,KAAK,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,iBAAiB,CAAC;AAC3F,CAAC;AAED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