@serfab/cadre-core 1.13.0 → 1.15.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 +293 -274
- package/dist/cadre-invite-protocol.d.ts +383 -0
- package/dist/cadre-invite-protocol.js +774 -0
- package/dist/cadre-invite-protocol.js.map +1 -0
- package/dist/cadre-join-request.d.ts +42 -0
- package/dist/cadre-join-request.js +144 -0
- package/dist/cadre-join-request.js.map +1 -0
- package/dist/cadre-node.d.ts +849 -210
- package/dist/cadre-node.js +1574 -374
- package/dist/cadre-node.js.map +1 -1
- package/dist/claim-proof.d.ts +45 -0
- package/dist/claim-proof.js +132 -0
- package/dist/claim-proof.js.map +1 -0
- package/dist/control-authorization.d.ts +80 -19
- package/dist/control-authorization.js +55 -13
- package/dist/control-authorization.js.map +1 -1
- package/dist/control-cohort.js +1 -1
- package/dist/control-cohort.js.map +1 -1
- package/dist/control-database.d.ts +605 -108
- package/dist/control-database.js +1299 -280
- package/dist/control-database.js.map +1 -1
- package/dist/control-protocol-guard.d.ts +142 -0
- package/dist/control-protocol-guard.js +293 -0
- package/dist/control-protocol-guard.js.map +1 -0
- package/dist/control-schema.d.ts +1 -1
- package/dist/control-schema.js +817 -1067
- package/dist/control-schema.js.map +1 -1
- package/dist/control-stream.d.ts +4 -0
- package/dist/control-stream.js +22 -7
- package/dist/control-stream.js.map +1 -1
- package/dist/delegate-admission.d.ts +1 -1
- package/dist/delegate-admission.js +1 -1
- package/dist/device-token.d.ts +11 -9
- package/dist/device-token.js +14 -12
- package/dist/device-token.js.map +1 -1
- package/dist/ed25519-key.d.ts +22 -9
- package/dist/ed25519-key.js +47 -10
- package/dist/ed25519-key.js.map +1 -1
- package/dist/fetch-impl.d.ts +12 -0
- package/dist/fetch-impl.js +23 -0
- package/dist/fetch-impl.js.map +1 -0
- package/dist/file-durable-slot.js +2 -1
- package/dist/file-durable-slot.js.map +1 -1
- package/dist/file-safe-name.d.ts +25 -0
- package/dist/file-safe-name.js +29 -0
- package/dist/file-safe-name.js.map +1 -0
- package/dist/formation-approval.js +5 -11
- package/dist/formation-approval.js.map +1 -1
- package/dist/fs-atomic.d.ts +0 -19
- package/dist/fs-atomic.js +3 -24
- package/dist/fs-atomic.js.map +1 -1
- package/dist/index.d.ts +22 -10
- package/dist/index.js +54 -11
- package/dist/index.js.map +1 -1
- package/dist/invitation-bootstrap.d.ts +50 -12
- package/dist/invitation-bootstrap.js +76 -13
- package/dist/invitation-bootstrap.js.map +1 -1
- package/dist/joined-strand-store.d.ts +7 -0
- package/dist/joined-strand-store.js +9 -0
- package/dist/joined-strand-store.js.map +1 -1
- package/dist/key-store-file.js +2 -1
- package/dist/key-store-file.js.map +1 -1
- package/dist/link-budget.d.ts +25 -33
- package/dist/link-budget.js +25 -35
- package/dist/link-budget.js.map +1 -1
- package/dist/machine-removal.d.ts +78 -0
- package/dist/machine-removal.js +166 -0
- package/dist/machine-removal.js.map +1 -0
- package/dist/membership-connection-gater.d.ts +191 -151
- package/dist/membership-connection-gater.js +236 -173
- package/dist/membership-connection-gater.js.map +1 -1
- package/dist/node-claim-payload.d.ts +74 -0
- package/dist/node-claim-payload.js +224 -0
- package/dist/node-claim-payload.js.map +1 -0
- package/dist/node-default-transports.d.ts +27 -0
- package/dist/node-default-transports.js +35 -0
- package/dist/node-default-transports.js.map +1 -0
- package/dist/node-transports.d.ts +30 -0
- package/dist/node-transports.js +40 -0
- package/dist/node-transports.js.map +1 -0
- package/dist/owner-anchor-sync.d.ts +22 -0
- package/dist/owner-anchor-sync.js +143 -0
- package/dist/owner-anchor-sync.js.map +1 -0
- package/dist/peer-authorization.d.ts +113 -18
- package/dist/peer-authorization.js +225 -29
- package/dist/peer-authorization.js.map +1 -1
- package/dist/peer-dial.d.ts +143 -27
- package/dist/peer-dial.js +276 -31
- package/dist/peer-dial.js.map +1 -1
- package/dist/peer-join-backfill.d.ts +26 -2
- package/dist/peer-join-backfill.js +60 -12
- package/dist/peer-join-backfill.js.map +1 -1
- package/dist/peer-record.d.ts +17 -52
- package/dist/peer-record.js +20 -58
- package/dist/peer-record.js.map +1 -1
- package/dist/pending-join-runner.d.ts +66 -58
- package/dist/pending-join-runner.js +136 -145
- package/dist/pending-join-runner.js.map +1 -1
- package/dist/primary-lan-address.d.ts +8 -0
- package/dist/primary-lan-address.js +46 -0
- package/dist/primary-lan-address.js.map +1 -0
- package/dist/provider/client.d.ts +131 -0
- package/dist/provider/client.js +226 -0
- package/dist/provider/client.js.map +1 -0
- package/dist/provider/descriptor.d.ts +41 -0
- package/dist/provider/descriptor.js +103 -0
- package/dist/provider/descriptor.js.map +1 -0
- package/dist/provider/index.d.ts +9 -0
- package/dist/provider/index.js +10 -0
- package/dist/provider/index.js.map +1 -0
- package/dist/provider/oauth.d.ts +125 -0
- package/dist/provider/oauth.js +199 -0
- package/dist/provider/oauth.js.map +1 -0
- package/dist/provider/rent-node.d.ts +101 -0
- package/dist/provider/rent-node.js +220 -0
- package/dist/provider/rent-node.js.map +1 -0
- package/dist/push-fanout.d.ts +8 -2
- package/dist/push-fanout.js +8 -2
- package/dist/push-fanout.js.map +1 -1
- package/dist/relay-addrs.d.ts +9 -4
- package/dist/relay-addrs.js +9 -4
- package/dist/relay-addrs.js.map +1 -1
- package/dist/relay-reservation.d.ts +51 -16
- package/dist/relay-reservation.js +107 -24
- package/dist/relay-reservation.js.map +1 -1
- package/dist/seed-bootstrap.d.ts +165 -123
- package/dist/seed-bootstrap.js +313 -275
- package/dist/seed-bootstrap.js.map +1 -1
- package/dist/seed-trust-policy.d.ts +98 -37
- package/dist/seed-trust-policy.js +188 -2
- package/dist/seed-trust-policy.js.map +1 -1
- package/dist/strand-addr-protocol.d.ts +24 -26
- package/dist/strand-addr-protocol.js +19 -26
- package/dist/strand-addr-protocol.js.map +1 -1
- package/dist/strand-commit-durability.d.ts +54 -0
- package/dist/strand-commit-durability.js +74 -0
- package/dist/strand-commit-durability.js.map +1 -0
- package/dist/strand-database.d.ts +23 -8
- package/dist/strand-database.js +41 -13
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-first-sync-gate.d.ts +7 -1
- package/dist/strand-first-sync-gate.js +7 -1
- package/dist/strand-first-sync-gate.js.map +1 -1
- package/dist/strand-formation-protocol.js +5 -2
- package/dist/strand-formation-protocol.js.map +1 -1
- package/dist/strand-fret-addrs.d.ts +19 -1
- package/dist/strand-fret-addrs.js +27 -9
- package/dist/strand-fret-addrs.js.map +1 -1
- package/dist/strand-instance-manager.d.ts +81 -19
- package/dist/strand-instance-manager.js +216 -105
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-move.d.ts +124 -0
- package/dist/strand-move.js +438 -0
- package/dist/strand-move.js.map +1 -0
- package/dist/strand-network-config.js +7 -6
- package/dist/strand-network-config.js.map +1 -1
- package/dist/strand-peer-redial.d.ts +113 -0
- package/dist/strand-peer-redial.js +236 -0
- package/dist/strand-peer-redial.js.map +1 -0
- package/dist/strand-revocation-enforcer.d.ts +11 -11
- package/dist/strand-revocation-enforcer.js +11 -11
- package/dist/strand-wake-protocol.d.ts +13 -16
- package/dist/strand-wake-protocol.js +23 -27
- package/dist/strand-wake-protocol.js.map +1 -1
- package/dist/trusted-owner-store.d.ts +35 -5
- package/dist/trusted-owner-store.js +50 -8
- package/dist/trusted-owner-store.js.map +1 -1
- package/dist/types.d.ts +512 -89
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -1
- package/package.json +19 -10
- package/src/cadre-invite-protocol.ts +1052 -0
- package/src/cadre-join-request.ts +167 -0
- package/src/cadre-node.ts +1703 -386
- package/src/claim-proof.ts +147 -0
- package/src/control-authorization.ts +203 -117
- package/src/control-cohort.ts +1 -1
- package/src/control-database.ts +4663 -3453
- package/src/control-protocol-guard.ts +348 -0
- package/src/control-schema.ts +828 -1078
- package/src/control-stream.ts +26 -7
- package/src/delegate-admission.ts +1 -1
- package/src/device-token.ts +14 -10
- package/src/ed25519-key.ts +47 -10
- package/src/fetch-impl.ts +23 -0
- package/src/file-durable-slot.ts +64 -63
- package/src/file-safe-name.ts +32 -0
- package/src/formation-approval.ts +604 -610
- package/src/fs-atomic.ts +92 -117
- package/src/index.ts +789 -648
- package/src/invitation-bootstrap.ts +91 -13
- package/src/joined-strand-store.ts +508 -498
- package/src/key-store-file.ts +142 -141
- package/src/link-budget.ts +25 -36
- package/src/machine-removal.ts +216 -0
- package/src/membership-connection-gater.ts +259 -191
- package/src/node-claim-payload.ts +259 -0
- package/src/node-default-transports.ts +38 -0
- package/src/node-transports.ts +49 -0
- package/src/owner-anchor-sync.ts +171 -0
- package/src/peer-authorization.ts +258 -29
- package/src/peer-dial.ts +604 -315
- package/src/peer-join-backfill.ts +62 -11
- package/src/peer-record.ts +159 -197
- package/src/pending-join-runner.ts +729 -735
- package/src/primary-lan-address.ts +47 -0
- package/src/provider/client.ts +326 -0
- package/src/provider/descriptor.ts +129 -0
- package/src/provider/index.ts +59 -0
- package/src/provider/oauth.ts +285 -0
- package/src/provider/rent-node.ts +275 -0
- package/src/push-fanout.ts +8 -2
- package/src/relay-addrs.ts +9 -4
- package/src/relay-reservation.ts +1211 -1121
- package/src/seed-bootstrap.ts +1502 -1448
- package/src/seed-trust-policy.ts +353 -140
- package/src/strand-addr-protocol.ts +26 -35
- package/src/strand-commit-durability.ts +116 -0
- package/src/strand-database.ts +46 -14
- package/src/strand-first-sync-gate.ts +7 -1
- package/src/strand-formation-protocol.ts +1039 -1036
- package/src/strand-fret-addrs.ts +179 -145
- package/src/strand-instance-manager.ts +2026 -1883
- package/src/strand-move.ts +585 -0
- package/src/strand-network-config.ts +7 -6
- package/src/strand-peer-redial.ts +307 -0
- package/src/strand-revocation-enforcer.ts +11 -11
- package/src/strand-wake-protocol.ts +23 -30
- package/src/trusted-owner-store.ts +242 -171
- package/src/types.ts +2687 -2242
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A running strand node redialing the strand's other members itself, when it holds a
|
|
3
|
+
* connection to none of them, with the dial budget the host's declared link gives a
|
|
4
|
+
* relayed connection.
|
|
5
|
+
*
|
|
6
|
+
* Why. Below cadre-core the only thing that redials a strand peer is FRET's maintenance:
|
|
7
|
+
* its pings and neighbour announcements open the connection themselves (`dial: true`) under
|
|
8
|
+
* a fixed 2 000 ms limit on the whole call (`MAINTENANCE_RPC_TIMEOUT_MS` in `p2p-fret`'s
|
|
9
|
+
* `fret-service.ts`). Opening a relayed connection takes longer than that on a slow link:
|
|
10
|
+
* about 9 s on a 20 ms per-frame cap with a 70%-busy event loop
|
|
11
|
+
* (`joiner-first-commit-over-slow-relay`, whose slow-restart arm reproduces this), where
|
|
12
|
+
* {@link relayedDialBudgetMs} allows 21.5 s at the default declaration. Each such redial is
|
|
13
|
+
* cut off part-way through the handshake, from both sides, for as long as the link stays that
|
|
14
|
+
* slow. And after a restart nothing else dials a strand peer: a cross-party strand's launch
|
|
15
|
+
* seed is empty, and cadre-core's address passes only fill the address book. Two phones that
|
|
16
|
+
* restarted then never reconnect, and a write either made alone never reaches the other.
|
|
17
|
+
*
|
|
18
|
+
* What it does. One loop per strand runtime, started in `StrandInstanceManager`'s runtime
|
|
19
|
+
* build and stopped with the runtime (stop, quiesce, failed build), so a hibernating strand
|
|
20
|
+
* never dials. Each look at the node:
|
|
21
|
+
* - a member connected: nothing to do; look again in {@link STRAND_REDIAL_CHECK_MS}, or as
|
|
22
|
+
* soon as a peer disconnects.
|
|
23
|
+
* - no member connected and none known: likewise nothing (a founder alone, a storage replica
|
|
24
|
+
* before anyone arrives).
|
|
25
|
+
* - no member connected and some known: dial every known member at once
|
|
26
|
+
* ({@link dialPeerAddrs}, direct addresses before relayed ones), each address with the
|
|
27
|
+
* relayed-dial budget. A round that connects to one goes back to watching; one that does
|
|
28
|
+
* not waits a backoff starting at that budget and doubling to
|
|
29
|
+
* {@link STRAND_REDIAL_MAX_BACKOFF_MS}.
|
|
30
|
+
*
|
|
31
|
+
* Who is known: every peer the node's FRET table holds a verified signed address record for
|
|
32
|
+
* (`strand-fret-addrs.ts`), plus the launch seed (sibling strand addresses and a formation's
|
|
33
|
+
* carried addresses). Who counts as connected: a peer FRET labels `'member'` (it has seen it
|
|
34
|
+
* speak this strand's protocols), or a seed peer. Neither ever includes a configured relay, a
|
|
35
|
+
* peer FRET labels `'foreign'`, or a peer the revocation gate refuses. The relay matters most:
|
|
36
|
+
* the strand node is connected to it throughout and FRET files it with a record like any
|
|
37
|
+
* peer, so counting it would leave this loop idle exactly when it is needed.
|
|
38
|
+
*
|
|
39
|
+
* NOTE: this compensates for FRET's 2 000 ms maintenance dial limit, which cannot open a
|
|
40
|
+
* relayed connection on a slow link (upstream half:
|
|
41
|
+
* `blocked/fret-maintenance-ping-dial-budget-below-a-relayed-dial`). If FRET's maintenance
|
|
42
|
+
* dial ever takes a limit derived from the declared link, this loop becomes a backstop and
|
|
43
|
+
* may be deleted, as `peer-join-backfill.ts` says of itself.
|
|
44
|
+
*/
|
|
45
|
+
import debug from 'debug';
|
|
46
|
+
import { relayedDialBudgetMs } from './link-budget.js';
|
|
47
|
+
import { CONTROL_COHORT_DIAL_ADDRESS_ATTEMPTS, SelfRelayOnlyError, dialPeerAddrs } from './peer-dial.js';
|
|
48
|
+
import { groupAddrsByPeerId } from './peer-addr-book.js';
|
|
49
|
+
import { strandFretMembership, strandFretPeerAddrs } from './strand-fret-addrs.js';
|
|
50
|
+
import { defaultTimeoutScheduler } from './timeout-scheduler.js';
|
|
51
|
+
const log = debug('sereus:cadre:strand-redial');
|
|
52
|
+
/**
|
|
53
|
+
* Gap between looks while a member is connected or none is known. While a member is
|
|
54
|
+
* connected a look reads FRET's labels and the connection list and checks no signature
|
|
55
|
+
* ({@link strandFretMembership}); a disconnect also triggers a look at once.
|
|
56
|
+
*/
|
|
57
|
+
export const STRAND_REDIAL_CHECK_MS = 5000;
|
|
58
|
+
/**
|
|
59
|
+
* Ceiling on the wait between failed rounds. A member that is gone for good is dialed this
|
|
60
|
+
* often for as long as FRET keeps its record (up to 14 days after it was last confirmed).
|
|
61
|
+
*/
|
|
62
|
+
export const STRAND_REDIAL_MAX_BACKOFF_MS = 5 * 60000;
|
|
63
|
+
/**
|
|
64
|
+
* The timings at a declared link round trip: {@link relayedDialBudgetMs} per address, the
|
|
65
|
+
* same whole-budget count per member as the control cohort's dials (dead direct addresses
|
|
66
|
+
* a record lists ahead of the relayed one that works), and a first backoff of one per-address
|
|
67
|
+
* budget.
|
|
68
|
+
*/
|
|
69
|
+
export function strandRedialTimings(linkRoundTripMs) {
|
|
70
|
+
const perAddressMs = relayedDialBudgetMs(linkRoundTripMs);
|
|
71
|
+
return {
|
|
72
|
+
budget: { perAddressMs, totalMs: CONTROL_COHORT_DIAL_ADDRESS_ATTEMPTS * perAddressMs },
|
|
73
|
+
minBackoffMs: perAddressMs,
|
|
74
|
+
maxBackoffMs: STRAND_REDIAL_MAX_BACKOFF_MS,
|
|
75
|
+
checkMs: STRAND_REDIAL_CHECK_MS
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** Start the loop; its first look runs at once. */
|
|
79
|
+
export function superviseStrandPeerRedial(deps, timings) {
|
|
80
|
+
return new StrandPeerRedialLoop(deps, timings);
|
|
81
|
+
}
|
|
82
|
+
class StrandPeerRedialLoop {
|
|
83
|
+
constructor(deps, timings) {
|
|
84
|
+
this.deps = deps;
|
|
85
|
+
this.timings = timings;
|
|
86
|
+
this.timer = null;
|
|
87
|
+
/**
|
|
88
|
+
* Whether the pending wait is a plain gap between looks, which a disconnect cuts short. A
|
|
89
|
+
* backoff after a failed round is not cut short, or a flapping relay connection would turn
|
|
90
|
+
* the backoff into a dial on every flap; and while a look or round runs there is no wait.
|
|
91
|
+
*/
|
|
92
|
+
this.watching = false;
|
|
93
|
+
this.stopped = false;
|
|
94
|
+
this.onDisconnect = () => {
|
|
95
|
+
if (this.watching && !this.stopped) {
|
|
96
|
+
this.cancelTimer();
|
|
97
|
+
void this.tick();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
this.scheduler = deps.scheduler ?? defaultTimeoutScheduler;
|
|
101
|
+
this.seed = groupAddrsByPeerId([...deps.seed]);
|
|
102
|
+
this.selfId = deps.node.peerId.toString();
|
|
103
|
+
this.backoffMs = timings.minBackoffMs;
|
|
104
|
+
deps.node.addEventListener('peer:disconnect', this.onDisconnect);
|
|
105
|
+
void this.tick();
|
|
106
|
+
}
|
|
107
|
+
stop() {
|
|
108
|
+
if (this.stopped) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
this.stopped = true;
|
|
112
|
+
this.cancelTimer();
|
|
113
|
+
this.deps.node.removeEventListener('peer:disconnect', this.onDisconnect);
|
|
114
|
+
}
|
|
115
|
+
async tick() {
|
|
116
|
+
if (this.stopped) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this.watching = false;
|
|
120
|
+
let outcome = 'watch';
|
|
121
|
+
try {
|
|
122
|
+
outcome = await this.lookAndDial();
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
// A node torn down under the look throws from its table export or connection list.
|
|
126
|
+
log('strand %s: redial look failed (looking again in %dms): %o', this.deps.label, this.timings.checkMs, error);
|
|
127
|
+
}
|
|
128
|
+
if (this.stopped) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this.watching = outcome === 'watch';
|
|
132
|
+
const waitMs = outcome === 'watch' ? this.resetBackoff() : this.nextBackoff();
|
|
133
|
+
this.timer = this.scheduler.setTimeout(() => {
|
|
134
|
+
this.timer = null;
|
|
135
|
+
void this.tick();
|
|
136
|
+
}, waitMs);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* One look, and a round of dials when it finds no member connected but some known. A node
|
|
140
|
+
* whose own party was removed dials nobody: the strand keeps running for the session, but a
|
|
141
|
+
* removed party must not keep dialing the strand's peers (`CadreNode.forgetRevokedJoin`).
|
|
142
|
+
*/
|
|
143
|
+
async lookAndDial() {
|
|
144
|
+
if (this.deps.isRevoked?.(this.selfId) === true) {
|
|
145
|
+
return 'watch';
|
|
146
|
+
}
|
|
147
|
+
const membership = strandFretMembership(this.deps.node);
|
|
148
|
+
if (this.memberConnected(membership)) {
|
|
149
|
+
return 'watch';
|
|
150
|
+
}
|
|
151
|
+
const known = await this.knownMembers(membership);
|
|
152
|
+
if (known.size === 0 || this.stopped) {
|
|
153
|
+
return 'watch';
|
|
154
|
+
}
|
|
155
|
+
log('strand %s: no member connected; dialing %d known member(s)', this.deps.label, known.size);
|
|
156
|
+
if (await this.dialAny(known)) {
|
|
157
|
+
log('strand %s: reconnected to a member', this.deps.label);
|
|
158
|
+
return 'watch';
|
|
159
|
+
}
|
|
160
|
+
log('strand %s: no known member answered; next round in %dms', this.deps.label, this.backoffMs);
|
|
161
|
+
return 'retry';
|
|
162
|
+
}
|
|
163
|
+
/** The gap between looks, with the backoff started over. */
|
|
164
|
+
resetBackoff() {
|
|
165
|
+
this.backoffMs = this.timings.minBackoffMs;
|
|
166
|
+
return this.timings.checkMs;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The wait after a round that reached no member, doubling the next one up to the cap.
|
|
170
|
+
*
|
|
171
|
+
* NOTE: a round whose dials failed within milliseconds (a relay connection that is still
|
|
172
|
+
* closing, the member's relay reservation not back yet) waits as long as one whose dials ran
|
|
173
|
+
* out their budget. In `joiner-first-commit-over-slow-relay`'s third arm that first wait is what
|
|
174
|
+
* leaves the joiner writable with no member connected. If reconnecting within seconds of a cut
|
|
175
|
+
* ever matters, retry a round that failed that fast after a short delay instead.
|
|
176
|
+
*
|
|
177
|
+
* NOTE: one such fast failure is `ConnectionClosedError: The connection muxer is "closed"`. A
|
|
178
|
+
* relay that aborts its connection to this node cannot tell it so (`@libp2p/websockets`'
|
|
179
|
+
* listener resets with close code 1006, which the `ws` package refuses to send;
|
|
180
|
+
* `blocked/report-libp2p-websockets-buffered-amount`, second arm), so this node keeps a dead
|
|
181
|
+
* relay connection until its own monitor drops it, up to 65 s, and every relayed dial reuses
|
|
182
|
+
* it. If rounds keep failing that way, close a relay connection whose muxer is closed before
|
|
183
|
+
* the next round instead of waiting it out.
|
|
184
|
+
*/
|
|
185
|
+
nextBackoff() {
|
|
186
|
+
const waitMs = this.backoffMs;
|
|
187
|
+
this.backoffMs = Math.min(waitMs * 2, this.timings.maxBackoffMs);
|
|
188
|
+
return waitMs;
|
|
189
|
+
}
|
|
190
|
+
eligible(peerId) {
|
|
191
|
+
return peerId !== this.selfId && !this.deps.excluded.has(peerId) && this.deps.isRevoked?.(peerId) !== true;
|
|
192
|
+
}
|
|
193
|
+
/** Whether an open connection reaches a peer FRET has seen speak this strand's protocols, or a seed peer. */
|
|
194
|
+
memberConnected(membership) {
|
|
195
|
+
return this.deps.node.getConnections().some((connection) => {
|
|
196
|
+
const peerId = connection.remotePeer.toString();
|
|
197
|
+
return this.eligible(peerId) && (membership.get(peerId) === 'member' || this.seed.has(peerId));
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/** The members to dial, each with its candidate addresses: verified FRET records first, then the seed's. */
|
|
201
|
+
async knownMembers(membership) {
|
|
202
|
+
const { peers } = await strandFretPeerAddrs(this.deps.node);
|
|
203
|
+
const known = new Map();
|
|
204
|
+
for (const [peerId, addrs] of [...peers, ...this.seed]) {
|
|
205
|
+
if (!this.eligible(peerId) || membership.get(peerId) === 'foreign') {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
known.set(peerId, unionAddrs(known.get(peerId) ?? [], addrs));
|
|
209
|
+
}
|
|
210
|
+
return known;
|
|
211
|
+
}
|
|
212
|
+
/** Dial every member in `known` at once; resolves to whether any connected. */
|
|
213
|
+
async dialAny(known) {
|
|
214
|
+
const members = [...known];
|
|
215
|
+
const outcomes = await Promise.allSettled(members.map(([peerId, addrs]) => dialPeerAddrs(this.deps.node, peerId, addrs, this.timings.budget, `strand ${this.deps.label} redial of ${peerId}`)));
|
|
216
|
+
outcomes.forEach((outcome, i) => {
|
|
217
|
+
if (outcome.status === 'rejected') {
|
|
218
|
+
const reason = outcome.reason instanceof SelfRelayOnlyError ? 'reachable only by relaying through this node' : outcome.reason;
|
|
219
|
+
log('strand %s: redial of %s failed: %o', this.deps.label, members[i][0], reason);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
return outcomes.some((outcome) => outcome.status === 'fulfilled');
|
|
223
|
+
}
|
|
224
|
+
cancelTimer() {
|
|
225
|
+
if (this.timer !== null) {
|
|
226
|
+
this.scheduler.clearTimeout(this.timer);
|
|
227
|
+
this.timer = null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/** `primary` then the entries of `extra` it lacks, compared as strings. */
|
|
232
|
+
function unionAddrs(primary, extra) {
|
|
233
|
+
const seen = new Set(primary.map((addr) => addr.toString()));
|
|
234
|
+
return [...primary, ...extra.filter((addr) => !seen.has(addr.toString()))];
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=strand-peer-redial.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strand-peer-redial.js","sourceRoot":"","sources":["../src/strand-peer-redial.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,oCAAoC,EAAE,kBAAkB,EAAE,aAAa,EAAwC,MAAM,gBAAgB,CAAC;AAC/I,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAA0C,MAAM,wBAAwB,CAAC;AAC3H,OAAO,EAAE,uBAAuB,EAAyB,MAAM,wBAAwB,CAAC;AAExF,MAAM,GAAG,GAAG,KAAK,CAAC,4BAA4B,CAAC,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAK,CAAC;AAE5C;;;GAGG;AACH,M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AAC;IAEO,WAAW;QACjB,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YACxB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACxC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;IACH,CAAC;CACF;AAED,2EAA2E;AAC3E,SAAS,UAAU,CAAC,OAA6B,EAAE,KAA2B;IAC5E,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,OAAO,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -83,23 +83,23 @@
|
|
|
83
83
|
*
|
|
84
84
|
* ## What transfers from the control gater (`membership-connection-gater.ts`)
|
|
85
85
|
*
|
|
86
|
-
* Transfers: the two-layer shape (fail-closed per-stream gate as PRIMARY,
|
|
87
|
-
*
|
|
86
|
+
* Transfers: the two-layer shape (fail-closed per-stream gate as PRIMARY, a
|
|
87
|
+
* connection-level layer on top), the synchronous in-memory
|
|
88
88
|
* snapshot judged by the stream gate (a live DB read inside a gate deadlocks —
|
|
89
89
|
* the same argument as the control node's `authorizeInboundControlStream`), the
|
|
90
90
|
* fail-open-on-error/timeout posture for the connection hooks
|
|
91
91
|
* (`decideWithinDeadline`, reused as-is), and the "compose over the caller's
|
|
92
92
|
* gater, every base hook preserved" mechanics.
|
|
93
93
|
*
|
|
94
|
-
* Does NOT transfer — the relay-reservation seam
|
|
95
|
-
* unauthorized budget). That
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* verdict, no
|
|
94
|
+
* Does NOT transfer — provisional admission and the relay-reservation seam
|
|
95
|
+
* (`'admit-provisionally'`, its deadline, the unauthorized budget). That
|
|
96
|
+
* machinery exists because the control gate judges on ABSENCE of placement,
|
|
97
|
+
* where a member whose row is in flight, or a device whose invitation row has
|
|
98
|
+
* not arrived, is indistinguishable from an outsider, and a wrong reservation
|
|
99
|
+
* deny is unrecoverable. This gate denies on POSITIVE revocation evidence, so a
|
|
100
|
+
* deny is never that kind of wrong answer; the one stale-wrong case (a missed
|
|
101
|
+
* re-add) heals via replication as above. Every hook here is therefore a plain
|
|
102
|
+
* "deny iff revoked" — no budget, no provisional verdict, no deadline.
|
|
103
103
|
*
|
|
104
104
|
* Does NOT transfer — the bring-up quiet period. A strand node's DB bring-up
|
|
105
105
|
* NEEDS its cross-party cohort connections; this enforcer simply starts with an
|
|
@@ -83,23 +83,23 @@
|
|
|
83
83
|
*
|
|
84
84
|
* ## What transfers from the control gater (`membership-connection-gater.ts`)
|
|
85
85
|
*
|
|
86
|
-
* Transfers: the two-layer shape (fail-closed per-stream gate as PRIMARY,
|
|
87
|
-
*
|
|
86
|
+
* Transfers: the two-layer shape (fail-closed per-stream gate as PRIMARY, a
|
|
87
|
+
* connection-level layer on top), the synchronous in-memory
|
|
88
88
|
* snapshot judged by the stream gate (a live DB read inside a gate deadlocks —
|
|
89
89
|
* the same argument as the control node's `authorizeInboundControlStream`), the
|
|
90
90
|
* fail-open-on-error/timeout posture for the connection hooks
|
|
91
91
|
* (`decideWithinDeadline`, reused as-is), and the "compose over the caller's
|
|
92
92
|
* gater, every base hook preserved" mechanics.
|
|
93
93
|
*
|
|
94
|
-
* Does NOT transfer — the relay-reservation seam
|
|
95
|
-
* unauthorized budget). That
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* verdict, no
|
|
94
|
+
* Does NOT transfer — provisional admission and the relay-reservation seam
|
|
95
|
+
* (`'admit-provisionally'`, its deadline, the unauthorized budget). That
|
|
96
|
+
* machinery exists because the control gate judges on ABSENCE of placement,
|
|
97
|
+
* where a member whose row is in flight, or a device whose invitation row has
|
|
98
|
+
* not arrived, is indistinguishable from an outsider, and a wrong reservation
|
|
99
|
+
* deny is unrecoverable. This gate denies on POSITIVE revocation evidence, so a
|
|
100
|
+
* deny is never that kind of wrong answer; the one stale-wrong case (a missed
|
|
101
|
+
* re-add) heals via replication as above. Every hook here is therefore a plain
|
|
102
|
+
* "deny iff revoked" — no budget, no provisional verdict, no deadline.
|
|
103
103
|
*
|
|
104
104
|
* Does NOT transfer — the bring-up quiet period. A strand node's DB bring-up
|
|
105
105
|
* NEEDS its cross-party cohort connections; this enforcer simply starts with an
|
|
@@ -16,13 +16,12 @@
|
|
|
16
16
|
*
|
|
17
17
|
* **Authorization (v1):** a wake is low-risk — it only causes the receiver to
|
|
18
18
|
* spend resources coming online for a strand it already participates in — so the
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* a voucher that verifies against an owner key in the receiver's
|
|
23
|
-
* trusted-owner anchor), so a peer that merely published rows into the
|
|
24
|
-
* control DB
|
|
25
|
-
* predicate it is given.
|
|
19
|
+
* request carries no signature. Membership is checked before this handler runs, by
|
|
20
|
+
* the control node's protocol guard (`control-protocol-guard.ts`, the `members`
|
|
21
|
+
* class: `CadreNode.isAuthorizedMember`, under which the sender's `CadrePeer` row
|
|
22
|
+
* must carry a voucher that verifies against an owner key in the receiver's
|
|
23
|
+
* node-local trusted-owner anchor), so a peer that merely published rows into the
|
|
24
|
+
* replicated control DB gets its stream reset and never reaches this module.
|
|
26
25
|
*/
|
|
27
26
|
import type { Libp2p } from '@libp2p/interface';
|
|
28
27
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
@@ -38,8 +37,8 @@ export declare const WAKE_PROTOCOL = "/sereus/strand-wake/1.0.0";
|
|
|
38
37
|
* It holds only link work because the receiver acks as soon as it has DECIDED, before the
|
|
39
38
|
* wake itself runs ({@link StrandWakeService.processWakeRequest}).
|
|
40
39
|
*
|
|
41
|
-
* NOTE: the receiver's membership check (two live control reads
|
|
42
|
-
* is not counted. In steady state those reads touch only held blocks and do not consult the
|
|
40
|
+
* NOTE: the receiver's membership check (two live control reads, in its protocol guard) runs
|
|
41
|
+
* inside this deadline and is not counted. In steady state those reads touch only held blocks and do not consult the
|
|
43
42
|
* cohort. If a wake or address request is seen timing out while the receiver's membership read
|
|
44
43
|
* is consulting, count one membership decision in this deadline or answer the check from the
|
|
45
44
|
* materialized authorized-peer snapshot. See docs/cadre-consistency.md → "Deadlines Over
|
|
@@ -83,8 +82,6 @@ export declare const DEFAULT_WAKE_DIAL_BUDGET_MS: number;
|
|
|
83
82
|
* (`CadreNode`), injected so the service is testable without a full node.
|
|
84
83
|
*/
|
|
85
84
|
export interface StrandWakeServiceOptions {
|
|
86
|
-
/** Membership gate: is the remote peer a `CadrePeer` member of this cadre? */
|
|
87
|
-
isMember(remotePeerId: string): Promise<boolean>;
|
|
88
85
|
/** Look up a local strand instance by id (undefined if not participated in). */
|
|
89
86
|
getStrand(strandId: string): StrandInstance | undefined;
|
|
90
87
|
/**
|
|
@@ -117,9 +114,10 @@ export interface StrandWakeServiceOptions {
|
|
|
117
114
|
}
|
|
118
115
|
/**
|
|
119
116
|
* Receiver side of the push-wake protocol. Registers a `WAKE_PROTOCOL` handler
|
|
120
|
-
* on the control node and, for each inbound {@link WakeRequest}
|
|
121
|
-
*
|
|
122
|
-
* strand if it is hibernating/idle
|
|
117
|
+
* on the control node and, for each inbound {@link WakeRequest} (from a peer the
|
|
118
|
+
* protocol guard has already admitted as an authorized member), replies with a
|
|
119
|
+
* {@link WakeAck} and starts resuming the named strand if it is hibernating/idle
|
|
120
|
+
* and we participate in it.
|
|
123
121
|
*/
|
|
124
122
|
export declare class StrandWakeService {
|
|
125
123
|
private readonly options;
|
|
@@ -155,8 +153,7 @@ export declare class StrandWakeService {
|
|
|
155
153
|
* Decide the wake for a decoded request and start it. Exposed (not private) so
|
|
156
154
|
* the decision matrix can be unit-tested directly.
|
|
157
155
|
*
|
|
158
|
-
* -
|
|
159
|
-
* - Unknown / not-participated strand → rejected.
|
|
156
|
+
* - Unknown / not-participated strand → rejected (`accepted: false`).
|
|
160
157
|
* - Hibernating or idle strand → `accepted` with that status, and a wake started.
|
|
161
158
|
* - Already-live strand → no-op, `accepted` with current status.
|
|
162
159
|
*
|
|
@@ -16,18 +16,17 @@
|
|
|
16
16
|
*
|
|
17
17
|
* **Authorization (v1):** a wake is low-risk — it only causes the receiver to
|
|
18
18
|
* spend resources coming online for a strand it already participates in — so the
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* a voucher that verifies against an owner key in the receiver's
|
|
23
|
-
* trusted-owner anchor), so a peer that merely published rows into the
|
|
24
|
-
* control DB
|
|
25
|
-
* predicate it is given.
|
|
19
|
+
* request carries no signature. Membership is checked before this handler runs, by
|
|
20
|
+
* the control node's protocol guard (`control-protocol-guard.ts`, the `members`
|
|
21
|
+
* class: `CadreNode.isAuthorizedMember`, under which the sender's `CadrePeer` row
|
|
22
|
+
* must carry a voucher that verifies against an owner key in the receiver's
|
|
23
|
+
* node-local trusted-owner anchor), so a peer that merely published rows into the
|
|
24
|
+
* replicated control DB gets its stream reset and never reaches this module.
|
|
26
25
|
*/
|
|
27
26
|
import debug from 'debug';
|
|
28
27
|
import { decodeLengthPrefixedFrame } from './seed-bootstrap.js';
|
|
29
28
|
import { exchangeFrame, readStreamToEnd, replyAndClose } from './control-stream.js';
|
|
30
|
-
import { tryAddrsInTurn } from './peer-dial.js';
|
|
29
|
+
import { dialAddr, tryAddrsInTurn } from './peer-dial.js';
|
|
31
30
|
import { relayedRequestBudgetMs } from './link-budget.js';
|
|
32
31
|
const log = debug('sereus:cadre:strand-wake');
|
|
33
32
|
/** Protocol id for control-network push-wake (parallel to `/sereus/seed/1.0.0`). */
|
|
@@ -47,8 +46,8 @@ const MAX_WAKE_SIZE = 64 * 1024;
|
|
|
47
46
|
* It holds only link work because the receiver acks as soon as it has DECIDED, before the
|
|
48
47
|
* wake itself runs ({@link StrandWakeService.processWakeRequest}).
|
|
49
48
|
*
|
|
50
|
-
* NOTE: the receiver's membership check (two live control reads
|
|
51
|
-
* is not counted. In steady state those reads touch only held blocks and do not consult the
|
|
49
|
+
* NOTE: the receiver's membership check (two live control reads, in its protocol guard) runs
|
|
50
|
+
* inside this deadline and is not counted. In steady state those reads touch only held blocks and do not consult the
|
|
52
51
|
* cohort. If a wake or address request is seen timing out while the receiver's membership read
|
|
53
52
|
* is consulting, count one membership decision in this deadline or answer the check from the
|
|
54
53
|
* materialized authorized-peer snapshot. See docs/cadre-consistency.md → "Deadlines Over
|
|
@@ -105,9 +104,10 @@ async function readFrame(stream, timeoutMs) {
|
|
|
105
104
|
}
|
|
106
105
|
/**
|
|
107
106
|
* Receiver side of the push-wake protocol. Registers a `WAKE_PROTOCOL` handler
|
|
108
|
-
* on the control node and, for each inbound {@link WakeRequest}
|
|
109
|
-
*
|
|
110
|
-
* strand if it is hibernating/idle
|
|
107
|
+
* on the control node and, for each inbound {@link WakeRequest} (from a peer the
|
|
108
|
+
* protocol guard has already admitted as an authorized member), replies with a
|
|
109
|
+
* {@link WakeAck} and starts resuming the named strand if it is hibernating/idle
|
|
110
|
+
* and we participate in it.
|
|
111
111
|
*/
|
|
112
112
|
export class StrandWakeService {
|
|
113
113
|
constructor(options) {
|
|
@@ -187,8 +187,7 @@ export class StrandWakeService {
|
|
|
187
187
|
* Decide the wake for a decoded request and start it. Exposed (not private) so
|
|
188
188
|
* the decision matrix can be unit-tested directly.
|
|
189
189
|
*
|
|
190
|
-
* -
|
|
191
|
-
* - Unknown / not-participated strand → rejected.
|
|
190
|
+
* - Unknown / not-participated strand → rejected (`accepted: false`).
|
|
192
191
|
* - Hibernating or idle strand → `accepted` with that status, and a wake started.
|
|
193
192
|
* - Already-live strand → no-op, `accepted` with current status.
|
|
194
193
|
*
|
|
@@ -198,12 +197,6 @@ export class StrandWakeService {
|
|
|
198
197
|
* sender's attempt deadline, coupling that deadline to this node's own budgets.
|
|
199
198
|
*/
|
|
200
199
|
async processWakeRequest(request, remotePeerId) {
|
|
201
|
-
// The injected membership predicate is the whole v1 authorization (CadreNode
|
|
202
|
-
// supplies the voucher-anchored one); only a peer it admits may ask us to wake.
|
|
203
|
-
if (!(await this.options.isMember(remotePeerId))) {
|
|
204
|
-
log('Rejecting wake from non-member %s', remotePeerId);
|
|
205
|
-
return { accepted: false, reason: 'Sender is not a cadre member' };
|
|
206
|
-
}
|
|
207
200
|
const instance = this.options.getStrand(request.strandId);
|
|
208
201
|
if (!instance) {
|
|
209
202
|
log('Rejecting wake for unknown/unparticipated strand %s', request.strandId);
|
|
@@ -275,20 +268,23 @@ export async function dialWake(node, addrs, request, options = {}) {
|
|
|
275
268
|
return await tryAddrsInTurn(addrs, budget, 'Wake dial', (addr, signal, attemptMs) => sendWake(node, addr, protocolId, request, attemptMs, signal));
|
|
276
269
|
}
|
|
277
270
|
/**
|
|
278
|
-
*
|
|
271
|
+
* Dial one address, open one stream, send the request, half-close, and read the ack.
|
|
272
|
+
*
|
|
273
|
+
* The address is dialed outside libp2p's dial queue (`dialAddr`), so another dial of
|
|
274
|
+
* the target in flight cannot capture this attempt; an open connection is still reused.
|
|
279
275
|
*
|
|
280
|
-
* `signal` is the per-attempt deadline from {@link dialWake}: it goes to
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* releasing the otherwise unbounded ack-read.
|
|
276
|
+
* `signal` is the per-attempt deadline from {@link dialWake}: it goes to the dial so a
|
|
277
|
+
* timeout during connect aborts it, and into {@link exchangeFrame} so a timeout after
|
|
278
|
+
* the stream is open resets it — releasing the otherwise unbounded ack-read.
|
|
284
279
|
*/
|
|
285
280
|
async function sendWake(node, addr, protocolId, request, timeoutMs, signal) {
|
|
281
|
+
const connection = await dialAddr(node, addr, signal, 'Wake dial');
|
|
286
282
|
// `runOnLimitedConnection: true`: the target may be reachable only over a
|
|
287
283
|
// circuit-relay connection (the signaling-first addr), which libp2p marks
|
|
288
284
|
// "limited". The wake exchange is a single tiny request→ack well within the
|
|
289
285
|
// relay's data/duration cap, so opening it on the limited connection is safe
|
|
290
286
|
// and is the whole point of dialing the relay address.
|
|
291
|
-
const rawStream = await
|
|
287
|
+
const rawStream = await connection.newStream(protocolId, { runOnLimitedConnection: true, signal });
|
|
292
288
|
const ack = await exchangeFrame(rawStream, signal, request, (stream) => readFrame(stream, timeoutMs), 'Wake dial aborted by timeout');
|
|
293
289
|
log('Wake ack from %s: accepted=%s status=%s', addr.toString(), ack.accepted, ack.status ?? '-');
|
|
294
290
|
return ack;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strand-wake-protocol.js","sourceRoot":"","sources":["../src/strand-wake-protocol.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"strand-wake-protocol.js","sourceRoot":"","sources":["../src/strand-wake-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAsB,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACxG,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,MAAM,GAAG,GAAG,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAE9C,oFAAoF;AACpF,MAAM,CAAC,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAEzD;;;;GAIG;AACH,MAAM,aAAa,GAAG,EAAE,GAAG,IAAI,CAAC;AAEhC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM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EAAE,MAAM,CAAC,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;;;;GASG;AACH,KAAK,UAAU,QAAQ,CACrB,IAAY,EACZ,IAAe,EACf,UAAkB,EAClB,OAAoB,EACpB,SAAiB,EACjB,MAAmB;IAEnB,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACnE,0EAA0E;IAC1E,0EAA0E;IAC1E,4EAA4E;IAC5E,6EAA6E;IAC7E,uDAAuD;IACvD,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,sBAAsB,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAEnG,MAAM,GAAG,GAAG,MAAM,aAAa,CAC7B,SAAqC,EACrC,MAAM,EACN,OAAO,EACP,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,CAAU,MAAM,EAAE,SAAS,CAAC,EACjD,8BAA8B,CAC/B,CAAC;IAEF,GAAG,CAAC,yCAAyC,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC;IACjG,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { type DurableSlot } from './node-local-snapshot.js';
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* How an owner key entered the anchor. Every source but `chain` is out-of-band provenance
|
|
4
|
+
* and forms the base the anchor sync derives from; `claim` is the durable "this node has
|
|
5
|
+
* been claimed" marker: the first seed whose sender proved it held the node's claim secret
|
|
6
|
+
* anchored its signer under this source. `chain` marks a key derived from the replicated
|
|
7
|
+
* `OwnerKey` table through a proof that verified against a key already anchored
|
|
8
|
+
* (`CadreNode.syncOwnerAnchor`); the sync keeps such an entry while its row is live and
|
|
9
|
+
* prunes it once the row is gone, which a base entry never is.
|
|
10
|
+
*/
|
|
11
|
+
export type TrustSource = 'genesis' | 'invite' | 'operator' | 'claim' | 'chain';
|
|
4
12
|
export interface TrustedOwnerStore {
|
|
5
13
|
/** Party this anchor is scoped to. */
|
|
6
14
|
readonly partyId: string;
|
|
@@ -16,14 +24,28 @@ export interface TrustedOwnerStore {
|
|
|
16
24
|
*/
|
|
17
25
|
all(): ReadonlySet<string>;
|
|
18
26
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
27
|
+
* Every anchored key with its provenance, as a snapshot (same copy contract as
|
|
28
|
+
* {@link all}). The anchor sync splits the base (every source but `chain`) from the
|
|
29
|
+
* derived entries with this.
|
|
30
|
+
*/
|
|
31
|
+
sources(): ReadonlyMap<string, TrustSource>;
|
|
32
|
+
/**
|
|
33
|
+
* Add a key. Idempotent with one asymmetry in provenance: re-trusting a known key
|
|
34
|
+
* keeps its source, EXCEPT that an out-of-band source over an existing `chain` entry
|
|
35
|
+
* rewrites the provenance (out of band wins: the key is then base, and a later sync
|
|
36
|
+
* no longer prunes it when its row goes), while `trust(key, 'chain')` over any
|
|
37
|
+
* existing entry is a no-op. Implementations MUST reflect the key in {@link has} /
|
|
22
38
|
* {@link all} synchronously; the returned promise tracks durability only
|
|
23
39
|
* (a persistent backend's write), so a synchronous caller may safely consult
|
|
24
40
|
* the store right after invoking this.
|
|
25
41
|
*/
|
|
26
42
|
trust(ownerKey: string, source: TrustSource): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Drop a key, with {@link trust}'s contract: gone from {@link has} / {@link all}
|
|
45
|
+
* synchronously, the returned promise tracks durability. Removing an absent key
|
|
46
|
+
* is a no-op. See the module doc for who may call this.
|
|
47
|
+
*/
|
|
48
|
+
remove(ownerKey: string): Promise<void>;
|
|
27
49
|
}
|
|
28
50
|
/**
|
|
29
51
|
* Ephemeral in-memory anchor for nodes without durable storage (tests, browser
|
|
@@ -36,7 +58,9 @@ export declare class MemoryTrustedOwnerStore implements TrustedOwnerStore {
|
|
|
36
58
|
constructor(partyId: string);
|
|
37
59
|
has(ownerKey: string): boolean;
|
|
38
60
|
all(): ReadonlySet<string>;
|
|
61
|
+
sources(): ReadonlyMap<string, TrustSource>;
|
|
39
62
|
trust(ownerKey: string, source: TrustSource): Promise<void>;
|
|
63
|
+
remove(ownerKey: string): Promise<void>;
|
|
40
64
|
}
|
|
41
65
|
/**
|
|
42
66
|
* Durable {@link TrustedOwnerStore} over an app-supplied {@link DurableSlot} —
|
|
@@ -56,9 +80,15 @@ export declare class PersistentTrustedOwnerStore implements TrustedOwnerStore {
|
|
|
56
80
|
get partyId(): string;
|
|
57
81
|
has(ownerKey: string): boolean;
|
|
58
82
|
all(): ReadonlySet<string>;
|
|
83
|
+
sources(): ReadonlyMap<string, TrustSource>;
|
|
59
84
|
/**
|
|
60
85
|
* Anchor a key: visible via {@link has} / {@link all} synchronously, then the
|
|
61
86
|
* full snapshot is persisted (see `NodeLocalSnapshot.put`).
|
|
62
87
|
*/
|
|
63
88
|
trust(ownerKey: string, source: TrustSource): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Drop a key: gone from {@link has} / {@link all} synchronously, then the full
|
|
91
|
+
* snapshot is persisted (see `NodeLocalSnapshot.remove`).
|
|
92
|
+
*/
|
|
93
|
+
remove(ownerKey: string): Promise<void>;
|
|
64
94
|
}
|