wire-mesh-core 3.6.0 → 3.6.1

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.
@@ -81,7 +81,17 @@ export interface MeshSession {
81
81
  readonly coordinatorFrames: AsyncIterable<CoordinatorFrame>;
82
82
  connect: (address: string, localDomains: readonly string[]) => Promise<void>;
83
83
  sendPing: () => Promise<void>;
84
- /** Sends a ping-frame and resolves with the round-trip time in milliseconds once the correlated pong-frame arrives -- FIFO-paired against this call's own ping, since ping-frame carries no correlation id of its own (spec/transport.cddl): the Nth call's own promise resolves against the Nth pong received after it, never matched by any other means. Rejects if the connection closes, or (when timeoutMs is given) if no pong arrives within timeoutMs, rather than resolving a sentinel value the way sendManageRequest's own timeout does -- there is no natural "no answer" value for a bare millisecond count to double as. Unlike sendPing (fire-and-forget, answered by nothing on an ordinary peer connection), this is answered only by a peer that replies to ping with pong -- today, relay-hub's own frame handling (wire-mesh#181) -- so calling this against a connection to a plain peer that never sends pong hangs until timeoutMs (if given) or forever. Exists to isolate the sender-to-hub leg of a relayed path.trace round trip: time this over the same connection a relayed manage-request travelled, then subtract it from path.trace's own end-to-end RTT to recover the hub-to-target leg. */
84
+ /**
85
+ * Sends a ping-frame and resolves with the round-trip time in milliseconds once the correlated pong-frame arrives.
86
+ *
87
+ * The pairing is FIFO because ping-frame carries no correlation id of its own (spec/transport.cddl): the Nth call's promise resolves against the Nth pong received after it, never matched by any other means.
88
+ *
89
+ * Rejects with a plain Error if the connection closes, and with a PingTimeoutError (from ping-round-trips.ts) when `timeoutMs` is given and no pong arrives within it, so a caller can tell an unanswered ping from a dropped connection. It never resolves a sentinel the way sendManageRequest's own timeout does, because there is no natural "no answer" value for a bare millisecond count to double as.
90
+ *
91
+ * Unlike sendPing (fire-and-forget, answered by nothing on an ordinary peer connection), this is answered only by a peer that replies to ping with pong, which today means relay-hub's own frame handling (wire-mesh#181). Called against a plain peer that never sends pong it hangs until `timeoutMs` if given, or forever.
92
+ *
93
+ * It exists to isolate the sender-to-hub leg of a relayed path.trace round trip: time it over the same connection a relayed manage-request travelled, then subtract it from path.trace's own end-to-end RTT to recover the hub-to-target leg.
94
+ */
85
95
  sendPingMeasureRtt: (timeoutMs?: number) => Promise<number>;
86
96
  /** Attaches this token to every `manage-request` sent from now on. */
87
97
  setToken: (token: CapabilityToken) => void;
@@ -81,7 +81,17 @@ export interface MeshSession {
81
81
  readonly coordinatorFrames: AsyncIterable<CoordinatorFrame>;
82
82
  connect: (address: string, localDomains: readonly string[]) => Promise<void>;
83
83
  sendPing: () => Promise<void>;
84
- /** Sends a ping-frame and resolves with the round-trip time in milliseconds once the correlated pong-frame arrives -- FIFO-paired against this call's own ping, since ping-frame carries no correlation id of its own (spec/transport.cddl): the Nth call's own promise resolves against the Nth pong received after it, never matched by any other means. Rejects if the connection closes, or (when timeoutMs is given) if no pong arrives within timeoutMs, rather than resolving a sentinel value the way sendManageRequest's own timeout does -- there is no natural "no answer" value for a bare millisecond count to double as. Unlike sendPing (fire-and-forget, answered by nothing on an ordinary peer connection), this is answered only by a peer that replies to ping with pong -- today, relay-hub's own frame handling (wire-mesh#181) -- so calling this against a connection to a plain peer that never sends pong hangs until timeoutMs (if given) or forever. Exists to isolate the sender-to-hub leg of a relayed path.trace round trip: time this over the same connection a relayed manage-request travelled, then subtract it from path.trace's own end-to-end RTT to recover the hub-to-target leg. */
84
+ /**
85
+ * Sends a ping-frame and resolves with the round-trip time in milliseconds once the correlated pong-frame arrives.
86
+ *
87
+ * The pairing is FIFO because ping-frame carries no correlation id of its own (spec/transport.cddl): the Nth call's promise resolves against the Nth pong received after it, never matched by any other means.
88
+ *
89
+ * Rejects with a plain Error if the connection closes, and with a PingTimeoutError (from ping-round-trips.ts) when `timeoutMs` is given and no pong arrives within it, so a caller can tell an unanswered ping from a dropped connection. It never resolves a sentinel the way sendManageRequest's own timeout does, because there is no natural "no answer" value for a bare millisecond count to double as.
90
+ *
91
+ * Unlike sendPing (fire-and-forget, answered by nothing on an ordinary peer connection), this is answered only by a peer that replies to ping with pong, which today means relay-hub's own frame handling (wire-mesh#181). Called against a plain peer that never sends pong it hangs until `timeoutMs` if given, or forever.
92
+ *
93
+ * It exists to isolate the sender-to-hub leg of a relayed path.trace round trip: time it over the same connection a relayed manage-request travelled, then subtract it from path.trace's own end-to-end RTT to recover the hub-to-target leg.
94
+ */
85
95
  sendPingMeasureRtt: (timeoutMs?: number) => Promise<number>;
86
96
  /** Attaches this token to every `manage-request` sent from now on. */
87
97
  setToken: (token: CapabilityToken) => void;
@@ -1,5 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/domain/ping-round-trips.ts
3
+ /** Why a ping was given up on: no pong arrived within the caller's `timeoutMs`. A call rejected for any other reason (the connection dropped or closed first) rejects with a plain Error, so a caller counting unanswered pings tells the two apart by this class rather than by message text. */
4
+ var PingTimeoutError = class extends Error {
5
+ constructor() {
6
+ super("timed out waiting for pong");
7
+ this.name = "PingTimeoutError";
8
+ }
9
+ };
3
10
  function createPingRoundTrips() {
4
11
  const pending = [];
5
12
  function cancel(sentAt) {
@@ -28,11 +35,12 @@ function createPingRoundTrips() {
28
35
  if (timeoutMs === void 0) return rtt;
29
36
  return Promise.race([rtt, new Promise((_resolve, reject) => {
30
37
  setTimeout(() => {
31
- if (cancel(sentAt)) reject(/* @__PURE__ */ new Error("timed out waiting for pong"));
38
+ if (cancel(sentAt)) reject(new PingTimeoutError());
32
39
  }, timeoutMs);
33
40
  })]);
34
41
  }
35
42
  };
36
43
  }
37
44
  //#endregion
45
+ exports.PingTimeoutError = PingTimeoutError;
38
46
  exports.createPingRoundTrips = createPingRoundTrips;
@@ -1,4 +1,8 @@
1
1
  //#region src/domain/ping-round-trips.d.ts
2
+ /** Why a ping was given up on: no pong arrived within the caller's `timeoutMs`. A call rejected for any other reason (the connection dropped or closed first) rejects with a plain Error, so a caller counting unanswered pings tells the two apart by this class rather than by message text. */
3
+ export declare class PingTimeoutError extends Error {
4
+ constructor();
5
+ }
2
6
  export interface PingRoundTrips {
3
7
  /** Resolves the oldest still-pending call with (nowMs - itsOwnSentAt) -- called once per pong-frame received. A no-op if nothing is pending (a stray pong with no outstanding call). */
4
8
  resolveOldest: (nowMs: number) => void;
@@ -1,4 +1,8 @@
1
1
  //#region src/domain/ping-round-trips.d.ts
2
+ /** Why a ping was given up on: no pong arrived within the caller's `timeoutMs`. A call rejected for any other reason (the connection dropped or closed first) rejects with a plain Error, so a caller counting unanswered pings tells the two apart by this class rather than by message text. */
3
+ export declare class PingTimeoutError extends Error {
4
+ constructor();
5
+ }
2
6
  export interface PingRoundTrips {
3
7
  /** Resolves the oldest still-pending call with (nowMs - itsOwnSentAt) -- called once per pong-frame received. A no-op if nothing is pending (a stray pong with no outstanding call). */
4
8
  resolveOldest: (nowMs: number) => void;
@@ -1,4 +1,11 @@
1
1
  //#region src/domain/ping-round-trips.ts
2
+ /** Why a ping was given up on: no pong arrived within the caller's `timeoutMs`. A call rejected for any other reason (the connection dropped or closed first) rejects with a plain Error, so a caller counting unanswered pings tells the two apart by this class rather than by message text. */
3
+ var PingTimeoutError = class extends Error {
4
+ constructor() {
5
+ super("timed out waiting for pong");
6
+ this.name = "PingTimeoutError";
7
+ }
8
+ };
2
9
  function createPingRoundTrips() {
3
10
  const pending = [];
4
11
  function cancel(sentAt) {
@@ -27,11 +34,11 @@ function createPingRoundTrips() {
27
34
  if (timeoutMs === void 0) return rtt;
28
35
  return Promise.race([rtt, new Promise((_resolve, reject) => {
29
36
  setTimeout(() => {
30
- if (cancel(sentAt)) reject(/* @__PURE__ */ new Error("timed out waiting for pong"));
37
+ if (cancel(sentAt)) reject(new PingTimeoutError());
31
38
  }, timeoutMs);
32
39
  })]);
33
40
  }
34
41
  };
35
42
  }
36
43
  //#endregion
37
- export { createPingRoundTrips };
44
+ export { PingTimeoutError, createPingRoundTrips };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wire-mesh-core",
3
- "version": "3.6.0",
3
+ "version": "3.6.1",
4
4
  "dependencies": {
5
5
  "cbor2": "2.3.0",
6
6
  "cddl.js": "1.0.1",