diff options
author | Gabor X Toth <*@tg-x.net> | 2015-08-28 13:33:43 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2015-08-28 13:33:43 +0000 |
commit | 38963d1e81332032e0ac774f4f2c6b804c38802a (patch) | |
tree | ce33b979e47fe332c7c744744d60077a7e1fefee /src/social/test_social.c | |
parent | b4fa14499c64140273850569247abda687803053 (diff) | |
download | gnunet-38963d1e81332032e0ac774f4f2c6b804c38802a.tar.gz gnunet-38963d1e81332032e0ac774f4f2c6b804c38802a.zip |
psyc/social: get state from psycstore
Diffstat (limited to 'src/social/test_social.c')
-rw-r--r-- | src/social/test_social.c | 125 |
1 files changed, 108 insertions, 17 deletions
diff --git a/src/social/test_social.c b/src/social/test_social.c index 19a81f43d..dbcf822f8 100644 --- a/src/social/test_social.c +++ b/src/social/test_social.c | |||
@@ -36,7 +36,7 @@ | |||
36 | #include "gnunet_core_service.h" | 36 | #include "gnunet_core_service.h" |
37 | #include "gnunet_identity_service.h" | 37 | #include "gnunet_identity_service.h" |
38 | 38 | ||
39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) |
40 | 40 | ||
41 | #define DATA2ARG(data) data, sizeof (data) | 41 | #define DATA2ARG(data) data, sizeof (data) |
42 | 42 | ||
@@ -99,6 +99,10 @@ struct TransmitClosure | |||
99 | uint8_t n; | 99 | uint8_t n; |
100 | } tmit; | 100 | } tmit; |
101 | 101 | ||
102 | struct ResultClosure { | ||
103 | uint32_t n; | ||
104 | }; | ||
105 | |||
102 | uint8_t join_req_count; | 106 | uint8_t join_req_count; |
103 | struct GNUNET_PSYC_Message *join_resp; | 107 | struct GNUNET_PSYC_Message *join_resp; |
104 | 108 | ||
@@ -107,19 +111,21 @@ uint32_t counter; | |||
107 | enum | 111 | enum |
108 | { | 112 | { |
109 | TEST_NONE = 0, | 113 | TEST_NONE = 0, |
110 | TEST_HOST_ANSWER_DOOR_REFUSE = 1, | 114 | TEST_HOST_ANSWER_DOOR_REFUSE = 1, |
111 | TEST_GUEST_RECV_ENTRY_DCSN_REFUSE = 2, | 115 | TEST_GUEST_RECV_ENTRY_DCSN_REFUSE = 2, |
112 | TEST_HOST_ANSWER_DOOR_ADMIT = 3, | 116 | TEST_HOST_ANSWER_DOOR_ADMIT = 3, |
113 | TEST_GUEST_RECV_ENTRY_DCSN_ADMIT = 4, | 117 | TEST_GUEST_RECV_ENTRY_DCSN_ADMIT = 4, |
114 | TEST_HOST_ANNOUNCE = 5, | 118 | TEST_HOST_ANNOUNCE = 5, |
115 | TEST_HOST_ANNOUNCE_END = 6, | 119 | TEST_HOST_ANNOUNCE_END = 6, |
116 | TEST_HOST_ANNOUNCE2 = 7, | 120 | TEST_HOST_ANNOUNCE2 = 7, |
117 | TEST_HOST_ANNOUNCE2_END = 8, | 121 | TEST_HOST_ANNOUNCE2_END = 8, |
118 | TEST_GUEST_TALK = 9, | 122 | TEST_GUEST_TALK = 9, |
119 | TEST_GUEST_HISTORY_REPLAY = 10, | 123 | TEST_GUEST_HISTORY_REPLAY = 10, |
120 | TEST_GUEST_HISTORY_REPLAY_LATEST = 11, | 124 | TEST_GUEST_HISTORY_REPLAY_LATEST = 11, |
121 | TEST_GUEST_LEAVE = 12, | 125 | TEST_GUEST_LOOK_AT = 12, |
122 | TEST_HOST_LEAVE = 13, | 126 | TEST_GUEST_LOOK_FOR = 13, |
127 | TEST_GUEST_LEAVE = 14, | ||
128 | TEST_HOST_LEAVE = 15, | ||
123 | } test; | 129 | } test; |
124 | 130 | ||
125 | 131 | ||
@@ -351,6 +357,86 @@ schedule_guest_leave (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
351 | 357 | ||
352 | 358 | ||
353 | static void | 359 | static void |
360 | guest_look_for_result (void *cls, int64_t result_code, | ||
361 | const void *data, uint16_t data_size) | ||
362 | { | ||
363 | struct ResultClosure *rcls = cls; | ||
364 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
365 | "guest_look_for_result: %d\n", result_code); | ||
366 | GNUNET_assert (GNUNET_OK == result_code); | ||
367 | GNUNET_assert (3 == rcls->n); | ||
368 | GNUNET_free (rcls); | ||
369 | GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL); | ||
370 | } | ||
371 | |||
372 | |||
373 | static void | ||
374 | guest_look_for_var (void *cls, | ||
375 | const struct GNUNET_MessageHeader *mod, | ||
376 | const char *name, | ||
377 | const void *value, | ||
378 | uint32_t value_size, | ||
379 | uint32_t full_value_size) | ||
380 | { | ||
381 | struct ResultClosure *rcls = cls; | ||
382 | rcls->n++; | ||
383 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
384 | "guest_look_for_var: %s\n%.*s\n", | ||
385 | name, value_size, value); | ||
386 | } | ||
387 | |||
388 | |||
389 | static void | ||
390 | guest_look_for () | ||
391 | { | ||
392 | test = TEST_GUEST_LOOK_FOR; | ||
393 | struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls)); | ||
394 | GNUNET_SOCIAL_place_look_for (gst_plc, "_foo", guest_look_for_var, guest_look_for_result, rcls); | ||
395 | } | ||
396 | |||
397 | |||
398 | static void | ||
399 | guest_look_at_result (void *cls, int64_t result_code, | ||
400 | const void *data, uint16_t data_size) | ||
401 | { | ||
402 | struct ResultClosure *rcls = cls; | ||
403 | |||
404 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
405 | "guest_look_at_result: %d\n", result_code); | ||
406 | GNUNET_assert (GNUNET_OK == result_code); | ||
407 | GNUNET_assert (1 == rcls->n); | ||
408 | GNUNET_free (rcls); | ||
409 | guest_look_for (); | ||
410 | } | ||
411 | |||
412 | |||
413 | static void | ||
414 | guest_look_at_var (void *cls, | ||
415 | const struct GNUNET_MessageHeader *mod, | ||
416 | const char *name, | ||
417 | const void *value, | ||
418 | uint32_t value_size, | ||
419 | uint32_t full_value_size) | ||
420 | { | ||
421 | struct ResultClosure *rcls = cls; | ||
422 | rcls->n++; | ||
423 | |||
424 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
425 | "guest_look_at_var: %s\n%.*s\n", | ||
426 | name, value_size, value); | ||
427 | } | ||
428 | |||
429 | |||
430 | static void | ||
431 | guest_look_at () | ||
432 | { | ||
433 | test = TEST_GUEST_LOOK_AT; | ||
434 | struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls)); | ||
435 | GNUNET_SOCIAL_place_look_at (gst_plc, "_foo_bar", guest_look_at_var, guest_look_at_result, rcls); | ||
436 | } | ||
437 | |||
438 | |||
439 | static void | ||
354 | guest_recv_history_replay_latest_result (void *cls, int64_t result, | 440 | guest_recv_history_replay_latest_result (void *cls, int64_t result, |
355 | const void *data, uint16_t data_size) | 441 | const void *data, uint16_t data_size) |
356 | { | 442 | { |
@@ -361,7 +447,7 @@ guest_recv_history_replay_latest_result (void *cls, int64_t result, | |||
361 | GNUNET_assert (2 == counter); /* message count */ | 447 | GNUNET_assert (2 == counter); /* message count */ |
362 | GNUNET_assert (7 == result); /* fragment count */ | 448 | GNUNET_assert (7 == result); /* fragment count */ |
363 | 449 | ||
364 | GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL); | 450 | guest_look_at (); |
365 | } | 451 | } |
366 | 452 | ||
367 | 453 | ||
@@ -488,6 +574,7 @@ guest_recv_eom (void *cls, | |||
488 | break; | 574 | break; |
489 | 575 | ||
490 | default: | 576 | default: |
577 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test); | ||
491 | GNUNET_assert (0); | 578 | GNUNET_assert (0); |
492 | } | 579 | } |
493 | } | 580 | } |
@@ -570,10 +657,11 @@ host_recv_eom (void *cls, | |||
570 | break; | 657 | break; |
571 | 658 | ||
572 | case TEST_GUEST_TALK: | 659 | case TEST_GUEST_TALK: |
573 | guest_history_replay (); | 660 | guest_history_replay (); |
574 | break; | 661 | break; |
575 | 662 | ||
576 | default: | 663 | default: |
664 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test); | ||
577 | GNUNET_assert (0); | 665 | GNUNET_assert (0); |
578 | } | 666 | } |
579 | } | 667 | } |
@@ -624,7 +712,8 @@ host_announce () | |||
624 | tmit.host_ann | 712 | tmit.host_ann |
625 | = GNUNET_SOCIAL_host_announce (hst, "_message_host", tmit.env, | 713 | = GNUNET_SOCIAL_host_announce (hst, "_message_host", tmit.env, |
626 | ¬ify_data, &tmit, | 714 | ¬ify_data, &tmit, |
627 | GNUNET_SOCIAL_ANNOUNCE_NONE); | 715 | GNUNET_SOCIAL_ANNOUNCE_NONE |
716 | | GNUNET_PSYC_MASTER_TRANSMIT_STATE_MODIFY); | ||
628 | } | 717 | } |
629 | 718 | ||
630 | 719 | ||
@@ -689,6 +778,7 @@ guest_recv_entry_decision (void *cls, | |||
689 | break; | 778 | break; |
690 | 779 | ||
691 | default: | 780 | default: |
781 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test); | ||
692 | GNUNET_assert (0); | 782 | GNUNET_assert (0); |
693 | } | 783 | } |
694 | } | 784 | } |
@@ -728,6 +818,7 @@ host_answer_door (void *cls, | |||
728 | break; | 818 | break; |
729 | 819 | ||
730 | default: | 820 | default: |
821 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test); | ||
731 | GNUNET_assert (0); | 822 | GNUNET_assert (0); |
732 | } | 823 | } |
733 | } | 824 | } |