@serfab/cadre-core 1.22.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 +159 -53
- package/dist/cadre-node.js +276 -89
- 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 +6 -3
- package/dist/membership-view.js.map +1 -1
- 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 +134 -42
- package/dist/strand-instance-manager.js +331 -76
- 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 +127 -57
- 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 -12252
- 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 -144
- 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 +381 -85
- 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 -3112
- package/src/webrtc-upgrade.ts +439 -0
package/src/control-cohort.ts
CHANGED
|
@@ -1,204 +1,223 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Control-cohort dial selection: the pure policy behind
|
|
3
|
-
* {@link CadreNode.reconcileControlCohort}. Decides WHICH known cadre siblings a
|
|
4
|
-
* node proactively dials each pass to keep the `CadreControl` collections' cohort
|
|
5
|
-
* connected (and thus replicating), without devolving into an N² mesh.
|
|
6
|
-
*
|
|
7
|
-
* FRET only needs a *connected* graph with the block clusters reachable, not a
|
|
8
|
-
* full mesh. Always-on
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* - **Always dial every backbone (always-on) member** — a party runs few of them,
|
|
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
|
|
16
|
-
* deterministically (peerId sort) so every node makes the same stable choice
|
|
17
|
-
* across passes and load spreads predictably.
|
|
18
|
-
*
|
|
19
|
-
* For a small party (members ≤ degree) this degenerates to a full mesh, which is
|
|
20
|
-
* correct, cheap, and matches what the convergence tests do by hand; for a large
|
|
21
|
-
* party it bounds out-degree to `backbone + targetDegree`.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
*/
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Control-cohort dial selection: the pure policy behind
|
|
3
|
+
* {@link CadreNode.reconcileControlCohort}. Decides WHICH known cadre siblings a
|
|
4
|
+
* node proactively dials each pass to keep the `CadreControl` collections' cohort
|
|
5
|
+
* connected (and thus replicating), without devolving into an N² mesh.
|
|
6
|
+
*
|
|
7
|
+
* FRET only needs a *connected* graph with the block clusters reachable, not a
|
|
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
|
+
*
|
|
12
|
+
* - **Always dial every backbone (always-on) member** — a party runs few of them,
|
|
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 (devices,
|
|
15
|
+
* and machines that have not yet published whether they are always on), ordered
|
|
16
|
+
* deterministically (peerId sort) so every node makes the same stable choice
|
|
17
|
+
* across passes and load spreads predictably.
|
|
18
|
+
*
|
|
19
|
+
* For a small party (members ≤ degree) this degenerates to a full mesh, which is
|
|
20
|
+
* correct, cheap, and matches what the convergence tests do by hand; for a large
|
|
21
|
+
* party it bounds out-degree to `backbone + targetDegree`.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { decodeAlwaysOn } from './node-class.js';
|
|
25
|
+
import type { CohortPeerRow } from './strand-cohort.js';
|
|
26
|
+
import type { CadrePeerRow } from './types.js';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A sibling as this policy judges it: its addressing row plus the backbone fact, decoded from
|
|
30
|
+
* the stored `CadrePeer.Profile` code by {@link controlCohortSiblingsOf}. Required, not
|
|
31
|
+
* optional, so a caller cannot hand the policy raw rows and silently get no backbone.
|
|
32
|
+
*/
|
|
33
|
+
export interface ControlCohortSibling extends CohortPeerRow {
|
|
34
|
+
/** Whether the machine declared itself always on; null until it self-publishes. */
|
|
35
|
+
alwaysOn: boolean | null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Live `CadrePeer` rows as this policy reads them — the one place the stored `Profile` code
|
|
40
|
+
* reaches a dial decision, so no policy compares it.
|
|
41
|
+
*/
|
|
42
|
+
export function controlCohortSiblingsOf(rows: readonly CadrePeerRow[]): ControlCohortSibling[] {
|
|
43
|
+
return rows.map(({ peerId, multiaddr, profile }) => ({ peerId, multiaddr, alwaysOn: decodeAlwaysOn(profile) }));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Default backstop for {@link CadreNode.reconcileControlCohort} (ms): a pass runs this long
|
|
48
|
+
* after the last one settled whether or not anything woke it. Passes normally run on a
|
|
49
|
+
* change — a membership table changing, a sibling connecting or disconnecting, an address
|
|
50
|
+
* change — and on the retries a pass arms for itself ({@link nextReconcileWakeMs}); the
|
|
51
|
+
* backstop bounds how stale this node can be after a change it hears nothing of: one that
|
|
52
|
+
* reaches it with no storage event, which happens to a machine outside the block's cohort
|
|
53
|
+
* (a cadre larger than `CONTROL_REPLICATION_BREADTH`) and to one in the cohort that the
|
|
54
|
+
* writer could not reach when it committed. The membership rows view's maximum age
|
|
55
|
+
* (`MEMBERSHIP_VIEW_MAX_AGE_MS`, 15 s) is shorter than this, so the backstop pass reads
|
|
56
|
+
* storage and starts the cohort consult that brings such a change in.
|
|
57
|
+
*
|
|
58
|
+
* `network.controlCohort.reconcileMs` overrides it. An interval between a pass settling and
|
|
59
|
+
* the next start, not a deadline on a pass: passes are single-flight, and one unreachable
|
|
60
|
+
* sibling's dial alone can take the whole per-peer dial budget (86 s at the default
|
|
61
|
+
* declared link).
|
|
62
|
+
*
|
|
63
|
+
* NOTE: a machine whose storage takes no event for a change — one outside the block's cohort
|
|
64
|
+
* in a cadre larger than `CONTROL_REPLICATION_BREADTH` (16 machines), or one the writer could
|
|
65
|
+
* not reach when it committed — sees it only at this backstop, where the change-driven path
|
|
66
|
+
* serves a machine the commit reached within the 50 ms coalescing window. If a party ever
|
|
67
|
+
* needs a tighter bound, lower the backstop for its nodes or give the plugin's change bridge
|
|
68
|
+
* a path for outside-the-cohort reads.
|
|
69
|
+
*/
|
|
70
|
+
export const DEFAULT_CONTROL_COHORT_RECONCILE_MS = 120_000;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* First redial delay after a pass's dial of a selected sibling, or a cold-start bootstrap peer,
|
|
74
|
+
* fails (ms). Doubles per consecutive such pass and is capped at the backstop, so a
|
|
75
|
+
* sibling that is offline costs one dial per backstop once the ladder saturates, and a
|
|
76
|
+
* stranded cold-start node keeps trying forever (15 s, 30 s, 60 s, then every backstop).
|
|
77
|
+
*/
|
|
78
|
+
export const CONTROL_COHORT_REDIAL_MS = 15_000;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* How often an owner retries a node it has just claimed while that node restarts into the
|
|
82
|
+
* owner's party (ms; `CadreNode.claimNode`). A poll step, not a deadline: the retries run for
|
|
83
|
+
* {@link CONTROL_COHORT_REDIAL_MS} after the node accepts the claim, the delay of the reconcile
|
|
84
|
+
* pass's first redial, which would otherwise be the owner's next dial of the node.
|
|
85
|
+
*/
|
|
86
|
+
export const CLAIM_RESTART_REDIAL_STEP_MS = 1_000;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Default cap on the number of **non-backbone** members a single reconcile pass
|
|
90
|
+
* proactively dials. Backbone (always-on) members are always dialed and do NOT
|
|
91
|
+
* count against this cap.
|
|
92
|
+
*/
|
|
93
|
+
export const DEFAULT_CONTROL_COHORT_TARGET_DEGREE = 6;
|
|
94
|
+
|
|
95
|
+
// The per-sibling and per-address dial time limits live in `peer-dial.ts`
|
|
96
|
+
// (`DEFAULT_CONTROL_COHORT_DIAL_TIMEOUT_MS`,
|
|
97
|
+
// `DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS`), beside the dial they
|
|
98
|
+
// bound, which `seed-bootstrap.ts` also uses and cannot import from here.
|
|
99
|
+
|
|
100
|
+
/** Outcome of {@link selectControlCohortDials}: who to dial + what the cap dropped. */
|
|
101
|
+
export interface ControlCohortSelection {
|
|
102
|
+
/**
|
|
103
|
+
* Siblings to dial this pass, backbone first then the bounded non-backbone
|
|
104
|
+
* fill. Already self-excluded (the caller must pass self-excluded `siblings`).
|
|
105
|
+
* Still includes peers that may turn out to be already-connected — the caller
|
|
106
|
+
* diffs against live connections separately.
|
|
107
|
+
*/
|
|
108
|
+
dials: ControlCohortSibling[];
|
|
109
|
+
/** Non-backbone members dropped by the `targetDegree` cap (0 when none). */
|
|
110
|
+
cappedNonBackbone: number;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** What one {@link CadreNode.reconcileControlCohort} pass did. */
|
|
114
|
+
export interface ControlCohortReconcileResult {
|
|
115
|
+
/**
|
|
116
|
+
* Peer ids this pass dialled and whose dial resolved, in dial order: selected
|
|
117
|
+
* siblings on the steady-state pass, retained bootstrap peers on the cold-start
|
|
118
|
+
* pass (the pass takes one branch or the other, never both). A peer already
|
|
119
|
+
* connected when the pass began is never listed — the pass skips it. A resolved
|
|
120
|
+
* dial can still be refused moments later by the remote's membership gate, so
|
|
121
|
+
* an entry means "this pass opened a connection", not "that connection is still
|
|
122
|
+
* open".
|
|
123
|
+
*/
|
|
124
|
+
dialed: string[];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Stable peerId ordering so the bounded fill is identical across passes/nodes. */
|
|
128
|
+
function byPeerId(a: ControlCohortSibling, b: ControlCohortSibling): number {
|
|
129
|
+
if (a.peerId < b.peerId) return -1;
|
|
130
|
+
if (a.peerId > b.peerId) return 1;
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Backbone-preferential, bounded-out-degree selection of control-cohort siblings
|
|
136
|
+
* to dial.
|
|
137
|
+
*
|
|
138
|
+
* A member is **backbone** iff its `CadrePeer` row declares it always on. All
|
|
139
|
+
* backbone members are selected; the rest fill up to `targetDegree` in
|
|
140
|
+
* deterministic peerId order. A member that has not self-published yet is not
|
|
141
|
+
* backbone until it does. Being always on is a dial preference only: it is
|
|
142
|
+
* self-declared, and a machine misdeclaring it costs extra dials, never access.
|
|
143
|
+
*
|
|
144
|
+
* @param siblings - cadre members EXCLUDING self (the caller filters self out).
|
|
145
|
+
* @param targetDegree - cap on non-backbone dials (negative is treated as 0).
|
|
146
|
+
*/
|
|
147
|
+
export function selectControlCohortDials(
|
|
148
|
+
siblings: ControlCohortSibling[],
|
|
149
|
+
targetDegree: number,
|
|
150
|
+
): ControlCohortSelection {
|
|
151
|
+
const backbone: ControlCohortSibling[] = [];
|
|
152
|
+
const rest: ControlCohortSibling[] = [];
|
|
153
|
+
|
|
154
|
+
// NOTE: the backbone is uncapped, so out-degree grows with the number of always-on
|
|
155
|
+
// machines (and with any sibling that declares itself always on without being one); if a
|
|
156
|
+
// party ever runs more than a handful, cap the backbone too.
|
|
157
|
+
for (const peer of siblings) {
|
|
158
|
+
if (peer.alwaysOn === true) {
|
|
159
|
+
backbone.push(peer);
|
|
160
|
+
} else {
|
|
161
|
+
rest.push(peer);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
backbone.sort(byPeerId);
|
|
166
|
+
rest.sort(byPeerId);
|
|
167
|
+
|
|
168
|
+
const cap = Math.max(0, targetDegree);
|
|
169
|
+
const fill = rest.slice(0, cap);
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
dials: [...backbone, ...fill],
|
|
173
|
+
cappedNonBackbone: rest.length - fill.length,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** What {@link nextReconcileWakeMs} decides from, all times epoch milliseconds. */
|
|
178
|
+
export interface ReconcileWakeInput {
|
|
179
|
+
/**
|
|
180
|
+
* Consecutive passes, this one included, whose dial of a selected sibling or a cold-start
|
|
181
|
+
* bootstrap peer failed; 0 when none of this pass's dials did.
|
|
182
|
+
*/
|
|
183
|
+
redialStreak: number;
|
|
184
|
+
/** When the pass that just ended began. */
|
|
185
|
+
passStartedAt: number;
|
|
186
|
+
/** Every (sibling, strand) strand-address due time this node holds. */
|
|
187
|
+
strandAddrDueAt: Iterable<number>;
|
|
188
|
+
now: number;
|
|
189
|
+
/** The scheduler's backstop (ms); no wake is later than it. */
|
|
190
|
+
backstopMs: number;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* How long after a pass the next one should run for the pass's own reasons, or `undefined`
|
|
195
|
+
* when the backstop covers everything:
|
|
196
|
+
*
|
|
197
|
+
* - **Redial.** A streak of unconnected passes wakes after
|
|
198
|
+
* `min(CONTROL_COHORT_REDIAL_MS × 2^(streak − 1), backstop)`.
|
|
199
|
+
* - **Strand addresses.** The earliest strand-address due time LATER THAN the pass's start,
|
|
200
|
+
* when it is sooner than the backstop, wakes when it falls due (now at the latest). A due
|
|
201
|
+
* time at or before the start belongs to a (sibling, strand) the pass skipped for another
|
|
202
|
+
* reason — the strand stopped, the sibling disconnected — and waking for it would spin; the
|
|
203
|
+
* strand watcher's launch retry keeps the same rule.
|
|
204
|
+
*
|
|
205
|
+
* The smaller wins.
|
|
206
|
+
*/
|
|
207
|
+
export function nextReconcileWakeMs(input: ReconcileWakeInput): number | undefined {
|
|
208
|
+
const { redialStreak, passStartedAt, strandAddrDueAt, now, backstopMs } = input;
|
|
209
|
+
let wake: number | undefined;
|
|
210
|
+
if (redialStreak > 0) {
|
|
211
|
+
wake = Math.min(CONTROL_COHORT_REDIAL_MS * 2 ** (redialStreak - 1), backstopMs);
|
|
212
|
+
}
|
|
213
|
+
for (const dueAt of strandAddrDueAt) {
|
|
214
|
+
if (dueAt <= passStartedAt) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const delay = Math.max(0, dueAt - now);
|
|
218
|
+
if (delay < backstopMs && (wake === undefined || delay < wake)) {
|
|
219
|
+
wake = delay;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return wake;
|
|
223
|
+
}
|
package/src/control-database.ts
CHANGED
|
@@ -9,12 +9,14 @@ import type { Libp2p } from '@libp2p/interface';
|
|
|
9
9
|
import type { IRepo } from '@optimystic/db-core';
|
|
10
10
|
import { createEmptyCollections } from '@serfab/quereus-plugin-sereus';
|
|
11
11
|
import type { CollectionRegistrySource } from '@serfab/quereus-plugin-sereus';
|
|
12
|
-
import type { StrandRow, StrandPeerRow, PendingStrandPartyKeyRow, SealedPendingPartyKey, JoinRequestRow, JoinOutcome, PendingJoin,
|
|
12
|
+
import type { StrandRow, StrandPeerRow, StrandPeerRole, PendingStrandPartyKeyRow, SealedPendingPartyKey, JoinRequestRow, JoinOutcome, PendingJoin, PeerAddressRecord, CadrePeerRow, OwnerKeyRow, RevocationRow, DeviceTokenRecord, DeviceTokenRow, PushPlatform, CadreInviteRow, CadreInviteUsageRow, CadreInviteRedemptionResult, CadreInviteStatus, OwnerGrantRow, OwnerGrantUsageRow, OwnerGrantRedemptionResult, OwnerGrantStatus, SeedPeer, MachineRemovalWrites } from './types.js';
|
|
13
13
|
import { APPLY_CONTROL_SCHEMA, CONTROL_SCHEMA_DECLARATION, CONTROL_SCHEMA_NAME, controlSchemaFileDeclaration } from './control-schema.js';
|
|
14
14
|
import { refuseIncompatibleControlStore } from './control-schema-version.js';
|
|
15
|
+
import { decodeAlwaysOn } from './node-class.js';
|
|
16
|
+
import type { PublishedProfile } from './node-class.js';
|
|
15
17
|
import { canonicalDatetime } from './canonical-datetime.js';
|
|
16
18
|
import { controlAuthorizationFields, unboundAuthorizationFields, cadreInviteRowFields, ownerGrantRowFields, strandPeerRowFields, pendingStrandPartyKeyRowFields, CONTROL_TABLES } from './control-authorization.js';
|
|
17
|
-
import type { ControlTable, RevocableTable, BoundControlDomain, UnboundControlDomain, ControlAction, CadreInviteSignedFields, OwnerGrantSignedFields } from './control-authorization.js';
|
|
19
|
+
import type { ControlTable, RevocableTable, BoundControlDomain, UnboundControlDomain, ControlAction, CadreInviteSignedFields, OwnerGrantSignedFields, StrandPeerSignedFields } from './control-authorization.js';
|
|
18
20
|
import { requireEd25519PublicKeyB64 } from './ed25519-key.js';
|
|
19
21
|
import { strandMemberKeyPair } from './strand-member-key.js';
|
|
20
22
|
import { verifyCadreInviteRow, verifyOwnerGrantRow, verifyStrandPeerRow } from './peer-authorization.js';
|
|
@@ -579,6 +581,51 @@ function pendingPartyKeyOfRow(row: Record<string, SqlValue>): PendingStrandParty
|
|
|
579
581
|
};
|
|
580
582
|
}
|
|
581
583
|
|
|
584
|
+
/** The columns every `StrandPeer` read takes, as {@link strandPeerRowOf} maps them. */
|
|
585
|
+
const STRAND_PEER_COLUMNS = 'StrandId, PeerId, StrandPeerId, Role, Sig';
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* A stored `StrandPeer.Role` as this build knows it. Null, and a row written before the column
|
|
589
|
+
* existed, read as a serving machine's. A value this build does not know also reads as null, and
|
|
590
|
+
* the row then fails {@link verifyStrandPeerRow}, whose digest omits a null role, and is dropped:
|
|
591
|
+
* a reader acts only on roles it knows, as a version-4 reader drops a row marked `'client'`. Such
|
|
592
|
+
* a value reaches a store only from a machine that bypassed its own `KnownStrandPeerRole` check,
|
|
593
|
+
* or from a later schema version that adds one.
|
|
594
|
+
*/
|
|
595
|
+
function strandPeerRoleOf(value: SqlValue): StrandPeerRole | null {
|
|
596
|
+
return value === 'client' ? value : null;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/** A stored `StrandPeer` row as {@link StrandPeerRow}. */
|
|
600
|
+
function strandPeerRowOf(row: Record<string, SqlValue>): StrandPeerRow {
|
|
601
|
+
return {
|
|
602
|
+
strandId: row.StrandId as string,
|
|
603
|
+
peerId: row.PeerId as string,
|
|
604
|
+
strandPeerId: row.StrandPeerId as string,
|
|
605
|
+
role: strandPeerRoleOf(row.Role),
|
|
606
|
+
sig: row.Sig as string,
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/** How a `StrandPeer` role reads in a log line: the null role is the serving machine's. */
|
|
611
|
+
const strandPeerRoleName = (role: StrandPeerRole | null): string => role ?? 'serving';
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* The "already present" line of {@link ControlDatabase.insertStrandPeer}. The row is immutable, so
|
|
615
|
+
* when the held row states a role other than the one this machine now publishes, the line names
|
|
616
|
+
* both: the stored role stands until the machine is removed and re-added.
|
|
617
|
+
*/
|
|
618
|
+
function logHeldStrandPeer(held: StrandPeerRow, role: StrandPeerRole | null): void {
|
|
619
|
+
if (held.role === role) {
|
|
620
|
+
log('StrandPeer row already present for strand %s (names %s); insert skipped', held.strandId, held.strandPeerId);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
log(
|
|
624
|
+
'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',
|
|
625
|
+
held.strandId, held.strandPeerId, strandPeerRoleName(held.role), strandPeerRoleName(role)
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
|
|
582
629
|
/**
|
|
583
630
|
* The key the party moves to in one strand, for {@link ControlDatabase.removeMachine}: its public
|
|
584
631
|
* half in the clear, its private half sealed to the machines that remain (`sealed-party-key.ts`).
|
|
@@ -852,16 +899,16 @@ function errorChainMatches(error: unknown, pattern: RegExp): boolean {
|
|
|
852
899
|
*
|
|
853
900
|
* A peer is `preferred` when it is the minter, the one machine certain to be reachable by the
|
|
854
901
|
* receiver at that moment, since it is delivering the seed or the reply, or an always-on
|
|
855
|
-
* machine
|
|
856
|
-
*
|
|
857
|
-
*
|
|
858
|
-
*
|
|
902
|
+
* machine, the ones that stay dialable. Preference is a dial hint and reads no `OwnerKey` row:
|
|
903
|
+
* owner keys are not machines, and a receiver derives trust from its own anchor, never from
|
|
904
|
+
* this list. Being always on is self-declared and not checked here, so a machine misdeclaring
|
|
905
|
+
* it costs the receiver a wasted dial at most.
|
|
859
906
|
*/
|
|
860
907
|
export function projectSeedPeers(rows: readonly CadrePeerRow[], minterPeerId: string): SeedPeer[] {
|
|
861
908
|
return rows.map(({ peerId, multiaddr, profile }) => ({
|
|
862
909
|
peerId,
|
|
863
910
|
multiaddrs: multiaddr ? multiaddr.split(',') : [],
|
|
864
|
-
preferred: peerId === minterPeerId || profile ===
|
|
911
|
+
preferred: peerId === minterPeerId || decodeAlwaysOn(profile) === true,
|
|
865
912
|
}));
|
|
866
913
|
}
|
|
867
914
|
|
|
@@ -950,7 +997,7 @@ function cadrePeerRowOf(row: Record<string, SqlValue>): CadrePeerRow {
|
|
|
950
997
|
publicKey: (row.PublicKey as string | null) ?? null,
|
|
951
998
|
multiaddr: (row.Multiaddr as string | null) ?? null,
|
|
952
999
|
updatedAt: (row.UpdatedAt as number | null) ?? 0,
|
|
953
|
-
profile: (row.Profile as
|
|
1000
|
+
profile: (row.Profile as PublishedProfile | null) ?? null,
|
|
954
1001
|
sig: (row.Sig as string | null) ?? null,
|
|
955
1002
|
stampId: (row.StampId as string | null) ?? null,
|
|
956
1003
|
vouchOwner: (row.VouchOwner as string | null) ?? null,
|
|
@@ -2371,19 +2418,12 @@ export class ControlDatabase {
|
|
|
2371
2418
|
*/
|
|
2372
2419
|
private async readStrandPeerRows(strandId: string, retry: boolean): Promise<StrandPeerRow[]> {
|
|
2373
2420
|
const rows = await this.readRows(
|
|
2374
|
-
|
|
2421
|
+
`select ${STRAND_PEER_COLUMNS} from CadreControl.StrandPeer where StrandId = ?`,
|
|
2375
2422
|
[strandId],
|
|
2376
2423
|
'strand-peers',
|
|
2377
2424
|
retry
|
|
2378
2425
|
);
|
|
2379
|
-
return rows
|
|
2380
|
-
.filter((row) => row.StrandId === strandId)
|
|
2381
|
-
.map((row) => ({
|
|
2382
|
-
strandId,
|
|
2383
|
-
peerId: row.PeerId as string,
|
|
2384
|
-
strandPeerId: row.StrandPeerId as string,
|
|
2385
|
-
sig: row.Sig as string,
|
|
2386
|
-
}));
|
|
2426
|
+
return rows.filter((row) => row.StrandId === strandId).map(strandPeerRowOf);
|
|
2387
2427
|
}
|
|
2388
2428
|
|
|
2389
2429
|
/** `ValidationKey` stamp nonce — bound into {@link deleteValidationKey}'s remove digest. */
|
|
@@ -3511,32 +3551,36 @@ export class ControlDatabase {
|
|
|
3511
3551
|
}
|
|
3512
3552
|
|
|
3513
3553
|
/**
|
|
3514
|
-
* Publish this machine's peer id in one strand
|
|
3515
|
-
*
|
|
3516
|
-
*
|
|
3517
|
-
* the
|
|
3554
|
+
* Publish this machine's peer id in one strand, and whether it serves the strand (`StrandPeer`
|
|
3555
|
+
* row), signed by this machine's own identity key in the form its role selects
|
|
3556
|
+
* (`strandPeerRowFields`). Insert-if-absent: `true` when a row was written, `false` when this
|
|
3557
|
+
* machine already has one for the strand. The row is immutable, so a held row stands even when
|
|
3558
|
+
* its role differs from `row.role`; that case is logged ({@link logHeldStrandPeer}). The schema
|
|
3559
|
+
* refuses the insert while this node does not hold the machine's `CadrePeer` row, and that
|
|
3560
|
+
* rejection propagates.
|
|
3518
3561
|
*
|
|
3519
|
-
* @param row - The strand,
|
|
3562
|
+
* @param row - The strand, this machine's peer id in it (`strandTransportKey`), and its role
|
|
3563
|
+
* there: `'client'` when it stores none of the strand, null when it serves it.
|
|
3520
3564
|
* @param sign - Signs the raw message bytes with the identity key behind this machine's
|
|
3521
3565
|
* control peer id. A callback for the reason {@link updateSelfPeerRecord} takes one: this
|
|
3522
3566
|
* class holds no private key.
|
|
3523
3567
|
*/
|
|
3524
|
-
async insertStrandPeer(row:
|
|
3568
|
+
async insertStrandPeer(row: Omit<StrandPeerSignedFields, 'peerId'>, sign: ControlSign): Promise<boolean> {
|
|
3525
3569
|
this.ensureInitialized();
|
|
3526
3570
|
const peerId = this.config.libp2pNode.peerId.toString();
|
|
3527
|
-
const fields = { strandId: row.strandId, peerId, strandPeerId: row.strandPeerId };
|
|
3571
|
+
const fields: StrandPeerSignedFields = { strandId: row.strandId, peerId, strandPeerId: row.strandPeerId, role: row.role };
|
|
3528
3572
|
return this.lockedWithRetry(async () => {
|
|
3529
3573
|
// retry: false — this guard runs inside the locked write body (see queryStampId's NOTE).
|
|
3530
3574
|
const held = (await this.readStrandPeerRows(row.strandId, false)).find((stored) => stored.peerId === peerId);
|
|
3531
3575
|
if (held !== undefined) {
|
|
3532
|
-
|
|
3576
|
+
logHeldStrandPeer(held, row.role);
|
|
3533
3577
|
return false;
|
|
3534
3578
|
}
|
|
3535
3579
|
const sig = await sign(buildAuthorizationMessage('CadreControl.StrandPeer', 'add', this.config.partyId, strandPeerRowFields(fields)));
|
|
3536
3580
|
// Bare `exec`: already inside the write lock, which is NOT re-entrant.
|
|
3537
3581
|
await this.db!.exec(
|
|
3538
|
-
|
|
3539
|
-
[fields.strandId, fields.peerId, fields.strandPeerId, sig]
|
|
3582
|
+
`insert into CadreControl.StrandPeer (${STRAND_PEER_COLUMNS}) values (?, ?, ?, ?, ?)`,
|
|
3583
|
+
[fields.strandId, fields.peerId, fields.strandPeerId, fields.role, sig]
|
|
3540
3584
|
);
|
|
3541
3585
|
return true;
|
|
3542
3586
|
}, {}, 'strand-peer-insert');
|
|
@@ -3849,7 +3893,7 @@ export class ControlDatabase {
|
|
|
3849
3893
|
multiaddr: string;
|
|
3850
3894
|
updatedAt: number;
|
|
3851
3895
|
sig: string | null;
|
|
3852
|
-
profile:
|
|
3896
|
+
profile: PublishedProfile | null;
|
|
3853
3897
|
},
|
|
3854
3898
|
ownerKey: string,
|
|
3855
3899
|
signMessage: ControlSign
|