@serfab/cadre-core 1.9.0 → 1.10.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.
Files changed (87) hide show
  1. package/dist/cadre-node.d.ts +148 -17
  2. package/dist/cadre-node.js +361 -45
  3. package/dist/cadre-node.js.map +1 -1
  4. package/dist/control-authorization.d.ts +2 -2
  5. package/dist/control-authorization.js +1 -0
  6. package/dist/control-authorization.js.map +1 -1
  7. package/dist/control-cohort.d.ts +1 -1
  8. package/dist/control-cohort.js +1 -1
  9. package/dist/control-database.d.ts +105 -14
  10. package/dist/control-database.js +242 -73
  11. package/dist/control-database.js.map +1 -1
  12. package/dist/control-formation-recorder.d.ts +6 -6
  13. package/dist/control-formation-recorder.js +7 -8
  14. package/dist/control-formation-recorder.js.map +1 -1
  15. package/dist/control-schema.d.ts +1 -1
  16. package/dist/control-schema.js +90 -3
  17. package/dist/control-schema.js.map +1 -1
  18. package/dist/control-write-retry.d.ts +21 -15
  19. package/dist/control-write-retry.js +21 -15
  20. package/dist/control-write-retry.js.map +1 -1
  21. package/dist/index.d.ts +5 -3
  22. package/dist/index.js +6 -2
  23. package/dist/index.js.map +1 -1
  24. package/dist/invitation-bootstrap.d.ts +32 -0
  25. package/dist/invitation-bootstrap.js +30 -0
  26. package/dist/invitation-bootstrap.js.map +1 -0
  27. package/dist/link-budget.d.ts +204 -119
  28. package/dist/link-budget.js +208 -120
  29. package/dist/link-budget.js.map +1 -1
  30. package/dist/membership-connection-gater.d.ts +3 -3
  31. package/dist/membership-connection-gater.js +3 -3
  32. package/dist/peer-dial.d.ts +18 -14
  33. package/dist/peer-dial.js +18 -14
  34. package/dist/peer-dial.js.map +1 -1
  35. package/dist/peer-join-backfill.d.ts +3 -3
  36. package/dist/pending-join-runner.d.ts +186 -0
  37. package/dist/pending-join-runner.js +649 -0
  38. package/dist/pending-join-runner.js.map +1 -0
  39. package/dist/push-fanout.d.ts +1 -1
  40. package/dist/push-fanout.js +1 -1
  41. package/dist/seed-bootstrap.d.ts +2 -2
  42. package/dist/seed-bootstrap.js +1 -1
  43. package/dist/strand-addr-protocol.js +2 -2
  44. package/dist/strand-formation-deadlines.d.ts +5 -5
  45. package/dist/strand-formation-deadlines.js +5 -5
  46. package/dist/strand-formation-manager.d.ts +18 -4
  47. package/dist/strand-formation-manager.js +48 -33
  48. package/dist/strand-formation-manager.js.map +1 -1
  49. package/dist/strand-formation-protocol.d.ts +71 -14
  50. package/dist/strand-formation-protocol.js +222 -47
  51. package/dist/strand-formation-protocol.js.map +1 -1
  52. package/dist/strand-formation-rejection.d.ts +94 -0
  53. package/dist/strand-formation-rejection.js +77 -0
  54. package/dist/strand-formation-rejection.js.map +1 -0
  55. package/dist/strand-instance-manager.js +4 -1
  56. package/dist/strand-instance-manager.js.map +1 -1
  57. package/dist/strand-solicitation.d.ts +11 -3
  58. package/dist/strand-solicitation.js +9 -0
  59. package/dist/strand-solicitation.js.map +1 -1
  60. package/dist/types.d.ts +103 -17
  61. package/dist/types.js +5 -9
  62. package/dist/types.js.map +1 -1
  63. package/package.json +22 -22
  64. package/src/cadre-node.ts +399 -46
  65. package/src/control-authorization.ts +117 -116
  66. package/src/control-cohort.ts +1 -1
  67. package/src/control-database.ts +303 -82
  68. package/src/control-formation-recorder.ts +8 -9
  69. package/src/control-schema.ts +90 -3
  70. package/src/control-write-retry.ts +21 -15
  71. package/src/index.ts +21 -1
  72. package/src/invitation-bootstrap.ts +40 -0
  73. package/src/link-budget.ts +221 -120
  74. package/src/membership-connection-gater.ts +3 -3
  75. package/src/peer-dial.ts +18 -14
  76. package/src/peer-join-backfill.ts +3 -3
  77. package/src/pending-join-runner.ts +735 -0
  78. package/src/push-fanout.ts +1 -1
  79. package/src/seed-bootstrap.ts +2 -2
  80. package/src/strand-addr-protocol.ts +2 -2
  81. package/src/strand-formation-deadlines.ts +5 -5
  82. package/src/strand-formation-manager.ts +62 -37
  83. package/src/strand-formation-protocol.ts +1036 -802
  84. package/src/strand-formation-rejection.ts +129 -0
  85. package/src/strand-instance-manager.ts +4 -1
  86. package/src/strand-solicitation.ts +17 -4
  87. package/src/types.ts +99 -17
@@ -58,66 +58,87 @@
58
58
  *
59
59
  * ── The counts, and what they cost ──
60
60
  *
61
- * | operation | link round trips | at the declared default |
62
- * | ---------------------------------------------------- | ---------------- | ----------------------- |
63
- * | open a relayed connection to another machine | 4 | 14 000 ms |
64
- * | dial the relay itself | 1 | 3 500 ms |
65
- * | request a reservation on an open relay connection | 1 | 3 500 ms |
66
- * | negotiate a protocol over an established circuit | 1 | 3 500 ms |
67
- * | one request and its answer over an open circuit | 2 | 7 000 ms |
68
- * | open a relayed connection, then negotiate one protocol| 5 | 17 500 ms |
69
- * | open a relayed connection, then one request on it | 6 | 21 000 ms |
70
- * | one Optimystic commit over connections already open | 20 | 70 000 ms |
71
- *
72
- * The reservation-request row is {@link RELAY_RESERVE_REQUEST_ROUND_TRIPS}, which also sizes how long
61
+ * | operation | link round trips | at the declared default |
62
+ * | ---------------------------------------------------------------- | ---------------- | ----------------------- |
63
+ * | open a relayed connection over a relay connection already open | 4 | 14 000 ms |
64
+ * | dial the relay itself | 1 | 3 500 ms |
65
+ * | open a relayed connection, opening the relay connection first | 5 | 17 500 ms |
66
+ * | request a reservation on an open relay connection | 1 | 3 500 ms |
67
+ * | negotiate a protocol over an established circuit | 1 | 3 500 ms |
68
+ * | one request and its answer over an open circuit | 2 | 7 000 ms |
69
+ * | open a relayed connection, then negotiate one protocol | 6 | 21 000 ms |
70
+ * | open a relayed connection, then one request on it | 7 | 24 500 ms |
71
+ * | one Optimystic commit over connections already open | 20 | 70 000 ms |
72
+ *
73
+ * Every row that opens a relayed connection counts opening the relay connection too
74
+ * ({@link RELAYED_DIAL_ROUND_TRIPS}), because a dialer cannot know beforehand whether it holds
75
+ * one, and a budget that is too short fails as silently as an absent peer. The
76
+ * reservation-request row is {@link RELAY_RESERVE_REQUEST_ROUND_TRIPS}, which also sizes how long
73
77
  * a party-run relay waits for a stranger's reservation ({@link relayAdmissionReserveDeadlineMs}).
74
78
  * The commit row is a measurement of a whole write, not a count of exchanges; its doc comment
75
79
  * ({@link COMMIT_ROUND_TRIPS}) holds the figures and says when to re-measure it.
76
80
  *
77
- * **Measured** 2026-09-26, one Windows machine, loopback dedicated relay: a relayed dial took
78
- * 20-25 ms at no delay, **7 255-7 279 ms at 900 ms one-way**, and **12 066-12 094 ms at 1 500 ms
79
- * one-way**. Four link round trips of pure delay would be 7 200 and 12 000, so the real cost
80
- * sits about 60-95 ms ABOVE the arithmetic — the handshakes, which no delay figure contains.
81
- * That residue is why {@link DECLARED_LINK_ROUND_TRIP_MS} carries headroom over the link sereus
82
- * supports rather than matching it exactly: a declaration equal to the supported round trip
83
- * would derive a budget marginally BELOW the dial it has to contain.
84
- *
85
- * ── The listener's admission decision ──
81
+ * **Measured** 2026-09-26, one Windows machine, loopback dedicated relay: a relayed dial over a
82
+ * relay connection the dialer already held took 20-25 ms at no delay, **7 255-7 279 ms at 900 ms
83
+ * one-way**, and **12 066-12 094 ms at 1 500 ms one-way**. Four link round trips of pure delay
84
+ * would be 7 200 and 12 000, so the real cost sits about 60-95 ms ABOVE the arithmetic — the
85
+ * handshakes, which no delay figure contains. On 2026-10-01 (libp2p 3.3.11), a dialer holding no
86
+ * relay connection took **15 113 ms at 1 500 ms one-way**: ten one-way delays, five link round
87
+ * trips, 113 ms above the arithmetic. That residue is why {@link DECLARED_LINK_ROUND_TRIP_MS}
88
+ * carries headroom over the link sereus supports rather than matching it exactly: a declaration
89
+ * equal to the supported round trip would derive a budget marginally BELOW the dial it has to
90
+ * contain.
91
+ *
92
+ * NOTE: the instrument splits the delay evenly across both hops (each node's own dialed socket
93
+ * gets the same one-way figure). On a link whose whole round trip sits on one machine's hop to
94
+ * the relay (a phone on a congested mobile link), the exchanges that cross only that hop — the
95
+ * relay dial, the hop-stream negotiation and CONNECT — may cost up to twice their share of the
96
+ * count. Not measured. If relayed dials are seen failing near their budget on such a link,
97
+ * measure that split before raising any count or the declaration.
98
+ *
99
+ * ── Admission decisions ──
86
100
  *
87
101
  * The table is link time only. Every budget that OPENS a connection also adds
88
- * {@link ADMISSION_DECISION_TIMEOUT_MS} (2 000 ms) per admission decision the machine being
89
- * called may make on the way, because that machine's gate runs on the dialer's clock (the
90
- * constant's doc says why). So a relayed dial is budgeted at 14 000 + 2 000 = 16 000 ms at the
91
- * default declaration, a dial plus one request at 23 000 ms, and a reservation drive, which a
92
- * party-run relay decides twice, at 18 000 ms. The allowance is flat: it is local decision
93
- * time, not link time, so it does not scale with the declaration.
94
- *
95
- * The measurement above crossed no gate. The instrument is bare libp2p on both sides, with no
96
- * cadre connection gater, so the 12 094 ms contains no admission decision at all. The
97
- * allowance is therefore on top of the measured dial rather than already inside it.
98
- *
99
- * NOTE: the measured dial also reused a connection to the relay that the dialer already held
100
- * (the instrument dials the relay first). A relayed dial that has to open that connection itself
101
- * spends one more link round trip, plus the relay's own admission decision when the relay is a
102
- * party-run control node, and the count counts neither; at the supported link such a dial fits
103
- * only while the called machine decides in under about 0.9 s.
104
- * `bug-relayed-dial-budget-omits-opening-the-relay-connection`.
102
+ * {@link ADMISSION_DECISION_TIMEOUT_MS} (2 000 ms) once for each gate the open may pass, because
103
+ * each gate runs on the dialer's clock (the constant's doc says why). A relayed dial passes
104
+ * {@link DIAL_ADMISSION_DECISIONS}, two: a party-run relay's, on the dialer's connection to it,
105
+ * then the called machine's. So a relayed dial is budgeted at 17 500 + 2 x 2 000 = 21 500 ms at
106
+ * the default declaration, a dial plus one request at 28 500 ms, and a reservation drive, which
107
+ * a party-run relay decides twice, at 18 000 ms. The allowance is flat: it is local decision
108
+ * time, not link time, so it does not scale with the declaration. One allowance per gate, rather
109
+ * than slack in the count, is what keeps each budget valid at every declaration.
110
+ *
111
+ * The measurement above crossed no gate. The instrument is bare libp2p on every side, with no
112
+ * cadre connection gater, so the 15 113 ms contains no admission decision at all. The
113
+ * allowances are therefore on top of the measured dial rather than already inside it.
105
114
  *
106
115
  * ── Optimystic's deadlines, from the same declaration ──
107
116
  *
108
117
  * cadre states its declared link to Optimystic on the control node and every strand node
109
- * (`@optimystic/db-p2p`'s `NodeOptions.linkRoundTripMs`, from 1.8.0), and Optimystic derives
110
- * its network deadlines from it (`resolveLinkDeadlines` in its `rpc-deadline.ts`), each never
111
- * below the LAN value it replaced. At the default declaration:
112
- *
113
- * | Optimystic deadline | link round trips | at the default | undeclared |
114
- * | ---------------------------------------------------- | ---------------- | -------------- | ---------- |
115
- * | libp2p `dialTimeout` and `inboundUpgradeTimeout` | 5 | 17 500 ms | 10 000 ms |
116
- * | one request's dial, stream negotiation included | 6 | 21 000 ms | 3 000 ms |
117
- * | one request's response | 3 | 10 500 ms | 10 000 ms |
118
- * | a rebalance transfer's dial, and again its reply | 6, floor 30 000 | 30 000 ms | 30 000 ms |
119
- *
120
- * Its churn and under-replication pushes take the request rows' values. The undeclared column
118
+ * (`@optimystic/db-p2p`'s `NodeOptions.linkRoundTripMs`), and Optimystic derives its network
119
+ * deadlines from it (`resolveLinkDeadlines` in its `rpc-deadline.ts`), each never below the LAN
120
+ * value it replaced. Optimystic's derivation is link time only, so cadre states the three limits
121
+ * that cover opening a connection itself ({@link optimysticDialLimits}): Optimystic's value plus
122
+ * {@link DIAL_ADMISSION_DECISIONS} admission decisions. At the default declaration:
123
+ *
124
+ * | deadline | link round trips | at the default | undeclared |
125
+ * | ------------------------------------------------------- | ---------------------- | -------------- | ---------- |
126
+ * | libp2p `addressDialTimeout`, one address of a dial | 10, + 2 decisions | 39 000 ms | 6 000 ms |
127
+ * | libp2p `dialTimeout`, a dial that carries no signal | 10, + 2 decisions | 39 000 ms | 10 000 ms |
128
+ * | libp2p `inboundUpgradeTimeout`, the listener's side | 5 | 17 500 ms | 10 000 ms |
129
+ * | one request's dial, stream negotiation included | 11, + 2 decisions | 42 500 ms | 3 000 ms |
130
+ * | one request's response | 3 | 10 500 ms | 10 000 ms |
131
+ * | a rebalance transfer's dial, and again its reply | request dial, ≥ 30 000 | 42 500 ms | 30 000 ms |
132
+ *
133
+ * Ten round trips is Optimystic's count for opening a relayed connection through a relay the
134
+ * dialer is not yet connected to, which opens that connection first (about 8.6 round trips over
135
+ * WebSocket, 9.6 over `wss`), with a margin. The two decisions are the gates that open runs
136
+ * through on the dialer's clock: a party-run relay's, on the dialer's connection to it, then the
137
+ * called machine's. Each may take {@link ADMISSION_DECISION_TIMEOUT_MS}.
138
+ *
139
+ * Its churn and under-replication pushes take the request rows' values, and the Quereus plugin
140
+ * derives a write's budgets from the request dial: four of them for the transaction (170 000 ms)
141
+ * and one for cancelling it (42 500 ms). The undeclared column
121
142
  * is why cadre always states the value, default included. A fixed 3 000 ms request dial cannot
122
143
  * open a relayed connection above 375 ms one-way, and it also bounded the protocol negotiation
123
144
  * on a connection that was already open, which is one link round trip: at the supported link
@@ -128,29 +149,38 @@
128
149
  * ({@link cohortReadDeadlineMs} says why).
129
150
  *
130
151
  * NOTE: the longer deadlines are paid against a machine that is gone. An Optimystic request
131
- * to a peer that never completes a connection now waits up to the 21 000 ms dial deadline where
132
- * it waited 3 000, and one that connects and never answers waits 10 500 where it waited 10 000.
133
- * Measured 2026-09-30 (`control-write-degraded-cohort-member.integration.ts`): a control write
134
- * against a connected, silent member failed at 42.2 s, against 40.2 s with no link declared.
135
- * The dial case was not measured. cadre's cut-off budgets (`CONTROL_WRITE_RETRY_BUDGET_MS`,
136
- * `CONTROL_READ_RETRY_BUDGET_MS`) are checked between attempts, so one attempt can outlast
137
- * them by that much. If writes on a fast link are seen waiting out the dial deadline against an
138
- * unreachable machine, declare that deployment's real round trip instead of the default.
139
- *
140
- * libp2p's two limits bound the same relayed dial as cadre's budgets do: the DIALER's
141
- * `dialTimeout`, which bounds every dial that carries no abort signal of its own, and the
142
- * LISTENER's `inboundUpgradeTimeout`, which is how long the machine being called lets a
143
- * half-built connection finish its handshakes. At libp2p's 10 000 ms, no relayed connection
144
- * could be opened above about 1 250 ms one-way (a 2.5-second link round trip) whatever cadre
145
- * declared, and the listener's limit is the one that makes that failure silent: at 1 500 ms
146
- * one-way the dialer's own 12 094 ms dial RESOLVED while the listener had already thrown the
147
- * connection away at 10 s, so the first stream over it died with `Unexpected EOF - stream
148
- * closed while reading 0/1 bytes` and the listener reported no peer at all. Optimystic's
149
- * derivation contains {@link relayedDialBudgetMs} at every declaration: five round trips are at
150
- * least four plus the {@link ADMISSION_DECISION_TIMEOUT_MS} allowance once the round trip
151
- * reaches 2 000 ms, and the 10 000 ms floor covers every shorter one. `link-budget.spec.ts` pins
152
- * that against Optimystic's own derivation, so a change on either side that breaks it fails
153
- * there rather than silently on a slow link.
152
+ * to a peer that never completes a connection waits up to the 42 500 ms dial deadline, each of
153
+ * that peer's addresses up to 39 000 ms inside it, and one that connects and never answers
154
+ * waits 10 500. A control write against a connected, silent member fails after about 84 s
155
+ * (one pend round and three cancel rounds; `docs/cadre-consistency.md` → "Deadlines Over
156
+ * Optimystic's Reads and Commits"). The dial case was not measured. cadre's cut-off budgets
157
+ * (`CONTROL_WRITE_RETRY_BUDGET_MS`, `CONTROL_READ_RETRY_BUDGET_MS`) are checked between
158
+ * attempts, so one attempt can outlast them by that much. If writes on a fast link are seen
159
+ * waiting out the dial deadline against an unreachable machine, declare that deployment's real
160
+ * round trip instead of the default.
161
+ *
162
+ * The LISTENER's `inboundUpgradeTimeout` is how long the machine being called lets a half-built
163
+ * connection finish its handshakes, and it is the limit that makes a dial outlasting it silent:
164
+ * at libp2p's 10 000 ms and 1 500 ms one-way, the dialer's own 12 094 ms dial RESOLVED while
165
+ * the listener had already thrown the connection away at 10 s, so the first stream over it died
166
+ * with `Unexpected EOF - stream closed while reading 0/1 bytes` and the listener reported no
167
+ * peer at all. cadre leaves it to Optimystic, with no decisions added: its timer starts when the
168
+ * relay hands the listener the inbound circuit, so it runs over the listener's own upgrade and
169
+ * the listener's own decision, never over the dialer's connection to the relay or the relay's
170
+ * decision. So it has to contain the part of {@link relayedDialBudgetMs} its clock covers, not
171
+ * the whole budget: at most the circuit leg ({@link CIRCUIT_DIAL_ROUND_TRIPS}) plus one
172
+ * {@link ADMISSION_DECISION_TIMEOUT_MS}. Optimystic's derivation does at every declaration: five
173
+ * round trips are at least four plus the allowance once the round trip reaches 2 000 ms, and the
174
+ * 10 000 ms floor covers every shorter one. `link-budget.spec.ts` pins that against Optimystic's
175
+ * own derivation, so a change on either side that breaks it fails there rather than silently on
176
+ * a slow link.
177
+ *
178
+ * NOTE: the whole {@link relayedDialBudgetMs} is longer than the listener's limit (21 500 ms
179
+ * against 17 500 ms at the default), so on a link SLOWER than the one declared, a dial over a
180
+ * relay connection the dialer already holds can outlast the listener while its own budget still
181
+ * runs (at the default, between about a 4.4 s and a 5.4 s round trip), and fails silently
182
+ * instead of with a timeout. At or below the declared link it cannot. If streams dying with
183
+ * `Unexpected EOF` are seen on such a link, declare that link's real round trip.
154
184
  *
155
185
  * NOTE: derived from the declaration alone, so a per-field override that raises a cadre dial
156
186
  * budget above it (`controlCohort.perAddressDialTimeoutMs`, `strandBackfill.dialTimeoutMs`)
@@ -173,20 +203,20 @@
173
203
  * declaring a faster link than a client closes that client's connection before its request
174
204
  * arrives.
175
205
  */
206
+ import { type Libp2pConnectionTimeouts, type RpcDeadlineDefaults } from '@optimystic/db-p2p';
176
207
  /**
177
208
  * The link round trip cadre assumes when a host declares none, in milliseconds. A deployment
178
209
  * that knows its own link states it with `NetworkConfig.linkRoundTripMs` instead.
179
210
  *
180
211
  * **Why 3 500.** Sereus supports two machines that reach each other only through a relay up to
181
212
  * a **3-second link round trip** (1 500 ms each way — a congested mobile or satellite link;
182
- * `docs/architecture.md` → "Relay Integration"). The worst relayed dial measured at that link
183
- * was 12 094 ms, above the 12 000 ms a declaration of exactly 3 000 would derive, so the
184
- * declaration rounds the supported link up to the next half second. 3 500 derives 14 000 ms
185
- * of link time and leaves about 1.9 s over that dial: room for a phone's Noise handshake,
186
- * which the loopback measurement on a desktop does not contain. The listener's admission
187
- * decision is not in that 1.9 s; it has its own allowance on top (the module doc's "The
188
- * listener's admission decision"). (The previous 2 000 followed the same convention for the
189
- * 1.8 s band sereus supported before, with about 720 ms to spare.)
213
+ * `docs/architecture.md` → "Relay Integration"). The worst relayed dial measured at that link,
214
+ * opening the relay connection first, was 15 113 ms, above the 15 000 ms a declaration of
215
+ * exactly 3 000 would derive, so the declaration rounds the supported link up to the next half
216
+ * second. 3 500 derives 17 500 ms of link time and leaves about 2.4 s over that dial: room for a
217
+ * phone's Noise handshakes, which the loopback measurement on a desktop does not contain. The
218
+ * admission decisions are not in that 2.4 s; they have their own allowance on top (the module
219
+ * doc's "Admission decisions").
190
220
  *
191
221
  * One budget outside this module does NOT move with it: `DEFAULT_STRAND_FIRST_SYNC_TIMEOUT_MS`
192
222
  * (`strand-first-sync-gate.ts`) bounds a whole first sync, which has no round-trip count, so it
@@ -195,31 +225,35 @@
195
225
  * ({@link cohortReadDeadlineMs}).
196
226
  *
197
227
  * What 3 500 costs, against 2 000: a peer that is genuinely gone holds each operation longer
198
- * before it is abandoned and retried — the link part of a relayed dial or a reservation drive
199
- * 14 s instead of 8 s, and of a control-cohort dial of one peer across all its addresses 56 s
200
- * instead of 32 s. The admission allowance adds to both (see {@link relayedDialBudgetMs}).
228
+ * before it is abandoned and retried — the link part of a relayed dial 17.5 s instead of 10 s,
229
+ * of a reservation drive 14 s instead of 8 s, and of a control-cohort dial of one peer across
230
+ * all its addresses 70 s instead of 40 s. The admission allowances add to each (see
231
+ * {@link relayedDialBudgetMs}).
201
232
  * Raise it further for a link slower still; lower it only on a deployment where EVERY machine
202
233
  * of the party is that close, for the reason the "What still fails" list gives.
203
234
  */
204
235
  export declare const DECLARED_LINK_ROUND_TRIP_MS = 3500;
205
236
  /**
206
- * Link round trips one relayed connection setup costs: transport, encryption and multiplexer
207
- * handshakes to the relay, the circuit open, then both handshakes again end to end through it.
208
- * Measured at 8 one-way delays, which is 4 link round trips.
237
+ * Link round trips opening a relayed connection costs over a relay connection the dialer
238
+ * ALREADY holds: the circuit open through the relay (hop-stream negotiation and CONNECT, then
239
+ * the relay's stop stream to the called machine), then the encryption and multiplexer
240
+ * handshakes end to end through it. Measured at 8 one-way delays.
209
241
  */
210
- export declare const RELAYED_DIAL_ROUND_TRIPS = 4;
242
+ export declare const CIRCUIT_DIAL_ROUND_TRIPS = 4;
211
243
  /**
212
- * Link round trips one whole reservation drive is budgeted for
213
- * (`relay-reservation.ts`'s `driveRelayReservation`, whose ONE deadline covers the dial, the
214
- * reservation request and the wait together).
215
- *
216
- * The protocol work measured is 2 — dial the relay (1) plus request the reservation (1). It is
217
- * budgeted at 4, the relayed-dial count, because the wait afterwards may instead be satisfied
218
- * by libp2p's own relay discovery, which repeats both legs after identify has run; 4 is
219
- * therefore the largest thing this one deadline can be asked to contain, and the poll interval
220
- * (`DEFAULT_RELAY_RESERVE_POLL_MS`) rounds up on top of it.
244
+ * Link round trips the dialer spends opening its own connection to the relay: transport,
245
+ * encryption and multiplexer handshakes on its one hop. Measured at 2 one-way delays. libp2p's
246
+ * circuit transport opens it inside the relayed dial, under the caller's signal, whenever no
247
+ * relay connection is open yet.
221
248
  */
222
- export declare const RELAY_RESERVATION_ROUND_TRIPS = 4;
249
+ export declare const RELAY_DIAL_ROUND_TRIPS = 1;
250
+ /**
251
+ * Link round trips a relayed dial is budgeted for: opening the relay connection
252
+ * ({@link RELAY_DIAL_ROUND_TRIPS}) and then the circuit over it ({@link CIRCUIT_DIAL_ROUND_TRIPS}).
253
+ * Measured at 10 one-way delays from a dialer holding no relay connection. Counted for every
254
+ * relayed dial, because a dialer cannot know beforehand whether that connection is open.
255
+ */
256
+ export declare const RELAYED_DIAL_ROUND_TRIPS: number;
223
257
  /**
224
258
  * Link round trips from the moment a party-run relay admits a stranger's connection for relay
225
259
  * use to the moment that stranger's RESERVE request reaches it. libp2p's reservation store
@@ -237,6 +271,19 @@ export declare const RELAY_RESERVATION_ROUND_TRIPS = 4;
237
271
  * {@link relayAdmissionReserveDeadlineMs} adds it separately.
238
272
  */
239
273
  export declare const RELAY_RESERVE_REQUEST_ROUND_TRIPS = 1;
274
+ /**
275
+ * Link round trips one whole reservation drive is budgeted for
276
+ * (`relay-reservation.ts`'s `driveRelayReservation`, whose ONE deadline covers the dial, the
277
+ * reservation request and the wait together).
278
+ *
279
+ * The protocol work measured is 2 — dial the relay ({@link RELAY_DIAL_ROUND_TRIPS}) plus request
280
+ * the reservation ({@link RELAY_RESERVE_REQUEST_ROUND_TRIPS}). It is budgeted at twice that,
281
+ * because the wait afterwards may instead be satisfied by libp2p's own relay discovery, which
282
+ * repeats both legs after identify has run; 4 is therefore the largest thing this one deadline
283
+ * can be asked to contain, and the poll interval (`DEFAULT_RELAY_RESERVE_POLL_MS`) rounds up on
284
+ * top of it.
285
+ */
286
+ export declare const RELAY_RESERVATION_ROUND_TRIPS: number;
240
287
  /**
241
288
  * Link round trips negotiating one protocol over an ALREADY-OPEN connection costs: the
242
289
  * multistream-select exchange that `dialProtocol` / `newStream` runs before the stream is
@@ -282,7 +329,7 @@ export declare const COMMIT_ROUND_TRIPS = 20;
282
329
  * possibly through a relay: {@link RELAYED_DIAL_ROUND_TRIPS} + {@link CIRCUIT_REQUEST_ROUND_TRIPS}.
283
330
  * The shape of cadre's own one-frame control protocols (strand wake, strand address, seed
284
331
  * delivery), each of which bounds the dial and the exchange with ONE deadline. Link time only:
285
- * {@link relayedRequestBudgetMs} adds the listener's admission allowance on top.
332
+ * {@link relayedRequestBudgetMs} adds the dial's admission allowances on top.
286
333
  */
287
334
  export declare const RELAYED_REQUEST_ROUND_TRIPS: number;
288
335
  /**
@@ -340,11 +387,13 @@ export declare const PUSH_TRANSFER_ALLOWANCE_MS = 6000;
340
387
  * - **The decision is spent on the dialing machine's clock.** libp2p's listener
341
388
  * runs this gate before it answers the multiplexer negotiation the dialer is
342
389
  * waiting on (`libp2p/dist/src/upgrader.js`), and the listener's own
343
- * `inboundUpgradeTimeout` is already running while it does. So
344
- * {@link relayedDialBudgetMs}, and every budget built on it, adds this
345
- * deadline once per decision the called machine may make, and the two libp2p
346
- * limits Optimystic derives from the same declaration contain it (the module
347
- * doc's "Optimystic's deadlines, from the same declaration").
390
+ * `inboundUpgradeTimeout` is already running while it does; a party-run
391
+ * relay runs the same gate on the dialer's connection to it. So
392
+ * {@link relayedDialBudgetMs}, every budget built on it, and the dial limits
393
+ * cadre states to Optimystic ({@link optimysticDialLimits}) add this deadline
394
+ * once for each of the {@link DIAL_ADMISSION_DECISIONS} gates a dial passes,
395
+ * and the listener's limit Optimystic derives contains the called machine's
396
+ * (the module doc's "Optimystic's deadlines, from the same declaration").
348
397
  * Raising it therefore lengthens every dial budget with it: a slow decision
349
398
  * still fits, and a dial to a peer that is gone takes that much longer to
350
399
  * give up.
@@ -370,28 +419,35 @@ export declare const ADMISSION_DECISION_TIMEOUT_MS = 2000;
370
419
  * throw inside a best-effort path that logs and carries on.
371
420
  */
372
421
  export declare function resolveLinkRoundTripMs(linkRoundTripMs?: number): number;
422
+ /**
423
+ * Admission decisions a relayed dial may wait on, each on the dialer's clock: a party-run relay's,
424
+ * on the dialer's connection to it (`denyInboundEncryptedConnection`), then the called machine's.
425
+ */
426
+ export declare const DIAL_ADMISSION_DECISIONS = 2;
373
427
  /**
374
428
  * Deadline for OPENING a connection to another machine that may only be reachable through a
375
- * relay: {@link RELAYED_DIAL_ROUND_TRIPS} at the declared link round trip, plus one
376
- * {@link ADMISSION_DECISION_TIMEOUT_MS} for the called machine's inbound gate, which runs on
377
- * this dial's clock. 4 x 3 500 + 2 000 = 16 000 ms at the default declaration.
378
- *
379
- * What the allowance costs: a peer that is truly gone holds each dial 2 s longer before it is
380
- * abandoned — a per-address dial 16 s instead of 14 s, a control-cohort dial of one peer across
381
- * its 4 addresses 64 s instead of 56 s, and a wake call's two attempts 46 s instead of 42 s. A
382
- * machine that runs no gate (the dedicated relay container, an open-strand node) gets the same
383
- * budget; the extra 2 s only lengthens a failure there, never a success.
429
+ * relay: {@link RELAYED_DIAL_ROUND_TRIPS} at the declared link round trip, which includes opening
430
+ * the dialer's own connection to the relay, plus one {@link ADMISSION_DECISION_TIMEOUT_MS} for
431
+ * each of the {@link DIAL_ADMISSION_DECISIONS} gates that run on this dial's clock.
432
+ * 5 x 3 500 + 2 x 2 000 = 21 500 ms at the default declaration.
433
+ *
434
+ * What it costs: a peer that is truly gone holds each dial this long before it is abandoned — a
435
+ * per-address dial 21.5 s, a control-cohort dial of one peer across its 4 addresses 86 s, and a
436
+ * wake call's two attempts 57 s — of which the relay leg and the relay's decision are 5.5 s per
437
+ * dial. A dial over a relay connection already open, or to a machine that runs no gate (the
438
+ * dedicated relay container, an open-strand node), gets the same budget; the unused part only
439
+ * lengthens a failure there, never a success.
384
440
  *
385
441
  * A per-field override of a deadline derived from this one
386
442
  * (`network.controlCohort.perAddressDialTimeoutMs`, `strandBackfill.dialTimeoutMs`,
387
- * `DialWakeOptions.timeoutMs`, …) replaces the whole derived value, allowance included.
443
+ * `DialWakeOptions.timeoutMs`, …) replaces the whole derived value, allowances included.
388
444
  */
389
445
  export declare function relayedDialBudgetMs(linkRoundTripMs?: number): number;
390
446
  /**
391
447
  * Deadline for what `dialProtocol` does end to end: OPEN a possibly relayed connection
392
- * ({@link relayedDialBudgetMs}, admission allowance included) and then NEGOTIATE one protocol
393
- * on it ({@link PROTOCOL_NEGOTIATION_ROUND_TRIPS} at the declared link round trip). 16 000 +
394
- * 3 500 = 19 500 ms at the default declaration. The strand formation dial is bounded by this;
448
+ * ({@link relayedDialBudgetMs}, admission allowances included) and then NEGOTIATE one protocol
449
+ * on it ({@link PROTOCOL_NEGOTIATION_ROUND_TRIPS} at the declared link round trip). 21 500 +
450
+ * 3 500 = 25 000 ms at the default declaration. The strand formation dial is bounded by this;
395
451
  * the one-frame control exchanges bound the negotiation together with their request instead
396
452
  * ({@link relayedRequestBudgetMs}).
397
453
  */
@@ -438,9 +494,9 @@ export declare function relayAdmissionReserveDeadlineMs(linkRoundTripMs?: number
438
494
  export declare function circuitRequestBudgetMs(linkRoundTripMs?: number, transferAllowanceMs?: number): number;
439
495
  /**
440
496
  * Deadline for opening a (possibly relayed) connection and completing one small request on it:
441
- * {@link relayedDialBudgetMs}, admission allowance included, plus
497
+ * {@link relayedDialBudgetMs}, admission allowances included, plus
442
498
  * {@link CIRCUIT_REQUEST_ROUND_TRIPS} at the declared link round trip — so
443
- * {@link RELAYED_REQUEST_ROUND_TRIPS} of link time in all. 16 000 + 2 x 3 500 = 23 000 ms at the
499
+ * {@link RELAYED_REQUEST_ROUND_TRIPS} of link time in all. 21 500 + 2 x 3 500 = 28 500 ms at the
444
500
  * default declaration.
445
501
  *
446
502
  * No transfer allowance, unlike {@link circuitRequestBudgetMs}: the requests this bounds are a few
@@ -520,3 +576,32 @@ export interface PeerJoinPushBudget {
520
576
  * `DEFAULT_PEER_JOIN_BACKFILL` must not drift apart.
521
577
  */
522
578
  export declare function peerJoinPushBudget(linkRoundTripMs?: number): PeerJoinPushBudget;
579
+ /** The connection limits cadre states to Optimystic on every node it builds, beside the declared link. */
580
+ export interface OptimysticDialLimits {
581
+ /** `NodeOptions.connectionManager`: libp2p's limit on one address of a dial, and on a dial that carries no signal. */
582
+ connectionManager: Required<Pick<Libp2pConnectionTimeouts, 'addressDialTimeout' | 'dialTimeout'>>;
583
+ /** `NodeOptions.rpcDeadlines`: the dial deadline of every Optimystic request. */
584
+ rpcDeadlines: Pick<RpcDeadlineDefaults, 'dialTimeoutMs'>;
585
+ }
586
+ /**
587
+ * The three limits that cover opening a connection, as cadre states them to Optimystic on the
588
+ * control node and every strand node: Optimystic's own derivation from the declared link
589
+ * (`resolveLinkDeadlines`), which is link time only, plus one {@link ADMISSION_DECISION_TIMEOUT_MS}
590
+ * for each of the {@link DIAL_ADMISSION_DECISIONS} gates the open runs through. 39 000 ms per
591
+ * address, 39 000 ms per dial and a 42 500 ms request dial at the default declaration.
592
+ *
593
+ * Built on Optimystic's derivation rather than restating its round-trip counts, so a change to
594
+ * them reaches every node without an edit here. `dialTimeout` stays at least `addressDialTimeout`,
595
+ * as Optimystic's derivation has it, because both take the same addition. The request dial stays
596
+ * one round trip longer than `addressDialTimeout`, also as Optimystic derives them, although
597
+ * Optimystic's `rpcDeadlines` doc asks for it to be no longer: that round trip is the stream
598
+ * negotiation after the connection opens, which the per-address limit does not cover.
599
+ *
600
+ * The listener's `inboundUpgradeTimeout` and the request response deadline are left to Optimystic:
601
+ * the listener's timer runs over its own upgrade and its own decision only (the module doc's
602
+ * "Optimystic's deadlines, from the same declaration"), and a response waits on no gate.
603
+ *
604
+ * The declaration is resolved first, so an invalid one fails with cadre's message. A round trip
605
+ * above Optimystic's `MAX_LINK_ROUND_TRIP_MS` throws from Optimystic, here.
606
+ */
607
+ export declare function optimysticDialLimits(linkRoundTripMs?: number): OptimysticDialLimits;