@avatarsd-llc/libtracer-client 0.15.1 → 0.16.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 +54 -4
- package/dist/client.js +118 -24
- package/dist/index.d.ts +1 -1
- package/dist/tlv.d.ts +35 -25
- package/dist/tlv.js +32 -32
- package/package.json +3 -3
package/dist/client.d.ts
CHANGED
|
@@ -121,9 +121,51 @@ export declare class LibtracerClient {
|
|
|
121
121
|
onError(handler: (err: Error) => void): void;
|
|
122
122
|
/** @brief Decode one inbound frame: correlate a REPLY, deliver a write, or shed/deliver a VALUE. */
|
|
123
123
|
private dispatch;
|
|
124
|
+
/**
|
|
125
|
+
* @brief Which outstanding request this REPLY answers — its index, or `-1` for none.
|
|
126
|
+
*
|
|
127
|
+
* @section correlation Why not FIFO
|
|
128
|
+
*
|
|
129
|
+
* FIFO correlation is only correct while at most one request is outstanding.
|
|
130
|
+
* `FWD` carries no correlation id, and nothing in RFC-0004 promises reply order:
|
|
131
|
+
* a request that is FORWARDED across a mounted link answers in tens of
|
|
132
|
+
* milliseconds while a local one answers in about one, so a later request
|
|
133
|
+
* routinely OVERTAKES an earlier one on the same link. Under `shift()` the first
|
|
134
|
+
* overtake transposes two answers and the queue never realigns — every later
|
|
135
|
+
* caller gets the previous request's reply. Nothing errors: the caller receives a
|
|
136
|
+
* well-formed `RESULT` for somebody else's path (#1530).
|
|
137
|
+
*
|
|
138
|
+
* @section key What the wire does carry
|
|
139
|
+
*
|
|
140
|
+
* RFC-0004 §B: a REPLY "does not accumulate `src`; the `src` child of a REPLY is
|
|
141
|
+
* still required and is set to the **responder's own endpoint** (the vertex that
|
|
142
|
+
* produced the result)". `dst` SHRINKS per hop, so what the terminus resolved —
|
|
143
|
+
* and echoes — is the TAIL of the request's `dst` after every mount prefix was
|
|
144
|
+
* stripped: a request to `/net/ws-client/peer0/hw/variant` answers `src=hw/variant`,
|
|
145
|
+
* and so does a local request to `/hw/variant`. The key is therefore a SUFFIX
|
|
146
|
+
* match, not an equality, and it is genuinely ambiguous between those two.
|
|
147
|
+
*
|
|
148
|
+
* So: the oldest outstanding request whose `dst` ends with the reply's `src`, which
|
|
149
|
+
* is FIFO among the ones the wire cannot tell apart — exactly the tiebreak #1530
|
|
150
|
+
* prescribes, and it resolves that issue's measured four-request trace correctly.
|
|
151
|
+
*
|
|
152
|
+
* @section fallback When the key is unusable
|
|
153
|
+
*
|
|
154
|
+
* An empty `src` (RFC-0004 Amendment 2's "no reply requested"), a `PATH_REF` src on
|
|
155
|
+
* a reply to a bound operation, a label escape, or a `src` matching nothing
|
|
156
|
+
* outstanding all fall back to the oldest entry — today's behaviour exactly, so
|
|
157
|
+
* this change can only ever improve a correlation, never break one that worked.
|
|
158
|
+
*/
|
|
159
|
+
private correlate;
|
|
124
160
|
private deliver;
|
|
125
161
|
private emitError;
|
|
126
|
-
/**
|
|
162
|
+
/**
|
|
163
|
+
* @brief Send a one-shot FWD and resolve its FWD{REPLY}.
|
|
164
|
+
*
|
|
165
|
+
* @param frame the encoded request frame
|
|
166
|
+
* @param dst the request's destination segments — the key its reply's `src`
|
|
167
|
+
* echoes (see {@link correlate})
|
|
168
|
+
*/
|
|
127
169
|
private request;
|
|
128
170
|
/** @brief Turn a RESULT reply into its payload TLV; throw {@link FwdError} on ERROR. */
|
|
129
171
|
private result;
|
|
@@ -161,13 +203,21 @@ export declare class LibtracerClient {
|
|
|
161
203
|
* src=…, payload }` — the write counterpart of {@link readField}.
|
|
162
204
|
*
|
|
163
205
|
* The append form (`":children[]"` — a whole-array ELEMENT selector with no index) is
|
|
164
|
-
* how a vertex is CREATED in band: `writeField('/
|
|
165
|
-
*
|
|
166
|
-
*
|
|
206
|
+
* how a vertex is CREATED in band: `writeField('/cfg', ':children[]', spec)` mints a
|
|
207
|
+
* `stored_value` child on a remote device (ADR-0017), and
|
|
208
|
+
* `writeField('/sensor/temp', ':subscribers[]', encodeSubscriber(…))` binds a
|
|
167
209
|
* consumer-initiated subscription (ADR-0026). Neither was expressible from this client
|
|
168
210
|
* before: {@link write} takes no selector, so every field-addressed write — the entire
|
|
169
211
|
* in-band formation plane — was out of reach.
|
|
170
212
|
*
|
|
213
|
+
* A CONNECTION is the one thing this door no longer creates. RFC-0014 S7 retired
|
|
214
|
+
* `writeField('/net', ':children[]', …)`: a transport link is now brought up by a
|
|
215
|
+
* WHOLE-VERTEX write to its module's creator endpoint —
|
|
216
|
+
* `write(['net', '<module>', 'conn'], encodeConnSpec(…))`. Removal is the same endpoint
|
|
217
|
+
* written with a bare `NAME{<name>}` payload instead of a SPEC (RFC-0014 §2,
|
|
218
|
+
* reference/13 §2). The module segment is what fixes the transport and the role, which is
|
|
219
|
+
* why the payload carries neither. Generic `:children[]` creation is unaffected.
|
|
220
|
+
*
|
|
171
221
|
* Vector-pinned by `fwd-write-subscriber-field`.
|
|
172
222
|
*
|
|
173
223
|
* @param path the destination path (string or segments)
|
package/dist/client.js
CHANGED
|
@@ -20,13 +20,15 @@
|
|
|
20
20
|
* Each one-shot op sends a FWD and resolves the FWD{REPLY} the responder
|
|
21
21
|
* source-routes back (RESULT → the value, ERROR → a typed {@link FwdError}).
|
|
22
22
|
*
|
|
23
|
-
* Reply correlation is the transport's concern (RFC-0004 §D):
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
23
|
+
* Reply correlation is the transport's concern (RFC-0004 §D): `FWD` stays pure —
|
|
24
|
+
* there is no end-to-end correlation id. What the wire DOES carry is the
|
|
25
|
+
* responder's own endpoint in the reply's `src` (RFC-0004 §B: "the `src` child of
|
|
26
|
+
* a REPLY … is set to the responder's own endpoint — the vertex that produced the
|
|
27
|
+
* result"), and this client correlates on that, FIFO only among requests it cannot
|
|
28
|
+
* tell apart. See {@link LibtracerClient} §correlation.
|
|
27
29
|
*/
|
|
28
30
|
import { TYPE, decode, CodecError } from '@avatarsd-llc/libtracer';
|
|
29
|
-
import { encodeValue, encodePath, encodeSubscriber } from './tlv.js';
|
|
31
|
+
import { encodeValue, encodePath, encodeSubscriber, pathSegments } from './tlv.js';
|
|
30
32
|
import { FWD_OP, FWD_KIND, encodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, } from './fwd.js';
|
|
31
33
|
/**
|
|
32
34
|
* @brief A `kind=ERROR` FWD reply, surfaced as a typed rejection.
|
|
@@ -161,10 +163,13 @@ export class LibtracerClient {
|
|
|
161
163
|
return;
|
|
162
164
|
}
|
|
163
165
|
if (parsed.op === FWD_OP.REPLY) {
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
const at = this.correlate(parsed);
|
|
167
|
+
if (at < 0)
|
|
168
|
+
return; // a reply with nothing outstanding to answer
|
|
169
|
+
const [waiter] = this.pending.splice(at, 1);
|
|
170
|
+
// A settled waiter (timed out) still consumes its slot; its late reply is
|
|
171
|
+
// dropped rather than handed to a live caller.
|
|
172
|
+
if (!waiter.settled) {
|
|
168
173
|
settle(waiter);
|
|
169
174
|
waiter.resolve(parsed);
|
|
170
175
|
}
|
|
@@ -188,6 +193,59 @@ export class LibtracerClient {
|
|
|
188
193
|
if (data.type === TYPE.VALUE)
|
|
189
194
|
this.deliver(data);
|
|
190
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* @brief Which outstanding request this REPLY answers — its index, or `-1` for none.
|
|
198
|
+
*
|
|
199
|
+
* @section correlation Why not FIFO
|
|
200
|
+
*
|
|
201
|
+
* FIFO correlation is only correct while at most one request is outstanding.
|
|
202
|
+
* `FWD` carries no correlation id, and nothing in RFC-0004 promises reply order:
|
|
203
|
+
* a request that is FORWARDED across a mounted link answers in tens of
|
|
204
|
+
* milliseconds while a local one answers in about one, so a later request
|
|
205
|
+
* routinely OVERTAKES an earlier one on the same link. Under `shift()` the first
|
|
206
|
+
* overtake transposes two answers and the queue never realigns — every later
|
|
207
|
+
* caller gets the previous request's reply. Nothing errors: the caller receives a
|
|
208
|
+
* well-formed `RESULT` for somebody else's path (#1530).
|
|
209
|
+
*
|
|
210
|
+
* @section key What the wire does carry
|
|
211
|
+
*
|
|
212
|
+
* RFC-0004 §B: a REPLY "does not accumulate `src`; the `src` child of a REPLY is
|
|
213
|
+
* still required and is set to the **responder's own endpoint** (the vertex that
|
|
214
|
+
* produced the result)". `dst` SHRINKS per hop, so what the terminus resolved —
|
|
215
|
+
* and echoes — is the TAIL of the request's `dst` after every mount prefix was
|
|
216
|
+
* stripped: a request to `/net/ws-client/peer0/hw/variant` answers `src=hw/variant`,
|
|
217
|
+
* and so does a local request to `/hw/variant`. The key is therefore a SUFFIX
|
|
218
|
+
* match, not an equality, and it is genuinely ambiguous between those two.
|
|
219
|
+
*
|
|
220
|
+
* So: the oldest outstanding request whose `dst` ends with the reply's `src`, which
|
|
221
|
+
* is FIFO among the ones the wire cannot tell apart — exactly the tiebreak #1530
|
|
222
|
+
* prescribes, and it resolves that issue's measured four-request trace correctly.
|
|
223
|
+
*
|
|
224
|
+
* @section fallback When the key is unusable
|
|
225
|
+
*
|
|
226
|
+
* An empty `src` (RFC-0004 Amendment 2's "no reply requested"), a `PATH_REF` src on
|
|
227
|
+
* a reply to a bound operation, a label escape, or a `src` matching nothing
|
|
228
|
+
* outstanding all fall back to the oldest entry — today's behaviour exactly, so
|
|
229
|
+
* this change can only ever improve a correlation, never break one that worked.
|
|
230
|
+
*/
|
|
231
|
+
correlate(parsed) {
|
|
232
|
+
const fifo = this.pending.length > 0 ? 0 : -1;
|
|
233
|
+
let src;
|
|
234
|
+
try {
|
|
235
|
+
src = pathSegments(parsed.src);
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
return fifo; // a PATH_REF / escaped src is not an address this client can match
|
|
239
|
+
}
|
|
240
|
+
if (src.length === 0)
|
|
241
|
+
return fifo;
|
|
242
|
+
for (let i = 0; i < this.pending.length; i++) {
|
|
243
|
+
const dst = this.pending[i].dst;
|
|
244
|
+
if (dst !== null && endsWith(dst, src))
|
|
245
|
+
return i;
|
|
246
|
+
}
|
|
247
|
+
return fifo;
|
|
248
|
+
}
|
|
191
249
|
deliver(value) {
|
|
192
250
|
for (const handler of this.valueHandlers)
|
|
193
251
|
handler(value.payload, value);
|
|
@@ -196,14 +254,20 @@ export class LibtracerClient {
|
|
|
196
254
|
if (this.errorHandler)
|
|
197
255
|
this.errorHandler(err);
|
|
198
256
|
}
|
|
199
|
-
/**
|
|
200
|
-
|
|
257
|
+
/**
|
|
258
|
+
* @brief Send a one-shot FWD and resolve its FWD{REPLY}.
|
|
259
|
+
*
|
|
260
|
+
* @param frame the encoded request frame
|
|
261
|
+
* @param dst the request's destination segments — the key its reply's `src`
|
|
262
|
+
* echoes (see {@link correlate})
|
|
263
|
+
*/
|
|
264
|
+
request(frame, dst) {
|
|
201
265
|
return new Promise((resolve, reject) => {
|
|
202
266
|
if (this.closed) {
|
|
203
267
|
reject(this.closed);
|
|
204
268
|
return;
|
|
205
269
|
}
|
|
206
|
-
const entry = { resolve, reject, settled: false, timer: null };
|
|
270
|
+
const entry = { resolve, reject, settled: false, timer: null, dst };
|
|
207
271
|
if (this.requestTimeoutMs > 0 && Number.isFinite(this.requestTimeoutMs)) {
|
|
208
272
|
entry.timer = setTimeout(() => {
|
|
209
273
|
// Leave the settled entry in the FIFO (see Pending) — its slot is
|
|
@@ -243,7 +307,8 @@ export class LibtracerClient {
|
|
|
243
307
|
* @throws {FwdError} when the responder replies `kind=ERROR` (e.g. NOT_FOUND)
|
|
244
308
|
*/
|
|
245
309
|
async read(path) {
|
|
246
|
-
const
|
|
310
|
+
const dst = splitPath(path);
|
|
311
|
+
const reply = await this.request(encodeFwd({ op: FWD_OP.READ, dst, src: this.replyEndpoint }), dst);
|
|
247
312
|
const value = this.result(reply);
|
|
248
313
|
if (!value)
|
|
249
314
|
throw new FwdError(0); // RESULT with no payload — malformed read reply
|
|
@@ -261,7 +326,8 @@ export class LibtracerClient {
|
|
|
261
326
|
* @throws {FwdError} when the responder replies `kind=ERROR`
|
|
262
327
|
*/
|
|
263
328
|
async readField(path, selector) {
|
|
264
|
-
const
|
|
329
|
+
const dst = splitPath(path);
|
|
330
|
+
const reply = await this.request(encodeFwd({ op: FWD_OP.READ, dst, field: selector, src: this.replyEndpoint }), dst);
|
|
265
331
|
const value = this.result(reply);
|
|
266
332
|
if (!value)
|
|
267
333
|
throw new FwdError(0);
|
|
@@ -276,7 +342,8 @@ export class LibtracerClient {
|
|
|
276
342
|
* @throws {FwdError} when the responder replies `kind=ERROR`
|
|
277
343
|
*/
|
|
278
344
|
async write(path, valueTLV) {
|
|
279
|
-
const
|
|
345
|
+
const dst = splitPath(path);
|
|
346
|
+
const reply = await this.request(encodeFwd({ op: FWD_OP.WRITE, dst, src: this.replyEndpoint, payload: valueTLV }), dst);
|
|
280
347
|
this.result(reply); // throws on ERROR; RESULT carries no payload
|
|
281
348
|
}
|
|
282
349
|
/**
|
|
@@ -284,13 +351,21 @@ export class LibtracerClient {
|
|
|
284
351
|
* src=…, payload }` — the write counterpart of {@link readField}.
|
|
285
352
|
*
|
|
286
353
|
* The append form (`":children[]"` — a whole-array ELEMENT selector with no index) is
|
|
287
|
-
* how a vertex is CREATED in band: `writeField('/
|
|
288
|
-
*
|
|
289
|
-
*
|
|
354
|
+
* how a vertex is CREATED in band: `writeField('/cfg', ':children[]', spec)` mints a
|
|
355
|
+
* `stored_value` child on a remote device (ADR-0017), and
|
|
356
|
+
* `writeField('/sensor/temp', ':subscribers[]', encodeSubscriber(…))` binds a
|
|
290
357
|
* consumer-initiated subscription (ADR-0026). Neither was expressible from this client
|
|
291
358
|
* before: {@link write} takes no selector, so every field-addressed write — the entire
|
|
292
359
|
* in-band formation plane — was out of reach.
|
|
293
360
|
*
|
|
361
|
+
* A CONNECTION is the one thing this door no longer creates. RFC-0014 S7 retired
|
|
362
|
+
* `writeField('/net', ':children[]', …)`: a transport link is now brought up by a
|
|
363
|
+
* WHOLE-VERTEX write to its module's creator endpoint —
|
|
364
|
+
* `write(['net', '<module>', 'conn'], encodeConnSpec(…))`. Removal is the same endpoint
|
|
365
|
+
* written with a bare `NAME{<name>}` payload instead of a SPEC (RFC-0014 §2,
|
|
366
|
+
* reference/13 §2). The module segment is what fixes the transport and the role, which is
|
|
367
|
+
* why the payload carries neither. Generic `:children[]` creation is unaffected.
|
|
368
|
+
*
|
|
294
369
|
* Vector-pinned by `fwd-write-subscriber-field`.
|
|
295
370
|
*
|
|
296
371
|
* @param path the destination path (string or segments)
|
|
@@ -300,13 +375,14 @@ export class LibtracerClient {
|
|
|
300
375
|
* @throws {FwdError} when the responder replies `kind=ERROR`
|
|
301
376
|
*/
|
|
302
377
|
async writeField(path, selector, valueTLV) {
|
|
378
|
+
const dst = splitPath(path);
|
|
303
379
|
const reply = await this.request(encodeFwd({
|
|
304
380
|
op: FWD_OP.WRITE,
|
|
305
|
-
dst
|
|
381
|
+
dst,
|
|
306
382
|
field: selector,
|
|
307
383
|
src: this.replyEndpoint,
|
|
308
384
|
payload: valueTLV,
|
|
309
|
-
}));
|
|
385
|
+
}), dst);
|
|
310
386
|
this.result(reply); // throws on ERROR; RESULT carries no payload
|
|
311
387
|
}
|
|
312
388
|
/**
|
|
@@ -322,12 +398,13 @@ export class LibtracerClient {
|
|
|
322
398
|
* @throws {FwdError} with code TIMEOUT when the responder's deadline elapses
|
|
323
399
|
*/
|
|
324
400
|
async await_(path, timeoutNs) {
|
|
401
|
+
const dst = splitPath(path);
|
|
325
402
|
const reply = await this.request(encodeFwd({
|
|
326
403
|
op: FWD_OP.AWAIT,
|
|
327
|
-
dst
|
|
404
|
+
dst,
|
|
328
405
|
src: this.replyEndpoint,
|
|
329
406
|
awaitTimeoutNs: timeoutNs,
|
|
330
|
-
}));
|
|
407
|
+
}), dst);
|
|
331
408
|
const value = this.result(reply);
|
|
332
409
|
if (!value)
|
|
333
410
|
throw new FwdError(0);
|
|
@@ -357,6 +434,7 @@ export class LibtracerClient {
|
|
|
357
434
|
* @throws {FwdError} when the subscribe-write is rejected
|
|
358
435
|
*/
|
|
359
436
|
async subscribe(producerPath, handler, opts = {}) {
|
|
437
|
+
const dst = splitPath(producerPath);
|
|
360
438
|
const subscriber = encodeSubscriber(this.replyEndpoint, opts);
|
|
361
439
|
// Register the handler BEFORE awaiting the ack: a producer may stream its
|
|
362
440
|
// first delivery before its subscribe REPLY is seen on the wire, and we must
|
|
@@ -365,11 +443,11 @@ export class LibtracerClient {
|
|
|
365
443
|
try {
|
|
366
444
|
const reply = await this.request(encodeFwd({
|
|
367
445
|
op: FWD_OP.WRITE,
|
|
368
|
-
dst
|
|
446
|
+
dst,
|
|
369
447
|
field: ':subscribers[]',
|
|
370
448
|
src: this.replyEndpoint,
|
|
371
449
|
payload: subscriber,
|
|
372
|
-
}));
|
|
450
|
+
}), dst);
|
|
373
451
|
this.result(reply); // throws on ERROR
|
|
374
452
|
}
|
|
375
453
|
catch (err) {
|
|
@@ -405,6 +483,22 @@ Object.defineProperty(LibtracerClient.prototype, 'await', {
|
|
|
405
483
|
configurable: true,
|
|
406
484
|
enumerable: false,
|
|
407
485
|
});
|
|
486
|
+
/**
|
|
487
|
+
* @brief Does @p path end with the segments @p tail — the reply-`src` suffix test.
|
|
488
|
+
*
|
|
489
|
+
* A suffix rather than an equality because `dst` shrinks per hop (RFC-0004 §B): the
|
|
490
|
+
* responder's own endpoint is what is left of the request's `dst` once every mount
|
|
491
|
+
* prefix has been stripped.
|
|
492
|
+
*/
|
|
493
|
+
function endsWith(path, tail) {
|
|
494
|
+
if (tail.length > path.length)
|
|
495
|
+
return false;
|
|
496
|
+
const at = path.length - tail.length;
|
|
497
|
+
for (let i = 0; i < tail.length; i++)
|
|
498
|
+
if (path[at + i] !== tail[i])
|
|
499
|
+
return false;
|
|
500
|
+
return true;
|
|
501
|
+
}
|
|
408
502
|
/** @brief Normalize a `/`-path string (or segment array) into validated segments. */
|
|
409
503
|
function splitPath(path) {
|
|
410
504
|
if (Array.isArray(path))
|
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ 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
19
|
export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec, firstChild, pathSegments, PACKED_ESCAPE_LEN, DELIVERY_DURABILITY_REQUEST, DELIVERY_CLASS, deliveryClassBits, deliveryClassOf, } from './tlv.js';
|
|
20
|
-
export type { ValueOptions, SubscriberOptions, ConnSpecOptions
|
|
20
|
+
export type { ValueOptions, SubscriberOptions, ConnSpecOptions } from './tlv.js';
|
|
21
21
|
export { walkTopology, routeKey, CONN_ENDPOINT_NAME } from './topology.js';
|
|
22
22
|
export type { TopologyGraph, TopologyNode, TopologyEdge, TopologyBusPeers, TopologyGap, WalkOptions, } from './topology.js';
|
|
23
23
|
export { FWD_OP, FWD_OPCODE_MASK, FWD_OP_FLAG_MINT_REQUEST, 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
|
@@ -104,21 +104,17 @@ export declare const PACKED_ESCAPE_LEN = 0;
|
|
|
104
104
|
* a record is the escape
|
|
105
105
|
*/
|
|
106
106
|
export declare function pathSegments(path: Tlv): string[];
|
|
107
|
-
/** @brief The
|
|
108
|
-
export type ConnRole = 'dial' | 'listen';
|
|
109
|
-
/** @brief The connection SPEC a {@link encodeConnSpec} call describes (ADR-0027 / reference/13). */
|
|
107
|
+
/** @brief The connection SPEC a {@link encodeConnSpec} call describes (RFC-0014 §2 / reference/13). */
|
|
110
108
|
export interface ConnSpecOptions {
|
|
111
|
-
/** @brief The
|
|
112
|
-
readonly type: 'client' | 'listener';
|
|
113
|
-
/** @brief The connection NAME — the `/net/<name>` segment AND the routing key a `dst` hops through. */
|
|
109
|
+
/** @brief The connection NAME — the `/net/<module>/<name>` segment AND the routing key a `dst` hops through. */
|
|
114
110
|
readonly name: string;
|
|
115
|
-
/** @brief The link direction; overrides the type's default. */
|
|
116
|
-
readonly role: ConnRole;
|
|
117
111
|
/** @brief Peer port (DIAL) / bind port (LISTEN). Required — 0 is rejected by every built-in factory. */
|
|
118
112
|
readonly port: number;
|
|
119
|
-
/** @brief The transport-factory selector (`ws`, `tcp`, `udp`, …). Omit
|
|
113
|
+
/** @brief The transport-factory selector (`ws`, `tcp`, `udp`, …). Omit when the module declares
|
|
114
|
+
* exactly one kind, or for a pre-staged link. */
|
|
120
115
|
readonly kind?: string;
|
|
121
|
-
/** @brief Peer IPv4 dotted-quad. Required
|
|
116
|
+
/** @brief Peer IPv4 dotted-quad. Required by every built-in DIAL factory (`inet_pton`-only, no
|
|
117
|
+
* DNS) and ignored on a LISTEN. NOT validated here — see {@link encodeConnSpec}. */
|
|
122
118
|
readonly addr?: string;
|
|
123
119
|
/** @brief ws-private (LISTEN): expose the ADR-0044 bus facet, so `:children[]` lists live peers. */
|
|
124
120
|
readonly peerNamed?: boolean;
|
|
@@ -127,33 +123,47 @@ export interface ConnSpecOptions {
|
|
|
127
123
|
}
|
|
128
124
|
/**
|
|
129
125
|
* @brief Build a connection-creation SPEC TLV (`type=0x0e`, PL=1) — the payload of the
|
|
130
|
-
* in-band `write /net
|
|
131
|
-
* reference/13 §2).
|
|
126
|
+
* in-band `write /net/<module>/conn <- SPEC{…}` that brings a transport link up
|
|
127
|
+
* (RFC-0014 §2, ADR-0027, reference/13 §2).
|
|
132
128
|
*
|
|
133
129
|
* This is the wire form of the formation write a third party (typically a web UI holding
|
|
134
130
|
* delegated admin) issues on a device to create a link — the mechanism that makes a
|
|
135
131
|
* device-to-device connection with no third party in the data path.
|
|
136
132
|
*
|
|
137
133
|
* ```
|
|
138
|
-
* SPEC{ NAME "
|
|
139
|
-
* NAME "config" SETTINGS{ NAME "
|
|
140
|
-
* NAME "
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* [ NAME "max_peers" VALUE u32 (LE) ] } }
|
|
134
|
+
* SPEC{ NAME "name" NAME <name>,
|
|
135
|
+
* NAME "config" SETTINGS{ [ NAME "kind" NAME <kind> ],
|
|
136
|
+
* [ NAME "addr" NAME <addr> ],
|
|
137
|
+
* NAME "port" VALUE u16 (LE),
|
|
138
|
+
* [ NAME "peer_named" VALUE u8 ],
|
|
139
|
+
* [ NAME "max_peers" VALUE u32 (LE) ] } }
|
|
145
140
|
* ```
|
|
146
141
|
*
|
|
142
|
+
* **There is no `type` pair and no `role` pair.** RFC-0014 S7 retired the global
|
|
143
|
+
* `write /net:children[] += SPEC{…}` creation door; the surviving door is the module's own
|
|
144
|
+
* creator endpoint, and the module segment of the path it is written to fixes BOTH the
|
|
145
|
+
* transport and the link direction. A `role` pair here would be an ignored unknown pair,
|
|
146
|
+
* not an override — so this encoder does not emit one, under that or any other spelling.
|
|
147
|
+
* (Removal is the same endpoint written with a bare `NAME{<name>}`, not a SPEC.)
|
|
148
|
+
*
|
|
147
149
|
* Key order matters only for readability — the C++ `config_reader_t` walk is
|
|
148
|
-
* order-insensitive and ignores unknown keys (forward-compat).
|
|
149
|
-
*
|
|
150
|
-
*
|
|
150
|
+
* order-insensitive and ignores unknown keys (forward-compat). The order emitted here is
|
|
151
|
+
* the one the shared `conn/create-via-spec` conformance vector uses, so the two agree
|
|
152
|
+
* byte-for-byte. `peer_named` / `max_peers` are **ws-private** keys parsed by the ws
|
|
153
|
+
* factory itself (ADR-0043 §5); they are ignored by other kinds and on a DIAL.
|
|
154
|
+
*
|
|
155
|
+
* @note **No client-side DIAL/`addr` check.** The caller now learns the role from the
|
|
156
|
+
* endpoint it writes to, not from this record, so this encoder cannot know whether a
|
|
157
|
+
* missing `addr` is a bug (a DIAL) or correct (a LISTEN, where `addr` is ignored).
|
|
158
|
+
* Rather than reintroduce `role` under another name it emits what it is given — the
|
|
159
|
+
* same contract as the C++ `tr::net::conn_spec_t`, which validates no key against any
|
|
160
|
+
* kind either. A DIAL module handed an `addr`-less config answers `TYPE_MISMATCH`.
|
|
151
161
|
*
|
|
152
|
-
* Byte-pinned against the
|
|
162
|
+
* Byte-pinned against the shared `conn/create-via-spec` vector in `test/vectors.test.mjs`.
|
|
153
163
|
*
|
|
154
164
|
* @param o the connection to describe
|
|
155
|
-
* @returns the encoded SPEC TLV bytes — the payload of a
|
|
156
|
-
* @throws {RangeError} on a
|
|
165
|
+
* @returns the encoded SPEC TLV bytes — the payload of a `write` to `/net/<module>/conn`
|
|
166
|
+
* @throws {RangeError} on a text field over 64 UTF-8 bytes
|
|
157
167
|
*/
|
|
158
168
|
export declare function encodeConnSpec(o: ConnSpecOptions): Uint8Array;
|
|
159
169
|
/** @brief Options for {@link encodeSubscriber}. The ACL-capability and subscriber_id
|
package/dist/tlv.js
CHANGED
|
@@ -253,48 +253,55 @@ function valueLe(v, width) {
|
|
|
253
253
|
}
|
|
254
254
|
/**
|
|
255
255
|
* @brief Build a connection-creation SPEC TLV (`type=0x0e`, PL=1) — the payload of the
|
|
256
|
-
* in-band `write /net
|
|
257
|
-
* reference/13 §2).
|
|
256
|
+
* in-band `write /net/<module>/conn <- SPEC{…}` that brings a transport link up
|
|
257
|
+
* (RFC-0014 §2, ADR-0027, reference/13 §2).
|
|
258
258
|
*
|
|
259
259
|
* This is the wire form of the formation write a third party (typically a web UI holding
|
|
260
260
|
* delegated admin) issues on a device to create a link — the mechanism that makes a
|
|
261
261
|
* device-to-device connection with no third party in the data path.
|
|
262
262
|
*
|
|
263
263
|
* ```
|
|
264
|
-
* SPEC{ NAME "
|
|
265
|
-
* NAME "config" SETTINGS{ NAME "
|
|
266
|
-
* NAME "
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* [ NAME "max_peers" VALUE u32 (LE) ] } }
|
|
264
|
+
* SPEC{ NAME "name" NAME <name>,
|
|
265
|
+
* NAME "config" SETTINGS{ [ NAME "kind" NAME <kind> ],
|
|
266
|
+
* [ NAME "addr" NAME <addr> ],
|
|
267
|
+
* NAME "port" VALUE u16 (LE),
|
|
268
|
+
* [ NAME "peer_named" VALUE u8 ],
|
|
269
|
+
* [ NAME "max_peers" VALUE u32 (LE) ] } }
|
|
271
270
|
* ```
|
|
272
271
|
*
|
|
272
|
+
* **There is no `type` pair and no `role` pair.** RFC-0014 S7 retired the global
|
|
273
|
+
* `write /net:children[] += SPEC{…}` creation door; the surviving door is the module's own
|
|
274
|
+
* creator endpoint, and the module segment of the path it is written to fixes BOTH the
|
|
275
|
+
* transport and the link direction. A `role` pair here would be an ignored unknown pair,
|
|
276
|
+
* not an override — so this encoder does not emit one, under that or any other spelling.
|
|
277
|
+
* (Removal is the same endpoint written with a bare `NAME{<name>}`, not a SPEC.)
|
|
278
|
+
*
|
|
273
279
|
* Key order matters only for readability — the C++ `config_reader_t` walk is
|
|
274
|
-
* order-insensitive and ignores unknown keys (forward-compat).
|
|
275
|
-
*
|
|
276
|
-
*
|
|
280
|
+
* order-insensitive and ignores unknown keys (forward-compat). The order emitted here is
|
|
281
|
+
* the one the shared `conn/create-via-spec` conformance vector uses, so the two agree
|
|
282
|
+
* byte-for-byte. `peer_named` / `max_peers` are **ws-private** keys parsed by the ws
|
|
283
|
+
* factory itself (ADR-0043 §5); they are ignored by other kinds and on a DIAL.
|
|
284
|
+
*
|
|
285
|
+
* @note **No client-side DIAL/`addr` check.** The caller now learns the role from the
|
|
286
|
+
* endpoint it writes to, not from this record, so this encoder cannot know whether a
|
|
287
|
+
* missing `addr` is a bug (a DIAL) or correct (a LISTEN, where `addr` is ignored).
|
|
288
|
+
* Rather than reintroduce `role` under another name it emits what it is given — the
|
|
289
|
+
* same contract as the C++ `tr::net::conn_spec_t`, which validates no key against any
|
|
290
|
+
* kind either. A DIAL module handed an `addr`-less config answers `TYPE_MISMATCH`.
|
|
277
291
|
*
|
|
278
|
-
* Byte-pinned against the
|
|
292
|
+
* Byte-pinned against the shared `conn/create-via-spec` vector in `test/vectors.test.mjs`.
|
|
279
293
|
*
|
|
280
294
|
* @param o the connection to describe
|
|
281
|
-
* @returns the encoded SPEC TLV bytes — the payload of a
|
|
282
|
-
* @throws {RangeError} on a
|
|
295
|
+
* @returns the encoded SPEC TLV bytes — the payload of a `write` to `/net/<module>/conn`
|
|
296
|
+
* @throws {RangeError} on a text field over 64 UTF-8 bytes
|
|
283
297
|
*/
|
|
284
298
|
export function encodeConnSpec(o) {
|
|
285
|
-
|
|
286
|
-
throw new RangeError('a DIAL connection requires an addr (the built-in factories reject it as TYPE_MISMATCH)');
|
|
287
|
-
}
|
|
288
|
-
const cfg = [
|
|
289
|
-
textTlv('role'),
|
|
290
|
-
valueLe(o.role === 'listen' ? 1 : 0, 1),
|
|
291
|
-
textTlv('port'),
|
|
292
|
-
valueLe(o.port, 2),
|
|
293
|
-
];
|
|
299
|
+
const cfg = [];
|
|
294
300
|
if (o.kind !== undefined)
|
|
295
301
|
cfg.push(textTlv('kind'), textTlv(o.kind));
|
|
296
302
|
if (o.addr !== undefined)
|
|
297
303
|
cfg.push(textTlv('addr'), textTlv(o.addr));
|
|
304
|
+
cfg.push(textTlv('port'), valueLe(o.port, 2));
|
|
298
305
|
if (o.peerNamed !== undefined)
|
|
299
306
|
cfg.push(textTlv('peer_named'), valueLe(o.peerNamed ? 1 : 0, 1));
|
|
300
307
|
if (o.maxPeers !== undefined)
|
|
@@ -310,14 +317,7 @@ export function encodeConnSpec(o) {
|
|
|
310
317
|
type: TYPE.SPEC,
|
|
311
318
|
opt: opt({ pl: true }),
|
|
312
319
|
payload: new Uint8Array(0),
|
|
313
|
-
children: [
|
|
314
|
-
textTlv('type'),
|
|
315
|
-
textTlv(o.type),
|
|
316
|
-
textTlv('name'),
|
|
317
|
-
textTlv(o.name),
|
|
318
|
-
textTlv('config'),
|
|
319
|
-
settings,
|
|
320
|
-
],
|
|
320
|
+
children: [textTlv('name'), textTlv(o.name), textTlv('config'), settings],
|
|
321
321
|
trailer: null,
|
|
322
322
|
};
|
|
323
323
|
return encode(spec);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avatarsd-llc/libtracer-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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.16.0 <0.17.0",
|
|
37
|
+
"@avatarsd-llc/libtracer-ws": ">=0.16.0 <0.17.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@avatarsd-llc/libtracer-ws": {
|