2 * This file is part of GNUnet
3 * Copyright (C) 2013 Christian Grothoff (and other contributing authors)
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_env_lib.h"
34 #include "gnunet_psyc_util_lib.h"
35 #include "gnunet_social_service.h"
36 #include "gnunet_core_service.h"
37 #include "gnunet_identity_service.h"
39 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
41 #define DATA2ARG(data) data, sizeof (data)
44 * Return value from 'main'.
49 * Handle for task for timeout termination.
51 struct GNUNET_SCHEDULER_Task * end_badly_task;
53 const struct GNUNET_CONFIGURATION_Handle *cfg;
55 struct GNUNET_CORE_Handle *core;
56 struct GNUNET_PeerIdentity this_peer;
58 struct GNUNET_IDENTITY_Handle *id;
60 const struct GNUNET_IDENTITY_Ego *host_ego;
61 const struct GNUNET_IDENTITY_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_CRYPTO_EcdsaPublicKey guest_pub_key;
71 struct GNUNET_CRYPTO_EcdsaPublicKey host_pub_key;
73 struct GNUNET_SOCIAL_Slicer *host_slicer;
74 struct GNUNET_SOCIAL_Slicer *guest_slicer;
76 struct GNUNET_SOCIAL_Host *hst;
77 struct GNUNET_SOCIAL_Guest *gst;
79 struct GNUNET_SOCIAL_Place *hst_plc;
80 struct GNUNET_SOCIAL_Place *gst_plc;
82 struct GNUNET_SOCIAL_Nym *nym_eject;
84 struct GuestEnterMessage
86 struct GNUNET_PSYC_Message *msg;
87 const char *method_name;
88 struct GNUNET_ENV_Environment *env;
93 struct TransmitClosure
95 struct GNUNET_SOCIAL_Announcement *host_ann;
96 struct GNUNET_SOCIAL_TalkRequest *guest_talk;
97 struct GNUNET_ENV_Environment *env;
99 uint8_t data_delay[16];
105 struct ResultClosure {
109 uint8_t join_req_count;
110 struct GNUNET_PSYC_Message *join_resp;
114 uint8_t guest_pkey_added = GNUNET_NO;
119 TEST_HOST_ANSWER_DOOR_REFUSE = 1,
120 TEST_GUEST_RECV_ENTRY_DCSN_REFUSE = 2,
121 TEST_HOST_ANSWER_DOOR_ADMIT = 3,
122 TEST_GUEST_RECV_ENTRY_DCSN_ADMIT = 4,
123 TEST_HOST_ANNOUNCE = 5,
124 TEST_HOST_ANNOUNCE_END = 6,
125 TEST_HOST_ANNOUNCE2 = 7,
126 TEST_HOST_ANNOUNCE2_END = 8,
128 TEST_GUEST_HISTORY_REPLAY = 10,
129 TEST_GUEST_HISTORY_REPLAY_LATEST = 11,
130 TEST_GUEST_LOOK_AT = 12,
131 TEST_GUEST_LOOK_FOR = 13,
132 TEST_GUEST_LEAVE = 14,
133 TEST_HOST_ADVERTISE = 15,
134 TEST_GUEST_ENTER_BY_NAME = 16,
135 TEST_HOST_LEAVE = 17,
143 guest_enter_by_name ();
153 * Clean up all resources used.
160 GNUNET_CORE_disconnect (core);
166 GNUNET_IDENTITY_disconnect (id);
172 GNUNET_SOCIAL_guest_leave (gst, GNUNET_NO, NULL, NULL, NULL);
178 GNUNET_SOCIAL_host_leave (hst, GNUNET_NO, NULL, NULL);
182 GNUNET_SCHEDULER_shutdown ();
187 * Terminate the test case (failure).
190 * @param tc scheduler context
193 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test FAILED.\n");
202 * Terminate the test case (success).
205 * @param tc scheduler context
208 end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
212 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test PASSED.\n");
217 * Finish the test case (successfully).
222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending tests.\n");
224 if (end_badly_task != NULL)
226 GNUNET_SCHEDULER_cancel (end_badly_task);
227 end_badly_task = NULL;
229 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
230 &end_normally, NULL);
235 transmit_resume (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission resumed.\n");
238 struct TransmitClosure *tmit = cls;
239 if (NULL != tmit->host_ann)
240 GNUNET_SOCIAL_host_announce_resume (tmit->host_ann);
242 GNUNET_SOCIAL_guest_talk_resume (tmit->guest_talk);
247 notify_data (void *cls, uint16_t *data_size, void *data)
249 struct TransmitClosure *tmit = cls;
250 if (NULL != tmit->env)
252 GNUNET_ENV_environment_destroy (tmit->env);
255 if (0 == tmit->data_count)
261 uint16_t size = strlen (tmit->data[tmit->n]) + 1;
262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
263 "Transmit notify data: %u bytes available, "
264 "processing fragment %u/%u (size %u).\n",
265 *data_size, tmit->n + 1, tmit->data_count, size);
266 if (*data_size < size)
270 return GNUNET_SYSERR;
273 if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n])
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission paused.\n");
276 tmit->paused = GNUNET_YES;
277 GNUNET_SCHEDULER_add_delayed (
278 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
279 tmit->data_delay[tmit->n]),
280 &transmit_resume, tmit);
284 tmit->paused = GNUNET_NO;
287 memcpy (data, tmit->data[tmit->n], size);
289 return ++tmit->n < tmit->data_count ? GNUNET_NO : GNUNET_YES;
296 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
297 "The host has left the place.\n");
298 GNUNET_SOCIAL_slicer_destroy (host_slicer);
308 schedule_host_leave (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
310 test = TEST_HOST_LEAVE;
311 GNUNET_SOCIAL_host_leave (hst, GNUNET_NO, &host_left, NULL);
316 id_guest_ego_cb2 (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
318 GNUNET_assert (NULL != ego);
321 guest_enter_by_name ();
326 host_recv_advertise_result (void *cls, int32_t success, const char *emsg)
328 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
329 "Test #%u: Advertise result: %d (%s).\n",
330 test, success, emsg);
331 GNUNET_assert (GNUNET_YES == success);
333 GNUNET_assert (GNUNET_YES == guest_pkey_added);
334 GNUNET_IDENTITY_ego_lookup (cfg, guest_name, id_guest_ego_cb2, NULL);
341 test = TEST_HOST_ADVERTISE;
342 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
343 "Test #%u: Advertising place.\n", test);
345 GNUNET_SOCIAL_host_advertise (hst, "home", 1, &this_peer,
346 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
347 "let.me*in!", host_recv_advertise_result, hst);
352 host_farewell (void *cls,
353 const struct GNUNET_SOCIAL_Nym *nym,
354 struct GNUNET_ENV_Environment *env)
356 const struct GNUNET_CRYPTO_EcdsaPublicKey *
357 nym_key = GNUNET_SOCIAL_nym_get_key (nym);
359 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
360 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
361 "Farewell: nym %s (%s) has left the place.\n",
362 GNUNET_h2s (GNUNET_SOCIAL_nym_get_key_hash (nym)), str);
364 GNUNET_assert (1 == GNUNET_ENV_environment_get_count (env));
365 if (0 != memcmp (&guest_pub_key, nym_key, sizeof (*nym_key)))
367 str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&guest_pub_key);
368 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
369 "Farewell: nym does not match guest: %s\n", str);
378 guest_left (void *cls)
380 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
381 "The guest has left the place.\n");
382 GNUNET_SOCIAL_slicer_destroy (guest_slicer);
392 test = TEST_GUEST_LEAVE;
394 struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create ();
395 GNUNET_ENV_environment_add (env, GNUNET_ENV_OP_SET,
396 "_message", DATA2ARG ("Leaving."));
397 GNUNET_SOCIAL_guest_leave (gst, GNUNET_NO, env, &guest_left, NULL);
398 GNUNET_ENV_environment_destroy (env);
400 /* @todo test keep_active */
405 schedule_guest_leave (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
412 guest_look_for_result (void *cls, int64_t result_code,
413 const void *data, uint16_t data_size)
415 struct ResultClosure *rcls = cls;
416 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
417 "guest_look_for_result: %d\n", result_code);
418 GNUNET_assert (GNUNET_OK == result_code);
419 GNUNET_assert (3 == rcls->n);
421 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
426 guest_look_for_var (void *cls,
427 const struct GNUNET_MessageHeader *mod,
431 uint32_t full_value_size)
433 struct ResultClosure *rcls = cls;
435 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
436 "guest_look_for_var: %s\n%.*s\n",
437 name, value_size, value);
444 test = TEST_GUEST_LOOK_FOR;
445 struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls));
446 GNUNET_SOCIAL_place_look_for (gst_plc, "_foo", guest_look_for_var, guest_look_for_result, rcls);
451 guest_look_at_result (void *cls, int64_t result_code,
452 const void *data, uint16_t data_size)
454 struct ResultClosure *rcls = cls;
456 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
457 "guest_look_at_result: %d\n", result_code);
458 GNUNET_assert (GNUNET_OK == result_code);
459 GNUNET_assert (1 == rcls->n);
466 guest_look_at_var (void *cls,
467 const struct GNUNET_MessageHeader *mod,
471 uint32_t full_value_size)
473 struct ResultClosure *rcls = cls;
476 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
477 "guest_look_at_var: %s\n%.*s\n",
478 name, value_size, value);
485 test = TEST_GUEST_LOOK_AT;
486 struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls));
487 GNUNET_SOCIAL_place_look_at (gst_plc, "_foo_bar", guest_look_at_var, guest_look_at_result, rcls);
492 guest_recv_history_replay_latest_result (void *cls, int64_t result,
493 const void *data, uint16_t data_size)
495 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
496 "Test #%u: Guest received latest history replay result: %" PRId64 "\n"
498 test, result, data_size, data);
499 GNUNET_assert (2 == counter); /* message count */
500 GNUNET_assert (7 == result); /* fragment count */
507 guest_history_replay_latest ()
509 test = TEST_GUEST_HISTORY_REPLAY_LATEST;
511 GNUNET_SOCIAL_place_history_replay_latest (gst_plc, 3, "",
512 GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
514 &guest_recv_history_replay_latest_result,
520 guest_recv_history_replay_result (void *cls, int64_t result,
521 const void *data, uint16_t data_size)
523 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
524 "Test #%u: Guest received history replay result: %" PRId64 "\n"
526 test, result, data_size, data);
527 GNUNET_assert (2 == counter); /* message count */
528 GNUNET_assert (7 == result); /* fragment count */
530 guest_history_replay_latest ();
535 guest_history_replay ()
537 test = TEST_GUEST_HISTORY_REPLAY;
539 GNUNET_SOCIAL_place_history_replay (gst_plc, 1, 3, "",
540 GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
542 &guest_recv_history_replay_result,
548 guest_recv_method (void *cls,
549 const struct GNUNET_PSYC_MessageMethod *meth,
552 const struct GNUNET_SOCIAL_Nym *nym,
553 const char *method_name)
555 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
556 "Test #%u: Guest received method for message ID %" PRIu64 ":\n"
558 test, message_id, method_name, flags);
559 /** @todo FIXME: check message */
564 guest_recv_modifier (void *cls,
565 const struct GNUNET_MessageHeader *msg,
567 enum GNUNET_ENV_Operator oper,
571 uint16_t full_value_size)
573 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
574 "Test #%u: Guest received modifier for message ID %" PRIu64 ":\n"
575 "%c%s: %.*s (size: %u)\n",
576 test, message_id, oper, name, value_size, value, value_size);
577 /** @todo FIXME: check modifier */
581 guest_recv_mod_foo_bar (void *cls,
582 const struct GNUNET_MessageHeader *msg,
584 enum GNUNET_ENV_Operator oper,
588 uint16_t full_value_size)
590 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
591 "Test #%u: Guest received modifier matching _foo_bar for message ID %" PRIu64 ":\n"
592 "%c%s: %.*s (size: %u)\n",
593 test, message_id, oper, name, value_size, value, value_size);
594 struct ResultClosure *rc = cls;
596 /** @todo FIXME: check modifier */
601 guest_recv_data (void *cls,
602 const struct GNUNET_MessageHeader *msg,
604 uint64_t data_offset,
608 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
609 "Test #%u: Guest received data for message ID %" PRIu64 ":\n"
611 test, message_id, data_size, data);
612 /** @todo FIXME: check data */
617 guest_recv_eom (void *cls,
618 const struct GNUNET_MessageHeader *msg,
622 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
623 "Test #%u: Guest received end of message ID %" PRIu64
625 test, message_id, cancelled);
629 case TEST_HOST_ANNOUNCE:
630 test = TEST_HOST_ANNOUNCE_END;
633 case TEST_HOST_ANNOUNCE_END:
637 case TEST_HOST_ANNOUNCE2:
638 test = TEST_HOST_ANNOUNCE2_END;
641 case TEST_HOST_ANNOUNCE2_END:
645 case TEST_GUEST_HISTORY_REPLAY:
646 case TEST_GUEST_HISTORY_REPLAY_LATEST:
651 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
658 host_recv_method (void *cls,
659 const struct GNUNET_PSYC_MessageMethod *meth,
662 const struct GNUNET_SOCIAL_Nym *nym,
663 const char *method_name)
665 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
666 "Test #%u: Host received method for message ID %" PRIu64 ":\n"
668 test, message_id, method_name);
669 /** @todo FIXME: check message */
674 host_recv_modifier (void *cls,
675 const struct GNUNET_MessageHeader *msg,
677 enum GNUNET_ENV_Operator oper,
681 uint16_t full_value_size)
683 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
684 "Test #%u: Host received modifier for message ID %" PRIu64 ":\n"
686 test, message_id, oper, name, value_size, value);
691 host_recv_data (void *cls,
692 const struct GNUNET_MessageHeader *msg,
694 uint64_t data_offset,
698 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
699 "Test #%u: Host received data for message ID %" PRIu64 ":\n"
701 test, message_id, data_size, data);
706 host_recv_eom (void *cls,
707 const struct GNUNET_MessageHeader *msg,
711 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
712 "Test #%u: Host received end of message ID %" PRIu64
714 test, message_id, cancelled);
718 case TEST_HOST_ANNOUNCE:
719 test = TEST_HOST_ANNOUNCE_END;
722 case TEST_HOST_ANNOUNCE_END:
726 case TEST_HOST_ANNOUNCE2:
727 test = TEST_HOST_ANNOUNCE2_END;
730 case TEST_HOST_ANNOUNCE2_END:
734 case TEST_GUEST_TALK:
735 guest_history_replay ();
739 if (TEST_GUEST_LEAVE <= test)
741 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
750 test = TEST_GUEST_TALK;
752 tmit = (struct TransmitClosure) {};
753 tmit.env = GNUNET_ENV_environment_create ();
754 GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
755 "_bar_foo", DATA2ARG ("one two three"));
756 GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
757 "_bar_baz", DATA2ARG ("four five"));
758 tmit.data[0] = "zzz xxx yyy";
759 tmit.data[1] = "zyx wvu tsr qpo";
760 tmit.data_delay[1] = 1;
761 tmit.data[2] = "testing ten nine eight";
765 = GNUNET_SOCIAL_guest_talk (gst, "_message_guest", tmit.env,
767 GNUNET_SOCIAL_TALK_NONE);
774 test = TEST_HOST_ANNOUNCE;
776 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
777 "Test #%u: Host announcement.\n", test);
779 tmit = (struct TransmitClosure) {};
780 tmit.env = GNUNET_ENV_environment_create ();
781 GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
782 "_foo", DATA2ARG ("bar baz"));
783 GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
784 "_foo_bar", DATA2ARG ("foo bar"));
785 GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
786 "_foo_bar_baz", DATA2ARG ("foo bar baz"));
787 tmit.data[0] = "aaa bbb ccc";
788 tmit.data[1] = "abc def ghi jkl";
789 tmit.data_delay[1] = 1;
790 tmit.data[2] = "testing one two three";
791 tmit.data[3] = "four five";
795 = GNUNET_SOCIAL_host_announce (hst, "_message_host", tmit.env,
797 GNUNET_SOCIAL_ANNOUNCE_NONE);
804 GNUNET_assert (2 == mod_foo_bar_rcls.n);
805 GNUNET_SOCIAL_slicer_modifier_remove (guest_slicer, "_foo_bar",
806 guest_recv_mod_foo_bar);
808 test = TEST_HOST_ANNOUNCE2;
810 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
811 "Test #%u: Host announcement 2.\n", test);
813 tmit = (struct TransmitClosure) {};
814 tmit.env = GNUNET_ENV_environment_create ();
815 GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
816 "_foo2", DATA2ARG ("BAR BAZ"));
817 GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
818 "_foo2_bar", DATA2ARG ("FOO BAR"));
819 GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
820 "_foo2_bar", DATA2ARG ("FOO BAR BAZ"));
821 tmit.data[0] = "AAA BBB CCC";
822 tmit.data[1] = "ABC DEF GHI JKL";
823 tmit.data[2] = "TESTING ONE TWO THREE";
827 = GNUNET_SOCIAL_host_announce (hst, "_message_host_two", tmit.env,
829 GNUNET_SOCIAL_ANNOUNCE_NONE);
834 guest_recv_entry_decision (void *cls,
836 const struct GNUNET_PSYC_Message *entry_msg)
838 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
839 "Test #%u: Guest received entry decision (try %u): %d.\n",
840 test, join_req_count, is_admitted);
842 if (NULL != entry_msg)
844 struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create ();
845 const char *method_name = NULL;
846 const void *data = NULL;
847 uint16_t data_size = 0;
848 struct GNUNET_PSYC_MessageHeader *
849 pmsg = GNUNET_PSYC_message_header_create_from_psyc (entry_msg);
850 GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size);
853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
855 method_name, data_size, data);
856 /** @todo FIXME: check response message */
861 case TEST_GUEST_RECV_ENTRY_DCSN_REFUSE:
862 GNUNET_assert (GNUNET_NO == is_admitted);
866 case TEST_GUEST_RECV_ENTRY_DCSN_ADMIT:
867 GNUNET_assert (GNUNET_YES == is_admitted);
871 case TEST_GUEST_ENTER_BY_NAME:
872 GNUNET_SCHEDULER_add_now (schedule_host_leave, NULL);
876 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
883 host_answer_door (void *cls,
884 struct GNUNET_SOCIAL_Nym *nym,
885 const char *method_name,
886 struct GNUNET_ENV_Environment *env,
892 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
893 "Test #%u: Host received entry request from guest (try %u).\n",
894 test, join_req_count);
895 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
897 method_name, data_size, data);
901 case TEST_HOST_ANSWER_DOOR_REFUSE:
902 test = TEST_GUEST_RECV_ENTRY_DCSN_REFUSE;
903 join_resp = GNUNET_PSYC_message_create ("_refuse_nym", env,
904 DATA2ARG ("Go away!"));
905 GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_NO, join_resp);
908 case TEST_HOST_ANSWER_DOOR_ADMIT:
909 test = TEST_GUEST_RECV_ENTRY_DCSN_ADMIT;
910 case TEST_GUEST_ENTER_BY_NAME:
911 join_resp = GNUNET_PSYC_message_create ("_admit_nym", env,
912 DATA2ARG ("Welcome, nym!"));
913 GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp);
917 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
924 guest_recv_local_enter (void *cls, int result, uint64_t max_message_id)
926 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
927 "Test #%u: Guest entered to local place: %d\n",
929 GNUNET_assert (0 <= result);
936 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
937 "Test #%u: Entering to place as guest.\n", test);
939 struct GuestEnterMessage *emsg = &guest_enter_msg;
941 emsg->method_name = "_request_enter";
942 emsg->env = GNUNET_ENV_environment_create ();
943 GNUNET_ENV_environment_add (emsg->env, GNUNET_ENV_OP_ASSIGN,
944 "_abc", "abc def", 7);
945 GNUNET_ENV_environment_add (emsg->env, GNUNET_ENV_OP_ASSIGN,
946 "_abc_def", "abc def ghi", 11);
947 emsg->data = "let me in";
948 emsg->data_size = strlen (emsg->data) + 1;
949 emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
950 emsg->data, emsg->data_size);
952 gst = GNUNET_SOCIAL_guest_enter (cfg, guest_ego, &place_pub_key,
953 &this_peer, 0, NULL, emsg->msg, guest_slicer,
954 guest_recv_local_enter,
955 guest_recv_entry_decision, NULL);
956 gst_plc = GNUNET_SOCIAL_guest_get_place (gst);
961 guest_enter_by_name ()
963 test = TEST_GUEST_ENTER_BY_NAME;
964 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
965 "Test #%u: Entering to place by name as guest.\n", test);
967 struct GuestEnterMessage *emsg = &guest_enter_msg;
969 emsg->method_name = "_request_enter";
970 emsg->env = GNUNET_ENV_environment_create ();
971 GNUNET_ENV_environment_add (emsg->env, GNUNET_ENV_OP_ASSIGN,
972 "_abc", "abc def", 7);
973 GNUNET_ENV_environment_add (emsg->env, GNUNET_ENV_OP_ASSIGN,
974 "_abc_def", "abc def ghi", 11);
975 emsg->data = "let me in";
976 emsg->data_size = strlen (emsg->data) + 1;
977 emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
978 emsg->data, emsg->data_size);
980 gst = GNUNET_SOCIAL_guest_enter_by_name (cfg, guest_ego,
981 "home.host.gnu", "let.me*in!",
982 emsg->msg, guest_slicer,
983 guest_recv_local_enter,
984 guest_recv_entry_decision, NULL);
985 gst_plc = GNUNET_SOCIAL_guest_get_place (gst);
990 guest_recv_add_pkey_result (void *cls, int32_t success, const char *emsg)
992 GNUNET_assert (GNUNET_YES == success);
993 guest_pkey_added = GNUNET_YES;
998 id_guest_ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
1000 GNUNET_assert (NULL != ego);
1002 GNUNET_IDENTITY_ego_get_public_key (ego, &guest_pub_key);
1004 guest_slicer = GNUNET_SOCIAL_slicer_create ();
1005 GNUNET_SOCIAL_slicer_method_add (guest_slicer, "",
1006 guest_recv_method, guest_recv_modifier,
1007 guest_recv_data, guest_recv_eom, NULL);
1008 GNUNET_SOCIAL_slicer_modifier_add (guest_slicer, "_foo_bar",
1009 guest_recv_mod_foo_bar, &mod_foo_bar_rcls);
1010 test = TEST_HOST_ANSWER_DOOR_ADMIT;
1012 GNUNET_SOCIAL_zone_add_pkey (cfg, guest_ego, "host", &host_pub_key,
1013 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
1014 guest_recv_add_pkey_result, NULL);
1021 id_guest_created (void *cls, const char *emsg)
1025 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1026 "Could not create guest identity: %s\n", emsg);
1027 #if ! DEBUG_TEST_SOCIAL
1032 GNUNET_IDENTITY_ego_lookup (cfg, guest_name, &id_guest_ego_cb, NULL);
1037 host_entered (void *cls, int result, uint64_t max_message_id)
1039 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Host entered to place.\n");
1041 GNUNET_IDENTITY_create (id, guest_name, &id_guest_created, NULL);
1046 id_host_ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
1048 GNUNET_assert (NULL != ego);
1050 GNUNET_IDENTITY_ego_get_public_key (ego, &host_pub_key);
1052 host_slicer = GNUNET_SOCIAL_slicer_create ();
1053 GNUNET_SOCIAL_slicer_method_add (host_slicer, "",
1054 &host_recv_method, &host_recv_modifier,
1055 &host_recv_data, &host_recv_eom, NULL);
1057 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering to place as host.\n");
1058 hst = GNUNET_SOCIAL_host_enter (cfg, host_ego, place_key,
1059 GNUNET_PSYC_CHANNEL_PRIVATE, host_slicer,
1060 host_entered, host_answer_door,
1061 host_farewell, NULL);
1062 hst_plc = GNUNET_SOCIAL_host_get_place (hst);
1067 id_host_created (void *cls, const char *emsg)
1071 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1072 "Could not create host identity: %s\n", emsg);
1073 #if ! DEBUG_TEST_SOCIAL
1078 GNUNET_IDENTITY_ego_lookup (cfg, host_name, &id_host_ego_cb, NULL);
1083 identity_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego,
1084 void **ctx, const char *name)
1091 core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity)
1093 this_peer = *my_identity;
1095 id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL);
1096 GNUNET_IDENTITY_create (id, host_name, &id_host_created, NULL);
1101 * Main function of the test, run from scheduler.
1104 * @param cfg configuration we use (also to connect to Social service)
1105 * @param peer handle to access more of the peer (not used)
1108 #if DEBUG_TEST_SOCIAL
1109 run (void *cls, char *const *args, const char *cfgfile,
1110 const struct GNUNET_CONFIGURATION_Handle *c)
1113 const struct GNUNET_CONFIGURATION_Handle *c,
1114 struct GNUNET_TESTING_Peer *peer)
1118 end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
1120 place_key = GNUNET_CRYPTO_eddsa_key_create ();
1121 GNUNET_CRYPTO_eddsa_key_get_public (place_key, &place_pub_key);
1123 core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL,
1124 NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
1129 main (int argc, char *argv[])
1132 #if DEBUG_TEST_SOCIAL
1133 const struct GNUNET_GETOPT_CommandLineOption opts[] = {
1134 GNUNET_GETOPT_OPTION_END
1136 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-social",
1137 "test-social [options]",
1141 if (0 != GNUNET_TESTING_peer_run ("test-social", "test_social.conf", &run, NULL))
1147 /* end of test_social.c */