@rootintf/protocol-2phw 1.2.1-api.1 → 1.3.3-api.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dev.txt +16 -0
- package/dist/ajv-gen-validate.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/twoPhW.cjs.js +329 -193
- package/dist/twoPhW.d.ts +16 -16
- package/dist/twoPhW.es.mjs +329 -193
- package/package.json +11 -10
- package/src/index.ts +1 -0
- package/src/twoPhW.ts +54 -84
package/dist/twoPhW.cjs.js
CHANGED
|
@@ -1,6 +1,182 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const schema_MsgWarp = validate19;
|
|
3
|
+
const schema_MsgWarp = validate19;
|
|
4
|
+
function validate19(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate19.evaluated; if (evaluated0.dynamicProps) {
|
|
5
|
+
evaluated0.props = undefined;
|
|
6
|
+
} if (evaluated0.dynamicItems) {
|
|
7
|
+
evaluated0.items = undefined;
|
|
8
|
+
} {
|
|
9
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
10
|
+
let missing0;
|
|
11
|
+
if ((data.warp === undefined) && (missing0 = "warp")) {
|
|
12
|
+
validate19.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
if (data.warp !== undefined) {
|
|
17
|
+
let data0 = data.warp;
|
|
18
|
+
const _errs1 = errors;
|
|
19
|
+
{
|
|
20
|
+
if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
|
|
21
|
+
let missing1;
|
|
22
|
+
if (((((data0.id === undefined) && (missing1 = "id")) || ((data0.user === undefined) && (missing1 = "user"))) || ((data0.hyperport === undefined) && (missing1 = "hyperport"))) || ((data0.ttl_msec === undefined) && (missing1 = "ttl_msec"))) {
|
|
23
|
+
validate19.errors = [{ instancePath: instancePath + "/warp", schemaPath: "#/properties/warp/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }];
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
if (data0.id !== undefined) {
|
|
28
|
+
const _errs3 = errors;
|
|
29
|
+
if (typeof data0.id !== "string") {
|
|
30
|
+
validate19.errors = [{ instancePath: instancePath + "/warp/id", schemaPath: "definitions#/definitions/warp_id/type", keyword: "type", params: { type: "string" }, message: "must be string" }];
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
var valid1 = _errs3 === errors;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
var valid1 = true;
|
|
37
|
+
}
|
|
38
|
+
if (valid1) {
|
|
39
|
+
if (data0.ttl_msec !== undefined) {
|
|
40
|
+
let data2 = data0.ttl_msec;
|
|
41
|
+
const _errs6 = errors;
|
|
42
|
+
if (!(((typeof data2 == "number") && (!(data2 % 1) && !isNaN(data2))) && (isFinite(data2)))) {
|
|
43
|
+
validate19.errors = [{ instancePath: instancePath + "/warp/ttl_msec", schemaPath: "#/properties/warp/properties/ttl_msec/type", keyword: "type", params: { type: "integer" }, message: "must be integer" }];
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
var valid1 = _errs6 === errors;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
var valid1 = true;
|
|
50
|
+
}
|
|
51
|
+
if (valid1) {
|
|
52
|
+
if (data0.instantaneous !== undefined) {
|
|
53
|
+
const _errs8 = errors;
|
|
54
|
+
if (typeof data0.instantaneous !== "boolean") {
|
|
55
|
+
validate19.errors = [{ instancePath: instancePath + "/warp/instantaneous", schemaPath: "#/properties/warp/properties/instantaneous/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
var valid1 = _errs8 === errors;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
var valid1 = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
validate19.errors = [{ instancePath: instancePath + "/warp", schemaPath: "#/properties/warp/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
var valid0 = _errs1 === errors;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
var valid0 = true;
|
|
76
|
+
}
|
|
77
|
+
if (valid0) {
|
|
78
|
+
if (data["2PhW"] !== undefined) {
|
|
79
|
+
const _errs10 = errors;
|
|
80
|
+
if ("1" !== data["2PhW"]) {
|
|
81
|
+
validate19.errors = [{ instancePath: instancePath + "/2PhW", schemaPath: "definitions#/definitions/2PhW/const", keyword: "const", params: { allowedValue: "1" }, message: "must be equal to constant" }];
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
var valid0 = _errs10 === errors;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
var valid0 = true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
validate19.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
} validate19.errors = vErrors; return errors === 0; }
|
|
97
|
+
validate19.evaluated = { "props": { "warp": true, "2PhW": true }, "dynamicProps": false, "dynamicItems": false };
|
|
98
|
+
const schema_MsgEngage = validate20;
|
|
99
|
+
function validate20(data, { instancePath = "", parentData, parentDataProperty, rootData = data, dynamicAnchors = {} } = {}) { let vErrors = null; let errors = 0; const evaluated0 = validate20.evaluated; if (evaluated0.dynamicProps) {
|
|
100
|
+
evaluated0.props = undefined;
|
|
101
|
+
} if (evaluated0.dynamicItems) {
|
|
102
|
+
evaluated0.items = undefined;
|
|
103
|
+
} {
|
|
104
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
105
|
+
let missing0;
|
|
106
|
+
if ((data.engage === undefined) && (missing0 = "engage")) {
|
|
107
|
+
validate20.errors = [{ instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: missing0 }, message: "must have required property '" + missing0 + "'" }];
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
if (data.engage !== undefined) {
|
|
112
|
+
let data0 = data.engage;
|
|
113
|
+
const _errs1 = errors;
|
|
114
|
+
{
|
|
115
|
+
if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
|
|
116
|
+
let missing1;
|
|
117
|
+
if (((data0.ok === undefined) && (missing1 = "ok")) || ((data0.rtt_msec === undefined) && (missing1 = "rtt_msec"))) {
|
|
118
|
+
validate20.errors = [{ instancePath: instancePath + "/engage", schemaPath: "#/properties/engage/required", keyword: "required", params: { missingProperty: missing1 }, message: "must have required property '" + missing1 + "'" }];
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
if (data0.ok !== undefined) {
|
|
123
|
+
const _errs3 = errors;
|
|
124
|
+
if (typeof data0.ok !== "boolean") {
|
|
125
|
+
validate20.errors = [{ instancePath: instancePath + "/engage/ok", schemaPath: "#/properties/engage/properties/ok/type", keyword: "type", params: { type: "boolean" }, message: "must be boolean" }];
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
var valid1 = _errs3 === errors;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
var valid1 = true;
|
|
132
|
+
}
|
|
133
|
+
if (valid1) {
|
|
134
|
+
if (data0.rtt_msec !== undefined) {
|
|
135
|
+
let data2 = data0.rtt_msec;
|
|
136
|
+
const _errs5 = errors;
|
|
137
|
+
if (!(((typeof data2 == "number") && (!(data2 % 1) && !isNaN(data2))) && (isFinite(data2)))) {
|
|
138
|
+
validate20.errors = [{ instancePath: instancePath + "/engage/rtt_msec", schemaPath: "#/properties/engage/properties/rtt_msec/type", keyword: "type", params: { type: "integer" }, message: "must be integer" }];
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
var valid1 = _errs5 === errors;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
var valid1 = true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
validate20.errors = [{ instancePath: instancePath + "/engage", schemaPath: "#/properties/engage/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
var valid0 = _errs1 === errors;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
var valid0 = true;
|
|
158
|
+
}
|
|
159
|
+
if (valid0) {
|
|
160
|
+
if (data["2PhW"] !== undefined) {
|
|
161
|
+
const _errs7 = errors;
|
|
162
|
+
if ("1" !== data["2PhW"]) {
|
|
163
|
+
validate20.errors = [{ instancePath: instancePath + "/2PhW", schemaPath: "definitions#/definitions/2PhW/const", keyword: "const", params: { allowedValue: "1" }, message: "must be equal to constant" }];
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
var valid0 = _errs7 === errors;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
var valid0 = true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
validate20.errors = [{ instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" }];
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
} validate20.errors = vErrors; return errors === 0; }
|
|
179
|
+
validate20.evaluated = { "props": { "engage": true, "2PhW": true }, "dynamicProps": false, "dynamicItems": false };
|
|
4
180
|
|
|
5
181
|
// console.log('OUT', __name({variableName}) );
|
|
6
182
|
|
|
@@ -433,139 +609,118 @@ function requireJsonMsg_cjs () {
|
|
|
433
609
|
|
|
434
610
|
var jsonMsg_cjsExports = requireJsonMsg_cjs();
|
|
435
611
|
|
|
436
|
-
//-------------------------------------------------------------------------------------------------
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
//
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
const timeout_id
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
const evt = this.arr_events[idx];
|
|
549
|
-
if (evt.dt < cutoff) {
|
|
550
|
-
break; // Stop once we pass the cutoff
|
|
551
|
-
}
|
|
552
|
-
if (predicate(evt)) {
|
|
553
|
-
result.push({ idx, evt });
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
return result; // Newest to oldest order
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
// setLogr(obj_logr) {
|
|
561
|
-
// this.logr.toggled = obj_logr;
|
|
562
|
-
// }
|
|
563
|
-
|
|
564
|
-
clear() {
|
|
565
|
-
this.cancelAllTimeouts(); // Clear all timeouts before clearing events
|
|
566
|
-
this.arr_events.length = 0;
|
|
567
|
-
this.map_index_id.clear();
|
|
568
|
-
}
|
|
612
|
+
//-------------------------------------------------------------------------------------------------
|
|
613
|
+
let LOGR_$1 = LOGR.get_instance();
|
|
614
|
+
const log_$1 = LOGR_$1.log;
|
|
615
|
+
const l_$1 = {
|
|
616
|
+
EVENTS: 0b1 << 0,
|
|
617
|
+
TIMEOUTS: 0b1 << 1,
|
|
618
|
+
};
|
|
619
|
+
LOGR_$1.labels = l_$1;
|
|
620
|
+
// LOGR_.toggled= {
|
|
621
|
+
// EVENTS : 1
|
|
622
|
+
// }
|
|
623
|
+
//-------------------------------------------------------------------------------------------------
|
|
624
|
+
class EventLog {
|
|
625
|
+
constructor() {
|
|
626
|
+
this.arr_events = []; // In-memory event store
|
|
627
|
+
this.map_index_id = new Map(); // Map of id -> array of indices into arr_events; arr_events[idx]
|
|
628
|
+
this.map_timeouts = new Map(); // Store timeout references: idx -> timeout_id
|
|
629
|
+
}
|
|
630
|
+
addEvent(type, id, data, timeout_ms = null, timeout_callback = null) {
|
|
631
|
+
const evt = {
|
|
632
|
+
type,
|
|
633
|
+
dt: Date.now(),
|
|
634
|
+
id,
|
|
635
|
+
data,
|
|
636
|
+
timeout_id: null // Will store timeout reference if set
|
|
637
|
+
};
|
|
638
|
+
const idx = this.arr_events.push(evt) - 1; // More efficient than .length before push
|
|
639
|
+
let arr_indices = this.map_index_id.get(id);
|
|
640
|
+
if (!arr_indices) {
|
|
641
|
+
arr_indices = [];
|
|
642
|
+
this.map_index_id.set(id, arr_indices);
|
|
643
|
+
}
|
|
644
|
+
arr_indices.push(idx);
|
|
645
|
+
// Set timeout if specified
|
|
646
|
+
if (timeout_ms && timeout_callback) {
|
|
647
|
+
evt.timeout_id = setTimeout(() => {
|
|
648
|
+
if (this.map_timeouts.delete(idx)) {
|
|
649
|
+
evt.timeout_id = null;
|
|
650
|
+
timeout_callback({ idx, evt });
|
|
651
|
+
log_$1(l_$1.EVENTS, () => [`Event DELETED[${idx}]: ${type}`, evt]);
|
|
652
|
+
}
|
|
653
|
+
}, timeout_ms);
|
|
654
|
+
this.map_timeouts.set(idx, evt.timeout_id);
|
|
655
|
+
}
|
|
656
|
+
// the error "toISOString is not a function" occurs because Date(evt.dt) is not doing what you expect.
|
|
657
|
+
// When you pass a number to the Date constructor without using new, it doesn’t return a Date object—it returns a string. Specifically, it’s equivalent to new Date(evt.dt).toString().
|
|
658
|
+
// Date(evt.dt).toISOString() -> new Date(evt.dt).toISOString()
|
|
659
|
+
log_$1(l_$1.EVENTS, () => [`Event added[${idx}] @${new Date(evt.dt).toISOString()}: ${type}`, evt]);
|
|
660
|
+
return { idx, evt };
|
|
661
|
+
}
|
|
662
|
+
cancelTimeout(idx) {
|
|
663
|
+
const timeout_id = this.map_timeouts.get(idx);
|
|
664
|
+
if (timeout_id) {
|
|
665
|
+
clearTimeout(timeout_id);
|
|
666
|
+
this.map_timeouts.delete(idx);
|
|
667
|
+
if (this.arr_events[idx])
|
|
668
|
+
this.arr_events[idx].timeout_id = null;
|
|
669
|
+
return true;
|
|
670
|
+
}
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
cancelAllTimeouts() {
|
|
674
|
+
for (const [idx, timeout_id] of this.map_timeouts) {
|
|
675
|
+
clearTimeout(timeout_id);
|
|
676
|
+
if (this.arr_events[idx])
|
|
677
|
+
this.arr_events[idx].timeout_id = null;
|
|
678
|
+
}
|
|
679
|
+
this.map_timeouts.clear();
|
|
680
|
+
}
|
|
681
|
+
getEventsById(id, lookback_ms = null) {
|
|
682
|
+
const arr_indices = this.map_index_id.get(id);
|
|
683
|
+
if (!arr_indices?.length)
|
|
684
|
+
return [];
|
|
685
|
+
const result = [];
|
|
686
|
+
const cutoff = lookback_ms !== null ? Date.now() - lookback_ms : -Infinity;
|
|
687
|
+
// Single loop with early cutoff
|
|
688
|
+
for (let i = arr_indices.length - 1; i >= 0; i--) {
|
|
689
|
+
const idx = arr_indices[i];
|
|
690
|
+
const evt = this.arr_events[idx];
|
|
691
|
+
if (evt.dt < cutoff)
|
|
692
|
+
break;
|
|
693
|
+
result.push({ idx, evt });
|
|
694
|
+
}
|
|
695
|
+
return result; // Newest to oldest order
|
|
696
|
+
}
|
|
697
|
+
// getRecentEvents(id, lookbackMs) {
|
|
698
|
+
// const cutoff = Date.now() - lookbackMs;
|
|
699
|
+
// return this.events.filter(e => e.id === id && e.dt >= cutoff);
|
|
700
|
+
// }
|
|
701
|
+
getEvents(lookback_ms, predicate) {
|
|
702
|
+
const cutoff = Date.now() - lookback_ms;
|
|
703
|
+
const result = [];
|
|
704
|
+
// Iterate backwards from the end
|
|
705
|
+
for (let idx = this.arr_events.length - 1; idx >= 0; idx--) {
|
|
706
|
+
const evt = this.arr_events[idx];
|
|
707
|
+
if (evt.dt < cutoff) {
|
|
708
|
+
break; // Stop once we pass the cutoff
|
|
709
|
+
}
|
|
710
|
+
if (predicate(evt)) {
|
|
711
|
+
result.push({ idx, evt });
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return result; // Newest to oldest order
|
|
715
|
+
}
|
|
716
|
+
// setLogr(obj_logr) {
|
|
717
|
+
// this.logr.toggled = obj_logr;
|
|
718
|
+
// }
|
|
719
|
+
clear() {
|
|
720
|
+
this.cancelAllTimeouts(); // Clear all timeouts before clearing events
|
|
721
|
+
this.arr_events.length = 0;
|
|
722
|
+
this.map_index_id.clear();
|
|
723
|
+
}
|
|
569
724
|
}
|
|
570
725
|
|
|
571
726
|
// interface Event extends Required<EventMinimal> {
|
|
@@ -573,9 +728,6 @@ class EventLog {
|
|
|
573
728
|
// id : string | number;
|
|
574
729
|
// timeout_id : NodeJS.Timeout | null;
|
|
575
730
|
// };
|
|
576
|
-
const k_ERROR = -1;
|
|
577
|
-
const k_NOP = 0;
|
|
578
|
-
// const k_HANDLED = 1;
|
|
579
731
|
const k_TTL = 20000;
|
|
580
732
|
//-------------------------------------------------------------------------------------------------
|
|
581
733
|
const LOGR_ = LOGR.get_instance();
|
|
@@ -595,19 +747,19 @@ class Config {
|
|
|
595
747
|
// Initialize callbacks as no-op functions
|
|
596
748
|
this._callback_msgWarp = (_msg, _json_msg) => {
|
|
597
749
|
console.assert(false, 'callback_msgWarp uninitialized');
|
|
598
|
-
return
|
|
750
|
+
return false;
|
|
599
751
|
};
|
|
600
752
|
this._callback_msgEngage = (_msg, _json_msg) => {
|
|
601
753
|
console.assert(false, 'callback_msgEngage uninitialized');
|
|
602
|
-
return
|
|
754
|
+
return false;
|
|
603
755
|
};
|
|
604
756
|
this._callback_msgAckWarp = (_msg, _json_msg) => {
|
|
605
757
|
console.assert(false, 'callback_msgAckWarp uninitialized');
|
|
606
|
-
return
|
|
758
|
+
return false;
|
|
607
759
|
};
|
|
608
760
|
this._callback_msgAckEngage = (_msg, _json_msg) => {
|
|
609
761
|
console.assert(false, 'callback_msgAckEngage uninitialized');
|
|
610
|
-
return
|
|
762
|
+
return false;
|
|
611
763
|
};
|
|
612
764
|
this._callback_msg_sent_expired = (_msg, _json_msg) => {
|
|
613
765
|
console.assert(false, '_callback_msg_sent_expired uninitialized');
|
|
@@ -645,7 +797,7 @@ class Config {
|
|
|
645
797
|
let k_VERSION = "1";
|
|
646
798
|
// rtt_msec <= ttl_msec *2 => rtt_msec = ttl_msec *2
|
|
647
799
|
// t_ttl_rtt_(TTL, RTT) = t_ttl_rtt_(TTL, TTL *2) = TTL *2 + TTL *2 = TTL *4 MAX
|
|
648
|
-
function
|
|
800
|
+
function time_ttl_rtt_(ttl_msec, rtt_msec) {
|
|
649
801
|
if (ttl_msec === undefined)
|
|
650
802
|
return undefined;
|
|
651
803
|
if (rtt_msec === undefined)
|
|
@@ -837,7 +989,7 @@ class StateEngage extends StateState {
|
|
|
837
989
|
return false;
|
|
838
990
|
// The Engage gets to live for THE WARP'S creation time + TTL*2 + RTT
|
|
839
991
|
const json_msgWarp = this.json_msgEngage._msg;
|
|
840
|
-
const timeout_ms =
|
|
992
|
+
const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec, this.json_msgEngage.engage.rtt_msec);
|
|
841
993
|
log_(l_.PROTOCOL_STATE, () => [`StateEngage: evt_AckEngage.dt@${state_new.evt_AckEngage.dt}, msgWarp.dt@${Date.parse(json_msgWarp.dt)} + ${timeout_ms}`]);
|
|
842
994
|
if (state_new.evt_AckEngage.dt >= Date.parse(json_msgWarp.dt) + timeout_ms)
|
|
843
995
|
return false;
|
|
@@ -860,7 +1012,7 @@ class StateAckWarp extends StateState {
|
|
|
860
1012
|
// - Engage: T0 +2TTL +RTT; RTT= STT+STT
|
|
861
1013
|
// - AckWarp: TAckWarp +2TLL +STT; TAckWarp= T0 +STT;
|
|
862
1014
|
// - STT: Date of the Ack minus date of the Warp.
|
|
863
|
-
const timeout_ms =
|
|
1015
|
+
const timeout_ms = time_ttl_rtt_(this.json_msgAckWarp._msg.warp.ttl_msec) + Date.parse(this.json_msgAckWarp.dt) - Date.parse(this.json_msgAckWarp._msg.dt);
|
|
864
1016
|
log_(l_.PROTOCOL_STATE, () => [`StateAckWarp: evt_Engage.dt@${state_new.evt_Engage.dt}, msgAckWarp.dt@${Date.parse(this.json_msgAckWarp.dt)} + ${timeout_ms}`]);
|
|
865
1017
|
if (state_new.evt_Engage.dt >= Date.parse(this.json_msgAckWarp.dt) + timeout_ms)
|
|
866
1018
|
return false;
|
|
@@ -875,7 +1027,7 @@ class StateWarp extends StateState {
|
|
|
875
1027
|
if (false === state_new instanceof StateAckWarp)
|
|
876
1028
|
return false;
|
|
877
1029
|
// The Warp gets to live for THE WARP'S creation time + TTL*2
|
|
878
|
-
const timeout_ms =
|
|
1030
|
+
const timeout_ms = time_ttl_rtt_(this.json_msgWarp.warp.ttl_msec);
|
|
879
1031
|
log_(l_.PROTOCOL_STATE, () => [`StateWarp: evt_AckWarp.dt@${state_new.evt_AckWarp.dt}, msgWarp.dt@${Date.parse(this.json_msgWarp.dt)} + ${timeout_ms}`]);
|
|
880
1032
|
if (state_new.evt_AckWarp.dt >= Date.parse(this.json_msgWarp.dt) + timeout_ms)
|
|
881
1033
|
return false;
|
|
@@ -1038,7 +1190,7 @@ class TwoPhW {
|
|
|
1038
1190
|
return true;
|
|
1039
1191
|
}
|
|
1040
1192
|
*/
|
|
1041
|
-
return
|
|
1193
|
+
return false;
|
|
1042
1194
|
}
|
|
1043
1195
|
//-------------------------------------------------------------------------------------------------
|
|
1044
1196
|
// sender Source (src)
|
|
@@ -1051,8 +1203,8 @@ class TwoPhW {
|
|
|
1051
1203
|
}));
|
|
1052
1204
|
log_(l_.HANDLERS | l_.SENDER, () => ['register_msgWarp: protocolState.canChangeState ', b_changeState]);
|
|
1053
1205
|
if (!b_changeState)
|
|
1054
|
-
return
|
|
1055
|
-
const timeout_ms =
|
|
1206
|
+
return false;
|
|
1207
|
+
const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec);
|
|
1056
1208
|
const elapsed_ms = Date.now() - Date.parse(json_msgWarp.dt);
|
|
1057
1209
|
this.eventLog._addEvent(msg, json_msgWarp, timeout_ms - elapsed_ms, () => {
|
|
1058
1210
|
this.config._callback_msg_sent_expired(msg, json_msgWarp);
|
|
@@ -1068,7 +1220,7 @@ class TwoPhW {
|
|
|
1068
1220
|
}));
|
|
1069
1221
|
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: protocolState.canChangeState ', b_changeState]);
|
|
1070
1222
|
if (!b_changeState)
|
|
1071
|
-
return
|
|
1223
|
+
return false;
|
|
1072
1224
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
1073
1225
|
this.eventLog._addEvent(msg, json_msgAckWarp);
|
|
1074
1226
|
return this.config._callback_msgAckWarp(msg, json_msgAckWarp);
|
|
@@ -1083,8 +1235,8 @@ class TwoPhW {
|
|
|
1083
1235
|
}));
|
|
1084
1236
|
log_(l_.HANDLERS | l_.SENDER, () => ['register_msgEngage: protocolState.canChangeState ', b_changeState]);
|
|
1085
1237
|
if (!b_changeState)
|
|
1086
|
-
return
|
|
1087
|
-
const timeout_ms =
|
|
1238
|
+
return false;
|
|
1239
|
+
const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec, json_msgEngage.engage.rtt_msec);
|
|
1088
1240
|
const elapsed_ms = Date.now() - Date.parse(json_msgWarp.dt);
|
|
1089
1241
|
this.eventLog._addEvent(msg, json_msgEngage, timeout_ms - elapsed_ms, () => {
|
|
1090
1242
|
this.config._callback_msg_sent_expired(msg, json_msgEngage);
|
|
@@ -1100,7 +1252,7 @@ class TwoPhW {
|
|
|
1100
1252
|
}));
|
|
1101
1253
|
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage_: protocolState.canChangeState ', b_changeState]);
|
|
1102
1254
|
if (!b_changeState)
|
|
1103
|
-
return
|
|
1255
|
+
return false;
|
|
1104
1256
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
1105
1257
|
this.eventLog._addEvent(msg, json_msgAckEngage);
|
|
1106
1258
|
return this.config._callback_msgAckEngage(msg, json_msgAckEngage);
|
|
@@ -1116,7 +1268,7 @@ class TwoPhW {
|
|
|
1116
1268
|
}));
|
|
1117
1269
|
log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: protocolState.canChangeState: ', b_changeState]);
|
|
1118
1270
|
if (!b_changeState)
|
|
1119
|
-
return
|
|
1271
|
+
return false;
|
|
1120
1272
|
this.eventLog._addEvent(msg, json_msgWarp);
|
|
1121
1273
|
return this.config._callback_msgWarp(msg, json_msgWarp);
|
|
1122
1274
|
}
|
|
@@ -1130,9 +1282,9 @@ class TwoPhW {
|
|
|
1130
1282
|
}));
|
|
1131
1283
|
log_(l_.HANDLERS | l_.RECVER, () => ['register_msgAckWarp: protocolState.canChangeState: ', b_changeState]);
|
|
1132
1284
|
if (!b_changeState)
|
|
1133
|
-
return
|
|
1285
|
+
return false;
|
|
1134
1286
|
const elapsed_ms = Date.now() - Date.parse(json_msgAckWarp.dt);
|
|
1135
|
-
const timeout_ms =
|
|
1287
|
+
const timeout_ms = time_ttl_rtt_(json_msgWarp.warp.ttl_msec) + Date.parse(json_msgAckWarp.dt) - Date.parse(json_msgWarp.dt);
|
|
1136
1288
|
this.eventLog._addEvent(msg, json_msgAckWarp, timeout_ms - elapsed_ms, () => {
|
|
1137
1289
|
this.config._callback_msg_sent_expired(msg, json_msgAckWarp);
|
|
1138
1290
|
});
|
|
@@ -1147,7 +1299,7 @@ class TwoPhW {
|
|
|
1147
1299
|
}));
|
|
1148
1300
|
log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: protocolState.canChangeState: ', b_changeState]);
|
|
1149
1301
|
if (!b_changeState)
|
|
1150
|
-
return
|
|
1302
|
+
return false;
|
|
1151
1303
|
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
1152
1304
|
this.eventLog._addEvent(msg, json_msgEngage);
|
|
1153
1305
|
return this.config._callback_msgEngage(msg, json_msgEngage);
|
|
@@ -1162,33 +1314,32 @@ class TwoPhW {
|
|
|
1162
1314
|
}));
|
|
1163
1315
|
log_(l_.HANDLERS | l_.RECVER, () => ['register_msgAckEngage: protocolState.canChangeState: ', b_changeState]);
|
|
1164
1316
|
if (!b_changeState)
|
|
1165
|
-
return
|
|
1317
|
+
return false;
|
|
1166
1318
|
this.eventLog._addEvent(msg, json_msgAckEngage);
|
|
1167
1319
|
}
|
|
1168
1320
|
//-------------------------------------------------------------------------------------------------
|
|
1169
1321
|
handler_json_msgAck_msg(msg, json_msgAck_msg) {
|
|
1170
1322
|
log_(l_.HANDLERS, () => ['handler_json_msgAck_msg: ', json_msgAck_msg]);
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
return k_NOP;
|
|
1323
|
+
if (JSON_MsgAckWarp.validate(json_msgAck_msg) && this._handler_msgAckWarp(msg, json_msgAck_msg))
|
|
1324
|
+
return true;
|
|
1325
|
+
if (JSON_MsgAckEngage.validate(json_msgAck_msg) && this._handler_msgAckEngage(msg, json_msgAck_msg))
|
|
1326
|
+
return true;
|
|
1327
|
+
return false;
|
|
1177
1328
|
}
|
|
1178
1329
|
handler_json_msg_msg(msg, json_msg_msg) {
|
|
1179
1330
|
log_(l_.HANDLERS, () => ['handler_json_msg_msg: ', json_msg_msg]);
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1331
|
+
if (jsonMsg_cjsExports.JSON_MsgAck_msg.validate(json_msg_msg) && this.handler_json_msgAck_msg(msg, json_msg_msg))
|
|
1332
|
+
return true;
|
|
1333
|
+
if (JSON_MsgEngage.validate(json_msg_msg) && this._handler_msgEngage(msg, json_msg_msg))
|
|
1334
|
+
return true;
|
|
1183
1335
|
// if (JSON_MsgOptions.validate(json_msg) && this.handler_msgOptions_(this._config, msg, json_msg))
|
|
1184
1336
|
// return true;
|
|
1185
|
-
return
|
|
1337
|
+
return false;
|
|
1186
1338
|
}
|
|
1187
1339
|
handler_json_msg(msg, json_msg) {
|
|
1188
1340
|
log_(l_.HANDLERS, () => ['handler_json_msg: ', json_msg]);
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
return ret;
|
|
1341
|
+
if (JSON_MsgWarp.validate(json_msg) && this._handler_msgWarp(msg, json_msg))
|
|
1342
|
+
return true;
|
|
1192
1343
|
// https://attacomsian.com/blog/javascript-iterate-objects
|
|
1193
1344
|
// Object.keys(json_msg).forEach((key, index) => {
|
|
1194
1345
|
// if (key == 'dt')
|
|
@@ -1197,30 +1348,15 @@ class TwoPhW {
|
|
|
1197
1348
|
// return;
|
|
1198
1349
|
// console.log(`${key}: ${json_msg[key]}`);
|
|
1199
1350
|
// });
|
|
1200
|
-
return
|
|
1351
|
+
return false;
|
|
1201
1352
|
}
|
|
1202
1353
|
handler_json(msg, json) {
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
if (JSON_MsgAckEngage.validate(json) && (ret = this._handler_msgAckEngage(msg, json)))
|
|
1210
|
-
return ret;
|
|
1211
|
-
return k_NOP;
|
|
1212
|
-
}
|
|
1213
|
-
let ret;
|
|
1214
|
-
if (JSON_MsgEngage.validate(json) && (ret = this._handler_msgEngage(msg, json)))
|
|
1215
|
-
return ret;
|
|
1216
|
-
return k_NOP;
|
|
1217
|
-
}
|
|
1218
|
-
let ret;
|
|
1219
|
-
if (JSON_MsgWarp.validate(json) && (ret = this._handler_msgWarp(msg, json)))
|
|
1220
|
-
return ret;
|
|
1221
|
-
return k_NOP;
|
|
1222
|
-
}
|
|
1223
|
-
return k_NOP;
|
|
1354
|
+
log_(l_.HANDLERS, () => ['handler_json: ', json]);
|
|
1355
|
+
if (jsonMsg_cjsExports.JSON_Msg_msg.validate(json) && this.handler_json_msg_msg(msg, json))
|
|
1356
|
+
return true;
|
|
1357
|
+
if (jsonMsg_cjsExports.JSON_Msg.validate(json) && this.handler_json_msg(msg, json))
|
|
1358
|
+
return true;
|
|
1359
|
+
return false;
|
|
1224
1360
|
}
|
|
1225
1361
|
}
|
|
1226
1362
|
|
|
@@ -1238,4 +1374,4 @@ exports.StateInitialState = StateInitialState;
|
|
|
1238
1374
|
exports.StateWarp = StateWarp;
|
|
1239
1375
|
exports.TwoPhW = TwoPhW;
|
|
1240
1376
|
exports.l = l_;
|
|
1241
|
-
exports.t_ttl_rtt =
|
|
1377
|
+
exports.t_ttl_rtt = time_ttl_rtt_;
|