@rootintf/protocol-2phw 2.3.4-api.2 → 3.0.13-api.2

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 (40) hide show
  1. package/README.md +384 -1
  2. package/dist/generated/iface-TwoPhW/index.d.mts +25 -0
  3. package/dist/generated/iface-TwoPhW/validate.d.cts +76 -0
  4. package/dist/generated/iface-TwoPhW/validate.d.mts +75 -0
  5. package/dist/twoPhW.cjs.js +419 -974
  6. package/dist/twoPhW.d.ts +51 -36
  7. package/dist/twoPhW.es.mjs +403 -970
  8. package/package.json +31 -17
  9. package/src/generated/.gitattributes +4 -0
  10. package/src/generated/iface-TwoPhW/index.cjs +26 -0
  11. package/src/generated/iface-TwoPhW/index.d.cts +25 -0
  12. package/src/generated/iface-TwoPhW/index.d.mts +25 -0
  13. package/src/generated/iface-TwoPhW/index.d.ts +25 -0
  14. package/src/generated/iface-TwoPhW/index.mjs +23 -0
  15. package/src/generated/iface-TwoPhW/package.json +36 -0
  16. package/src/generated/iface-TwoPhW/schema/schema_TwoPhW.json +131 -0
  17. package/src/generated/iface-TwoPhW/validate.cjs +1 -0
  18. package/src/generated/iface-TwoPhW/validate.mjs +1 -0
  19. package/src/generated/iface-introspection/index.cjs +13 -0
  20. package/src/generated/iface-introspection/index.d.cts +6 -0
  21. package/src/generated/iface-introspection/index.d.mts +6 -0
  22. package/src/generated/iface-introspection/index.d.ts +6 -0
  23. package/src/generated/iface-introspection/index.mjs +10 -0
  24. package/src/generated/iface-introspection/package.json +30 -0
  25. package/src/schema-cache/.gitattributes +4 -0
  26. package/src/schema-cache/5fdbd096ad99962b7e3d77cde8bd355fe180c859f35a61cfd07ee36b96c6700a.json +131 -0
  27. package/src/twoPhW.ts +770 -833
  28. package/.claude/scheduled_tasks.lock +0 -1
  29. package/antora-docs/antora.yml +0 -2
  30. package/antora-docs/modules/npm/pages/index.adoc +0 -7
  31. package/dev.txt +0 -23
  32. package/dist/ajv-gen-validate.d.cts +0 -1
  33. package/dist/validate-esm.d.mts +0 -48
  34. package/jasmine.json +0 -7
  35. package/rollup.config.mjs +0 -40
  36. package/schema/schema_2PhW.json +0 -61
  37. package/src/ajv-gen-validate.cjs +0 -40
  38. package/src/validate-esm.mjs +0 -1
  39. package/tests/twoPhW-new.spec.mjs +0 -850
  40. package/tsconfig.json +0 -115
package/src/twoPhW.ts CHANGED
@@ -1,833 +1,770 @@
1
-
2
- import {
3
- definitions_2PhW as definitions_2PhW_,
4
- schema_MsgWarp as schema_MsgWarp_,
5
- schema_MsgEngage as schema_MsgEngage_,
6
- // schema_MsgOptions as schema_MsgOptions_,
7
- // schema_Options_delay as schema_Options_delay_,
8
- } from './validate-esm.mjs';
9
-
10
- // import { v4 as uuidv4 } from 'uuid'; // uuid is already a dep of JSON_Msg, so why not
11
- import { LOGR, lRef, l_merge, l_array, l_concat, l_LL } from '@knev/bitlogr';
12
- import { JSON_Msg, JSON_MsgEffect, JSON_MsgAck, logr as logr_json_msg_ } from '@rootintf/json-msg'
13
-
14
- import { EventLog, logr as logr_evtlog_ } from '@rootintf/eventlog'
15
-
16
- type t_msg = string;
17
-
18
- interface EventMinimal {
19
- dt : number;
20
- data : { msg : t_msg, json_msg };
21
- }
22
-
23
- // interface Event extends Required<EventMinimal> {
24
- // type : string;
25
- // id : string | number;
26
- // timeout_id : NodeJS.Timeout | null;
27
- // };
28
-
29
- const k_TTL= 20000;
30
-
31
- //-------------------------------------------------------------------------------------------------
32
-
33
- const obj_labels_merge_= l_merge(logr_evtlog_.lref.get(), logr_json_msg_.lref.get()); // VALIDATION : 4
34
- const obj_labels_concat_= l_concat(obj_labels_merge_, l_array(['HANDLERS', 'DROPS', 'PROTOCOL_STATE', 'RECVER', 'SENDER']) );
35
-
36
- const lref_= lRef(obj_labels_concat_);
37
- logr_json_msg_.lref= lref_;
38
- logr_evtlog_.lref= lref_;
39
-
40
- const LOGR_= LOGR.get_instance();
41
- const logr_= LOGR_.create(); // don't let create() make a new ref, assign lref_ from here
42
- logr_.lref= lref_;
43
-
44
- const l_= logr_.l;
45
-
46
- //-------------------------------------------------------------------------------------------------
47
-
48
- type t_callback = (msg : t_msg, json_msg) => boolean;
49
- type t_callback_void = (msg : t_msg, json_msg) => void;
50
-
51
- class Config {
52
- public _callback_msgWarp : t_callback
53
- public _callback_msgEngage : t_callback
54
- public _callback_msgAckWarp : t_callback
55
- public _callback_msgAckEngage : t_callback
56
- public _callback_msg_sent_expired : t_callback_void
57
- public _callback_msgOptions: () => void;
58
-
59
- constructor() {
60
- // Initialize callbacks as no-op functions
61
- this._callback_msgWarp = (_msg : t_msg, _json_msg) => {
62
- console.assert(false, 'callback_msgWarp uninitialized'); return false;
63
- };
64
- this._callback_msgEngage = (_msg : t_msg, _json_msg) => {
65
- console.assert(false, 'callback_msgEngage uninitialized'); return false;
66
- };
67
- this._callback_msgAckWarp = (_msg : t_msg, _json_msg) => {
68
- console.assert(false, 'callback_msgAckWarp uninitialized'); return false;
69
- };
70
- this._callback_msgAckEngage = (_msg : t_msg, _json_msg) => {
71
- console.assert(false, 'callback_msgAckEngage uninitialized'); return false;
72
- };
73
- this._callback_msg_sent_expired = (_msg : t_msg, _json_msg) => {
74
- console.assert(false, '_callback_msg_sent_expired uninitialized');
75
- };
76
- this._callback_msgOptions = () => {
77
- console.assert(false, 'callback_msgOptions uninitialized');
78
- };
79
- }
80
-
81
- receiver(callback_msgWarp : t_callback, callback_msgEngage : t_callback, callback_msg_sent_expired : t_callback_void) {
82
- this._callback_msgWarp= callback_msgWarp;
83
- this._callback_msgEngage= callback_msgEngage;
84
- this._callback_msg_sent_expired= callback_msg_sent_expired;
85
- }
86
- sender(callback_msgAckWarp : t_callback, callback_msgAckEngage : t_callback, callback_msg_sent_expired : t_callback_void ) {
87
- this._callback_msgAckWarp= callback_msgAckWarp;
88
- this._callback_msgAckEngage= callback_msgAckEngage;
89
- this._callback_msg_sent_expired= callback_msg_sent_expired;
90
- }
91
-
92
- set callback_msgOptions(callback) {
93
- this._callback_msgOptions= callback;
94
- }
95
- }
96
-
97
- // var config = (function() {
98
- // let _options;
99
-
100
- // return {
101
- // get callback_Abort() { return _options.callback_Abort; },
102
-
103
- // set options(obj) {
104
- // _options= obj;
105
- // if (_options.logr) // && options_.logr[ __name(l_) ] )
106
- // LOGR_.toggled= _options.logr
107
- // }
108
- // }
109
- // })();
110
-
111
- //-------------------------------------------------------------------------------------------------
112
-
113
- let k_VERSION= "2";
114
-
115
- // rtt_msec <= ttl_msec *2 => rtt_msec = ttl_msec *2
116
- // t_ttl_rtt_(TTL, RTT) = t_ttl_rtt_(TTL, TTL *2) = TTL *2 + TTL *2 = TTL *4 MAX
117
-
118
- function time_ttl_rtt_(ttl_msec: number | undefined, rtt_msec?: number): number | undefined {
119
- if (ttl_msec === undefined)
120
- return undefined;
121
- if (rtt_msec === undefined)
122
- return ttl_msec *2;
123
-
124
- console.assert(rtt_msec <= ttl_msec *2, `t_ttl_rtt_: INVALID rtt_msec ttl_msec[${ttl_msec}] rtt_msec[${rtt_msec}]`)
125
- return (ttl_msec *2) + rtt_msec;
126
- }
127
-
128
- var JSON_MsgOptions = (function() {
129
- return {
130
- create_with_cause_options : function(msg_cause, options) {
131
- return JSON_MsgEffect.create_with_msg_merge(msg_cause, {
132
- options: options,
133
- "2PhW": k_VERSION
134
- });
135
- },
136
- validate : function(json) {
137
- // if (! JSON_Msg_msg.validate(json))
138
- // return false;
139
- // if (! schema_MsgOptions_(json)) {
140
- // logr_.log(l_.VALIDATION, () => ['JSON_MsgOptions: schema_MsgOptions_: ', (schema_MsgOptions_ as any).errors])
141
- // return false;
142
- // }
143
- return true;
144
- }
145
- }
146
- })();
147
-
148
- var JSON_MsgWarp = (function() {
149
- return {
150
- create_with_id_user_hyperport : function(json_warp_id, json_user, json_hyperport, nr_ttl_msec) {
151
- return JSON_Msg.merge({
152
- warp : {
153
- id : json_warp_id,
154
- user : json_user,
155
- hyperport : json_hyperport,
156
- ttl_msec : nr_ttl_msec
157
- },
158
- "2PhW": k_VERSION
159
- });
160
- },
161
- compare : function(json_L, json_R) {
162
- if (json_L.dt !== json_R.dt)
163
- return false;
164
- if (json_L.warp.id !== json_R.warp.id)
165
- return false;
166
- if (json_L.referer[0] !== json_R.referer[0])
167
- return false;
168
- if (json_L.referer[1] !== json_R.referer[1])
169
- return false;
170
- return true;
171
- },
172
- validate : function(json_msg) {
173
- // if (! JSON_Msg.validate(json))
174
- // return false;
175
- if (! schema_MsgWarp_(json_msg)) {
176
- logr_.log(l_.VALIDATION, () => ['JSON_MsgWarp: schema_MsgWarp_: ', (schema_MsgWarp_ as any).errors])
177
- return false;
178
- }
179
- return true;
180
- }
181
- }
182
- })();
183
-
184
- var JSON_MsgEngage = (function() {
185
- return {
186
- create_with_Warp : function(json_msgWarp) {
187
- console.assert(json_msgWarp.ack === undefined, "Engage with a Warp, not an Ack");
188
- return JSON_MsgEffect.create_with_cause_merge(json_msgWarp, {
189
- engage : {
190
- "ok" : true,
191
- "rtt_msec" : Date.now() - Date.parse(json_msgWarp.dt)
192
- },
193
- "2PhW": k_VERSION
194
- });
195
- },
196
- validate : function(json_msgEffect) {
197
- // if (! JSON_Msg_msg.validate(json))
198
- // return false;
199
- if (! JSON_MsgWarp.validate(json_msgEffect._cause))
200
- return false;
201
- if (! schema_MsgEngage_(json_msgEffect)) {
202
- logr_.log(l_.VALIDATION, () => ['JSON_MsgEngage: schema_MsgEngage_: ', (schema_MsgEngage_ as any).errors])
203
- return false;
204
- }
205
- return true;
206
- }
207
- };
208
- })();
209
-
210
- var JSON_MsgAckWarp = (function() {
211
- return {
212
- // createWith_msgAck_msg : function(json_msgAck, _msg) {
213
- // const json_msgAckWarp= structuredClone(json_msgAck);
214
- // json_msgAckWarp._cause= _cause;
215
- // return json_msgAckWarp;
216
- // }
217
- create_with_Warp_Ok : function(json_msgWarp, b_ok= true) {
218
- const json_msgAck= JSON_MsgAck.create_with_cause_Ok(json_msgWarp, b_ok);
219
- json_msgAck["2PhW"]= k_VERSION;
220
- return json_msgAck;
221
- },
222
- // create_with_msgExpired : function( json_msgWarp ) {
223
- // const json_msgAck_msg= JSON_MsgAck_msg.create_with_msgExpired( json_msgWarp )
224
- // json_msgAck_msg["2PhW"]= k_VERSION;
225
- // return json_msgAck_msg;
226
- // },
227
- validate : function(json_msgAck) {
228
- // if (! JSON_MsgAck_msg.validate(json))
229
- // return false;
230
- if (! JSON_MsgWarp.validate(json_msgAck._cause))
231
- return false;
232
- return true;
233
- }
234
- }
235
- })();
236
-
237
- var JSON_MsgAckEngage = (function() {
238
- return {
239
- // createWith_msgAck_msg : function(json_msgAck, _msg) {
240
- // const json_msgAckEngage= structuredClone(json_msgAck);
241
- // json_msgAckEngage._cause= _cause;
242
- // return json_msgAckEngage;
243
- // }
244
- create_with_Engage_Ok : function(json_msgEngage, b_ok= true) {
245
- const json_msgAck= JSON_MsgAck.create_with_cause_Ok(json_msgEngage, b_ok);
246
- json_msgAck["2PhW"]= k_VERSION;
247
- return json_msgAck;
248
- },
249
- // create_with_msgExpired : function( json_msgEngage ) {
250
- // const json_msgAck_msg= JSON_MsgAck_msg.create_with_msgExpired( json_msgEngage )
251
- // json_msgAck_msg["2PhW"]= k_VERSION;
252
- // return json_msgAck_msg;
253
- // },
254
- validate : function(json_msgAck) {
255
- // if (! JSON_MsgAck_msg.validate(json_msgAck_msg))
256
- // return false;
257
- if (! JSON_MsgEngage.validate(json_msgAck._cause))
258
- return false;
259
- return true;
260
- }
261
- }
262
- })();
263
-
264
- //-------------------------------------------------------------------------------------------------
265
- // States
266
-
267
- class StateState {
268
- private _idx_event : number;
269
- private _event : EventMinimal;
270
- protected _statekeeper : ProtocolStateState;
271
-
272
- constructor(idx_event : number, event : EventMinimal) {
273
- this._statekeeper = null;
274
- this._idx_event = idx_event;
275
- this._event = event;
276
- }
277
- get protocol() {
278
- return this._statekeeper;
279
- }
280
- set protocol(parent) {
281
- this._statekeeper = parent;
282
- }
283
- get idx_event() {
284
- return this._idx_event;
285
- }
286
- get event() {
287
- return this._event;
288
- }
289
- get json_msg() {
290
- return this._event.data.json_msg;
291
- }
292
- changeState(state_new : StateState) {
293
- if (this.canChangeState(state_new))
294
- this.protocol.state = state_new;
295
- else
296
- this.protocol.state = new StateINVALID(state_new._idx_event, state_new._event);
297
- }
298
- canChangeState(_state_new : StateState) : boolean {
299
- throw new Error("Subclass must implement canChangeState()");
300
- }
301
- }
302
-
303
- class StateAckEngage extends StateState {
304
- constructor(idx_event : number, event : EventMinimal) { super(idx_event, event); }
305
- get evt_AckEngage() { return this.event }
306
- get json_msgAckEngage() { return this.json_msg }
307
- canChangeState(_state_new : StateState) {
308
- return false;
309
- }
310
- }
311
-
312
- class StateEngage extends StateState {
313
- constructor(idx_event : number, event : EventMinimal) { super(idx_event, event); }
314
- get evt_Engage() { return this.event }
315
- get json_msgEngage() { return this.json_msg }
316
- canChangeState(state_new : StateState) {
317
- if (false === state_new instanceof StateAckEngage)
318
- return false;
319
-
320
- // The Engage gets to live for THE WARP'S creation time + TTL*2 + RTT
321
- const json_msgWarp= this.json_msgEngage._cause;
322
- const timeout_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec, this.json_msgEngage.engage.rtt_msec);
323
- logr_.log(l_.PROTOCOL_STATE, () => [`StateEngage: evt_AckEngage.dt@${state_new.evt_AckEngage.dt}, msgWarp.dt@${Date.parse(json_msgWarp.dt)} + ${timeout_ms}`])
324
- if (state_new.evt_AckEngage.dt >= Date.parse(json_msgWarp.dt) + timeout_ms)
325
- return false;
326
-
327
- return true;
328
- }
329
- }
330
-
331
- class StateAckWarp extends StateState {
332
- constructor(idx_event : number, event : EventMinimal) { super(idx_event, event); }
333
- get evt_AckWarp() { return this.event }
334
- get json_msgAckWarp() { return this.json_msg }
335
- canChangeState(state_new : StateState) {
336
- if (false === state_new instanceof StateEngage)
337
- return false;
338
-
339
- if (! this.json_msgAckWarp.ack.ok)
340
- return false;
341
-
342
- if (this.json_msgAckWarp._cause.warp.instantaneous)
343
- return false;
344
-
345
- // The Ack gets to live for THE ACK'S creation time + TTL*2 + STT
346
- // +STT, so lines up with the Engage timeout
347
- // - Engage: T0 +2TTL +RTT; RTT= STT+STT
348
- // - AckWarp: TAckWarp +2TLL +STT; TAckWarp= T0 +STT;
349
- // - STT: Date of the Ack minus date of the Warp.
350
- const timeout_ms= time_ttl_rtt_(this.json_msgAckWarp._cause.warp.ttl_msec) + Date.parse(this.json_msgAckWarp.dt) - Date.parse(this.json_msgAckWarp._cause.dt);
351
- logr_.log(l_.PROTOCOL_STATE, () => [`StateAckWarp: evt_Engage.dt@${state_new.evt_Engage.dt}, msgAckWarp.dt@${Date.parse(this.json_msgAckWarp.dt)} + ${timeout_ms}`])
352
- if (state_new.evt_Engage.dt >= Date.parse(this.json_msgAckWarp.dt) + timeout_ms)
353
- return false;
354
-
355
- return true;
356
- }
357
- }
358
-
359
- class StateWarp extends StateState {
360
- constructor(idx_event : number, event : EventMinimal) { super(idx_event, event); }
361
- get evt_Warp() { return this.event }
362
- get json_msgWarp() { return this.json_msg }
363
- canChangeState(state_new : StateState) {
364
- if (false === state_new instanceof StateAckWarp)
365
- return false;
366
-
367
- // The Warp gets to live for THE WARP'S creation time + TTL*2
368
- const timeout_ms= time_ttl_rtt_(this.json_msgWarp.warp.ttl_msec);
369
- logr_.log(l_.PROTOCOL_STATE, () => [`StateWarp: evt_AckWarp.dt@${state_new.evt_AckWarp.dt}, msgWarp.dt@${Date.parse(this.json_msgWarp.dt)} + ${timeout_ms}`])
370
- if (state_new.evt_AckWarp.dt >= Date.parse(this.json_msgWarp.dt) + timeout_ms)
371
- return false;
372
-
373
- return true;
374
- }
375
- }
376
-
377
- class StateINVALID extends StateState {
378
- constructor(idx_event : number, event : EventMinimal) { super(idx_event, event); }
379
- canChangeState(_state_new : StateState) {
380
- // INVALID can't transition to any state
381
- return false;
382
- }
383
- }
384
-
385
- class StateInitialState extends StateState {
386
- constructor() { super(null, null); }
387
- canChangeState(state_new : StateState) {
388
- if (false === state_new instanceof StateWarp)
389
- return false;
390
-
391
- // The NEWLY created Warp only gets to live for its creation time + TTL
392
- const timeout_ms= state_new.json_msgWarp.warp.ttl_msec;
393
- logr_.log(l_.PROTOCOL_STATE, () => [`StateInitialState: evt_Warp.dt@${state_new.evt_Warp.dt}, msgWarp.dt@${Date.parse(state_new.json_msgWarp.dt)} + ${timeout_ms}`])
394
- if (state_new.evt_Warp.dt >= Date.parse(state_new.json_msgWarp.dt) + timeout_ms)
395
- return false;
396
-
397
- return true;
398
- }
399
- }
400
-
401
- //----
402
-
403
- class ProtocolStateState {
404
- private _state : StateState;
405
-
406
- constructor(state_initial? : StateState) {
407
- this.state = state_initial || new StateInitialState();
408
- }
409
-
410
- set state(state_new : StateState) {
411
- if (! (state_new instanceof StateState)) {
412
- throw new Error("initState must be an instance of StateState or its subclasses");
413
- }
414
- this._state = state_new;
415
- if (state_new && state_new.protocol !== this) {
416
- state_new.protocol = this;
417
- }
418
- }
419
- get state() : StateState {
420
- return this._state;
421
- }
422
-
423
- canChangeState(state_new : StateState) : boolean {
424
- return this._state.canChangeState(state_new);
425
- }
426
- }
427
-
428
- //-------------------------------------------------------------------------------------------------
429
-
430
- class TwoPhW_EventLog {
431
- private _eventLog : EventLog;
432
-
433
- constructor(eventLog : EventLog) {
434
- this._eventLog = eventLog;
435
- }
436
-
437
- _warp(json_msg) {
438
- const b_Ack = json_msg.ack !== undefined;
439
- const json = b_Ack ? json_msg["_cause"] : json_msg;
440
-
441
- if (json.warp) {
442
- return {
443
- str_type: `2PhW[JSON_Msg${b_Ack ? 'Ack' : ''}Warp]`,
444
- json_msgWarp: json
445
- };
446
- }
447
- if (json.engage) {
448
- return {
449
- str_type: `2PhW[JSON_Msg${b_Ack ? 'Ack' : ''}Engage]`,
450
- json_msgWarp: json["_cause"]
451
- };
452
- }
453
- return { str_type: null, json_msgWarp: null }; // Explicit default for invalid cases
454
- }
455
-
456
- // _addEvent(msg: t_msg, json_msg : JSON_Msg, timeout_ms? : number, timeout_callback? : ( args? : {idx_event : number, event : EventMinimal} ) => {}) {
457
- _addEvent(msg: t_msg, json_msg, timeout_ms? : number, timeout_callback? : () => void) {
458
- const { str_type, json_msgWarp }= this._warp(json_msg);
459
- const { idx }= this._eventLog.add_Event(str_type, json_msgWarp.warp.id, {msg, json_msg}, timeout_ms, timeout_callback);
460
- logr_.log(l_.PROTOCOL_STATE, () => [`_addEvent: [${idx}] timeout:${Date.now()}+${timeout_ms} `, json_msg]);
461
- }
462
-
463
- _dropEvent(json_msg) {
464
- const { json_msgWarp }= this._warp(json_msg);
465
- if (! json_msgWarp)
466
- return;
467
- this._eventLog.add_Event('2PhW[DROPPED!]', json_msgWarp.warp.id, json_msg);
468
- }
469
-
470
- _cancelTimeout(idx_event) {
471
- logr_.log(l_.PROTOCOL_STATE, () => [`_cancelTimeout: [${idx_event}] timeout cancelled`]);
472
- this._eventLog.cancel_timeout(idx_event);
473
- }
474
-
475
- traverse_State(json_msgWarp) {
476
- const protocolState = new ProtocolStateState();
477
-
478
- const arr_evts= this._eventLog.get_Events_by_id(json_msgWarp.warp.id, k_TTL);
479
- logr_.log(l_.EVENTS, () => ['traverse_State: arr_evts: ', arr_evts]);
480
- //TODO: what is the right TTL? should it be a constant or calculated
481
-
482
- for (let i = arr_evts.length - 1; i >= 0; i--) {
483
- const { idx, evt } = arr_evts[i];
484
-
485
- const json_msg= evt.data.json_msg;
486
- if (! JSON_MsgWarp.compare(json_msgWarp, this._warp(json_msg).json_msgWarp) )
487
- protocolState.state.changeState( new StateINVALID(idx, evt) );
488
-
489
- switch(evt.type) {
490
- case '2PhW[JSON_MsgWarp]' :
491
- protocolState.state.changeState( new StateWarp(idx, evt) );
492
- break;
493
- case '2PhW[JSON_MsgAckWarp]' :
494
- protocolState.state.changeState( new StateAckWarp(idx, evt) );
495
- break;
496
- case '2PhW[JSON_MsgEngage]' :
497
- protocolState.state.changeState( new StateEngage(idx, evt) );
498
- break;
499
- case '2PhW[JSON_MsgAckEngage]' :
500
- protocolState.state.changeState( new StateAckEngage(idx, evt) );
501
- break;
502
- default :
503
- break;
504
- }
505
-
506
- logr_.log(l_.PROTOCOL_STATE, () => ['traverse_State: type,state: ',
507
- evt.type,
508
- (protocolState.state.json_msg.ack?.ok === false) ? '--NACK--' : '',
509
- protocolState.state
510
- ]);
511
- }
512
- return protocolState;
513
- }
514
-
515
- }
516
-
517
- class TwoPhW {
518
- private _2PhW_eventLog : TwoPhW_EventLog;
519
- private _config : Config;
520
-
521
- constructor(eventLog : EventLog) {
522
- this._2PhW_eventLog = new TwoPhW_EventLog(eventLog);
523
- this._config= new Config();
524
- }
525
-
526
- get config() : Config {
527
- return this._config;
528
- }
529
-
530
- get eventLog() : TwoPhW_EventLog {
531
- return this._2PhW_eventLog;
532
- }
533
-
534
- //-------------------------------------------------------------------------------------------------
535
-
536
- _handler_msgOptions(cfg, msg, json_msgOptions) : boolean
537
- {
538
- logr_.log(l_.HANDLERS, () => ['handler_msgOptions_: ...']);
539
-
540
- /*
541
- if (! validate_Options_delay_(json_msgOptions.options))
542
- return false;
543
-
544
- if (JSON_MsgWarp.validate(json_msgOptions._cause)) {
545
- const json_msgWarp= json_msgOptions._cause;
546
-
547
- const ctx= get_ctx(json_msgWarp.id);
548
- if (!ctx )
549
- return false;
550
-
551
- const ttl_msec= json_msgOptions.options.ttl_msec_incr[0];
552
- const ttl_incr= json_msgOptions.options.ttl_msec_incr[1];
553
-
554
- //TODO: double check ttl_msec is the same as current accummulated ttl for idempotence.
555
-
556
- logr_.log(l_.HANDLERS, () => ['handler_msgOptions_: ', json_msgOptions]);
557
-
558
- ctx.protocol.delayTimeout(ttl_incr);
559
-
560
- if (cfg._callback_msgOptions)
561
- return cfg._callback_msgOptions(msg, json_msgOptions);
562
-
563
- return true;
564
- }
565
- */
566
-
567
- return false;
568
- }
569
-
570
- //-------------------------------------------------------------------------------------------------
571
- // sender Source (src)
572
-
573
- register_msgWarp(msg : t_msg, json_msgWarp) : boolean
574
- {
575
- logr_.log(l_.SENDER, () => ['register_msgWarp: ', json_msgWarp]);
576
-
577
- const protocolState= this.eventLog.traverse_State(json_msgWarp);
578
- const b_changeState= protocolState.canChangeState( new StateWarp(null, {
579
- dt: Date.now(),
580
- data: { msg, json_msg: json_msgWarp }
581
- }) );
582
-
583
- logr_.log(l_.HANDLERS | l_.SENDER, () => ['register_msgWarp: protocolState.canChangeState ', b_changeState]);
584
- if (! b_changeState)
585
- return false;
586
-
587
- const timeout_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec);
588
- const elapsed_ms= Date.now() - Date.parse(json_msgWarp.dt);
589
-
590
- this.eventLog._addEvent(msg, json_msgWarp, timeout_ms-elapsed_ms, () => { // pass { _idx, _evt}?
591
- this.config._callback_msg_sent_expired(msg, json_msgWarp);
592
- });
593
- }
594
-
595
- _handler_msgAckWarp(msg : t_msg, json_msgAckWarp) : boolean
596
- {
597
- logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: ', json_msgAckWarp]);
598
-
599
- const json_msgWarp= json_msgAckWarp._cause;
600
-
601
- const protocolState= this.eventLog.traverse_State(json_msgWarp);
602
- const b_changeState= protocolState.canChangeState( new StateAckWarp(null, {
603
- dt: Date.now(),
604
- data: { msg, json_msg: json_msgAckWarp }
605
- }) );
606
-
607
- logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: protocolState.canChangeState ', b_changeState]);
608
- if (! b_changeState)
609
- return false;
610
-
611
- this.eventLog._cancelTimeout(protocolState.state.idx_event);
612
- this.eventLog._addEvent(msg, json_msgAckWarp);
613
- return this.config._callback_msgAckWarp(msg, json_msgAckWarp);
614
- }
615
-
616
- register_msgEngage(msg : t_msg, json_msgEngage) : boolean
617
- {
618
- logr_.log(l_.SENDER, () => ['register_msgEngage: ', json_msgEngage]);
619
-
620
- const json_msgWarp= json_msgEngage._cause;
621
-
622
- const protocolState= this.eventLog.traverse_State(json_msgWarp);
623
- const b_changeState = protocolState.canChangeState( new StateEngage(null, {
624
- dt: Date.now(),
625
- data : { msg, json_msg: json_msgEngage }
626
- }) );
627
-
628
- logr_.log(l_.HANDLERS | l_.SENDER, () => ['register_msgEngage: protocolState.canChangeState ', b_changeState]);
629
- if (! b_changeState)
630
- return false;
631
-
632
- const timeout_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec, json_msgEngage.engage.rtt_msec);
633
- const elapsed_ms= Date.now() - Date.parse(json_msgWarp.dt);
634
-
635
- this.eventLog._addEvent(msg, json_msgEngage, timeout_ms-elapsed_ms, () => {
636
- this.config._callback_msg_sent_expired(msg, json_msgEngage);
637
- });
638
- }
639
-
640
- _handler_msgAckEngage(msg : t_msg, json_msgAckEngage) : boolean
641
- {
642
- logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage: ', json_msgAckEngage]);
643
-
644
- const json_msgWarp= json_msgAckEngage._cause._cause;
645
-
646
- const protocolState= this.eventLog.traverse_State(json_msgWarp);
647
- const b_changeState= protocolState.canChangeState( new StateAckEngage(null, {
648
- dt: Date.now(),
649
- data : { msg, json_msg: json_msgAckEngage }
650
- }) );
651
-
652
- logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage_: protocolState.canChangeState ', b_changeState]);
653
- if (! b_changeState)
654
- return false;
655
-
656
- this.eventLog._cancelTimeout(protocolState.state.idx_event);
657
- this.eventLog._addEvent(msg, json_msgAckEngage);
658
- return this.config._callback_msgAckEngage(msg, json_msgAckEngage)
659
- }
660
-
661
- //-------------------------------------------------------------------------------------------------
662
- // receiver Destination (dst)
663
-
664
- _handler_msgWarp(msg : t_msg, json_msgWarp) : boolean
665
- {
666
- logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: ', json_msgWarp]);
667
-
668
- const protocolState= this.eventLog.traverse_State(json_msgWarp);
669
- const b_changeState= protocolState.canChangeState( new StateWarp(null, {
670
- dt: Date.now(),
671
- data: { msg, json_msg: json_msgWarp }
672
- }) );
673
-
674
- logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: protocolState.canChangeState: ', b_changeState]);
675
- if (! b_changeState)
676
- return false;
677
-
678
- this.eventLog._addEvent(msg, json_msgWarp);
679
- return this.config._callback_msgWarp(msg, json_msgWarp)
680
- }
681
-
682
- register_msgAckWarp(msg: t_msg, json_msgAckWarp) : boolean
683
- {
684
- logr_.log(l_.RECVER, () => ['register_msgAckWarp: ', json_msgAckWarp]);
685
-
686
- const json_msgWarp= json_msgAckWarp._cause;
687
-
688
- const protocolState= this.eventLog.traverse_State(json_msgWarp);
689
- const b_changeState= protocolState.canChangeState( new StateAckWarp(null, {
690
- dt: Date.now(),
691
- data: { msg, json_msg: json_msgAckWarp }
692
- }) );
693
-
694
- logr_.log(l_.HANDLERS | l_.RECVER, () => ['register_msgAckWarp: protocolState.canChangeState: ', b_changeState]);
695
- if (! b_changeState)
696
- return false;
697
-
698
- const elapsed_ms= Date.now() - Date.parse(json_msgAckWarp.dt);
699
- const timeout_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec) + Date.parse(json_msgAckWarp.dt) - Date.parse(json_msgWarp.dt);
700
-
701
- this.eventLog._addEvent(msg, json_msgAckWarp, timeout_ms-elapsed_ms, () => { // pass { _idx, _evt} ?
702
- this.config._callback_msg_sent_expired(msg, json_msgAckWarp);
703
- });
704
- }
705
-
706
- _handler_msgEngage(msg : t_msg, json_msgEngage) : boolean
707
- {
708
- logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: ', json_msgEngage]);
709
-
710
- const json_msgWarp= json_msgEngage._cause;
711
-
712
- const protocolState= this.eventLog.traverse_State(json_msgWarp);
713
- const b_changeState= protocolState.canChangeState( new StateEngage(null, {
714
- dt: Date.now(),
715
- data: { msg, json_msg: json_msgEngage }
716
- }) );
717
-
718
- logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: protocolState.canChangeState: ', b_changeState]);
719
- if (! b_changeState)
720
- return false;
721
-
722
- this.eventLog._cancelTimeout(protocolState.state.idx_event);
723
- this.eventLog._addEvent(msg, json_msgEngage);
724
- return this.config._callback_msgEngage(msg, json_msgEngage)
725
- }
726
-
727
- register_msgAckEngage(msg : t_msg, json_msgAckEngage) : boolean
728
- {
729
- logr_.log(l_.RECVER, () => ['register_msgAckEngage: ', json_msgAckEngage]);
730
-
731
- const json_msgWarp= json_msgAckEngage._cause._cause;
732
-
733
- const protocolState= this.eventLog.traverse_State(json_msgWarp);
734
- const b_changeState= protocolState.canChangeState( new StateAckEngage(null, {
735
- dt: Date.now(),
736
- data: { msg, json_msg: json_msgAckEngage }
737
- }) );
738
-
739
- logr_.log(l_.HANDLERS | l_.RECVER, () => ['register_msgAckEngage: protocolState.canChangeState: ', b_changeState]);
740
- if (! b_changeState)
741
- return false;
742
-
743
- this.eventLog._addEvent(msg, json_msgAckEngage);
744
- }
745
-
746
- //-------------------------------------------------------------------------------------------------
747
-
748
- handler_json_msgAck(msg : t_msg, json_msgAck) : boolean
749
- {
750
- logr_.log(l_.HANDLERS, () => ['TwoPhW: handler_json_msgAck: ', json_msgAck]);
751
-
752
- if (JSON_MsgAckWarp.validate(json_msgAck) && this._handler_msgAckWarp(msg, json_msgAck) )
753
- return true;
754
-
755
- if (JSON_MsgAckEngage.validate(json_msgAck) && this._handler_msgAckEngage(msg, json_msgAck) )
756
- return true;
757
-
758
- return false;
759
- }
760
-
761
- handler_json_msgEffect(msg : t_msg, json_msgEffect) : boolean
762
- {
763
- logr_.log(l_.HANDLERS, () => ['TwoPhW: handler_json_msgEffect: ', json_msgEffect]);
764
-
765
- // if (JSON_MsgAck.validate(json_msgEffect) && this.handler_json_msgAck(msg, json_msgEffect) )
766
- // return true;
767
-
768
- if (JSON_MsgEngage.validate(json_msgEffect) && this._handler_msgEngage(msg, json_msgEffect) )
769
- return true;
770
-
771
- // if (JSON_MsgOptions.validate(json_msg) && this.handler_msgOptions_(this._config, msg, json_msg))
772
- // return true;
773
-
774
- return false;
775
- }
776
-
777
- handler_json_msg(msg : t_msg, json_msg) : boolean
778
- {
779
- logr_.log(l_.HANDLERS, () => ['TwoPhW: handler_json_msg: ', json_msg]);
780
-
781
- if (JSON_MsgWarp.validate(json_msg) && this._handler_msgWarp(msg, json_msg) )
782
- return true;
783
-
784
- // https://attacomsian.com/blog/javascript-iterate-objects
785
- // Object.keys(json_msg).forEach((key, index) => {
786
- // if (key == 'dt')
787
- // return;
788
- // if (key == 'referer')
789
- // return;
790
- // console.log(`${key}: ${json_msg[key]}`);
791
- // });
792
-
793
- return false;
794
- }
795
-
796
- // handler_json(msg : t_msg, json) : boolean
797
- // {
798
- // logr_.log(l_.HANDLERS, () => ['handler_json: ', json]);
799
-
800
- // if (JSON_MsgEffect.validate(json) && this.handler_json_msgEffect(msg, json) )
801
- // return true;
802
-
803
- // if (JSON_Msg.validate(json) && this.handler_json_msg(msg, json) )
804
- // return true;
805
-
806
- // return false;
807
- // }
808
-
809
- };
810
-
811
- //-------------------------------------------------------------------------------------------------
812
-
813
- export {
814
- time_ttl_rtt_ as t_ttl_rtt,
815
- TwoPhW,
816
- JSON_MsgOptions,
817
- JSON_MsgWarp,
818
- JSON_MsgEngage,
819
- JSON_MsgAckWarp,
820
- JSON_MsgAckEngage,
821
- logr_ as logr,
822
- JSON_Msg,
823
- JSON_MsgEffect,
824
- JSON_MsgAck,
825
- // -----
826
- StateAckEngage,
827
- StateEngage,
828
- StateAckWarp,
829
- StateWarp,
830
- StateINVALID,
831
- StateInitialState
832
- };
833
-
1
+
2
+ // The wire interface (validators, constructors, VERSION) is GENERATED by iface-gen from the pinned
3
+ // schema_TwoPhW.json (see ifacegenconfig.json; `npm run gen`) -- never hand-written here.
4
+ import * as iface_TwoPhW_ from './generated/iface-TwoPhW/index.mjs';
5
+
6
+ // import { v4 as uuidv4 } from 'uuid'; // uuid is already a dep of JSON_Msg, so why not
7
+ import { LOGR, lRef, l_merge, l_array, l_concat, l_LL } from '@knev/bitlogr';
8
+ import { JSON_Msg, JSON_Eff, JSON_Ack, logr as logr_json_msg_ } from '@rootintf/json-msg'
9
+
10
+ import { EventLog, logr as logr_evtlog_ } from '@rootintf/eventlog'
11
+
12
+ type t_msg = string;
13
+
14
+ interface EventMinimal {
15
+ dt : number;
16
+ // b_sent: the step is one THIS participant sent (register_*), not one it received (handler_json_*)
17
+ data : { msg : t_msg, json_msg, b_sent : boolean };
18
+ }
19
+
20
+ // interface Event extends Required<EventMinimal> {
21
+ // type : string;
22
+ // id : string | number;
23
+ // timeout_id : NodeJS.Timeout | null;
24
+ // };
25
+
26
+ //-------------------------------------------------------------------------------------------------
27
+
28
+ const obj_labels_merge_= l_merge(logr_evtlog_.lref.get(), logr_json_msg_.lref.get()); // VALIDATION : 4
29
+ const obj_labels_concat_= l_concat(obj_labels_merge_, l_array(['HANDLERS', 'DROPS', 'PROTOCOL_STATE', 'RECVER', 'SENDER']) );
30
+
31
+ const lref_= lRef(obj_labels_concat_);
32
+ logr_json_msg_.lref= lref_;
33
+ logr_evtlog_.lref= lref_;
34
+
35
+ const LOGR_= LOGR.get_instance();
36
+ const logr_= LOGR_.create(); // don't let create() make a new ref, assign lref_ from here
37
+ logr_.lref= lref_;
38
+
39
+ const l_= logr_.l;
40
+
41
+ //-------------------------------------------------------------------------------------------------
42
+
43
+ type t_callback = (msg : t_msg, json_msg) => boolean;
44
+ type t_callback_void = (msg : t_msg, json_msg) => void;
45
+
46
+ class Config {
47
+ // A step's callback is what makes the step this participant's to handle: with no callback set,
48
+ // the step's handler refuses it (returns false) before anything is logged. Every participant on
49
+ // the ME hears every exchange, so "no callback" is the normal case for a role it does not play.
50
+ public _callback_msgWarp : t_callback | null = null;
51
+ public _callback_effEngage : t_callback | null = null;
52
+ public _callback_ackWarp : t_callback | null = null;
53
+ public _callback_ackEngage : t_callback | null = null;
54
+ // "a step I sent was never answered inside its window", one per role: the sender's fires for its
55
+ // Warp / Engage, the receiver's for its AckWarp. A participant playing both roles keeps both.
56
+ public _callback_sender_sent_expired : t_callback_void
57
+ public _callback_receiver_sent_expired : t_callback_void
58
+ public _callback_msgOptions: () => void;
59
+
60
+ constructor() {
61
+ this._callback_sender_sent_expired = (_msg : t_msg, _json_msg) => {
62
+ console.assert(false, '_callback_sender_sent_expired uninitialized');
63
+ };
64
+ this._callback_receiver_sent_expired = (_msg : t_msg, _json_msg) => {
65
+ console.assert(false, '_callback_receiver_sent_expired uninitialized');
66
+ };
67
+ this._callback_msgOptions = () => {
68
+ console.assert(false, 'callback_msgOptions uninitialized');
69
+ };
70
+ }
71
+
72
+ receiver(callback_msgWarp : t_callback, callback_effEngage : t_callback, callback_msg_sent_expired : t_callback_void) {
73
+ this._callback_msgWarp= callback_msgWarp;
74
+ this._callback_effEngage= callback_effEngage;
75
+ this._callback_receiver_sent_expired= callback_msg_sent_expired;
76
+ }
77
+ sender(callback_ackWarp : t_callback, callback_ackEngage : t_callback, callback_msg_sent_expired : t_callback_void ) {
78
+ this._callback_ackWarp= callback_ackWarp;
79
+ this._callback_ackEngage= callback_ackEngage;
80
+ this._callback_sender_sent_expired= callback_msg_sent_expired;
81
+ }
82
+
83
+ set callback_msgOptions(callback) {
84
+ this._callback_msgOptions= callback;
85
+ }
86
+ }
87
+
88
+ // var config = (function() {
89
+ // let _options;
90
+
91
+ // return {
92
+ // get callback_Abort() { return _options.callback_Abort; },
93
+
94
+ // set options(obj) {
95
+ // _options= obj;
96
+ // if (_options.logr) // && options_.logr[ __name(l_) ] )
97
+ // LOGR_.toggled= _options.logr
98
+ // }
99
+ // }
100
+ // })();
101
+
102
+ //-------------------------------------------------------------------------------------------------
103
+
104
+ const k_VERSION= iface_TwoPhW_.VERSION;
105
+
106
+ // rtt_msec <= ttl_msec *2 => rtt_msec = ttl_msec *2
107
+ // t_ttl_rtt_(TTL, RTT) = t_ttl_rtt_(TTL, TTL *2) = TTL *2 + TTL *2 = TTL *4 MAX
108
+
109
+ function time_ttl_rtt_(ttl_msec: number | undefined, rtt_msec?: number): number | undefined {
110
+ if (ttl_msec === undefined)
111
+ return undefined;
112
+ if (rtt_msec === undefined)
113
+ return ttl_msec *2;
114
+
115
+ console.assert(rtt_msec <= ttl_msec *2, `t_ttl_rtt_: INVALID rtt_msec ttl_msec[${ttl_msec}] rtt_msec[${rtt_msec}]`)
116
+ return (ttl_msec *2) + rtt_msec;
117
+ }
118
+
119
+ // not part of the generated interface (no schema yet)
120
+ var JSON_MsgOptions = (function() {
121
+ return {
122
+ create_with_cause_options : function(msg_cause, options) {
123
+ return JSON_Eff.create_with_cause_merge(msg_cause, {
124
+ options: options,
125
+ "2PhW": k_VERSION
126
+ });
127
+ },
128
+ validate : function(json) {
129
+ // if (! JSON_Msg_msg.validate(json))
130
+ // return false;
131
+ // if (! schema_MsgOptions_(json)) {
132
+ // logr_.log(l_.VALIDATION, () => ['JSON_MsgOptions: schema_MsgOptions_: ', (schema_MsgOptions_ as any).errors])
133
+ // return false;
134
+ // }
135
+ return true;
136
+ }
137
+ }
138
+ })();
139
+
140
+ // Each JSON_* below is the generated namespace (validate + merge / create_with_cause_merge; the
141
+ // validators are delta-only: the base is validated upstream, in the responder chain) extended with
142
+ // what the schema cannot express: the protocol's own constructors.
143
+
144
+ var JSON_MsgWarp = (function() {
145
+ return {
146
+ ...iface_TwoPhW_.JSON_MsgWarp,
147
+ create_with_id_user_hyperport : function(json_warp_id, json_user, json_hyperport, nr_ttl_msec) {
148
+ return iface_TwoPhW_.JSON_MsgWarp.merge({
149
+ id : json_warp_id,
150
+ user : json_user,
151
+ hyperport : json_hyperport,
152
+ ttl_msec : nr_ttl_msec
153
+ });
154
+ },
155
+ compare : function(json_L, json_R) {
156
+ if (json_L.dt !== json_R.dt)
157
+ return false;
158
+ if (json_L.warp.id !== json_R.warp.id)
159
+ return false;
160
+ if (json_L.referer[0] !== json_R.referer[0])
161
+ return false;
162
+ if (json_L.referer[1] !== json_R.referer[1])
163
+ return false;
164
+ return true;
165
+ }
166
+ }
167
+ })();
168
+
169
+ var JSON_EffEngage = (function() {
170
+ return {
171
+ ...iface_TwoPhW_.JSON_EffEngage,
172
+ create_with_Warp : function(json_msgWarp) {
173
+ console.assert(json_msgWarp.ack === undefined, "Engage with a Warp, not an Ack");
174
+ return iface_TwoPhW_.JSON_EffEngage.create_with_cause_merge(json_msgWarp, {
175
+ "ok" : true,
176
+ "rtt_msec" : Date.now() - Date.parse(json_msgWarp.dt)
177
+ });
178
+ }
179
+ };
180
+ })();
181
+
182
+ // iface-gen emits no constructor for a JSON_Ack: build the base ack, stamp the protocol marker
183
+
184
+ var JSON_AckWarp = (function() {
185
+ return {
186
+ ...iface_TwoPhW_.JSON_AckWarp,
187
+ create_with_Warp_Ok : function(json_msgWarp, b_ok= true) {
188
+ const json_ack= JSON_Ack.create_with_cause_Ok(json_msgWarp, b_ok);
189
+ json_ack["2PhW"]= k_VERSION;
190
+ return json_ack;
191
+ }
192
+ }
193
+ })();
194
+
195
+ var JSON_AckEngage = (function() {
196
+ return {
197
+ ...iface_TwoPhW_.JSON_AckEngage,
198
+ create_with_Engage_Ok : function(json_effEngage, b_ok= true) {
199
+ const json_ack= JSON_Ack.create_with_cause_Ok(json_effEngage, b_ok);
200
+ json_ack["2PhW"]= k_VERSION;
201
+ return json_ack;
202
+ }
203
+ }
204
+ })();
205
+
206
+ //-------------------------------------------------------------------------------------------------
207
+ // States
208
+
209
+ class StateState {
210
+ private _idx_event : number;
211
+ private _event : EventMinimal;
212
+ protected _statekeeper : ProtocolStateState;
213
+
214
+ constructor(idx_event : number, event : EventMinimal) {
215
+ this._statekeeper = null;
216
+ this._idx_event = idx_event;
217
+ this._event = event;
218
+ }
219
+ get protocol() {
220
+ return this._statekeeper;
221
+ }
222
+ set protocol(parent) {
223
+ this._statekeeper = parent;
224
+ }
225
+ get idx_event() {
226
+ return this._idx_event;
227
+ }
228
+ get event() {
229
+ return this._event;
230
+ }
231
+ get json_msg() {
232
+ return this._event.data.json_msg;
233
+ }
234
+ changeState(state_new : StateState) {
235
+ if (this.canChangeState(state_new))
236
+ this.protocol.state = state_new;
237
+ else
238
+ this.protocol.state = new StateINVALID(state_new._idx_event, state_new._event);
239
+ }
240
+ canChangeState(_state_new : StateState) : boolean {
241
+ throw new Error("Subclass must implement canChangeState()");
242
+ }
243
+ }
244
+
245
+ class StateAckEngage extends StateState {
246
+ constructor(idx_event : number, event : EventMinimal) { super(idx_event, event); }
247
+ get evt_AckEngage() { return this.event }
248
+ get json_ackEngage() { return this.json_msg }
249
+ canChangeState(_state_new : StateState) {
250
+ return false;
251
+ }
252
+ }
253
+
254
+ class StateEngage extends StateState {
255
+ constructor(idx_event : number, event : EventMinimal) { super(idx_event, event); }
256
+ get evt_Engage() { return this.event }
257
+ get json_effEngage() { return this.json_msg }
258
+ canChangeState(state_new : StateState) {
259
+ if (false === state_new instanceof StateAckEngage)
260
+ return false;
261
+
262
+ // The Engage gets to live for THE WARP'S creation time + TTL*2 + RTT
263
+ const json_msgWarp= this.json_effEngage._cause;
264
+ const timeout_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec, this.json_effEngage.engage.rtt_msec);
265
+ logr_.log(l_.PROTOCOL_STATE, () => [`StateEngage: evt_AckEngage.dt@${state_new.evt_AckEngage.dt}, msgWarp.dt@${Date.parse(json_msgWarp.dt)} + ${timeout_ms}`])
266
+ if (state_new.evt_AckEngage.dt >= Date.parse(json_msgWarp.dt) + timeout_ms)
267
+ return false;
268
+
269
+ return true;
270
+ }
271
+ }
272
+
273
+ // Can a JSON_EffEngage follow this JSON_AckWarp? Not after a nack (it ends the exchange), and not
274
+ // after the ack of an instantaneous warp (single phase: the ack concludes it).
275
+ function isEngageAwaited_(json_ackWarp) : boolean {
276
+ return !! json_ackWarp.ack.ok && ! json_ackWarp._cause.warp.instantaneous;
277
+ }
278
+
279
+ class StateAckWarp extends StateState {
280
+ constructor(idx_event : number, event : EventMinimal) { super(idx_event, event); }
281
+ get evt_AckWarp() { return this.event }
282
+ get json_ackWarp() { return this.json_msg }
283
+ canChangeState(state_new : StateState) {
284
+ if (false === state_new instanceof StateEngage)
285
+ return false;
286
+
287
+ if (! isEngageAwaited_(this.json_ackWarp))
288
+ return false;
289
+
290
+ // RTT <= TTL*2: the cap that bounds the whole exchange at TTL*4 (see traverse_State's lookback)
291
+ if (state_new.json_effEngage.engage.rtt_msec > this.json_ackWarp._cause.warp.ttl_msec *2)
292
+ return false;
293
+
294
+ // The Ack gets to live for THE ACK'S creation time + TTL*2 + STT
295
+ // +STT, so lines up with the Engage timeout
296
+ // - Engage: T0 +2TTL +RTT; RTT= STT+STT
297
+ // - AckWarp: TAckWarp +2TLL +STT; TAckWarp= T0 +STT;
298
+ // - STT: Date of the Ack minus date of the Warp.
299
+ 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);
300
+ logr_.log(l_.PROTOCOL_STATE, () => [`StateAckWarp: evt_Engage.dt@${state_new.evt_Engage.dt}, msgAckWarp.dt@${Date.parse(this.json_ackWarp.dt)} + ${timeout_ms}`])
301
+ if (state_new.evt_Engage.dt >= Date.parse(this.json_ackWarp.dt) + timeout_ms)
302
+ return false;
303
+
304
+ return true;
305
+ }
306
+ }
307
+
308
+ class StateWarp extends StateState {
309
+ constructor(idx_event : number, event : EventMinimal) { super(idx_event, event); }
310
+ get evt_Warp() { return this.event }
311
+ get json_msgWarp() { return this.json_msg }
312
+ canChangeState(state_new : StateState) {
313
+ if (false === state_new instanceof StateAckWarp)
314
+ return false;
315
+
316
+ // The Warp gets to live for THE WARP'S creation time + TTL*2
317
+ const timeout_ms= time_ttl_rtt_(this.json_msgWarp.warp.ttl_msec);
318
+ logr_.log(l_.PROTOCOL_STATE, () => [`StateWarp: evt_AckWarp.dt@${state_new.evt_AckWarp.dt}, msgWarp.dt@${Date.parse(this.json_msgWarp.dt)} + ${timeout_ms}`])
319
+ if (state_new.evt_AckWarp.dt >= Date.parse(this.json_msgWarp.dt) + timeout_ms)
320
+ return false;
321
+
322
+ return true;
323
+ }
324
+ }
325
+
326
+ class StateINVALID extends StateState {
327
+ constructor(idx_event : number, event : EventMinimal) { super(idx_event, event); }
328
+ canChangeState(_state_new : StateState) {
329
+ // INVALID can't transition to any state
330
+ return false;
331
+ }
332
+ }
333
+
334
+ class StateInitialState extends StateState {
335
+ constructor() { super(null, null); }
336
+ canChangeState(state_new : StateState) {
337
+ if (false === state_new instanceof StateWarp)
338
+ return false;
339
+
340
+ // The NEWLY created Warp only gets to live for its creation time + TTL
341
+ const timeout_ms= state_new.json_msgWarp.warp.ttl_msec;
342
+ logr_.log(l_.PROTOCOL_STATE, () => [`StateInitialState: evt_Warp.dt@${state_new.evt_Warp.dt}, msgWarp.dt@${Date.parse(state_new.json_msgWarp.dt)} + ${timeout_ms}`])
343
+ if (state_new.evt_Warp.dt >= Date.parse(state_new.json_msgWarp.dt) + timeout_ms)
344
+ return false;
345
+
346
+ return true;
347
+ }
348
+ }
349
+
350
+ //----
351
+
352
+ class ProtocolStateState {
353
+ private _state : StateState;
354
+
355
+ constructor(state_initial? : StateState) {
356
+ this.state = state_initial || new StateInitialState();
357
+ }
358
+
359
+ set state(state_new : StateState) {
360
+ if (! (state_new instanceof StateState)) {
361
+ throw new Error("initState must be an instance of StateState or its subclasses");
362
+ }
363
+ this._state = state_new;
364
+ if (state_new && state_new.protocol !== this) {
365
+ state_new.protocol = this;
366
+ }
367
+ }
368
+ get state() : StateState {
369
+ return this._state;
370
+ }
371
+
372
+ canChangeState(state_new : StateState) : boolean {
373
+ // An exchange is a dialogue: a step we RECEIVE is only legal after a step we SENT, and vice
374
+ // versa. Every participant on the ME hears every exchange, so without this a warp we merely
375
+ // heard would be "answered" by the ack its real receiver sent, and we could answer our own step.
376
+ if (! (this._state instanceof StateInitialState) && this._state.event.data.b_sent === state_new.event.data.b_sent)
377
+ return false;
378
+
379
+ return this._state.canChangeState(state_new);
380
+ }
381
+ }
382
+
383
+ //-------------------------------------------------------------------------------------------------
384
+
385
+ const kstr_EVT_DROPPED_= '2PhW[DROPPED!]';
386
+
387
+ class TwoPhW_EventLog {
388
+ private _eventLog : EventLog;
389
+
390
+ constructor(eventLog : EventLog) {
391
+ this._eventLog = eventLog;
392
+ }
393
+
394
+ _warp(json_msg) {
395
+ const b_Ack = json_msg.ack !== undefined;
396
+ const json = b_Ack ? json_msg["_cause"] : json_msg;
397
+
398
+ if (json.warp) {
399
+ return {
400
+ str_type: b_Ack ? '2PhW[JSON_AckWarp]' : '2PhW[JSON_MsgWarp]',
401
+ json_msgWarp: json
402
+ };
403
+ }
404
+ if (json.engage) {
405
+ return {
406
+ str_type: b_Ack ? '2PhW[JSON_AckEngage]' : '2PhW[JSON_EffEngage]',
407
+ json_msgWarp: json["_cause"]
408
+ };
409
+ }
410
+ return { str_type: null, json_msgWarp: null }; // Explicit default for invalid cases
411
+ }
412
+
413
+ // _addEvent(msg: t_msg, json_msg : JSON_Msg, timeout_ms? : number, timeout_callback? : ( args? : {idx_event : number, event : EventMinimal} ) => {}) {
414
+ _addEvent(msg: t_msg, json_msg, b_sent : boolean, timeout_ms? : number, timeout_callback? : () => void) {
415
+ const { str_type, json_msgWarp }= this._warp(json_msg);
416
+ const { idx }= this._eventLog.add_Event(str_type, json_msgWarp.warp.id, {msg, json_msg, b_sent}, timeout_ms, timeout_callback);
417
+ logr_.log(l_.PROTOCOL_STATE, () => [`_addEvent: [${idx}] timeout:${Date.now()}+${timeout_ms} `, json_msg]);
418
+ }
419
+
420
+ // Record a message we refused, for forensics: under its exchange and in the shape of every other
421
+ // 2PhW event, but never a step -- traverse_State skips it.
422
+ _dropEvent(msg: t_msg, json_msg) {
423
+ const { json_msgWarp }= this._warp(json_msg);
424
+ if (! json_msgWarp)
425
+ return;
426
+ this._eventLog.add_Event(kstr_EVT_DROPPED_, json_msgWarp.warp.id, {msg, json_msg, b_sent: false});
427
+ }
428
+
429
+ _cancelTimeout(idx_event) {
430
+ logr_.log(l_.PROTOCOL_STATE, () => [`_cancelTimeout: [${idx_event}] timeout cancelled`]);
431
+ this._eventLog.cancel_timeout(idx_event);
432
+ }
433
+
434
+ traverse_State(json_msgWarp) {
435
+ const protocolState = new ProtocolStateState();
436
+
437
+ // Look back over the WHOLE exchange. Its longest window is the Warp's dt + TTL*2 + RTT (the
438
+ // AckEngage), and RTT <= TTL*2 (StateAckWarp refuses an Engage that claims more), so no step is
439
+ // legal more than TTL*4 after the Warp: the oldest event is never older than that.
440
+ const lookback_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec, json_msgWarp.warp.ttl_msec *2);
441
+ const arr_evts= this._eventLog.get_Events_by_id(json_msgWarp.warp.id, lookback_ms);
442
+ logr_.log(l_.EVENTS, () => ['traverse_State: arr_evts: ', arr_evts]);
443
+
444
+ for (let i = arr_evts.length - 1; i >= 0; i--) {
445
+ const { idx, evt } = arr_evts[i];
446
+
447
+ // a dropped message is not a step: not of this exchange, and it must not poison it either
448
+ // (it may well belong to ANOTHER exchange that reused the warp id -- that is why it was dropped)
449
+ if (evt.type === kstr_EVT_DROPPED_)
450
+ continue;
451
+
452
+ const json_msg= evt.data.json_msg;
453
+ if (! JSON_MsgWarp.compare(json_msgWarp, this._warp(json_msg).json_msgWarp) )
454
+ protocolState.state.changeState( new StateINVALID(idx, evt) );
455
+
456
+ switch(evt.type) {
457
+ case '2PhW[JSON_MsgWarp]' :
458
+ protocolState.state.changeState( new StateWarp(idx, evt) );
459
+ break;
460
+ case '2PhW[JSON_AckWarp]' :
461
+ protocolState.state.changeState( new StateAckWarp(idx, evt) );
462
+ break;
463
+ case '2PhW[JSON_EffEngage]' :
464
+ protocolState.state.changeState( new StateEngage(idx, evt) );
465
+ break;
466
+ case '2PhW[JSON_AckEngage]' :
467
+ protocolState.state.changeState( new StateAckEngage(idx, evt) );
468
+ break;
469
+ default :
470
+ break;
471
+ }
472
+
473
+ logr_.log(l_.PROTOCOL_STATE, () => ['traverse_State: type,state: ',
474
+ evt.type,
475
+ (protocolState.state.json_msg.ack?.ok === false) ? '--NACK--' : '',
476
+ protocolState.state
477
+ ]);
478
+ }
479
+ return protocolState;
480
+ }
481
+
482
+ }
483
+
484
+ class TwoPhW {
485
+ private _2PhW_eventLog : TwoPhW_EventLog;
486
+ private _config : Config;
487
+
488
+ constructor(eventLog : EventLog) {
489
+ this._2PhW_eventLog = new TwoPhW_EventLog(eventLog);
490
+ this._config= new Config();
491
+ }
492
+
493
+ get config() : Config {
494
+ return this._config;
495
+ }
496
+
497
+ get eventLog() : TwoPhW_EventLog {
498
+ return this._2PhW_eventLog;
499
+ }
500
+
501
+ //-------------------------------------------------------------------------------------------------
502
+
503
+ _handler_msgOptions(cfg, msg, json_msgOptions) : boolean
504
+ {
505
+ logr_.log(l_.HANDLERS, () => ['handler_msgOptions_: ...']);
506
+
507
+ /*
508
+ if (! validate_Options_delay_(json_msgOptions.options))
509
+ return false;
510
+
511
+ if (JSON_MsgWarp.validate(json_msgOptions._cause)) {
512
+ const json_msgWarp= json_msgOptions._cause;
513
+
514
+ const ctx= get_ctx(json_msgWarp.id);
515
+ if (!ctx )
516
+ return false;
517
+
518
+ const ttl_msec= json_msgOptions.options.ttl_msec_incr[0];
519
+ const ttl_incr= json_msgOptions.options.ttl_msec_incr[1];
520
+
521
+ //TODO: double check ttl_msec is the same as current accummulated ttl for idempotence.
522
+
523
+ logr_.log(l_.HANDLERS, () => ['handler_msgOptions_: ', json_msgOptions]);
524
+
525
+ ctx.protocol.delayTimeout(ttl_incr);
526
+
527
+ if (cfg._callback_msgOptions)
528
+ return cfg._callback_msgOptions(msg, json_msgOptions);
529
+
530
+ return true;
531
+ }
532
+ */
533
+
534
+ return false;
535
+ }
536
+
537
+ //-------------------------------------------------------------------------------------------------
538
+ // The typed handlers (handler_json_<message>) are what the responder's base dispatch calls AFTER it
539
+ // validated the message as that type (generated: `JSON_AckWarp.validate(json_ack) &&
540
+ // this.handler_json_ackWarp(msg, json_ack)`). They do not validate again.
541
+
542
+ //-------------------------------------------------------------------------------------------------
543
+ // sender Source (src)
544
+
545
+ register_msgWarp(msg : t_msg, json_msgWarp) : boolean
546
+ {
547
+ logr_.log(l_.SENDER, () => ['register_msgWarp: ', json_msgWarp]);
548
+
549
+ const protocolState= this.eventLog.traverse_State(json_msgWarp);
550
+ const b_changeState= protocolState.canChangeState( new StateWarp(null, {
551
+ dt: Date.now(),
552
+ data: { msg, json_msg: json_msgWarp, b_sent: true }
553
+ }) );
554
+
555
+ logr_.log(l_.HANDLERS | l_.SENDER, () => ['register_msgWarp: protocolState.canChangeState ', b_changeState]);
556
+ if (! b_changeState)
557
+ return false;
558
+
559
+ const timeout_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec);
560
+ const elapsed_ms= Date.now() - Date.parse(json_msgWarp.dt);
561
+
562
+ this.eventLog._addEvent(msg, json_msgWarp, true, timeout_ms-elapsed_ms, () => { // pass { _idx, _evt}?
563
+ this.config._callback_sender_sent_expired(msg, json_msgWarp);
564
+ });
565
+ return true;
566
+ }
567
+
568
+ handler_json_ackWarp(msg : t_msg, json_ackWarp) : boolean
569
+ {
570
+ logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_json_ackWarp: ', json_ackWarp]);
571
+
572
+ // no callback for this step: not ours -- before anything is logged
573
+ if (! this.config._callback_ackWarp)
574
+ return false;
575
+
576
+ const json_msgWarp= json_ackWarp._cause;
577
+
578
+ const protocolState= this.eventLog.traverse_State(json_msgWarp);
579
+ const b_changeState= protocolState.canChangeState( new StateAckWarp(null, {
580
+ dt: Date.now(),
581
+ data: { msg, json_msg: json_ackWarp, b_sent: false }
582
+ }) );
583
+
584
+ logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_json_ackWarp: protocolState.canChangeState ', b_changeState]);
585
+ if (! b_changeState)
586
+ return false;
587
+
588
+ this.eventLog._cancelTimeout(protocolState.state.idx_event);
589
+ this.eventLog._addEvent(msg, json_ackWarp, false);
590
+ return this.config._callback_ackWarp(msg, json_ackWarp);
591
+ }
592
+
593
+ register_effEngage(msg : t_msg, json_effEngage) : boolean
594
+ {
595
+ logr_.log(l_.SENDER, () => ['register_effEngage: ', json_effEngage]);
596
+
597
+ const json_msgWarp= json_effEngage._cause;
598
+
599
+ const protocolState= this.eventLog.traverse_State(json_msgWarp);
600
+ const b_changeState = protocolState.canChangeState( new StateEngage(null, {
601
+ dt: Date.now(),
602
+ data: { msg, json_msg: json_effEngage, b_sent: true }
603
+ }) );
604
+
605
+ logr_.log(l_.HANDLERS | l_.SENDER, () => ['register_effEngage: protocolState.canChangeState ', b_changeState]);
606
+ if (! b_changeState)
607
+ return false;
608
+
609
+ const timeout_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec, json_effEngage.engage.rtt_msec);
610
+ const elapsed_ms= Date.now() - Date.parse(json_msgWarp.dt);
611
+
612
+ this.eventLog._addEvent(msg, json_effEngage, true, timeout_ms-elapsed_ms, () => {
613
+ this.config._callback_sender_sent_expired(msg, json_effEngage);
614
+ });
615
+ return true;
616
+ }
617
+
618
+ handler_json_ackEngage(msg : t_msg, json_ackEngage) : boolean
619
+ {
620
+ logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_json_ackEngage: ', json_ackEngage]);
621
+
622
+ // no callback for this step: not ours -- before anything is logged
623
+ if (! this.config._callback_ackEngage)
624
+ return false;
625
+
626
+ const json_msgWarp= json_ackEngage._cause._cause;
627
+
628
+ const protocolState= this.eventLog.traverse_State(json_msgWarp);
629
+ const b_changeState= protocolState.canChangeState( new StateAckEngage(null, {
630
+ dt: Date.now(),
631
+ data: { msg, json_msg: json_ackEngage, b_sent: false }
632
+ }) );
633
+
634
+ logr_.log(l_.HANDLERS | l_.SENDER, () => ['handler_json_ackEngage: protocolState.canChangeState ', b_changeState]);
635
+ if (! b_changeState)
636
+ return false;
637
+
638
+ this.eventLog._cancelTimeout(protocolState.state.idx_event);
639
+ this.eventLog._addEvent(msg, json_ackEngage, false);
640
+ return this.config._callback_ackEngage(msg, json_ackEngage)
641
+ }
642
+
643
+ //-------------------------------------------------------------------------------------------------
644
+ // receiver Destination (dst)
645
+
646
+ handler_json_msgWarp(msg : t_msg, json_msgWarp) : boolean
647
+ {
648
+ logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_json_msgWarp: ', json_msgWarp]);
649
+
650
+ // no callback for this step: not ours -- before anything is logged
651
+ if (! this.config._callback_msgWarp)
652
+ return false;
653
+
654
+ const protocolState= this.eventLog.traverse_State(json_msgWarp);
655
+ const b_changeState= protocolState.canChangeState( new StateWarp(null, {
656
+ dt: Date.now(),
657
+ data: { msg, json_msg: json_msgWarp, b_sent: false }
658
+ }) );
659
+
660
+ logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_json_msgWarp: protocolState.canChangeState: ', b_changeState]);
661
+ if (! b_changeState)
662
+ return false;
663
+
664
+ this.eventLog._addEvent(msg, json_msgWarp, false);
665
+ return this.config._callback_msgWarp(msg, json_msgWarp)
666
+ }
667
+
668
+ register_ackWarp(msg: t_msg, json_ackWarp) : boolean
669
+ {
670
+ logr_.log(l_.RECVER, () => ['register_ackWarp: ', json_ackWarp]);
671
+
672
+ const json_msgWarp= json_ackWarp._cause;
673
+
674
+ const protocolState= this.eventLog.traverse_State(json_msgWarp);
675
+ const b_changeState= protocolState.canChangeState( new StateAckWarp(null, {
676
+ dt: Date.now(),
677
+ data: { msg, json_msg: json_ackWarp, b_sent: true }
678
+ }) );
679
+
680
+ logr_.log(l_.HANDLERS | l_.RECVER, () => ['register_ackWarp: protocolState.canChangeState: ', b_changeState]);
681
+ if (! b_changeState)
682
+ return false;
683
+
684
+ // The expiry means "the Engage I was waiting for never came". An ack no Engage can follow
685
+ // concludes the exchange and awaits nothing: logged, with no timer.
686
+ if (! isEngageAwaited_(json_ackWarp)) {
687
+ this.eventLog._addEvent(msg, json_ackWarp, true);
688
+ return true;
689
+ }
690
+
691
+ const elapsed_ms= Date.now() - Date.parse(json_ackWarp.dt);
692
+ const timeout_ms= time_ttl_rtt_(json_msgWarp.warp.ttl_msec) + Date.parse(json_ackWarp.dt) - Date.parse(json_msgWarp.dt);
693
+
694
+ this.eventLog._addEvent(msg, json_ackWarp, true, timeout_ms-elapsed_ms, () => { // pass { _idx, _evt} ?
695
+ this.config._callback_receiver_sent_expired(msg, json_ackWarp);
696
+ });
697
+ return true;
698
+ }
699
+
700
+ handler_json_effEngage(msg : t_msg, json_effEngage) : boolean
701
+ {
702
+ logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_json_effEngage: ', json_effEngage]);
703
+
704
+ // no callback for this step: not ours -- before anything is logged
705
+ if (! this.config._callback_effEngage)
706
+ return false;
707
+
708
+ const json_msgWarp= json_effEngage._cause;
709
+
710
+ const protocolState= this.eventLog.traverse_State(json_msgWarp);
711
+ const b_changeState= protocolState.canChangeState( new StateEngage(null, {
712
+ dt: Date.now(),
713
+ data: { msg, json_msg: json_effEngage, b_sent: false }
714
+ }) );
715
+
716
+ logr_.log(l_.HANDLERS | l_.RECVER, () => ['handler_json_effEngage: protocolState.canChangeState: ', b_changeState]);
717
+ if (! b_changeState)
718
+ return false;
719
+
720
+ this.eventLog._cancelTimeout(protocolState.state.idx_event);
721
+ this.eventLog._addEvent(msg, json_effEngage, false);
722
+ return this.config._callback_effEngage(msg, json_effEngage)
723
+ }
724
+
725
+ register_ackEngage(msg : t_msg, json_ackEngage) : boolean
726
+ {
727
+ logr_.log(l_.RECVER, () => ['register_ackEngage: ', json_ackEngage]);
728
+
729
+ const json_msgWarp= json_ackEngage._cause._cause;
730
+
731
+ const protocolState= this.eventLog.traverse_State(json_msgWarp);
732
+ const b_changeState= protocolState.canChangeState( new StateAckEngage(null, {
733
+ dt: Date.now(),
734
+ data: { msg, json_msg: json_ackEngage, b_sent: true }
735
+ }) );
736
+
737
+ logr_.log(l_.HANDLERS | l_.RECVER, () => ['register_ackEngage: protocolState.canChangeState: ', b_changeState]);
738
+ if (! b_changeState)
739
+ return false;
740
+
741
+ this.eventLog._addEvent(msg, json_ackEngage, true);
742
+ return true;
743
+ }
744
+
745
+ };
746
+
747
+ //-------------------------------------------------------------------------------------------------
748
+
749
+ export {
750
+ time_ttl_rtt_ as t_ttl_rtt,
751
+ TwoPhW,
752
+ JSON_MsgOptions,
753
+ JSON_MsgWarp,
754
+ JSON_EffEngage,
755
+ JSON_AckWarp,
756
+ JSON_AckEngage,
757
+ logr_ as logr,
758
+ JSON_Msg,
759
+ JSON_Eff,
760
+ JSON_Ack,
761
+ k_VERSION as VERSION,
762
+ // -----
763
+ StateAckEngage,
764
+ StateEngage,
765
+ StateAckWarp,
766
+ StateWarp,
767
+ StateINVALID,
768
+ StateInitialState
769
+ };
770
+