@rootintf/protocol-2phw 0.7.5-api-0.7 → 1.0.34-api.0.8
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 +7 -0
- package/dist/twoPhW.cjs.js +918 -452
- package/dist/twoPhW.es.mjs +911 -453
- package/package.json +43 -42
- package/schema/definitions_2PhW.json +12 -0
- package/schema/schema_MsgEngage.json +13 -4
- package/schema/schema_MsgOptions.json +4 -3
- package/schema/schema_MsgWarp.json +6 -4
- package/schema/schema_Options_delay.json +2 -2
- package/src/EventLog-mem.mjs +139 -0
- package/src/ajv-gen-validate.cjs +24 -8
- package/src/twoPhW.mjs +510 -281
- package/src/validate-esm.mjs +1 -1
- package/tests/event-log-mem.spec.mjs +234 -0
- package/tests/twoPhW-new.spec.mjs +771 -120
- package/schema/schema_Msg2PhW.json +0 -12
- package/tests/twoPhW.test.mjs +0 -175
package/dist/twoPhW.es.mjs
CHANGED
|
@@ -1,23 +1,97 @@
|
|
|
1
|
-
const
|
|
1
|
+
const schema_MsgWarp = validate19;function validate19(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate19.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.warp === undefined) && (missing0 = "warp")){validate19.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.warp !== undefined){let data0 = data.warp;const _errs1 = errors;{if(data0 && typeof data0 == "object" && !Array.isArray(data0)){let missing1;if(((((data0.id === undefined) && (missing1 = "id")) || ((data0.user === undefined) && (missing1 = "user"))) || ((data0.hyperport === undefined) && (missing1 = "hyperport"))) || ((data0.ttl_msec === undefined) && (missing1 = "ttl_msec"))){validate19.errors = [{instancePath:instancePath+"/warp",schemaPath:"#/properties/warp/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;}else {if(data0.id !== undefined){const _errs3 = errors;if(typeof data0.id !== "string"){validate19.errors = [{instancePath:instancePath+"/warp/id",schemaPath:"definitions_2PhW#/definitions/warp_id/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs3 === errors;}else {var valid1 = true;}if(valid1){if(data0.ttl_msec !== undefined){let data2 = data0.ttl_msec;const _errs6 = errors;if(!(((typeof data2 == "number") && (!(data2 % 1) && !isNaN(data2))) && (isFinite(data2)))){validate19.errors = [{instancePath:instancePath+"/warp/ttl_msec",schemaPath:"#/properties/warp/properties/ttl_msec/type",keyword:"type",params:{type: "integer"},message:"must be integer"}];return false;}var valid1 = _errs6 === errors;}else {var valid1 = true;}if(valid1){if(data0.instantaneous !== undefined){const _errs8 = errors;if(typeof data0.instantaneous !== "boolean"){validate19.errors = [{instancePath:instancePath+"/warp/instantaneous",schemaPath:"#/properties/warp/properties/instantaneous/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];return false;}var valid1 = _errs8 === errors;}else {var valid1 = true;}}}}}else {validate19.errors = [{instancePath:instancePath+"/warp",schemaPath:"#/properties/warp/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data["2PhW"] !== undefined){const _errs10 = errors;if("0.8" !== data["2PhW"]){validate19.errors = [{instancePath:instancePath+"/2PhW",schemaPath:"definitions_2PhW#/definitions/2PhW/const",keyword:"const",params:{allowedValue: "0.8"},message:"must be equal to constant"}];return false;}var valid0 = _errs10 === errors;}else {var valid0 = true;}}}}else {validate19.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate19.errors = vErrors;return errors === 0;}validate19.evaluated = {"props":{"warp":true,"2PhW":true},"dynamicProps":false,"dynamicItems":false};const schema_MsgEngage = validate20;function validate20(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate20.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.engage === undefined) && (missing0 = "engage")){validate20.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.engage !== undefined){let data0 = data.engage;const _errs1 = errors;{if(data0 && typeof data0 == "object" && !Array.isArray(data0)){let missing1;if(((data0.ok === undefined) && (missing1 = "ok")) || ((data0.rtt_msec === undefined) && (missing1 = "rtt_msec"))){validate20.errors = [{instancePath:instancePath+"/engage",schemaPath:"#/properties/engage/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;}else {if(data0.ok !== undefined){const _errs3 = errors;if(typeof data0.ok !== "boolean"){validate20.errors = [{instancePath:instancePath+"/engage/ok",schemaPath:"#/properties/engage/properties/ok/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];return false;}var valid1 = _errs3 === errors;}else {var valid1 = true;}if(valid1){if(data0.rtt_msec !== undefined){let data2 = data0.rtt_msec;const _errs5 = errors;if(!(((typeof data2 == "number") && (!(data2 % 1) && !isNaN(data2))) && (isFinite(data2)))){validate20.errors = [{instancePath:instancePath+"/engage/rtt_msec",schemaPath:"#/properties/engage/properties/rtt_msec/type",keyword:"type",params:{type: "integer"},message:"must be integer"}];return false;}var valid1 = _errs5 === errors;}else {var valid1 = true;}}}}else {validate20.errors = [{instancePath:instancePath+"/engage",schemaPath:"#/properties/engage/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data["2PhW"] !== undefined){const _errs7 = errors;if("0.8" !== data["2PhW"]){validate20.errors = [{instancePath:instancePath+"/2PhW",schemaPath:"definitions_2PhW#/definitions/2PhW/const",keyword:"const",params:{allowedValue: "0.8"},message:"must be equal to constant"}];return false;}var valid0 = _errs7 === errors;}else {var valid0 = true;}}}}else {validate20.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate20.errors = vErrors;return errors === 0;}validate20.evaluated = {"props":{"engage":true,"2PhW":true},"dynamicProps":false,"dynamicItems":false};const schema_MsgOptions = validate21;function validate21(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate21.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.options === undefined) && (missing0 = "options")){validate21.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.options !== undefined){let data0 = data.options;const _errs1 = errors;if(!(data0 && typeof data0 == "object" && !Array.isArray(data0))){validate21.errors = [{instancePath:instancePath+"/options",schemaPath:"#/properties/options/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data["2PhW"] !== undefined){const _errs3 = errors;if("0.8" !== data["2PhW"]){validate21.errors = [{instancePath:instancePath+"/2PhW",schemaPath:"definitions_2PhW#/definitions/2PhW/const",keyword:"const",params:{allowedValue: "0.8"},message:"must be equal to constant"}];return false;}var valid0 = _errs3 === errors;}else {var valid0 = true;}}}}else {validate21.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate21.errors = vErrors;return errors === 0;}validate21.evaluated = {"props":{"options":true,"2PhW":true},"dynamicProps":false,"dynamicItems":false};
|
|
2
2
|
|
|
3
3
|
// console.log('OUT', __name({variableName}) );
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
//-------------------------------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
function l_length_(obj_labels) {
|
|
8
|
+
if (! obj_labels || typeof obj_labels !== 'object')
|
|
9
|
+
throw new Error('obj_labels must be an object');
|
|
10
|
+
const obj_1label = Object.values(obj_labels);
|
|
11
|
+
if (! obj_1label.every(v => typeof v === 'number' && Number.isFinite(v)))
|
|
12
|
+
throw new Error('All values must be finite numbers');
|
|
13
|
+
|
|
14
|
+
const labels = Object.values(obj_labels);
|
|
15
|
+
if (labels.length === 0)
|
|
16
|
+
return 1; // Empty object case, start at 1
|
|
17
|
+
|
|
18
|
+
const value_max = Math.max(...labels);
|
|
19
|
+
if (value_max <= 0) return 1
|
|
20
|
+
|
|
21
|
+
const bit_highest = Math.floor(Math.log2(value_max));
|
|
22
|
+
return 1 << (bit_highest + 1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function l_array_(arr_labels, start = 1) {
|
|
26
|
+
if (! Array.isArray(arr_labels))
|
|
27
|
+
throw new Error('arr_labels must be an array');
|
|
28
|
+
if (! Number.isSafeInteger(start) || start < 0)
|
|
29
|
+
throw new Error('start must be a safe, non-negative integer');
|
|
30
|
+
|
|
31
|
+
return Object.freeze(arr_labels.reduce((acc, key, index) => {
|
|
32
|
+
acc[key] = start << index;
|
|
33
|
+
return acc;
|
|
34
|
+
}, {}));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function l_concat_(obj_labels, arg) {
|
|
38
|
+
if (! obj_labels || typeof obj_labels !== 'object')
|
|
39
|
+
throw new Error('obj_labels must be an object');
|
|
40
|
+
const obj_1label = Object.values(obj_labels);
|
|
41
|
+
if (! obj_1label.every(v => typeof v === 'number' && Number.isFinite(v)))
|
|
42
|
+
throw new Error('All values must be finite numbers');
|
|
43
|
+
if (! arg || (typeof arg !== 'object' && ! Array.isArray(arg)))
|
|
44
|
+
throw new Error('arg must be an object or array');
|
|
45
|
+
|
|
46
|
+
if (Array.isArray(arg)) {
|
|
47
|
+
const len = l_length_(obj_labels);
|
|
48
|
+
const arr_labels_new = l_array_(arg, len);
|
|
49
|
+
return l_concat_(obj_labels, arr_labels_new);
|
|
12
50
|
}
|
|
13
|
-
|
|
51
|
+
|
|
52
|
+
const next_pos = l_length_(obj_labels);
|
|
53
|
+
const arg_entries = Object.entries(arg);
|
|
54
|
+
const result = Object.create(null);
|
|
55
|
+
Object.entries(obj_labels).forEach(([k, v]) => {
|
|
56
|
+
if (k !== '__proto__' && k !== 'constructor')
|
|
57
|
+
result[k] = v;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
let min_arg = Infinity;
|
|
61
|
+
for (const [, value] of arg_entries) {
|
|
62
|
+
if (typeof value !== 'number' || ! Number.isFinite(value))
|
|
63
|
+
continue; // Skip non-numeric
|
|
64
|
+
|
|
65
|
+
if (value > 0 && value < min_arg)
|
|
66
|
+
min_arg = value;
|
|
67
|
+
}
|
|
68
|
+
// Shift only if min_arg is less than next_pos
|
|
69
|
+
const shift = min_arg === Infinity || min_arg >= next_pos
|
|
70
|
+
? 0
|
|
71
|
+
: Math.floor(Math.log2(next_pos / min_arg));
|
|
72
|
+
|
|
73
|
+
for (const [key, value] of arg_entries) {
|
|
74
|
+
if (!(key in result)) {
|
|
75
|
+
result[key] = value === 0 ? 0 : value << shift;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return Object.freeze(result);
|
|
14
80
|
}
|
|
15
81
|
|
|
16
82
|
function l_LL_(obj, x) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
83
|
+
if (! obj || typeof obj !== 'object')
|
|
84
|
+
throw new Error('obj must be an object');
|
|
85
|
+
if (! Number.isSafeInteger(x) || x < 0)
|
|
86
|
+
throw new Error('Shift value must be a safe, non-negative integer');
|
|
87
|
+
|
|
88
|
+
const obj_new= {};
|
|
89
|
+
for (const [k,v] of Object.entries(obj)) {
|
|
90
|
+
if (typeof v !== 'number' || ! Number.isFinite(v))
|
|
91
|
+
continue; // Skip non-numeric
|
|
92
|
+
obj_new[k] = v<<x;
|
|
93
|
+
}
|
|
94
|
+
return Object.freeze(obj_new);
|
|
21
95
|
}
|
|
22
96
|
|
|
23
97
|
//-------------------------------------------------------------------------------------------------
|
|
@@ -30,56 +104,85 @@ function handler_default_( /* ... */ ) {
|
|
|
30
104
|
|
|
31
105
|
//-------------------------------------------------------------------------------------------------
|
|
32
106
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
BitLogr.prototype['log']= function (nr_logged, /* ... */ ) {
|
|
40
|
-
// console.log('NOP')
|
|
41
|
-
};
|
|
42
|
-
}
|
|
107
|
+
function l_toBigInt_(obj_labels, obj, ignore= false) {
|
|
108
|
+
if (! obj_labels || typeof obj_labels !== 'object')
|
|
109
|
+
throw new Error('obj_labels must be an object');
|
|
110
|
+
if (! obj || typeof obj !== 'object')
|
|
111
|
+
throw new Error('obj must be an object');
|
|
43
112
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
set labels(obj) {
|
|
50
|
-
this._Bint_labels= obj;
|
|
51
|
-
this._Bint_toggled= BigInt(0);
|
|
113
|
+
let bigInt = BigInt(0);
|
|
114
|
+
for (const [k,v] of Object.entries(obj)) {
|
|
115
|
+
if ( ( ignore || v ) && obj_labels[k] !== undefined && typeof obj_labels[k] === 'number')
|
|
116
|
+
bigInt|= BigInt( obj_labels[k] );
|
|
117
|
+
// console.log('0b'+ bigInt.toString(2) );
|
|
52
118
|
}
|
|
119
|
+
return bigInt;
|
|
120
|
+
}
|
|
53
121
|
|
|
54
|
-
|
|
55
|
-
// let name= __name(label);
|
|
56
|
-
// _labels[name]= label[name];
|
|
57
|
-
// console.log(_labels);
|
|
58
|
-
// }
|
|
122
|
+
// console.log(l_toBigInt_({},{}))
|
|
59
123
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this._Bint_toggled= l_toBigInt_(this._Bint_labels, obj);
|
|
124
|
+
const LOGR = (function () {
|
|
125
|
+
let _instance; // Private variable to hold the single instance
|
|
63
126
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
127
|
+
function _create_instance() {
|
|
128
|
+
// Private state (replacing constructor properties)
|
|
129
|
+
let _handler_log = handler_default_;
|
|
130
|
+
let _obj_labels = undefined;
|
|
131
|
+
let _Bint_toggled = BigInt(0);
|
|
68
132
|
|
|
69
|
-
|
|
70
|
-
if (
|
|
133
|
+
function _log_fxn(nr_logged, argsFn /* args */) {
|
|
134
|
+
if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
|
|
71
135
|
return false;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
136
|
+
|
|
137
|
+
const args = argsFn();
|
|
138
|
+
_handler_log.apply(this, args);
|
|
139
|
+
// _handler_log.apply(this, args);
|
|
77
140
|
return true;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
set handler(fx) {
|
|
145
|
+
_handler_log = fx;
|
|
146
|
+
},
|
|
147
|
+
get handler() {
|
|
148
|
+
return _handler_log;
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
get labels() { return _obj_labels; },
|
|
152
|
+
set labels(obj) {
|
|
153
|
+
_obj_labels = obj;
|
|
154
|
+
_Bint_toggled = BigInt(0);
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
// put= function(label, abbrv) {
|
|
158
|
+
// let name= __name(label);
|
|
159
|
+
// _labels[name]= label[name];
|
|
160
|
+
// console.log(_labels);
|
|
161
|
+
// }
|
|
162
|
+
|
|
163
|
+
get toggled() { return _Bint_toggled; },
|
|
164
|
+
set toggled(obj_toggled) {
|
|
165
|
+
_Bint_toggled= l_toBigInt_(_obj_labels, obj_toggled);
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
log(nr_logged, argsFn) {
|
|
169
|
+
|
|
170
|
+
return _log_fxn.call(this, nr_logged, argsFn); // Pass the thunk
|
|
171
|
+
}
|
|
78
172
|
};
|
|
79
173
|
}
|
|
80
174
|
|
|
81
|
-
//
|
|
82
|
-
|
|
175
|
+
// Public interface
|
|
176
|
+
return {
|
|
177
|
+
get_instance() {
|
|
178
|
+
if (!_instance) {
|
|
179
|
+
_instance = _create_instance(); // Lazy initialization
|
|
180
|
+
}
|
|
181
|
+
return _instance;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
})();
|
|
83
186
|
|
|
84
187
|
var jsonMsg_cjs = {};
|
|
85
188
|
|
|
@@ -89,77 +192,66 @@ function requireJsonMsg_cjs () {
|
|
|
89
192
|
if (hasRequiredJsonMsg_cjs) return jsonMsg_cjs;
|
|
90
193
|
hasRequiredJsonMsg_cjs = 1;
|
|
91
194
|
|
|
92
|
-
|
|
195
|
+
const schema_Msg = validate18;function validate18(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate18.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((((data.id === undefined) && (missing0 = "id")) || ((data.referer === undefined) && (missing0 = "referer"))) || ((data.dt === undefined) && (missing0 = "dt"))){validate18.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.id !== undefined){const _errs1 = errors;if(typeof data.id !== "string"){validate18.errors = [{instancePath:instancePath+"/id",schemaPath:"#/properties/id/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data.dt !== undefined){const _errs3 = errors;if(typeof data.dt !== "string"){validate18.errors = [{instancePath:instancePath+"/dt",schemaPath:"#/properties/dt/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs3 === errors;}else {var valid0 = true;}}}}else {validate18.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate18.errors = vErrors;return errors === 0;}validate18.evaluated = {"props":{"id":true,"dt":true},"dynamicProps":false,"dynamicItems":false};const schema_Msg_msg = validate19;function validate19(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate19.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data._msg === undefined) && (missing0 = "_msg")){validate19.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}}else {validate19.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate19.errors = vErrors;return errors === 0;}validate19.evaluated = {"dynamicProps":false,"dynamicItems":false};const schema_MsgAck_msg = validate20;function validate20(data, {instancePath="", parentData, parentDataProperty, rootData=data, dynamicAnchors={}}={}){let vErrors = null;let errors = 0;const evaluated0 = validate20.evaluated;if(evaluated0.dynamicProps){evaluated0.props = undefined;}if(evaluated0.dynamicItems){evaluated0.items = undefined;}{if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.ack === undefined) && (missing0 = "ack")){validate20.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.ack !== undefined){let data0 = data.ack;{if(data0 && typeof data0 == "object" && !Array.isArray(data0)){let missing1;if((data0.ok === undefined) && (missing1 = "ok")){validate20.errors = [{instancePath:instancePath+"/ack",schemaPath:"#/properties/ack/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;}else {if(data0.ok !== undefined){if(typeof data0.ok !== "boolean"){validate20.errors = [{instancePath:instancePath+"/ack/ok",schemaPath:"#/properties/ack/properties/ok/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];return false;}}}}else {validate20.errors = [{instancePath:instancePath+"/ack",schemaPath:"#/properties/ack/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}}}}else {validate20.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate20.errors = vErrors;return errors === 0;}validate20.evaluated = {"props":{"ack":true},"dynamicProps":false,"dynamicItems":false};
|
|
93
196
|
|
|
94
|
-
const
|
|
197
|
+
const byteToHex = [];
|
|
198
|
+
for (let i = 0; i < 256; ++i) {
|
|
199
|
+
byteToHex.push((i + 0x100).toString(16).slice(1));
|
|
200
|
+
}
|
|
201
|
+
function unsafeStringify(arr, offset = 0) {
|
|
202
|
+
return (byteToHex[arr[offset + 0]] +
|
|
203
|
+
byteToHex[arr[offset + 1]] +
|
|
204
|
+
byteToHex[arr[offset + 2]] +
|
|
205
|
+
byteToHex[arr[offset + 3]] +
|
|
206
|
+
'-' +
|
|
207
|
+
byteToHex[arr[offset + 4]] +
|
|
208
|
+
byteToHex[arr[offset + 5]] +
|
|
209
|
+
'-' +
|
|
210
|
+
byteToHex[arr[offset + 6]] +
|
|
211
|
+
byteToHex[arr[offset + 7]] +
|
|
212
|
+
'-' +
|
|
213
|
+
byteToHex[arr[offset + 8]] +
|
|
214
|
+
byteToHex[arr[offset + 9]] +
|
|
215
|
+
'-' +
|
|
216
|
+
byteToHex[arr[offset + 10]] +
|
|
217
|
+
byteToHex[arr[offset + 11]] +
|
|
218
|
+
byteToHex[arr[offset + 12]] +
|
|
219
|
+
byteToHex[arr[offset + 13]] +
|
|
220
|
+
byteToHex[arr[offset + 14]] +
|
|
221
|
+
byteToHex[arr[offset + 15]]).toLowerCase();
|
|
222
|
+
}
|
|
95
223
|
|
|
96
|
-
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
|
97
|
-
// require the crypto API and do not support built-in fallback to lower quality random number
|
|
98
|
-
// generators (like Math.random()).
|
|
99
224
|
let getRandomValues;
|
|
100
225
|
const rnds8 = new Uint8Array(16);
|
|
101
226
|
function rng() {
|
|
102
|
-
// lazy load so that environments that need to polyfill have a chance to do so
|
|
103
|
-
if (!getRandomValues) {
|
|
104
|
-
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
|
|
105
|
-
getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
|
|
106
|
-
|
|
107
227
|
if (!getRandomValues) {
|
|
108
|
-
|
|
228
|
+
if (typeof crypto === 'undefined' || !crypto.getRandomValues) {
|
|
229
|
+
throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
|
230
|
+
}
|
|
231
|
+
getRandomValues = crypto.getRandomValues.bind(crypto);
|
|
109
232
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return getRandomValues(rnds8);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Convert array of 16 byte values to UUID string format of the form:
|
|
117
|
-
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
118
|
-
*/
|
|
119
|
-
|
|
120
|
-
const byteToHex = [];
|
|
121
|
-
|
|
122
|
-
for (let i = 0; i < 256; ++i) {
|
|
123
|
-
byteToHex.push((i + 0x100).toString(16).slice(1));
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function unsafeStringify(arr, offset = 0) {
|
|
127
|
-
// Note: Be careful editing this code! It's been tuned for performance
|
|
128
|
-
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
129
|
-
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
233
|
+
return getRandomValues(rnds8);
|
|
130
234
|
}
|
|
131
235
|
|
|
132
236
|
const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
133
|
-
var native = {
|
|
134
|
-
randomUUID
|
|
135
|
-
};
|
|
237
|
+
var native = { randomUUID };
|
|
136
238
|
|
|
137
239
|
function v4(options, buf, offset) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
240
|
+
if (native.randomUUID && true && !options) {
|
|
241
|
+
return native.randomUUID();
|
|
242
|
+
}
|
|
243
|
+
options = options || {};
|
|
244
|
+
const rnds = options.random ?? options.rng?.() ?? rng();
|
|
245
|
+
if (rnds.length < 16) {
|
|
246
|
+
throw new Error('Random bytes length must be >= 16');
|
|
247
|
+
}
|
|
248
|
+
rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
|
249
|
+
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
|
250
|
+
return unsafeStringify(rnds);
|
|
149
251
|
}
|
|
150
252
|
|
|
151
253
|
// console.log('OUT', __name({variableName}) );
|
|
152
254
|
|
|
153
|
-
function l_toBigInt_(ref, obj, ignore= false) {
|
|
154
|
-
console.assert(ref !== BigInt(0), 'no labels initialized');
|
|
155
|
-
let bigInt = BigInt(0);
|
|
156
|
-
for (const [k,v] of Object.entries(obj)) {
|
|
157
|
-
if ( ( ignore || v ) && ref[k])
|
|
158
|
-
bigInt|= BigInt( ref[k] );
|
|
159
|
-
// console.log('0b'+ bigInt.toString(2) );
|
|
160
|
-
}
|
|
161
|
-
return bigInt;
|
|
162
|
-
}
|
|
163
255
|
|
|
164
256
|
//-------------------------------------------------------------------------------------------------
|
|
165
257
|
|
|
@@ -171,87 +263,112 @@ function requireJsonMsg_cjs () {
|
|
|
171
263
|
|
|
172
264
|
//-------------------------------------------------------------------------------------------------
|
|
173
265
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
BitLogr.prototype['log']= function (nr_logged, /* ... */ ) {
|
|
181
|
-
// console.log('NOP')
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
set handler(fx) {
|
|
186
|
-
this._handler_log= fx;
|
|
187
|
-
}
|
|
266
|
+
function l_toBigInt_(obj_labels, obj, ignore= false) {
|
|
267
|
+
if (! obj_labels || typeof obj_labels !== 'object')
|
|
268
|
+
throw new Error('obj_labels must be an object');
|
|
269
|
+
if (! obj || typeof obj !== 'object')
|
|
270
|
+
throw new Error('obj must be an object');
|
|
188
271
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
272
|
+
let bigInt = BigInt(0);
|
|
273
|
+
for (const [k,v] of Object.entries(obj)) {
|
|
274
|
+
if ( ( ignore || v ) && obj_labels[k] !== undefined && typeof obj_labels[k] === 'number')
|
|
275
|
+
bigInt|= BigInt( obj_labels[k] );
|
|
276
|
+
// console.log('0b'+ bigInt.toString(2) );
|
|
193
277
|
}
|
|
278
|
+
return bigInt;
|
|
279
|
+
}
|
|
194
280
|
|
|
195
|
-
|
|
196
|
-
// let name= __name(label);
|
|
197
|
-
// _labels[name]= label[name];
|
|
198
|
-
// console.log(_labels);
|
|
199
|
-
// }
|
|
281
|
+
// console.log(l_toBigInt_({},{}))
|
|
200
282
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
this._Bint_toggled= l_toBigInt_(this._Bint_labels, obj);
|
|
283
|
+
const LOGR = (function () {
|
|
284
|
+
let _instance; // Private variable to hold the single instance
|
|
204
285
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
286
|
+
function _create_instance() {
|
|
287
|
+
// Private state (replacing constructor properties)
|
|
288
|
+
let _handler_log = handler_default_;
|
|
289
|
+
let _obj_labels = undefined;
|
|
290
|
+
let _Bint_toggled = BigInt(0);
|
|
209
291
|
|
|
210
|
-
|
|
211
|
-
if (
|
|
292
|
+
function _log_fxn(nr_logged, argsFn /* args */) {
|
|
293
|
+
if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
|
|
212
294
|
return false;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
295
|
+
|
|
296
|
+
const args = argsFn();
|
|
297
|
+
_handler_log.apply(this, args);
|
|
298
|
+
// _handler_log.apply(this, args);
|
|
218
299
|
return true;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return {
|
|
303
|
+
set handler(fx) {
|
|
304
|
+
_handler_log = fx;
|
|
305
|
+
},
|
|
306
|
+
get handler() {
|
|
307
|
+
return _handler_log;
|
|
308
|
+
},
|
|
309
|
+
|
|
310
|
+
get labels() { return _obj_labels; },
|
|
311
|
+
set labels(obj) {
|
|
312
|
+
_obj_labels = obj;
|
|
313
|
+
_Bint_toggled = BigInt(0);
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
// put= function(label, abbrv) {
|
|
317
|
+
// let name= __name(label);
|
|
318
|
+
// _labels[name]= label[name];
|
|
319
|
+
// console.log(_labels);
|
|
320
|
+
// }
|
|
321
|
+
|
|
322
|
+
get toggled() { return _Bint_toggled; },
|
|
323
|
+
set toggled(obj_toggled) {
|
|
324
|
+
_Bint_toggled= l_toBigInt_(_obj_labels, obj_toggled);
|
|
325
|
+
},
|
|
326
|
+
|
|
327
|
+
log(nr_logged, argsFn) {
|
|
328
|
+
|
|
329
|
+
return _log_fxn.call(this, nr_logged, argsFn); // Pass the thunk
|
|
330
|
+
}
|
|
219
331
|
};
|
|
220
332
|
}
|
|
221
333
|
|
|
222
|
-
//
|
|
223
|
-
|
|
334
|
+
// Public interface
|
|
335
|
+
return {
|
|
336
|
+
get_instance() {
|
|
337
|
+
if (!_instance) {
|
|
338
|
+
_instance = _create_instance(); // Lazy initialization
|
|
339
|
+
}
|
|
340
|
+
return _instance;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
224
343
|
|
|
225
|
-
|
|
344
|
+
})();
|
|
345
|
+
|
|
346
|
+
let LOGR_= LOGR.get_instance();
|
|
347
|
+
const log_= LOGR_.log;
|
|
226
348
|
|
|
227
349
|
const l_= {
|
|
228
350
|
VALIDATION : 0b1 << 0,
|
|
229
351
|
};
|
|
352
|
+
LOGR_.labels= l_;
|
|
230
353
|
|
|
231
354
|
// TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
|
|
232
355
|
|
|
233
356
|
// "module" pattern to avoid "static" and "#" private : https://stackoverflow.com/a/1479341/298545
|
|
234
357
|
var JSON_Msg = (function() {
|
|
235
358
|
return {
|
|
236
|
-
merge
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
};
|
|
243
|
-
// https://stackoverflow.com/questions/684672/how-do-i-loop-through-or-enumerate-a-javascript-object
|
|
244
|
-
for (var key of Object.keys(json)) {
|
|
245
|
-
json_msg[key]= json[key];
|
|
246
|
-
}
|
|
247
|
-
return json_msg;
|
|
359
|
+
merge: function(json) {
|
|
360
|
+
return Object.assign({
|
|
361
|
+
id: v4(),
|
|
362
|
+
referer: null,
|
|
363
|
+
dt: new Date().toISOString()
|
|
364
|
+
}, json || {});
|
|
248
365
|
},
|
|
249
|
-
validate : function(json) {
|
|
250
|
-
const b_valid=
|
|
251
|
-
if (!b_valid)
|
|
252
|
-
|
|
366
|
+
validate : function (json) {
|
|
367
|
+
const b_valid = schema_Msg(json);
|
|
368
|
+
if (!b_valid)
|
|
369
|
+
log_(l_.VALIDATION, () => ['JSON_Msg: validate: ', schema_Msg.errors]);
|
|
253
370
|
return b_valid;
|
|
254
|
-
}
|
|
371
|
+
},
|
|
255
372
|
// TODO: requires a separate ajv module require, and JTD specific schema
|
|
256
373
|
// https://ajv.js.org/guide/getting-started.html#parsing-and-serializing-json
|
|
257
374
|
// static #ajv_parse_= ajv.compileParser(this.#schema_json_Msg);
|
|
@@ -260,26 +377,24 @@ function requireJsonMsg_cjs () {
|
|
|
260
377
|
// }
|
|
261
378
|
}
|
|
262
379
|
})();
|
|
263
|
-
|
|
380
|
+
|
|
264
381
|
var JSON_Msg_msg = (function() {
|
|
265
382
|
return {
|
|
266
|
-
create_with_msg_merge
|
|
267
|
-
|
|
268
|
-
json_msg._msg= _msg;
|
|
269
|
-
return json_msg;
|
|
383
|
+
create_with_msg_merge: function(_msg, json) {
|
|
384
|
+
return Object.assign(JSON_Msg.merge(json), { _msg });
|
|
270
385
|
},
|
|
271
386
|
validate : function(json) {
|
|
272
387
|
if (! JSON_Msg.validate(json))
|
|
273
388
|
return false;
|
|
274
|
-
const b_valid=
|
|
389
|
+
const b_valid= schema_Msg_msg(json);
|
|
275
390
|
if (!b_valid)
|
|
276
|
-
|
|
391
|
+
log_(l_.VALIDATION, () => ['JSON_Msg_msg: validate: ', schema_Msg_msg.errors]);
|
|
277
392
|
return b_valid;
|
|
278
393
|
}
|
|
279
394
|
}
|
|
280
395
|
})();
|
|
281
396
|
|
|
282
|
-
var
|
|
397
|
+
var JSON_MsgAck_msg = (function() {
|
|
283
398
|
return {
|
|
284
399
|
create_with_msgOk : function(_msg, b_ok= true) {
|
|
285
400
|
return JSON_Msg_msg.create_with_msg_merge(_msg, {
|
|
@@ -299,53 +414,177 @@ function requireJsonMsg_cjs () {
|
|
|
299
414
|
validate : function(json) {
|
|
300
415
|
if (! JSON_Msg_msg.validate(json))
|
|
301
416
|
return false;
|
|
302
|
-
const b_valid=
|
|
417
|
+
const b_valid= schema_MsgAck_msg(json);
|
|
303
418
|
if (!b_valid)
|
|
304
|
-
|
|
419
|
+
log_(l_.VALIDATION, () => ['JSON_MsgAck: validate: ', schema_MsgAck_msg.errors]);
|
|
305
420
|
return b_valid;
|
|
306
421
|
}
|
|
307
422
|
}
|
|
308
423
|
})();
|
|
309
424
|
|
|
310
425
|
jsonMsg_cjs.JSON_Msg = JSON_Msg;
|
|
311
|
-
jsonMsg_cjs.
|
|
426
|
+
jsonMsg_cjs.JSON_MsgAck_msg = JSON_MsgAck_msg;
|
|
312
427
|
jsonMsg_cjs.JSON_Msg_msg = JSON_Msg_msg;
|
|
428
|
+
jsonMsg_cjs.l = l_;
|
|
313
429
|
return jsonMsg_cjs;
|
|
314
430
|
}
|
|
315
431
|
|
|
316
432
|
var jsonMsg_cjsExports = requireJsonMsg_cjs();
|
|
317
433
|
|
|
434
|
+
//-------------------------------------------------------------------------------------------------
|
|
435
|
+
|
|
436
|
+
let LOGR_$1= LOGR.get_instance();
|
|
437
|
+
const log_$1= LOGR_$1.log;
|
|
438
|
+
|
|
439
|
+
const l_$1= {
|
|
440
|
+
EVENTS : 0b1 << 0,
|
|
441
|
+
TIMEOUTS : 0b1 << 1,
|
|
442
|
+
};
|
|
443
|
+
LOGR_$1.labels= l_$1;
|
|
444
|
+
// LOGR_.toggled= {
|
|
445
|
+
// EVENTS : 1
|
|
446
|
+
// }
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
//-------------------------------------------------------------------------------------------------
|
|
450
|
+
|
|
451
|
+
class EventLog {
|
|
452
|
+
constructor() {
|
|
453
|
+
this.arr_events = []; // In-memory event store
|
|
454
|
+
this.map_index_id = new Map(); // Map of id -> array of indices into arr_events; arr_events[idx]
|
|
455
|
+
this.map_timeouts = new Map(); // Store timeout references: idx -> timeout_id
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
addEvent(type, id, data, timeout_ms = null, timeout_callback = null) {
|
|
459
|
+
const evt = {
|
|
460
|
+
type,
|
|
461
|
+
dt: Date.now(),
|
|
462
|
+
id,
|
|
463
|
+
data,
|
|
464
|
+
timeout_id: null // Will store timeout reference if set
|
|
465
|
+
};
|
|
466
|
+
const idx = this.arr_events.push(evt) - 1; // More efficient than .length before push
|
|
467
|
+
|
|
468
|
+
let arr_indices = this.map_index_id.get(id);
|
|
469
|
+
if (! arr_indices) {
|
|
470
|
+
arr_indices = [];
|
|
471
|
+
this.map_index_id.set(id, arr_indices);
|
|
472
|
+
}
|
|
473
|
+
arr_indices.push(idx);
|
|
474
|
+
|
|
475
|
+
// Set timeout if specified
|
|
476
|
+
if (timeout_ms && timeout_callback) {
|
|
477
|
+
evt.timeout_id = setTimeout(() => {
|
|
478
|
+
if (this.map_timeouts.delete(idx)) {
|
|
479
|
+
evt.timeout_id = null;
|
|
480
|
+
timeout_callback({idx, evt});
|
|
481
|
+
log_$1(l_$1.EVENTS, () => [`Event DELETED[${idx}]: ${type}`, evt]);
|
|
482
|
+
}
|
|
483
|
+
}, timeout_ms);
|
|
484
|
+
|
|
485
|
+
this.map_timeouts.set(idx, evt.timeout_id);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// the error "toISOString is not a function" occurs because Date(evt.dt) is not doing what you expect.
|
|
489
|
+
// 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().
|
|
490
|
+
// Date(evt.dt).toISOString() -> new Date(evt.dt).toISOString()
|
|
491
|
+
log_$1(l_$1.EVENTS, () => [`Event added[${idx}] @${new Date(evt.dt).toISOString()}: ${type}`, evt]);
|
|
492
|
+
return { idx, evt };
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
cancelTimeout(idx) {
|
|
496
|
+
const timeout_id = this.map_timeouts.get(idx);
|
|
497
|
+
if (timeout_id) {
|
|
498
|
+
clearTimeout(timeout_id);
|
|
499
|
+
this.map_timeouts.delete(idx);
|
|
500
|
+
if (this.arr_events[idx])
|
|
501
|
+
this.arr_events[idx].timeout_id = null;
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
cancelAllTimeouts() {
|
|
508
|
+
for (const [idx, timeout_id] of this.map_timeouts) {
|
|
509
|
+
clearTimeout(timeout_id);
|
|
510
|
+
if (this.arr_events[idx])
|
|
511
|
+
this.arr_events[idx].timeout_id = null;
|
|
512
|
+
}
|
|
513
|
+
this.map_timeouts.clear();
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
getEventById(id, lookback_ms = null) {
|
|
517
|
+
const arr_indices = this.map_index_id.get(id);
|
|
518
|
+
if (!arr_indices?.length) return [];
|
|
519
|
+
|
|
520
|
+
const result = [];
|
|
521
|
+
const cutoff = lookback_ms !== null ? Date.now() - lookback_ms : -Infinity;
|
|
522
|
+
|
|
523
|
+
// Single loop with early cutoff
|
|
524
|
+
for (let i = arr_indices.length - 1; i >= 0; i--) {
|
|
525
|
+
const idx = arr_indices[i];
|
|
526
|
+
const evt = this.arr_events[idx];
|
|
527
|
+
if (evt.dt < cutoff)
|
|
528
|
+
break;
|
|
529
|
+
result.push({ idx, evt });
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
return result; // Newest to oldest order
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// getRecentEvents(id, lookbackMs) {
|
|
536
|
+
// const cutoff = Date.now() - lookbackMs;
|
|
537
|
+
// return this.events.filter(e => e.id === id && e.dt >= cutoff);
|
|
538
|
+
// }
|
|
539
|
+
|
|
540
|
+
getEvents(lookback_ms, predicate) {
|
|
541
|
+
const cutoff = Date.now() - lookback_ms;
|
|
542
|
+
const result = [];
|
|
543
|
+
|
|
544
|
+
// Iterate backwards from the end
|
|
545
|
+
for (let idx = this.arr_events.length - 1; idx >= 0; idx--) {
|
|
546
|
+
const evt = this.arr_events[idx];
|
|
547
|
+
if (evt.dt < cutoff) {
|
|
548
|
+
break; // Stop once we pass the cutoff
|
|
549
|
+
}
|
|
550
|
+
if (predicate(evt)) {
|
|
551
|
+
result.push({ idx, evt });
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
return result; // Newest to oldest order
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// setLogr(obj_logr) {
|
|
559
|
+
// this.logr.toggled = obj_logr;
|
|
560
|
+
// }
|
|
561
|
+
|
|
562
|
+
clear() {
|
|
563
|
+
this.cancelAllTimeouts(); // Clear all timeouts before clearing events
|
|
564
|
+
this.arr_events.length = 0;
|
|
565
|
+
this.map_index_id.clear();
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
318
569
|
const k_TTL= 20000;
|
|
319
570
|
|
|
320
571
|
//-------------------------------------------------------------------------------------------------
|
|
321
572
|
|
|
322
|
-
let LOGR_= new BitLogr();
|
|
323
573
|
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
574
|
+
const LOGR_= LOGR.get_instance();
|
|
575
|
+
const log_= LOGR_.log;
|
|
576
|
+
|
|
577
|
+
Object.assign(jsonMsg_cjsExports.l, l_LL_(jsonMsg_cjsExports.l, 2)); // VALIDATION : 4
|
|
578
|
+
|
|
579
|
+
const l_twoPhW_ = l_array_(['HANDLERS','DROPS', 'PROTOCOL_STATE','RECVER','SENDER']);
|
|
580
|
+
const l_ = l_concat_(l_$1, l_concat_(jsonMsg_cjsExports.l, l_twoPhW_) );
|
|
330
581
|
|
|
331
|
-
const l_= {
|
|
332
|
-
HANDLERS : 0b1 << 0,
|
|
333
|
-
DROPS : 0b1 << 1,
|
|
334
|
-
VALIDATION : 0b1 << 2,
|
|
335
|
-
... l_LL_(l_msgs_, 8)
|
|
336
|
-
};
|
|
337
582
|
LOGR_.labels= l_;
|
|
338
583
|
|
|
339
584
|
//-------------------------------------------------------------------------------------------------
|
|
340
585
|
|
|
341
586
|
let map_Context_= new Map();
|
|
342
587
|
|
|
343
|
-
function set_ctx(key, ctx) {
|
|
344
|
-
map_Context_.set(key, ctx);
|
|
345
|
-
// console.log(map_Context_);
|
|
346
|
-
return ctx;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
588
|
function get_ctx(key) {
|
|
350
589
|
return map_Context_.get(key);
|
|
351
590
|
}
|
|
@@ -353,20 +592,30 @@ function get_ctx(key) {
|
|
|
353
592
|
//-------------------------------------------------------------------------------------------------
|
|
354
593
|
|
|
355
594
|
class Config {
|
|
356
|
-
|
|
595
|
+
constructor() {
|
|
596
|
+
// Initialize callbacks as no-op functions
|
|
597
|
+
this._callback_msgWarp = () => { console.assert(false, 'callback_msgWarp uninitialized'); };
|
|
598
|
+
this._callback_msgEngage = () => { console.assert(false, 'callback_msgEngage uninitialized'); };
|
|
599
|
+
this._callback_msgAckWarp = () => { console.assert(false, 'callback_msgAckWarp uninitialized'); };
|
|
600
|
+
this._callback_msgAckEngage = () => { console.assert(false, 'callback_msgAckEngage uninitialized'); };
|
|
601
|
+
this._callback_msg_sent_expired = () => { console.assert(false, '_callback_msg_sent_expired uninitialized'); };
|
|
602
|
+
this._callback_msgOptions = () => { console.assert(false, 'callback_msgOptions uninitialized'); };
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
receiver(callback_msgWarp, callback_msgEngage, callback_msg_sent_expired) {
|
|
357
606
|
this._callback_msgWarp= callback_msgWarp;
|
|
358
607
|
this._callback_msgEngage= callback_msgEngage;
|
|
608
|
+
this._callback_msg_sent_expired= callback_msg_sent_expired;
|
|
359
609
|
}
|
|
360
|
-
sender(callback_msgAckWarp,callback_msgAckEngage ) {
|
|
610
|
+
sender(callback_msgAckWarp, callback_msgAckEngage, callback_msg_sent_expired ) {
|
|
361
611
|
this._callback_msgAckWarp= callback_msgAckWarp;
|
|
362
612
|
this._callback_msgAckEngage= callback_msgAckEngage;
|
|
613
|
+
this._callback_msg_sent_expired= callback_msg_sent_expired;
|
|
363
614
|
}
|
|
615
|
+
|
|
364
616
|
set callback_msgOptions(callback) {
|
|
365
617
|
this._callback_msgOptions= callback;
|
|
366
618
|
}
|
|
367
|
-
set logr(obj_logr) {
|
|
368
|
-
LOGR_.toggled= obj_logr;
|
|
369
|
-
}
|
|
370
619
|
}
|
|
371
620
|
|
|
372
621
|
// var config = (function() {
|
|
@@ -385,11 +634,21 @@ class Config {
|
|
|
385
634
|
|
|
386
635
|
//-------------------------------------------------------------------------------------------------
|
|
387
636
|
|
|
388
|
-
let k_VERSION= "0.
|
|
637
|
+
let k_VERSION= "0.8";
|
|
638
|
+
|
|
639
|
+
function t_ttl_rtt_(ttl_msec, rtt_msec) {
|
|
640
|
+
if (ttl_msec === undefined)
|
|
641
|
+
return undefined;
|
|
642
|
+
if (rtt_msec === undefined)
|
|
643
|
+
return ttl_msec *2;
|
|
644
|
+
|
|
645
|
+
console.assert(rtt_msec <= ttl_msec *2, `t_ttl_rtt_: INVALID rtt_msec ttl_msec[${ttl_msec}] rtt_msec[${rtt_msec}]`);
|
|
646
|
+
return (ttl_msec *2) + rtt_msec;
|
|
647
|
+
}
|
|
389
648
|
|
|
390
649
|
var JSON_MsgOptions = (function() {
|
|
391
650
|
return {
|
|
392
|
-
create_with_msg_options :
|
|
651
|
+
create_with_msg_options : function(_msg, options) {
|
|
393
652
|
return jsonMsg_cjsExports.JSON_Msg_msg.create_with_msg_merge(_msg, {
|
|
394
653
|
options: options,
|
|
395
654
|
"2PhW": k_VERSION
|
|
@@ -398,12 +657,8 @@ var JSON_MsgOptions = (function() {
|
|
|
398
657
|
validate : function(json) {
|
|
399
658
|
if (! jsonMsg_cjsExports.JSON_Msg_msg.validate(json))
|
|
400
659
|
return false;
|
|
401
|
-
if (!
|
|
402
|
-
|
|
403
|
-
return false;
|
|
404
|
-
}
|
|
405
|
-
if (! validate_MsgOptions(json)) {
|
|
406
|
-
LOGR_.log(l_.VALIDATION, 'JSON_MsgOptions: validate_MsgOptions_: ', validate_MsgOptions.errors);
|
|
660
|
+
if (! schema_MsgOptions(json)) {
|
|
661
|
+
log_(l_.VALIDATION, () => ['JSON_MsgOptions: schema_MsgOptions_: ', schema_MsgOptions.errors]);
|
|
407
662
|
return false;
|
|
408
663
|
}
|
|
409
664
|
return true;
|
|
@@ -413,9 +668,10 @@ var JSON_MsgOptions = (function() {
|
|
|
413
668
|
|
|
414
669
|
var JSON_MsgWarp = (function() {
|
|
415
670
|
return {
|
|
416
|
-
|
|
671
|
+
create_with_id_user_hyperport : function(json_warp_id, json_user, json_hyperport, nr_ttl_msec) {
|
|
417
672
|
return jsonMsg_cjsExports.JSON_Msg.merge({
|
|
418
673
|
warp : {
|
|
674
|
+
id : json_warp_id,
|
|
419
675
|
user : json_user,
|
|
420
676
|
hyperport : json_hyperport,
|
|
421
677
|
ttl_msec : nr_ttl_msec
|
|
@@ -423,15 +679,22 @@ var JSON_MsgWarp = (function() {
|
|
|
423
679
|
"2PhW": k_VERSION
|
|
424
680
|
});
|
|
425
681
|
},
|
|
682
|
+
compare : function(json_L, json_R) {
|
|
683
|
+
if (json_L.dt !== json_R.dt)
|
|
684
|
+
return false;
|
|
685
|
+
if (json_L.warp.id !== json_R.warp.id)
|
|
686
|
+
return false;
|
|
687
|
+
if (json_L.referer[0] !== json_R.referer[0])
|
|
688
|
+
return false;
|
|
689
|
+
if (json_L.referer[1] !== json_R.referer[1])
|
|
690
|
+
return false;
|
|
691
|
+
return true;
|
|
692
|
+
},
|
|
426
693
|
validate : function(json) {
|
|
427
694
|
if (! jsonMsg_cjsExports.JSON_Msg.validate(json))
|
|
428
695
|
return false;
|
|
429
|
-
if (!
|
|
430
|
-
|
|
431
|
-
return false;
|
|
432
|
-
}
|
|
433
|
-
if (! validate_MsgWarp(json)) {
|
|
434
|
-
LOGR_.log(l_.VALIDATION, 'JSON_MsgWarp: validate_MsgWarp_: ', validate_MsgWarp.errors);
|
|
696
|
+
if (! schema_MsgWarp(json)) {
|
|
697
|
+
log_(l_.VALIDATION, () => ['JSON_MsgWarp: schema_MsgWarp_: ', schema_MsgWarp.errors]);
|
|
435
698
|
return false;
|
|
436
699
|
}
|
|
437
700
|
return true;
|
|
@@ -440,32 +703,29 @@ var JSON_MsgWarp = (function() {
|
|
|
440
703
|
})();
|
|
441
704
|
|
|
442
705
|
var JSON_MsgEngage = (function() {
|
|
443
|
-
return {
|
|
706
|
+
return {
|
|
444
707
|
create_with_MsgWarp : function(json_msgWarp) {
|
|
445
|
-
|
|
708
|
+
console.assert(json_msgWarp.ack === undefined, "Engage with a Warp, not an Ack");
|
|
709
|
+
return jsonMsg_cjsExports.JSON_Msg_msg.create_with_msg_merge(json_msgWarp, {
|
|
446
710
|
engage : {
|
|
447
|
-
|
|
448
|
-
|
|
711
|
+
"ok" : true,
|
|
712
|
+
"rtt_msec" : Date.now() - Date.parse(json_msgWarp.dt)
|
|
449
713
|
},
|
|
450
714
|
"2PhW": k_VERSION
|
|
451
715
|
});
|
|
452
|
-
json_msgEngage["id"]= json_msgWarp.id;
|
|
453
|
-
return json_msgEngage;
|
|
454
716
|
},
|
|
455
717
|
validate : function(json) {
|
|
456
|
-
if (! jsonMsg_cjsExports.
|
|
718
|
+
if (! jsonMsg_cjsExports.JSON_Msg_msg.validate(json))
|
|
457
719
|
return false;
|
|
458
|
-
if (!
|
|
459
|
-
LOGR_.log(l_.VALIDATION, 'JSON_MsgWarp: validate_Msg2PhW_: ', validate_Msg2PhW.errors);
|
|
720
|
+
if (! JSON_MsgWarp.validate(json._msg))
|
|
460
721
|
return false;
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
LOGR_.log(l_.VALIDATION, 'JSON_MsgEngage: validate_MsgEngage_: ', validate_MsgEngage.errors);
|
|
722
|
+
if (! schema_MsgEngage(json)) {
|
|
723
|
+
log_(l_.VALIDATION, () => ['JSON_MsgEngage: schema_MsgEngage_: ', schema_MsgEngage.errors]);
|
|
464
724
|
return false;
|
|
465
725
|
}
|
|
466
726
|
return true;
|
|
467
727
|
}
|
|
468
|
-
}
|
|
728
|
+
};
|
|
469
729
|
})();
|
|
470
730
|
|
|
471
731
|
var JSON_MsgAckWarp = (function() {
|
|
@@ -476,21 +736,17 @@ var JSON_MsgAckWarp = (function() {
|
|
|
476
736
|
// return json_msgAckWarp;
|
|
477
737
|
// }
|
|
478
738
|
create_with_msgOk : function(json_msgWarp, b_ok= true) {
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
return
|
|
739
|
+
const json_msgAck_msg= jsonMsg_cjsExports.JSON_MsgAck_msg.create_with_msgOk(json_msgWarp, b_ok);
|
|
740
|
+
json_msgAck_msg["2PhW"]= k_VERSION;
|
|
741
|
+
return json_msgAck_msg;
|
|
482
742
|
},
|
|
483
743
|
create_with_msgExpired : function( json_msgWarp ) {
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
return
|
|
744
|
+
const json_msgAck_msg= jsonMsg_cjsExports.JSON_MsgAck_msg.create_with_msgExpired( json_msgWarp );
|
|
745
|
+
json_msgAck_msg["2PhW"]= k_VERSION;
|
|
746
|
+
return json_msgAck_msg;
|
|
487
747
|
},
|
|
488
748
|
validate : function(json) {
|
|
489
|
-
if (!
|
|
490
|
-
LOGR_.log(l_.VALIDATION, 'JSON_MsgAckWarp: validate_Msg2PhW_: ', validate_Msg2PhW.errors);
|
|
491
|
-
return false;
|
|
492
|
-
}
|
|
493
|
-
if (! jsonMsg_cjsExports.JSON_MsgAck.validate(json))
|
|
749
|
+
if (! jsonMsg_cjsExports.JSON_MsgAck_msg.validate(json))
|
|
494
750
|
return false;
|
|
495
751
|
if (! JSON_MsgWarp.validate(json._msg))
|
|
496
752
|
return false;
|
|
@@ -507,21 +763,17 @@ var JSON_MsgAckEngage = (function() {
|
|
|
507
763
|
// return json_msgAckEngage;
|
|
508
764
|
// }
|
|
509
765
|
create_with_msgOk : function(json_msgEngage, b_ok= true) {
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
return
|
|
766
|
+
const json_msgAck_msg= jsonMsg_cjsExports.JSON_MsgAck_msg.create_with_msgOk(json_msgEngage, b_ok);
|
|
767
|
+
json_msgAck_msg["2PhW"]= k_VERSION;
|
|
768
|
+
return json_msgAck_msg;
|
|
513
769
|
},
|
|
514
770
|
create_with_msgExpired : function( json_msgEngage ) {
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
return
|
|
771
|
+
const json_msgAck_msg= jsonMsg_cjsExports.JSON_MsgAck_msg.create_with_msgExpired( json_msgEngage );
|
|
772
|
+
json_msgAck_msg["2PhW"]= k_VERSION;
|
|
773
|
+
return json_msgAck_msg;
|
|
518
774
|
},
|
|
519
775
|
validate : function(json) {
|
|
520
|
-
if (!
|
|
521
|
-
LOGR_.log(l_.VALIDATION, 'JSON_MsgAckEngage: validate_Msg2PhW_: ', validate_Msg2PhW.errors);
|
|
522
|
-
return false;
|
|
523
|
-
}
|
|
524
|
-
if (! jsonMsg_cjsExports.JSON_MsgAck.validate(json))
|
|
776
|
+
if (! jsonMsg_cjsExports.JSON_MsgAck_msg.validate(json))
|
|
525
777
|
return false;
|
|
526
778
|
if (! JSON_MsgEngage.validate(json._msg))
|
|
527
779
|
return false;
|
|
@@ -530,305 +782,510 @@ var JSON_MsgAckEngage = (function() {
|
|
|
530
782
|
}
|
|
531
783
|
})();
|
|
532
784
|
|
|
533
|
-
|
|
534
785
|
//-------------------------------------------------------------------------------------------------
|
|
535
|
-
//
|
|
786
|
+
// States
|
|
536
787
|
|
|
537
788
|
class StateState {
|
|
538
|
-
constructor(
|
|
539
|
-
this.
|
|
540
|
-
this.
|
|
541
|
-
this.
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
start() {
|
|
546
|
-
this.dt_start_= Date.now();
|
|
547
|
-
console.log(`setTimeout: start ${this.dt_start_}, remaining ${this.nr_remaining_msec_}`);
|
|
548
|
-
this.nr_timeout_id_= setTimeout(this.f_callback_, this.nr_remaining_msec_);
|
|
549
|
-
}
|
|
550
|
-
changeState(newState, nr_ttl_msec, f_callback) {
|
|
551
|
-
if (! this.state_current_.changeState(newState))
|
|
552
|
-
return false;
|
|
553
|
-
this.state_current_ = newState;
|
|
554
|
-
|
|
555
|
-
clearTimeout(this.nr_timeout_id_);
|
|
556
|
-
if (nr_ttl_msec != undefined && f_callback != undefined) {
|
|
557
|
-
this.f_callback_= f_callback;
|
|
558
|
-
this.nr_remaining_msec_= nr_ttl_msec;
|
|
559
|
-
this.start();
|
|
560
|
-
}
|
|
561
|
-
return true;
|
|
789
|
+
constructor(idx_event, event) {
|
|
790
|
+
this._protocol_parent = null;
|
|
791
|
+
this._idx_event = idx_event;
|
|
792
|
+
this._event = event;
|
|
793
|
+
}
|
|
794
|
+
get protocol() {
|
|
795
|
+
return this._protocol_parent;
|
|
562
796
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
const nr_elapsed_ms= Date.now() - this.dt_start_;
|
|
566
|
-
this.nr_remaining_msec_= Math.max(this.nr_remaining_msec_ - nr_elapsed_ms, 0) + nr_delay_msec;
|
|
567
|
-
this.start();
|
|
797
|
+
set protocol(parent) {
|
|
798
|
+
this._protocol_parent = parent;
|
|
568
799
|
}
|
|
569
|
-
|
|
570
|
-
return this.
|
|
800
|
+
get idx_event() {
|
|
801
|
+
return this._idx_event;
|
|
802
|
+
}
|
|
803
|
+
get event() {
|
|
804
|
+
return this._event;
|
|
805
|
+
}
|
|
806
|
+
get json_msg() {
|
|
807
|
+
return this._event.data;
|
|
808
|
+
}
|
|
809
|
+
changeState(state_new) {
|
|
810
|
+
if (this.canChangeState(state_new))
|
|
811
|
+
this.protocol.state = state_new;
|
|
812
|
+
else
|
|
813
|
+
this.protocol.state = new StateINVALID(state_new._idx_event, state_new._event);
|
|
814
|
+
}
|
|
815
|
+
canChangeState(_state_new) {
|
|
816
|
+
throw new Error("Subclass must implement canChangeState()");
|
|
571
817
|
}
|
|
572
818
|
}
|
|
573
819
|
|
|
574
|
-
class
|
|
575
|
-
|
|
576
|
-
|
|
820
|
+
class StateAckEngage extends StateState {
|
|
821
|
+
constructor(idx_event, event) { super(idx_event, event); }
|
|
822
|
+
get evt_AckEngage() { return this.event }
|
|
823
|
+
get json_msgAckEngage() { return this.json_msg }
|
|
824
|
+
canChangeState(_state_new) {
|
|
825
|
+
return false;
|
|
577
826
|
}
|
|
578
827
|
}
|
|
579
|
-
|
|
580
|
-
// class State<Name> {
|
|
581
|
-
// changeState= function(newState) {
|
|
582
|
-
// return false;
|
|
583
|
-
// }
|
|
584
|
-
// }
|
|
585
828
|
|
|
586
|
-
|
|
587
|
-
|
|
829
|
+
class StateEngage extends StateState {
|
|
830
|
+
constructor(idx_event, event) { super(idx_event, event); }
|
|
831
|
+
get evt_Engage() { return this.event }
|
|
832
|
+
get json_msgEngage() { return this.json_msg }
|
|
833
|
+
canChangeState(state_new) {
|
|
834
|
+
if (false === state_new instanceof StateAckEngage)
|
|
835
|
+
return false;
|
|
588
836
|
|
|
589
|
-
//
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
837
|
+
// The Engage gets to live for THE WARP'S creation time + TTL*2 + RTT
|
|
838
|
+
const json_msgWarp= this.json_msgEngage._msg;
|
|
839
|
+
const timeout_ms= t_ttl_rtt_(json_msgWarp.warp.ttl_msec, this.json_msgEngage.engage.rtt_msec);
|
|
840
|
+
log_(l_.PROTOCOL_STATE, () => [`StateEngage: evt_AckEngage.dt@${state_new.evt_AckEngage.dt}, msgWarp.dt@${Date.parse(json_msgWarp.dt)} + ${timeout_ms}`]);
|
|
841
|
+
if (state_new.evt_AckEngage.dt >= Date.parse(json_msgWarp.dt) + timeout_ms)
|
|
842
|
+
return false;
|
|
593
843
|
|
|
594
|
-
|
|
595
|
-
constructor(initState= new StateInitialState() ) {
|
|
596
|
-
super(initState);
|
|
844
|
+
return true;
|
|
597
845
|
}
|
|
598
846
|
}
|
|
599
847
|
|
|
600
|
-
class
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
}
|
|
608
|
-
}
|
|
848
|
+
class StateAckWarp extends StateState {
|
|
849
|
+
constructor(idx_event, event) { super(idx_event, event); }
|
|
850
|
+
get evt_AckWarp() { return this.event }
|
|
851
|
+
get json_msgAckWarp() { return this.json_msg }
|
|
852
|
+
canChangeState(state_new) {
|
|
853
|
+
if (false === state_new instanceof StateEngage)
|
|
854
|
+
return false;
|
|
609
855
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
856
|
+
if (! this.json_msgAckWarp.ack.ok)
|
|
857
|
+
return false;
|
|
858
|
+
|
|
859
|
+
if (this.json_msgAckWarp._msg.warp.instantaneous)
|
|
860
|
+
return false;
|
|
861
|
+
|
|
862
|
+
// The Ack gets to live for THE ACK'S creation time + TTL*2 + STT
|
|
863
|
+
// +STT, so lines up with the Engage timeout
|
|
864
|
+
// - Engage: T0 +2TTL +RTT; RTT= STT+STT
|
|
865
|
+
// - AckWarp: TAckWarp +2TLL +STT; TAckWarp= T0 +STT;
|
|
866
|
+
// - STT: Date of the Ack minus date of the Warp.
|
|
867
|
+
const timeout_ms= t_ttl_rtt_(this.json_msgAckWarp._msg.warp.ttl_msec) + Date.parse(this.json_msgAckWarp.dt) - Date.parse(this.json_msgAckWarp._msg.dt);
|
|
868
|
+
log_(l_.PROTOCOL_STATE, () => [`StateAckWarp: evt_Engage.dt@${state_new.evt_Engage.dt}, msgAckWarp.dt@${Date.parse(this.json_msgAckWarp.dt)} + ${timeout_ms}`]);
|
|
869
|
+
if (state_new.evt_Engage.dt >= Date.parse(this.json_msgAckWarp.dt) + timeout_ms)
|
|
870
|
+
return false;
|
|
871
|
+
|
|
872
|
+
return true;
|
|
617
873
|
}
|
|
618
874
|
}
|
|
619
875
|
|
|
620
|
-
class
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
876
|
+
class StateWarp extends StateState {
|
|
877
|
+
constructor(idx_event, event) { super(idx_event, event); }
|
|
878
|
+
get evt_Warp() { return this.event }
|
|
879
|
+
get json_msgWarp() { return this.json_msg }
|
|
880
|
+
canChangeState(state_new) {
|
|
881
|
+
if (false === state_new instanceof StateAckWarp)
|
|
882
|
+
return false;
|
|
883
|
+
|
|
884
|
+
// The Warp gets to live for THE WARP'S creation time + TTL*2
|
|
885
|
+
const timeout_ms= t_ttl_rtt_(this.json_msgWarp.warp.ttl_msec);
|
|
886
|
+
log_(l_.PROTOCOL_STATE, () => [`StateWarp: evt_AckWarp.dt@${state_new.evt_AckWarp.dt}, msgWarp.dt@${Date.parse(this.json_msgWarp.dt)} + ${timeout_ms}`]);
|
|
887
|
+
if (state_new.evt_AckWarp.dt >= Date.parse(this.json_msgWarp.dt) + timeout_ms)
|
|
888
|
+
return false;
|
|
889
|
+
|
|
890
|
+
return true;
|
|
625
891
|
}
|
|
626
892
|
}
|
|
627
893
|
|
|
628
|
-
class
|
|
629
|
-
|
|
894
|
+
class StateINVALID extends StateState {
|
|
895
|
+
constructor(idx_event, event) { super(idx_event, event); }
|
|
896
|
+
canChangeState(_state_new) {
|
|
897
|
+
// INVALID can't transition to any state
|
|
630
898
|
return false;
|
|
631
899
|
}
|
|
632
900
|
}
|
|
633
901
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
LOGR_.log(l_.HANDLERS, 'handler_msgOptions_: ...');
|
|
639
|
-
|
|
640
|
-
if (! validate_Options_delay(json_msgOptions.options))
|
|
641
|
-
return false;
|
|
642
|
-
|
|
643
|
-
if (JSON_MsgWarp.validate(json_msgOptions._msg)) {
|
|
644
|
-
const json_msgWarp= json_msgOptions._msg;
|
|
645
|
-
|
|
646
|
-
const ctx= get_ctx(json_msgWarp.id);
|
|
647
|
-
if (!ctx )
|
|
902
|
+
class StateInitialState extends StateState {
|
|
903
|
+
constructor() { super(null, null); }
|
|
904
|
+
canChangeState(state_new) {
|
|
905
|
+
if (false === state_new instanceof StateWarp)
|
|
648
906
|
return false;
|
|
649
907
|
|
|
650
|
-
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
|
|
908
|
+
// The NEWLY created Warp only gets to live for its creation time + TTL
|
|
909
|
+
const timeout_ms= state_new.json_msgWarp.warp.ttl_msec;
|
|
910
|
+
log_(l_.PROTOCOL_STATE, () => [`StateInitialState: evt_Warp.dt@${state_new.evt_Warp.dt}, msgWarp.dt@${Date.parse(state_new.json_msgWarp.dt)} + ${timeout_ms}`]);
|
|
911
|
+
if (state_new.evt_Warp.dt >= Date.parse(state_new.json_msgWarp.dt) + timeout_ms)
|
|
912
|
+
return false;
|
|
654
913
|
|
|
655
|
-
|
|
914
|
+
return true;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
656
917
|
|
|
657
|
-
|
|
918
|
+
//----
|
|
658
919
|
|
|
659
|
-
|
|
660
|
-
|
|
920
|
+
class ProtocolStateState {
|
|
921
|
+
constructor(state_initial) {
|
|
922
|
+
this.state = state_initial || new StateInitialState();
|
|
923
|
+
}
|
|
661
924
|
|
|
662
|
-
|
|
925
|
+
set state(state_new) {
|
|
926
|
+
if (! (state_new instanceof StateState)) {
|
|
927
|
+
throw new Error("initState must be an instance of StateState or its subclasses");
|
|
928
|
+
}
|
|
929
|
+
this._state = state_new;
|
|
930
|
+
if (state_new && state_new.protocol !== this) {
|
|
931
|
+
state_new.protocol = this;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
get state() {
|
|
935
|
+
return this._state;
|
|
663
936
|
}
|
|
664
937
|
|
|
665
|
-
|
|
938
|
+
canChangeState(state_new) {
|
|
939
|
+
return this._state.canChangeState(state_new);
|
|
940
|
+
}
|
|
666
941
|
}
|
|
667
942
|
|
|
668
943
|
//-------------------------------------------------------------------------------------------------
|
|
669
|
-
// Sender
|
|
670
944
|
|
|
671
|
-
|
|
672
|
-
{
|
|
673
|
-
|
|
945
|
+
class TwoPhW_EventLog {
|
|
946
|
+
constructor(eventLog) {
|
|
947
|
+
this._eventLog = eventLog;
|
|
948
|
+
}
|
|
674
949
|
|
|
675
|
-
|
|
950
|
+
_warp(json_msg) {
|
|
951
|
+
const b_Ack = json_msg.ack !== undefined;
|
|
952
|
+
const json = b_Ack ? json_msg["_msg"] : json_msg;
|
|
676
953
|
|
|
677
|
-
|
|
954
|
+
if (json.warp) {
|
|
955
|
+
return {
|
|
956
|
+
str_type: `2PhW[JSON_Msg${b_Ack ? 'Ack' : ''}Warp]`,
|
|
957
|
+
json_msgWarp: json
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
if (json.engage) {
|
|
961
|
+
return {
|
|
962
|
+
str_type: `2PhW[JSON_Msg${b_Ack ? 'Ack' : ''}Engage]`,
|
|
963
|
+
json_msgWarp: json["_msg"]
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
return { str_type: null, json_msgWarp: null }; // Explicit default for invalid cases
|
|
967
|
+
}
|
|
678
968
|
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
969
|
+
_addEvent(json_msg, timeout_ms, timeout_callback) {
|
|
970
|
+
const { str_type, json_msgWarp }= this._warp(json_msg);
|
|
971
|
+
const { idx }= this._eventLog.addEvent(str_type, json_msgWarp.warp.id, json_msg, timeout_ms, timeout_callback);
|
|
972
|
+
log_(l_.PROTOCOL_STATE, () => [`_addEvent: [${idx}] timeout:${Date.now()}+${timeout_ms} `, json_msg]);
|
|
973
|
+
}
|
|
682
974
|
|
|
683
|
-
|
|
975
|
+
_dropEvent(json_msg) {
|
|
976
|
+
const { json_msgWarp }= this._warp(json_msg);
|
|
977
|
+
if (! json_msgWarp)
|
|
978
|
+
return;
|
|
979
|
+
this._eventLog.addEvent('2PhW[DROPPED!]', json_msgWarp.warp.id, json_msg);
|
|
980
|
+
}
|
|
684
981
|
|
|
685
|
-
|
|
982
|
+
_cancelTimeout(idx_event) {
|
|
983
|
+
log_(l_.PROTOCOL_STATE, () => [`_cancelTimeout: [${idx_event}] timeout cancelled`]);
|
|
984
|
+
this._eventLog.cancelTimeout(idx_event);
|
|
985
|
+
}
|
|
686
986
|
|
|
687
|
-
|
|
987
|
+
get_protocolState(json_msgWarp) {
|
|
988
|
+
const protocolState = new ProtocolStateState();
|
|
989
|
+
|
|
990
|
+
const arr_evts= this._eventLog.getEventById(json_msgWarp.warp.id, k_TTL);
|
|
991
|
+
log_(l_.EVENTS, () => ['get_protocolState: arr_evts: ', arr_evts]);
|
|
992
|
+
|
|
993
|
+
for (let i = arr_evts.length - 1; i >= 0; i--) {
|
|
994
|
+
const { idx, evt } = arr_evts[i];
|
|
995
|
+
|
|
996
|
+
if (evt.type === '2PhW[DROPPED!]')
|
|
997
|
+
continue;
|
|
998
|
+
|
|
999
|
+
const json_msg= evt.data;
|
|
1000
|
+
if (! JSON_MsgWarp.compare(json_msgWarp, this._warp(json_msg).json_msgWarp) )
|
|
1001
|
+
protocolState.state.changeState( new StateINVALID(idx, evt) );
|
|
1002
|
+
|
|
1003
|
+
switch(evt.type) {
|
|
1004
|
+
case '2PhW[JSON_MsgWarp]' :
|
|
1005
|
+
protocolState.state.changeState( new StateWarp(idx, evt) );
|
|
1006
|
+
break;
|
|
1007
|
+
case '2PhW[JSON_MsgAckWarp]' :
|
|
1008
|
+
protocolState.state.changeState( new StateAckWarp(idx, evt) );
|
|
1009
|
+
break;
|
|
1010
|
+
case '2PhW[JSON_MsgEngage]' :
|
|
1011
|
+
protocolState.state.changeState( new StateEngage(idx, evt) );
|
|
1012
|
+
break;
|
|
1013
|
+
case '2PhW[JSON_MsgAckEngage]' :
|
|
1014
|
+
protocolState.state.changeState( new StateAckEngage(idx, evt) );
|
|
1015
|
+
break;
|
|
1016
|
+
default :
|
|
1017
|
+
protocolState.state.changeState( new StateINVALID(idx, evt) );
|
|
1018
|
+
break;
|
|
1019
|
+
}
|
|
1020
|
+
log_(l_.PROTOCOL_STATE, () => ['get_protocolState: type,state: ',
|
|
1021
|
+
evt.type,
|
|
1022
|
+
(protocolState.state.json_msg.ack?.ok === false) ? '--NACK--' : '',
|
|
1023
|
+
protocolState.state
|
|
1024
|
+
]);
|
|
1025
|
+
}
|
|
1026
|
+
return protocolState;
|
|
1027
|
+
}
|
|
688
1028
|
|
|
689
|
-
|
|
690
|
-
return false;
|
|
1029
|
+
}
|
|
691
1030
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
return true;
|
|
1031
|
+
class TwoPhW {
|
|
1032
|
+
constructor(eventLog) {
|
|
1033
|
+
this._2PhW_eventLog = new TwoPhW_EventLog(eventLog);
|
|
1034
|
+
this._config= new Config();
|
|
697
1035
|
}
|
|
698
1036
|
|
|
699
|
-
|
|
700
|
-
|
|
1037
|
+
get config() {
|
|
1038
|
+
return this._config;
|
|
1039
|
+
}
|
|
701
1040
|
|
|
702
|
-
|
|
703
|
-
|
|
1041
|
+
get eventLog() {
|
|
1042
|
+
return this._2PhW_eventLog;
|
|
1043
|
+
}
|
|
704
1044
|
|
|
705
|
-
|
|
706
|
-
{
|
|
707
|
-
// NOTE: json_msgAck here has a string as _msg, instead of JSON.
|
|
1045
|
+
//-------------------------------------------------------------------------------------------------
|
|
708
1046
|
|
|
709
|
-
|
|
1047
|
+
_handler_msgOptions(cfg, msg, json_msgOptions)
|
|
1048
|
+
{
|
|
1049
|
+
log_(l_.HANDLERS, () => ['handler_msgOptions_: ...']);
|
|
1050
|
+
|
|
1051
|
+
if (! validate_Options_delay_(json_msgOptions.options))
|
|
1052
|
+
return false;
|
|
1053
|
+
|
|
1054
|
+
if (JSON_MsgWarp.validate(json_msgOptions._msg)) {
|
|
1055
|
+
const json_msgWarp= json_msgOptions._msg;
|
|
1056
|
+
|
|
1057
|
+
const ctx= get_ctx(json_msgWarp.id);
|
|
1058
|
+
if (!ctx )
|
|
1059
|
+
return false;
|
|
1060
|
+
|
|
1061
|
+
json_msgOptions.options.ttl_msec_incr[0];
|
|
1062
|
+
const ttl_incr= json_msgOptions.options.ttl_msec_incr[1];
|
|
1063
|
+
|
|
1064
|
+
//TODO: double check ttl_msec is the same as current accummulated ttl for idempotence.
|
|
1065
|
+
|
|
1066
|
+
log_(l_.HANDLERS, () => ['handler_msgOptions_: ', json_msgOptions]);
|
|
1067
|
+
|
|
1068
|
+
ctx.protocol.delayTimeout(ttl_incr);
|
|
1069
|
+
|
|
1070
|
+
if (cfg._callback_msgOptions)
|
|
1071
|
+
return cfg._callback_msgOptions(msg, json_msgOptions);
|
|
1072
|
+
|
|
1073
|
+
return true;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
return false;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
//-------------------------------------------------------------------------------------------------
|
|
1080
|
+
// sender Source (src)
|
|
1081
|
+
|
|
1082
|
+
register_msgWarp(json_msgWarp)
|
|
1083
|
+
{
|
|
1084
|
+
log_(l_.SENDER, () => ['register_msgWarp: ', json_msgWarp]);
|
|
710
1085
|
|
|
711
|
-
|
|
1086
|
+
const protocolState= this.eventLog.get_protocolState(json_msgWarp);
|
|
1087
|
+
const b_changeState= protocolState.canChangeState( new StateWarp(null, {
|
|
1088
|
+
dt: Date.now(),
|
|
1089
|
+
data: json_msgWarp
|
|
1090
|
+
}) );
|
|
712
1091
|
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
1092
|
+
log_(l_.HANDLERS | l_.SENDER, () => ['register_msgWarp: protocolState.canChangeState ', b_changeState]);
|
|
1093
|
+
if (! b_changeState)
|
|
1094
|
+
return false;
|
|
716
1095
|
|
|
717
|
-
|
|
1096
|
+
const timeout_ms= t_ttl_rtt_(json_msgWarp.warp.ttl_msec);
|
|
1097
|
+
const elapsed_ms= Date.now() - Date.parse(json_msgWarp.dt);
|
|
718
1098
|
|
|
719
|
-
|
|
1099
|
+
this.eventLog._addEvent(json_msgWarp, timeout_ms-elapsed_ms, ({ _idx, _evt}) => {
|
|
1100
|
+
this.config._callback_msg_sent_expired(json_msgWarp);
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
720
1103
|
|
|
721
|
-
|
|
722
|
-
|
|
1104
|
+
_handler_msgAckWarp(msg, json_msgAckWarp)
|
|
1105
|
+
{
|
|
1106
|
+
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: ', json_msgAckWarp]);
|
|
1107
|
+
|
|
1108
|
+
const json_msgWarp= json_msgAckWarp._msg;
|
|
1109
|
+
|
|
1110
|
+
const protocolState= this.eventLog.get_protocolState(json_msgWarp);
|
|
1111
|
+
const b_changeState= protocolState.canChangeState( new StateAckWarp(null, {
|
|
1112
|
+
dt: Date.now(),
|
|
1113
|
+
data: json_msgAckWarp
|
|
1114
|
+
}) );
|
|
1115
|
+
|
|
1116
|
+
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckWarp: protocolState.canChangeState ', b_changeState]);
|
|
1117
|
+
if (! b_changeState)
|
|
1118
|
+
return false;
|
|
723
1119
|
|
|
724
|
-
|
|
725
|
-
|
|
1120
|
+
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
1121
|
+
this.eventLog._addEvent(json_msgAckWarp);
|
|
1122
|
+
if (! this.config._callback_msgAckWarp(msg, json_msgAckWarp))
|
|
1123
|
+
return false;
|
|
1124
|
+
|
|
1125
|
+
return true;
|
|
1126
|
+
}
|
|
726
1127
|
|
|
727
|
-
|
|
728
|
-
|
|
1128
|
+
register_msgEngage(json_msgEngage)
|
|
1129
|
+
{
|
|
1130
|
+
log_(l_.SENDER, () => ['register_msgEngage: ', json_msgEngage]);
|
|
729
1131
|
|
|
730
|
-
|
|
731
|
-
{
|
|
732
|
-
LOGR_.log(l_.HANDLERS, 'handler_msgWarp: ...');
|
|
1132
|
+
const json_msgWarp= json_msgEngage._msg;
|
|
733
1133
|
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
1134
|
+
const protocolState= this.eventLog.get_protocolState(json_msgWarp);
|
|
1135
|
+
const b_changeState= protocolState.canChangeState( new StateEngage(null, {
|
|
1136
|
+
dt: Date.now(),
|
|
1137
|
+
data : json_msgEngage
|
|
1138
|
+
}) );
|
|
737
1139
|
|
|
738
|
-
|
|
739
|
-
|
|
1140
|
+
log_(l_.HANDLERS | l_.SENDER, () => ['register_msgEngage: protocolState.canChangeState ', b_changeState]);
|
|
1141
|
+
if (! b_changeState)
|
|
1142
|
+
return false;
|
|
1143
|
+
|
|
1144
|
+
const timeout_ms= t_ttl_rtt_(json_msgWarp.warp.ttl_msec, json_msgEngage.engage.rtt_msec);
|
|
1145
|
+
const elapsed_ms= Date.now() - Date.parse(json_msgWarp.dt);
|
|
740
1146
|
|
|
741
|
-
|
|
1147
|
+
this.eventLog._addEvent(json_msgEngage, timeout_ms-elapsed_ms, () => {
|
|
1148
|
+
this.config._callback_msg_sent_expired(json_msgEngage);
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
_handler_msgAckEngage(msg, json_msgAckEngage)
|
|
1153
|
+
{
|
|
1154
|
+
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage: ', json_msgAckEngage]);
|
|
1155
|
+
|
|
1156
|
+
const json_msgWarp= json_msgAckEngage._msg._msg;
|
|
742
1157
|
|
|
743
|
-
|
|
744
|
-
|
|
1158
|
+
const protocolState= this.eventLog.get_protocolState(json_msgWarp);
|
|
1159
|
+
const b_changeState= protocolState.canChangeState( new StateAckEngage(null, {
|
|
1160
|
+
dt: Date.now(),
|
|
1161
|
+
data : json_msgAckEngage
|
|
1162
|
+
}) );
|
|
1163
|
+
|
|
1164
|
+
log_(l_.HANDLERS | l_.SENDER, () => ['handler_msgAckEngage_: protocolState.canChangeState ', b_changeState]);
|
|
1165
|
+
if (! b_changeState)
|
|
1166
|
+
return false;
|
|
745
1167
|
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
1168
|
+
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
1169
|
+
this.eventLog._addEvent(json_msgAckEngage);
|
|
1170
|
+
if (! this.config._callback_msgAckEngage(msg, json_msgAckEngage))
|
|
1171
|
+
return false;
|
|
749
1172
|
|
|
750
1173
|
return true;
|
|
751
1174
|
}
|
|
1175
|
+
|
|
1176
|
+
//-------------------------------------------------------------------------------------------------
|
|
1177
|
+
// receiver Destination (dst)
|
|
752
1178
|
|
|
753
|
-
|
|
754
|
-
|
|
1179
|
+
_handler_msgWarp(msg, json_msgWarp)
|
|
1180
|
+
{
|
|
1181
|
+
log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: ', json_msgWarp]);
|
|
1182
|
+
|
|
1183
|
+
const protocolState= this.eventLog.get_protocolState(json_msgWarp);
|
|
1184
|
+
const b_changeState= protocolState.canChangeState( new StateWarp(null, {
|
|
1185
|
+
dt: Date.now(),
|
|
1186
|
+
data: json_msgWarp
|
|
1187
|
+
}) );
|
|
1188
|
+
|
|
1189
|
+
log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgWarp: protocolState.canChangeState: ', b_changeState]);
|
|
1190
|
+
if (! b_changeState)
|
|
1191
|
+
return false;
|
|
755
1192
|
|
|
756
|
-
|
|
757
|
-
|
|
1193
|
+
this.eventLog._addEvent(json_msgWarp);
|
|
1194
|
+
if (! this.config._callback_msgWarp(msg, json_msgWarp))
|
|
1195
|
+
return false;
|
|
1196
|
+
|
|
1197
|
+
return true;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
register_msgAckWarp(json_msgAckWarp)
|
|
1201
|
+
{
|
|
1202
|
+
log_(l_.RECVER, () => ['register_msgAckWarp: ', json_msgAckWarp]);
|
|
758
1203
|
|
|
759
|
-
|
|
760
|
-
{
|
|
761
|
-
LOGR_.log(l_.HANDLERS, 'handler_msgEngage: ...');
|
|
1204
|
+
const json_msgWarp= json_msgAckWarp._msg;
|
|
762
1205
|
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
1206
|
+
const protocolState= this.eventLog.get_protocolState(json_msgWarp);
|
|
1207
|
+
const b_changeState= protocolState.canChangeState( new StateAckWarp(null, {
|
|
1208
|
+
dt: Date.now(),
|
|
1209
|
+
data: json_msgAckWarp
|
|
1210
|
+
}) );
|
|
766
1211
|
|
|
767
|
-
|
|
1212
|
+
log_(l_.HANDLERS | l_.RECVER, () => ['register_msgAckWarp: protocolState.canChangeState: ', b_changeState]);
|
|
1213
|
+
if (! b_changeState)
|
|
1214
|
+
return false;
|
|
768
1215
|
|
|
769
|
-
|
|
770
|
-
|
|
1216
|
+
const elapsed_ms= Date.now() - Date.parse(json_msgAckWarp.dt);
|
|
1217
|
+
const timeout_ms= t_ttl_rtt_(json_msgWarp.warp.ttl_msec) + Date.parse(json_msgAckWarp.dt) - Date.parse(json_msgWarp.dt);
|
|
771
1218
|
|
|
772
|
-
|
|
773
|
-
|
|
1219
|
+
this.eventLog._addEvent(json_msgAckWarp, timeout_ms-elapsed_ms, ({ _idx, _evt}) => {
|
|
1220
|
+
this.config._callback_msg_sent_expired(json_msgAckWarp);
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
774
1223
|
|
|
775
|
-
|
|
776
|
-
|
|
1224
|
+
_handler_msgEngage(msg, json_msgEngage)
|
|
1225
|
+
{
|
|
1226
|
+
log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: ', json_msgEngage]);
|
|
777
1227
|
|
|
778
|
-
|
|
1228
|
+
const json_msgWarp= json_msgEngage["_msg"];
|
|
779
1229
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
1230
|
+
const protocolState= this.eventLog.get_protocolState(json_msgWarp);
|
|
1231
|
+
const b_changeState= protocolState.canChangeState( new StateEngage(null, {
|
|
1232
|
+
dt: Date.now(),
|
|
1233
|
+
data: json_msgEngage
|
|
1234
|
+
}) );
|
|
784
1235
|
|
|
785
|
-
|
|
786
|
-
|
|
1236
|
+
log_(l_.HANDLERS | l_.RECVER, () => ['handler_msgEngage: protocolState.canChangeState: ', b_changeState]);
|
|
1237
|
+
if (! b_changeState)
|
|
1238
|
+
return false;
|
|
1239
|
+
|
|
1240
|
+
this.eventLog._cancelTimeout(protocolState.state.idx_event);
|
|
1241
|
+
this.eventLog._addEvent(json_msgEngage);
|
|
1242
|
+
if (! this.config._callback_msgEngage(msg, json_msgEngage))
|
|
1243
|
+
return false;
|
|
1244
|
+
|
|
1245
|
+
return true;
|
|
787
1246
|
}
|
|
788
1247
|
|
|
789
|
-
|
|
790
|
-
create_MsgWarp_out(str_id, json_user, json_hyperport, nr_ttl_msec, b_instantaneous)
|
|
1248
|
+
register_msgAckEngage(json_msgAckEngage)
|
|
791
1249
|
{
|
|
792
|
-
|
|
793
|
-
nr_ttl_msec= k_TTL;
|
|
1250
|
+
log_(l_.RECVER, () => ['register_msgAckEngage: ', json_msgAckEngage]);
|
|
794
1251
|
|
|
795
|
-
const json_msgWarp=
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
1252
|
+
const json_msgWarp= json_msgAckEngage._msg._msg;
|
|
1253
|
+
|
|
1254
|
+
const protocolState= this.eventLog.get_protocolState(json_msgWarp);
|
|
1255
|
+
const b_changeState= protocolState.canChangeState( new StateAckEngage(null, {
|
|
1256
|
+
dt: Date.now(),
|
|
1257
|
+
data: json_msgAckEngage
|
|
1258
|
+
}) );
|
|
800
1259
|
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
//TODO: the referer is NULL here !
|
|
805
|
-
this._config._callback_msgAckWarp(json_Nack, json_Nack);
|
|
806
|
-
}.bind(this) );
|
|
1260
|
+
log_(l_.HANDLERS | l_.RECVER, () => ['register_msgAckEngage: protocolState.canChangeState: ', b_changeState]);
|
|
1261
|
+
if (! b_changeState)
|
|
1262
|
+
return false;
|
|
807
1263
|
|
|
808
|
-
|
|
809
|
-
return json_msgWarp;
|
|
1264
|
+
this.eventLog._addEvent(json_msgAckEngage);
|
|
810
1265
|
}
|
|
811
1266
|
|
|
1267
|
+
//-------------------------------------------------------------------------------------------------
|
|
1268
|
+
|
|
812
1269
|
handler_msg_json(msg, json_msg)
|
|
813
1270
|
{
|
|
814
|
-
|
|
1271
|
+
log_(l_.HANDLERS, () => ['handler_msg_json: ', json_msg]);
|
|
815
1272
|
|
|
816
1273
|
// ADR: I could parse json_Msg_msg first and then MsgAck or MsgOptions, but
|
|
817
1274
|
// doing so means super classes get parsed multiple times for no reason
|
|
818
1275
|
|
|
819
|
-
if (JSON_MsgOptions.validate(json_msg) && handler_msgOptions_(this._config, msg, json_msg))
|
|
820
|
-
|
|
1276
|
+
// if (JSON_MsgOptions.validate(json_msg) && this.handler_msgOptions_(this._config, msg, json_msg))
|
|
1277
|
+
// return true;
|
|
821
1278
|
|
|
822
|
-
if (JSON_MsgWarp.validate(json_msg) &&
|
|
1279
|
+
if (JSON_MsgWarp.validate(json_msg) && this._handler_msgWarp(msg, json_msg))
|
|
823
1280
|
return true;
|
|
824
1281
|
|
|
825
|
-
if (JSON_MsgEngage.validate(json_msg) &&
|
|
1282
|
+
if (JSON_MsgEngage.validate(json_msg) && this._handler_msgEngage(msg, json_msg))
|
|
826
1283
|
return true;
|
|
827
1284
|
|
|
828
|
-
if (JSON_MsgAckWarp.validate(json_msg) &&
|
|
1285
|
+
if (JSON_MsgAckWarp.validate(json_msg) && this._handler_msgAckWarp(msg, json_msg))
|
|
829
1286
|
return true;
|
|
830
1287
|
|
|
831
|
-
if (JSON_MsgAckEngage.validate(json_msg) &&
|
|
1288
|
+
if (JSON_MsgAckEngage.validate(json_msg) && this._handler_msgAckEngage(msg, json_msg))
|
|
832
1289
|
return true;
|
|
833
1290
|
|
|
834
1291
|
// https://attacomsian.com/blog/javascript-iterate-objects
|
|
@@ -840,12 +1297,14 @@ class TwoPhW {
|
|
|
840
1297
|
// console.log(`${key}: ${json_msg[key]}`);
|
|
841
1298
|
// });
|
|
842
1299
|
|
|
1300
|
+
this.eventLog._dropEvent(json_msg);
|
|
1301
|
+
log_(l_.DROPS, () => ["TwoPhW: handler_msg: DROP! ", msg]);
|
|
843
1302
|
return false;
|
|
844
1303
|
}
|
|
845
1304
|
|
|
846
1305
|
handler_msg_str(msg, str_msg)
|
|
847
1306
|
{
|
|
848
|
-
|
|
1307
|
+
log_(l_.HANDLERS, () => ['handler_msg_str: ['+ str_msg +']']);
|
|
849
1308
|
|
|
850
1309
|
// ... test strings here
|
|
851
1310
|
|
|
@@ -862,18 +1321,17 @@ class TwoPhW {
|
|
|
862
1321
|
|
|
863
1322
|
handler_msg(msg)
|
|
864
1323
|
{
|
|
865
|
-
|
|
1324
|
+
log_(l_.HANDLERS, () => ['handler_msg: ', msg]);
|
|
866
1325
|
|
|
867
1326
|
if (typeof (msg) === 'string' && this.handler_msg_str(msg, msg))
|
|
868
1327
|
return true;
|
|
869
1328
|
|
|
870
1329
|
if (typeof (msg) === 'object' && this.handler_msg_json(msg, msg))
|
|
871
1330
|
return true;
|
|
872
|
-
|
|
873
|
-
LOGR_.log(l_.DROPS, "handler_msg: DROP! ", msg);
|
|
1331
|
+
|
|
874
1332
|
return false
|
|
875
1333
|
}
|
|
876
1334
|
|
|
877
1335
|
}
|
|
878
1336
|
|
|
879
|
-
export { JSON_MsgAckEngage, JSON_MsgAckWarp, JSON_MsgEngage, JSON_MsgOptions, JSON_MsgWarp, TwoPhW, l_ as l };
|
|
1337
|
+
export { EventLog, JSON_MsgAckEngage, JSON_MsgAckWarp, JSON_MsgEngage, JSON_MsgOptions, JSON_MsgWarp, StateAckEngage, StateAckWarp, StateEngage, StateINVALID, StateInitialState, StateWarp, TwoPhW, l_ as l, t_ttl_rtt_ as t_ttl_rtt };
|