@serve.zone/interfaces 32.80.0 → 32.82.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,83 @@
1
+ import * as plugins from '../plugins.js';
2
+ import type { ICompareAndSetWitnessRecordRequest, IEnrollWitnessMemberRequest, IGetWitnessRecordRequest, IPairWitnessControllerRequest, IWitnessHealth, IWitnessRecord } from '../data/witness.js';
3
+ /**
4
+ * A controller pairs with the witness: it redeems the one-time code the witness's operator made on
5
+ * the witness host for this controller id, with the SHA-256 of the bearer it created for itself.
6
+ * In one atomic write the witness consumes the code and creates the record (`revision` 1, the
7
+ * caller's origin as the active site and only member, no in-sync standby, `bearerSha256` as that
8
+ * member's hash); it answers the record.
9
+ *
10
+ * A caller whose answer was lost reads the record with its own bearer (`getWitnessRecord`): the
11
+ * record answers when the pairing was stored, and `credential-invalid` when it was not, so the code
12
+ * was not consumed and the caller pairs again with it.
13
+ *
14
+ * Refused `pairing-code-unknown`, `pairing-code-expired` or `pairing-code-used` for the code, then,
15
+ * with the code left unconsumed, `controller-mismatch` for a code made for another controller id
16
+ * and `controller-paired` when the witness holds a record for the controller already.
17
+ */
18
+ export interface IReq_Cloudly_Witness_PairWitnessController extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Cloudly_Witness_PairWitnessController> {
19
+ method: 'pairWitnessController';
20
+ /** `data.validatePairWitnessControllerRequest`. */
21
+ request: IPairWitnessControllerRequest;
22
+ response: {
23
+ /** `data.validateWitnessRecord`. */
24
+ record: IWitnessRecord;
25
+ };
26
+ }
27
+ /**
28
+ * The active site enrolls another site with the SHA-256 of the bearer that site created for itself
29
+ * and handed it, never the bearer: a new member (`member-limit` once the record holds
30
+ * `data.witnessContract.maximumMemberOrigins`), or an existing one whose bearer hash is replaced,
31
+ * never the recorded in-sync standby (`transition-invalid`; the active drops it by compare-and-set
32
+ * first). A compare-and-set on `expectedRevision` that raises the revision by one and leaves the
33
+ * state as it is (`data.judgeWitnessMemberEnrollment`). The answer is the record as stored.
34
+ */
35
+ export interface IReq_Cloudly_Witness_EnrollWitnessMember extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Cloudly_Witness_EnrollWitnessMember> {
36
+ method: 'enrollWitnessMember';
37
+ /** `data.validateEnrollWitnessMemberRequest`. */
38
+ request: IEnrollWitnessMemberRequest;
39
+ response: {
40
+ /** `data.validateWitnessRecord`. */
41
+ record: IWitnessRecord;
42
+ };
43
+ }
44
+ /** A member site reads the controller's witness record. */
45
+ export interface IReq_Cloudly_Witness_GetWitnessRecord extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Cloudly_Witness_GetWitnessRecord> {
46
+ method: 'getWitnessRecord';
47
+ /** `data.validateGetWitnessRecordRequest`. */
48
+ request: IGetWitnessRecordRequest;
49
+ response: {
50
+ /** `data.validateWitnessRecord`. */
51
+ record: IWitnessRecord;
52
+ };
53
+ }
54
+ /**
55
+ * A member site changes the record's state: the active drops its standby or records it in sync
56
+ * again, the in-sync standby promotes itself, or the active raises the epoch after a restore
57
+ * (`data.judgeWitnessChange`). The change is stored only while the stored revision is
58
+ * `expectedRevision`, and raises it by one; of two changes naming one revision at most one is
59
+ * stored and the other is refused `revision-stale`. The answer is the record as stored.
60
+ *
61
+ * A controller acts on a change only once this answer arrived. A change refused `outcome-unknown`,
62
+ * or whose answer never arrived, may have been stored: the caller reads the record first.
63
+ */
64
+ export interface IReq_Cloudly_Witness_CompareAndSetWitnessRecord extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Cloudly_Witness_CompareAndSetWitnessRecord> {
65
+ method: 'compareAndSetWitnessRecord';
66
+ /** `data.validateCompareAndSetWitnessRecordRequest`. */
67
+ request: ICompareAndSetWitnessRecordRequest;
68
+ response: {
69
+ /** `data.validateWitnessRecord`. */
70
+ record: IWitnessRecord;
71
+ };
72
+ }
73
+ /**
74
+ * Whether the witness can serve, and which releases it runs. Unauthenticated, and it names no
75
+ * controller. A controller records `witnessVersion` with the takeover-path components and gates a
76
+ * later witness contract member on `interfacesVersion`.
77
+ */
78
+ export interface IReq_Cloudly_Witness_GetWitnessHealth extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Cloudly_Witness_GetWitnessHealth> {
79
+ method: 'getWitnessHealth';
80
+ request: {};
81
+ /** `data.validateWitnessHealth`. */
82
+ response: IWitnessHealth;
83
+ }
@@ -0,0 +1,2 @@
1
+ import * as plugins from '../plugins.js';
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2l0bmVzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3RzL3JlcXVlc3RzL3dpdG5lc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLE9BQU8sTUFBTSxlQUFlLENBQUMifQ==
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serve.zone/interfaces",
3
- "version": "32.80.0",
3
+ "version": "32.82.0",
4
4
  "private": false,
5
5
  "description": "Shared TypeScript interfaces and TypedRequest contracts for the serve.zone ecosystem.",
6
6
  "exports": {
package/readme.md CHANGED
@@ -4381,8 +4381,10 @@ guard that names roles excludes it by type.
4381
4381
  (send the newest status again after the interval), `controller-gateway-adopted`, `request-invalid`
4382
4382
  (the text carries the validator's sentences), `desired-state-stale` (the text names the applied
4383
4383
  epoch and revision), `gateway-mismatch`, `unsupported-area` (an export of an area the gateway does
4384
- not take) and `gateway-client-unbound`. An unknown location stays `location-not-found`
4385
- (`data.locationRefusals`).
4384
+ not take), `gateway-client-unbound`, `controller-epoch-older` (a pushed peer set older than the
4385
+ stored one) and `forward-sources-exceed-allowlist` (a `new` adoption whose forward sources would
4386
+ make the union of every gateway's forward source prefixes exceed one cluster ingress allowlist; the
4387
+ code stays unconsumed). An unknown location stays `location-not-found` (`data.locationRefusals`).
4386
4388
  - Revisions: `data.IControllerRevision` is one record of the controller-wide sequence, validated
4387
4389
  exactly by `data.validateControllerRevision`: the actor's `sub` is `null` exactly for `system`,
4388
4390
  the bounds of `data.controllerRevisionContract` only ever rise,
@@ -4411,7 +4413,8 @@ guard that names roles excludes it by type.
4411
4413
  gateway client id of 1 to 253 visible ASCII characters, exact keys at every level. No refusal
4412
4414
  carries the bearer.
4413
4415
  - Peers: a gateway stores the peer set (`controllerId`, `epoch`, `activeOrigin`, `shadowOrigins`) and
4414
- refuses any other controller and any older epoch. A takeover and a database restore raise the
4416
+ refuses any other controller and any older epoch (`data.judgeControllerPeerSet`, see
4417
+ [Controller Peer Set](#controller-peer-set)). A takeover and a database restore raise the
4415
4418
  epoch. Later controller contracts extend `data.IControllerPeerSet` and never define a second one.
4416
4419
  - Desired state: the controller pushes the whole `data.IGatewayDesiredState` (`applyDesiredState`):
4417
4420
  `{ gatewayId, controllerId, epoch, revision, areas }`, one whole table per controller-owned area.
@@ -4479,6 +4482,137 @@ const desired: requests.gatewayconnector.IReq_Cloudly_Gateway_ApplyDesiredState[
4479
4482
  data.validateGatewayDesiredState(desired.desired); // []
4480
4483
  ```
4481
4484
 
4485
+ ### Controller Peer Set
4486
+
4487
+ `data.IControllerPeerSet` (`controllerId`, `epoch`, `activeOrigin`, `shadowOrigins`) is where the
4488
+ components that dial a controller reach it: a gateway, a relay and a Spark node. AGL-1192 adds the
4489
+ ways the controller states it beyond the gateway's adoption and hello answers, and one rule for
4490
+ admitting it.
4491
+
4492
+ - Judge: `data.judgeControllerPeerSet(stored, next)` answers, in this order, `controller-mismatch`
4493
+ for another `controllerId`, `controller-epoch-older` for an older `epoch`, `equal` when all four
4494
+ keys are equal with `shadowOrigins` in the same order (it is the dialling order), and otherwise
4495
+ `replace`. A newer epoch replaces, and so does a changed origin or shadow list at an equal epoch.
4496
+ `equal` writes nothing. The refusals are `data.controllerPeerSetRefusals`
4497
+ (`data.TControllerPeerSetRefusal`); a refusal leaves the stored set as it was.
4498
+ - Push: `requests.controller.IReq_Cloudly_Any_PushControllerPeerSet` (`pushControllerPeerSet`,
4499
+ `{ controller }`, answered `{}`) is declared once and travels on gateway and relay sessions. The
4500
+ controller sends it before any document of the set's epoch on that session. A gateway refuses it
4501
+ as a connector refusal: `controller-mismatch`, `controller-epoch-older`, or `request-invalid` for a
4502
+ set that fails `data.validateControllerPeerSet`. A relay answers the same two names the way its
4503
+ session states every refusal (`data.applyClusterVpnNetworkRefusals`): the error text leads with
4504
+ `<name>: <reason>` and Cloudly matches the name. A set that fails `data.validateControllerPeerSet`
4505
+ is refused by a relay with the validator's sentences and no refusal name: that is Cloudly's
4506
+ defect, and Cloudly has nothing to act on.
4507
+ - Answers: `data.IRegisterClusterRelayResponse.controller` and
4508
+ `data.ISparkSwarmNodeHeartbeatResponse.controller` are optional. A Cloudly before them sends
4509
+ none, and a relay or Spark that receives none keeps what it dials. Cloudly always sends the whole
4510
+ set, so `data.sparkSwarmNodeContracts.heartbeat.maxResponseBytes` is 40_960: the largest set
4511
+ `data.validateControllerPeerSet` admits (a 200-character id, a 16-digit epoch, 17 origins of
4512
+ 2048 characters) on top of the 2048 bytes the rest of the answer takes.
4513
+ - Adding a shadow: `requests.controller.IReq_Admin_Cloudly_AddControllerShadow`
4514
+ (`addControllerShadow`, `{ identity, origin, bearerSha256 }`) names the shadow's site origin and
4515
+ the SHA-256 of the witness bearer that site created for itself, never the bearer. The active
4516
+ enrolls the site with its witness, then sets `shadowOrigins` to the witness members other than
4517
+ itself in one transaction with a revision, and answers `{ controller }`, the set it stored.
4518
+ - Shared rules: `data.validateControllerIdentifier(value, path)` is the canonical identifier rule
4519
+ every controller contract applies to a controller id, and `data.compareWireTokens(left, right)` the
4520
+ canonical order (UTF-16 code units ascending) of `data.IWitnessRecord.memberOrigins` and every
4521
+ other canonical list here. Sort and check with these, never with a copy.
4522
+
4523
+ ```typescript
4524
+ import { data, requests } from '@serve.zone/interfaces';
4525
+
4526
+ declare const stored: data.IControllerPeerSet;
4527
+ declare const pushed: requests.controller.IReq_Cloudly_Any_PushControllerPeerSet['request'];
4528
+ if (data.validateControllerPeerSet(pushed.controller).length === 0) {
4529
+ const judgement = data.judgeControllerPeerSet(stored, pushed.controller);
4530
+ // 'equal': write nothing; 'replace': store pushed.controller; otherwise refuse with judgement.
4531
+ }
4532
+ ```
4533
+
4534
+ ### Witness
4535
+
4536
+ The witness (AGL-1195) is a small service of its own at a third site that keeps one compare-and-set
4537
+ record per controller, `data.IWitnessRecord`: `controllerId`, `epoch`, `activeOrigin`,
4538
+ `inSyncStandbyOrigin` (or `null`), `revision` and `memberOrigins`. A site is named by its site
4539
+ origin, the canonical `https` origin of one controller site (the value `data.IControllerPeerSet`
4540
+ carries as `activeOrigin` while that site is active), never the public origin browsers use. Cloudly
4541
+ is the only caller and sends `requests.witness` with TypedRequest over HTTPS to
4542
+ `data.witnessContract.typedRequestPath` (`/typedrequest`) below the witness's origin. The witness
4543
+ holds no controller data and no controller credential.
4544
+
4545
+ - Bearers: a member's bearer is a fact about one site. The site creates it, the unpadded base64url
4546
+ of `data.witnessContract.bearerRandomBytes` (32) random bytes, 43 characters checked by an exact
4547
+ pattern, and keeps it in that site's own config or secret store, never in the replicated
4548
+ controller database. The witness learns only `bearerSha256`, the SHA-256 of the bearer's UTF-8 as
4549
+ 64 lowercase hex characters, and no answer carries a bearer.
4550
+ - Pairing: the witness's operator makes a one-time code for a controller id on the witness host;
4551
+ the controller redeems it with `pairWitnessController` (its `epoch`, its own origin and its
4552
+ `bearerSha256`), and the witness creates the record (revision 1, the caller active and only
4553
+ member, no standby) and answers `{ record }`. A controller whose answer was lost reads the record
4554
+ with its own bearer (`getWitnessRecord`). The active enrolls every other member with
4555
+ `enrollWitnessMember`, by the `bearerSha256` that site handed it, a compare-and-set on
4556
+ `expectedRevision` that raises the revision and replaces an existing member's hash; it answers
4557
+ `{ record }`. It never enrolls the recorded in-sync standby (`transition-invalid`): the active
4558
+ drops that standby first. At most `data.witnessContract.maximumMemberOrigins` (17) members.
4559
+ - Changes: `compareAndSetWitnessRecord` stores `next` (`data.IWitnessState`) only while the stored
4560
+ revision is `expectedRevision`, and raises it by one, so of two changes naming one revision at most
4561
+ one is stored. `data.judgeWitnessChange` is the rule both sides apply: within an epoch only the
4562
+ active changes the record, and only its in-sync standby (dropping it before it continues without
4563
+ one, or recording it again once it caught up); an epoch rises by exactly one and every epoch raise
4564
+ records no standby; a promotion names the recorded in-sync standby as active and is stated by that
4565
+ site, so a stale standby is never promoted; the active raises its own epoch after a restore.
4566
+ `data.judgeWitnessMemberEnrollment` is the rule for enrollment. `getWitnessRecord` reads the
4567
+ record for any member.
4568
+ - Refusals: one of `data.witnessRefusals`, as a `TypedResponseError` whose `errorData` is
4569
+ `data.IWitnessRefusalErrorData` (`{ code, retryable }`, `data.createWitnessRefusalErrorData`). The
4570
+ list is a vocabulary, not a check order. The witness answers the first refusal of its gates, in
4571
+ this order: `request-invalid`; then the pairing code (`pairing-code-unknown`,
4572
+ `pairing-code-expired`, `pairing-code-used`, then `controller-mismatch` and `controller-paired`
4573
+ with the code unconsumed) or the authentication (`credential-invalid`, one code for an unknown
4574
+ controller, a non-member site and a bad bearer); then `revision-stale` (the text names the stored
4575
+ revision); then the judge's first refusal, in the order each judge's doc states. Only
4576
+ `witness-unavailable` and `outcome-unknown` (`data.witnessMomentaryRefusals`) are momentary. A
4577
+ change refused `outcome-unknown`, or whose answer never arrived, may have been stored: read the
4578
+ record before acting on it. `data.readWitnessRefusalErrorData` reads anything but exactly one
4579
+ refusal as no answer.
4580
+ - Health: the unauthenticated `getWitnessHealth` answers `{ ready, witnessVersion, interfacesVersion }`
4581
+ and names no controller. `ready` is true while the witness's embedded storage engine runs and
4582
+ answers a bounded read; it does not claim the next write will be stored. A write the storage cannot
4583
+ make is answered on that write (`witness-unavailable` or `outcome-unknown`).
4584
+ - Validators are exact and never carry a bearer or a pairing code in a refusal:
4585
+ `data.validateWitnessRecord`, `data.validateWitnessState`, `data.validateWitnessMemberCredential`,
4586
+ `data.validatePairWitnessControllerRequest`, `data.validateEnrollWitnessMemberRequest`,
4587
+ `data.validateGetWitnessRecordRequest`, `data.validateCompareAndSetWitnessRecordRequest` and
4588
+ `data.validateWitnessHealth`.
4589
+
4590
+ ```typescript
4591
+ import { data, requests } from '@serve.zone/interfaces';
4592
+
4593
+ declare const activeBearer: string; // the active's own witness bearer, from its site's secret store
4594
+ // The record as getWitnessRecord answered it.
4595
+ const record: data.IWitnessRecord = {
4596
+ controllerId: 'controller-0123456789abcdef0123456789abcdef',
4597
+ epoch: 1,
4598
+ activeOrigin: 'https://fra.cloudly.example.com',
4599
+ inSyncStandbyOrigin: 'https://nbg.cloudly.example.com',
4600
+ revision: 4,
4601
+ memberOrigins: ['https://fra.cloudly.example.com', 'https://nbg.cloudly.example.com'],
4602
+ };
4603
+ // The active stops waiting for a standby that stopped answering: first the witness records none.
4604
+ const dropStandby: requests.witness.IReq_Cloudly_Witness_CompareAndSetWitnessRecord['request'] = {
4605
+ controllerId: record.controllerId,
4606
+ member: { origin: record.activeOrigin, bearer: activeBearer },
4607
+ expectedRevision: record.revision,
4608
+ next: { epoch: record.epoch, activeOrigin: record.activeOrigin, inSyncStandbyOrigin: null },
4609
+ };
4610
+ data.judgeWitnessChange(record, dropStandby.member.origin, dropStandby.next); // null: admissible
4611
+ // A promotion of the standby once the record no longer names it in sync:
4612
+ data.judgeWitnessChange({ ...record, inSyncStandbyOrigin: null, revision: 5 }, 'https://nbg.cloudly.example.com',
4613
+ { epoch: 2, activeOrigin: 'https://nbg.cloudly.example.com', inSyncStandbyOrigin: null }); // 'standby-not-in-sync'
4614
+ ```
4615
+
4482
4616
  ### CoreMail contracts
4483
4617
 
4484
4618
  `requests.coremail` is the shared contract boundary for authenticated workload
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@serve.zone/interfaces',
6
- version: '32.80.0',
6
+ version: '32.82.0',
7
7
  description: 'Shared TypeScript interfaces and TypedRequest contracts for the serve.zone ecosystem.'
8
8
  }
@@ -2,6 +2,7 @@ import * as plugins from '../plugins.js';
2
2
 
3
3
  import { type IDockerRegistryInfo } from '../data/docker.js';
4
4
  import type { IClusterNode } from './clusternode.js';
5
+ import type { IControllerPeerSet } from './controller.js';
5
6
  import type { IFleetCutoverAcceptedEvidenceReference } from './fleetcutover.js';
6
7
  import type { TSha256Digest } from './immutableimage.js';
7
8
  import type { IRuntimeAuthorityReference } from './runtimeassignment.js';
@@ -159,6 +160,12 @@ export interface IRegisterClusterRelayResponse {
159
160
  credential: IRuntimeAuthorityReference;
160
161
  /** The accepted registration record this answer wrote, as a retirement record later cites it. */
161
162
  acceptedRegistration: IFleetCutoverAcceptedEvidenceReference;
163
+ /**
164
+ * The controller's current peer set (`validateControllerPeerSet`), which the relay admits by
165
+ * `judgeControllerPeerSet` and, once admitted, dials. Absent from a Cloudly before this member;
166
+ * a relay that receives none keeps what it dials, and one built before the member ignores it.
167
+ */
168
+ controller?: IControllerPeerSet;
162
169
  }
163
170
 
164
171
  /**
@@ -3,6 +3,7 @@ import { isSha256Digest, type TSha256Digest, type TImmutableContainerPlatform }
3
3
  import type { ISparkNodeReportRecord } from './sparknodereport.js';
4
4
  import type { INodeActionExpiry, INodeActionLifecycle } from './nodeaction.js';
5
5
  import type { IClusterNodeHostnameIntent } from './clusternodehostname.js';
6
+ import type { IControllerPeerSet } from './controller.js';
6
7
  import type { IPlatformObjectStorageEndpoint } from '../platform/objectstorage.js';
7
8
  import type { IPlatformDatabaseEndpoint } from '../platform/database.js';
8
9
  import {
@@ -147,7 +148,13 @@ export const sparkSwarmNodeContracts = Object.freeze({
147
148
  heartbeat: Object.freeze({
148
149
  endpoint: '/spark/swarm-nodes/heartbeat',
149
150
  maxRequestBytes: 32_768,
150
- maxResponseBytes: 2048,
151
+ /**
152
+ * The answer may carry `controller` at its largest: 1 active origin plus 16 shadow origins
153
+ * (`controllerPeerSetContract.maximumShadowOrigins`), each up to
154
+ * `controllerPeerSetContract.maximumOriginLength` characters, a 200-character id and a 16-digit
155
+ * epoch, on top of the 2048 bytes the rest of the answer was bounded by.
156
+ */
157
+ maxResponseBytes: 40_960,
151
158
  } as const),
152
159
  /** One sample up, every action the server holds for this node back down. */
153
160
  metricsSample: Object.freeze({
@@ -202,6 +209,12 @@ export interface ISparkSwarmNodeHeartbeatResponse {
202
209
  message?: string;
203
210
  /** The answering server's offer; see `sparkSwarmNodeContracts`. */
204
211
  protocol: IProtocolOffer;
212
+ /**
213
+ * The controller's current peer set (`validateControllerPeerSet`), which Spark admits by
214
+ * `judgeControllerPeerSet` and, once admitted, dials. Absent from a Cloudly before this member;
215
+ * a Spark that receives none keeps what it dials, and one built before the member ignores it.
216
+ */
217
+ controller?: IControllerPeerSet;
205
218
  }
206
219
 
207
220
  /** Spark -> Cloudly body for `sparkSwarmNodeContracts.metricsSample.endpoint`. */
@@ -8,15 +8,24 @@ import {
8
8
  import { readDataElements, readDataProperty, readExactDataRecord } from '../private/dataproperties.js';
9
9
  import type { TCompleteKeyList } from '../private/keylist.js';
10
10
 
11
+ /**
12
+ * The generic canonical identifier rule the controller contracts judge ids by (a controller id, an
13
+ * actor's `sub`, a revision's object kind and id), stated as refusals: an empty list for a valid
14
+ * id, otherwise one sentence naming `pathArg`. Public so a component that checks a controller id
15
+ * before any contract body carries it (a witness making a pairing code) runs this rule and never a
16
+ * copy of it.
17
+ */
18
+ export { validateControllerIdentifier };
19
+
11
20
  /**
12
21
  * The controller as the components that dial it know it: which controller they belong to, which
13
22
  * epoch it is in and where to reach it.
14
23
  *
15
- * A dialling component (a gateway today) stores this when it is adopted and replaces it with every
16
- * answer the controller gives it. It refuses any other `controllerId` and any older `epoch`: a
17
- * takeover and a database restore both raise the epoch, so the controller that answers with the
18
- * highest one is the one whose revisions count. Later controller contracts extend this shape and
19
- * never define a second one.
24
+ * A dialling component (a gateway, a relay, a Spark node) stores this when it is adopted and
25
+ * replaces it with every answer the controller gives it, as `judgeControllerPeerSet` admits it. It
26
+ * refuses any other `controllerId` and any older `epoch`: a takeover and a database restore both
27
+ * raise the epoch, so the controller that answers with the highest one is the one whose revisions
28
+ * count. Later controller contracts extend this shape and never define a second one.
20
29
  */
21
30
  export interface IControllerPeerSet {
22
31
  /** Fixed for the controller's life; stored at adoption. */
@@ -34,6 +43,55 @@ export const controllerPeerSetContract = Object.freeze({
34
43
  maximumShadowOrigins: 16,
35
44
  } as const);
36
45
 
46
+ /**
47
+ * Every reason a dialling component refuses a peer set the controller states
48
+ * (`judgeControllerPeerSet`); the stored peer set stays as it was.
49
+ */
50
+ export const controllerPeerSetRefusals = Object.freeze([
51
+ /** The peer set names another controller than the one the component stored. */
52
+ 'controller-mismatch',
53
+ /** The peer set's epoch is older than the one the component stored. */
54
+ 'controller-epoch-older',
55
+ ] as const);
56
+
57
+ /** One of the reasons a dialling component refuses a peer set. */
58
+ export type TControllerPeerSetRefusal = typeof controllerPeerSetRefusals[number];
59
+
60
+ /**
61
+ * What a dialling component does with a peer set the controller states: `equal` writes nothing,
62
+ * `replace` stores it in place of the stored one, and a refusal leaves the stored one as it was.
63
+ */
64
+ export type TControllerPeerSetJudgement = 'equal' | 'replace' | TControllerPeerSetRefusal;
65
+
66
+ /**
67
+ * Whether a dialling component takes `nextArg` in place of its stored peer set: the one admission
68
+ * rule for every peer set a controller states, in an adoption answer, a hello answer, a relay
69
+ * registration answer, a Spark heartbeat answer or `pushControllerPeerSet`, so no receiver keeps a
70
+ * copy of it.
71
+ *
72
+ * It judges values that passed `validateControllerPeerSet`, and answers the first of these that
73
+ * applies, in this order: `controller-mismatch` for another `controllerId`; `controller-epoch-older`
74
+ * for an older `epoch`; `equal` when all four keys are equal, `shadowOrigins` in the same order
75
+ * (the order is the dialling order, so a reordered list is a different set); otherwise `replace`. A
76
+ * newer epoch replaces, and so does a changed origin or shadow list at an equal epoch.
77
+ */
78
+ export const judgeControllerPeerSet = (
79
+ storedArg: Readonly<IControllerPeerSet>,
80
+ nextArg: Readonly<IControllerPeerSet>,
81
+ ): TControllerPeerSetJudgement => {
82
+ if (nextArg.controllerId !== storedArg.controllerId) {
83
+ return 'controller-mismatch';
84
+ }
85
+ if (nextArg.epoch < storedArg.epoch) {
86
+ return 'controller-epoch-older';
87
+ }
88
+ const equal = nextArg.epoch === storedArg.epoch
89
+ && nextArg.activeOrigin === storedArg.activeOrigin
90
+ && nextArg.shadowOrigins.length === storedArg.shadowOrigins.length
91
+ && nextArg.shadowOrigins.every((originArg, indexArg) => originArg === storedArg.shadowOrigins[indexArg]);
92
+ return equal ? 'equal' : 'replace';
93
+ };
94
+
37
95
  /**
38
96
  * Negative, zero or positive as the left controller position is older than, the same as or newer
39
97
  * than the right one: the epoch decides first and the revision only within one epoch, so a higher
@@ -241,8 +241,8 @@ export interface IGatewayDesiredState {
241
241
  * answers them instead of `adoptGateway`, `registerGatewaySession`, `pushGatewayStatus` and
242
242
  * `createGatewayAdoptionCode`, and instead of a legacy gateway setting it no longer owns. The
243
243
  * gateway answers them instead of a whole `applyDesiredState` document, an `exportGatewayArea`, a
244
- * gateway-client call on the connector socket, or an HTTP call authenticated with a token of its
245
- * controller-bound gateway client.
244
+ * `pushControllerPeerSet`, a gateway-client call on the connector socket, or an HTTP call
245
+ * authenticated with a token of its controller-bound gateway client.
246
246
  *
247
247
  * Each is answered as a `TypedResponseError` whose `errorData` is
248
248
  * `IGatewayConnectorRefusalErrorData` and whose text carries the detail, so a peer acts on the code
@@ -322,6 +322,19 @@ export const gatewayConnectorRefusals = Object.freeze([
322
322
  * (`controllerGatewayClientId: null`).
323
323
  */
324
324
  'gateway-client-unbound',
325
+ /**
326
+ * A peer set whose epoch is older than the controller epoch the gateway stored
327
+ * (`controllerPeerSetRefusals`, `judgeControllerPeerSet`): a `pushControllerPeerSet` the gateway
328
+ * refuses and stores nothing of.
329
+ */
330
+ 'controller-epoch-older',
331
+ /**
332
+ * An `adoptGateway` for a `new` gateway whose stated `forwardSourceAddresses` would make the union
333
+ * of every gateway's forward source prefixes exceed one cluster ingress allowlist
334
+ * (`clusterIngressLimits.maximumSourceAllowListEntries` prefixes). Nothing is adopted and the code
335
+ * stays unconsumed.
336
+ */
337
+ 'forward-sources-exceed-allowlist',
325
338
  ] as const);
326
339
 
327
340
  /** One of the reasons one side of the gateway connector answers instead of a request. */
package/ts/data/index.ts CHANGED
@@ -100,4 +100,5 @@ export * from './traffic.js';
100
100
  export * from './user.js';
101
101
  export * from './version.js';
102
102
  export * from './webpush.js';
103
+ export * from './witness.js';
103
104
  export * from './workloadreplicaidentity.js';