@avatarsd-llc/libtracer-client 0.6.0 → 0.7.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/dist/client.d.ts +6 -2
- package/dist/client.js +7 -3
- package/dist/fwd.d.ts +1 -1
- package/dist/fwd.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/tlv.d.ts +21 -3
- package/dist/tlv.js +45 -6
- package/dist/topology.d.ts +101 -10
- package/dist/topology.js +91 -15
- package/package.json +3 -3
package/dist/client.d.ts
CHANGED
|
@@ -202,14 +202,18 @@ export declare class LibtracerClient {
|
|
|
202
202
|
* additionally needs the producer auto-promote / flush seam (#136 / RFC-0004 §E)
|
|
203
203
|
* — out of scope for this client slice. `unsubscribe()` is a LOCAL detach: it
|
|
204
204
|
* stops firing `handler` but does not clear the remote slot (an indexed
|
|
205
|
-
* `:subscribers[N]` field-write,
|
|
205
|
+
* `:subscribers[N]` field-write, which REPLACES that slot rather than adding
|
|
206
|
+
* to it — RFC-0009 §D.1).
|
|
206
207
|
*
|
|
207
208
|
* @param producerPath the producer vertex path (string or segments)
|
|
208
209
|
* @param handler invoked with each inbound VALUE delivery
|
|
210
|
+
* @param opts the SUBSCRIBER's optional children — notably RFC-0022 §3.A's
|
|
211
|
+
* `deliveryPolicy`, whose bit 5 asks the producer to deliver its
|
|
212
|
+
* latched last value on join (omitted ⇒ today's behaviour)
|
|
209
213
|
* @returns a function that locally detaches `handler`
|
|
210
214
|
* @throws {FwdError} when the subscribe-write is rejected
|
|
211
215
|
*/
|
|
212
|
-
subscribe(producerPath: string | string[], handler: ValueHandler): Promise<Unsubscribe>;
|
|
216
|
+
subscribe(producerPath: string | string[], handler: ValueHandler, opts?: SubscriberOptions): Promise<Unsubscribe>;
|
|
213
217
|
/** @brief {@link encodeValue} — the exact VALUE TLV bytes, independently of any transport. */
|
|
214
218
|
static encodeValue(value: Uint8Array, opts?: ValueOptions): Uint8Array;
|
|
215
219
|
/** @brief {@link encodePath} — the exact PATH TLV bytes. */
|
package/dist/client.js
CHANGED
|
@@ -345,15 +345,19 @@ export class LibtracerClient {
|
|
|
345
345
|
* additionally needs the producer auto-promote / flush seam (#136 / RFC-0004 §E)
|
|
346
346
|
* — out of scope for this client slice. `unsubscribe()` is a LOCAL detach: it
|
|
347
347
|
* stops firing `handler` but does not clear the remote slot (an indexed
|
|
348
|
-
* `:subscribers[N]` field-write,
|
|
348
|
+
* `:subscribers[N]` field-write, which REPLACES that slot rather than adding
|
|
349
|
+
* to it — RFC-0009 §D.1).
|
|
349
350
|
*
|
|
350
351
|
* @param producerPath the producer vertex path (string or segments)
|
|
351
352
|
* @param handler invoked with each inbound VALUE delivery
|
|
353
|
+
* @param opts the SUBSCRIBER's optional children — notably RFC-0022 §3.A's
|
|
354
|
+
* `deliveryPolicy`, whose bit 5 asks the producer to deliver its
|
|
355
|
+
* latched last value on join (omitted ⇒ today's behaviour)
|
|
352
356
|
* @returns a function that locally detaches `handler`
|
|
353
357
|
* @throws {FwdError} when the subscribe-write is rejected
|
|
354
358
|
*/
|
|
355
|
-
async subscribe(producerPath, handler) {
|
|
356
|
-
const subscriber = encodeSubscriber(this.replyEndpoint);
|
|
359
|
+
async subscribe(producerPath, handler, opts = {}) {
|
|
360
|
+
const subscriber = encodeSubscriber(this.replyEndpoint, opts);
|
|
357
361
|
// Register the handler BEFORE awaiting the ack: a producer may stream its
|
|
358
362
|
// first delivery before its subscribe REPLY is seen on the wire, and we must
|
|
359
363
|
// not drop it. On a rejected subscribe we detach again.
|
package/dist/fwd.d.ts
CHANGED
|
@@ -78,7 +78,7 @@ export interface FieldLevel {
|
|
|
78
78
|
*
|
|
79
79
|
* `":subscribers[]"` → `[{ name: "subscribers", mode: "ELEMENT" }]`;
|
|
80
80
|
* `":subscribers[3]"` → `[{ name: "subscribers", index: 3, mode: "ELEMENT" }]`;
|
|
81
|
-
* `":settings.
|
|
81
|
+
* `":settings.app"` → `[{ name: "settings" }, { name: "app" }]`.
|
|
82
82
|
*
|
|
83
83
|
* @param field the selector string (with or without the leading `:`)
|
|
84
84
|
* @returns the parsed levels
|
package/dist/fwd.js
CHANGED
|
@@ -122,7 +122,7 @@ function valueU64(v) {
|
|
|
122
122
|
*
|
|
123
123
|
* `":subscribers[]"` → `[{ name: "subscribers", mode: "ELEMENT" }]`;
|
|
124
124
|
* `":subscribers[3]"` → `[{ name: "subscribers", index: 3, mode: "ELEMENT" }]`;
|
|
125
|
-
* `":settings.
|
|
125
|
+
* `":settings.app"` → `[{ name: "settings" }, { name: "app" }]`.
|
|
126
126
|
*
|
|
127
127
|
* @param field the selector string (with or without the leading `:`)
|
|
128
128
|
* @returns the parsed levels
|
package/dist/index.d.ts
CHANGED
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
export declare const CLIENT_EXPERIMENTAL: true;
|
|
17
17
|
export { LibtracerClient, FwdError, CompactFlowError } from './client.js';
|
|
18
18
|
export type { ClientTransport, ValueHandler, Unsubscribe, ClientOptions, } from './client.js';
|
|
19
|
-
export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec } from './tlv.js';
|
|
19
|
+
export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec, DELIVERY_DURABILITY_REQUEST } from './tlv.js';
|
|
20
20
|
export type { ValueOptions, SubscriberOptions, ConnSpecOptions, ConnRole } from './tlv.js';
|
|
21
21
|
export { walkTopology, routeKey } from './topology.js';
|
|
22
|
-
export type { TopologyGraph, TopologyNode, TopologyEdge, TopologyBusPeers, WalkOptions, } from './topology.js';
|
|
22
|
+
export type { TopologyGraph, TopologyNode, TopologyEdge, TopologyBusPeers, TopologyGap, WalkOptions, } from './topology.js';
|
|
23
23
|
export { FWD_OP, FWD_KIND, FWD_ERROR, FWD_ERROR_PATH, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, encodeFwd, encodeField, parseField, decodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, } from './fwd.js';
|
|
24
24
|
export type { FwdRequest, ParsedFwd, FieldLevel } from './fwd.js';
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,6 @@
|
|
|
17
17
|
*/
|
|
18
18
|
export const CLIENT_EXPERIMENTAL = true;
|
|
19
19
|
export { LibtracerClient, FwdError, CompactFlowError } from './client.js';
|
|
20
|
-
export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec } from './tlv.js';
|
|
20
|
+
export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec, DELIVERY_DURABILITY_REQUEST } from './tlv.js';
|
|
21
21
|
export { walkTopology, routeKey } from './topology.js';
|
|
22
22
|
export { FWD_OP, FWD_KIND, FWD_ERROR, FWD_ERROR_PATH, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, encodeFwd, encodeField, parseField, decodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, } from './fwd.js';
|
package/dist/tlv.d.ts
CHANGED
|
@@ -106,9 +106,27 @@ export interface ConnSpecOptions {
|
|
|
106
106
|
* @throws {RangeError} on a DIAL with no `addr`, or a text field over 64 UTF-8 bytes
|
|
107
107
|
*/
|
|
108
108
|
export declare function encodeConnSpec(o: ConnSpecOptions): Uint8Array;
|
|
109
|
-
/** @brief Options for {@link encodeSubscriber}.
|
|
109
|
+
/** @brief Options for {@link encodeSubscriber}. The ACL-capability and subscriber_id
|
|
110
|
+
* children remain deferred (ADR-0034); the delivery policy is RFC-0022 §3.A. */
|
|
110
111
|
export interface SubscriberOptions {
|
|
112
|
+
/**
|
|
113
|
+
* @brief This subscription's DELIVERY policy — the packed 16-bit field of RFC-0022 §3.A,
|
|
114
|
+
* carried as `SETTINGS{ NAME "delivery_policy" VALUE u16 }` (the same `SETTINGS` child
|
|
115
|
+
* `delivery_compact` uses, so no new wire structure).
|
|
116
|
+
*
|
|
117
|
+
* Bit 0–1 reliability (0 = best-effort, 1 = reliable), bits 2–4 priority (0–7, 0 =
|
|
118
|
+
* default), bit 5 `durability_request` (deliver the producer's latched last value on
|
|
119
|
+
* join), bits 6–15 reserved — a sender MUST write them 0 and a receiver MUST ignore them.
|
|
120
|
+
*
|
|
121
|
+
* Omitted or `0` emits **no** SETTINGS child at all: absent ⇒ all-zero ⇒ today's
|
|
122
|
+
* behaviour, byte-identically (the `subscriber/policy-absent` vector).
|
|
123
|
+
*/
|
|
124
|
+
deliveryPolicy?: number;
|
|
111
125
|
}
|
|
126
|
+
/** @brief `durability_request` (RFC-0022 §3.A bit 5): ask the producer to deliver its
|
|
127
|
+
* latched last value once, on join. Before RFC-0022 this was the producer's
|
|
128
|
+
* `:settings.durability`, which applied to every subscriber at once. */
|
|
129
|
+
export declare const DELIVERY_DURABILITY_REQUEST = 32;
|
|
112
130
|
/**
|
|
113
131
|
* @brief Build a SUBSCRIBER TLV (`type=0x04`, PL=1) wrapping a target PATH —
|
|
114
132
|
* the payload of a subscribe-write (reference/04 §Subscribe).
|
|
@@ -120,7 +138,7 @@ export interface SubscriberOptions {
|
|
|
120
138
|
* dispatches matched writes (reference/05 §SUBSCRIBER).
|
|
121
139
|
*
|
|
122
140
|
* @param targetPath the delivery target path segments
|
|
123
|
-
* @param
|
|
141
|
+
* @param opts optional children — currently the RFC-0022 §3.A delivery policy
|
|
124
142
|
* @returns the encoded SUBSCRIBER TLV bytes
|
|
125
143
|
*/
|
|
126
|
-
export declare function encodeSubscriber(targetPath: string[],
|
|
144
|
+
export declare function encodeSubscriber(targetPath: string[], opts?: SubscriberOptions): Uint8Array;
|
package/dist/tlv.js
CHANGED
|
@@ -19,6 +19,20 @@
|
|
|
19
19
|
import { TYPE, encode } from '@avatarsd-llc/libtracer';
|
|
20
20
|
/** @brief Path-segment constraints from reference/03-addressing.md §path syntax. */
|
|
21
21
|
const MAX_SEGMENT_BYTES = 64;
|
|
22
|
+
/**
|
|
23
|
+
* @brief Maximum NAME segments in one PATH (reference/03 §path syntax; `core` `kMaxSegments`).
|
|
24
|
+
*
|
|
25
|
+
* Repriced 32 -> 255 by RFC-0023 — chosen so every per-segment quantity stays u8-representable,
|
|
26
|
+
* not inherited from a parser guard. Under this body encoding each segment costs `4 + len`, so
|
|
27
|
+
* {@link MAX_PATH_BYTES} admits at most 204 segments and the BYTE cap binds first; this is the
|
|
28
|
+
* encoding-independent ceiling.
|
|
29
|
+
*/
|
|
30
|
+
const MAX_SEGMENTS = 255;
|
|
31
|
+
/**
|
|
32
|
+
* @brief Maximum encoded PATH body — the concatenated NAME TLVs, i.e. exactly the PATH TLV's own
|
|
33
|
+
* `length` field (reference/03 §path syntax, 2026-07-31 erratum; `core` `kMaxPathBytes`).
|
|
34
|
+
*/
|
|
35
|
+
const MAX_PATH_BYTES = 1024;
|
|
22
36
|
/** @brief Reserved characters that MUST NOT appear inside a NAME segment (reference/03, /05 §NAME). */
|
|
23
37
|
const RESERVED_SEGMENT_CHARS = /[/:.[\]*?]/;
|
|
24
38
|
const utf8 = new TextEncoder();
|
|
@@ -98,13 +112,21 @@ export function encodePath(segments) {
|
|
|
98
112
|
export function pathTlv(segments) {
|
|
99
113
|
if (segments.length < 1)
|
|
100
114
|
throw new RangeError('a path must have at least one segment');
|
|
101
|
-
if (segments.length >
|
|
102
|
-
throw new RangeError(`a path may have at most
|
|
115
|
+
if (segments.length > MAX_SEGMENTS)
|
|
116
|
+
throw new RangeError(`a path may have at most ${MAX_SEGMENTS} segments (got ${segments.length})`);
|
|
117
|
+
const children = segments.map(nameTlv);
|
|
118
|
+
// The encode-time byte check the spec has always required and this client never had
|
|
119
|
+
// (RFC-0023 §5.6): the 1024-byte budget is measured as the PATH TLV's own `length` field —
|
|
120
|
+
// each NAME costs its 4-byte header plus its UTF-8 bytes. It binds BEFORE the segment count
|
|
121
|
+
// under this encoding (204 * 5 = 1020), so it is the bound that actually fires.
|
|
122
|
+
const bodyBytes = children.reduce((n, child) => n + 4 + child.payload.length, 0);
|
|
123
|
+
if (bodyBytes > MAX_PATH_BYTES)
|
|
124
|
+
throw new RangeError(`a path's encoded body may be at most ${MAX_PATH_BYTES} bytes (got ${bodyBytes})`);
|
|
103
125
|
return {
|
|
104
126
|
type: TYPE.PATH,
|
|
105
127
|
opt: opt({ pl: true }),
|
|
106
128
|
payload: new Uint8Array(0),
|
|
107
|
-
children
|
|
129
|
+
children,
|
|
108
130
|
trailer: null,
|
|
109
131
|
};
|
|
110
132
|
}
|
|
@@ -213,6 +235,10 @@ export function encodeConnSpec(o) {
|
|
|
213
235
|
};
|
|
214
236
|
return encode(spec);
|
|
215
237
|
}
|
|
238
|
+
/** @brief `durability_request` (RFC-0022 §3.A bit 5): ask the producer to deliver its
|
|
239
|
+
* latched last value once, on join. Before RFC-0022 this was the producer's
|
|
240
|
+
* `:settings.durability`, which applied to every subscriber at once. */
|
|
241
|
+
export const DELIVERY_DURABILITY_REQUEST = 0x0020;
|
|
216
242
|
/**
|
|
217
243
|
* @brief Build a SUBSCRIBER TLV (`type=0x04`, PL=1) wrapping a target PATH —
|
|
218
244
|
* the payload of a subscribe-write (reference/04 §Subscribe).
|
|
@@ -224,15 +250,28 @@ export function encodeConnSpec(o) {
|
|
|
224
250
|
* dispatches matched writes (reference/05 §SUBSCRIBER).
|
|
225
251
|
*
|
|
226
252
|
* @param targetPath the delivery target path segments
|
|
227
|
-
* @param
|
|
253
|
+
* @param opts optional children — currently the RFC-0022 §3.A delivery policy
|
|
228
254
|
* @returns the encoded SUBSCRIBER TLV bytes
|
|
229
255
|
*/
|
|
230
|
-
export function encodeSubscriber(targetPath,
|
|
256
|
+
export function encodeSubscriber(targetPath, opts = {}) {
|
|
257
|
+
const children = [pathTlv(targetPath)];
|
|
258
|
+
const policy = opts.deliveryPolicy ?? 0;
|
|
259
|
+
if (policy !== 0) {
|
|
260
|
+
if (!Number.isInteger(policy) || policy < 0 || policy > 0xffff)
|
|
261
|
+
throw new RangeError('deliveryPolicy must be a u16');
|
|
262
|
+
children.push({
|
|
263
|
+
type: TYPE.SETTINGS,
|
|
264
|
+
opt: opt({ pl: true }),
|
|
265
|
+
payload: new Uint8Array(0),
|
|
266
|
+
children: [textTlv('delivery_policy'), valueLe(policy, 2)],
|
|
267
|
+
trailer: null,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
231
270
|
const tlv = {
|
|
232
271
|
type: TYPE.SUBSCRIBER,
|
|
233
272
|
opt: opt({ pl: true }),
|
|
234
273
|
payload: new Uint8Array(0),
|
|
235
|
-
children
|
|
274
|
+
children,
|
|
236
275
|
trailer: null,
|
|
237
276
|
};
|
|
238
277
|
return encode(tlv);
|
package/dist/topology.d.ts
CHANGED
|
@@ -19,11 +19,14 @@
|
|
|
19
19
|
*
|
|
20
20
|
* ## Addressing (the part that surprises people)
|
|
21
21
|
*
|
|
22
|
-
* A connection's **routing key
|
|
23
|
-
* `/net/b` is where you *read* the link's state
|
|
24
|
-
* *routes through* it. So the walk composes routes as
|
|
25
|
-
*
|
|
26
|
-
*
|
|
22
|
+
* A connection's **routing key IS its vertex path** — `/net/<module>/<name>` (RFC-0014 §1,
|
|
23
|
+
* ADR-0061). `/net/ws-client/b` is both where you *read* the link's state and the run of
|
|
24
|
+
* `dst` segments that *routes through* it. So the walk composes routes as
|
|
25
|
+
* `[] → ['net','ws-client','b'] → ['net','ws-client','b','net','ws-client','c']`, and
|
|
26
|
+
* discovers a node's links in TWO levels: `[...route,'net']:children[]` lists the modules,
|
|
27
|
+
* and `[...route,'net',<module>]:children[]` lists that module's connections. This CLOSES
|
|
28
|
+
* #419 — reference/03 and /07 documented the prefixed form all along, and the old
|
|
29
|
+
* bare-NAME demux was the divergence.
|
|
27
30
|
*
|
|
28
31
|
* ## Termination — read this before trusting a result
|
|
29
32
|
*
|
|
@@ -49,6 +52,17 @@
|
|
|
49
52
|
* peer address, a value — would be exactly the identity-matching ADR-0044 forbids the
|
|
50
53
|
* core from doing, moved into the client and dressed up. When the answer is unknown,
|
|
51
54
|
* this says so.
|
|
55
|
+
*
|
|
56
|
+
* ## Two independent honesty flags (#676)
|
|
57
|
+
*
|
|
58
|
+
* {@link TopologyGraph.authoritative} answers *"are these nodes devices?"* and keys on
|
|
59
|
+
* identity resolution alone. It says **nothing** about whether the walk read everything
|
|
60
|
+
* it meant to: a node whose `/net` read is refused becomes a leaf and its whole subtree
|
|
61
|
+
* is silently absent, while identity resolution — and therefore `authoritative` — is
|
|
62
|
+
* untouched. Completeness is a **separate property** and gets its own flag,
|
|
63
|
+
* {@link TopologyGraph.complete}, cleared by every site that drops data and itemized in
|
|
64
|
+
* {@link TopologyGraph.gaps}. A caller wanting a trustworthy picture checks
|
|
65
|
+
* `authoritative && complete && !truncated`.
|
|
52
66
|
*/
|
|
53
67
|
import type { LibtracerClient } from './client.js';
|
|
54
68
|
/** @brief One node of the stitched graph — a device, or (pre-identity) one route to one. */
|
|
@@ -105,6 +119,48 @@ export interface TopologyBusPeers {
|
|
|
105
119
|
/** @brief True when every peer name is a legal path segment, so a directed hop is expressible. */
|
|
106
120
|
readonly routable: boolean;
|
|
107
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* @brief One read the walk intended to make and did not get — the structured form of
|
|
124
|
+
* an incompleteness (#676).
|
|
125
|
+
*
|
|
126
|
+
* Every entry corresponds to data that is **absent from the graph**, and every entry
|
|
127
|
+
* clears {@link TopologyGraph.complete}. A `net` gap is the expensive one: the node
|
|
128
|
+
* became a leaf, so its entire subtree is missing, not just one link.
|
|
129
|
+
*
|
|
130
|
+
* A legitimate absence is NOT a gap. `NOT_FOUND` on a node's `/net` means the node
|
|
131
|
+
* genuinely has no transport vertices — a real leaf — and costs neither a warning nor
|
|
132
|
+
* completeness.
|
|
133
|
+
*/
|
|
134
|
+
export interface TopologyGap {
|
|
135
|
+
/** @brief The {@link TopologyNode.id} whose read failed. */
|
|
136
|
+
readonly at: string;
|
|
137
|
+
/** @brief The route to that node, from the walk's vantage. */
|
|
138
|
+
readonly route: string[];
|
|
139
|
+
/**
|
|
140
|
+
* @brief Which read was lost, and therefore what is missing.
|
|
141
|
+
*
|
|
142
|
+
* - `"net"` — the node's module listing: **its whole subtree** is absent.
|
|
143
|
+
* - `"module"` — one module's connection listing: that module's links are absent.
|
|
144
|
+
* - `"peers"` — one link's peer listing: the link was assumed point-to-point, so a
|
|
145
|
+
* bus may be under-reported (or wrongly descended).
|
|
146
|
+
*/
|
|
147
|
+
readonly site: 'net' | 'module' | 'peers';
|
|
148
|
+
/** @brief The module NAME for a `module`/`peers` gap; `null` for a `net` gap. */
|
|
149
|
+
readonly module: string | null;
|
|
150
|
+
/** @brief The connection NAME for a `peers` gap; `null` otherwise. */
|
|
151
|
+
readonly name: string | null;
|
|
152
|
+
/**
|
|
153
|
+
* @brief The registered wire ERROR code ({@link FWD_ERROR}) when the peer answered
|
|
154
|
+
* with one, else `null` — a `null` means no reply at all (a local timeout, a closed
|
|
155
|
+
* transport). A `null` code is always transport-class; a non-`null` one can be too
|
|
156
|
+
* (`TRANSPORT_DOWN`) — {@link TopologyGraph.pruned} names the deciding predicate.
|
|
157
|
+
*/
|
|
158
|
+
readonly code: number | null;
|
|
159
|
+
/** @brief The symbolic name of {@link TopologyGap.code}, or `null`. */
|
|
160
|
+
readonly codeName: string | null;
|
|
161
|
+
/** @brief The underlying failure, stringified — the same text the warning carries. */
|
|
162
|
+
readonly message: string;
|
|
163
|
+
}
|
|
108
164
|
/** @brief The assembled projection. */
|
|
109
165
|
export interface TopologyGraph {
|
|
110
166
|
readonly nodes: TopologyNode[];
|
|
@@ -121,8 +177,35 @@ export interface TopologyGraph {
|
|
|
121
177
|
* When false the graph is a **shape, not a map**: one device may appear as several
|
|
122
178
|
* nodes, and a cycle appears as an unbounded chain truncated by `maxDepth`. Do not
|
|
123
179
|
* present a non-authoritative graph as the network's topology.
|
|
180
|
+
*
|
|
181
|
+
* This flag is about **identity only**. It is `true` on a graph that is missing whole
|
|
182
|
+
* subtrees — for that question read {@link TopologyGraph.complete} (#676).
|
|
124
183
|
*/
|
|
125
184
|
readonly authoritative: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* @brief True only if EVERY read the walk intended succeeded, so nothing is missing.
|
|
187
|
+
*
|
|
188
|
+
* When false the walk dropped data it meant to have: see {@link TopologyGraph.gaps}
|
|
189
|
+
* for what, where and why. The severe case is a failed `/net` read — that node became
|
|
190
|
+
* a leaf and **its entire subtree is absent from `nodes` and `edges`**, with no other
|
|
191
|
+
* signal that it ever existed.
|
|
192
|
+
*
|
|
193
|
+
* Orthogonal to {@link TopologyGraph.authoritative} (identity) and to
|
|
194
|
+
* {@link TopologyGraph.truncated} (the `maxDepth` bound, which is a deliberate stop,
|
|
195
|
+
* not a failed read). All three must hold to trust the graph as the network.
|
|
196
|
+
*/
|
|
197
|
+
readonly complete: boolean;
|
|
198
|
+
/** @brief Every dropped read, itemized — empty exactly when `complete` (see {@link TopologyGap}). */
|
|
199
|
+
readonly gaps: TopologyGap[];
|
|
200
|
+
/**
|
|
201
|
+
* @brief Routes abandoned after a transport-class failure — the node did not answer.
|
|
202
|
+
*
|
|
203
|
+
* A node that is gone costs one `requestTimeoutMs` per read. Once a read to it fails
|
|
204
|
+
* with no reply (a local timeout, a closed transport) or with `TRANSPORT_DOWN`, the
|
|
205
|
+
* walk stops reading that node's remaining modules rather than re-paying the timeout
|
|
206
|
+
* for each one.
|
|
207
|
+
*/
|
|
208
|
+
readonly pruned: string[][];
|
|
126
209
|
/** @brief Non-fatal problems (an unreadable node, a failed identity read). */
|
|
127
210
|
readonly warnings: string[];
|
|
128
211
|
}
|
|
@@ -132,8 +215,9 @@ export interface WalkOptions {
|
|
|
132
215
|
* @brief Hop limit. Default 8.
|
|
133
216
|
*
|
|
134
217
|
* WITHOUT {@link WalkOptions.identify} this is the ONLY thing that stops the walk on
|
|
135
|
-
* a cyclic topology — keep it modest. A route may not exceed the protocol's
|
|
136
|
-
* PATH cap
|
|
218
|
+
* a cyclic topology — keep it modest. A route may not exceed the protocol's 255-segment
|
|
219
|
+
* PATH cap (RFC-0023), and in practice the 1024-byte PATH budget binds first — ≈ 30–50 hops
|
|
220
|
+
* at 3-segment mount runs — while every hop costs a round trip across the whole route.
|
|
137
221
|
*/
|
|
138
222
|
readonly maxDepth?: number;
|
|
139
223
|
/** @brief The transport-vertex parent segment. Default `"net"`. */
|
|
@@ -168,11 +252,18 @@ export declare function routeKey(route: string[]): string;
|
|
|
168
252
|
* than one deep tendril. Each node costs one `readField` for its connections plus one
|
|
169
253
|
* {@link WalkOptions.identify} call, both routed across the full path to it.
|
|
170
254
|
*
|
|
171
|
-
* An unreadable node (a dead link, a denied read) becomes a
|
|
172
|
-
*
|
|
255
|
+
* An unreadable node (a dead link, a denied read) becomes a leaf — the walk continues,
|
|
256
|
+
* because one unreachable branch is not a reason to lose the rest. What it drops is
|
|
257
|
+
* **recorded**: the loss clears {@link TopologyGraph.complete} and appends a
|
|
258
|
+
* {@link TopologyGap} naming the route, the module and the wire ERROR code, so a caller
|
|
259
|
+
* never has to regex `warnings` to learn the graph is missing a subtree (#676).
|
|
173
260
|
*
|
|
174
261
|
* @param client attached to the vantage node
|
|
175
262
|
* @param opts identity resolution and bounds
|
|
176
|
-
* @returns the projection
|
|
263
|
+
* @returns the projection. Before trusting it check **both** honesty flags —
|
|
264
|
+
* {@link TopologyGraph.authoritative} (are these nodes devices?) and
|
|
265
|
+
* {@link TopologyGraph.complete} (did every intended read succeed?) — plus
|
|
266
|
+
* {@link TopologyGraph.truncated}. `authoritative` alone does not detect a missing
|
|
267
|
+
* subtree.
|
|
177
268
|
*/
|
|
178
269
|
export declare function walkTopology(client: LibtracerClient, opts?: WalkOptions): Promise<TopologyGraph>;
|
package/dist/topology.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: Copyright 2026 avatarsd LLC
|
|
3
|
+
import { FwdError } from './client.js';
|
|
4
|
+
import { FWD_ERROR } from './fwd.js';
|
|
3
5
|
import { TYPE } from '@avatarsd-llc/libtracer';
|
|
4
6
|
const utf8 = new TextDecoder();
|
|
5
7
|
/**
|
|
@@ -31,12 +33,19 @@ function listingNames(tlv) {
|
|
|
31
33
|
* than one deep tendril. Each node costs one `readField` for its connections plus one
|
|
32
34
|
* {@link WalkOptions.identify} call, both routed across the full path to it.
|
|
33
35
|
*
|
|
34
|
-
* An unreadable node (a dead link, a denied read) becomes a
|
|
35
|
-
*
|
|
36
|
+
* An unreadable node (a dead link, a denied read) becomes a leaf — the walk continues,
|
|
37
|
+
* because one unreachable branch is not a reason to lose the rest. What it drops is
|
|
38
|
+
* **recorded**: the loss clears {@link TopologyGraph.complete} and appends a
|
|
39
|
+
* {@link TopologyGap} naming the route, the module and the wire ERROR code, so a caller
|
|
40
|
+
* never has to regex `warnings` to learn the graph is missing a subtree (#676).
|
|
36
41
|
*
|
|
37
42
|
* @param client attached to the vantage node
|
|
38
43
|
* @param opts identity resolution and bounds
|
|
39
|
-
* @returns the projection
|
|
44
|
+
* @returns the projection. Before trusting it check **both** honesty flags —
|
|
45
|
+
* {@link TopologyGraph.authoritative} (are these nodes devices?) and
|
|
46
|
+
* {@link TopologyGraph.complete} (did every intended read succeed?) — plus
|
|
47
|
+
* {@link TopologyGraph.truncated}. `authoritative` alone does not detect a missing
|
|
48
|
+
* subtree.
|
|
40
49
|
*/
|
|
41
50
|
export async function walkTopology(client, opts = {}) {
|
|
42
51
|
const maxDepth = opts.maxDepth ?? 8;
|
|
@@ -44,20 +53,54 @@ export async function walkTopology(client, opts = {}) {
|
|
|
44
53
|
const byId = new Map();
|
|
45
54
|
const edges = [];
|
|
46
55
|
const busLinks = [];
|
|
56
|
+
const gaps = [];
|
|
57
|
+
const pruned = [];
|
|
47
58
|
const warnings = [];
|
|
48
59
|
let truncated = false;
|
|
49
60
|
let anyUnidentified = false;
|
|
61
|
+
/**
|
|
62
|
+
* A `NOT_FOUND` is an ANSWER, not a loss: the vertex genuinely is not there. That is a
|
|
63
|
+
* legitimate leaf (a node with no `/net`, a link with no `:children[]`) and must cost
|
|
64
|
+
* neither a warning nor completeness — the conflation the blanket catch used to make.
|
|
65
|
+
*/
|
|
66
|
+
const isNotFound = (err) => err instanceof FwdError && err.code === FWD_ERROR.NOT_FOUND;
|
|
67
|
+
/**
|
|
68
|
+
* Transport-class: the node did not answer at all (a local request timeout, a closed
|
|
69
|
+
* transport — neither is a `FwdError`) or the network below us said the link is down.
|
|
70
|
+
* Any other `FwdError` came FROM the node, so the node is alive and worth continuing.
|
|
71
|
+
*/
|
|
72
|
+
const isTransportClass = (err) => !(err instanceof FwdError) || err.code === FWD_ERROR.TRANSPORT_DOWN;
|
|
73
|
+
/** Record a dropped read: clears `complete`, itemizes the loss, and warns as before. */
|
|
74
|
+
const noteGap = (site, route, at, module, name, err, warning) => {
|
|
75
|
+
gaps.push({
|
|
76
|
+
at,
|
|
77
|
+
route,
|
|
78
|
+
site,
|
|
79
|
+
module,
|
|
80
|
+
name,
|
|
81
|
+
code: err instanceof FwdError ? err.code : null,
|
|
82
|
+
codeName: err instanceof FwdError ? err.codeName : null,
|
|
83
|
+
message: String(err),
|
|
84
|
+
});
|
|
85
|
+
warnings.push(warning);
|
|
86
|
+
};
|
|
50
87
|
/**
|
|
51
88
|
* A connection's `:children[]` discriminates the two link shapes (ADR-0044): a BUS
|
|
52
89
|
* link synthesizes its live peers there, while a point-to-point link has no such
|
|
53
90
|
* facet and the generic member listing of a childless vertex is empty. Empty ⇒ safe
|
|
54
91
|
* to route through by name; non-empty ⇒ a bus, and routing by name would broadcast.
|
|
55
92
|
*/
|
|
56
|
-
const peersOf = async (route, name) => {
|
|
93
|
+
const peersOf = async (route, at, module, name) => {
|
|
57
94
|
try {
|
|
58
|
-
return listingNames(await client.readField([...route, netRoot, name], ':children[]'));
|
|
95
|
+
return listingNames(await client.readField([...route, netRoot, module, name], ':children[]'));
|
|
59
96
|
}
|
|
60
|
-
catch {
|
|
97
|
+
catch (err) {
|
|
98
|
+
// NOT_FOUND is the childless answer — genuinely point-to-point, nothing lost. Any
|
|
99
|
+
// other failure means we do NOT know the link's shape and are about to assume the
|
|
100
|
+
// riskier half of the guess, so the graph is not complete.
|
|
101
|
+
if (!isNotFound(err)) {
|
|
102
|
+
noteGap('peers', route, at, module, name, err, `could not read peers of link "${module}/${name}" at ${routeKey(route)} — assumed point-to-point, a bus here would be under-reported: ${String(err)}`);
|
|
103
|
+
}
|
|
61
104
|
return []; // unreadable ⇒ treat as point-to-point; the descend below will warn if it fails
|
|
62
105
|
}
|
|
63
106
|
};
|
|
@@ -94,24 +137,50 @@ export async function walkTopology(client, opts = {}) {
|
|
|
94
137
|
for (let depth = 0; depth < maxDepth && frontier.length > 0; depth++) {
|
|
95
138
|
const next = [];
|
|
96
139
|
for (const { route, id } of frontier) {
|
|
97
|
-
|
|
140
|
+
// RFC-0014 §1: `/net` enumerates the per-(transport, role) MODULES, and each module
|
|
141
|
+
// enumerates its member connections. So discovering a node's links is two levels, not
|
|
142
|
+
// one — and the same NAME may legitimately appear in two modules.
|
|
143
|
+
let modules;
|
|
98
144
|
try {
|
|
99
|
-
|
|
100
|
-
names = listingNames(listing);
|
|
145
|
+
modules = listingNames(await client.readField([...route, netRoot], ':children[]'));
|
|
101
146
|
}
|
|
102
147
|
catch (err) {
|
|
103
|
-
// A node with no /net has no connections
|
|
104
|
-
//
|
|
105
|
-
|
|
148
|
+
// A node with no /net has no connections. That is DISTINGUISHABLE from a refused
|
|
149
|
+
// read: NOT_FOUND is the node answering "there is nothing there" — a legitimate
|
|
150
|
+
// leaf, no warning, no loss. Anything else means the node HAS a subtree we could
|
|
151
|
+
// not see, and the whole of it is now missing from the graph (#676).
|
|
152
|
+
if (!isNotFound(err)) {
|
|
153
|
+
noteGap('net', route, id, null, null, err, `could not read connections at ${routeKey(route)} — it becomes a leaf and its subtree is absent: ${String(err)}`);
|
|
154
|
+
if (isTransportClass(err))
|
|
155
|
+
pruned.push(route);
|
|
156
|
+
}
|
|
106
157
|
continue;
|
|
107
158
|
}
|
|
108
|
-
|
|
159
|
+
const links = [];
|
|
160
|
+
for (const module of modules) {
|
|
161
|
+
try {
|
|
162
|
+
const names = listingNames(await client.readField([...route, netRoot, module], ':children[]'));
|
|
163
|
+
for (const name of names)
|
|
164
|
+
links.push({ module, name });
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
noteGap('module', route, id, module, null, err, `could not read connections of module "${module}" at ${routeKey(route)}: ${String(err)}`);
|
|
168
|
+
// A node that has stopped answering costs requestTimeoutMs PER module if we
|
|
169
|
+
// keep asking. Stop asking: the rest of this node is unreachable too.
|
|
170
|
+
if (isTransportClass(err)) {
|
|
171
|
+
pruned.push(route);
|
|
172
|
+
warnings.push(`stopped reading ${routeKey(route)} after a transport-class failure — its remaining modules are not attempted`);
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
for (const { module, name } of links) {
|
|
109
178
|
if (opts.skipLink?.(name, route))
|
|
110
179
|
continue;
|
|
111
180
|
// A bus link is a dead end: routing through its NAME broadcasts to every peer,
|
|
112
181
|
// drawing N replies for one request. Record its peers and stop. (See
|
|
113
182
|
// TopologyBusPeers for why the directed per-peer hop is not expressible either.)
|
|
114
|
-
const peers = await peersOf(route, name);
|
|
183
|
+
const peers = await peersOf(route, id, module, name);
|
|
115
184
|
if (peers.length > 0) {
|
|
116
185
|
const routable = peers.every((p) => !RESERVED_SEGMENT_CHARS.test(p));
|
|
117
186
|
busLinks.push({ at: id, name, peers, routable });
|
|
@@ -119,7 +188,9 @@ export async function walkTopology(client, opts = {}) {
|
|
|
119
188
|
(routable ? '' : ' — its peer names are not legal path segments, so no directed hop exists'));
|
|
120
189
|
continue;
|
|
121
190
|
}
|
|
122
|
-
|
|
191
|
+
// The routing address IS the vertex path (ADR-0061), so a hop is the three
|
|
192
|
+
// segments `<netRoot>/<module>/<name>`, not the bare NAME.
|
|
193
|
+
const childRoute = [...route, netRoot, module, name];
|
|
123
194
|
const child = await intern(childRoute);
|
|
124
195
|
edges.push({ from: id, to: child.id, name });
|
|
125
196
|
// Only descend into a node we have not already expanded — the dedup that makes
|
|
@@ -146,6 +217,11 @@ export async function walkTopology(client, opts = {}) {
|
|
|
146
217
|
root,
|
|
147
218
|
truncated,
|
|
148
219
|
authoritative: !anyUnidentified,
|
|
220
|
+
// The split (#676): completeness is whether every intended read landed, and NOTHING
|
|
221
|
+
// else decides it. One gap is one piece of the network the caller does not have.
|
|
222
|
+
complete: gaps.length === 0,
|
|
223
|
+
gaps,
|
|
224
|
+
pruned,
|
|
149
225
|
warnings,
|
|
150
226
|
};
|
|
151
227
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avatarsd-llc/libtracer-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "EXPERIMENTAL libtracer client SDK (#56, ADR-0034/0035) — a path-addressed client over the cross-validated codec (@avatarsd-llc/libtracer) and an injected transport seam (e.g. @avatarsd-llc/libtracer-ws). Speaks the RFC-0004 remote operations over FWD: read / write / await / readField / subscribe, each a FWD frame whose source-routed FWD{REPLY} is decoded back. Pre-1.0 and experimental.",
|
|
5
5
|
"author": "avatarsd LLC",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@avatarsd-llc/libtracer": ">=0.
|
|
37
|
-
"@avatarsd-llc/libtracer-ws": ">=0.
|
|
36
|
+
"@avatarsd-llc/libtracer": ">=0.7.0 <0.8.0",
|
|
37
|
+
"@avatarsd-llc/libtracer-ws": ">=0.7.0 <0.8.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@avatarsd-llc/libtracer-ws": {
|