@serve.zone/interfaces 32.81.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.
@@ -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. */
@@ -9,6 +9,15 @@ import type { TCompleteKeyList } from '../private/keylist.js';
9
9
  import { controllerPeerSetContract } from './controller.js';
10
10
  import { isReleaseVersion } from './releaseversion.js';
11
11
 
12
+ /**
13
+ * The canonical order of two wire tokens (UTF-16 code units ascending): negative, zero or positive
14
+ * as `leftArg` sorts before, equal to or after `rightArg`. It is the order of
15
+ * `IWitnessRecord.memberOrigins` and of every other canonical list this package judges, public so a
16
+ * witness or a controller sorts a member list by this rule and never by a copy of it: a copy that
17
+ * drifted would build lists the validators refuse.
18
+ */
19
+ export { compareWireTokens };
20
+
12
21
  /*
13
22
  * The witness (AGL-1195, Linus rulings 69 Q5, Q6 and 73): a small service of its own, at a third site, that
14
23
  * keeps one compare-and-set record per controller. Cloudly is its only caller and reaches it with
@@ -156,7 +165,11 @@ export interface ICompareAndSetWitnessRecordRequest {
156
165
 
157
166
  /** What the witness answers `getWitnessHealth` (`validateWitnessHealth`); it names no controller. */
158
167
  export interface IWitnessHealth {
159
- /** True while the witness can read and write its records. */
168
+ /**
169
+ * True while the witness's embedded storage engine runs and answers a bounded read. It does not
170
+ * claim the next write will be stored: a write the storage cannot make is answered on that write
171
+ * (`witness-unavailable` or `outcome-unknown`).
172
+ */
160
173
  ready: boolean;
161
174
  /** The witness release the site runs (`data.isReleaseVersion`). */
162
175
  witnessVersion: string;
@@ -0,0 +1,66 @@
1
+ import * as plugins from '../plugins.js';
2
+ import type { IControllerPeerSet } from '../data/controller.js';
3
+ import type { IIdentityCredential } from '../data/user.js';
4
+
5
+ /*
6
+ * The controller peer set (AGL-1192, Linus ruling 79): where the components that dial a controller
7
+ * reach it. `data.IControllerPeerSet` is the one shape, and `data.judgeControllerPeerSet` the one
8
+ * rule by which a receiver admits it.
9
+ */
10
+
11
+ /**
12
+ * The controller states its current peer set on a session a component opened to it: a gateway's
13
+ * connector socket and a relay's session both carry this one request. The receiver judges it
14
+ * against the peer set it stored with `data.judgeControllerPeerSet`, the same admission as a hello
15
+ * or registration answer: `replace` stores it, `equal` writes nothing, and either is answered `{}`.
16
+ *
17
+ * The controller sends it before any document of the set's epoch on that session, so a receiver
18
+ * never holds a document of an epoch whose peer set it has not admitted.
19
+ *
20
+ * The receiver refuses it with the judge's refusal (`data.controllerPeerSetRefusals`) and keeps the
21
+ * set it stored: `controller-mismatch` for another controller, `controller-epoch-older` for an
22
+ * older epoch. A gateway answers it as a connector refusal (`data.IGatewayConnectorRefusalErrorData`),
23
+ * and `request-invalid` for a set that fails `data.validateControllerPeerSet`. A relay answers the
24
+ * same two names the way its session states every refusal (`data.applyClusterVpnNetworkRefusals`):
25
+ * the error text leads with `<name>: <reason>` and Cloudly matches the name. A relay refuses a set
26
+ * that fails `data.validateControllerPeerSet` with the validator's sentences and names no refusal:
27
+ * that is Cloudly's defect, and Cloudly has nothing to act on.
28
+ */
29
+ export interface IReq_Cloudly_Any_PushControllerPeerSet extends plugins.typedrequestInterfaces.implementsTR<
30
+ plugins.typedrequestInterfaces.ITypedRequest,
31
+ IReq_Cloudly_Any_PushControllerPeerSet
32
+ > {
33
+ method: 'pushControllerPeerSet';
34
+ request: {
35
+ /** `data.validateControllerPeerSet`. */
36
+ controller: IControllerPeerSet;
37
+ };
38
+ response: {};
39
+ }
40
+
41
+ /**
42
+ * An administrator adds a shadow controller site to the active controller. `origin` is the shadow's
43
+ * site origin, a canonical `https` origin other than the controller's public origin and the active's
44
+ * own site origin; `bearerSha256` is the SHA-256 of the witness bearer that site created for itself,
45
+ * as 64 lowercase hex characters (`data.IEnrollWitnessMemberRequest.bearerSha256`), never the bearer.
46
+ *
47
+ * The active enrolls the site with its witness (`enrollWitnessMember`), then in one transaction sets
48
+ * the peer set's `shadowOrigins` to the witness members other than the active, in the witness's
49
+ * member order, and writes a revision. It answers the peer set it stored, which reaches every
50
+ * dialling component before any later document of its epoch. Running it again after the enrollment
51
+ * was stored and the transaction was not completes it.
52
+ */
53
+ export interface IReq_Admin_Cloudly_AddControllerShadow extends plugins.typedrequestInterfaces.implementsTR<
54
+ plugins.typedrequestInterfaces.ITypedRequest,
55
+ IReq_Admin_Cloudly_AddControllerShadow
56
+ > {
57
+ method: 'addControllerShadow';
58
+ request: {
59
+ identity: IIdentityCredential;
60
+ origin: string;
61
+ bearerSha256: string;
62
+ };
63
+ response: {
64
+ controller: IControllerPeerSet;
65
+ };
66
+ }
@@ -9,6 +9,7 @@ import * as certificateRequests from './certificate.js';
9
9
  import * as clusterRequests from './cluster.js';
10
10
  import * as clusterIngressRequests from './clusteringress.js';
11
11
  import * as configRequests from './config.js';
12
+ import * as controllerRequests from './controller.js';
12
13
  import * as coreMailRequests from './coremail.js';
13
14
  import * as coreMailAdminRequests from './coremail.admin.js';
14
15
  import * as corestoreRequests from './corestore.js';
@@ -53,6 +54,7 @@ export {
53
54
  clusterRequests as cluster,
54
55
  clusterIngressRequests as clusteringress,
55
56
  configRequests as config,
57
+ controllerRequests as controller,
56
58
  coreMailRequests as coremail,
57
59
  coreMailAdminRequests as coremailAdmin,
58
60
  corestoreRequests as corestore,