@serfab/cadre-core 1.23.0 → 1.24.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.
- package/README.md +216 -294
- package/dist/arachnode-stub.d.ts +12 -4
- package/dist/arachnode-stub.js +15 -8
- package/dist/arachnode-stub.js.map +1 -1
- package/dist/cadre-invite-protocol.js +5 -4
- package/dist/cadre-invite-protocol.js.map +1 -1
- package/dist/cadre-node.d.ts +145 -44
- package/dist/cadre-node.js +239 -79
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-authorization.d.ts +14 -2
- package/dist/control-authorization.js +8 -3
- package/dist/control-authorization.js.map +1 -1
- package/dist/control-cohort.d.ts +27 -13
- package/dist/control-cohort.js +21 -14
- package/dist/control-cohort.js.map +1 -1
- package/dist/control-database.d.ts +18 -16
- package/dist/control-database.js +57 -22
- package/dist/control-database.js.map +1 -1
- package/dist/control-protocol-guard.d.ts +1 -1
- package/dist/control-protocol-guard.js +7 -3
- package/dist/control-protocol-guard.js.map +1 -1
- package/dist/control-read-retry.d.ts +49 -11
- package/dist/control-read-retry.js +56 -15
- package/dist/control-read-retry.js.map +1 -1
- package/dist/control-retry.d.ts +32 -3
- package/dist/control-retry.js +35 -4
- package/dist/control-retry.js.map +1 -1
- package/dist/control-schema-version.d.ts +5 -5
- package/dist/control-schema-version.js +5 -5
- package/dist/control-schema-version.js.map +1 -1
- package/dist/control-schema.d.ts +5 -5
- package/dist/control-schema.js +1032 -1011
- package/dist/control-schema.js.map +1 -1
- package/dist/control-write-retry.d.ts +54 -65
- package/dist/control-write-retry.js +134 -158
- package/dist/control-write-retry.js.map +1 -1
- package/dist/delegate-admission.d.ts +1 -1
- package/dist/delegate-admission.js +1 -1
- package/dist/edge-node/config.d.ts +4 -3
- package/dist/edge-node/config.js +11 -9
- package/dist/edge-node/config.js.map +1 -1
- package/dist/edge-node/dissolve.d.ts +4 -4
- package/dist/edge-node/dissolve.js +4 -4
- package/dist/edge-node/edge-join.d.ts +1 -1
- package/dist/edge-node/edge-join.js +1 -1
- package/dist/edge-node/edge-node.js +2 -2
- package/dist/edge-node/edge-node.js.map +1 -1
- package/dist/edge-node/index.d.ts +1 -0
- package/dist/edge-node/index.js +1 -0
- package/dist/edge-node/index.js.map +1 -1
- package/dist/edge-node/join-credential.d.ts +1 -1
- package/dist/edge-node/join-credential.js +1 -1
- package/dist/edge-node/lazy-raw-storage.js +12 -0
- package/dist/edge-node/lazy-raw-storage.js.map +1 -1
- package/dist/edge-node/listen-addrs.d.ts +21 -0
- package/dist/edge-node/listen-addrs.js +25 -0
- package/dist/edge-node/listen-addrs.js.map +1 -0
- package/dist/edge-node/owner-grant.d.ts +1 -1
- package/dist/edge-node/owner-grant.js +1 -1
- package/dist/edge-node/platform.d.ts +5 -4
- package/dist/edge-node/platform.js.map +1 -1
- package/dist/edge-node/strand-move.d.ts +1 -1
- package/dist/edge-node/strand-move.js +1 -1
- package/dist/edge-node/strands.js +27 -11
- package/dist/edge-node/strands.js.map +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/dist/invitation-bootstrap.d.ts +28 -5
- package/dist/invitation-bootstrap.js +41 -8
- package/dist/invitation-bootstrap.js.map +1 -1
- package/dist/link-budget.d.ts +53 -4
- package/dist/link-budget.js +58 -5
- package/dist/link-budget.js.map +1 -1
- package/dist/machine-removal.d.ts +2 -2
- package/dist/machine-removal.js +4 -3
- package/dist/machine-removal.js.map +1 -1
- package/dist/membership-connection-gater.d.ts +2 -2
- package/dist/membership-connection-gater.js +2 -2
- package/dist/membership-view.d.ts +2 -2
- package/dist/membership-view.js +2 -2
- package/dist/node-claim-payload.d.ts +15 -7
- package/dist/node-claim-payload.js +25 -9
- package/dist/node-claim-payload.js.map +1 -1
- package/dist/node-class.d.ts +36 -0
- package/dist/node-class.js +26 -0
- package/dist/node-class.js.map +1 -0
- package/dist/node-default-transports.d.ts +50 -3
- package/dist/node-default-transports.js +48 -3
- package/dist/node-default-transports.js.map +1 -1
- package/dist/node-roles.d.ts +118 -0
- package/dist/node-roles.js +142 -0
- package/dist/node-roles.js.map +1 -0
- package/dist/node-transports.d.ts +6 -2
- package/dist/node-transports.js +39 -7
- package/dist/node-transports.js.map +1 -1
- package/dist/owner-anchor-sync.js +1 -1
- package/dist/owner-key-export.js +1 -1
- package/dist/owner-key-flows.d.ts +1 -1
- package/dist/owner-key-store.js +1 -1
- package/dist/owner-signer.js +1 -1
- package/dist/peer-authorization.d.ts +3 -1
- package/dist/peer-authorization.js +3 -1
- package/dist/peer-authorization.js.map +1 -1
- package/dist/peer-dial.d.ts +74 -10
- package/dist/peer-dial.js +89 -17
- package/dist/peer-dial.js.map +1 -1
- package/dist/peer-join-backfill.js +4 -4
- package/dist/peer-join-backfill.js.map +1 -1
- package/dist/peer-record.d.ts +34 -9
- package/dist/peer-record.js +66 -13
- package/dist/peer-record.js.map +1 -1
- package/dist/pending-join-runner.d.ts +1 -1
- package/dist/pending-join-runner.js +1 -1
- package/dist/provider/client.d.ts +6 -5
- package/dist/provider/client.js +3 -3
- package/dist/provider/client.js.map +1 -1
- package/dist/provider/descriptor.d.ts +1 -1
- package/dist/provider/descriptor.js +1 -1
- package/dist/provider/oauth.d.ts +1 -1
- package/dist/provider/oauth.js +1 -1
- package/dist/provider/rent-node.d.ts +4 -3
- package/dist/provider/rent-node.js +3 -3
- package/dist/provider/rent-node.js.map +1 -1
- package/dist/relay-addrs.d.ts +62 -7
- package/dist/relay-addrs.js +74 -11
- package/dist/relay-addrs.js.map +1 -1
- package/dist/relay-reservation.d.ts +1 -1
- package/dist/relay-reservation.js +1 -1
- package/dist/relay-server.d.ts +6 -5
- package/dist/relay-server.js +5 -5
- package/dist/relay-server.js.map +1 -1
- package/dist/schema-verification.d.ts +13 -10
- package/dist/schema-verification.js +32 -24
- package/dist/schema-verification.js.map +1 -1
- package/dist/sealed-party-key.js +1 -1
- package/dist/seed-bootstrap.d.ts +4 -3
- package/dist/seed-bootstrap.js +6 -7
- package/dist/seed-bootstrap.js.map +1 -1
- package/dist/strand-addr-protocol.d.ts +8 -6
- package/dist/strand-addr-protocol.js +12 -10
- package/dist/strand-addr-protocol.js.map +1 -1
- package/dist/strand-app-schema-report.d.ts +16 -2
- package/dist/strand-app-schema-report.js +15 -0
- package/dist/strand-app-schema-report.js.map +1 -1
- package/dist/strand-cohort.d.ts +1 -4
- package/dist/strand-cohort.js.map +1 -1
- package/dist/strand-commit-durability.d.ts +1 -1
- package/dist/strand-database.d.ts +13 -6
- package/dist/strand-database.js +17 -9
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-first-sync-gate.d.ts +3 -2
- package/dist/strand-first-sync-gate.js +3 -2
- package/dist/strand-first-sync-gate.js.map +1 -1
- package/dist/strand-formation-deadlines.d.ts +2 -2
- package/dist/strand-formation-deadlines.js +2 -2
- package/dist/strand-formation-protocol.d.ts +1 -1
- package/dist/strand-formation-protocol.js +51 -16
- package/dist/strand-formation-protocol.js.map +1 -1
- package/dist/strand-instance-manager.d.ts +67 -33
- package/dist/strand-instance-manager.js +164 -55
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-membership-reconciler.d.ts +8 -3
- package/dist/strand-membership-reconciler.js +8 -3
- package/dist/strand-membership-reconciler.js.map +1 -1
- package/dist/strand-membership-writer.d.ts +2 -2
- package/dist/strand-membership-writer.js +41 -39
- package/dist/strand-membership-writer.js.map +1 -1
- package/dist/strand-move.js +1 -1
- package/dist/strand-network-config.d.ts +15 -5
- package/dist/strand-network-config.js +7 -6
- package/dist/strand-network-config.js.map +1 -1
- package/dist/strand-party-key-rotation.d.ts +7 -3
- package/dist/strand-party-key-rotation.js +7 -3
- package/dist/strand-party-key-rotation.js.map +1 -1
- package/dist/strand-party-machines.d.ts +19 -8
- package/dist/strand-party-machines.js +26 -11
- package/dist/strand-party-machines.js.map +1 -1
- package/dist/strand-party-peers.d.ts +36 -14
- package/dist/strand-party-peers.js +24 -15
- package/dist/strand-party-peers.js.map +1 -1
- package/dist/strand-peer-redial.d.ts +1 -1
- package/dist/strand-peer-redial.js +1 -1
- package/dist/strand-reactivity.d.ts +20 -17
- package/dist/strand-reactivity.js +31 -18
- package/dist/strand-reactivity.js.map +1 -1
- package/dist/strand-revocation-enforcer.d.ts +3 -3
- package/dist/strand-revocation-enforcer.js +3 -3
- package/dist/strand-wake-protocol.d.ts +19 -7
- package/dist/strand-wake-protocol.js +22 -10
- package/dist/strand-wake-protocol.js.map +1 -1
- package/dist/strand-watcher.d.ts +1 -1
- package/dist/strand-watcher.js +1 -1
- package/dist/table-change-watch.js +1 -1
- package/dist/types.d.ts +116 -55
- package/dist/types.js.map +1 -1
- package/dist/webrtc-upgrade.d.ts +254 -0
- package/dist/webrtc-upgrade.js +355 -0
- package/dist/webrtc-upgrade.js.map +1 -0
- package/package.json +9 -9
- package/src/announce-addrs.ts +93 -93
- package/src/arachnode-stub.ts +18 -10
- package/src/bootstrap-peer-store-file.ts +44 -44
- package/src/bootstrap-peer-store.ts +214 -214
- package/src/cadre-invite-protocol.ts +741 -740
- package/src/cadre-node.ts +12462 -12280
- package/src/claim-proof.ts +147 -147
- package/src/control-authorization.ts +290 -276
- package/src/control-cohort.ts +223 -204
- package/src/control-database.ts +72 -28
- package/src/control-formation-recorder.ts +359 -359
- package/src/control-protocol-guard.ts +370 -366
- package/src/control-read-retry.ts +222 -180
- package/src/control-retry.ts +36 -4
- package/src/control-schema-version.ts +301 -301
- package/src/control-schema.ts +1108 -1087
- package/src/control-write-retry.ts +639 -669
- package/src/delegate-admission.ts +351 -351
- package/src/describe-thrown.ts +60 -60
- package/src/ed25519-key.ts +185 -185
- package/src/edge-node/config.ts +13 -10
- package/src/edge-node/dissolve.ts +252 -252
- package/src/edge-node/edge-join.ts +320 -320
- package/src/edge-node/edge-node.ts +1095 -1095
- package/src/edge-node/index.ts +60 -59
- package/src/edge-node/join-credential.ts +16 -16
- package/src/edge-node/lazy-raw-storage.ts +194 -178
- package/src/edge-node/listen-addrs.ts +26 -0
- package/src/edge-node/node-local.ts +84 -84
- package/src/edge-node/options.ts +195 -195
- package/src/edge-node/owner-grant.ts +63 -63
- package/src/edge-node/platform.ts +5 -4
- package/src/edge-node/strand-move.ts +266 -266
- package/src/edge-node/strands.ts +27 -12
- package/src/enrolled-machine-store-file.ts +43 -43
- package/src/enrolled-machine-store.ts +280 -280
- package/src/fetch-impl.ts +23 -23
- package/src/file-durable-slot.ts +64 -64
- package/src/file-safe-name.ts +32 -32
- package/src/formation-approval.ts +604 -604
- package/src/formation-token.ts +63 -63
- package/src/fs-atomic.ts +92 -92
- package/src/index.ts +987 -957
- package/src/invitation-bootstrap.ts +152 -118
- package/src/joined-strand-store.ts +553 -553
- package/src/key-store-file.ts +142 -142
- package/src/link-budget.ts +61 -5
- package/src/machine-removal.ts +211 -210
- package/src/member-redemption.ts +643 -643
- package/src/membership-connection-gater.ts +650 -650
- package/src/membership-view.ts +147 -147
- package/src/node-claim-payload.ts +34 -12
- package/src/node-class.ts +47 -0
- package/src/node-default-transports.ts +65 -3
- package/src/node-roles.ts +220 -0
- package/src/node-transports.ts +86 -49
- package/src/owner-anchor-sync.ts +172 -172
- package/src/owner-grant-protocol.ts +547 -547
- package/src/owner-key-export.ts +348 -348
- package/src/owner-key-flows.ts +109 -109
- package/src/owner-key-store.ts +1 -1
- package/src/owner-keys.ts +179 -179
- package/src/owner-signer.ts +92 -92
- package/src/peer-addr-book.ts +252 -252
- package/src/peer-authorization.ts +584 -582
- package/src/peer-dial.ts +698 -605
- package/src/peer-join-backfill.ts +961 -961
- package/src/peer-record.ts +71 -16
- package/src/pending-join-runner.ts +798 -798
- package/src/primary-lan-address.ts +47 -47
- package/src/provider/client.ts +327 -326
- package/src/provider/descriptor.ts +129 -129
- package/src/provider/index.ts +59 -59
- package/src/provider/oauth.ts +285 -285
- package/src/provider/rent-node.ts +276 -275
- package/src/relay-addrs.ts +90 -12
- package/src/relay-reservation.ts +1 -1
- package/src/relay-server.ts +99 -98
- package/src/schema-verification.ts +38 -23
- package/src/sealed-party-key.ts +190 -190
- package/src/seed-bootstrap.ts +8 -11
- package/src/seed-trust-policy.ts +353 -353
- package/src/self-address-update.ts +19 -19
- package/src/strand-addr-protocol.ts +17 -14
- package/src/strand-app-schema-report.ts +147 -122
- package/src/strand-cohort.ts +1 -5
- package/src/strand-commit-durability.ts +165 -165
- package/src/strand-database.ts +522 -510
- package/src/strand-first-sync-gate.ts +3 -2
- package/src/strand-formation-deadlines.ts +227 -227
- package/src/strand-formation-manager.ts +731 -731
- package/src/strand-formation-protocol.ts +1174 -1138
- package/src/strand-fret-addrs.ts +179 -179
- package/src/strand-instance-manager.ts +188 -63
- package/src/strand-membership-reconciler.ts +1315 -1310
- package/src/strand-membership-writer.ts +2152 -2150
- package/src/strand-move.ts +1 -1
- package/src/strand-network-config.ts +16 -6
- package/src/strand-offline.ts +178 -178
- package/src/strand-party-key-rotation.ts +440 -436
- package/src/strand-party-machines.ts +308 -293
- package/src/strand-party-peers.ts +151 -129
- package/src/strand-peer-redial.ts +1 -1
- package/src/strand-reactivity.ts +36 -19
- package/src/strand-revocation-enforcer.ts +758 -758
- package/src/strand-wake-protocol.ts +406 -394
- package/src/strand-watcher.ts +1 -1
- package/src/table-change-watch.ts +285 -285
- package/src/timed-step.ts +28 -28
- package/src/timeout-scheduler.ts +29 -29
- package/src/trusted-owner-store.ts +242 -242
- package/src/types.ts +3182 -3121
- package/src/webrtc-upgrade.ts +439 -0
|
@@ -157,6 +157,13 @@ export interface OwnerGrantSignedFields {
|
|
|
157
157
|
* coalesce(cast(new.ExpiresAt as text), ''), coalesce(cast(new.TotalUses as text), ''), new.StampId`.
|
|
158
158
|
*/
|
|
159
159
|
export declare function ownerGrantRowFields(row: OwnerGrantSignedFields): string[];
|
|
160
|
+
/**
|
|
161
|
+
* What a machine states about its part in one strand on its `CadreControl.StrandPeer` row.
|
|
162
|
+
* `'client'`: it runs the strand without storing any of its blocks (`NodeRoles.strandCohortMember`
|
|
163
|
+
* off). A serving machine states no role (`null` on the row), which is also what every row written
|
|
164
|
+
* before the column existed means. The schema's `KnownStrandPeerRole` check admits the same values.
|
|
165
|
+
*/
|
|
166
|
+
export type StrandPeerRole = 'client';
|
|
160
167
|
/**
|
|
161
168
|
* The `StrandPeer` columns its `'add'` signature binds, in the schema's order. Structurally
|
|
162
169
|
* satisfied by a `StrandPeerRow` (`types.ts`), which adds the signature itself.
|
|
@@ -165,12 +172,17 @@ export interface StrandPeerSignedFields {
|
|
|
165
172
|
strandId: string;
|
|
166
173
|
peerId: string;
|
|
167
174
|
strandPeerId: string;
|
|
175
|
+
role: StrandPeerRole | null;
|
|
168
176
|
}
|
|
169
177
|
/**
|
|
170
178
|
* The row-field half of a `StrandPeer` `'add'` digest, shared by the signer
|
|
171
179
|
* (`ControlDatabase.insertStrandPeer`) and the verifier (`peer-authorization.ts`'s
|
|
172
|
-
* `strandPeerAddDigest`).
|
|
173
|
-
* `new.StrandId, new.PeerId, new.StrandPeerId
|
|
180
|
+
* `strandPeerAddDigest`). Two forms, chosen by the row's own role, mirroring the two branches
|
|
181
|
+
* of `StrandPeer.Authorized`: `new.StrandId, new.PeerId, new.StrandPeerId` when `role` is
|
|
182
|
+
* null, the form every row before control schema version 5 was signed over, and the same with
|
|
183
|
+
* `new.Role` appended when it is set. The framed digest is injective over its field list, so a
|
|
184
|
+
* row signed over one form never verifies against the other; the schema's `StrandPeer` comment
|
|
185
|
+
* says why the null form is kept rather than digesting `coalesce(Role, '')`.
|
|
174
186
|
*/
|
|
175
187
|
export declare function strandPeerRowFields(row: StrandPeerSignedFields): string[];
|
|
176
188
|
/** The `PendingStrandPartyKey` columns its `'add'` signature binds, in the schema's order and with the row's stored forms. */
|
|
@@ -100,11 +100,16 @@ export function ownerGrantRowFields(row) {
|
|
|
100
100
|
/**
|
|
101
101
|
* The row-field half of a `StrandPeer` `'add'` digest, shared by the signer
|
|
102
102
|
* (`ControlDatabase.insertStrandPeer`) and the verifier (`peer-authorization.ts`'s
|
|
103
|
-
* `strandPeerAddDigest`).
|
|
104
|
-
* `new.StrandId, new.PeerId, new.StrandPeerId
|
|
103
|
+
* `strandPeerAddDigest`). Two forms, chosen by the row's own role, mirroring the two branches
|
|
104
|
+
* of `StrandPeer.Authorized`: `new.StrandId, new.PeerId, new.StrandPeerId` when `role` is
|
|
105
|
+
* null, the form every row before control schema version 5 was signed over, and the same with
|
|
106
|
+
* `new.Role` appended when it is set. The framed digest is injective over its field list, so a
|
|
107
|
+
* row signed over one form never verifies against the other; the schema's `StrandPeer` comment
|
|
108
|
+
* says why the null form is kept rather than digesting `coalesce(Role, '')`.
|
|
105
109
|
*/
|
|
106
110
|
export function strandPeerRowFields(row) {
|
|
107
|
-
|
|
111
|
+
const fields = [row.strandId, row.peerId, row.strandPeerId];
|
|
112
|
+
return row.role === null ? fields : [...fields, row.role];
|
|
108
113
|
}
|
|
109
114
|
/**
|
|
110
115
|
* The row-field half of a `PendingStrandPartyKey` `'add'` digest. SQL mirror, in
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-authorization.js","sourceRoot":"","sources":["../src/control-authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,UAAU;IACV,eAAe;IACf,QAAQ;IACR,gBAAgB;IAChB,uBAAuB;IACvB,cAAc;IACd,aAAa;IACb,aAAa;IACb,aAAa;IACb,WAAW;IACX,aAAa;IACb,YAAY;IACZ,iBAAiB;IACjB,gBAAgB;IAChB,aAAa;IACb,kBAAkB;IAClB,YAAY;IACZ,iBAAiB;IACjB,YAAY;CACJ,CAAC;AA2FX;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAA4B;IAC/D,OAAO;QACL,GAAG,CAAC,GAAG;QACP,GAAG,CAAC,MAAM,IAAI,EAAE;QAChB,GAAG,CAAC,SAAS,IAAI,EAAE;QACnB,GAAG,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;QACnD,GAAG,CAAC,OAAO;KACZ,CAAC;AACJ,CAAC;AAiBD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAA2B;IAC7D,OAAO;QACL,GAAG,CAAC,GAAG;QACP,GAAG,CAAC,KAAK,IAAI,EAAE;QACf,GAAG,CAAC,SAAS,IAAI,EAAE;QACnB,GAAG,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;QACnD,GAAG,CAAC,OAAO;KACZ,CAAC;AACJ,CAAC;
|
|
1
|
+
{"version":3,"file":"control-authorization.js","sourceRoot":"","sources":["../src/control-authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,UAAU;IACV,eAAe;IACf,QAAQ;IACR,gBAAgB;IAChB,uBAAuB;IACvB,cAAc;IACd,aAAa;IACb,aAAa;IACb,aAAa;IACb,WAAW;IACX,aAAa;IACb,YAAY;IACZ,iBAAiB;IACjB,gBAAgB;IAChB,aAAa;IACb,kBAAkB;IAClB,YAAY;IACZ,iBAAiB;IACjB,YAAY;CACJ,CAAC;AA2FX;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAA4B;IAC/D,OAAO;QACL,GAAG,CAAC,GAAG;QACP,GAAG,CAAC,MAAM,IAAI,EAAE;QAChB,GAAG,CAAC,SAAS,IAAI,EAAE;QACnB,GAAG,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;QACnD,GAAG,CAAC,OAAO;KACZ,CAAC;AACJ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
|
package/dist/control-cohort.d.ts
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
* connected (and thus replicating), without devolving into an N² mesh.
|
|
6
6
|
*
|
|
7
7
|
* FRET only needs a *connected* graph with the block clusters reachable, not a
|
|
8
|
-
* full mesh. Always-on
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* full mesh. Always-on machines are the stable, dialable backbone that hold the
|
|
9
|
+
* control blocks, so the policy is **backbone-preferential with a bounded
|
|
10
|
+
* out-degree**:
|
|
11
11
|
*
|
|
12
12
|
* - **Always dial every backbone (always-on) member** — a party runs few of them,
|
|
13
13
|
* and they are the machines that stay reachable while phones sleep or roam.
|
|
14
|
-
* - **Fill the remainder** up to `targetDegree` with the other members (
|
|
15
|
-
* and machines that have not yet published
|
|
14
|
+
* - **Fill the remainder** up to `targetDegree` with the other members (devices,
|
|
15
|
+
* and machines that have not yet published whether they are always on), ordered
|
|
16
16
|
* deterministically (peerId sort) so every node makes the same stable choice
|
|
17
17
|
* across passes and load spreads predictably.
|
|
18
18
|
*
|
|
@@ -21,6 +21,21 @@
|
|
|
21
21
|
* party it bounds out-degree to `backbone + targetDegree`.
|
|
22
22
|
*/
|
|
23
23
|
import type { CohortPeerRow } from './strand-cohort.js';
|
|
24
|
+
import type { CadrePeerRow } from './types.js';
|
|
25
|
+
/**
|
|
26
|
+
* A sibling as this policy judges it: its addressing row plus the backbone fact, decoded from
|
|
27
|
+
* the stored `CadrePeer.Profile` code by {@link controlCohortSiblingsOf}. Required, not
|
|
28
|
+
* optional, so a caller cannot hand the policy raw rows and silently get no backbone.
|
|
29
|
+
*/
|
|
30
|
+
export interface ControlCohortSibling extends CohortPeerRow {
|
|
31
|
+
/** Whether the machine declared itself always on; null until it self-publishes. */
|
|
32
|
+
alwaysOn: boolean | null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Live `CadrePeer` rows as this policy reads them — the one place the stored `Profile` code
|
|
36
|
+
* reaches a dial decision, so no policy compares it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function controlCohortSiblingsOf(rows: readonly CadrePeerRow[]): ControlCohortSibling[];
|
|
24
39
|
/**
|
|
25
40
|
* Default backstop for {@link CadreNode.reconcileControlCohort} (ms): a pass runs this long
|
|
26
41
|
* after the last one settled whether or not anything woke it. Passes normally run on a
|
|
@@ -74,7 +89,7 @@ export interface ControlCohortSelection {
|
|
|
74
89
|
* Still includes peers that may turn out to be already-connected — the caller
|
|
75
90
|
* diffs against live connections separately.
|
|
76
91
|
*/
|
|
77
|
-
dials:
|
|
92
|
+
dials: ControlCohortSibling[];
|
|
78
93
|
/** Non-backbone members dropped by the `targetDegree` cap (0 when none). */
|
|
79
94
|
cappedNonBackbone: number;
|
|
80
95
|
}
|
|
@@ -95,17 +110,16 @@ export interface ControlCohortReconcileResult {
|
|
|
95
110
|
* Backbone-preferential, bounded-out-degree selection of control-cohort siblings
|
|
96
111
|
* to dial.
|
|
97
112
|
*
|
|
98
|
-
* A member is **backbone** iff its `CadrePeer` row declares
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* misdeclaring one costs extra dials, never access.
|
|
113
|
+
* A member is **backbone** iff its `CadrePeer` row declares it always on. All
|
|
114
|
+
* backbone members are selected; the rest fill up to `targetDegree` in
|
|
115
|
+
* deterministic peerId order. A member that has not self-published yet is not
|
|
116
|
+
* backbone until it does. Being always on is a dial preference only: it is
|
|
117
|
+
* self-declared, and a machine misdeclaring it costs extra dials, never access.
|
|
104
118
|
*
|
|
105
119
|
* @param siblings - cadre members EXCLUDING self (the caller filters self out).
|
|
106
120
|
* @param targetDegree - cap on non-backbone dials (negative is treated as 0).
|
|
107
121
|
*/
|
|
108
|
-
export declare function selectControlCohortDials(siblings:
|
|
122
|
+
export declare function selectControlCohortDials(siblings: ControlCohortSibling[], targetDegree: number): ControlCohortSelection;
|
|
109
123
|
/** What {@link nextReconcileWakeMs} decides from, all times epoch milliseconds. */
|
|
110
124
|
export interface ReconcileWakeInput {
|
|
111
125
|
/**
|
package/dist/control-cohort.js
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
* connected (and thus replicating), without devolving into an N² mesh.
|
|
6
6
|
*
|
|
7
7
|
* FRET only needs a *connected* graph with the block clusters reachable, not a
|
|
8
|
-
* full mesh. Always-on
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* full mesh. Always-on machines are the stable, dialable backbone that hold the
|
|
9
|
+
* control blocks, so the policy is **backbone-preferential with a bounded
|
|
10
|
+
* out-degree**:
|
|
11
11
|
*
|
|
12
12
|
* - **Always dial every backbone (always-on) member** — a party runs few of them,
|
|
13
13
|
* and they are the machines that stay reachable while phones sleep or roam.
|
|
14
|
-
* - **Fill the remainder** up to `targetDegree` with the other members (
|
|
15
|
-
* and machines that have not yet published
|
|
14
|
+
* - **Fill the remainder** up to `targetDegree` with the other members (devices,
|
|
15
|
+
* and machines that have not yet published whether they are always on), ordered
|
|
16
16
|
* deterministically (peerId sort) so every node makes the same stable choice
|
|
17
17
|
* across passes and load spreads predictably.
|
|
18
18
|
*
|
|
@@ -20,6 +20,14 @@
|
|
|
20
20
|
* correct, cheap, and matches what the convergence tests do by hand; for a large
|
|
21
21
|
* party it bounds out-degree to `backbone + targetDegree`.
|
|
22
22
|
*/
|
|
23
|
+
import { decodeAlwaysOn } from './node-class.js';
|
|
24
|
+
/**
|
|
25
|
+
* Live `CadrePeer` rows as this policy reads them — the one place the stored `Profile` code
|
|
26
|
+
* reaches a dial decision, so no policy compares it.
|
|
27
|
+
*/
|
|
28
|
+
export function controlCohortSiblingsOf(rows) {
|
|
29
|
+
return rows.map(({ peerId, multiaddr, profile }) => ({ peerId, multiaddr, alwaysOn: decodeAlwaysOn(profile) }));
|
|
30
|
+
}
|
|
23
31
|
/**
|
|
24
32
|
* Default backstop for {@link CadreNode.reconcileControlCohort} (ms): a pass runs this long
|
|
25
33
|
* after the last one settled whether or not anything woke it. Passes normally run on a
|
|
@@ -77,12 +85,11 @@ function byPeerId(a, b) {
|
|
|
77
85
|
* Backbone-preferential, bounded-out-degree selection of control-cohort siblings
|
|
78
86
|
* to dial.
|
|
79
87
|
*
|
|
80
|
-
* A member is **backbone** iff its `CadrePeer` row declares
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* misdeclaring one costs extra dials, never access.
|
|
88
|
+
* A member is **backbone** iff its `CadrePeer` row declares it always on. All
|
|
89
|
+
* backbone members are selected; the rest fill up to `targetDegree` in
|
|
90
|
+
* deterministic peerId order. A member that has not self-published yet is not
|
|
91
|
+
* backbone until it does. Being always on is a dial preference only: it is
|
|
92
|
+
* self-declared, and a machine misdeclaring it costs extra dials, never access.
|
|
86
93
|
*
|
|
87
94
|
* @param siblings - cadre members EXCLUDING self (the caller filters self out).
|
|
88
95
|
* @param targetDegree - cap on non-backbone dials (negative is treated as 0).
|
|
@@ -91,10 +98,10 @@ export function selectControlCohortDials(siblings, targetDegree) {
|
|
|
91
98
|
const backbone = [];
|
|
92
99
|
const rest = [];
|
|
93
100
|
// NOTE: the backbone is uncapped, so out-degree grows with the number of always-on
|
|
94
|
-
// machines (and with any sibling that declares
|
|
95
|
-
// ever runs more than a handful, cap the backbone too.
|
|
101
|
+
// machines (and with any sibling that declares itself always on without being one); if a
|
|
102
|
+
// party ever runs more than a handful, cap the backbone too.
|
|
96
103
|
for (const peer of siblings) {
|
|
97
|
-
if (peer.
|
|
104
|
+
if (peer.alwaysOn === true) {
|
|
98
105
|
backbone.push(peer);
|
|
99
106
|
}
|
|
100
107
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-cohort.js","sourceRoot":"","sources":["../src/control-cohort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;
|
|
1
|
+
{"version":3,"file":"control-cohort.js","sourceRoot":"","sources":["../src/control-cohort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;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;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -2,8 +2,9 @@ import { Database } from '@quereus/quereus';
|
|
|
2
2
|
import type { SqlParameters } from '@quereus/quereus';
|
|
3
3
|
import type { Libp2p } from '@libp2p/interface';
|
|
4
4
|
import type { IRepo } from '@optimystic/db-core';
|
|
5
|
-
import type { StrandRow, StrandPeerRow, PendingStrandPartyKeyRow, SealedPendingPartyKey, JoinRequestRow, JoinOutcome, PendingJoin,
|
|
6
|
-
import type {
|
|
5
|
+
import type { StrandRow, StrandPeerRow, PendingStrandPartyKeyRow, SealedPendingPartyKey, JoinRequestRow, JoinOutcome, PendingJoin, PeerAddressRecord, CadrePeerRow, OwnerKeyRow, RevocationRow, DeviceTokenRecord, DeviceTokenRow, CadreInviteRow, CadreInviteUsageRow, CadreInviteRedemptionResult, CadreInviteStatus, OwnerGrantRow, OwnerGrantUsageRow, OwnerGrantRedemptionResult, OwnerGrantStatus, SeedPeer, MachineRemovalWrites } from './types.js';
|
|
6
|
+
import type { PublishedProfile } from './node-class.js';
|
|
7
|
+
import type { ControlTable, RevocableTable, BoundControlDomain, ControlAction, CadreInviteSignedFields, OwnerGrantSignedFields, StrandPeerSignedFields } from './control-authorization.js';
|
|
7
8
|
import type { ControlWriteRetryOptions } from './control-write-retry.js';
|
|
8
9
|
import type { ControlRetryAbandonment } from './control-retry.js';
|
|
9
10
|
import type { TableChangeWatch, TableChangeWatchOptions } from './table-change-watch.js';
|
|
@@ -466,10 +467,10 @@ export declare class PendingJoinChangedError extends Error {
|
|
|
466
467
|
*
|
|
467
468
|
* A peer is `preferred` when it is the minter, the one machine certain to be reachable by the
|
|
468
469
|
* receiver at that moment, since it is delivering the seed or the reply, or an always-on
|
|
469
|
-
* machine
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
470
|
+
* machine, the ones that stay dialable. Preference is a dial hint and reads no `OwnerKey` row:
|
|
471
|
+
* owner keys are not machines, and a receiver derives trust from its own anchor, never from
|
|
472
|
+
* this list. Being always on is self-declared and not checked here, so a machine misdeclaring
|
|
473
|
+
* it costs the receiver a wasted dial at most.
|
|
473
474
|
*/
|
|
474
475
|
export declare function projectSeedPeers(rows: readonly CadrePeerRow[], minterPeerId: string): SeedPeer[];
|
|
475
476
|
/**
|
|
@@ -1642,20 +1643,21 @@ export declare class ControlDatabase {
|
|
|
1642
1643
|
/** The `StrandPartyKey` row stored for `strandId` with its stamp, for a locked write body (`retry: false`), or null. */
|
|
1643
1644
|
private readStoredPartyKey;
|
|
1644
1645
|
/**
|
|
1645
|
-
* Publish this machine's peer id in one strand
|
|
1646
|
-
*
|
|
1647
|
-
*
|
|
1648
|
-
* the
|
|
1646
|
+
* Publish this machine's peer id in one strand, and whether it serves the strand (`StrandPeer`
|
|
1647
|
+
* row), signed by this machine's own identity key in the form its role selects
|
|
1648
|
+
* (`strandPeerRowFields`). Insert-if-absent: `true` when a row was written, `false` when this
|
|
1649
|
+
* machine already has one for the strand. The row is immutable, so a held row stands even when
|
|
1650
|
+
* its role differs from `row.role`; that case is logged ({@link logHeldStrandPeer}). The schema
|
|
1651
|
+
* refuses the insert while this node does not hold the machine's `CadrePeer` row, and that
|
|
1652
|
+
* rejection propagates.
|
|
1649
1653
|
*
|
|
1650
|
-
* @param row - The strand,
|
|
1654
|
+
* @param row - The strand, this machine's peer id in it (`strandTransportKey`), and its role
|
|
1655
|
+
* there: `'client'` when it stores none of the strand, null when it serves it.
|
|
1651
1656
|
* @param sign - Signs the raw message bytes with the identity key behind this machine's
|
|
1652
1657
|
* control peer id. A callback for the reason {@link updateSelfPeerRecord} takes one: this
|
|
1653
1658
|
* class holds no private key.
|
|
1654
1659
|
*/
|
|
1655
|
-
insertStrandPeer(row:
|
|
1656
|
-
strandId: string;
|
|
1657
|
-
strandPeerId: string;
|
|
1658
|
-
}, sign: ControlSign): Promise<boolean>;
|
|
1660
|
+
insertStrandPeer(row: Omit<StrandPeerSignedFields, 'peerId'>, sign: ControlSign): Promise<boolean>;
|
|
1659
1661
|
/**
|
|
1660
1662
|
* Record, party-wide, a strand this party joined from another party (`JoinedStrand` row),
|
|
1661
1663
|
* using an owner signature.
|
|
@@ -1807,7 +1809,7 @@ export declare class ControlDatabase {
|
|
|
1807
1809
|
multiaddr: string;
|
|
1808
1810
|
updatedAt: number;
|
|
1809
1811
|
sig: string | null;
|
|
1810
|
-
profile:
|
|
1812
|
+
profile: PublishedProfile | null;
|
|
1811
1813
|
}, ownerKey: string, signMessage: ControlSign): Promise<boolean>;
|
|
1812
1814
|
/**
|
|
1813
1815
|
* Owner "re-touch" of an existing `CadrePeer` membership row: rewrite `VouchOwner`/`VouchSig`
|
package/dist/control-database.js
CHANGED
|
@@ -7,6 +7,7 @@ import { digest, randomBytes } from '@optimystic/quereus-plugin-crypto';
|
|
|
7
7
|
import { createEmptyCollections } from '@serfab/quereus-plugin-sereus';
|
|
8
8
|
import { APPLY_CONTROL_SCHEMA, CONTROL_SCHEMA_DECLARATION, CONTROL_SCHEMA_NAME, controlSchemaFileDeclaration } from './control-schema.js';
|
|
9
9
|
import { refuseIncompatibleControlStore } from './control-schema-version.js';
|
|
10
|
+
import { decodeAlwaysOn } from './node-class.js';
|
|
10
11
|
import { canonicalDatetime } from './canonical-datetime.js';
|
|
11
12
|
import { controlAuthorizationFields, unboundAuthorizationFields, cadreInviteRowFields, ownerGrantRowFields, strandPeerRowFields, pendingStrandPartyKeyRowFields, CONTROL_TABLES } from './control-authorization.js';
|
|
12
13
|
import { requireEd25519PublicKeyB64 } from './ed25519-key.js';
|
|
@@ -397,6 +398,43 @@ function pendingPartyKeyOfRow(row) {
|
|
|
397
398
|
stampId: row.StampId,
|
|
398
399
|
};
|
|
399
400
|
}
|
|
401
|
+
/** The columns every `StrandPeer` read takes, as {@link strandPeerRowOf} maps them. */
|
|
402
|
+
const STRAND_PEER_COLUMNS = 'StrandId, PeerId, StrandPeerId, Role, Sig';
|
|
403
|
+
/**
|
|
404
|
+
* A stored `StrandPeer.Role` as this build knows it. Null, and a row written before the column
|
|
405
|
+
* existed, read as a serving machine's. A value this build does not know also reads as null, and
|
|
406
|
+
* the row then fails {@link verifyStrandPeerRow}, whose digest omits a null role, and is dropped:
|
|
407
|
+
* a reader acts only on roles it knows, as a version-4 reader drops a row marked `'client'`. Such
|
|
408
|
+
* a value reaches a store only from a machine that bypassed its own `KnownStrandPeerRole` check,
|
|
409
|
+
* or from a later schema version that adds one.
|
|
410
|
+
*/
|
|
411
|
+
function strandPeerRoleOf(value) {
|
|
412
|
+
return value === 'client' ? value : null;
|
|
413
|
+
}
|
|
414
|
+
/** A stored `StrandPeer` row as {@link StrandPeerRow}. */
|
|
415
|
+
function strandPeerRowOf(row) {
|
|
416
|
+
return {
|
|
417
|
+
strandId: row.StrandId,
|
|
418
|
+
peerId: row.PeerId,
|
|
419
|
+
strandPeerId: row.StrandPeerId,
|
|
420
|
+
role: strandPeerRoleOf(row.Role),
|
|
421
|
+
sig: row.Sig,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
/** How a `StrandPeer` role reads in a log line: the null role is the serving machine's. */
|
|
425
|
+
const strandPeerRoleName = (role) => role ?? 'serving';
|
|
426
|
+
/**
|
|
427
|
+
* The "already present" line of {@link ControlDatabase.insertStrandPeer}. The row is immutable, so
|
|
428
|
+
* when the held row states a role other than the one this machine now publishes, the line names
|
|
429
|
+
* both: the stored role stands until the machine is removed and re-added.
|
|
430
|
+
*/
|
|
431
|
+
function logHeldStrandPeer(held, role) {
|
|
432
|
+
if (held.role === role) {
|
|
433
|
+
log('StrandPeer row already present for strand %s (names %s); insert skipped', held.strandId, held.strandPeerId);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
log('StrandPeer row already present for strand %s (names %s) and states role %s; this machine now publishes role %s, and the row cannot be changed; insert skipped', held.strandId, held.strandPeerId, strandPeerRoleName(held.role), strandPeerRoleName(role));
|
|
437
|
+
}
|
|
400
438
|
/**
|
|
401
439
|
* The exact bytes an owner signs to append one `Revocation` tombstone — `Revocation.Authorized`
|
|
402
440
|
* binds the whole (TableName, RowKey, StampId) row under its own domain tag. Shared by both
|
|
@@ -534,16 +572,16 @@ function errorChainMatches(error, pattern) {
|
|
|
534
572
|
*
|
|
535
573
|
* A peer is `preferred` when it is the minter, the one machine certain to be reachable by the
|
|
536
574
|
* receiver at that moment, since it is delivering the seed or the reply, or an always-on
|
|
537
|
-
* machine
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
575
|
+
* machine, the ones that stay dialable. Preference is a dial hint and reads no `OwnerKey` row:
|
|
576
|
+
* owner keys are not machines, and a receiver derives trust from its own anchor, never from
|
|
577
|
+
* this list. Being always on is self-declared and not checked here, so a machine misdeclaring
|
|
578
|
+
* it costs the receiver a wasted dial at most.
|
|
541
579
|
*/
|
|
542
580
|
export function projectSeedPeers(rows, minterPeerId) {
|
|
543
581
|
return rows.map(({ peerId, multiaddr, profile }) => ({
|
|
544
582
|
peerId,
|
|
545
583
|
multiaddrs: multiaddr ? multiaddr.split(',') : [],
|
|
546
|
-
preferred: peerId === minterPeerId || profile ===
|
|
584
|
+
preferred: peerId === minterPeerId || decodeAlwaysOn(profile) === true,
|
|
547
585
|
}));
|
|
548
586
|
}
|
|
549
587
|
/**
|
|
@@ -1815,15 +1853,8 @@ export class ControlDatabase {
|
|
|
1815
1853
|
* composite-key seek rather than a secondary index, which would restore the seek dependency.
|
|
1816
1854
|
*/
|
|
1817
1855
|
async readStrandPeerRows(strandId, retry) {
|
|
1818
|
-
const rows = await this.readRows(
|
|
1819
|
-
return rows
|
|
1820
|
-
.filter((row) => row.StrandId === strandId)
|
|
1821
|
-
.map((row) => ({
|
|
1822
|
-
strandId,
|
|
1823
|
-
peerId: row.PeerId,
|
|
1824
|
-
strandPeerId: row.StrandPeerId,
|
|
1825
|
-
sig: row.Sig,
|
|
1826
|
-
}));
|
|
1856
|
+
const rows = await this.readRows(`select ${STRAND_PEER_COLUMNS} from CadreControl.StrandPeer where StrandId = ?`, [strandId], 'strand-peers', retry);
|
|
1857
|
+
return rows.filter((row) => row.StrandId === strandId).map(strandPeerRowOf);
|
|
1827
1858
|
}
|
|
1828
1859
|
/** `ValidationKey` stamp nonce — bound into {@link deleteValidationKey}'s remove digest. */
|
|
1829
1860
|
queryValidationKeyStampId(key) {
|
|
@@ -2808,12 +2839,16 @@ export class ControlDatabase {
|
|
|
2808
2839
|
return row === undefined ? null : { privateKey: row.PrivateKey, stampId: row.StampId };
|
|
2809
2840
|
}
|
|
2810
2841
|
/**
|
|
2811
|
-
* Publish this machine's peer id in one strand
|
|
2812
|
-
*
|
|
2813
|
-
*
|
|
2814
|
-
* the
|
|
2842
|
+
* Publish this machine's peer id in one strand, and whether it serves the strand (`StrandPeer`
|
|
2843
|
+
* row), signed by this machine's own identity key in the form its role selects
|
|
2844
|
+
* (`strandPeerRowFields`). Insert-if-absent: `true` when a row was written, `false` when this
|
|
2845
|
+
* machine already has one for the strand. The row is immutable, so a held row stands even when
|
|
2846
|
+
* its role differs from `row.role`; that case is logged ({@link logHeldStrandPeer}). The schema
|
|
2847
|
+
* refuses the insert while this node does not hold the machine's `CadrePeer` row, and that
|
|
2848
|
+
* rejection propagates.
|
|
2815
2849
|
*
|
|
2816
|
-
* @param row - The strand,
|
|
2850
|
+
* @param row - The strand, this machine's peer id in it (`strandTransportKey`), and its role
|
|
2851
|
+
* there: `'client'` when it stores none of the strand, null when it serves it.
|
|
2817
2852
|
* @param sign - Signs the raw message bytes with the identity key behind this machine's
|
|
2818
2853
|
* control peer id. A callback for the reason {@link updateSelfPeerRecord} takes one: this
|
|
2819
2854
|
* class holds no private key.
|
|
@@ -2821,17 +2856,17 @@ export class ControlDatabase {
|
|
|
2821
2856
|
async insertStrandPeer(row, sign) {
|
|
2822
2857
|
this.ensureInitialized();
|
|
2823
2858
|
const peerId = this.config.libp2pNode.peerId.toString();
|
|
2824
|
-
const fields = { strandId: row.strandId, peerId, strandPeerId: row.strandPeerId };
|
|
2859
|
+
const fields = { strandId: row.strandId, peerId, strandPeerId: row.strandPeerId, role: row.role };
|
|
2825
2860
|
return this.lockedWithRetry(async () => {
|
|
2826
2861
|
// retry: false — this guard runs inside the locked write body (see queryStampId's NOTE).
|
|
2827
2862
|
const held = (await this.readStrandPeerRows(row.strandId, false)).find((stored) => stored.peerId === peerId);
|
|
2828
2863
|
if (held !== undefined) {
|
|
2829
|
-
|
|
2864
|
+
logHeldStrandPeer(held, row.role);
|
|
2830
2865
|
return false;
|
|
2831
2866
|
}
|
|
2832
2867
|
const sig = await sign(buildAuthorizationMessage('CadreControl.StrandPeer', 'add', this.config.partyId, strandPeerRowFields(fields)));
|
|
2833
2868
|
// Bare `exec`: already inside the write lock, which is NOT re-entrant.
|
|
2834
|
-
await this.db.exec(
|
|
2869
|
+
await this.db.exec(`insert into CadreControl.StrandPeer (${STRAND_PEER_COLUMNS}) values (?, ?, ?, ?, ?)`, [fields.strandId, fields.peerId, fields.strandPeerId, fields.role, sig]);
|
|
2835
2870
|
return true;
|
|
2836
2871
|
}, {}, 'strand-peer-insert');
|
|
2837
2872
|
}
|