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