@avatarsd-llc/libtracer-client 0.21.0 → 0.22.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 +72 -28
- package/dist/client.js +160 -75
- package/dist/fwd.d.ts +13 -22
- package/dist/fwd.js +13 -31
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/tlv.d.ts +2 -2
- package/dist/tlv.js +2 -2
- package/package.json +3 -3
package/dist/client.d.ts
CHANGED
|
@@ -28,7 +28,8 @@ export type Unsubscribe = () => void;
|
|
|
28
28
|
export interface ClientOptions {
|
|
29
29
|
/**
|
|
30
30
|
* @brief The originator's reply endpoint, as path segments — the `src` route seeded on
|
|
31
|
-
* every outbound FWD
|
|
31
|
+
* every outbound FWD. A subscription targets its own path one segment below it
|
|
32
|
+
* (`<reply-ep>/sub<n>`), used as both its `src` and its SUBSCRIBER `target`. Over a single
|
|
32
33
|
* ws hop the responder replies back over the same link, so any 1+-segment path
|
|
33
34
|
* is fine; default `["client"]`.
|
|
34
35
|
*/
|
|
@@ -87,7 +88,18 @@ export declare class LibtracerClient {
|
|
|
87
88
|
private readonly replyEndpoint;
|
|
88
89
|
private readonly requestTimeoutMs;
|
|
89
90
|
private readonly valueHandlers;
|
|
91
|
+
/**
|
|
92
|
+
* @brief Each live subscription's handler, keyed by its target's last segment
|
|
93
|
+
* (`sub<n>`, the one segment below the reply endpoint).
|
|
94
|
+
*/
|
|
95
|
+
private readonly subscriptions;
|
|
96
|
+
/** @brief The number the next subscription's target segment carries. */
|
|
97
|
+
private nextSubscription;
|
|
98
|
+
/** @brief The number the next one-shot request's reply token (`q<n>`) carries. */
|
|
99
|
+
private nextRequest;
|
|
90
100
|
private readonly pending;
|
|
101
|
+
/** @brief The `dst` of the most recent timed-out requests, oldest first, at most {@link EXPIRED_CAP}. */
|
|
102
|
+
private readonly expired;
|
|
91
103
|
private errorHandler;
|
|
92
104
|
private closed;
|
|
93
105
|
/**
|
|
@@ -103,7 +115,8 @@ export declare class LibtracerClient {
|
|
|
103
115
|
*
|
|
104
116
|
* A delivery is a FWD{WRITE} (delivery-is-a-write, RFC-0004 §D); a bare VALUE
|
|
105
117
|
* or a single ROUTER wrapper is also accepted. Multiple handlers may be
|
|
106
|
-
* registered; each receives every delivery
|
|
118
|
+
* registered; each receives every delivery, including the ones a
|
|
119
|
+
* {@link subscribe} handler also receives.
|
|
107
120
|
*/
|
|
108
121
|
onValue(handler: ValueHandler): void;
|
|
109
122
|
/** @brief Register the sink for inbound decode failures and other client-side errors. */
|
|
@@ -121,48 +134,75 @@ export declare class LibtracerClient {
|
|
|
121
134
|
* milliseconds while a local one answers in about one, so a later request
|
|
122
135
|
* routinely OVERTAKES an earlier one on the same link. Under `shift()` the first
|
|
123
136
|
* overtake transposes two answers and the queue never realigns — every later
|
|
124
|
-
* caller gets the previous request's reply.
|
|
125
|
-
* well-formed `RESULT` for somebody else's path (#1530).
|
|
137
|
+
* caller gets the previous request's reply (#1530).
|
|
126
138
|
*
|
|
127
|
-
* @section
|
|
139
|
+
* @section token The originator matches by its own reply token
|
|
128
140
|
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
141
|
+
* Every request's `src` is the reply endpoint plus one segment of its own: `q<n>`
|
|
142
|
+
* for a one-shot, `sub<n>` for a subscribe. A REPLY is routed by that `src`, so its
|
|
143
|
+
* `dst` carries the token home; `dst` shrinks per hop, so what arrives is a TAIL of
|
|
144
|
+
* `<reply-ep>/<token>` — its last segment is the token and whatever precedes it must
|
|
145
|
+
* end the reply endpoint, the same reading {@link deliver} applies. The token is an
|
|
146
|
+
* ordinary `src` segment, not a field in `FWD`, and the receiver holds no state for
|
|
147
|
+
* it ([18 §Acknowledged one-shot operations and safe retry](
|
|
148
|
+
* ../../../../../docs/reference/18-composition-over-the-network.md#acknowledged-one-shot-operations-and-safe-retry)).
|
|
136
149
|
*
|
|
137
|
-
*
|
|
138
|
-
* is FIFO among the ones the wire cannot tell apart — exactly the tiebreak #1530
|
|
139
|
-
* prescribes, and it resolves that issue's measured four-request trace correctly.
|
|
150
|
+
* @section fallback When the token is absent
|
|
140
151
|
*
|
|
141
|
-
*
|
|
152
|
+
* A peer that answers to its own endpoint instead of routing to `src` leaves no token
|
|
153
|
+
* in `dst`. Then the reply's `src` is matched as before: the oldest outstanding
|
|
154
|
+
* request whose `dst` ends with it, FIFO among the ones the wire cannot tell apart.
|
|
155
|
+
* Since #2245 a reply's `src` is the target's PAIR (RFC-0029 §6.2), an escape that
|
|
156
|
+
* names no segments, so such a reply falls through to the oldest entry — as does an
|
|
157
|
+
* empty `src`, or one matching nothing outstanding.
|
|
142
158
|
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
159
|
+
* @section expired A late reply
|
|
160
|
+
*
|
|
161
|
+
* A request that times out leaves `pending` (#2330). A reply whose token this client
|
|
162
|
+
* issued (`q<n>` with `n` below the next number, or any `sub<n>`) and that no live
|
|
163
|
+
* request holds is late, and is dropped (`-1`) with no memory needed. Only a peer that
|
|
164
|
+
* does not route its reply to `src` sends no token; for that reply alone `expired`
|
|
165
|
+
* remembers the last {@link EXPIRED_CAP} dead requests' `dst`, and a `src` that matches
|
|
166
|
+
* one of them and no live request is dropped too. A live request is always tried first,
|
|
167
|
+
* so a dead one can never take a reply from a live request to the same path.
|
|
147
168
|
*/
|
|
148
169
|
private correlate;
|
|
170
|
+
/**
|
|
171
|
+
* @brief Hand a delivered VALUE to every {@link onValue} handler, and to the one
|
|
172
|
+
* subscription its `dst` names.
|
|
173
|
+
*
|
|
174
|
+
* A producer addresses a delivery by the return route its subscribe request
|
|
175
|
+
* carried, which is that subscription's own target `<reply-ep>/sub<n>`. `dst`
|
|
176
|
+
* shrinks per hop, so what arrives is a TAIL of that target: its last segment
|
|
177
|
+
* names the subscription and whatever precedes it must end the reply endpoint (a
|
|
178
|
+
* node whose link shares the endpoint's first segment consumes that segment as a
|
|
179
|
+
* hop). A delivery whose `dst` names no live subscription (no `dst` at all, the bare
|
|
180
|
+
* reply endpoint, a detached or unknown subscription, a `PATH_REF` or an escaped
|
|
181
|
+
* path) reaches the {@link onValue} handlers only.
|
|
182
|
+
*
|
|
183
|
+
* @param value the delivered VALUE TLV
|
|
184
|
+
* @param dst the delivery's `dst` route, or `null` for a bare / ROUTER-wrapped VALUE
|
|
185
|
+
*/
|
|
149
186
|
private deliver;
|
|
150
187
|
private emitError;
|
|
151
188
|
/**
|
|
152
189
|
* @brief Send a one-shot FWD and resolve its FWD{REPLY}.
|
|
153
190
|
*
|
|
154
|
-
* @param frame the
|
|
155
|
-
*
|
|
191
|
+
* @param build builds the request frame around the `src` it is given: the reply
|
|
192
|
+
* endpoint plus this request's own reply token
|
|
193
|
+
* @param dst the request's destination segments — the fallback key a reply's `src`
|
|
156
194
|
* echoes (see {@link correlate})
|
|
157
195
|
* @param deadlineMs this request's own deadline in ms, overriding
|
|
158
196
|
* `requestTimeoutMs` (used by {@link await_})
|
|
159
197
|
* @param onDeadline the rejection raised when the deadline elapses
|
|
198
|
+
* @param token the reply token, when the caller already owns one (a subscription's
|
|
199
|
+
* `sub<n>`); otherwise a fresh `q<n>`
|
|
160
200
|
*/
|
|
161
201
|
private request;
|
|
162
202
|
/** @brief Turn a RESULT reply into its payload TLV; throw {@link FwdError} on ERROR. */
|
|
163
203
|
private result;
|
|
164
204
|
/**
|
|
165
|
-
* @brief Read a remote vertex's value: `FWD{ op=READ, dst=path, src=<reply-ep> }`.
|
|
205
|
+
* @brief Read a remote vertex's value: `FWD{ op=READ, dst=path, src=<reply-ep>/q<n> }`.
|
|
166
206
|
*
|
|
167
207
|
* @param path the destination path (a `/`-string like `"/sensor/temp"`, or segments)
|
|
168
208
|
* @returns the RESULT's value TLV (decoded)
|
|
@@ -231,8 +271,8 @@ export declare class LibtracerClient {
|
|
|
231
271
|
* of `requestTimeoutMs` (10 s by default; the default is used even when the
|
|
232
272
|
* option disables other requests' deadlines) and `timeoutNs`.
|
|
233
273
|
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
274
|
+
* Each request carries its own reply token, so an `await_` and a `read` to the same
|
|
275
|
+
* vertex may be outstanding at once.
|
|
236
276
|
*
|
|
237
277
|
* @param path the destination path (string or segments)
|
|
238
278
|
* @param timeoutNs the await timeout in ns, sent as `await_timeout` and used as
|
|
@@ -243,16 +283,20 @@ export declare class LibtracerClient {
|
|
|
243
283
|
await_(path: string | string[], timeoutNs?: bigint): Promise<Tlv>;
|
|
244
284
|
/**
|
|
245
285
|
* @brief Subscribe to a remote producer: a `WRITE` of a `SUBSCRIBER{
|
|
246
|
-
* target=<reply-ep> }` into `producer:subscribers[]` (RFC-0004 §C/§D —
|
|
286
|
+
* target=<reply-ep>/sub<n> }` into `producer:subscribers[]` (RFC-0004 §C/§D —
|
|
247
287
|
* subscribe is a field-write).
|
|
248
288
|
*
|
|
249
|
-
*
|
|
289
|
+
* Each call targets its own path `<reply-ep>/sub<n>` below the reply endpoint and
|
|
290
|
+
* sends the write from it, so the producer addresses its deliveries there. `handler`
|
|
291
|
+
* fires only for deliveries whose `dst` is that path; another subscription's
|
|
292
|
+
* deliveries never reach it.
|
|
250
293
|
*
|
|
251
294
|
* SCOPE: this issues the SUBSCRIBER and receives VALUEs the producer directly
|
|
252
295
|
* delivers to this client's reply endpoint. Full standing-stream delivery
|
|
253
296
|
* additionally needs the producer auto-promote / flush seam (#136 / RFC-0004 §E)
|
|
254
297
|
* — out of scope for this client slice. `unsubscribe()` is a LOCAL detach: it
|
|
255
|
-
* stops firing `handler
|
|
298
|
+
* stops firing `handler`, leaves every other subscription working, and does not
|
|
299
|
+
* clear the remote slot (an indexed
|
|
256
300
|
* `:subscribers[N]` field-write, which REPLACES that slot rather than adding
|
|
257
301
|
* to it — RFC-0009 §D.1).
|
|
258
302
|
*
|
package/dist/client.js
CHANGED
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
*
|
|
12
12
|
* Now that RFC-0004 fills spec §3 (the remote-operation envelope ADR-0034
|
|
13
13
|
* deferred), the client speaks the path-addressed higher operations over `FWD`:
|
|
14
|
-
* - read(path) — FWD{ op=READ, dst=path, src=<reply-ep> }
|
|
14
|
+
* - read(path) — FWD{ op=READ, dst=path, src=<reply-ep>/q<n> }
|
|
15
15
|
* - write(path, valueTLV) — FWD{ op=WRITE, dst=path, src=…, payload }
|
|
16
16
|
* - await(path, ns?) — FWD{ op=AWAIT, dst=path, src=…, await_timeout? }
|
|
17
17
|
* - readField(path, sel) — FWD{ op=READ, dst=path, FIELD=sel, src=… }
|
|
18
18
|
* - subscribe(prod, h) — FWD{ op=WRITE, dst=prod, FIELD=:subscribers[],
|
|
19
|
-
* src
|
|
19
|
+
* src=<reply-ep>/sub<n>,
|
|
20
|
+
* payload=SUBSCRIBER{ target=<reply-ep>/sub<n> } }
|
|
20
21
|
* Each one-shot op sends a FWD and resolves the FWD{REPLY} the responder
|
|
21
22
|
* source-routes back (RESULT → the value, ERROR → a typed {@link FwdError}).
|
|
22
23
|
*
|
|
@@ -57,6 +58,14 @@ export class FwdError extends Error {
|
|
|
57
58
|
this.path = trPath;
|
|
58
59
|
}
|
|
59
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* @brief How many timed-out requests' `dst` the client remembers, so a late reply that
|
|
63
|
+
* carries no token is dropped rather than handed to a live caller. The oldest is forgotten
|
|
64
|
+
* first. A reply that carries a token needs no memory (see `LibtracerClient.correlate`).
|
|
65
|
+
*/
|
|
66
|
+
const EXPIRED_CAP = 32;
|
|
67
|
+
/** @brief A reply token this client issues: `q<n>` for a one-shot, `sub<n>` for a subscribe. */
|
|
68
|
+
const TOKEN = /^(q|sub)([1-9][0-9]*)$/;
|
|
60
69
|
/** @brief The request deadline used when `requestTimeoutMs` is not given. */
|
|
61
70
|
const DEFAULT_REQUEST_TIMEOUT_MS = 10000;
|
|
62
71
|
/**
|
|
@@ -73,9 +82,12 @@ export function awaitDeadlineMs(requestTimeoutMs, timeoutNs) {
|
|
|
73
82
|
const own = Math.max(1, Math.ceil(Number(timeoutNs) / 1e6));
|
|
74
83
|
return Math.min(request, own);
|
|
75
84
|
}
|
|
76
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* @brief Settle a pending entry: clear its deadline. Every entry leaves `pending` as it
|
|
87
|
+
* settles (answered, timed out, or the transport closed), so the queue holds live
|
|
88
|
+
* requests only (#2330).
|
|
89
|
+
*/
|
|
77
90
|
function settle(p) {
|
|
78
|
-
p.settled = true;
|
|
79
91
|
if (p.timer !== null) {
|
|
80
92
|
clearTimeout(p.timer);
|
|
81
93
|
p.timer = null;
|
|
@@ -99,7 +111,18 @@ export class LibtracerClient {
|
|
|
99
111
|
*/
|
|
100
112
|
constructor(transport, options = {}) {
|
|
101
113
|
this.valueHandlers = new Set();
|
|
114
|
+
/**
|
|
115
|
+
* @brief Each live subscription's handler, keyed by its target's last segment
|
|
116
|
+
* (`sub<n>`, the one segment below the reply endpoint).
|
|
117
|
+
*/
|
|
118
|
+
this.subscriptions = new Map();
|
|
119
|
+
/** @brief The number the next subscription's target segment carries. */
|
|
120
|
+
this.nextSubscription = 1;
|
|
121
|
+
/** @brief The number the next one-shot request's reply token (`q<n>`) carries. */
|
|
122
|
+
this.nextRequest = 1;
|
|
102
123
|
this.pending = [];
|
|
124
|
+
/** @brief The `dst` of the most recent timed-out requests, oldest first, at most {@link EXPIRED_CAP}. */
|
|
125
|
+
this.expired = [];
|
|
103
126
|
this.errorHandler = null;
|
|
104
127
|
this.closed = null;
|
|
105
128
|
this.transport = transport;
|
|
@@ -112,12 +135,11 @@ export class LibtracerClient {
|
|
|
112
135
|
handleClose(cause) {
|
|
113
136
|
this.closed = new Error('transport closed' + (cause ? `: ${cause.message}` : ''));
|
|
114
137
|
for (const p of this.pending) {
|
|
115
|
-
if (p.settled)
|
|
116
|
-
continue;
|
|
117
138
|
settle(p);
|
|
118
139
|
p.reject(this.closed);
|
|
119
140
|
}
|
|
120
141
|
this.pending.length = 0;
|
|
142
|
+
this.expired.length = 0;
|
|
121
143
|
}
|
|
122
144
|
/* ---------------------------------------------------------- inbound --- */
|
|
123
145
|
/**
|
|
@@ -125,7 +147,8 @@ export class LibtracerClient {
|
|
|
125
147
|
*
|
|
126
148
|
* A delivery is a FWD{WRITE} (delivery-is-a-write, RFC-0004 §D); a bare VALUE
|
|
127
149
|
* or a single ROUTER wrapper is also accepted. Multiple handlers may be
|
|
128
|
-
* registered; each receives every delivery
|
|
150
|
+
* registered; each receives every delivery, including the ones a
|
|
151
|
+
* {@link subscribe} handler also receives.
|
|
129
152
|
*/
|
|
130
153
|
onValue(handler) {
|
|
131
154
|
this.valueHandlers.add(handler);
|
|
@@ -156,19 +179,15 @@ export class LibtracerClient {
|
|
|
156
179
|
if (parsed.op === FWD_OP.REPLY) {
|
|
157
180
|
const at = this.correlate(parsed);
|
|
158
181
|
if (at < 0)
|
|
159
|
-
return; // a reply with nothing outstanding to answer
|
|
182
|
+
return; // a late reply, or one with nothing outstanding to answer
|
|
160
183
|
const [waiter] = this.pending.splice(at, 1);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (!waiter.settled) {
|
|
164
|
-
settle(waiter);
|
|
165
|
-
waiter.resolve(parsed);
|
|
166
|
-
}
|
|
184
|
+
settle(waiter);
|
|
185
|
+
waiter.resolve(parsed);
|
|
167
186
|
return;
|
|
168
187
|
}
|
|
169
188
|
// A delivery IS a FWD{WRITE} (RFC-0004 §D): deliver its VALUE payload.
|
|
170
189
|
if (parsed.op === FWD_OP.WRITE && parsed.payload && parsed.payload.type === TYPE.VALUE) {
|
|
171
|
-
this.deliver(parsed.payload);
|
|
190
|
+
this.deliver(parsed.payload, parsed.dst);
|
|
172
191
|
}
|
|
173
192
|
return;
|
|
174
193
|
}
|
|
@@ -176,7 +195,7 @@ export class LibtracerClient {
|
|
|
176
195
|
// (the directly-delivered / bridge-mounted path, ADR-0034 inbound rule).
|
|
177
196
|
const data = tlv.type === TYPE.ROUTER && tlv.children.length > 0 ? tlv.children[tlv.children.length - 1] : tlv;
|
|
178
197
|
if (data.type === TYPE.VALUE)
|
|
179
|
-
this.deliver(data);
|
|
198
|
+
this.deliver(data, null);
|
|
180
199
|
}
|
|
181
200
|
/**
|
|
182
201
|
* @brief Which outstanding request this REPLY answers — its index, or `-1` for none.
|
|
@@ -189,51 +208,85 @@ export class LibtracerClient {
|
|
|
189
208
|
* milliseconds while a local one answers in about one, so a later request
|
|
190
209
|
* routinely OVERTAKES an earlier one on the same link. Under `shift()` the first
|
|
191
210
|
* overtake transposes two answers and the queue never realigns — every later
|
|
192
|
-
* caller gets the previous request's reply.
|
|
193
|
-
*
|
|
211
|
+
* caller gets the previous request's reply (#1530).
|
|
212
|
+
*
|
|
213
|
+
* @section token The originator matches by its own reply token
|
|
194
214
|
*
|
|
195
|
-
*
|
|
215
|
+
* Every request's `src` is the reply endpoint plus one segment of its own: `q<n>`
|
|
216
|
+
* for a one-shot, `sub<n>` for a subscribe. A REPLY is routed by that `src`, so its
|
|
217
|
+
* `dst` carries the token home; `dst` shrinks per hop, so what arrives is a TAIL of
|
|
218
|
+
* `<reply-ep>/<token>` — its last segment is the token and whatever precedes it must
|
|
219
|
+
* end the reply endpoint, the same reading {@link deliver} applies. The token is an
|
|
220
|
+
* ordinary `src` segment, not a field in `FWD`, and the receiver holds no state for
|
|
221
|
+
* it ([18 §Acknowledged one-shot operations and safe retry](
|
|
222
|
+
* ../../../../../docs/reference/18-composition-over-the-network.md#acknowledged-one-shot-operations-and-safe-retry)).
|
|
196
223
|
*
|
|
197
|
-
*
|
|
198
|
-
* still required and is set to the **responder's own endpoint** (the vertex that
|
|
199
|
-
* produced the result)". `dst` SHRINKS per hop, so what the terminus resolved —
|
|
200
|
-
* and echoes — is the TAIL of the request's `dst` after every mount prefix was
|
|
201
|
-
* stripped: a request to `/net/ws-client/peer0/hw/variant` answers `src=hw/variant`,
|
|
202
|
-
* and so does a local request to `/hw/variant`. The key is therefore a SUFFIX
|
|
203
|
-
* match, not an equality, and it is genuinely ambiguous between those two.
|
|
224
|
+
* @section fallback When the token is absent
|
|
204
225
|
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
226
|
+
* A peer that answers to its own endpoint instead of routing to `src` leaves no token
|
|
227
|
+
* in `dst`. Then the reply's `src` is matched as before: the oldest outstanding
|
|
228
|
+
* request whose `dst` ends with it, FIFO among the ones the wire cannot tell apart.
|
|
229
|
+
* Since #2245 a reply's `src` is the target's PAIR (RFC-0029 §6.2), an escape that
|
|
230
|
+
* names no segments, so such a reply falls through to the oldest entry — as does an
|
|
231
|
+
* empty `src`, or one matching nothing outstanding.
|
|
208
232
|
*
|
|
209
|
-
* @section
|
|
233
|
+
* @section expired A late reply
|
|
210
234
|
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
235
|
+
* A request that times out leaves `pending` (#2330). A reply whose token this client
|
|
236
|
+
* issued (`q<n>` with `n` below the next number, or any `sub<n>`) and that no live
|
|
237
|
+
* request holds is late, and is dropped (`-1`) with no memory needed. Only a peer that
|
|
238
|
+
* does not route its reply to `src` sends no token; for that reply alone `expired`
|
|
239
|
+
* remembers the last {@link EXPIRED_CAP} dead requests' `dst`, and a `src` that matches
|
|
240
|
+
* one of them and no live request is dropped too. A live request is always tried first,
|
|
241
|
+
* so a dead one can never take a reply from a live request to the same path.
|
|
215
242
|
*/
|
|
216
243
|
correlate(parsed) {
|
|
217
244
|
const fifo = this.pending.length > 0 ? 0 : -1;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
245
|
+
const byToken = segmentsOf(parsed.dst);
|
|
246
|
+
const token = byToken !== null && byToken.length > 0 ? byToken[byToken.length - 1] : '';
|
|
247
|
+
const issued = TOKEN.exec(token);
|
|
248
|
+
if (issued !== null && endsWith(this.replyEndpoint, byToken.slice(0, -1))) {
|
|
249
|
+
const at = this.pending.findIndex((p) => p.token === token);
|
|
250
|
+
if (at >= 0)
|
|
251
|
+
return at;
|
|
252
|
+
if (issued[1] === 'sub' || Number(issued[2]) < this.nextRequest)
|
|
253
|
+
return -1;
|
|
224
254
|
}
|
|
225
|
-
|
|
255
|
+
const src = segmentsOf(parsed.src);
|
|
256
|
+
if (src === null || src.length === 0)
|
|
226
257
|
return fifo;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
258
|
+
const at = this.pending.findIndex((p) => p.dst !== null && endsWith(p.dst, src));
|
|
259
|
+
if (at >= 0)
|
|
260
|
+
return at;
|
|
261
|
+
const dead = this.expired.findIndex((d) => endsWith(d, src));
|
|
262
|
+
if (dead < 0)
|
|
263
|
+
return fifo;
|
|
264
|
+
this.expired.splice(dead, 1);
|
|
265
|
+
return -1;
|
|
233
266
|
}
|
|
234
|
-
|
|
267
|
+
/**
|
|
268
|
+
* @brief Hand a delivered VALUE to every {@link onValue} handler, and to the one
|
|
269
|
+
* subscription its `dst` names.
|
|
270
|
+
*
|
|
271
|
+
* A producer addresses a delivery by the return route its subscribe request
|
|
272
|
+
* carried, which is that subscription's own target `<reply-ep>/sub<n>`. `dst`
|
|
273
|
+
* shrinks per hop, so what arrives is a TAIL of that target: its last segment
|
|
274
|
+
* names the subscription and whatever precedes it must end the reply endpoint (a
|
|
275
|
+
* node whose link shares the endpoint's first segment consumes that segment as a
|
|
276
|
+
* hop). A delivery whose `dst` names no live subscription (no `dst` at all, the bare
|
|
277
|
+
* reply endpoint, a detached or unknown subscription, a `PATH_REF` or an escaped
|
|
278
|
+
* path) reaches the {@link onValue} handlers only.
|
|
279
|
+
*
|
|
280
|
+
* @param value the delivered VALUE TLV
|
|
281
|
+
* @param dst the delivery's `dst` route, or `null` for a bare / ROUTER-wrapped VALUE
|
|
282
|
+
*/
|
|
283
|
+
deliver(value, dst) {
|
|
235
284
|
for (const handler of this.valueHandlers)
|
|
236
285
|
handler(value.payload, value);
|
|
286
|
+
const segs = segmentsOf(dst);
|
|
287
|
+
if (segs === null || segs.length === 0 || !endsWith(this.replyEndpoint, segs.slice(0, -1)))
|
|
288
|
+
return;
|
|
289
|
+
this.subscriptions.get(segs[segs.length - 1])?.(value.payload, value);
|
|
237
290
|
}
|
|
238
291
|
emitError(err) {
|
|
239
292
|
if (this.errorHandler)
|
|
@@ -242,25 +295,36 @@ export class LibtracerClient {
|
|
|
242
295
|
/**
|
|
243
296
|
* @brief Send a one-shot FWD and resolve its FWD{REPLY}.
|
|
244
297
|
*
|
|
245
|
-
* @param frame the
|
|
246
|
-
*
|
|
298
|
+
* @param build builds the request frame around the `src` it is given: the reply
|
|
299
|
+
* endpoint plus this request's own reply token
|
|
300
|
+
* @param dst the request's destination segments — the fallback key a reply's `src`
|
|
247
301
|
* echoes (see {@link correlate})
|
|
248
302
|
* @param deadlineMs this request's own deadline in ms, overriding
|
|
249
303
|
* `requestTimeoutMs` (used by {@link await_})
|
|
250
304
|
* @param onDeadline the rejection raised when the deadline elapses
|
|
305
|
+
* @param token the reply token, when the caller already owns one (a subscription's
|
|
306
|
+
* `sub<n>`); otherwise a fresh `q<n>`
|
|
251
307
|
*/
|
|
252
|
-
request(
|
|
308
|
+
request(build, dst, deadlineMs = this.requestTimeoutMs, onDeadline = () => new Error(`request timed out after ${deadlineMs}ms (no FWD reply)`), token = `q${this.nextRequest++}`) {
|
|
309
|
+
const frame = build([...this.replyEndpoint, token]);
|
|
253
310
|
return new Promise((resolve, reject) => {
|
|
254
311
|
if (this.closed) {
|
|
255
312
|
reject(this.closed);
|
|
256
313
|
return;
|
|
257
314
|
}
|
|
258
|
-
const entry = { resolve, reject,
|
|
315
|
+
const entry = { resolve, reject, timer: null, dst, token };
|
|
259
316
|
if (deadlineMs > 0 && Number.isFinite(deadlineMs)) {
|
|
260
317
|
entry.timer = setTimeout(() => {
|
|
261
|
-
//
|
|
262
|
-
//
|
|
318
|
+
// Evict the waiter so it cannot take a live request's reply, and remember it
|
|
319
|
+
// so its own late reply is dropped (#2330).
|
|
263
320
|
settle(entry);
|
|
321
|
+
const at = this.pending.indexOf(entry);
|
|
322
|
+
if (at >= 0)
|
|
323
|
+
this.pending.splice(at, 1);
|
|
324
|
+
if (entry.dst !== null)
|
|
325
|
+
this.expired.push(entry.dst);
|
|
326
|
+
if (this.expired.length > EXPIRED_CAP)
|
|
327
|
+
this.expired.shift();
|
|
264
328
|
entry.reject(onDeadline());
|
|
265
329
|
}, deadlineMs);
|
|
266
330
|
// Don't hold a Node event loop open for a pending deadline (no-op in browsers).
|
|
@@ -288,7 +352,7 @@ export class LibtracerClient {
|
|
|
288
352
|
}
|
|
289
353
|
/* --------------------------------------------------------- one-shot --- */
|
|
290
354
|
/**
|
|
291
|
-
* @brief Read a remote vertex's value: `FWD{ op=READ, dst=path, src=<reply-ep> }`.
|
|
355
|
+
* @brief Read a remote vertex's value: `FWD{ op=READ, dst=path, src=<reply-ep>/q<n> }`.
|
|
292
356
|
*
|
|
293
357
|
* @param path the destination path (a `/`-string like `"/sensor/temp"`, or segments)
|
|
294
358
|
* @returns the RESULT's value TLV (decoded)
|
|
@@ -296,7 +360,7 @@ export class LibtracerClient {
|
|
|
296
360
|
*/
|
|
297
361
|
async read(path) {
|
|
298
362
|
const dst = splitPath(path);
|
|
299
|
-
const reply = await this.request(encodeFwd({ op: FWD_OP.READ, dst, src
|
|
363
|
+
const reply = await this.request((src) => encodeFwd({ op: FWD_OP.READ, dst, src }), dst);
|
|
300
364
|
const value = this.result(reply);
|
|
301
365
|
if (!value)
|
|
302
366
|
throw new FwdError(0); // RESULT with no payload — malformed read reply
|
|
@@ -315,7 +379,7 @@ export class LibtracerClient {
|
|
|
315
379
|
*/
|
|
316
380
|
async readField(path, selector) {
|
|
317
381
|
const dst = splitPath(path);
|
|
318
|
-
const reply = await this.request(encodeFwd({ op: FWD_OP.READ, dst, field: selector, src
|
|
382
|
+
const reply = await this.request((src) => encodeFwd({ op: FWD_OP.READ, dst, field: selector, src }), dst);
|
|
319
383
|
const value = this.result(reply);
|
|
320
384
|
if (!value)
|
|
321
385
|
throw new FwdError(0);
|
|
@@ -331,7 +395,7 @@ export class LibtracerClient {
|
|
|
331
395
|
*/
|
|
332
396
|
async write(path, valueTLV) {
|
|
333
397
|
const dst = splitPath(path);
|
|
334
|
-
const reply = await this.request(encodeFwd({ op: FWD_OP.WRITE, dst, src
|
|
398
|
+
const reply = await this.request((src) => encodeFwd({ op: FWD_OP.WRITE, dst, src, payload: valueTLV }), dst);
|
|
335
399
|
this.result(reply); // throws on ERROR; RESULT carries no payload
|
|
336
400
|
}
|
|
337
401
|
/**
|
|
@@ -364,11 +428,11 @@ export class LibtracerClient {
|
|
|
364
428
|
*/
|
|
365
429
|
async writeField(path, selector, valueTLV) {
|
|
366
430
|
const dst = splitPath(path);
|
|
367
|
-
const reply = await this.request(encodeFwd({
|
|
431
|
+
const reply = await this.request((src) => encodeFwd({
|
|
368
432
|
op: FWD_OP.WRITE,
|
|
369
433
|
dst,
|
|
370
434
|
field: selector,
|
|
371
|
-
src
|
|
435
|
+
src,
|
|
372
436
|
payload: valueTLV,
|
|
373
437
|
}), dst);
|
|
374
438
|
this.result(reply); // throws on ERROR; RESULT carries no payload
|
|
@@ -385,8 +449,8 @@ export class LibtracerClient {
|
|
|
385
449
|
* of `requestTimeoutMs` (10 s by default; the default is used even when the
|
|
386
450
|
* option disables other requests' deadlines) and `timeoutNs`.
|
|
387
451
|
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
452
|
+
* Each request carries its own reply token, so an `await_` and a `read` to the same
|
|
453
|
+
* vertex may be outstanding at once.
|
|
390
454
|
*
|
|
391
455
|
* @param path the destination path (string or segments)
|
|
392
456
|
* @param timeoutNs the await timeout in ns, sent as `await_timeout` and used as
|
|
@@ -396,10 +460,10 @@ export class LibtracerClient {
|
|
|
396
460
|
*/
|
|
397
461
|
async await_(path, timeoutNs) {
|
|
398
462
|
const dst = splitPath(path);
|
|
399
|
-
const reply = await this.request(encodeFwd({
|
|
463
|
+
const reply = await this.request((src) => encodeFwd({
|
|
400
464
|
op: FWD_OP.AWAIT,
|
|
401
465
|
dst,
|
|
402
|
-
src
|
|
466
|
+
src,
|
|
403
467
|
awaitTimeoutNs: timeoutNs,
|
|
404
468
|
}), dst, awaitDeadlineMs(this.requestTimeoutMs, timeoutNs), () => new FwdError(FWD_ERROR.TIMEOUT));
|
|
405
469
|
const value = this.result(reply);
|
|
@@ -409,16 +473,20 @@ export class LibtracerClient {
|
|
|
409
473
|
}
|
|
410
474
|
/**
|
|
411
475
|
* @brief Subscribe to a remote producer: a `WRITE` of a `SUBSCRIBER{
|
|
412
|
-
* target=<reply-ep> }` into `producer:subscribers[]` (RFC-0004 §C/§D —
|
|
476
|
+
* target=<reply-ep>/sub<n> }` into `producer:subscribers[]` (RFC-0004 §C/§D —
|
|
413
477
|
* subscribe is a field-write).
|
|
414
478
|
*
|
|
415
|
-
*
|
|
479
|
+
* Each call targets its own path `<reply-ep>/sub<n>` below the reply endpoint and
|
|
480
|
+
* sends the write from it, so the producer addresses its deliveries there. `handler`
|
|
481
|
+
* fires only for deliveries whose `dst` is that path; another subscription's
|
|
482
|
+
* deliveries never reach it.
|
|
416
483
|
*
|
|
417
484
|
* SCOPE: this issues the SUBSCRIBER and receives VALUEs the producer directly
|
|
418
485
|
* delivers to this client's reply endpoint. Full standing-stream delivery
|
|
419
486
|
* additionally needs the producer auto-promote / flush seam (#136 / RFC-0004 §E)
|
|
420
487
|
* — out of scope for this client slice. `unsubscribe()` is a LOCAL detach: it
|
|
421
|
-
* stops firing `handler
|
|
488
|
+
* stops firing `handler`, leaves every other subscription working, and does not
|
|
489
|
+
* clear the remote slot (an indexed
|
|
422
490
|
* `:subscribers[N]` field-write, which REPLACES that slot rather than adding
|
|
423
491
|
* to it — RFC-0009 §D.1).
|
|
424
492
|
*
|
|
@@ -432,27 +500,29 @@ export class LibtracerClient {
|
|
|
432
500
|
*/
|
|
433
501
|
async subscribe(producerPath, handler, opts = {}) {
|
|
434
502
|
const dst = splitPath(producerPath);
|
|
435
|
-
const
|
|
503
|
+
const key = `sub${this.nextSubscription++}`;
|
|
504
|
+
const target = [...this.replyEndpoint, key];
|
|
505
|
+
const subscriber = encodeSubscriber(target, opts);
|
|
436
506
|
// Register the handler BEFORE awaiting the ack: a producer may stream its
|
|
437
507
|
// first delivery before its subscribe REPLY is seen on the wire, and we must
|
|
438
508
|
// not drop it. On a rejected subscribe we detach again.
|
|
439
|
-
this.
|
|
509
|
+
this.subscriptions.set(key, handler);
|
|
440
510
|
try {
|
|
441
|
-
const reply = await this.request(encodeFwd({
|
|
511
|
+
const reply = await this.request((src) => encodeFwd({
|
|
442
512
|
op: FWD_OP.WRITE,
|
|
443
513
|
dst,
|
|
444
514
|
field: ':subscribers[]',
|
|
445
|
-
src
|
|
515
|
+
src,
|
|
446
516
|
payload: subscriber,
|
|
447
|
-
}), dst);
|
|
517
|
+
}), dst, this.requestTimeoutMs, undefined, key);
|
|
448
518
|
this.result(reply); // throws on ERROR
|
|
449
519
|
}
|
|
450
520
|
catch (err) {
|
|
451
|
-
this.
|
|
521
|
+
this.subscriptions.delete(key);
|
|
452
522
|
throw err;
|
|
453
523
|
}
|
|
454
524
|
return () => {
|
|
455
|
-
this.
|
|
525
|
+
this.subscriptions.delete(key);
|
|
456
526
|
};
|
|
457
527
|
}
|
|
458
528
|
/* ------------------------------------------- pure builders (static) --- */
|
|
@@ -481,7 +551,8 @@ Object.defineProperty(LibtracerClient.prototype, 'await', {
|
|
|
481
551
|
enumerable: false,
|
|
482
552
|
});
|
|
483
553
|
/**
|
|
484
|
-
* @brief Does @p path end with the segments @p tail — the reply-`src` suffix test
|
|
554
|
+
* @brief Does @p path end with the segments @p tail — the reply-`src` suffix test,
|
|
555
|
+
* and the test that a delivery's shrunken `dst` still names this client's endpoint.
|
|
485
556
|
*
|
|
486
557
|
* A suffix rather than an equality because `dst` shrinks per hop (RFC-0004 §B): the
|
|
487
558
|
* responder's own endpoint is what is left of the request's `dst` once every mount
|
|
@@ -496,6 +567,20 @@ function endsWith(path, tail) {
|
|
|
496
567
|
return false;
|
|
497
568
|
return true;
|
|
498
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
* @brief A route's segments, or `null` when it names none this client can read: no route, a
|
|
572
|
+
* retired `PATH_REF`, or a `PATH` carrying an escape record such as a PAIR (RFC-0029 §4).
|
|
573
|
+
*/
|
|
574
|
+
function segmentsOf(route) {
|
|
575
|
+
if (route === null)
|
|
576
|
+
return null;
|
|
577
|
+
try {
|
|
578
|
+
return pathSegments(route);
|
|
579
|
+
}
|
|
580
|
+
catch {
|
|
581
|
+
return null;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
499
584
|
/** @brief Normalize a `/`-path string (or segment array) into validated segments. */
|
|
500
585
|
function splitPath(path) {
|
|
501
586
|
if (Array.isArray(path))
|
package/dist/fwd.d.ts
CHANGED
|
@@ -136,11 +136,14 @@ export declare function encodeFwd(req: FwdRequest): Uint8Array;
|
|
|
136
136
|
export interface ParsedFwd {
|
|
137
137
|
/** @brief The operation (a {@link FWD_OP} value). */
|
|
138
138
|
readonly op: number;
|
|
139
|
-
/** @brief The `dst` route child — a `PATH
|
|
139
|
+
/** @brief The `dst` route child — a `PATH` (a `0x14 PATH_REF` is refused, RFC-0029 S1). */
|
|
140
140
|
readonly dst: Tlv;
|
|
141
141
|
/** @brief The optional FIELD selector child (or `null`). */
|
|
142
142
|
readonly field: Tlv | null;
|
|
143
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* @brief The `src` route child — a `PATH`. On a REPLY it is the learned chain: the target's
|
|
145
|
+
* PAIR plus one element per relaying hop (RFC-0029 §6.2), PAIRs being escape records.
|
|
146
|
+
*/
|
|
144
147
|
readonly src: Tlv;
|
|
145
148
|
/** @brief The reply {@link FWD_KIND} (REPLY frames only, else `null`). */
|
|
146
149
|
readonly kind: number | null;
|
|
@@ -148,36 +151,24 @@ export interface ParsedFwd {
|
|
|
148
151
|
readonly payload: Tlv | null;
|
|
149
152
|
/** @brief The AWAIT `await_timeout` ns (else `null`). */
|
|
150
153
|
readonly awaitTimeoutNs: bigint | null;
|
|
151
|
-
/** @brief `op` bit 7 was set — the origin asked for a bound-path mint (RFC-0024 §7.5). */
|
|
152
|
-
readonly mintRequest: boolean;
|
|
153
|
-
/** @brief `dst` is a `PATH_REF` (`0x14`), not a canonical `PATH` (RFC-0024 §4). */
|
|
154
|
-
readonly dstBound: boolean;
|
|
155
154
|
/**
|
|
156
|
-
* @brief The
|
|
157
|
-
*
|
|
155
|
+
* @brief The reverse-direction list a FORWARDED subscribe carries — a `PATH_REF_REVERSE`
|
|
156
|
+
* (`0x15`) whose body is a `PATH` body of PAIR and NAME records, one per hop, grown by
|
|
157
|
+
* every forwarder with no flag (RFC-0029 §7.1); else `null`.
|
|
158
158
|
*
|
|
159
159
|
* Identified by its TYPE, never by its position: a WRITE's payload is whatever stands in
|
|
160
|
-
* the payload slot as long as it is not this code
|
|
161
|
-
*
|
|
160
|
+
* the payload slot as long as it is not this code. The origin never emits the child, so
|
|
161
|
+
* this is `null` on every frame a client builds.
|
|
162
162
|
*/
|
|
163
163
|
readonly reverse: Tlv | null;
|
|
164
164
|
}
|
|
165
165
|
/**
|
|
166
|
-
* @brief The opcode field of the `op` byte — bits 5-0
|
|
166
|
+
* @brief The opcode field of the `op` byte — bits 5-0.
|
|
167
167
|
*
|
|
168
|
-
* Bits 7-6 are
|
|
169
|
-
*
|
|
170
|
-
* which is what makes a flag additive at all.
|
|
168
|
+
* Bits 7-6 are reserved: no client sets them, a forwarder routes on the masked opcode, and
|
|
169
|
+
* the terminus refuses a set bit (#2245).
|
|
171
170
|
*/
|
|
172
171
|
export declare const FWD_OPCODE_MASK = 63;
|
|
173
|
-
/**
|
|
174
|
-
* @brief `op` bit 7 — the bound-path MINT REQUEST (RFC-0024 §7.5).
|
|
175
|
-
*
|
|
176
|
-
* Set by an origin asking each host on the route to answer with its own vertex ref. It costs
|
|
177
|
-
* ZERO request bytes: there is no free TLV `opt` bit, and a dedicated presence child would
|
|
178
|
-
* spend a 4-byte header to express one. The request is a hint, never an obligation.
|
|
179
|
-
*/
|
|
180
|
-
export declare const FWD_OP_FLAG_MINT_REQUEST = 128;
|
|
181
172
|
/** @brief Parse an already-decoded FWD {@link Tlv} positionally (RFC-0004 §B). */
|
|
182
173
|
export declare function parseFwdTlv(fwd: Tlv): ParsedFwd;
|
|
183
174
|
/**
|
package/dist/fwd.js
CHANGED
|
@@ -225,21 +225,12 @@ export function encodeFwd(req) {
|
|
|
225
225
|
return encode(fwd);
|
|
226
226
|
}
|
|
227
227
|
/**
|
|
228
|
-
* @brief The opcode field of the `op` byte — bits 5-0
|
|
228
|
+
* @brief The opcode field of the `op` byte — bits 5-0.
|
|
229
229
|
*
|
|
230
|
-
* Bits 7-6 are
|
|
231
|
-
*
|
|
232
|
-
* which is what makes a flag additive at all.
|
|
230
|
+
* Bits 7-6 are reserved: no client sets them, a forwarder routes on the masked opcode, and
|
|
231
|
+
* the terminus refuses a set bit (#2245).
|
|
233
232
|
*/
|
|
234
233
|
export const FWD_OPCODE_MASK = 0x3f;
|
|
235
|
-
/**
|
|
236
|
-
* @brief `op` bit 7 — the bound-path MINT REQUEST (RFC-0024 §7.5).
|
|
237
|
-
*
|
|
238
|
-
* Set by an origin asking each host on the route to answer with its own vertex ref. It costs
|
|
239
|
-
* ZERO request bytes: there is no free TLV `opt` bit, and a dedicated presence child would
|
|
240
|
-
* spend a 4-byte header to express one. The request is a hint, never an obligation.
|
|
241
|
-
*/
|
|
242
|
-
export const FWD_OP_FLAG_MINT_REQUEST = 0x80;
|
|
243
234
|
const u8 = (t) => (t.payload.length > 0 ? t.payload[0] : 0);
|
|
244
235
|
/** @brief Parse an already-decoded FWD {@link Tlv} positionally (RFC-0004 §B). */
|
|
245
236
|
export function parseFwdTlv(fwd) {
|
|
@@ -249,25 +240,18 @@ export function parseFwdTlv(fwd) {
|
|
|
249
240
|
let i = 0;
|
|
250
241
|
if (ch[i]?.type !== TYPE.VALUE)
|
|
251
242
|
throw new RangeError('FWD: missing op VALUE child');
|
|
252
|
-
// The opcode is `op & 0x3F
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
// Two address forms (RFC-0024 §4): a canonical PATH, or a bound PATH_REF whose body shape
|
|
258
|
-
// the grammar has already checked. What an element MEANS is node-scoped, so a binding core
|
|
259
|
-
// carries one and never interprets it.
|
|
260
|
-
const dstBound = ch[i]?.type === TYPE.PATH_REF;
|
|
261
|
-
if (!dstBound && ch[i]?.type !== TYPE.PATH)
|
|
243
|
+
// The opcode is `op & 0x3F`, read the way a forwarder reads it (bits 7-6 reserved).
|
|
244
|
+
const op = u8(ch[i++]) & FWD_OPCODE_MASK;
|
|
245
|
+
// One address form: a PATH, whose PAIR records a binding carries and never interprets.
|
|
246
|
+
// A retired 0x14 PATH_REF is not a PATH, so it is refused here like any other type.
|
|
247
|
+
if (ch[i]?.type !== TYPE.PATH)
|
|
262
248
|
throw new RangeError('FWD: missing dst PATH child');
|
|
263
249
|
const dst = ch[i++];
|
|
264
250
|
let field = null;
|
|
265
251
|
if (ch[i]?.type === TYPE.FIELD)
|
|
266
252
|
field = ch[i++];
|
|
267
|
-
|
|
268
|
-
if (ch[i]?.type !== TYPE.PATH && ch[i]?.type !== TYPE.PATH_REF) {
|
|
253
|
+
if (ch[i]?.type !== TYPE.PATH)
|
|
269
254
|
throw new RangeError('FWD: missing src PATH child');
|
|
270
|
-
}
|
|
271
255
|
const src = ch[i++];
|
|
272
256
|
let kind = null;
|
|
273
257
|
let payload = null;
|
|
@@ -279,8 +263,7 @@ export function parseFwdTlv(fwd) {
|
|
|
279
263
|
payload = ch[i++];
|
|
280
264
|
}
|
|
281
265
|
else if (op === FWD_OP.WRITE) {
|
|
282
|
-
// The reverse list is told from the payload by its TYPE
|
|
283
|
-
// raw PATH_REF payload is a payload and only 0x15 is the list.
|
|
266
|
+
// The reverse list is told from the payload by its TYPE: only 0x15 is the list.
|
|
284
267
|
if (i < ch.length && ch[i].type !== TYPE.PATH_REF_REVERSE)
|
|
285
268
|
payload = ch[i++];
|
|
286
269
|
}
|
|
@@ -290,10 +273,9 @@ export function parseFwdTlv(fwd) {
|
|
|
290
273
|
i++;
|
|
291
274
|
}
|
|
292
275
|
}
|
|
293
|
-
//
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
return { op, dst, field, src, kind, payload, awaitTimeoutNs, mintRequest, dstBound, reverse };
|
|
276
|
+
// Every forwarded subscribe carries it, with no flag (RFC-0029 §7.1).
|
|
277
|
+
const reverse = ch[i]?.type === TYPE.PATH_REF_REVERSE ? ch[i] : null;
|
|
278
|
+
return { op, dst, field, src, kind, payload, awaitTimeoutNs, reverse };
|
|
297
279
|
}
|
|
298
280
|
/**
|
|
299
281
|
* @brief Decode a complete FWD frame's bytes into its parsed children.
|
package/dist/index.d.ts
CHANGED
|
@@ -20,5 +20,5 @@ export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec, firstChild,
|
|
|
20
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
|
-
export { FWD_OP, FWD_OPCODE_MASK,
|
|
23
|
+
export { FWD_OP, FWD_OPCODE_MASK, 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
|
@@ -19,4 +19,4 @@ export const CLIENT_EXPERIMENTAL = true;
|
|
|
19
19
|
export { LibtracerClient, FwdError, awaitDeadlineMs } from './client.js';
|
|
20
20
|
export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec, firstChild, pathSegments, PACKED_ESCAPE_LEN, DELIVERY_DURABILITY_REQUEST, DELIVERY_CLASS, deliveryClassBits, deliveryClassOf, } from './tlv.js';
|
|
21
21
|
export { walkTopology, routeKey, CONN_ENDPOINT_NAME } from './topology.js';
|
|
22
|
-
export { FWD_OP, FWD_OPCODE_MASK,
|
|
22
|
+
export { FWD_OP, FWD_OPCODE_MASK, 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
|
@@ -83,8 +83,8 @@ export declare function pathTlv(segments: string[]): Tlv;
|
|
|
83
83
|
*
|
|
84
84
|
* An escape is `00 <u8 kind> <u8 len> <len bytes>`. It is **admissible in a frame path** — a
|
|
85
85
|
* forwarder steps over one whose `kind` it does not implement instead of dropping a frame it
|
|
86
|
-
* is only relaying — and **rejected in canonical / key context**, because
|
|
87
|
-
* canonical bytes. This client never mints one; `kind = 0x16` is
|
|
86
|
+
* is only relaying — and **rejected in canonical / key context**, because an escape is not
|
|
87
|
+
* canonical bytes. This client never mints one; `kind = 0x16` is the RFC-0029 PAIR element.
|
|
88
88
|
*/
|
|
89
89
|
export declare const PACKED_ESCAPE_LEN = 0;
|
|
90
90
|
/**
|
package/dist/tlv.js
CHANGED
|
@@ -180,8 +180,8 @@ export function pathTlv(segments) {
|
|
|
180
180
|
*
|
|
181
181
|
* An escape is `00 <u8 kind> <u8 len> <len bytes>`. It is **admissible in a frame path** — a
|
|
182
182
|
* forwarder steps over one whose `kind` it does not implement instead of dropping a frame it
|
|
183
|
-
* is only relaying — and **rejected in canonical / key context**, because
|
|
184
|
-
* canonical bytes. This client never mints one; `kind = 0x16` is
|
|
183
|
+
* is only relaying — and **rejected in canonical / key context**, because an escape is not
|
|
184
|
+
* canonical bytes. This client never mints one; `kind = 0x16` is the RFC-0029 PAIR element.
|
|
185
185
|
*/
|
|
186
186
|
export const PACKED_ESCAPE_LEN = 0;
|
|
187
187
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avatarsd-llc/libtracer-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.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.22.0 <0.23.0",
|
|
37
|
+
"@avatarsd-llc/libtracer-ws": ">=0.22.0 <0.23.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@avatarsd-llc/libtracer-ws": {
|