diff options
Diffstat (limited to 'src/social/test_social.c')
-rw-r--r-- | src/social/test_social.c | 103 |
1 files changed, 87 insertions, 16 deletions
diff --git a/src/social/test_social.c b/src/social/test_social.c index 50150449c..5a224c4ae 100644 --- a/src/social/test_social.c +++ b/src/social/test_social.c | |||
@@ -68,6 +68,7 @@ struct GNUNET_CRYPTO_EcdsaPrivateKey *guest_key; | |||
68 | 68 | ||
69 | struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key; | 69 | struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key; |
70 | struct GNUNET_CRYPTO_EcdsaPublicKey guest_pub_key; | 70 | struct GNUNET_CRYPTO_EcdsaPublicKey guest_pub_key; |
71 | struct GNUNET_CRYPTO_EcdsaPublicKey host_pub_key; | ||
71 | 72 | ||
72 | struct GNUNET_SOCIAL_Slicer *host_slicer; | 73 | struct GNUNET_SOCIAL_Slicer *host_slicer; |
73 | struct GNUNET_SOCIAL_Slicer *guest_slicer; | 74 | struct GNUNET_SOCIAL_Slicer *guest_slicer; |
@@ -110,6 +111,8 @@ struct GNUNET_PSYC_Message *join_resp; | |||
110 | 111 | ||
111 | uint32_t counter; | 112 | uint32_t counter; |
112 | 113 | ||
114 | uint8_t guest_pkey_added = GNUNET_NO; | ||
115 | |||
113 | enum | 116 | enum |
114 | { | 117 | { |
115 | TEST_NONE = 0, | 118 | TEST_NONE = 0, |
@@ -136,11 +139,12 @@ enum | |||
136 | static void | 139 | static void |
137 | guest_enter (); | 140 | guest_enter (); |
138 | 141 | ||
142 | static void | ||
143 | guest_enter_by_name (); | ||
139 | 144 | ||
140 | static void | 145 | static void |
141 | guest_talk (); | 146 | guest_talk (); |
142 | 147 | ||
143 | |||
144 | static void | 148 | static void |
145 | host_announce2 (); | 149 | host_announce2 (); |
146 | 150 | ||
@@ -309,10 +313,25 @@ schedule_host_leave (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
309 | 313 | ||
310 | 314 | ||
311 | static void | 315 | static void |
316 | id_guest_ego_cb2 (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | ||
317 | { | ||
318 | GNUNET_assert (NULL != ego); | ||
319 | guest_ego = ego; | ||
320 | |||
321 | guest_enter_by_name (); | ||
322 | } | ||
323 | |||
324 | |||
325 | static void | ||
312 | host_recv_advertise_result (void *cls, int32_t success, const char *emsg) | 326 | host_recv_advertise_result (void *cls, int32_t success, const char *emsg) |
313 | { | 327 | { |
328 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
329 | "Test #%u: Advertise result: %d (%s).\n", | ||
330 | test, success, emsg); | ||
314 | GNUNET_assert (GNUNET_YES == success); | 331 | GNUNET_assert (GNUNET_YES == success); |
315 | GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL); | 332 | |
333 | GNUNET_assert (GNUNET_YES == guest_pkey_added); | ||
334 | GNUNET_IDENTITY_ego_lookup (cfg, guest_name, id_guest_ego_cb2, NULL); | ||
316 | } | 335 | } |
317 | 336 | ||
318 | 337 | ||
@@ -320,10 +339,12 @@ static void | |||
320 | host_advertise () | 339 | host_advertise () |
321 | { | 340 | { |
322 | test = TEST_HOST_ADVERTISE; | 341 | test = TEST_HOST_ADVERTISE; |
323 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test #%u: Advertising place.\n", test); | 342 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
343 | "Test #%u: Advertising place.\n", test); | ||
344 | |||
324 | GNUNET_SOCIAL_host_advertise (hst, "home", 1, &this_peer, | 345 | GNUNET_SOCIAL_host_advertise (hst, "home", 1, &this_peer, |
325 | GNUNET_TIME_UNIT_MINUTES, "let.me*in!", | 346 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES), |
326 | host_recv_advertise_result, hst); | 347 | "let.me*in!", host_recv_advertise_result, hst); |
327 | } | 348 | } |
328 | 349 | ||
329 | 350 | ||
@@ -714,10 +735,9 @@ host_recv_eom (void *cls, | |||
714 | guest_history_replay (); | 735 | guest_history_replay (); |
715 | break; | 736 | break; |
716 | 737 | ||
717 | case TEST_GUEST_LEAVE: | ||
718 | break; | ||
719 | |||
720 | default: | 738 | default: |
739 | if (TEST_GUEST_LEAVE <= test) | ||
740 | break; | ||
721 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test); | 741 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test); |
722 | GNUNET_assert (0); | 742 | GNUNET_assert (0); |
723 | } | 743 | } |
@@ -811,19 +831,22 @@ host_announce2 () | |||
811 | static void | 831 | static void |
812 | guest_recv_entry_decision (void *cls, | 832 | guest_recv_entry_decision (void *cls, |
813 | int is_admitted, | 833 | int is_admitted, |
814 | const struct GNUNET_PSYC_Message *entry_resp) | 834 | const struct GNUNET_PSYC_Message *entry_msg) |
815 | { | 835 | { |
816 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 836 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
817 | "Test #%u: Guest received entry decision (try %u): %d.\n", | 837 | "Test #%u: Guest received entry decision (try %u): %d.\n", |
818 | test, join_req_count, is_admitted); | 838 | test, join_req_count, is_admitted); |
819 | 839 | ||
820 | if (NULL != entry_resp) | 840 | if (NULL != entry_msg) |
821 | { | 841 | { |
822 | struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create (); | 842 | struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create (); |
823 | const char *method_name = NULL; | 843 | const char *method_name = NULL; |
824 | const void *data = NULL; | 844 | const void *data = NULL; |
825 | uint16_t data_size = 0; | 845 | uint16_t data_size = 0; |
826 | GNUNET_PSYC_message_parse (entry_resp, &method_name, env, &data, &data_size); | 846 | struct GNUNET_PSYC_MessageHeader * |
847 | pmsg = GNUNET_PSYC_message_header_create_from_psyc (entry_msg); | ||
848 | GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size); | ||
849 | GNUNET_free (pmsg); | ||
827 | 850 | ||
828 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
829 | "%s\n%.*s\n", | 852 | "%s\n%.*s\n", |
@@ -843,6 +866,10 @@ guest_recv_entry_decision (void *cls, | |||
843 | host_announce (); | 866 | host_announce (); |
844 | break; | 867 | break; |
845 | 868 | ||
869 | case TEST_GUEST_ENTER_BY_NAME: | ||
870 | GNUNET_SCHEDULER_add_now (schedule_host_leave, NULL); | ||
871 | break; | ||
872 | |||
846 | default: | 873 | default: |
847 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test); | 874 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test); |
848 | GNUNET_assert (0); | 875 | GNUNET_assert (0); |
@@ -878,6 +905,7 @@ host_answer_door (void *cls, | |||
878 | 905 | ||
879 | case TEST_HOST_ANSWER_DOOR_ADMIT: | 906 | case TEST_HOST_ANSWER_DOOR_ADMIT: |
880 | test = TEST_GUEST_RECV_ENTRY_DCSN_ADMIT; | 907 | test = TEST_GUEST_RECV_ENTRY_DCSN_ADMIT; |
908 | case TEST_GUEST_ENTER_BY_NAME: | ||
881 | join_resp = GNUNET_PSYC_message_create ("_admit_nym", env, | 909 | join_resp = GNUNET_PSYC_message_create ("_admit_nym", env, |
882 | DATA2ARG ("Welcome, nym!")); | 910 | DATA2ARG ("Welcome, nym!")); |
883 | GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp); | 911 | GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp); |
@@ -894,8 +922,9 @@ static void | |||
894 | guest_recv_local_enter (void *cls, int result, uint64_t max_message_id) | 922 | guest_recv_local_enter (void *cls, int result, uint64_t max_message_id) |
895 | { | 923 | { |
896 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 924 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
897 | "Test #%u: Guest entered to local place.\n", test); | 925 | "Test #%u: Guest entered to local place: %d\n", |
898 | 926 | test, result); | |
927 | GNUNET_assert (0 <= result); | ||
899 | } | 928 | } |
900 | 929 | ||
901 | 930 | ||
@@ -919,14 +948,51 @@ guest_enter () | |||
919 | emsg->data, emsg->data_size); | 948 | emsg->data, emsg->data_size); |
920 | 949 | ||
921 | gst = GNUNET_SOCIAL_guest_enter (cfg, guest_ego, &place_pub_key, | 950 | gst = GNUNET_SOCIAL_guest_enter (cfg, guest_ego, &place_pub_key, |
922 | &this_peer, 0, NULL, emsg->msg, | 951 | &this_peer, 0, NULL, emsg->msg, guest_slicer, |
923 | guest_slicer, &guest_recv_local_enter, | 952 | guest_recv_local_enter, |
924 | &guest_recv_entry_decision, NULL); | 953 | guest_recv_entry_decision, NULL); |
954 | gst_plc = GNUNET_SOCIAL_guest_get_place (gst); | ||
955 | } | ||
956 | |||
957 | |||
958 | static void | ||
959 | guest_enter_by_name () | ||
960 | { | ||
961 | test = TEST_GUEST_ENTER_BY_NAME; | ||
962 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
963 | "Test #%u: Entering to place by name as guest.\n", test); | ||
964 | |||
965 | struct GuestEnterMessage *emsg = &guest_enter_msg; | ||
966 | |||
967 | emsg->method_name = "_request_enter"; | ||
968 | emsg->env = GNUNET_ENV_environment_create (); | ||
969 | GNUNET_ENV_environment_add (emsg->env, GNUNET_ENV_OP_ASSIGN, | ||
970 | "_abc", "abc def", 7); | ||
971 | GNUNET_ENV_environment_add (emsg->env, GNUNET_ENV_OP_ASSIGN, | ||
972 | "_abc_def", "abc def ghi", 11); | ||
973 | emsg->data = "let me in"; | ||
974 | emsg->data_size = strlen (emsg->data) + 1; | ||
975 | emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env, | ||
976 | emsg->data, emsg->data_size); | ||
977 | |||
978 | gst = GNUNET_SOCIAL_guest_enter_by_name (cfg, guest_ego, | ||
979 | "home.host.gnu", "let.me*in!", | ||
980 | emsg->msg, guest_slicer, | ||
981 | guest_recv_local_enter, | ||
982 | guest_recv_entry_decision, NULL); | ||
925 | gst_plc = GNUNET_SOCIAL_guest_get_place (gst); | 983 | gst_plc = GNUNET_SOCIAL_guest_get_place (gst); |
926 | } | 984 | } |
927 | 985 | ||
928 | 986 | ||
929 | static void | 987 | static void |
988 | guest_recv_add_pkey_result (void *cls, int32_t success, const char *emsg) | ||
989 | { | ||
990 | GNUNET_assert (GNUNET_YES == success); | ||
991 | guest_pkey_added = GNUNET_YES; | ||
992 | } | ||
993 | |||
994 | |||
995 | static void | ||
930 | id_guest_ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | 996 | id_guest_ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) |
931 | { | 997 | { |
932 | GNUNET_assert (NULL != ego); | 998 | GNUNET_assert (NULL != ego); |
@@ -941,6 +1007,10 @@ id_guest_ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | |||
941 | guest_recv_mod_foo_bar, &mod_foo_bar_rcls); | 1007 | guest_recv_mod_foo_bar, &mod_foo_bar_rcls); |
942 | test = TEST_HOST_ANSWER_DOOR_ADMIT; | 1008 | test = TEST_HOST_ANSWER_DOOR_ADMIT; |
943 | 1009 | ||
1010 | GNUNET_SOCIAL_zone_add_pkey (cfg, guest_ego, "host", &host_pub_key, | ||
1011 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES), | ||
1012 | guest_recv_add_pkey_result, NULL); | ||
1013 | |||
944 | guest_enter (); | 1014 | guest_enter (); |
945 | } | 1015 | } |
946 | 1016 | ||
@@ -975,6 +1045,7 @@ id_host_ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | |||
975 | { | 1045 | { |
976 | GNUNET_assert (NULL != ego); | 1046 | GNUNET_assert (NULL != ego); |
977 | host_ego = ego; | 1047 | host_ego = ego; |
1048 | GNUNET_IDENTITY_ego_get_public_key (ego, &host_pub_key); | ||
978 | 1049 | ||
979 | host_slicer = GNUNET_SOCIAL_slicer_create (); | 1050 | host_slicer = GNUNET_SOCIAL_slicer_create (); |
980 | GNUNET_SOCIAL_slicer_method_add (host_slicer, "", | 1051 | GNUNET_SOCIAL_slicer_method_add (host_slicer, "", |