@serfab/cadre-core 0.13.0 → 1.1.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 (131) hide show
  1. package/README.md +20 -6
  2. package/dist/bootstrap-peer-store-file.js +2 -2
  3. package/dist/bootstrap-peer-store.d.ts +32 -12
  4. package/dist/bootstrap-peer-store.js +41 -15
  5. package/dist/bootstrap-peer-store.js.map +1 -1
  6. package/dist/cadre-node.d.ts +558 -80
  7. package/dist/cadre-node.js +1060 -170
  8. package/dist/cadre-node.js.map +1 -1
  9. package/dist/control-authorization.d.ts +2 -2
  10. package/dist/control-authorization.js +1 -0
  11. package/dist/control-authorization.js.map +1 -1
  12. package/dist/control-cohort.d.ts +13 -26
  13. package/dist/control-cohort.js +0 -26
  14. package/dist/control-cohort.js.map +1 -1
  15. package/dist/control-database.d.ts +299 -44
  16. package/dist/control-database.js +469 -69
  17. package/dist/control-database.js.map +1 -1
  18. package/dist/control-read-retry.d.ts +40 -11
  19. package/dist/control-read-retry.js +48 -15
  20. package/dist/control-read-retry.js.map +1 -1
  21. package/dist/control-retry.d.ts +58 -3
  22. package/dist/control-retry.js +58 -3
  23. package/dist/control-retry.js.map +1 -1
  24. package/dist/control-schema.d.ts +1 -1
  25. package/dist/control-schema.js +103 -19
  26. package/dist/control-schema.js.map +1 -1
  27. package/dist/control-write-retry.d.ts +80 -11
  28. package/dist/control-write-retry.js +176 -29
  29. package/dist/control-write-retry.js.map +1 -1
  30. package/dist/enrolled-machine-store.js +2 -2
  31. package/dist/index.d.ts +14 -7
  32. package/dist/index.js +33 -6
  33. package/dist/index.js.map +1 -1
  34. package/dist/node-local-snapshot.d.ts +15 -7
  35. package/dist/node-local-snapshot.js +23 -8
  36. package/dist/node-local-snapshot.js.map +1 -1
  37. package/dist/peer-dial.d.ts +143 -0
  38. package/dist/peer-dial.js +176 -0
  39. package/dist/peer-dial.js.map +1 -0
  40. package/dist/relay-addrs.d.ts +90 -52
  41. package/dist/relay-addrs.js +91 -59
  42. package/dist/relay-addrs.js.map +1 -1
  43. package/dist/relay-reservation.d.ts +71 -3
  44. package/dist/relay-reservation.js +116 -8
  45. package/dist/relay-reservation.js.map +1 -1
  46. package/dist/seed-bootstrap.d.ts +30 -1
  47. package/dist/seed-bootstrap.js +62 -17
  48. package/dist/seed-bootstrap.js.map +1 -1
  49. package/dist/storage-scope.d.ts +62 -0
  50. package/dist/storage-scope.js +75 -0
  51. package/dist/storage-scope.js.map +1 -0
  52. package/dist/strand-database.d.ts +34 -16
  53. package/dist/strand-database.js +38 -24
  54. package/dist/strand-database.js.map +1 -1
  55. package/dist/strand-first-sync-gate.d.ts +152 -0
  56. package/dist/strand-first-sync-gate.js +208 -0
  57. package/dist/strand-first-sync-gate.js.map +1 -0
  58. package/dist/strand-formation-manager.d.ts +87 -5
  59. package/dist/strand-formation-manager.js +109 -5
  60. package/dist/strand-formation-manager.js.map +1 -1
  61. package/dist/strand-formation-protocol.d.ts +21 -1
  62. package/dist/strand-formation-protocol.js +30 -0
  63. package/dist/strand-formation-protocol.js.map +1 -1
  64. package/dist/strand-instance-manager.d.ts +243 -6
  65. package/dist/strand-instance-manager.js +470 -37
  66. package/dist/strand-instance-manager.js.map +1 -1
  67. package/dist/strand-member-key.d.ts +20 -12
  68. package/dist/strand-member-key.js +20 -12
  69. package/dist/strand-member-key.js.map +1 -1
  70. package/dist/strand-member-registry.js +3 -0
  71. package/dist/strand-member-registry.js.map +1 -1
  72. package/dist/strand-membership-reconciler.d.ts +361 -0
  73. package/dist/strand-membership-reconciler.js +548 -0
  74. package/dist/strand-membership-reconciler.js.map +1 -0
  75. package/dist/strand-membership-writer.d.ts +131 -11
  76. package/dist/strand-membership-writer.js +396 -134
  77. package/dist/strand-membership-writer.js.map +1 -1
  78. package/dist/strand-network-config.d.ts +46 -14
  79. package/dist/strand-network-config.js +79 -23
  80. package/dist/strand-network-config.js.map +1 -1
  81. package/dist/strand-solicitation.d.ts +10 -1
  82. package/dist/strand-solicitation.js +5 -0
  83. package/dist/strand-solicitation.js.map +1 -1
  84. package/dist/strand-wake-protocol.d.ts +11 -7
  85. package/dist/strand-wake-protocol.js +20 -52
  86. package/dist/strand-wake-protocol.js.map +1 -1
  87. package/dist/strand-watcher.js +6 -0
  88. package/dist/strand-watcher.js.map +1 -1
  89. package/dist/timed-step.d.ts +12 -0
  90. package/dist/timed-step.js +28 -0
  91. package/dist/timed-step.js.map +1 -0
  92. package/dist/timeout-scheduler.d.ts +19 -0
  93. package/dist/timeout-scheduler.js +22 -0
  94. package/dist/timeout-scheduler.js.map +1 -0
  95. package/dist/types.d.ts +262 -30
  96. package/dist/types.js.map +1 -1
  97. package/package.json +8 -8
  98. package/src/bootstrap-peer-store-file.ts +2 -2
  99. package/src/bootstrap-peer-store.ts +69 -27
  100. package/src/cadre-node.ts +7301 -6353
  101. package/src/control-authorization.ts +2 -1
  102. package/src/control-cohort.ts +122 -130
  103. package/src/control-database.ts +537 -69
  104. package/src/control-read-retry.ts +202 -167
  105. package/src/control-retry.ts +297 -190
  106. package/src/control-schema.ts +103 -19
  107. package/src/control-write-retry.ts +533 -383
  108. package/src/enrolled-machine-store.ts +2 -2
  109. package/src/index.ts +83 -6
  110. package/src/node-local-snapshot.ts +25 -8
  111. package/src/peer-dial.ts +215 -0
  112. package/src/relay-addrs.ts +458 -436
  113. package/src/relay-reservation.ts +951 -828
  114. package/src/seed-bootstrap.ts +76 -18
  115. package/src/storage-scope.ts +78 -0
  116. package/src/strand-database.ts +50 -27
  117. package/src/strand-first-sync-gate.ts +258 -0
  118. package/src/strand-formation-manager.ts +140 -5
  119. package/src/strand-formation-protocol.ts +43 -1
  120. package/src/strand-instance-manager.ts +577 -37
  121. package/src/strand-member-key.ts +20 -12
  122. package/src/strand-member-registry.ts +3 -0
  123. package/src/strand-membership-reconciler.ts +680 -0
  124. package/src/strand-membership-writer.ts +527 -189
  125. package/src/strand-network-config.ts +102 -24
  126. package/src/strand-solicitation.ts +16 -1
  127. package/src/strand-wake-protocol.ts +21 -66
  128. package/src/strand-watcher.ts +6 -0
  129. package/src/timed-step.ts +28 -0
  130. package/src/timeout-scheduler.ts +28 -0
  131. package/src/types.ts +1789 -1554
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,YAAY,CAAC;AAE3B,+DAA+D;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,uBAAuB;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,mBAAmB;AACnB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,eAAe,EAAoM,MAAM,uBAAuB,CAAC;AAE9W,+EAA+E;AAC/E,qFAAqF;AACrF,yCAAyC;AACzC,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC7B,oBAAoB,EACpB,wBAAwB,EACxB,8BAA8B,EAC9B,4BAA4B,EAC5B,iBAAiB,EAElB,MAAM,0BAA0B,CAAC;AAElC,gFAAgF;AAChF,yFAAyF;AACzF,OAAO,EACL,qBAAqB,EACrB,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,EAC7B,gBAAgB,EAEjB,MAAM,yBAAyB,CAAC;AAEjC,2FAA2F;AAC3F,OAAO,EAAE,0BAA0B,EAA0C,MAAM,4BAA4B,CAAC;AAEhH,2DAA2D;AAC3D,OAAO,EAAE,wBAAwB,EAAE,2BAA2B,EAAE,0BAA0B,EAAuB,MAAM,kBAAkB,CAAC;AAE1I,2EAA2E;AAC3E,gFAAgF;AAChF,8EAA8E;AAC9E,+EAA+E;AAC/E,2BAA2B;AAC3B,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EAGxB,MAAM,gBAAgB,CAAC;AAExB,8EAA8E;AAC9E,8EAA8E;AAC9E,gFAAgF;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 export declare class NodeLocalSnapshot<E> {
71
71
  private readonly spec;
72
72
  private readonly entries;
73
73
  /**
74
- * Serialises persists: every {@link put} snapshot-writes the full entry set,
75
- * so chaining writes keeps them ordered and the last landed snapshot
76
- * complete.
74
+ * Serialises persists: every write ({@link put}, {@link remove}) snapshot-writes
75
+ * the full entry set, so chaining writes keeps them ordered and the last landed
76
+ * snapshot complete.
77
77
  */
78
78
  private writeChain;
79
79
  private constructor();
@@ -95,12 +95,12 @@ export declare class NodeLocalSnapshot<E> {
95
95
  */
96
96
  static open<E>(slot: DurableSlot, partyId: string, spec: NodeLocalSnapshotSpec<E>): Promise<NodeLocalSnapshot<E>>;
97
97
  has(key: string): boolean;
98
- /** Fresh copy of the keys — a snapshot decoupled from later {@link put} calls. */
98
+ /** Fresh copy of the keys — a snapshot decoupled from later {@link put} / {@link remove} calls. */
99
99
  keySnapshot(): Set<string>;
100
100
  /**
101
101
  * Fresh copy of the `key -> entry` map — a snapshot decoupled from later
102
- * {@link put} calls. The entries themselves need no copy: {@link put}
103
- * REPLACES an entry rather than mutating it in place.
102
+ * {@link put} / {@link remove} calls. The entries themselves need no copy:
103
+ * {@link put} REPLACES an entry rather than mutating it in place.
104
104
  */
105
105
  entrySnapshot(): Map<string, E>;
106
106
  /**
@@ -108,8 +108,16 @@ export declare class NodeLocalSnapshot<E> {
108
108
  * synchronous caller may consult the store the moment this returns), then
109
109
  * the full snapshot is persisted. A persist failure rejects the returned
110
110
  * promise but leaves the entry in memory — this session's decision stands,
111
- * and any later successful {@link put} re-lands the complete set.
111
+ * and any later successful write re-lands the complete set.
112
112
  */
113
113
  put(key: string, entry: E): Promise<void>;
114
+ /**
115
+ * Remove an entry, with {@link put}'s contract: the in-memory map updates
116
+ * SYNCHRONOUSLY, then the full snapshot is persisted. Removing an absent key
117
+ * changes nothing, so it writes nothing.
118
+ */
119
+ remove(key: string): Promise<void>;
120
+ /** Chain a full-snapshot write behind every earlier one (see {@link put}). */
121
+ private queuePersist;
114
122
  private persistSnapshot;
115
123
  }
@@ -47,9 +47,9 @@ export class NodeLocalSnapshot {
47
47
  this.spec = spec;
48
48
  this.entries = entries;
49
49
  /**
50
- * Serialises persists: every {@link put} snapshot-writes the full entry set,
51
- * so chaining writes keeps them ordered and the last landed snapshot
52
- * complete.
50
+ * Serialises persists: every write ({@link put}, {@link remove}) snapshot-writes
51
+ * the full entry set, so chaining writes keeps them ordered and the last landed
52
+ * snapshot complete.
53
53
  */
54
54
  this.writeChain = Promise.resolve();
55
55
  }
@@ -75,14 +75,14 @@ export class NodeLocalSnapshot {
75
75
  has(key) {
76
76
  return this.entries.has(key);
77
77
  }
78
- /** Fresh copy of the keys — a snapshot decoupled from later {@link put} calls. */
78
+ /** Fresh copy of the keys — a snapshot decoupled from later {@link put} / {@link remove} calls. */
79
79
  keySnapshot() {
80
80
  return new Set(this.entries.keys());
81
81
  }
82
82
  /**
83
83
  * Fresh copy of the `key -> entry` map — a snapshot decoupled from later
84
- * {@link put} calls. The entries themselves need no copy: {@link put}
85
- * REPLACES an entry rather than mutating it in place.
84
+ * {@link put} / {@link remove} calls. The entries themselves need no copy:
85
+ * {@link put} REPLACES an entry rather than mutating it in place.
86
86
  */
87
87
  entrySnapshot() {
88
88
  return new Map(this.entries);
@@ -92,12 +92,27 @@ export class NodeLocalSnapshot {
92
92
  * synchronous caller may consult the store the moment this returns), then
93
93
  * the full snapshot is persisted. A persist failure rejects the returned
94
94
  * promise but leaves the entry in memory — this session's decision stands,
95
- * and any later successful {@link put} re-lands the complete set.
95
+ * and any later successful write re-lands the complete set.
96
96
  */
97
97
  put(key, entry) {
98
98
  this.entries.set(key, entry);
99
+ return this.queuePersist();
100
+ }
101
+ /**
102
+ * Remove an entry, with {@link put}'s contract: the in-memory map updates
103
+ * SYNCHRONOUSLY, then the full snapshot is persisted. Removing an absent key
104
+ * changes nothing, so it writes nothing.
105
+ */
106
+ remove(key) {
107
+ if (!this.entries.delete(key)) {
108
+ return Promise.resolve();
109
+ }
110
+ return this.queuePersist();
111
+ }
112
+ /** Chain a full-snapshot write behind every earlier one (see {@link put}). */
113
+ queuePersist() {
99
114
  const persist = this.writeChain.then(() => this.persistSnapshot());
100
- // The chain itself must survive a failed persist (the next put retries the
115
+ // The chain itself must survive a failed persist (the next write retries the
101
116
  // full snapshot); the caller still observes the rejection via `persist`.
102
117
  this.writeChain = persist.catch((error) => {
103
118
  log('%s: persist failed for party %s: %o', this.spec.label, this.partyId, error);
@@ -1 +1 @@
1
- {"version":3,"file":"node-local-snapshot.js","sourceRoot":"","sources":["../src/node-local-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,GAAG,GAAG,KAAK,CAAC,kCAAkC,CAAC,CAAC;AA+BtD,kFAAkF;AAClF,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAgC3B;;;;;;;;;;GAUG;AACH,MAAM,OAAO,iBAAiB;IAQ7B,YACkB,IAAiB,EACzB,OAAe,EACP,IAA8B,EAC9B,OAAuB;QAHvB,SAAI,GAAJ,IAAI,CAAa;QACzB,YAAO,GAAP,OAAO,CAAQ;QACP,SAAI,GAAJ,IAAI,CAA0B;QAC9B,YAAO,GAAP,OAAO,CAAgB;QAXzC;;;;WAIG;QACK,eAAU,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAOnD,CAAC;IAEJ;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,CAChB,IAAiB,EACjB,OAAe,EACf,IAA8B;QAE9B,OAAO,IAAI,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IAC3F,CAAC;IAED,GAAG,CAAC,GAAW;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED,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,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;gBAC5G,OAAO,IAAI,GAAG,EAAE,CAAC;YAClB,CAAC;YACD,GAAG,CAAC,+CAA+C,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;YAC/E,SAAS;QACV,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACzB,CAAC;IACD,GAAG,CAAC,sCAAsC,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/E,OAAO,OAAO,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,eAAe,CACvB,KAAc,EACd,OAAe,EACf,UAAkB;IAElB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACvC,2EAA2E;IAC3E,oDAAoD;IACpD,IAAI,KAAK,CAAC,OAAO,KAAK,gBAAgB,IAAI,KAAK,CAAC,OAAO,KAAK,OAAO;QAAE,OAAO,SAAS,CAAC;IACtF,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;IAClC,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Dialing one peer from a list of candidate addresses, so that an address that
3
+ * never answers cannot use up the time the others needed.
4
+ *
5
+ * libp2p's own multi-address dial (`libp2p.dial(addrs)`, libp2p 3.1.3's
6
+ * `DialQueue.dialPeer`) tries the addresses ONE AT A TIME under ONE signal, with
7
+ * no time limit per address. An address whose connection attempt is silently
8
+ * dropped — a firewall, a subnet the dialer cannot route to, a virtual adapter's
9
+ * address a Windows host reports alongside its real ones — holds that dial until
10
+ * the whole signal expires, and every address sorted after it is never tried. It
11
+ * also sorts the list itself (`defaultAddressSorter`), putting loopback addresses
12
+ * last, behind exactly the LAN addresses most likely to be dropped. A phone
13
+ * borrowing a node from a cadre-host whose only reachable address was the
14
+ * forwarded loopback one never connected for this reason.
15
+ *
16
+ * So the addresses are dialed here, each as its own `dial()` with its own time
17
+ * limit ({@link PeerDialBudget.perAddressMs}), inside a limit for the whole peer
18
+ * ({@link PeerDialBudget.totalMs}). One address per call also means libp2p's
19
+ * sorter has nothing to reorder, so the order is chosen here
20
+ * ({@link directBeforeRelayed}).
21
+ *
22
+ * Dependency-free apart from `control-stream.ts`, so any module may import it
23
+ * without creating an import cycle.
24
+ */
25
+ import type { Connection } from '@libp2p/interface';
26
+ import type { Multiaddr } from '@multiformats/multiaddr';
27
+ /**
28
+ * Default limit on ONE address's dial attempt, in ms.
29
+ *
30
+ * It has to cover the slowest address that should succeed, because an attempt
31
+ * that needs longer fails the same way on every retry. That is a relayed dial on
32
+ * a mobile link: connect to the relay (transport, encryption and multiplexer
33
+ * handshakes, when no relay connection is open yet), open the circuit, then run
34
+ * both handshakes again end to end through the relay at roughly twice the
35
+ * round-trip time. At a few hundred ms per round trip that is several seconds.
36
+ * A direct dial that works is far quicker — a phone's WebSocket dial to a node
37
+ * forwarded over `adb reverse` measured 1.6 s end to end. 8 s covers the relayed
38
+ * case with some margin while still abandoning a silently dropped address
39
+ * sooner than libp2p's own 10 s dial timeout would.
40
+ *
41
+ * NOTE: a `/p2p-circuit/webrtc` address also negotiates a WebRTC session after
42
+ * the relay leg. If such dials are ever seen failing at exactly this limit, raise
43
+ * it (or `network.controlCohort.perAddressDialTimeoutMs` on the affected nodes)
44
+ * rather than the per-peer limit, which cannot help an address that is itself
45
+ * cut off.
46
+ *
47
+ * Override per node with `network.controlCohort.perAddressDialTimeoutMs`.
48
+ */
49
+ export declare const DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS = 8000;
50
+ /**
51
+ * Default limit on dialing ONE peer — every candidate address together — in ms.
52
+ *
53
+ * Without it, an offline peer costs (address count × up to
54
+ * {@link DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS}), a number that
55
+ * depends on how many addresses the peer happens to report. Callers dial peers
56
+ * one after another (the control-cohort reconcile pass dials each sibling in
57
+ * turn), so that cost also delays every later peer. With the limit, a reconcile
58
+ * pass costs at most (dialed siblings) × this.
59
+ *
60
+ * Sized to fit a typical list with dead addresses ahead of the one that works:
61
+ * a lent cadre-host node reports two to four addresses a phone can dial
62
+ * (loopback and LAN WebSocket addresses, plus any virtual adapters). Three
63
+ * silently dropped addresses cost 3 × 8 s = 24 s, leaving 6 s for the working
64
+ * address after them — well over the 1.6 s the phone measured. A peer whose
65
+ * working address sits behind four or more dropped ones does not fit, and fails
66
+ * each pass the same way; if that shows up, the remedy is ordering (try the
67
+ * address that last connected first), not a larger number here.
68
+ *
69
+ * Override per node with `network.controlCohort.dialTimeoutMs` — tests that
70
+ * drive dead addresses on purpose set it low so a pass's duration is a chosen
71
+ * number rather than a transitive libp2p default stretched by machine load.
72
+ */
73
+ export declare const DEFAULT_CONTROL_COHORT_DIAL_TIMEOUT_MS = 30000;
74
+ /** Time limits for dialing one peer from a list of candidate addresses. */
75
+ export interface PeerDialBudget {
76
+ /** Limit on one address's attempt, in ms. */
77
+ perAddressMs: number;
78
+ /** Limit on the whole peer — every address together — in ms. */
79
+ totalMs: number;
80
+ }
81
+ /** {@link PeerDialBudget} built from the two defaults above. */
82
+ export declare const DEFAULT_PEER_DIAL_BUDGET: Readonly<PeerDialBudget>;
83
+ /** The slice of a libp2p node {@link dialPeerAddrs} uses. */
84
+ export interface AddrDialer {
85
+ dial(addr: Multiaddr, options: {
86
+ signal: AbortSignal;
87
+ }): Promise<Connection>;
88
+ }
89
+ /**
90
+ * Dial one peer from `addrs`, one address per `dial()` call, and return the
91
+ * first connection that forms. Direct addresses are tried before relayed ones
92
+ * ({@link directBeforeRelayed}); otherwise the given order is kept.
93
+ *
94
+ * Addresses naming a transport this node lacks are not filtered out first: a
95
+ * one-address `dial()` rejects those at once (`NoValidAddressesError`), so they
96
+ * cost a log line, not time.
97
+ *
98
+ * Throws when no address connects — see {@link tryAddrsInTurn} for the error.
99
+ *
100
+ * @param label Names the dial in timeout messages and logs, e.g.
101
+ * `reconcileControlCohort dial of sibling <peerId>`; each attempt reads
102
+ * `<label> via <addr>`.
103
+ */
104
+ export declare function dialPeerAddrs(dialer: AddrDialer, addrs: readonly Multiaddr[], budget: PeerDialBudget, label: string): Promise<Connection>;
105
+ /**
106
+ * Run `attempt` against each address in the given order until one succeeds, and
107
+ * return its result.
108
+ *
109
+ * Each attempt is limited to `budget.perAddressMs`, or to whatever remains of
110
+ * `budget.totalMs` when that is less. The attempt's signal is aborted when its
111
+ * limit passes, so a dial in progress is cancelled rather than left running.
112
+ * Addresses the total leaves no time for are reported as not tried.
113
+ *
114
+ * Throws when every address fails. With one address the error is that attempt's
115
+ * own, unchanged. With several it is one error naming each address and why it
116
+ * failed, in order, with the first failure as `cause` — so the report shows the
117
+ * address that mattered, not only whichever happened to be tried last.
118
+ *
119
+ * Between attempts this waits for one macrotask (`setTimeout(0)`). libp2p's dial
120
+ * queue lets a new `dial()` join any queued dial job for the same peer id
121
+ * WITHOUT checking whether that job has already finished, and an aborted job
122
+ * leaves the queue a few microtasks after its callers are rejected. Timing out
123
+ * one address and immediately dialing the next for the same peer therefore
124
+ * joins the dying job, which rejects the new dial with `AbortError` before it
125
+ * touches the network — the next address is never tried. Seen against libp2p
126
+ * 3.1.3; `test/peer-dial.spec.ts` dials real nodes so an upgrade that changes it
127
+ * shows up there. All of the queue's cleanup runs as microtasks, so it has
128
+ * finished by the time a macrotask runs.
129
+ */
130
+ export declare function tryAddrsInTurn<T>(addrs: readonly Multiaddr[], budget: PeerDialBudget, label: string, attempt: (addr: Multiaddr, signal: AbortSignal, attemptMs: number) => Promise<T>): Promise<T>;
131
+ /**
132
+ * `addrs` with every circuit-relay address (one containing `/p2p-circuit`) moved
133
+ * after every direct one, each group keeping its given order.
134
+ *
135
+ * The one part of libp2p's own ordering worth keeping: a relayed connection is
136
+ * slower and limited in how much data and time it may carry, so a direct
137
+ * address is always worth trying first. libp2p's other rules are deliberately
138
+ * dropped — it puts loopback addresses last and public ones before private ones,
139
+ * which is how a forwarded loopback address ended up behind addresses that
140
+ * never answer. With a per-address limit, trying a dead address first costs a
141
+ * bounded amount of time, so the caller's order is the better guide.
142
+ */
143
+ export declare function directBeforeRelayed(addrs: readonly Multiaddr[]): Multiaddr[];
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Dialing one peer from a list of candidate addresses, so that an address that
3
+ * never answers cannot use up the time the others needed.
4
+ *
5
+ * libp2p's own multi-address dial (`libp2p.dial(addrs)`, libp2p 3.1.3's
6
+ * `DialQueue.dialPeer`) tries the addresses ONE AT A TIME under ONE signal, with
7
+ * no time limit per address. An address whose connection attempt is silently
8
+ * dropped — a firewall, a subnet the dialer cannot route to, a virtual adapter's
9
+ * address a Windows host reports alongside its real ones — holds that dial until
10
+ * the whole signal expires, and every address sorted after it is never tried. It
11
+ * also sorts the list itself (`defaultAddressSorter`), putting loopback addresses
12
+ * last, behind exactly the LAN addresses most likely to be dropped. A phone
13
+ * borrowing a node from a cadre-host whose only reachable address was the
14
+ * forwarded loopback one never connected for this reason.
15
+ *
16
+ * So the addresses are dialed here, each as its own `dial()` with its own time
17
+ * limit ({@link PeerDialBudget.perAddressMs}), inside a limit for the whole peer
18
+ * ({@link PeerDialBudget.totalMs}). One address per call also means libp2p's
19
+ * sorter has nothing to reorder, so the order is chosen here
20
+ * ({@link directBeforeRelayed}).
21
+ *
22
+ * Dependency-free apart from `control-stream.ts`, so any module may import it
23
+ * without creating an import cycle.
24
+ */
25
+ import debug from 'debug';
26
+ import { withDeadline } from './control-stream.js';
27
+ const log = debug('sereus:cadre:peer-dial');
28
+ /**
29
+ * Default limit on ONE address's dial attempt, in ms.
30
+ *
31
+ * It has to cover the slowest address that should succeed, because an attempt
32
+ * that needs longer fails the same way on every retry. That is a relayed dial on
33
+ * a mobile link: connect to the relay (transport, encryption and multiplexer
34
+ * handshakes, when no relay connection is open yet), open the circuit, then run
35
+ * both handshakes again end to end through the relay at roughly twice the
36
+ * round-trip time. At a few hundred ms per round trip that is several seconds.
37
+ * A direct dial that works is far quicker — a phone's WebSocket dial to a node
38
+ * forwarded over `adb reverse` measured 1.6 s end to end. 8 s covers the relayed
39
+ * case with some margin while still abandoning a silently dropped address
40
+ * sooner than libp2p's own 10 s dial timeout would.
41
+ *
42
+ * NOTE: a `/p2p-circuit/webrtc` address also negotiates a WebRTC session after
43
+ * the relay leg. If such dials are ever seen failing at exactly this limit, raise
44
+ * it (or `network.controlCohort.perAddressDialTimeoutMs` on the affected nodes)
45
+ * rather than the per-peer limit, which cannot help an address that is itself
46
+ * cut off.
47
+ *
48
+ * Override per node with `network.controlCohort.perAddressDialTimeoutMs`.
49
+ */
50
+ export const DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS = 8000;
51
+ /**
52
+ * Default limit on dialing ONE peer — every candidate address together — in ms.
53
+ *
54
+ * Without it, an offline peer costs (address count × up to
55
+ * {@link DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS}), a number that
56
+ * depends on how many addresses the peer happens to report. Callers dial peers
57
+ * one after another (the control-cohort reconcile pass dials each sibling in
58
+ * turn), so that cost also delays every later peer. With the limit, a reconcile
59
+ * pass costs at most (dialed siblings) × this.
60
+ *
61
+ * Sized to fit a typical list with dead addresses ahead of the one that works:
62
+ * a lent cadre-host node reports two to four addresses a phone can dial
63
+ * (loopback and LAN WebSocket addresses, plus any virtual adapters). Three
64
+ * silently dropped addresses cost 3 × 8 s = 24 s, leaving 6 s for the working
65
+ * address after them — well over the 1.6 s the phone measured. A peer whose
66
+ * working address sits behind four or more dropped ones does not fit, and fails
67
+ * each pass the same way; if that shows up, the remedy is ordering (try the
68
+ * address that last connected first), not a larger number here.
69
+ *
70
+ * Override per node with `network.controlCohort.dialTimeoutMs` — tests that
71
+ * drive dead addresses on purpose set it low so a pass's duration is a chosen
72
+ * number rather than a transitive libp2p default stretched by machine load.
73
+ */
74
+ export const DEFAULT_CONTROL_COHORT_DIAL_TIMEOUT_MS = 30000;
75
+ /** {@link PeerDialBudget} built from the two defaults above. */
76
+ export const DEFAULT_PEER_DIAL_BUDGET = {
77
+ perAddressMs: DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS,
78
+ totalMs: DEFAULT_CONTROL_COHORT_DIAL_TIMEOUT_MS,
79
+ };
80
+ /**
81
+ * Dial one peer from `addrs`, one address per `dial()` call, and return the
82
+ * first connection that forms. Direct addresses are tried before relayed ones
83
+ * ({@link directBeforeRelayed}); otherwise the given order is kept.
84
+ *
85
+ * Addresses naming a transport this node lacks are not filtered out first: a
86
+ * one-address `dial()` rejects those at once (`NoValidAddressesError`), so they
87
+ * cost a log line, not time.
88
+ *
89
+ * Throws when no address connects — see {@link tryAddrsInTurn} for the error.
90
+ *
91
+ * @param label Names the dial in timeout messages and logs, e.g.
92
+ * `reconcileControlCohort dial of sibling <peerId>`; each attempt reads
93
+ * `<label> via <addr>`.
94
+ */
95
+ export function dialPeerAddrs(dialer, addrs, budget, label) {
96
+ return tryAddrsInTurn(directBeforeRelayed(addrs), budget, label, (addr, signal) => dialer.dial(addr, { signal }));
97
+ }
98
+ /**
99
+ * Run `attempt` against each address in the given order until one succeeds, and
100
+ * return its result.
101
+ *
102
+ * Each attempt is limited to `budget.perAddressMs`, or to whatever remains of
103
+ * `budget.totalMs` when that is less. The attempt's signal is aborted when its
104
+ * limit passes, so a dial in progress is cancelled rather than left running.
105
+ * Addresses the total leaves no time for are reported as not tried.
106
+ *
107
+ * Throws when every address fails. With one address the error is that attempt's
108
+ * own, unchanged. With several it is one error naming each address and why it
109
+ * failed, in order, with the first failure as `cause` — so the report shows the
110
+ * address that mattered, not only whichever happened to be tried last.
111
+ *
112
+ * Between attempts this waits for one macrotask (`setTimeout(0)`). libp2p's dial
113
+ * queue lets a new `dial()` join any queued dial job for the same peer id
114
+ * WITHOUT checking whether that job has already finished, and an aborted job
115
+ * leaves the queue a few microtasks after its callers are rejected. Timing out
116
+ * one address and immediately dialing the next for the same peer therefore
117
+ * joins the dying job, which rejects the new dial with `AbortError` before it
118
+ * touches the network — the next address is never tried. Seen against libp2p
119
+ * 3.1.3; `test/peer-dial.spec.ts` dials real nodes so an upgrade that changes it
120
+ * shows up there. All of the queue's cleanup runs as microtasks, so it has
121
+ * finished by the time a macrotask runs.
122
+ */
123
+ export async function tryAddrsInTurn(addrs, budget, label, attempt) {
124
+ const deadline = Date.now() + budget.totalMs;
125
+ const failures = [];
126
+ for (const addr of addrs) {
127
+ const remaining = deadline - Date.now();
128
+ if (remaining <= 0) {
129
+ failures.push({ addr, error: new Error(`not tried — the ${budget.totalMs}ms budget for ${label} was spent on earlier addresses`) });
130
+ continue;
131
+ }
132
+ if (failures.length > 0) {
133
+ await nextMacrotask();
134
+ }
135
+ const attemptMs = Math.min(budget.perAddressMs, remaining);
136
+ try {
137
+ return await withDeadline(attemptMs, `${label} via ${addr.toString()}`, (signal) => attempt(addr, signal, attemptMs));
138
+ }
139
+ catch (err) {
140
+ const error = err instanceof Error ? err : new Error(String(err));
141
+ failures.push({ addr, error });
142
+ log('%s via %s failed: %o', label, addr.toString(), error);
143
+ }
144
+ }
145
+ throw allAttemptsFailed(label, failures);
146
+ }
147
+ /**
148
+ * `addrs` with every circuit-relay address (one containing `/p2p-circuit`) moved
149
+ * after every direct one, each group keeping its given order.
150
+ *
151
+ * The one part of libp2p's own ordering worth keeping: a relayed connection is
152
+ * slower and limited in how much data and time it may carry, so a direct
153
+ * address is always worth trying first. libp2p's other rules are deliberately
154
+ * dropped — it puts loopback addresses last and public ones before private ones,
155
+ * which is how a forwarded loopback address ended up behind addresses that
156
+ * never answer. With a per-address limit, trying a dead address first costs a
157
+ * bounded amount of time, so the caller's order is the better guide.
158
+ */
159
+ export function directBeforeRelayed(addrs) {
160
+ const relayed = (addr) => addr.getComponents().some((c) => c.name === 'p2p-circuit');
161
+ return [...addrs.filter((addr) => !relayed(addr)), ...addrs.filter(relayed)];
162
+ }
163
+ function allAttemptsFailed(label, failures) {
164
+ if (failures.length === 0) {
165
+ return new Error(`${label}: no candidate addresses`);
166
+ }
167
+ if (failures.length === 1) {
168
+ return failures[0].error;
169
+ }
170
+ const detail = failures.map((f) => `${f.addr.toString()} — ${f.error.message}`).join('; ');
171
+ return new Error(`${label} failed for all ${failures.length} candidate addresses: ${detail}`, { cause: failures[0].error });
172
+ }
173
+ function nextMacrotask() {
174
+ return new Promise((resolve) => setTimeout(resolve, 0));
175
+ }
176
+ //# sourceMappingURL=peer-dial.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"peer-dial.js","sourceRoot":"","sources":["../src/peer-dial.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,GAAG,GAAG,KAAK,CAAC,wBAAwB,CAAC,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,kDAAkD,GAAG,IAAK,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,KAAM,CAAC;AAU7D,gEAAgE;AAChE,MAAM,CAAC,MAAM,wBAAwB,GAA6B;IACjE,YAAY,EAAE,kDAAkD;IAChE,OAAO,EAAE,sCAAsC;CAC/C,CAAC;AAaF;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,aAAa,CAC5B,MAAkB,EAClB,KAA2B,EAC3B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