@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
@@ -1,357 +1,13 @@
1
- import { JSON_Eff, JSON_Msg, logr as logr$1, JSON_Ack } from '@rootintf/json-msg';
2
- export { JSON_Ack, JSON_Eff, JSON_Msg } from '@rootintf/json-msg';
3
1
  import { l_merge, l_concat, l_array, lRef, LOGR } from '@knev/bitlogr';
2
+ import { logr as logr$1, JSON_Hold, JSON_Ack } from '@rootintf/json-msg';
3
+ export { JSON_Ack, JSON_Eff, JSON_Msg } from '@rootintf/json-msg';
4
4
  import { logr } from '@rootintf/eventlog';
5
5
 
6
- const _v_JSON_MsgWarp = validate18;
7
- function validate18(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate18.evaluated; if (evaluated0.dynamicProps) {
8
- evaluated0.props = undefined;
9
- } if (evaluated0.dynamicItems) {
10
- evaluated0.items = undefined;
11
- } {
12
- if (data && typeof data == "object" && !Array.isArray(data)) {
13
- let missing0;
14
- if (((data.warp === undefined) && (missing0 = "warp")) || ((data["2PhW"] === undefined) && (missing0 = "2PhW"))) {
15
- validate18.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
16
- return false;
17
- }
18
- else {
19
- if (data.warp !== undefined) {
20
- let data0 = data.warp;
21
- const _errs3 = errors;
22
- {
23
- if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
24
- let missing1;
25
- if (((((data0.id === undefined) && (missing1 = "id")) || ((data0.user === undefined) && (missing1 = "user"))) || ((data0.hyperport === undefined) && (missing1 = "hyperport"))) || ((data0.ttl_msec === undefined) && (missing1 = "ttl_msec"))) {
26
- validate18.errors = [{ instancePath: instancePath + "/warp", schemaPath: "#/properties/warp/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }];
27
- return false;
28
- }
29
- else {
30
- if (data0.id !== undefined) {
31
- const _errs5 = errors;
32
- if (typeof data0.id !== "string") {
33
- validate18.errors = [{ instancePath: instancePath + "/warp/id", schemaPath: "#/properties/warp/properties/id/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
34
- return false;
35
- }
36
- var valid1 = _errs5 === errors;
37
- }
38
- else {
39
- var valid1 = true;
40
- }
41
- if (valid1) {
42
- if (data0.ttl_msec !== undefined) {
43
- let data2 = data0.ttl_msec;
44
- const _errs7 = errors;
45
- if (!(((typeof data2 == "number") && (!(data2 % 1) && !isNaN(data2))) && (isFinite(data2)))) {
46
- validate18.errors = [{ instancePath: instancePath + "/warp/ttl_msec", schemaPath: "#/properties/warp/properties/ttl_msec/type", keyword: "type", params: { type: "integer" }, message: "must be integer" }];
47
- return false;
48
- }
49
- {
50
- if ((typeof data2 == "number") && (isFinite(data2))) {
51
- if (data2 <= 0 || isNaN(data2)) {
52
- validate18.errors = [{ instancePath: instancePath + "/warp/ttl_msec", schemaPath: "#/properties/warp/properties/ttl_msec/exclusiveMinimum", keyword: "exclusiveMinimum", params: { comparison: ">", limit: 0 }, message: "must be > 0" }];
53
- return false;
54
- }
55
- }
56
- }
57
- var valid1 = _errs7 === errors;
58
- }
59
- else {
60
- var valid1 = true;
61
- }
62
- if (valid1) {
63
- if (data0.instantaneous !== undefined) {
64
- const _errs9 = errors;
65
- if (typeof data0.instantaneous !== "boolean") {
66
- validate18.errors = [{ instancePath: instancePath + "/warp/instantaneous", schemaPath: "#/properties/warp/properties/instantaneous/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
67
- return false;
68
- }
69
- var valid1 = _errs9 === errors;
70
- }
71
- else {
72
- var valid1 = true;
73
- }
74
- }
75
- }
76
- }
77
- }
78
- else {
79
- validate18.errors = [{ instancePath: instancePath + "/warp", schemaPath: "#/properties/warp/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
80
- return false;
81
- }
82
- }
83
- var valid0 = _errs3 === errors;
84
- }
85
- else {
86
- var valid0 = true;
87
- }
88
- if (valid0) {
89
- if (data["2PhW"] !== undefined) {
90
- const _errs11 = errors;
91
- if ("2" !== data["2PhW"]) {
92
- validate18.errors = [{ instancePath: instancePath + "/2PhW", schemaPath: "definitions#/definitions/_v/const", keyword: "const", params: { allowedValue: "2" }, message: "must be equal to constant" }];
93
- return false;
94
- }
95
- var valid0 = _errs11 === errors;
96
- }
97
- else {
98
- var valid0 = true;
99
- }
100
- }
101
- }
102
- }
103
- else {
104
- validate18.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
105
- return false;
106
- }
107
- } validate18.errors = vErrors; return errors === 0; }
108
- validate18.evaluated = { "props": { "warp": true, "2PhW": true }, "dynamicProps": false, "dynamicItems": false };
109
- const _v_JSON_AckWarp = validate20;
110
- function validate20(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate20.evaluated; if (evaluated0.dynamicProps) {
111
- evaluated0.props = undefined;
112
- } if (evaluated0.dynamicItems) {
113
- evaluated0.items = undefined;
114
- } if (errors === 0) {
115
- if (data && typeof data == "object" && !Array.isArray(data)) {
116
- let missing0;
117
- if (((data.ack === undefined) && (missing0 = "ack")) || ((data["2PhW"] === undefined) && (missing0 = "2PhW"))) {
118
- validate20.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
119
- return false;
120
- }
121
- else {
122
- if (data._cause !== undefined) {
123
- const _errs3 = errors;
124
- if (!(validate18(data._cause, { instancePath: instancePath + "/_cause", parentData: data, parentDataProperty: "_cause", rootData, dynamicAnchors }))) {
125
- vErrors = vErrors === null ? validate18.errors : vErrors.concat(validate18.errors);
126
- errors = vErrors.length;
127
- }
128
- var valid0 = _errs3 === errors;
129
- }
130
- else {
131
- var valid0 = true;
132
- }
133
- if (valid0) {
134
- if (data.ack !== undefined) {
135
- let data1 = data.ack;
136
- const _errs4 = errors;
137
- if (!(data1 && typeof data1 == "object" && !Array.isArray(data1))) {
138
- validate20.errors = [{ instancePath: instancePath + "/ack", schemaPath: "#/properties/ack/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
139
- return false;
140
- }
141
- var valid0 = _errs4 === errors;
142
- }
143
- else {
144
- var valid0 = true;
145
- }
146
- if (valid0) {
147
- if (data["2PhW"] !== undefined) {
148
- const _errs6 = errors;
149
- if ("2" !== data["2PhW"]) {
150
- validate20.errors = [{ instancePath: instancePath + "/2PhW", schemaPath: "definitions#/definitions/_v/const", keyword: "const", params: { allowedValue: "2" }, message: "must be equal to constant" }];
151
- return false;
152
- }
153
- var valid0 = _errs6 === errors;
154
- }
155
- else {
156
- var valid0 = true;
157
- }
158
- }
159
- }
160
- }
161
- }
162
- else {
163
- validate20.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
164
- return false;
165
- }
166
- } validate20.errors = vErrors; return errors === 0; }
167
- validate20.evaluated = { "props": { "_cause": true, "ack": true, "2PhW": true }, "dynamicProps": false, "dynamicItems": false };
168
- const _v_JSON_EffEngage = validate22;
169
- function validate22(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate22.evaluated; if (evaluated0.dynamicProps) {
170
- evaluated0.props = undefined;
171
- } if (evaluated0.dynamicItems) {
172
- evaluated0.items = undefined;
173
- } if (errors === 0) {
174
- if (data && typeof data == "object" && !Array.isArray(data)) {
175
- let missing0;
176
- if (((data.engage === undefined) && (missing0 = "engage")) || ((data["2PhW"] === undefined) && (missing0 = "2PhW"))) {
177
- validate22.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
178
- return false;
179
- }
180
- else {
181
- if (data._cause !== undefined) {
182
- const _errs3 = errors;
183
- if (!(validate18(data._cause, { instancePath: instancePath + "/_cause", parentData: data, parentDataProperty: "_cause", rootData, dynamicAnchors }))) {
184
- vErrors = vErrors === null ? validate18.errors : vErrors.concat(validate18.errors);
185
- errors = vErrors.length;
186
- }
187
- var valid0 = _errs3 === errors;
188
- }
189
- else {
190
- var valid0 = true;
191
- }
192
- if (valid0) {
193
- if (data.engage !== undefined) {
194
- let data1 = data.engage;
195
- const _errs4 = errors;
196
- if (errors === _errs4) {
197
- if (data1 && typeof data1 == "object" && !Array.isArray(data1)) {
198
- let missing1;
199
- if (((data1.ok === undefined) && (missing1 = "ok")) || ((data1.rtt_msec === undefined) && (missing1 = "rtt_msec"))) {
200
- validate22.errors = [{ instancePath: instancePath + "/engage", schemaPath: "#/properties/engage/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }];
201
- return false;
202
- }
203
- else {
204
- if (data1.ok !== undefined) {
205
- const _errs6 = errors;
206
- if (typeof data1.ok !== "boolean") {
207
- validate22.errors = [{ instancePath: instancePath + "/engage/ok", schemaPath: "#/properties/engage/properties/ok/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
208
- return false;
209
- }
210
- var valid1 = _errs6 === errors;
211
- }
212
- else {
213
- var valid1 = true;
214
- }
215
- if (valid1) {
216
- if (data1.rtt_msec !== undefined) {
217
- let data3 = data1.rtt_msec;
218
- const _errs8 = errors;
219
- if (!(((typeof data3 == "number") && (!(data3 % 1) && !isNaN(data3))) && (isFinite(data3)))) {
220
- validate22.errors = [{ instancePath: instancePath + "/engage/rtt_msec", schemaPath: "#/properties/engage/properties/rtt_msec/type", keyword: "type", params: { type: "integer" }, message: "must be integer" }];
221
- return false;
222
- }
223
- if (errors === _errs8) {
224
- if ((typeof data3 == "number") && (isFinite(data3))) {
225
- if (data3 < 0 || isNaN(data3)) {
226
- validate22.errors = [{ instancePath: instancePath + "/engage/rtt_msec", schemaPath: "#/properties/engage/properties/rtt_msec/minimum", keyword: "minimum", params: { comparison: ">=", limit: 0 }, message: "must be >= 0" }];
227
- return false;
228
- }
229
- }
230
- }
231
- var valid1 = _errs8 === errors;
232
- }
233
- else {
234
- var valid1 = true;
235
- }
236
- }
237
- }
238
- }
239
- else {
240
- validate22.errors = [{ instancePath: instancePath + "/engage", schemaPath: "#/properties/engage/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
241
- return false;
242
- }
243
- }
244
- var valid0 = _errs4 === errors;
245
- }
246
- else {
247
- var valid0 = true;
248
- }
249
- if (valid0) {
250
- if (data["2PhW"] !== undefined) {
251
- const _errs10 = errors;
252
- if ("2" !== data["2PhW"]) {
253
- validate22.errors = [{ instancePath: instancePath + "/2PhW", schemaPath: "definitions#/definitions/_v/const", keyword: "const", params: { allowedValue: "2" }, message: "must be equal to constant" }];
254
- return false;
255
- }
256
- var valid0 = _errs10 === errors;
257
- }
258
- else {
259
- var valid0 = true;
260
- }
261
- }
262
- }
263
- }
264
- }
265
- else {
266
- validate22.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
267
- return false;
268
- }
269
- } validate22.errors = vErrors; return errors === 0; }
270
- validate22.evaluated = { "props": { "_cause": true, "engage": true, "2PhW": true }, "dynamicProps": false, "dynamicItems": false };
271
- const _v_JSON_AckEngage = validate24;
272
- function validate24(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate24.evaluated; if (evaluated0.dynamicProps) {
273
- evaluated0.props = undefined;
274
- } if (evaluated0.dynamicItems) {
275
- evaluated0.items = undefined;
276
- } if (errors === 0) {
277
- if (data && typeof data == "object" && !Array.isArray(data)) {
278
- let missing0;
279
- if (((data.ack === undefined) && (missing0 = "ack")) || ((data["2PhW"] === undefined) && (missing0 = "2PhW"))) {
280
- validate24.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
281
- return false;
282
- }
283
- else {
284
- if (data._cause !== undefined) {
285
- const _errs3 = errors;
286
- if (!(validate22(data._cause, { instancePath: instancePath + "/_cause", parentData: data, parentDataProperty: "_cause", rootData, dynamicAnchors }))) {
287
- vErrors = vErrors === null ? validate22.errors : vErrors.concat(validate22.errors);
288
- errors = vErrors.length;
289
- }
290
- var valid0 = _errs3 === errors;
291
- }
292
- else {
293
- var valid0 = true;
294
- }
295
- if (valid0) {
296
- if (data.ack !== undefined) {
297
- let data1 = data.ack;
298
- const _errs4 = errors;
299
- if (!(data1 && typeof data1 == "object" && !Array.isArray(data1))) {
300
- validate24.errors = [{ instancePath: instancePath + "/ack", schemaPath: "#/properties/ack/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
301
- return false;
302
- }
303
- var valid0 = _errs4 === errors;
304
- }
305
- else {
306
- var valid0 = true;
307
- }
308
- if (valid0) {
309
- if (data["2PhW"] !== undefined) {
310
- const _errs6 = errors;
311
- if ("2" !== data["2PhW"]) {
312
- validate24.errors = [{ instancePath: instancePath + "/2PhW", schemaPath: "definitions#/definitions/_v/const", keyword: "const", params: { allowedValue: "2" }, message: "must be equal to constant" }];
313
- return false;
314
- }
315
- var valid0 = _errs6 === errors;
316
- }
317
- else {
318
- var valid0 = true;
319
- }
320
- }
321
- }
322
- }
323
- }
324
- else {
325
- validate24.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
326
- return false;
327
- }
328
- } validate24.errors = vErrors; return errors === 0; }
329
- validate24.evaluated = { "props": { "_cause": true, "ack": true, "2PhW": true }, "dynamicProps": false, "dynamicItems": false };
330
-
331
- // GENERATED by iface-gen from schema_TwoPhW.json — DO NOT EDIT
332
-
333
- const VERSION = "2";
334
-
335
- const JSON_MsgWarp$1 = {
336
- validate: _v_JSON_MsgWarp,
337
- merge: (body) => JSON_Msg.merge({ "warp": body, "2PhW": VERSION }),
338
- };
339
-
340
- const JSON_AckWarp$1 = {
341
- validate: _v_JSON_AckWarp,
342
- };
343
-
344
- const JSON_EffEngage$1 = {
345
- validate: _v_JSON_EffEngage,
346
- create_with_cause_merge: (cause, body) => JSON_Eff.create_with_cause_merge(cause, { "engage": body, "2PhW": VERSION }),
347
- };
348
-
349
- const JSON_AckEngage$1 = {
350
- validate: _v_JSON_AckEngage,
351
- };
352
-
353
- // The wire interface (validators, constructors, VERSION) is GENERATED by iface-gen from the pinned
354
- // schema_TwoPhW.json (see ifacegenconfig.json; `npm run gen`) -- never hand-written here.
6
+ // The wire interface (validators, constructors, VERSION) is GENERATED by iface-gen from schema_TwoPhW.json
7
+ // -- in the HOST's project, never here. This package has no interface and no schema of its own: the host
8
+ // hands its generated interface to protocol_TwoPhW() (at the bottom of this file), which is what binds
9
+ // the two. So the package and the host cannot disagree about the wire, the version included.
10
+ // import { v4 as uuidv4 } from 'uuid'; // uuid is already a dep of JSON_Msg, so why not
355
11
  // interface Event extends Required<EventMinimal> {
356
12
  // type : string;
357
13
  // id : string | number;
@@ -375,11 +31,13 @@ class Config {
375
31
  _callback_effEngage = null;
376
32
  _callback_ackWarp = null;
377
33
  _callback_ackEngage = null;
34
+ // Optional, and not what makes a hold ours (that is the sender role, _callback_ackWarp): a hold
35
+ // moves the Warp's expiry whether or not anybody wants to be told about it.
36
+ _callback_holdWarp = null;
378
37
  // "a step I sent was never answered inside its window", one per role: the sender's fires for its
379
38
  // Warp / Engage, the receiver's for its AckWarp. A participant playing both roles keeps both.
380
39
  _callback_sender_sent_expired;
381
40
  _callback_receiver_sent_expired;
382
- _callback_msgOptions;
383
41
  constructor() {
384
42
  this._callback_sender_sent_expired = (_msg, _json_msg) => {
385
43
  console.assert(false, '_callback_sender_sent_expired uninitialized');
@@ -387,22 +45,18 @@ class Config {
387
45
  this._callback_receiver_sent_expired = (_msg, _json_msg) => {
388
46
  console.assert(false, '_callback_receiver_sent_expired uninitialized');
389
47
  };
390
- this._callback_msgOptions = () => {
391
- console.assert(false, 'callback_msgOptions uninitialized');
392
- };
393
48
  }
394
49
  receiver(callback_msgWarp, callback_effEngage, callback_msg_sent_expired) {
395
50
  this._callback_msgWarp = callback_msgWarp;
396
51
  this._callback_effEngage = callback_effEngage;
397
52
  this._callback_receiver_sent_expired = callback_msg_sent_expired;
398
53
  }
399
- sender(callback_ackWarp, callback_ackEngage, callback_msg_sent_expired) {
54
+ // callback_holdWarp: the receiver says it is working on our Warp (what it waits for, how far it is)
55
+ sender(callback_ackWarp, callback_ackEngage, callback_msg_sent_expired, callback_holdWarp = null) {
400
56
  this._callback_ackWarp = callback_ackWarp;
401
57
  this._callback_ackEngage = callback_ackEngage;
402
58
  this._callback_sender_sent_expired = callback_msg_sent_expired;
403
- }
404
- set callback_msgOptions(callback) {
405
- this._callback_msgOptions = callback;
59
+ this._callback_holdWarp = callback_holdWarp;
406
60
  }
407
61
  }
408
62
  // var config = (function() {
@@ -417,97 +71,31 @@ class Config {
417
71
  // }
418
72
  // })();
419
73
  //-------------------------------------------------------------------------------------------------
420
- const k_VERSION = VERSION;
421
- // rtt_msec <= ttl_msec *2 => rtt_msec = ttl_msec *2
422
- // t_ttl_rtt_(TTL, RTT) = t_ttl_rtt_(TTL, TTL *2) = TTL *2 + TTL *2 = TTL *4 MAX
423
- function time_ttl_rtt_(ttl_msec, rtt_msec) {
424
- if (ttl_msec === undefined)
425
- return undefined;
426
- if (rtt_msec === undefined)
427
- return ttl_msec * 2;
428
- console.assert(rtt_msec <= ttl_msec * 2, `t_ttl_rtt_: INVALID rtt_msec ttl_msec[${ttl_msec}] rtt_msec[${rtt_msec}]`);
429
- return (ttl_msec * 2) + rtt_msec;
74
+ // Timing. Every step is timed from the message it answers, by that message's own dt; no step looks further
75
+ // back than the message before it. Two durations:
76
+ // - TTL (warp.ttl_msec, set by the sender): the longest a message may take to travel ONE way. Network only.
77
+ // - the lease (hold.ttl_msec of a JSON_HoldWarp, set by the receiver): "my next word comes within this long".
78
+ // Work only.
79
+ // A message that hands the turn over (Warp, AckWarp, Engage) is answered within its dt + TTL*2, there and
80
+ // back. After a hold the next word is due within the hold's dt + its lease + TTL. Of several holds the one
81
+ // that ends latest counts; nothing is added up. The exchange as a whole has no limit: it stays open for as
82
+ // long as leases are renewed.
83
+ // the window in which a message that hands the turn over is answered: TTL there, TTL back
84
+ function window_msec_(nr_ttl_msec) {
85
+ return nr_ttl_msec * 2;
86
+ }
87
+ // Are these the same Warp? The identity of an exchange: the Warp's own dt, its warp.id and its sender.
88
+ function compare_msgWarp_(json_L, json_R) {
89
+ if (json_L.dt !== json_R.dt)
90
+ return false;
91
+ if (json_L.warp.id !== json_R.warp.id)
92
+ return false;
93
+ if (json_L.referer[0] !== json_R.referer[0])
94
+ return false;
95
+ if (json_L.referer[1] !== json_R.referer[1])
96
+ return false;
97
+ return true;
430
98
  }
431
- // not part of the generated interface (no schema yet)
432
- var JSON_MsgOptions = (function () {
433
- return {
434
- create_with_cause_options: function (msg_cause, options) {
435
- return JSON_Eff.create_with_cause_merge(msg_cause, {
436
- options: options,
437
- "2PhW": k_VERSION
438
- });
439
- },
440
- validate: function (json) {
441
- // if (! JSON_Msg_msg.validate(json))
442
- // return false;
443
- // if (! schema_MsgOptions_(json)) {
444
- // logr_.log(l_.VALIDATION, () => ['JSON_MsgOptions: schema_MsgOptions_: ', (schema_MsgOptions_ as any).errors])
445
- // return false;
446
- // }
447
- return true;
448
- }
449
- };
450
- })();
451
- // Each JSON_* below is the generated namespace (validate + merge / create_with_cause_merge; the
452
- // validators are delta-only: the base is validated upstream, in the responder chain) extended with
453
- // what the schema cannot express: the protocol's own constructors.
454
- var JSON_MsgWarp = (function () {
455
- return {
456
- ...JSON_MsgWarp$1,
457
- create_with_id_user_hyperport: function (json_warp_id, json_user, json_hyperport, nr_ttl_msec) {
458
- return JSON_MsgWarp$1.merge({
459
- id: json_warp_id,
460
- user: json_user,
461
- hyperport: json_hyperport,
462
- ttl_msec: nr_ttl_msec
463
- });
464
- },
465
- compare: function (json_L, json_R) {
466
- if (json_L.dt !== json_R.dt)
467
- return false;
468
- if (json_L.warp.id !== json_R.warp.id)
469
- return false;
470
- if (json_L.referer[0] !== json_R.referer[0])
471
- return false;
472
- if (json_L.referer[1] !== json_R.referer[1])
473
- return false;
474
- return true;
475
- }
476
- };
477
- })();
478
- var JSON_EffEngage = (function () {
479
- return {
480
- ...JSON_EffEngage$1,
481
- create_with_Warp: function (json_msgWarp) {
482
- console.assert(json_msgWarp.ack === undefined, "Engage with a Warp, not an Ack");
483
- return JSON_EffEngage$1.create_with_cause_merge(json_msgWarp, {
484
- "ok": true,
485
- "rtt_msec": Date.now() - Date.parse(json_msgWarp.dt)
486
- });
487
- }
488
- };
489
- })();
490
- // iface-gen emits no constructor for a JSON_Ack: build the base ack, stamp the protocol marker
491
- var JSON_AckWarp = (function () {
492
- return {
493
- ...JSON_AckWarp$1,
494
- create_with_Warp_Ok: function (json_msgWarp, b_ok = true) {
495
- const json_ack = JSON_Ack.create_with_cause_Ok(json_msgWarp, b_ok);
496
- json_ack["2PhW"] = k_VERSION;
497
- return json_ack;
498
- }
499
- };
500
- })();
501
- var JSON_AckEngage = (function () {
502
- return {
503
- ...JSON_AckEngage$1,
504
- create_with_Engage_Ok: function (json_effEngage, b_ok = true) {
505
- const json_ack = JSON_Ack.create_with_cause_Ok(json_effEngage, b_ok);
506
- json_ack["2PhW"] = k_VERSION;
507
- return json_ack;
508
- }
509
- };
510
- })();
511
99
  //-------------------------------------------------------------------------------------------------
512
100
  // States
513
101
  class StateState {
@@ -559,11 +147,10 @@ class StateEngage extends StateState {
559
147
  canChangeState(state_new) {
560
148
  if (false === state_new instanceof StateAckEngage)
561
149
  return false;
562
- // The Engage gets to live for THE WARP'S creation time + TTL*2 + RTT
563
- const json_msgWarp = this.json_effEngage._cause;
564
- const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec, this.json_effEngage.engage.rtt_msec);
565
- logr_.log(l_.PROTOCOL_STATE, () => [`StateEngage: evt_AckEngage.dt@${state_new.evt_AckEngage.dt}, msgWarp.dt@${Date.parse(json_msgWarp.dt)} + ${timeout_ms}`]);
566
- if (state_new.evt_AckEngage.dt >= Date.parse(json_msgWarp.dt) + timeout_ms)
150
+ // The AckEngage is accepted until THE ENGAGE'S creation time + TTL*2
151
+ const timeout_ms = window_msec_(this.json_effEngage._cause.warp.ttl_msec);
152
+ logr_.log(l_.PROTOCOL_STATE, () => [`StateEngage: evt_AckEngage.dt@${state_new.evt_AckEngage.dt}, effEngage.dt@${Date.parse(this.json_effEngage.dt)} + ${timeout_ms}`]);
153
+ if (state_new.evt_AckEngage.dt >= Date.parse(this.json_effEngage.dt) + timeout_ms)
567
154
  return false;
568
155
  return true;
569
156
  }
@@ -582,15 +169,9 @@ class StateAckWarp extends StateState {
582
169
  return false;
583
170
  if (!isEngageAwaited_(this.json_ackWarp))
584
171
  return false;
585
- // RTT <= TTL*2: the cap that bounds the whole exchange at TTL*4 (see traverse_State's lookback)
586
- if (state_new.json_effEngage.engage.rtt_msec > this.json_ackWarp._cause.warp.ttl_msec * 2)
587
- return false;
588
- // The Ack gets to live for THE ACK'S creation time + TTL*2 + STT
589
- // +STT, so lines up with the Engage timeout
590
- // - Engage: T0 +2TTL +RTT; RTT= STT+STT
591
- // - AckWarp: TAckWarp +2TLL +STT; TAckWarp= T0 +STT;
592
- // - STT: Date of the Ack minus date of the Warp.
593
- const timeout_ms = time_ttl_rtt_(this.json_ackWarp._cause.warp.ttl_msec) + Date.parse(this.json_ackWarp.dt) - Date.parse(this.json_ackWarp._cause.dt);
172
+ // The Engage is accepted until THE ACK'S creation time + TTL*2. Nothing of phase 1 enters it: how
173
+ // long the receiver took to acknowledge the Warp is not this phase's business.
174
+ const timeout_ms = window_msec_(this.json_ackWarp._cause.warp.ttl_msec);
594
175
  logr_.log(l_.PROTOCOL_STATE, () => [`StateAckWarp: evt_Engage.dt@${state_new.evt_Engage.dt}, msgAckWarp.dt@${Date.parse(this.json_ackWarp.dt)} + ${timeout_ms}`]);
595
176
  if (state_new.evt_Engage.dt >= Date.parse(this.json_ackWarp.dt) + timeout_ms)
596
177
  return false;
@@ -598,16 +179,44 @@ class StateAckWarp extends StateState {
598
179
  }
599
180
  }
600
181
  class StateWarp extends StateState {
182
+ // where the latest lease of a JSON_HoldWarp moved the end of the window to (epoch msec), and the event
183
+ // whose timer now guards it. null: no hold moved it.
184
+ _nr_deadline_lease = null;
185
+ _idx_event_timer = null;
601
186
  constructor(idx_event, event) { super(idx_event, event); }
602
187
  get evt_Warp() { return this.event; }
603
188
  get json_msgWarp() { return this.json_msg; }
189
+ // Where a JSON_HoldWarp puts the end of the window: its OWN dt + its lease (hold.ttl_msec) + the
190
+ // warp's TTL (one for the next message to travel). NaN when its dt does not read: a lease with no anchor.
191
+ static deadline_holdWarp(json_holdWarp) {
192
+ const nr_lease = JSON_Hold.lease_epoch_msec(json_holdWarp);
193
+ return (nr_lease === null) ? NaN : nr_lease + json_holdWarp._cause.warp.ttl_msec;
194
+ }
195
+ // The last instant the JSON_AckWarp is accepted: THE WARP'S creation time + TTL*2, or where a hold
196
+ // moved it, whichever is later. The latest counts; nothing is added up.
197
+ get deadline_msec() {
198
+ const nr_deadline = Date.parse(this.json_msgWarp.dt) + window_msec_(this.json_msgWarp.warp.ttl_msec);
199
+ return (this._nr_deadline_lease !== null && this._nr_deadline_lease > nr_deadline) ? this._nr_deadline_lease : nr_deadline;
200
+ }
201
+ // the event that holds this Warp's expiry timer: the Warp's own, or the hold that last moved the window
202
+ get idx_event_timer() {
203
+ return (this._idx_event_timer !== null) ? this._idx_event_timer : this.idx_event;
204
+ }
205
+ // A hold on this Warp, logged as event idx_event. Returns whether it moved the end of the window:
206
+ // not when its lease ends no later than the window in force, nor when its dt does not read.
207
+ lease(idx_event, json_holdWarp) {
208
+ const nr_deadline = StateWarp.deadline_holdWarp(json_holdWarp);
209
+ if (!(nr_deadline > this.deadline_msec))
210
+ return false;
211
+ this._nr_deadline_lease = nr_deadline;
212
+ this._idx_event_timer = idx_event;
213
+ return true;
214
+ }
604
215
  canChangeState(state_new) {
605
216
  if (false === state_new instanceof StateAckWarp)
606
217
  return false;
607
- // The Warp gets to live for THE WARP'S creation time + TTL*2
608
- const timeout_ms = time_ttl_rtt_(this.json_msgWarp.warp.ttl_msec);
609
- logr_.log(l_.PROTOCOL_STATE, () => [`StateWarp: evt_AckWarp.dt@${state_new.evt_AckWarp.dt}, msgWarp.dt@${Date.parse(this.json_msgWarp.dt)} + ${timeout_ms}`]);
610
- if (state_new.evt_AckWarp.dt >= Date.parse(this.json_msgWarp.dt) + timeout_ms)
218
+ logr_.log(l_.PROTOCOL_STATE, () => [`StateWarp: evt_AckWarp.dt@${state_new.evt_AckWarp.dt}, deadline@${this.deadline_msec}`]);
219
+ if (state_new.evt_AckWarp.dt >= this.deadline_msec)
611
220
  return false;
612
221
  return true;
613
222
  }
@@ -651,6 +260,12 @@ class ProtocolStateState {
651
260
  return this._state;
652
261
  }
653
262
  canChangeState(state_new) {
263
+ // Every window is measured from a message's own dt, and the schema only asks dt to be a string.
264
+ // A step whose dt does not read as a time has no window to be inside of: never legal. (Unchecked,
265
+ // it parses to NaN, every "is it past the deadline?" answers no, and it escapes all the windows.)
266
+ // Every logged step passed here, so the states can rely on the dt of the messages they wrap.
267
+ if (!Number.isFinite(Date.parse(state_new.json_msg.dt)))
268
+ return false;
654
269
  // An exchange is a dialogue: a step we RECEIVE is only legal after a step we SENT, and vice
655
270
  // versa. Every participant on the ME hears every exchange, so without this a warp we merely
656
271
  // heard would be "answered" by the ack its real receiver sent, and we could answer our own step.
@@ -661,6 +276,7 @@ class ProtocolStateState {
661
276
  }
662
277
  //-------------------------------------------------------------------------------------------------
663
278
  const kstr_EVT_DROPPED_ = '2PhW[DROPPED!]';
279
+ const kstr_EVT_HOLDWARP_ = '2PhW[JSON_HoldWarp]';
664
280
  class TwoPhW_EventLog {
665
281
  _eventLog;
666
282
  constructor(eventLog) {
@@ -668,10 +284,11 @@ class TwoPhW_EventLog {
668
284
  }
669
285
  _warp(json_msg) {
670
286
  const b_Ack = json_msg.ack !== undefined;
671
- const json = b_Ack ? json_msg["_cause"] : json_msg;
287
+ const b_Hold = !b_Ack && json_msg.hold !== undefined; // a message that carries both is an ack
288
+ const json = (b_Ack || b_Hold) ? json_msg["_cause"] : json_msg;
672
289
  if (json.warp) {
673
290
  return {
674
- str_type: b_Ack ? '2PhW[JSON_AckWarp]' : '2PhW[JSON_MsgWarp]',
291
+ str_type: b_Ack ? '2PhW[JSON_AckWarp]' : (b_Hold ? kstr_EVT_HOLDWARP_ : '2PhW[JSON_MsgWarp]'),
675
292
  json_msgWarp: json
676
293
  };
677
294
  }
@@ -703,10 +320,12 @@ class TwoPhW_EventLog {
703
320
  }
704
321
  traverse_State(json_msgWarp) {
705
322
  const protocolState = new ProtocolStateState();
706
- // Look back over the WHOLE exchange. Its longest window is the Warp's dt + TTL*2 + RTT (the
707
- // AckEngage), and RTT <= TTL*2 (StateAckWarp refuses an Engage that claims more), so no step is
708
- // legal more than TTL*4 after the Warp: the oldest event is never older than that.
709
- const lookback_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec, json_msgWarp.warp.ttl_msec * 2);
323
+ // Look back over the WHOLE exchange: to the Warp's own dt (+ TTL*2: a participant logs by its own
324
+ // clock). An exchange has no limit as a whole (holds keep it open for as long as they are renewed), so
325
+ // its age says nothing; whether it is still open is decided by its windows. A Warp whose dt does not
326
+ // read has no exchange to look back over, and is refused by every caller.
327
+ const nr_age_msec = Date.now() - Date.parse(json_msgWarp.dt);
328
+ const lookback_ms = window_msec_(json_msgWarp.warp.ttl_msec) + (Number.isFinite(nr_age_msec) ? Math.max(nr_age_msec, 0) : 0);
710
329
  const arr_evts = this._eventLog.get_Events_by_id(json_msgWarp.warp.id, lookback_ms);
711
330
  logr_.log(l_.EVENTS, () => ['traverse_State: arr_evts: ', arr_evts]);
712
331
  for (let i = arr_evts.length - 1; i >= 0; i--) {
@@ -716,12 +335,17 @@ class TwoPhW_EventLog {
716
335
  if (evt.type === kstr_EVT_DROPPED_)
717
336
  continue;
718
337
  const json_msg = evt.data.json_msg;
719
- if (!JSON_MsgWarp.compare(json_msgWarp, this._warp(json_msg).json_msgWarp))
338
+ if (!compare_msgWarp_(json_msgWarp, this._warp(json_msg).json_msgWarp))
720
339
  protocolState.state.changeState(new StateINVALID(idx, evt));
721
340
  switch (evt.type) {
722
341
  case '2PhW[JSON_MsgWarp]':
723
342
  protocolState.state.changeState(new StateWarp(idx, evt));
724
343
  break;
344
+ case kstr_EVT_HOLDWARP_:
345
+ // not a step: it changes no state, it moves the window of the Warp it is about
346
+ if (protocolState.state instanceof StateWarp)
347
+ protocolState.state.lease(idx, json_msg);
348
+ break;
725
349
  case '2PhW[JSON_AckWarp]':
726
350
  protocolState.state.changeState(new StateAckWarp(idx, evt));
727
351
  break;
@@ -755,37 +379,6 @@ class TwoPhW {
755
379
  return this._2PhW_eventLog;
756
380
  }
757
381
  //-------------------------------------------------------------------------------------------------
758
- _handler_msgOptions(cfg, msg, json_msgOptions) {
759
- logr_.log(l_.HANDLERS, () => ['handler_msgOptions_: ...']);
760
- /*
761
- if (! validate_Options_delay_(json_msgOptions.options))
762
- return false;
763
-
764
- if (JSON_MsgWarp.validate(json_msgOptions._cause)) {
765
- const json_msgWarp= json_msgOptions._cause;
766
-
767
- const ctx= get_ctx(json_msgWarp.id);
768
- if (!ctx )
769
- return false;
770
-
771
- const ttl_msec= json_msgOptions.options.ttl_msec_incr[0];
772
- const ttl_incr= json_msgOptions.options.ttl_msec_incr[1];
773
-
774
- //TODO: double check ttl_msec is the same as current accummulated ttl for idempotence.
775
-
776
- logr_.log(l_.HANDLERS, () => ['handler_msgOptions_: ', json_msgOptions]);
777
-
778
- ctx.protocol.delayTimeout(ttl_incr);
779
-
780
- if (cfg._callback_msgOptions)
781
- return cfg._callback_msgOptions(msg, json_msgOptions);
782
-
783
- return true;
784
- }
785
- */
786
- return false;
787
- }
788
- //-------------------------------------------------------------------------------------------------
789
382
  // The typed handlers (handler_json_<message>) are what the responder's base dispatch calls AFTER it
790
383
  // validated the message as that type (generated: `JSON_AckWarp.validate(json_ack) &&
791
384
  // this.handler_json_ackWarp(msg, json_ack)`). They do not validate again.
@@ -801,7 +394,8 @@ class TwoPhW {
801
394
  logr_.log(l_.HANDLERS | l_.SENDER, () => ['register_msgWarp: protocolState.canChangeState ', b_changeState]);
802
395
  if (!b_changeState)
803
396
  return false;
804
- const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec);
397
+ // the first answer, a hold or the ack, is due within the Warp's dt + TTL*2
398
+ const timeout_ms = window_msec_(json_msgWarp.warp.ttl_msec);
805
399
  const elapsed_ms = Date.now() - Date.parse(json_msgWarp.dt);
806
400
  this.eventLog._addEvent(msg, json_msgWarp, true, timeout_ms - elapsed_ms, () => {
807
401
  this.config._callback_sender_sent_expired(msg, json_msgWarp);
@@ -822,10 +416,44 @@ class TwoPhW {
822
416
  logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_json_ackWarp: protocolState.canChangeState ', b_changeState]);
823
417
  if (!b_changeState)
824
418
  return false;
825
- this.eventLog._cancelTimeout(protocolState.state.idx_event);
419
+ // the Warp's own timer, or the one of the hold that last moved its window
420
+ this.eventLog._cancelTimeout(protocolState.state.idx_event_timer);
826
421
  this.eventLog._addEvent(msg, json_ackWarp, false);
827
422
  return this.config._callback_ackWarp(msg, json_ackWarp);
828
423
  }
424
+ // The receiver says it is working on a Warp we sent and has not decided yet (JSON_HoldWarp). Not a step:
425
+ // the exchange stays where it is, waiting for the JSON_AckWarp. What changes is how long we wait for it:
426
+ // the expiry of the Warp moves to the end of the hold's lease.
427
+ handler_json_holdWarp(msg, json_holdWarp) {
428
+ logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_json_holdWarp: ', json_holdWarp]);
429
+ // the sender role is not played here: not ours -- before anything is logged
430
+ if (!this.config._callback_ackWarp)
431
+ return false;
432
+ const json_msgWarp = json_holdWarp._cause;
433
+ // ours iff it is about a Warp WE sent that is still unanswered and still inside its window. Anything
434
+ // else (a Warp we only heard, one already acknowledged or expired) is somebody else's, or too late.
435
+ const state = this.eventLog.traverse_State(json_msgWarp).state;
436
+ if (!(state instanceof StateWarp) || !state.event.data.b_sent)
437
+ return false;
438
+ const nr_now = Date.now();
439
+ if (nr_now >= state.deadline_msec)
440
+ return false;
441
+ const nr_deadline = StateWarp.deadline_holdWarp(json_holdWarp);
442
+ if (!Number.isFinite(nr_deadline))
443
+ return false; // a dt that does not read: a lease with no anchor
444
+ if (nr_deadline > state.deadline_msec) {
445
+ // the timer follows the window: the one in force is cancelled, this hold carries the new one.
446
+ // What expires is still the Warp: "the step I sent was never answered".
447
+ const { msg: msg_Warp, json_msg: json_msgWarp_sent } = state.event.data;
448
+ this.eventLog._cancelTimeout(state.idx_event_timer);
449
+ this.eventLog._addEvent(msg, json_holdWarp, false, nr_deadline - nr_now, () => {
450
+ this.config._callback_sender_sent_expired(msg_Warp, json_msgWarp_sent);
451
+ });
452
+ }
453
+ else
454
+ this.eventLog._addEvent(msg, json_holdWarp, false); // ends inside the window in force: logged, nothing moves
455
+ return this.config._callback_holdWarp ? this.config._callback_holdWarp(msg, json_holdWarp) : true;
456
+ }
829
457
  register_effEngage(msg, json_effEngage) {
830
458
  logr_.log(l_.SENDER, () => ['register_effEngage: ', json_effEngage]);
831
459
  const json_msgWarp = json_effEngage._cause;
@@ -837,8 +465,9 @@ class TwoPhW {
837
465
  logr_.log(l_.HANDLERS | l_.SENDER, () => ['register_effEngage: protocolState.canChangeState ', b_changeState]);
838
466
  if (!b_changeState)
839
467
  return false;
840
- const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec, json_effEngage.engage.rtt_msec);
841
- const elapsed_ms = Date.now() - Date.parse(json_msgWarp.dt);
468
+ // the AckEngage is due within the Engage's own dt + TTL*2
469
+ const timeout_ms = window_msec_(json_msgWarp.warp.ttl_msec);
470
+ const elapsed_ms = Date.now() - Date.parse(json_effEngage.dt);
842
471
  this.eventLog._addEvent(msg, json_effEngage, true, timeout_ms - elapsed_ms, () => {
843
472
  this.config._callback_sender_sent_expired(msg, json_effEngage);
844
473
  });
@@ -880,6 +509,23 @@ class TwoPhW {
880
509
  this.eventLog._addEvent(msg, json_msgWarp, false);
881
510
  return this.config._callback_msgWarp(msg, json_msgWarp);
882
511
  }
512
+ // Register a JSON_HoldWarp we are about to publish: "this Warp is being worked on, wait for the ack until
513
+ // my lease ends". Legal only for a Warp we RECEIVED, have not answered, and whose window is still open
514
+ // (a window that has closed cannot be reopened). It is what lets register_ackWarp succeed later than the
515
+ // Warp's own dt + TTL*2. Returns true, or false when it is not legal now: then do not publish it.
516
+ register_holdWarp(msg, json_holdWarp) {
517
+ logr_.log(l_.RECVER, () => ['register_holdWarp: ', json_holdWarp]);
518
+ const json_msgWarp = json_holdWarp._cause;
519
+ const state = this.eventLog.traverse_State(json_msgWarp).state;
520
+ if (!(state instanceof StateWarp) || state.event.data.b_sent)
521
+ return false;
522
+ if (Date.now() >= state.deadline_msec)
523
+ return false;
524
+ if (!Number.isFinite(StateWarp.deadline_holdWarp(json_holdWarp)))
525
+ return false;
526
+ this.eventLog._addEvent(msg, json_holdWarp, true);
527
+ return true;
528
+ }
883
529
  register_ackWarp(msg, json_ackWarp) {
884
530
  logr_.log(l_.RECVER, () => ['register_ackWarp: ', json_ackWarp]);
885
531
  const json_msgWarp = json_ackWarp._cause;
@@ -897,8 +543,9 @@ class TwoPhW {
897
543
  this.eventLog._addEvent(msg, json_ackWarp, true);
898
544
  return true;
899
545
  }
546
+ // the Engage is due within the ack's own dt + TTL*2
900
547
  const elapsed_ms = Date.now() - Date.parse(json_ackWarp.dt);
901
- const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec) + Date.parse(json_ackWarp.dt) - Date.parse(json_msgWarp.dt);
548
+ const timeout_ms = window_msec_(json_msgWarp.warp.ttl_msec);
902
549
  this.eventLog._addEvent(msg, json_ackWarp, true, timeout_ms - elapsed_ms, () => {
903
550
  this.config._callback_receiver_sent_expired(msg, json_ackWarp);
904
551
  });
@@ -937,5 +584,80 @@ class TwoPhW {
937
584
  return true;
938
585
  }
939
586
  }
587
+ // Bind the protocol to the HOST's generated interface. Called once, where the responder is set up:
588
+ //
589
+ // import * as iface_TwoPhW from '../generated/iface-TwoPhW';
590
+ // const { TwoPhW, JSON_MsgWarp, JSON_EffEngage, JSON_AckWarp, JSON_HoldWarp, JSON_AckEngage } = protocol_TwoPhW(iface_TwoPhW);
591
+ //
592
+ // Returns the state machine and, per message, the generated namespace (validate + merge /
593
+ // create_with_cause_merge; the validators are delta-only: the base is validated upstream, in the
594
+ // responder chain) extended with what the schema cannot express: the protocol's own constructors.
595
+ // Whatever is built through them carries the interface's own VERSION, so the package cannot speak
596
+ // another version of 2PhW than its host validates.
597
+ function protocol_TwoPhW(iface_TwoPhW) {
598
+ // What was handed in is the host's to get right: a wrong import (the module's default export, another
599
+ // interface) must fail here, where it is made, not as an undefined deep inside an exchange.
600
+ const arr_str_missing = [
601
+ ['VERSION', typeof iface_TwoPhW?.VERSION === 'string'],
602
+ ['JSON_MsgWarp.validate', typeof iface_TwoPhW?.JSON_MsgWarp?.validate === 'function'],
603
+ ['JSON_MsgWarp.merge', typeof iface_TwoPhW?.JSON_MsgWarp?.merge === 'function'],
604
+ ['JSON_AckWarp.validate', typeof iface_TwoPhW?.JSON_AckWarp?.validate === 'function'],
605
+ ['JSON_HoldWarp.validate', typeof iface_TwoPhW?.JSON_HoldWarp?.validate === 'function'],
606
+ ['JSON_HoldWarp.create_with_cause_ttl', typeof iface_TwoPhW?.JSON_HoldWarp?.create_with_cause_ttl === 'function'],
607
+ ['JSON_EffEngage.validate', typeof iface_TwoPhW?.JSON_EffEngage?.validate === 'function'],
608
+ ['JSON_EffEngage.create_with_cause_merge', typeof iface_TwoPhW?.JSON_EffEngage?.create_with_cause_merge === 'function'],
609
+ ['JSON_AckEngage.validate', typeof iface_TwoPhW?.JSON_AckEngage?.validate === 'function']
610
+ ].filter(([_str_member, b_present]) => !b_present).map(([str_member]) => str_member);
611
+ if (arr_str_missing.length)
612
+ throw new Error(`protocol_TwoPhW: not a generated 2PhW interface, it lacks: ${arr_str_missing.join(', ')}`);
613
+ const k_VERSION = iface_TwoPhW.VERSION;
614
+ const JSON_MsgWarp = {
615
+ ...iface_TwoPhW.JSON_MsgWarp,
616
+ create_with_id_user_hyperport: function (json_warp_id, json_user, json_hyperport, nr_ttl_msec) {
617
+ return iface_TwoPhW.JSON_MsgWarp.merge({
618
+ id: json_warp_id,
619
+ user: json_user,
620
+ hyperport: json_hyperport,
621
+ ttl_msec: nr_ttl_msec
622
+ });
623
+ },
624
+ compare: compare_msgWarp_
625
+ };
626
+ const JSON_EffEngage = {
627
+ ...iface_TwoPhW.JSON_EffEngage,
628
+ create_with_Warp: function (json_msgWarp) {
629
+ console.assert(json_msgWarp.ack === undefined, "Engage with a Warp, not an Ack");
630
+ return iface_TwoPhW.JSON_EffEngage.create_with_cause_merge(json_msgWarp, {
631
+ "ok": true
632
+ });
633
+ }
634
+ };
635
+ // iface-gen emits no constructor for a JSON_Ack: build the base ack, stamp the protocol marker
636
+ const JSON_AckWarp = {
637
+ ...iface_TwoPhW.JSON_AckWarp,
638
+ create_with_Warp_Ok: function (json_msgWarp, b_ok = true) {
639
+ const json_ack = JSON_Ack.create_with_cause_Ok(json_msgWarp, b_ok);
640
+ json_ack["2PhW"] = k_VERSION;
641
+ return json_ack;
642
+ }
643
+ };
644
+ const JSON_AckEngage = {
645
+ ...iface_TwoPhW.JSON_AckEngage,
646
+ create_with_Engage_Ok: function (json_effEngage, b_ok = true) {
647
+ const json_ack = JSON_Ack.create_with_cause_Ok(json_effEngage, b_ok);
648
+ json_ack["2PhW"] = k_VERSION;
649
+ return json_ack;
650
+ }
651
+ };
652
+ return {
653
+ TwoPhW,
654
+ VERSION: k_VERSION,
655
+ JSON_MsgWarp,
656
+ JSON_EffEngage,
657
+ JSON_AckWarp,
658
+ JSON_HoldWarp: iface_TwoPhW.JSON_HoldWarp, // as generated: its constructor is built from the lease already
659
+ JSON_AckEngage
660
+ };
661
+ }
940
662
 
941
- export { JSON_AckEngage, JSON_AckWarp, JSON_EffEngage, JSON_MsgOptions, JSON_MsgWarp, StateAckEngage, StateAckWarp, StateEngage, StateINVALID, StateInitialState, StateWarp, TwoPhW, k_VERSION as VERSION, logr_ as logr, time_ttl_rtt_ as t_ttl_rtt };
663
+ export { StateAckEngage, StateAckWarp, StateEngage, StateINVALID, StateInitialState, StateWarp, logr_ as logr, protocol_TwoPhW, window_msec_ as window_msec };