2 * This file is part of GNUnet
3 * Copyright (C) 2013 GNUnet e.V.
5 * GNUnet is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 3, or (at your
8 * option) any later version.
10 * GNUnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNUnet; see the file COPYING. If not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 * @file social/test_social.c
22 * @brief Tests for the Social API.
23 * @author Gabor X Toth
29 #include "gnunet_crypto_lib.h"
30 #include "gnunet_common.h"
31 #include "gnunet_util_lib.h"
32 #include "gnunet_testing_lib.h"
33 #include "gnunet_psyc_util_lib.h"
34 #include "gnunet_social_service.h"
35 #include "gnunet_identity_service.h"
37 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
39 #define DATA2ARG(data) data, sizeof (data)
42 * Return value from 'main'.
46 struct GNUNET_SOCIAL_App *app;
47 const char *app_id = "test";
50 * Handle for task for timeout termination.
52 struct GNUNET_SCHEDULER_Task *end_badly_task;
54 const struct GNUNET_CONFIGURATION_Handle *cfg;
56 struct GNUNET_PeerIdentity this_peer;
58 struct GNUNET_IDENTITY_Handle *id;
60 const struct GNUNET_SOCIAL_Ego *host_ego;
61 const struct GNUNET_SOCIAL_Ego *guest_ego;
63 const char *host_name = "Host One";
64 const char *guest_name = "Guest One";
66 struct GNUNET_CRYPTO_EddsaPrivateKey *place_key;
67 struct GNUNET_CRYPTO_EcdsaPrivateKey *guest_key;
69 struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key;
70 struct GNUNET_HashCode place_pub_hash;
72 struct GNUNET_CRYPTO_EcdsaPublicKey guest_pub_key;
73 struct GNUNET_CRYPTO_EcdsaPublicKey host_pub_key;
75 struct GNUNET_PSYC_Slicer *host_slicer;
76 struct GNUNET_PSYC_Slicer *guest_slicer;
78 struct GNUNET_SOCIAL_Host *hst;
79 struct GNUNET_SOCIAL_Guest *gst;
81 struct GNUNET_SOCIAL_Place *hst_plc;
82 struct GNUNET_SOCIAL_Place *gst_plc;
84 struct GNUNET_SOCIAL_Nym *nym_eject;
86 struct GuestEnterMessage
88 struct GNUNET_PSYC_Message *msg;
89 const char *method_name;
90 struct GNUNET_PSYC_Environment *env;
95 struct TransmitClosure
97 struct GNUNET_SOCIAL_Announcement *host_ann;
98 struct GNUNET_SOCIAL_TalkRequest *guest_talk;
99 struct GNUNET_PSYC_Environment *env;
101 uint8_t data_delay[16];
107 struct ResultClosure {
111 uint8_t join_req_count;
112 struct GNUNET_PSYC_Message *join_resp;
116 uint8_t is_guest_nym_added = GNUNET_NO;
117 uint8_t is_host_reconnected = GNUNET_NO;
118 uint8_t is_guest_reconnected = GNUNET_NO;
123 TEST_HOST_CREATE = 1,
125 TEST_GUEST_CREATE = 3,
126 TEST_GUEST_ENTER = 4,
127 TEST_HOST_ANSWER_DOOR_REFUSE = 5,
128 TEST_GUEST_RECV_ENTRY_DCSN_REFUSE = 6,
129 TEST_HOST_ANSWER_DOOR_ADMIT = 7,
130 TEST_GUEST_RECV_ENTRY_DCSN_ADMIT = 8,
131 TEST_HOST_ANNOUNCE = 9,
132 TEST_HOST_ANNOUNCE_END = 10,
133 TEST_GUEST_TALK = 11,
134 TEST_HOST_ANNOUNCE2 = 12,
135 TEST_HOST_ANNOUNCE2_END = 13,
136 TEST_GUEST_HISTORY_REPLAY = 14,
137 TEST_GUEST_HISTORY_REPLAY_LATEST = 15,
138 TEST_GUEST_LOOK_AT = 16,
139 TEST_GUEST_LOOK_FOR = 17,
140 TEST_GUEST_LEAVE = 18,
141 TEST_ZONE_ADD_PLACE = 19,
142 TEST_GUEST_ENTER_BY_NAME = 20,
144 TEST_GUEST_LEAVE2 = 22,
145 TEST_HOST_LEAVE = 23,
150 schedule_guest_leave (void *cls);
154 host_answer_door (void *cls,
155 struct GNUNET_SOCIAL_Nym *nym,
156 const char *method_name,
157 struct GNUNET_PSYC_Environment *env,
171 guest_enter_by_name ();
181 * Clean up all resources used.
188 GNUNET_IDENTITY_disconnect (id);
192 if (NULL != guest_slicer)
194 GNUNET_PSYC_slicer_destroy (guest_slicer);
198 if (NULL != host_slicer)
200 GNUNET_PSYC_slicer_destroy (host_slicer);
206 GNUNET_SOCIAL_guest_leave (gst, NULL, NULL, NULL);
212 GNUNET_SOCIAL_host_leave (hst, NULL, NULL, NULL);
216 GNUNET_SOCIAL_app_disconnect (app, NULL, NULL);
217 GNUNET_SCHEDULER_shutdown ();
222 * Terminate the test case (failure).
227 end_badly (void *cls)
231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test FAILED.\n");
236 * Terminate the test case (success).
241 end_normally (void *cls)
245 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test PASSED.\n");
250 * Finish the test case (successfully).
255 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
256 "Test #%u: Ending tests.\n", test);
258 if (end_badly_task != NULL)
260 GNUNET_SCHEDULER_cancel (end_badly_task);
261 end_badly_task = NULL;
263 GNUNET_SCHEDULER_add_now (&end_normally, NULL);
268 transmit_resume (void *cls)
270 struct TransmitClosure *tmit = cls;
272 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
273 "Test #%u: Transmission resumed.\n", test);
274 if (NULL != tmit->host_ann)
275 GNUNET_SOCIAL_host_announce_resume (tmit->host_ann);
277 GNUNET_SOCIAL_guest_talk_resume (tmit->guest_talk);
282 notify_data (void *cls, uint16_t *data_size, void *data)
284 struct TransmitClosure *tmit = cls;
285 if (NULL != tmit->env)
287 GNUNET_PSYC_env_destroy (tmit->env);
290 if (0 == tmit->data_count)
296 uint16_t size = strlen (tmit->data[tmit->n]);
297 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
298 "Test #%u: Transmit notify data: %u bytes available, "
299 "processing fragment %u/%u (size %u).\n",
300 test, *data_size, tmit->n + 1, tmit->data_count, size);
301 if (*data_size < size)
305 return GNUNET_SYSERR;
308 if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n])
310 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
311 "Test #%u: Transmission paused.\n", test);
312 tmit->paused = GNUNET_YES;
313 GNUNET_SCHEDULER_add_delayed (
314 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
315 tmit->data_delay[tmit->n]),
316 &transmit_resume, tmit);
320 tmit->paused = GNUNET_NO;
323 GNUNET_memcpy (data, tmit->data[tmit->n], size);
325 return ++tmit->n < tmit->data_count ? GNUNET_NO : GNUNET_YES;
332 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
333 "Test #%u: The host has left the place.\n", test);
339 schedule_host_leave (void *cls)
341 test = TEST_HOST_LEAVE;
342 GNUNET_SOCIAL_host_leave (hst, NULL, &host_left, NULL);
349 host_farewell2 (void *cls,
350 const struct GNUNET_SOCIAL_Nym *nym,
351 struct GNUNET_PSYC_Environment *env)
353 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
354 "Nym left the place again.\n");
355 GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL);
360 host_reconnected (void *cls, int result,
361 const struct GNUNET_CRYPTO_EddsaPublicKey *home_pub_key,
362 uint64_t max_message_id)
364 place_pub_key = *home_pub_key;
365 GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
366 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
367 "Test #%u: Host reconnected to place %s\n",
368 test, GNUNET_h2s (&place_pub_hash));
370 is_host_reconnected = GNUNET_YES;
371 if (GNUNET_YES == is_guest_reconnected)
373 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
379 guest_reconnected (void *cls, int result,
380 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
381 uint64_t max_message_id)
383 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
384 "Test #%u: Guest reconnected to place: %d\n",
386 GNUNET_assert (0 <= result);
388 is_guest_reconnected = GNUNET_YES;
389 if (GNUNET_YES == is_host_reconnected)
391 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
397 app_connected (void *cls)
399 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
400 "Test #%u: App connected: %p\n", test, cls);
405 app_recv_host (void *cls,
406 struct GNUNET_SOCIAL_HostConnection *hconn,
407 struct GNUNET_SOCIAL_Ego *ego,
408 const struct GNUNET_CRYPTO_EddsaPublicKey *host_pub_key,
409 enum GNUNET_SOCIAL_AppPlaceState place_state)
411 struct GNUNET_HashCode host_pub_hash;
412 GNUNET_CRYPTO_hash (host_pub_key, sizeof (*host_pub_key), &host_pub_hash);
414 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
415 "Test #%u: Got app host place notification: %s\n",
416 test, GNUNET_h2s (&host_pub_hash));
418 if (test == TEST_RECONNECT)
420 if (0 == memcmp (&place_pub_key, host_pub_key, sizeof (*host_pub_key)))
422 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
423 "Test #%u: Reconnecting to host place: %s\n",
424 test, GNUNET_h2s (&host_pub_hash));
425 hst = GNUNET_SOCIAL_host_enter_reconnect (hconn, host_slicer, host_reconnected,
426 host_answer_door, host_farewell2, NULL);
433 app_recv_guest (void *cls,
434 struct GNUNET_SOCIAL_GuestConnection *gconn,
435 struct GNUNET_SOCIAL_Ego *ego,
436 const struct GNUNET_CRYPTO_EddsaPublicKey *guest_pub_key,
437 enum GNUNET_SOCIAL_AppPlaceState place_state)
439 struct GNUNET_HashCode guest_pub_hash;
440 GNUNET_CRYPTO_hash (guest_pub_key, sizeof (*guest_pub_key), &guest_pub_hash);
442 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
443 "Test #%u: Got app guest place notification: %s\n",
444 test, GNUNET_h2s (&guest_pub_hash));
446 if (test == TEST_RECONNECT)
448 if (0 == memcmp (&place_pub_key, guest_pub_key, sizeof (*guest_pub_key)))
450 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
451 "Test #%u: Reconnecting to guest place: %s\n",
452 test, GNUNET_h2s (&guest_pub_hash));
453 gst = GNUNET_SOCIAL_guest_enter_reconnect (gconn, GNUNET_PSYC_SLAVE_JOIN_NONE,
454 guest_slicer, guest_reconnected, NULL);
461 app_recv_ego (void *cls,
462 struct GNUNET_SOCIAL_Ego *ego,
463 const struct GNUNET_CRYPTO_EcdsaPublicKey *ego_pub_key,
466 char *ego_pub_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (ego_pub_key);
467 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
468 "Test #%u: Got app ego notification: %p %s %s\n",
469 test, ego, name, ego_pub_str);
470 GNUNET_free (ego_pub_str);
472 if (NULL != strstr (name, host_name) && TEST_HOST_CREATE == test)
475 host_pub_key = *(GNUNET_SOCIAL_ego_get_pub_key (host_ego));
476 GNUNET_assert (TEST_HOST_CREATE == test);
479 else if (NULL != strstr (name, guest_name))
483 if (TEST_GUEST_CREATE == test)
490 schedule_reconnect (void *cls)
492 test = TEST_RECONNECT;
494 GNUNET_SOCIAL_host_disconnect (hst, NULL, NULL);
495 GNUNET_SOCIAL_guest_disconnect (gst, NULL, NULL);
499 GNUNET_SOCIAL_app_disconnect (app, NULL, NULL);
500 app = GNUNET_SOCIAL_app_connect (cfg, app_id,
510 host_recv_zone_add_place_result (void *cls, int64_t result,
511 const void *data, uint16_t data_size)
513 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
514 "Test #%u: Zone add place result: %" PRId64 " (%.*s).\n",
515 test, result, data_size, (const char *) data);
516 GNUNET_assert (GNUNET_YES == result);
518 GNUNET_assert (GNUNET_YES == is_guest_nym_added);
519 guest_enter_by_name ();
526 test = TEST_ZONE_ADD_PLACE;
527 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
528 "Test #%u: Adding place to zone.\n", test);
530 GNUNET_SOCIAL_zone_add_place (app, host_ego, "home", "let.me*in!",
531 &place_pub_key, &this_peer, 1, &this_peer,
532 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
533 host_recv_zone_add_place_result, app);
538 host_farewell (void *cls,
539 const struct GNUNET_SOCIAL_Nym *nym,
540 struct GNUNET_PSYC_Environment *env)
542 const struct GNUNET_CRYPTO_EcdsaPublicKey *
543 nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym);
545 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
546 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
547 "Test #%u: Farewell: nym %s (%s) has left the place.\n",
548 test, GNUNET_h2s (GNUNET_SOCIAL_nym_get_pub_key_hash (nym)), str);
550 GNUNET_assert (1 == GNUNET_PSYC_env_get_count (env));
551 if (0 != memcmp (&guest_pub_key, nym_key, sizeof (*nym_key)))
553 str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&guest_pub_key);
554 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
555 "Test #%u: Farewell: nym does not match guest: %s\n",
565 guest_left (void *cls)
567 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
568 "Test #%u: The guest has left the place.\n", test);
575 if (test < TEST_RECONNECT)
576 test = TEST_GUEST_LEAVE;
578 test = TEST_GUEST_LEAVE2;
580 struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
581 GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
582 "_notice_place_leave", DATA2ARG ("Leaving."));
583 GNUNET_SOCIAL_guest_leave (gst, env, &guest_left, NULL);
584 GNUNET_PSYC_env_destroy (env);
591 schedule_guest_leave (void *cls)
598 guest_look_for_result (void *cls,
603 struct ResultClosure *rcls = cls;
604 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
605 "Test #%u: guest_look_for_result: %" PRId64 "\n",
607 GNUNET_assert (GNUNET_OK == result_code);
608 GNUNET_assert (3 == rcls->n);
610 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
615 guest_look_for_var (void *cls,
616 const struct GNUNET_MessageHeader *mod,
620 uint32_t full_value_size)
622 struct ResultClosure *rcls = cls;
624 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
625 "Test #%u: guest_look_for_var: %s\n%.*s\n",
626 test, name, value_size, (const char *) value);
633 test = TEST_GUEST_LOOK_FOR;
634 struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls));
635 GNUNET_SOCIAL_place_look_for (gst_plc, "_foo", guest_look_for_var, guest_look_for_result, rcls);
640 guest_look_at_result (void *cls, int64_t result_code,
641 const void *data, uint16_t data_size)
643 struct ResultClosure *rcls = cls;
645 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
646 "Test #%u: guest_look_at_result: %" PRId64 "\n",
648 GNUNET_assert (GNUNET_OK == result_code);
649 GNUNET_assert (1 == rcls->n);
656 guest_look_at_var (void *cls,
657 const struct GNUNET_MessageHeader *mod,
661 uint32_t full_value_size)
663 struct ResultClosure *rcls = cls;
666 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
667 "Test #%u: guest_look_at_var: %s\n%.*s\n",
668 test ,name, value_size, (const char *) value);
675 test = TEST_GUEST_LOOK_AT;
676 struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls));
677 GNUNET_SOCIAL_place_look_at (gst_plc, "_foo_bar", guest_look_at_var, guest_look_at_result, rcls);
682 guest_recv_history_replay_latest_result (void *cls, int64_t result,
683 const void *data, uint16_t data_size)
685 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
686 "Test #%u: Guest received latest history replay result "
687 "(%" PRIu32 " messages, %" PRId64 " fragments):\n"
689 test, counter, result, data_size, (const char *) data);
690 //GNUNET_assert (2 == counter); /* message count */
691 //GNUNET_assert (7 == result); /* fragment count */
698 guest_history_replay_latest ()
700 test = TEST_GUEST_HISTORY_REPLAY_LATEST;
702 GNUNET_SOCIAL_place_history_replay_latest (gst_plc, 3, "",
703 GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
705 &guest_recv_history_replay_latest_result,
711 guest_recv_history_replay_result (void *cls, int64_t result,
712 const void *data, uint16_t data_size)
714 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
715 "Test #%u: Guest received history replay result: %" PRId64 "\n"
717 test, result, data_size, (const char *) data);
718 // GNUNET_assert (2 == counter); /* message count */
719 // GNUNET_assert (7 == result); /* fragment count */
721 guest_history_replay_latest ();
726 guest_history_replay ()
728 test = TEST_GUEST_HISTORY_REPLAY;
730 GNUNET_SOCIAL_place_history_replay (gst_plc, 1, 3, "",
731 GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
733 &guest_recv_history_replay_result,
739 guest_recv_method (void *cls,
740 const struct GNUNET_PSYC_MessageHeader *msg,
741 const struct GNUNET_PSYC_MessageMethod *meth,
743 const char *method_name)
745 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
746 "Test #%u: Guest received method for message ID %" PRIu64 ":\n"
748 test, message_id, method_name, ntohl (meth->flags));
749 /** @todo FIXME: check message */
754 guest_recv_modifier (void *cls,
755 const struct GNUNET_PSYC_MessageHeader *msg,
756 const struct GNUNET_MessageHeader *pmsg,
758 enum GNUNET_PSYC_Operator oper,
762 uint16_t full_value_size)
764 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
765 "Test #%u: Guest received modifier for message ID %" PRIu64 ":\n"
766 "%c%s: %.*s (size: %u)\n",
767 test, message_id, oper, name, value_size, (const char *) value, value_size);
768 /** @todo FIXME: check modifier */
772 guest_recv_mod_foo_bar (void *cls,
773 const struct GNUNET_PSYC_MessageHeader *msg,
774 const struct GNUNET_MessageHeader *pmsg,
776 enum GNUNET_PSYC_Operator oper,
780 uint16_t full_value_size)
782 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
783 "Test #%u: Guest received modifier matching _foo_bar for message ID %" PRIu64 ":\n"
784 "%c%s: %.*s (size: %u)\n",
785 test, message_id, oper, name, value_size, (const char *) value, value_size);
786 struct ResultClosure *rc = cls;
788 /** @todo FIXME: check modifier */
793 guest_recv_data (void *cls,
794 const struct GNUNET_PSYC_MessageHeader *msg,
795 const struct GNUNET_MessageHeader *pmsg,
800 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
801 "Test #%u: Guest received data for message ID %" PRIu64 ":\n"
803 test, message_id, data_size, (const char *) data);
804 /** @todo FIXME: check data */
809 guest_recv_eom (void *cls,
810 const struct GNUNET_PSYC_MessageHeader *msg,
811 const struct GNUNET_MessageHeader *pmsg,
813 uint8_t is_cancelled)
815 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
816 "Test #%u: Guest received end of message ID %" PRIu64
818 test, message_id, is_cancelled);
822 case TEST_HOST_ANNOUNCE:
823 test = TEST_HOST_ANNOUNCE_END;
826 case TEST_HOST_ANNOUNCE_END:
830 case TEST_HOST_ANNOUNCE2:
831 test = TEST_HOST_ANNOUNCE2_END;
834 case TEST_HOST_ANNOUNCE2_END:
835 guest_history_replay ();
838 case TEST_GUEST_HISTORY_REPLAY:
839 case TEST_GUEST_HISTORY_REPLAY_LATEST:
844 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
851 host_recv_method (void *cls,
852 const struct GNUNET_PSYC_MessageHeader *msg,
853 const struct GNUNET_PSYC_MessageMethod *meth,
855 const char *method_name)
857 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
858 "Test #%u: Host received method for message ID %" PRIu64 ":\n"
860 test, message_id, method_name);
861 /** @todo FIXME: check message */
866 host_recv_modifier (void *cls,
867 const struct GNUNET_PSYC_MessageHeader *msg,
868 const struct GNUNET_MessageHeader *pmsg,
870 enum GNUNET_PSYC_Operator oper,
874 uint16_t full_value_size)
876 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
877 "Test #%u: Host received modifier for message ID %" PRIu64 ":\n"
879 test, message_id, oper, name, value_size, (const char *) value);
884 host_recv_data (void *cls,
885 const struct GNUNET_PSYC_MessageHeader *msg,
886 const struct GNUNET_MessageHeader *pmsg,
891 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
892 "Test #%u: Host received data for message ID %" PRIu64 ":\n"
894 test, message_id, data_size, (const char *) data);
899 host_recv_eom (void *cls,
900 const struct GNUNET_PSYC_MessageHeader *msg,
901 const struct GNUNET_MessageHeader *pmsg,
903 uint8_t is_cancelled)
905 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
906 "Test #%u: Host received end of message ID %" PRIu64
908 test, message_id, is_cancelled);
912 case TEST_HOST_ANNOUNCE:
913 test = TEST_HOST_ANNOUNCE_END;
916 case TEST_HOST_ANNOUNCE_END:
920 case TEST_HOST_ANNOUNCE2:
921 test = TEST_HOST_ANNOUNCE2_END;
924 case TEST_HOST_ANNOUNCE2_END:
925 guest_history_replay ();
928 case TEST_GUEST_TALK:
933 if (TEST_GUEST_LEAVE <= test)
935 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid test: #%u\n", test);
944 test = TEST_GUEST_TALK;
946 tmit = (struct TransmitClosure) {};
947 tmit.env = GNUNET_PSYC_env_create ();
948 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
949 "_bar_foo", DATA2ARG ("one two three"));
950 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
951 "_bar_baz", DATA2ARG ("four five"));
952 tmit.data[0] = "zzz xxx yyy ";
953 tmit.data[1] = "zyx wvu tsr qpo.\n";
954 tmit.data_delay[1] = 1;
955 tmit.data[2] = "testing ten nine eight.\n";
959 = GNUNET_SOCIAL_guest_talk (gst, "_converse_guest", tmit.env,
961 GNUNET_SOCIAL_TALK_NONE);
968 test = TEST_HOST_ANNOUNCE;
970 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
971 "Test #%u: Host announcement.\n", test);
973 tmit = (struct TransmitClosure) {};
974 tmit.env = GNUNET_PSYC_env_create ();
975 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
976 "_foo", DATA2ARG ("bar baz"));
977 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
978 "_foo_bar", DATA2ARG ("foo bar"));
979 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
980 "_foo_bar_baz", DATA2ARG ("foo bar baz"));
981 tmit.data[0] = "aaa bbb ccc ";
982 tmit.data[1] = "abc def ghi jkl.\n";
983 tmit.data_delay[1] = 1;
984 tmit.data[2] = "testing one two three ";
985 tmit.data[3] = "four five.\n";
989 = GNUNET_SOCIAL_host_announce (hst, "_converse_host", tmit.env,
991 GNUNET_SOCIAL_ANNOUNCE_NONE);
998 GNUNET_assert (2 == mod_foo_bar_rcls.n);
999 GNUNET_PSYC_slicer_modifier_remove (guest_slicer, "_foo_bar",
1000 guest_recv_mod_foo_bar);
1002 test = TEST_HOST_ANNOUNCE2;
1004 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1005 "Test #%u: Host announcement 2.\n", test);
1007 tmit = (struct TransmitClosure) {};
1008 tmit.env = GNUNET_PSYC_env_create ();
1009 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
1010 "_foo2", DATA2ARG ("BAR BAZ"));
1011 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
1012 "_foo2_bar", DATA2ARG ("FOO BAR"));
1013 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
1014 "_foo2_bar", DATA2ARG ("FOO BAR BAZ"));
1015 tmit.data[0] = "AAA BBB CCC ";
1016 tmit.data[1] = "ABC DEF GHI JKL.\n";
1017 tmit.data[2] = "TESTING ONE TWO THREE.\n";
1018 tmit.data_count = 3;
1021 = GNUNET_SOCIAL_host_announce (hst, "_converse_host_two", tmit.env,
1022 ¬ify_data, &tmit,
1023 GNUNET_SOCIAL_ANNOUNCE_NONE);
1028 guest_recv_entry_decision (void *cls,
1030 const struct GNUNET_PSYC_Message *entry_msg)
1032 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1033 "Test #%u: Guest received entry decision (try %u): %d.\n",
1034 test, join_req_count, is_admitted);
1036 if (NULL != entry_msg)
1038 struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
1039 const char *method_name = NULL;
1040 const void *data = NULL;
1041 uint16_t data_size = 0;
1042 struct GNUNET_PSYC_MessageHeader *
1043 pmsg = GNUNET_PSYC_message_header_create_from_psyc (entry_msg);
1044 GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size);
1047 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1049 method_name, data_size, (const char *) data);
1050 /** @todo FIXME: check response message */
1055 case TEST_GUEST_RECV_ENTRY_DCSN_REFUSE:
1056 GNUNET_assert (GNUNET_NO == is_admitted);
1060 case TEST_GUEST_RECV_ENTRY_DCSN_ADMIT:
1061 GNUNET_assert (GNUNET_YES == is_admitted);
1065 case TEST_GUEST_ENTER_BY_NAME:
1066 GNUNET_SCHEDULER_add_now (&schedule_reconnect, NULL);
1070 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
1077 host_answer_door (void *cls,
1078 struct GNUNET_SOCIAL_Nym *nym,
1079 const char *method_name,
1080 struct GNUNET_PSYC_Environment *env,
1086 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1087 "Test #%u: Host received entry request from guest (try %u).\n",
1088 (uint8_t) test, join_req_count);
1089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1091 method_name, (int) data_size, (const char *) data);
1095 case TEST_HOST_ANSWER_DOOR_REFUSE:
1096 test = TEST_GUEST_RECV_ENTRY_DCSN_REFUSE;
1097 join_resp = GNUNET_PSYC_message_create ("_notice_place_refuse", env,
1098 DATA2ARG ("Go away!"));
1099 GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_NO, join_resp);
1102 case TEST_HOST_ANSWER_DOOR_ADMIT:
1103 test = TEST_GUEST_RECV_ENTRY_DCSN_ADMIT;
1106 case TEST_GUEST_ENTER_BY_NAME:
1107 join_resp = GNUNET_PSYC_message_create ("_notice_place_admit", env,
1108 DATA2ARG ("Welcome, nym!"));
1109 GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp);
1113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid test: #%u\n", test);
1120 guest_recv_local_enter (void *cls, int result,
1121 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
1122 uint64_t max_message_id)
1124 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1125 "Test #%u: Guest entered to local place: %d\n",
1127 GNUNET_assert (0 <= result);
1134 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1135 "Test #%u: Entering to place as guest.\n", test);
1137 struct GuestEnterMessage *emsg = &guest_enter_msg;
1139 emsg->method_name = "_request_enter";
1140 emsg->env = GNUNET_PSYC_env_create ();
1141 GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
1142 "_abc", "abc def", 7);
1143 GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
1144 "_abc_def", "abc def ghi", 11);
1145 emsg->data = "let me in";
1146 emsg->data_size = strlen (emsg->data) + 1;
1147 emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
1148 emsg->data, emsg->data_size);
1150 gst = GNUNET_SOCIAL_guest_enter (app, guest_ego, &place_pub_key,
1151 GNUNET_PSYC_SLAVE_JOIN_NONE,
1152 &this_peer, 0, NULL, emsg->msg, guest_slicer,
1153 guest_recv_local_enter,
1154 guest_recv_entry_decision, NULL);
1155 gst_plc = GNUNET_SOCIAL_guest_get_place (gst);
1157 GNUNET_SOCIAL_place_msg_proc_set (gst_plc, "_converse",
1158 GNUNET_SOCIAL_MSG_PROC_SAVE);
1163 guest_enter_by_name ()
1165 test = TEST_GUEST_ENTER_BY_NAME;
1166 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1167 "Test #%u: Entering to place by name as guest.\n", test);
1169 struct GuestEnterMessage *emsg = &guest_enter_msg;
1171 emsg->method_name = "_request_enter";
1172 emsg->env = GNUNET_PSYC_env_create ();
1173 GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
1174 "_abc", "abc def", 7);
1175 GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
1176 "_abc_def", "abc def ghi", 11);
1177 emsg->data = "let me in";
1178 emsg->data_size = strlen (emsg->data) + 1;
1179 emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
1180 emsg->data, emsg->data_size);
1182 gst = GNUNET_SOCIAL_guest_enter_by_name (app, guest_ego,
1183 "home.host.gnu", "let.me*in!",
1184 emsg->msg, guest_slicer,
1185 guest_recv_local_enter,
1186 guest_recv_entry_decision, NULL);
1187 gst_plc = GNUNET_SOCIAL_guest_get_place (gst);
1192 app_recv_zone_add_nym_result (void *cls, int64_t result,
1193 const void *data, uint16_t data_size)
1195 GNUNET_assert (GNUNET_YES == result);
1196 is_guest_nym_added = GNUNET_YES;
1203 guest_pub_key = *(GNUNET_SOCIAL_ego_get_pub_key (guest_ego));
1205 guest_slicer = GNUNET_PSYC_slicer_create ();
1206 GNUNET_PSYC_slicer_method_add (guest_slicer, "", NULL,
1207 guest_recv_method, guest_recv_modifier,
1208 guest_recv_data, guest_recv_eom, NULL);
1209 GNUNET_PSYC_slicer_modifier_add (guest_slicer, "_foo_bar",
1210 guest_recv_mod_foo_bar, &mod_foo_bar_rcls);
1211 test = TEST_HOST_ANSWER_DOOR_ADMIT;
1213 GNUNET_SOCIAL_zone_add_nym (app, guest_ego, "host", &host_pub_key,
1214 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
1215 app_recv_zone_add_nym_result, NULL);
1221 id_guest_created (void *cls, const char *emsg)
1225 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1226 "Test #%u: Could not create guest identity: %s\n",
1228 #if ! DEBUG_TEST_SOCIAL
1232 if (NULL != guest_ego)
1238 host_entered (void *cls, int result,
1239 const struct GNUNET_CRYPTO_EddsaPublicKey *home_pub_key,
1240 uint64_t max_message_id)
1242 place_pub_key = *home_pub_key;
1243 GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
1244 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1245 "Test #%u: Host entered to place %s\n",
1246 test, GNUNET_h2s (&place_pub_hash));
1248 test = TEST_GUEST_CREATE;
1249 GNUNET_IDENTITY_create (id, guest_name, &id_guest_created, NULL);
1256 host_slicer = GNUNET_PSYC_slicer_create ();
1257 GNUNET_PSYC_slicer_method_add (host_slicer, "", NULL,
1258 host_recv_method, host_recv_modifier,
1259 host_recv_data, host_recv_eom, NULL);
1261 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1262 "Test #%u: Entering to place as host.\n", test);
1263 test = TEST_HOST_ENTER;
1264 hst = GNUNET_SOCIAL_host_enter (app, host_ego,
1265 GNUNET_PSYC_CHANNEL_PRIVATE,
1266 host_slicer, host_entered,
1267 host_answer_door, host_farewell, NULL);
1268 hst_plc = GNUNET_SOCIAL_host_get_place (hst);
1270 GNUNET_SOCIAL_place_msg_proc_set (hst_plc, "_converse",
1271 GNUNET_SOCIAL_MSG_PROC_RELAY);
1276 id_host_created (void *cls, const char *emsg)
1280 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1281 "Test #%u: Could not create host identity: %s\n",
1283 #if ! DEBUG_TEST_SOCIAL
1288 app = GNUNET_SOCIAL_app_connect (cfg, app_id,
1298 identity_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego,
1299 void **ctx, const char *name)
1305 * Main function of the test, run from scheduler.
1308 * @param cfg configuration we use (also to connect to Social service)
1309 * @param peer handle to access more of the peer (not used)
1312 #if DEBUG_TEST_SOCIAL
1313 run (void *cls, char *const *args, const char *cfgfile,
1314 const struct GNUNET_CONFIGURATION_Handle *c)
1317 const struct GNUNET_CONFIGURATION_Handle *c,
1318 struct GNUNET_TESTING_Peer *peer)
1322 end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1325 GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer);
1327 id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL);
1329 test = TEST_HOST_CREATE;
1330 GNUNET_IDENTITY_create (id, host_name, &id_host_created, NULL);
1335 main (int argc, char *argv[])
1338 #if DEBUG_TEST_SOCIAL
1339 const struct GNUNET_GETOPT_CommandLineOption opts[] = {
1340 GNUNET_GETOPT_OPTION_END
1342 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-social",
1343 "test-social [options]",
1347 if (0 != GNUNET_TESTING_peer_run ("test-social", "test_social.conf", &run, NULL))
1353 /* end of test_social.c */