@rootintf/protocol-2phw 2.0.3-api.2 → 2.2.2-api.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EventLog-mem.d.mts +2 -5
- package/dist/twoPhW.cjs.js +451 -306
- package/dist/twoPhW.d.ts +23 -24
- package/dist/twoPhW.es.mjs +451 -306
- package/package.json +7 -7
- package/src/EventLog-mem.mjs +9 -15
- package/src/index.ts +1 -1
- package/src/twoPhW.ts +80 -80
- package/tests/event-log-mem.spec.mjs +9 -4
- package/tests/twoPhW-new.spec.mjs +66 -47
- package/dist/index.d.ts +0 -1
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
3
|
import { LOGR, l_concat } from '@knev/bitlogr';
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
StateAckEngage, StateEngage, StateAckWarp, StateWarp, StateInitialState, StateINVALID,
|
|
6
|
+
EventLog,
|
|
7
|
+
t_ttl_rtt,
|
|
8
|
+
TwoPhW, JSON_MsgOptions, JSON_MsgWarp, JSON_MsgEngage, JSON_MsgAckWarp, JSON_MsgAckEngage,
|
|
9
|
+
logr as logr_,
|
|
10
|
+
JSON_Msg, JSON_MsgEffect, JSON_MsgAck
|
|
11
|
+
} from '../dist/twoPhW.es.mjs';
|
|
12
|
+
|
|
13
|
+
// this leads to two copies of l_ from '@rootintf/json-msg'; one copy from twoPhW
|
|
14
|
+
// import { JSON_Msg, JSON_MsgEffect, JSON_MsgAck, l as l_json_msg } from '@rootintf/json-msg'
|
|
11
15
|
|
|
12
16
|
const k_VERSION= "2";
|
|
13
17
|
|
|
@@ -22,14 +26,13 @@ const RTT_MSEC_2000= 2000;
|
|
|
22
26
|
|
|
23
27
|
//-------------------------------------------------------------------------------------------------
|
|
24
28
|
|
|
25
|
-
const LOGR_= LOGR.get_instance()
|
|
29
|
+
const LOGR_= LOGR.get_instance();
|
|
30
|
+
const l_= logr_.l;
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
LOGR_.log(l_.LOG_TEST, () => ['const l_ ', l_])
|
|
32
|
+
LOGR_.toggle(l_, {
|
|
33
|
+
VALIDATION : true
|
|
34
|
+
});
|
|
35
|
+
logr_.raw('twoPhW-new.spec: const l_ ', l_.get())
|
|
33
36
|
|
|
34
37
|
//-------------------------------------------------------------------------------------------------
|
|
35
38
|
|
|
@@ -155,6 +158,22 @@ describe("Validation", function () {
|
|
|
155
158
|
it("JSON_MsgAckEngage.validate(json_msgAckEngage_)", function () {
|
|
156
159
|
expect( JSON_MsgAckEngage.validate(json_msgAckEngage_) ).toBe(true);
|
|
157
160
|
});
|
|
161
|
+
|
|
162
|
+
it("LOGR test", function () {
|
|
163
|
+
const json_msgWarp= JSON_MsgWarp.create_with_id_user_hyperport(
|
|
164
|
+
"f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
165
|
+
'',
|
|
166
|
+
'',
|
|
167
|
+
3000
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
LOGR_.toggle(l_, {
|
|
171
|
+
VALIDATION : true
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
expect( JSON_MsgEffect.validate(json_msgWarp) ).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
|
|
158
177
|
});
|
|
159
178
|
|
|
160
179
|
//-------------------------------------------------------------------------------------------------
|
|
@@ -208,7 +227,7 @@ describe('2PhW protocol', () => {
|
|
|
208
227
|
"t_ttl_rtt_: INVALID rtt_msec ttl_msec[1500] rtt_msec[3001]"
|
|
209
228
|
);
|
|
210
229
|
});
|
|
211
|
-
|
|
230
|
+
|
|
212
231
|
});
|
|
213
232
|
|
|
214
233
|
// ,---, ___
|
|
@@ -240,11 +259,11 @@ describe('2PhW protocol', () => {
|
|
|
240
259
|
callback_msg_sent_expired = jasmine.createSpy('callback_msg_sent_expired');
|
|
241
260
|
|
|
242
261
|
twoPhW.config.receiver( callback_msgWarp, callback_msgEngage, callback_msg_sent_expired )
|
|
243
|
-
LOGR_.
|
|
262
|
+
LOGR_.toggle(l_, {
|
|
244
263
|
// RECVER : 1,
|
|
245
264
|
// PROTOCOL_STATE : 1,
|
|
246
265
|
// DROPS : 1
|
|
247
|
-
}
|
|
266
|
+
});
|
|
248
267
|
|
|
249
268
|
expect(Date.now()-T0).toBe(0);
|
|
250
269
|
|
|
@@ -260,12 +279,12 @@ describe('2PhW protocol', () => {
|
|
|
260
279
|
});
|
|
261
280
|
|
|
262
281
|
afterEach(() => {
|
|
263
|
-
|
|
282
|
+
logr_.log(l_.LOG_TEST, () => ['afterEach: eventLog.arr_events', eventLog.arr_events])
|
|
264
283
|
});
|
|
265
284
|
|
|
266
285
|
it('receive JSON_MsgWarp', () => {
|
|
267
286
|
jasmine.clock().tick(TTL_MSEC_1500 -STT_MSEC_1000 -1); // 1499
|
|
268
|
-
twoPhW.
|
|
287
|
+
twoPhW.handler_json_msg(str_msgWarp_src, json_msgWarp_src);
|
|
269
288
|
expect(callback_msgWarp).toHaveBeenCalled();
|
|
270
289
|
expect(eventLog.arr_events.length).toBe(1);
|
|
271
290
|
expect(eventLog.arr_events[0].type).toBe('2PhW[JSON_MsgWarp]');
|
|
@@ -273,14 +292,14 @@ describe('2PhW protocol', () => {
|
|
|
273
292
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateWarp).toBe(true);
|
|
274
293
|
|
|
275
294
|
// dup
|
|
276
|
-
twoPhW.
|
|
295
|
+
twoPhW.handler_json_msg(str_msgWarp_src, json_msgWarp_src);
|
|
277
296
|
expect(eventLog.arr_events.length).toBe(1);
|
|
278
297
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateWarp).toBe(true);
|
|
279
298
|
});
|
|
280
299
|
|
|
281
300
|
it('receive JSON_MsgWarp expired', () => {
|
|
282
301
|
jasmine.clock().tick(TTL_MSEC_1500 -STT_MSEC_1000); // 1500
|
|
283
|
-
twoPhW.
|
|
302
|
+
twoPhW.handler_json_msg(str_msgWarp_src, json_msgWarp_src);
|
|
284
303
|
expect(callback_msgWarp).not.toHaveBeenCalled();
|
|
285
304
|
expect(eventLog.arr_events.length).toBe(0);
|
|
286
305
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateInitialState).toBe(true);
|
|
@@ -290,13 +309,13 @@ describe('2PhW protocol', () => {
|
|
|
290
309
|
const json_msgEngage_recvd= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
|
|
291
310
|
json_msgEngage_recvd.referer= karr_referer_src;
|
|
292
311
|
|
|
293
|
-
twoPhW.
|
|
312
|
+
twoPhW.handler_json_msgEffect(json_msgEngage_recvd, json_msgEngage_recvd);
|
|
294
313
|
expect(eventLog.arr_events.length).toBe(0);
|
|
295
314
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateInitialState).toBe(true);
|
|
296
315
|
});
|
|
297
316
|
|
|
298
317
|
it('traverse_State JSON_MsgWarp.compare(json_msgWarp, this._warp(json_msg).json_msgWarp )', () => {
|
|
299
|
-
twoPhW.
|
|
318
|
+
twoPhW.handler_json_msg(str_msgWarp_src, json_msgWarp_src);
|
|
300
319
|
expect(eventLog.arr_events.length).toBe(1);
|
|
301
320
|
expect(eventLog.arr_events[0].type).toBe('2PhW[JSON_MsgWarp]');
|
|
302
321
|
expect(eventLog.arr_events[0].data).toEqual({ msg : str_msgWarp_src, json_msg: json_msgWarp_src });
|
|
@@ -307,7 +326,7 @@ describe('2PhW protocol', () => {
|
|
|
307
326
|
};
|
|
308
327
|
jasmine.clock().tick(1); // 1001, make sure it is th wrong date
|
|
309
328
|
json_msgWarp_wrong_dt.dt= new Date().toISOString();
|
|
310
|
-
twoPhW.
|
|
329
|
+
twoPhW.handler_json_msg(json_msgWarp_wrong_dt, json_msgWarp_wrong_dt);
|
|
311
330
|
expect(eventLog.arr_events.length).toBe(1);
|
|
312
331
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateWarp).toBe(true);
|
|
313
332
|
});
|
|
@@ -331,7 +350,7 @@ describe('2PhW protocol', () => {
|
|
|
331
350
|
|
|
332
351
|
expect(Date.now()-T0).toBe(STT_MSEC_1000);
|
|
333
352
|
|
|
334
|
-
twoPhW.
|
|
353
|
+
twoPhW.handler_json_msg(str_msgWarp_src, json_msgWarp_src);
|
|
335
354
|
expect(callback_msgWarp).toHaveBeenCalled();
|
|
336
355
|
expect(eventLog.arr_events.length).toBe(1);
|
|
337
356
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateWarp).toBe(true);
|
|
@@ -362,7 +381,7 @@ describe('2PhW protocol', () => {
|
|
|
362
381
|
const json_msgEngage_src= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
|
|
363
382
|
json_msgEngage_src.referer= karr_referer_src;
|
|
364
383
|
|
|
365
|
-
twoPhW.
|
|
384
|
+
twoPhW.handler_json_msgEffect(json_msgEngage_src, json_msgEngage_src);
|
|
366
385
|
expect(eventLog.arr_events.length).toBe(2);
|
|
367
386
|
});
|
|
368
387
|
|
|
@@ -377,7 +396,7 @@ describe('2PhW protocol', () => {
|
|
|
377
396
|
json_msgEngage_src.referer= karr_referer_src;
|
|
378
397
|
|
|
379
398
|
jasmine.clock().tick(STT_MSEC_1000); // 3000, STT_MSEC_1000 *3
|
|
380
|
-
twoPhW.
|
|
399
|
+
twoPhW.handler_json_msgEffect(json_msgEngage_src, json_msgEngage_src);
|
|
381
400
|
expect(eventLog.arr_events.length).toBe(2);
|
|
382
401
|
});
|
|
383
402
|
|
|
@@ -386,12 +405,12 @@ describe('2PhW protocol', () => {
|
|
|
386
405
|
let str_msgEngage_src;
|
|
387
406
|
|
|
388
407
|
beforeEach(() => {
|
|
389
|
-
LOGR_.
|
|
408
|
+
LOGR_.toggle(l_, {
|
|
390
409
|
// RECVER : 1,
|
|
391
410
|
// PROTOCOL_STATE : 1,
|
|
392
411
|
// DROPS : 1,
|
|
393
412
|
// LOG_TEST : true
|
|
394
|
-
}
|
|
413
|
+
});
|
|
395
414
|
|
|
396
415
|
jasmine.clock().tick(0);
|
|
397
416
|
expect(Date.now()-T0).toBe(STT_MSEC_1000);
|
|
@@ -432,7 +451,7 @@ describe('2PhW protocol', () => {
|
|
|
432
451
|
// - TTL= 1500, RTT= 2000; TTL*2 + RTT= 5000; timeout= 5000
|
|
433
452
|
// - expires at 5000
|
|
434
453
|
|
|
435
|
-
twoPhW.
|
|
454
|
+
twoPhW.handler_json_msgEffect(str_msgEngage_src, json_msgEngage_src);
|
|
436
455
|
expect(callback_msgEngage).not.toHaveBeenCalled();
|
|
437
456
|
expect(eventLog.arr_events.length).toBe(2);
|
|
438
457
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
|
|
@@ -450,15 +469,15 @@ describe('2PhW protocol', () => {
|
|
|
450
469
|
let str_msgNackEngage_dst;
|
|
451
470
|
|
|
452
471
|
beforeEach(() => {
|
|
453
|
-
LOGR_.
|
|
472
|
+
LOGR_.toggle(l_, {
|
|
454
473
|
// RECVER : 1,
|
|
455
474
|
// PROTOCOL_STATE : 1,
|
|
456
475
|
// DROPS : 1
|
|
457
|
-
}
|
|
476
|
+
});
|
|
458
477
|
|
|
459
478
|
jasmine.clock().tick(STT_MSEC_1000); // 3000, STT_MSEC_1000 *3
|
|
460
479
|
|
|
461
|
-
twoPhW.
|
|
480
|
+
twoPhW.handler_json_msgEffect(str_msgEngage_src, json_msgEngage_src);
|
|
462
481
|
expect(callback_msgEngage).toHaveBeenCalled();
|
|
463
482
|
expect(callback_msg_sent_expired).not.toHaveBeenCalled();
|
|
464
483
|
expect(eventLog.arr_events.length).toBe(3);
|
|
@@ -579,11 +598,11 @@ describe('2PhW protocol', () => {
|
|
|
579
598
|
callback_msgAckEngage = jasmine.createSpy('callback_msgAckEngage').and.returnValue(true);
|
|
580
599
|
callback_msg_sent_expired = jasmine.createSpy('callback_msg_sent_expired');
|
|
581
600
|
twoPhW.config.sender( callback_msgAckWarp, callback_msgAckEngage, callback_msg_sent_expired )
|
|
582
|
-
LOGR_.
|
|
601
|
+
LOGR_.toggle(l_, {
|
|
583
602
|
// SENDER : 1,
|
|
584
603
|
// PROTOCOL_STATE : 1,
|
|
585
604
|
// DROPS : 1
|
|
586
|
-
}
|
|
605
|
+
});
|
|
587
606
|
|
|
588
607
|
jasmine.clock().tick(0);
|
|
589
608
|
expect(Date.now()-T0).toBe(0);
|
|
@@ -596,7 +615,7 @@ describe('2PhW protocol', () => {
|
|
|
596
615
|
});
|
|
597
616
|
|
|
598
617
|
afterEach(() => {
|
|
599
|
-
|
|
618
|
+
logr_.log(l_.LOG_TEST, () => ['afterEach: eventLog.arr_events', eventLog.arr_events])
|
|
600
619
|
});
|
|
601
620
|
|
|
602
621
|
it('send JSON_MsgWarp == can register a Warp', () => {
|
|
@@ -630,11 +649,11 @@ describe('2PhW protocol', () => {
|
|
|
630
649
|
let str_msgEngage_src;
|
|
631
650
|
|
|
632
651
|
beforeEach(() => {
|
|
633
|
-
LOGR_.
|
|
652
|
+
LOGR_.toggle(l_, {
|
|
634
653
|
// SENDER : 1,
|
|
635
654
|
// PROTOCOL_STATE : 1,
|
|
636
655
|
// DROPS : 1
|
|
637
|
-
}
|
|
656
|
+
});
|
|
638
657
|
|
|
639
658
|
twoPhW.register_msgWarp(str_msgWarp_src, json_msgWarp_src);
|
|
640
659
|
expect(eventLog.arr_events.length).toBe(1);
|
|
@@ -676,14 +695,14 @@ describe('2PhW protocol', () => {
|
|
|
676
695
|
expect(callback_msgAckWarp).not.toHaveBeenCalled();
|
|
677
696
|
expect(callback_msg_sent_expired).toHaveBeenCalled();
|
|
678
697
|
|
|
679
|
-
twoPhW.
|
|
698
|
+
twoPhW.handler_json_msgAck(json_msgAckWarp_dst, json_msgAckWarp_dst);
|
|
680
699
|
expect(callback_msgAckWarp).not.toHaveBeenCalled();
|
|
681
700
|
expect(eventLog.arr_events.length).toBe(1);
|
|
682
701
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateWarp).toBe(true);
|
|
683
702
|
});
|
|
684
703
|
|
|
685
704
|
it('send JSON_MsgWarp == NACK', () => {
|
|
686
|
-
twoPhW.
|
|
705
|
+
twoPhW.handler_json_msgAck(str_msgNackWarp_dst, json_msgNackWarp_dst);
|
|
687
706
|
expect(eventLog.arr_events.length).toBe(2);
|
|
688
707
|
expect(eventLog.arr_events[1].type).toBe('2PhW[JSON_MsgAckWarp]');
|
|
689
708
|
expect(eventLog.arr_events[1].data).toEqual({msg : str_msgNackWarp_dst, json_msg : json_msgNackWarp_dst });
|
|
@@ -698,21 +717,21 @@ describe('2PhW protocol', () => {
|
|
|
698
717
|
json_msgAckEngage_recv.referer= karr_referer_dst;
|
|
699
718
|
|
|
700
719
|
jasmine.clock().tick(STT_MSEC_1000); // 4000
|
|
701
|
-
twoPhW.
|
|
720
|
+
twoPhW.handler_json_msgAck(json_msgAckEngage_recv, json_msgAckEngage_recv);
|
|
702
721
|
expect(eventLog.arr_events.length).toBe(2);
|
|
703
722
|
});
|
|
704
723
|
|
|
705
724
|
describe('register Engage!', () => {
|
|
706
725
|
beforeEach(() => {
|
|
707
|
-
LOGR_.
|
|
726
|
+
LOGR_.toggle(l_, {
|
|
708
727
|
// SENDER : 1,
|
|
709
728
|
// PROTOCOL_STATE : 1,
|
|
710
729
|
// DROPS : 1
|
|
711
|
-
}
|
|
730
|
+
});
|
|
712
731
|
|
|
713
732
|
expect(Date.now()-T0).toBe(RTT_MSEC_2000);
|
|
714
733
|
|
|
715
|
-
twoPhW.
|
|
734
|
+
twoPhW.handler_json_msgAck(str_msgAckWarp_dst, json_msgAckWarp_dst);
|
|
716
735
|
expect(callback_msgAckWarp).toHaveBeenCalled();
|
|
717
736
|
expect(eventLog.arr_events.length).toBe(2);
|
|
718
737
|
expect(eventLog.arr_events[1].type).toBe('2PhW[JSON_MsgAckWarp]');
|
|
@@ -759,11 +778,11 @@ describe('2PhW protocol', () => {
|
|
|
759
778
|
let str_msgAckEngage_dst;
|
|
760
779
|
|
|
761
780
|
beforeEach(() => {
|
|
762
|
-
LOGR_.
|
|
781
|
+
LOGR_.toggle(l_, {
|
|
763
782
|
// SENDER : 1,
|
|
764
783
|
// PROTOCOL_STATE : 1,
|
|
765
784
|
// DROPS : 1
|
|
766
|
-
}
|
|
785
|
+
});
|
|
767
786
|
|
|
768
787
|
expect(Date.now()-T0).toBe(RTT_MSEC_2000);
|
|
769
788
|
|
|
@@ -790,7 +809,7 @@ describe('2PhW protocol', () => {
|
|
|
790
809
|
expect(Date.now()-T0).toBe(4999);
|
|
791
810
|
expect(callback_msg_sent_expired).not.toHaveBeenCalled();
|
|
792
811
|
|
|
793
|
-
twoPhW.
|
|
812
|
+
twoPhW.handler_json_msgAck(str_msgAckEngage_dst, json_msgAckEngage_dst);
|
|
794
813
|
expect(eventLog.arr_events.length).toBe(4);
|
|
795
814
|
expect(eventLog.arr_events[3].type).toBe('2PhW[JSON_MsgAckEngage]');
|
|
796
815
|
expect(eventLog.arr_events[3].data).toEqual({ msg: str_msgAckEngage_dst, json_msg : json_msgAckEngage_dst });
|
|
@@ -808,7 +827,7 @@ describe('2PhW protocol', () => {
|
|
|
808
827
|
expect(callback_msg_sent_expired).toHaveBeenCalled();
|
|
809
828
|
|
|
810
829
|
// test to make sure a late ack isn't a valid AckEngage state
|
|
811
|
-
twoPhW.
|
|
830
|
+
twoPhW.handler_json_msgAck(str_msgAckEngage_dst, json_msgAckEngage_dst);
|
|
812
831
|
expect(eventLog.arr_events.length).toBe(3);
|
|
813
832
|
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateEngage).toBe(true);
|
|
814
833
|
});
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './twoPhW';
|