@rootintf/protocol-2phw 3.0.13-api.2 → 3.1.2-api.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/README.md +78 -35
  2. package/dist/twoPhW.cjs.js +233 -517
  3. package/dist/twoPhW.d.ts +62 -43
  4. package/dist/twoPhW.es.mjs +233 -511
  5. package/package.json +5 -6
  6. package/src/twoPhW.ts +283 -188
  7. package/dist/generated/iface-TwoPhW/index.d.mts +0 -25
  8. package/dist/generated/iface-TwoPhW/validate.d.cts +0 -76
  9. package/dist/generated/iface-TwoPhW/validate.d.mts +0 -75
  10. package/schema/schema_MsgOptions.json +0 -12
  11. package/schema/schema_Options_delay.json +0 -17
  12. package/src/generated/.gitattributes +0 -4
  13. package/src/generated/iface-TwoPhW/index.cjs +0 -26
  14. package/src/generated/iface-TwoPhW/index.d.cts +0 -25
  15. package/src/generated/iface-TwoPhW/index.d.mts +0 -25
  16. package/src/generated/iface-TwoPhW/index.d.ts +0 -25
  17. package/src/generated/iface-TwoPhW/index.mjs +0 -23
  18. package/src/generated/iface-TwoPhW/package.json +0 -36
  19. package/src/generated/iface-TwoPhW/schema/schema_TwoPhW.json +0 -131
  20. package/src/generated/iface-TwoPhW/validate.cjs +0 -1
  21. package/src/generated/iface-TwoPhW/validate.mjs +0 -1
  22. package/src/generated/iface-introspection/index.cjs +0 -13
  23. package/src/generated/iface-introspection/index.d.cts +0 -6
  24. package/src/generated/iface-introspection/index.d.mts +0 -6
  25. package/src/generated/iface-introspection/index.d.ts +0 -6
  26. package/src/generated/iface-introspection/index.mjs +0 -10
  27. package/src/generated/iface-introspection/package.json +0 -30
  28. package/src/schema-cache/.gitattributes +0 -4
  29. package/src/schema-cache/5fdbd096ad99962b7e3d77cde8bd355fe180c859f35a61cfd07ee36b96c6700a.json +0 -131
package/README.md CHANGED
@@ -8,14 +8,26 @@ participant uses both:
8
8
 
9
9
  | part | what it is | where it comes from |
10
10
  |---|---|---|
11
- | the **interface** | the four messages on the wire: validators, constructors, `VERSION`, types | **generated** in your project by `iface-gen` from `schema_TwoPhW.json` |
11
+ | the **interface** | the five messages on the wire: validators, constructors, `VERSION`, types | **generated** in your project by `iface-gen` from `schema_TwoPhW.json` |
12
12
  | the **protocol** | the state machine: which step is legal now, inside which window, and the expiry timers | **this package** |
13
13
 
14
+ This package has **no interface and no schema of its own**. You hand it yours, once:
15
+
16
+ ```js
17
+ import * as iface_TwoPhW from '../generated/iface-TwoPhW'; // generated in your project
18
+ import { protocol_TwoPhW } from '@rootintf/protocol-2phw';
19
+
20
+ const { TwoPhW, JSON_MsgWarp, JSON_EffEngage, JSON_AckWarp, JSON_AckEngage } = protocol_TwoPhW(iface_TwoPhW);
21
+ ```
22
+
23
+ So the version you validate is the version the package builds its messages with; the two cannot
24
+ disagree.
25
+
14
26
  The generated responder in your project is where the two meet: its dispatch validates a message with
15
27
  the generated interface, then hands it to this package's typed handler.
16
28
 
17
29
  ```
18
- ME -> bridge -> Responder_TwoPhW.handler_json_{msg,eff,ack} generated: validate as a type
30
+ ME -> bridge -> Responder_TwoPhW.handler_json_{msg,eff,hold,ack} generated: validate as a type
19
31
  -> Responder_TwoPhW.handler_json_<message> you: one forwarding line
20
32
  -> twoPhW.handler_json_<message> this package: legal? in its window? log it
21
33
  -> your callback you: what the step means for the app
@@ -28,8 +40,9 @@ ME -> bridge -> Responder_TwoPhW.handler_json_{msg,eff,ack} generated: valid
28
40
  ```
29
41
  sender receiver
30
42
  | -- JSON_MsgWarp --------------------> | phase 1: "take this user to this hyperport"
43
+ | <------------------ JSON_HoldWarp --- | any number of times: "working on it, wait this long"
31
44
  | <------------------- JSON_AckWarp --- | ok:true, or ok:false (ends the exchange)
32
- | -- JSON_EffEngage ------------------> | phase 2: "commit" (carries the measured rtt_msec)
45
+ | -- JSON_EffEngage ------------------> | phase 2: "commit"
33
46
  | <----------------- JSON_AckEngage --- | concludes the exchange
34
47
  ```
35
48
 
@@ -37,28 +50,48 @@ sender receiver
37
50
  |---|---|---|---|
38
51
  | `JSON_MsgWarp` | `JSON_Msg` | `warp: { id, user, hyperport, ttl_msec, instantaneous? }` | — |
39
52
  | `JSON_AckWarp` | `JSON_Ack` | `ack: { ok }` | the `JSON_MsgWarp` |
40
- | `JSON_EffEngage` | `JSON_Eff` | `engage: { ok, rtt_msec }` | the `JSON_MsgWarp` (not its ack) |
53
+ | `JSON_HoldWarp` | `JSON_Hold` | `hold: { ttl_msec, stage?, percent?, eta_msec? }` | the `JSON_MsgWarp` |
54
+ | `JSON_EffEngage` | `JSON_Eff` | `engage: { ok }` | the `JSON_MsgWarp` (not its ack) |
41
55
  | `JSON_AckEngage` | `JSON_Ack` | `ack: { ok }` | the `JSON_EffEngage` |
42
56
 
43
- Every message carries the marker `"2PhW": "2"`. `warp.id` names the whole exchange: every later
57
+ Every message carries the marker `"2PhW": "3"`. `warp.id` names the whole exchange: every later
44
58
  message reaches it through its `_cause` chain.
45
59
 
46
- Each step is accepted only inside a window computed from the messages themselves (`TTL` =
47
- `warp.ttl_msec`, `STT` = the ack's `dt` minus the warp's `dt`, `RTT` = `engage.rtt_msec`):
60
+ **Timing.** Every step is timed from the message it answers, by that message's own `dt`; no step
61
+ looks further back than the message before it. There are two durations, each stating one cause of
62
+ lateness and set by the side that knows it:
63
+
64
+ - `TTL` = `warp.ttl_msec`, set by the sender: the longest a message of the exchange may take to
65
+ travel **one way**. Network delay and its variability, nothing else.
66
+ - **the lease** = `hold.ttl_msec` of a `JSON_HoldWarp`, set by the receiver: "my next word comes
67
+ within this long". Work, nothing else.
68
+
69
+ A message that hands the turn over is answered within its `dt` + `2·TTL`, there and back. After a
70
+ hold the next word is due within the hold's `dt` + its lease + `TTL`:
48
71
 
49
72
  | step | accepted until |
50
73
  |---|---|
51
- | `JSON_MsgWarp` | the warp's `dt` + `TTL` |
52
- | `JSON_AckWarp` | the warp's `dt` + `2·TTL` |
53
- | `JSON_EffEngage` | the ack's `dt` + `2·TTL` + `STT` |
54
- | `JSON_AckEngage` | the warp's `dt` + `2·TTL` + `RTT` |
74
+ | `JSON_MsgWarp` | the warp's `dt` + `TTL` (one way) |
75
+ | `JSON_HoldWarp`, `JSON_AckWarp` | the warp's `dt` + `2·TTL`, or where a hold moved that: the hold's `dt` + lease + `TTL` |
76
+ | `JSON_EffEngage` | the ack's `dt` + `2·TTL` |
77
+ | `JSON_AckEngage` | the engage's `dt` + `2·TTL` |
78
+
79
+ Of several holds the one that ends latest counts; nothing is added up, so a hold delivered twice
80
+ changes nothing. A hold whose lease ends inside the window in force is logged and moves nothing. A
81
+ window that has closed is not reopened. A hold is not a step: the exchange stays where it is, waiting
82
+ for the `JSON_AckWarp`, and holds stop with it.
55
83
 
56
- `ttl_msec` must be above 0 and `rtt_msec` 0 or more (the schema refuses anything else). `RTT` is also
57
- capped at `2·TTL`: an engage that claims more is refused. So an exchange never stays open longer
58
- than `4·TTL` after its warp, and that is how far back the package replays the event log.
84
+ So silence is noticed within `2·TTL`, or within a lease + `TTL` while work is under way, however
85
+ long the work is. The exchange as a whole has no limit: it stays open for as long as leases are
86
+ renewed, and the package replays the event log back to the warp's own `dt`. A receiver that parks a
87
+ warp (a user is asked, a world is installed) registers and publishes its first hold at once and renews
88
+ well inside its lease; work then never has to fit inside `ttl_msec`.
89
+
90
+ `ttl_msec` and a lease must be above 0 (the schemas refuse anything else).
59
91
 
60
92
  A step that arrives out of order, twice, late, or after a nack is refused: its handler returns
61
- `false` and nothing is logged.
93
+ `false` and nothing is logged. So is a step whose `dt` does not read as a time: every window is
94
+ measured from a `dt`, and the schema only asks it to be a string.
62
95
 
63
96
  **Single phase.** A warp with `instantaneous: true` has no phase 2: its `JSON_AckWarp` concludes the
64
97
  exchange, and an engage for it is refused (received, or registered). The receiver acts on the warp
@@ -83,21 +116,21 @@ Register `TwoPhW` once, pinned by hash, and list it in the target of the partici
83
116
  {
84
117
  "schemas": {
85
118
  "TwoPhW": { "src": "~/protocols.git/schemas.readonly/schema_TwoPhW.json",
86
- "sha256": "5fdbd096ad99962b7e3d77cde8bd355fe180c859f35a61cfd07ee36b96c6700a" }
119
+ "sha256": "<the hash in schema_TwoPhW.json.sha256>" }
87
120
  },
88
121
  "targets": [
89
122
  { "root": "src/renderer",
90
- "IPSME": { "main": "App.js", "object": "App", "shell": "electron-renderer", "out": "IPSME" },
123
+ "IPSME": { "main": "App.js", "object": "App", "runtime": "electron-renderer", "shape": "component", "out": "IPSME" },
91
124
  "schema-cache": "schema-cache", "out-npm": "generated",
92
125
  "scope": "@rootintf", "prefix": "iface-", "delete": true,
93
126
  "schemas": [ "Discovery", "TwoPhW" ] }
94
127
  ],
95
- "version": 3
128
+ "version": 4
96
129
  }
97
130
  ```
98
131
 
99
- The pin must be the same hash this package was built against (see its own `ifacegenconfig.json`).
100
- That is what keeps your validators and this package's constructors on the same definition.
132
+ The pin is yours alone: this package carries no schema and is not built against one. Whatever
133
+ interface you generate here is the one you hand to `protocol_TwoPhW`.
101
134
 
102
135
  ### 3. Generate
103
136
 
@@ -129,9 +162,12 @@ import { LOGR, l_array } from '@knev/bitlogr';
129
162
 
130
163
  import { JSON_MsgWarp, JSON_AckWarp, JSON_EffEngage, JSON_AckEngage } from '../generated/iface-TwoPhW'; // generated
131
164
 
132
- // this package's JSON_* are the generated ones extended with the protocol's own constructors,
133
- // so import the ones you need under an alias
134
- import { TwoPhW, JSON_EffEngage as TwoPhW_EffEngage, logr as logr_twoPhW_ } from '@rootintf/protocol-2phw';
165
+ // bind the package to YOUR generated interface. What it returns are the generated namespaces
166
+ // extended with the protocol's own constructors, so take the ones you need under an alias
167
+ import * as iface_TwoPhW from '../generated/iface-TwoPhW';
168
+ import { protocol_TwoPhW, logr as logr_twoPhW_ } from '@rootintf/protocol-2phw';
169
+
170
+ const { TwoPhW, JSON_EffEngage: TwoPhW_EffEngage } = protocol_TwoPhW(iface_TwoPhW);
135
171
 
136
172
  const logr_= LOGR_.create({ name: "Responder_TwoPhW", labels : obj_labels_ }); // generated
137
173
  const l_= logr_.l; // generated
@@ -184,7 +220,7 @@ _callback_ackWarp(msg, json_ackWarp) {
184
220
  return true;
185
221
  }
186
222
 
187
- const json_effEngage = TwoPhW_EffEngage.create_with_Warp(json_ackWarp._cause); // measures rtt_msec
223
+ const json_effEngage = TwoPhW_EffEngage.create_with_Warp(json_ackWarp._cause);
188
224
  json_effEngage.referer = this.interface_IPSME.karr_referer;
189
225
  const str_effEngage = JSON.stringify(json_effEngage);
190
226
 
@@ -308,16 +344,20 @@ Leave it empty. The package's expiries are timers on the event log, not parked e
308
344
 
309
345
  | export | what |
310
346
  |---|---|
311
- | `TwoPhW` | `new TwoPhW(eventLog)`: the protocol over one participant's event log |
312
- | `twoPhW.config.sender(callback_ackWarp, callback_ackEngage, callback_msg_sent_expired)` | the sender's callbacks |
347
+ | `protocol_TwoPhW(iface_TwoPhW)` | binds the package to your generated interface. Returns `{ TwoPhW, VERSION, JSON_MsgWarp, JSON_AckWarp, JSON_HoldWarp, JSON_EffEngage, JSON_AckEngage }`. Throws, naming what is missing, when what it is given is not a generated 2PhW interface |
348
+ | `TwoPhW` (returned) | `new TwoPhW(eventLog)`: the protocol over one participant's event log |
349
+ | `twoPhW.config.sender(callback_ackWarp, callback_ackEngage, callback_msg_sent_expired, callback_holdWarp = null)` | the sender's callbacks. The last is optional: a hold moves the warp's expiry whether or not you want to be told |
313
350
  | `twoPhW.config.receiver(callback_msgWarp, callback_effEngage, callback_msg_sent_expired)` | the receiver's callbacks |
314
351
  | `twoPhW.register_msgWarp` / `register_effEngage` | sender: register a send. Returns `true`, or `false` when the step is not legal now |
315
352
  | `twoPhW.register_ackWarp` / `register_ackEngage` | receiver: the same for its acks |
353
+ | `twoPhW.register_holdWarp` | receiver: the same for a hold. Legal for a warp it received, has not answered, and whose window is still open |
354
+ | `twoPhW.handler_json_holdWarp` | sender: a validated hold arrived. Moves the expiry of the warp to the end of the lease + `TTL` |
316
355
  | `twoPhW.handler_json_ackWarp` / `handler_json_ackEngage` | sender: a validated ack arrived |
317
356
  | `twoPhW.handler_json_msgWarp` / `handler_json_effEngage` | receiver: a validated request arrived |
318
- | `JSON_MsgWarp`, `JSON_EffEngage`, `JSON_AckWarp`, `JSON_AckEngage` | the generated namespaces, extended (next table) |
319
- | `VERSION` | the protocol marker's value, from the generated interface |
320
- | `t_ttl_rtt(ttl_msec, rtt_msec?)` | the window arithmetic (`2·TTL`, or `2·TTL + RTT`) |
357
+ | `JSON_MsgWarp`, `JSON_EffEngage`, `JSON_AckWarp`, `JSON_AckEngage` (returned) | your generated namespaces, extended (next table) |
358
+ | `JSON_HoldWarp` (returned) | your generated namespace, as it is: `create_with_cause_ttl(json_msgWarp, ttl_msec, body = {})` |
359
+ | `VERSION` (returned) | the protocol marker's value: your generated interface's |
360
+ | `window_msec(ttl_msec)` | the window in which a message that hands the turn over is answered: `2·TTL` |
321
361
  | `StateInitialState`, `StateWarp`, `StateAckWarp`, `StateEngage`, `StateAckEngage`, `StateINVALID` | the states `twoPhW.eventLog.traverse_State(json_msgWarp).state` replays to |
322
362
  | `JSON_Msg`, `JSON_Eff`, `JSON_Ack` | re-exported from `@rootintf/json-msg` |
323
363
  | `logr` | the package's logger (labels `PROTOCOL_STATE`, `SENDER`, `RECVER`, `HANDLERS`, `DROPS`) |
@@ -326,7 +366,7 @@ The constructors the schema cannot express:
326
366
 
327
367
  | constructor | why it is here |
328
368
  |---|---|
329
- | `JSON_EffEngage.create_with_Warp(json_msgWarp)` | measures `rtt_msec` from the warp's `dt` |
369
+ | `JSON_EffEngage.create_with_Warp(json_msgWarp)` | the commit: `engage: { ok: true }`, caused by the warp |
330
370
  | `JSON_AckWarp.create_with_Warp_Ok(json_msgWarp, b_ok = true)` | iface-gen emits no constructor for a `JSON_Ack`; stamps the marker |
331
371
  | `JSON_AckEngage.create_with_Engage_Ok(json_effEngage, b_ok = true)` | the same |
332
372
  | `JSON_MsgWarp.create_with_id_user_hyperport(id, user, hyperport, ttl_msec)` | shorthand for the generated `merge` |
@@ -364,9 +404,11 @@ the expiry firing, and a stranger's exchange (not handled, nothing logged).
364
404
  - **The windows assume the two clocks agree.** Every window compares the local clock with a `dt`
365
405
  the other side stamped. If the receiver's clock is ahead of the sender's by more than `ttl_msec`,
366
406
  the warp is already expired when it arrives; if it is behind, the windows stay open that much
367
- longer. (`rtt_msec` itself is not affected: the sender measures it against its own warp's `dt`.)
407
+ longer.
368
408
  2PhW does not measure or correct skew: keep participants on synchronised clocks (NTP), and pick a
369
409
  `ttl_msec` well above the skew you expect.
410
+ - **A held warp is not cancelled by anybody.** The sender waits for as long as the receiver renews;
411
+ there is no message yet by which the user's "cancel" reaches the receiver.
370
412
  - **Lost messages are not retried.** IPSME gives no delivery guarantee; the expiry is the only hook.
371
413
 
372
414
  ---
@@ -375,10 +417,11 @@ the expiry firing, and a stranger's exchange (not handled, nothing logged).
375
417
 
376
418
  ```sh
377
419
  npm ci
378
- npm run gen # regenerate src/generated from the pinned schema (ifacegenconfig.json)
379
420
  npm run build # rollup -> dist
380
- npm test # jasmine, against dist
421
+ npm test # generates the tests' interface, then jasmine, against dist
381
422
  ```
382
423
 
383
- `src/generated` is committed, so `build` and `test` work without `gen`. When `schema_TwoPhW.json`
384
- changes, re-pin its hash in `ifacegenconfig.json`, run `gen`, and tell consumers the new hash.
424
+ The package ships no interface, so its tests play the host: `npm test` first generates one into
425
+ `tests/generated` from `tests/ifacegenconfig.json` (the generator is a dev dependency, for the tests
426
+ only) and hands it to `protocol_TwoPhW`. When `schema_TwoPhW.json` changes, re-pin its hash in
427
+ `tests/ifacegenconfig.json`; nothing under `src` or `dist` depends on it.