diff options
Diffstat (limited to 'src/social/test_social.c')
-rw-r--r-- | src/social/test_social.c | 166 |
1 files changed, 109 insertions, 57 deletions
diff --git a/src/social/test_social.c b/src/social/test_social.c index 0dc2a9d30..64ef10125 100644 --- a/src/social/test_social.c +++ b/src/social/test_social.c | |||
@@ -57,6 +57,9 @@ struct GNUNET_PeerIdentity this_peer; | |||
57 | 57 | ||
58 | struct GNUNET_IDENTITY_Handle *id; | 58 | struct GNUNET_IDENTITY_Handle *id; |
59 | 59 | ||
60 | const struct GNUNET_IDENTITY_Ego *identity_host_ego; | ||
61 | const struct GNUNET_IDENTITY_Ego *identity_guest_ego; | ||
62 | |||
60 | const struct GNUNET_SOCIAL_Ego *host_ego; | 63 | const struct GNUNET_SOCIAL_Ego *host_ego; |
61 | const struct GNUNET_SOCIAL_Ego *guest_ego; | 64 | const struct GNUNET_SOCIAL_Ego *guest_ego; |
62 | 65 | ||
@@ -69,8 +72,8 @@ struct GNUNET_CRYPTO_EcdsaPrivateKey *guest_key; | |||
69 | struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key; | 72 | struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key; |
70 | struct GNUNET_HashCode place_pub_hash; | 73 | struct GNUNET_HashCode place_pub_hash; |
71 | 74 | ||
72 | struct GNUNET_CRYPTO_EcdsaPublicKey guest_pub_key; | 75 | const struct GNUNET_CRYPTO_EcdsaPublicKey *guest_pub_key; |
73 | struct GNUNET_CRYPTO_EcdsaPublicKey host_pub_key; | 76 | const struct GNUNET_CRYPTO_EcdsaPublicKey *host_pub_key; |
74 | 77 | ||
75 | struct GNUNET_PSYC_Slicer *host_slicer; | 78 | struct GNUNET_PSYC_Slicer *host_slicer; |
76 | struct GNUNET_PSYC_Slicer *guest_slicer; | 79 | struct GNUNET_PSYC_Slicer *guest_slicer; |
@@ -120,29 +123,28 @@ uint8_t is_guest_reconnected = GNUNET_NO; | |||
120 | enum | 123 | enum |
121 | { | 124 | { |
122 | TEST_NONE = 0, | 125 | TEST_NONE = 0, |
123 | TEST_HOST_CREATE = 1, | 126 | TEST_IDENTITIES_CREATE = 1, |
124 | TEST_HOST_ENTER = 2, | 127 | TEST_HOST_ENTER = 2, |
125 | TEST_GUEST_CREATE = 3, | 128 | TEST_GUEST_ENTER = 3, |
126 | TEST_GUEST_ENTER = 4, | 129 | TEST_HOST_ANSWER_DOOR_REFUSE = 4, |
127 | TEST_HOST_ANSWER_DOOR_REFUSE = 5, | 130 | TEST_GUEST_RECV_ENTRY_DCSN_REFUSE = 5, |
128 | TEST_GUEST_RECV_ENTRY_DCSN_REFUSE = 6, | 131 | TEST_HOST_ANSWER_DOOR_ADMIT = 6, |
129 | TEST_HOST_ANSWER_DOOR_ADMIT = 7, | 132 | TEST_GUEST_RECV_ENTRY_DCSN_ADMIT = 9, |
130 | TEST_GUEST_RECV_ENTRY_DCSN_ADMIT = 8, | 133 | TEST_HOST_ANNOUNCE = 10, |
131 | TEST_HOST_ANNOUNCE = 9, | 134 | TEST_HOST_ANNOUNCE_END = 11, |
132 | TEST_HOST_ANNOUNCE_END = 10, | 135 | TEST_GUEST_TALK = 12, |
133 | TEST_GUEST_TALK = 11, | 136 | TEST_HOST_ANNOUNCE2 = 13, |
134 | TEST_HOST_ANNOUNCE2 = 12, | 137 | TEST_HOST_ANNOUNCE2_END = 14, |
135 | TEST_HOST_ANNOUNCE2_END = 13, | 138 | TEST_GUEST_HISTORY_REPLAY = 15, |
136 | TEST_GUEST_HISTORY_REPLAY = 14, | 139 | TEST_GUEST_HISTORY_REPLAY_LATEST = 16, |
137 | TEST_GUEST_HISTORY_REPLAY_LATEST = 15, | 140 | TEST_GUEST_LOOK_AT = 17, |
138 | TEST_GUEST_LOOK_AT = 16, | 141 | TEST_GUEST_LOOK_FOR = 18, |
139 | TEST_GUEST_LOOK_FOR = 17, | ||
140 | TEST_GUEST_LEAVE = 18, | 142 | TEST_GUEST_LEAVE = 18, |
141 | TEST_ZONE_ADD_PLACE = 19, | 143 | TEST_ZONE_ADD_PLACE = 20, |
142 | TEST_GUEST_ENTER_BY_NAME = 20, | 144 | TEST_GUEST_ENTER_BY_NAME = 21, |
143 | TEST_RECONNECT = 21, | 145 | TEST_RECONNECT = 22, |
144 | TEST_GUEST_LEAVE2 = 22, | 146 | TEST_GUEST_LEAVE2 = 23, |
145 | TEST_HOST_LEAVE = 23, | 147 | TEST_HOST_LEAVE = 24, |
146 | } test; | 148 | } test; |
147 | 149 | ||
148 | 150 | ||
@@ -458,30 +460,42 @@ app_recv_guest (void *cls, | |||
458 | 460 | ||
459 | 461 | ||
460 | static void | 462 | static void |
463 | enter_if_ready () | ||
464 | { | ||
465 | if (NULL == host_ego || NULL == guest_ego) | ||
466 | { | ||
467 | return; | ||
468 | } | ||
469 | host_enter (); | ||
470 | guest_init (); | ||
471 | } | ||
472 | |||
473 | |||
474 | static void | ||
461 | app_recv_ego (void *cls, | 475 | app_recv_ego (void *cls, |
462 | struct GNUNET_SOCIAL_Ego *ego, | 476 | struct GNUNET_SOCIAL_Ego *ego, |
463 | const struct GNUNET_CRYPTO_EcdsaPublicKey *ego_pub_key, | 477 | const struct GNUNET_CRYPTO_EcdsaPublicKey *ego_pub_key, |
464 | const char *name) | 478 | const char *name) |
465 | { | 479 | { |
466 | char *ego_pub_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (ego_pub_key); | 480 | char *ego_pub_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (ego_pub_key); |
467 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 481 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
468 | "Test #%u: Got app ego notification: %p %s %s\n", | 482 | "Test #%u: Got app ego notification: %p %s %s\n", |
469 | test, ego, name, ego_pub_str); | 483 | test, ego, name, ego_pub_str); |
470 | GNUNET_free (ego_pub_str); | 484 | GNUNET_free (ego_pub_str); |
471 | 485 | ||
472 | if (NULL != strstr (name, host_name) && TEST_HOST_CREATE == test) | 486 | if (NULL != strstr (name, host_name)) |
473 | { | 487 | { |
474 | host_ego = ego; | 488 | host_ego = ego; |
475 | host_pub_key = *(GNUNET_SOCIAL_ego_get_pub_key (host_ego)); | 489 | host_pub_key = ego_pub_key; |
476 | GNUNET_assert (TEST_HOST_CREATE == test); | 490 | GNUNET_assert (TEST_IDENTITIES_CREATE == test); |
477 | host_enter (); | 491 | enter_if_ready (); |
478 | } | 492 | } |
479 | else if (NULL != strstr (name, guest_name)) | 493 | else if (NULL != strstr (name, guest_name)) |
480 | { | 494 | { |
481 | guest_ego = ego; | 495 | guest_ego = ego; |
482 | 496 | guest_pub_key = ego_pub_key; | |
483 | if (TEST_GUEST_CREATE == test) | 497 | GNUNET_assert (TEST_IDENTITIES_CREATE == test); |
484 | guest_init (); | 498 | enter_if_ready (); |
485 | } | 499 | } |
486 | } | 500 | } |
487 | 501 | ||
@@ -548,9 +562,9 @@ host_farewell (void *cls, | |||
548 | test, GNUNET_h2s (GNUNET_SOCIAL_nym_get_pub_key_hash (nym)), str); | 562 | test, GNUNET_h2s (GNUNET_SOCIAL_nym_get_pub_key_hash (nym)), str); |
549 | GNUNET_free (str); | 563 | GNUNET_free (str); |
550 | GNUNET_assert (1 == GNUNET_PSYC_env_get_count (env)); | 564 | GNUNET_assert (1 == GNUNET_PSYC_env_get_count (env)); |
551 | if (0 != memcmp (&guest_pub_key, nym_key, sizeof (*nym_key))) | 565 | if (0 != memcmp (guest_pub_key, nym_key, sizeof (*nym_key))) |
552 | { | 566 | { |
553 | str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&guest_pub_key); | 567 | str = GNUNET_CRYPTO_ecdsa_public_key_to_string (guest_pub_key); |
554 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 568 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
555 | "Test #%u: Farewell: nym does not match guest: %s\n", | 569 | "Test #%u: Farewell: nym does not match guest: %s\n", |
556 | test, str); | 570 | test, str); |
@@ -1029,7 +1043,7 @@ guest_recv_entry_decision (void *cls, | |||
1029 | int is_admitted, | 1043 | int is_admitted, |
1030 | const struct GNUNET_PSYC_Message *entry_msg) | 1044 | const struct GNUNET_PSYC_Message *entry_msg) |
1031 | { | 1045 | { |
1032 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1046 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1033 | "Test #%u: Guest received entry decision (try %u): %d.\n", | 1047 | "Test #%u: Guest received entry decision (try %u): %d.\n", |
1034 | test, join_req_count, is_admitted); | 1048 | test, join_req_count, is_admitted); |
1035 | 1049 | ||
@@ -1121,7 +1135,7 @@ guest_recv_local_enter (void *cls, int result, | |||
1121 | const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, | 1135 | const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, |
1122 | uint64_t max_message_id) | 1136 | uint64_t max_message_id) |
1123 | { | 1137 | { |
1124 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1138 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1125 | "Test #%u: Guest entered to local place: %d\n", | 1139 | "Test #%u: Guest entered to local place: %d\n", |
1126 | test, result); | 1140 | test, result); |
1127 | GNUNET_assert (0 <= result); | 1141 | GNUNET_assert (0 <= result); |
@@ -1131,7 +1145,7 @@ guest_recv_local_enter (void *cls, int result, | |||
1131 | static void | 1145 | static void |
1132 | guest_enter () | 1146 | guest_enter () |
1133 | { | 1147 | { |
1134 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1148 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1135 | "Test #%u: Entering to place as guest.\n", test); | 1149 | "Test #%u: Entering to place as guest.\n", test); |
1136 | 1150 | ||
1137 | struct GuestEnterMessage *emsg = &guest_enter_msg; | 1151 | struct GuestEnterMessage *emsg = &guest_enter_msg; |
@@ -1200,7 +1214,7 @@ app_recv_zone_add_nym_result (void *cls, int64_t result, | |||
1200 | static void | 1214 | static void |
1201 | guest_init () | 1215 | guest_init () |
1202 | { | 1216 | { |
1203 | guest_pub_key = *(GNUNET_SOCIAL_ego_get_pub_key (guest_ego)); | 1217 | guest_pub_key = GNUNET_SOCIAL_ego_get_pub_key (guest_ego); |
1204 | 1218 | ||
1205 | guest_slicer = GNUNET_PSYC_slicer_create (); | 1219 | guest_slicer = GNUNET_PSYC_slicer_create (); |
1206 | GNUNET_PSYC_slicer_method_add (guest_slicer, "", NULL, | 1220 | GNUNET_PSYC_slicer_method_add (guest_slicer, "", NULL, |
@@ -1210,10 +1224,25 @@ guest_init () | |||
1210 | guest_recv_mod_foo_bar, &mod_foo_bar_rcls); | 1224 | guest_recv_mod_foo_bar, &mod_foo_bar_rcls); |
1211 | test = TEST_HOST_ANSWER_DOOR_ADMIT; | 1225 | test = TEST_HOST_ANSWER_DOOR_ADMIT; |
1212 | 1226 | ||
1213 | GNUNET_SOCIAL_zone_add_nym (app, guest_ego, "host", &host_pub_key, | 1227 | GNUNET_SOCIAL_zone_add_nym (app, guest_ego, "host", host_pub_key, |
1214 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES), | 1228 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES), |
1215 | app_recv_zone_add_nym_result, NULL); | 1229 | app_recv_zone_add_nym_result, NULL); |
1216 | guest_enter (); | 1230 | } |
1231 | |||
1232 | |||
1233 | static void | ||
1234 | id_host_created (void *cls, const char *emsg) | ||
1235 | { | ||
1236 | if (NULL != emsg) | ||
1237 | { | ||
1238 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1239 | "Test #%u: Could not create host identity: %s\n", | ||
1240 | test, emsg); | ||
1241 | #if ! DEBUG_TEST_SOCIAL | ||
1242 | GNUNET_assert (0); | ||
1243 | #endif | ||
1244 | } | ||
1245 | |||
1217 | } | 1246 | } |
1218 | 1247 | ||
1219 | 1248 | ||
@@ -1229,8 +1258,8 @@ id_guest_created (void *cls, const char *emsg) | |||
1229 | GNUNET_assert (0); | 1258 | GNUNET_assert (0); |
1230 | #endif | 1259 | #endif |
1231 | } | 1260 | } |
1232 | if (NULL != guest_ego) | 1261 | //if (NULL != guest_ego) |
1233 | guest_init (); | 1262 | // guest_init (); |
1234 | } | 1263 | } |
1235 | 1264 | ||
1236 | 1265 | ||
@@ -1241,12 +1270,10 @@ host_entered (void *cls, int result, | |||
1241 | { | 1270 | { |
1242 | place_pub_key = *home_pub_key; | 1271 | place_pub_key = *home_pub_key; |
1243 | GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash); | 1272 | GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash); |
1244 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1273 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1245 | "Test #%u: Host entered to place %s\n", | 1274 | "Test #%u: Host entered to place %s\n", |
1246 | test, GNUNET_h2s (&place_pub_hash)); | 1275 | test, GNUNET_h2s (&place_pub_hash)); |
1247 | 1276 | guest_enter (); | |
1248 | test = TEST_GUEST_CREATE; | ||
1249 | GNUNET_IDENTITY_create (id, guest_name, &id_guest_created, NULL); | ||
1250 | } | 1277 | } |
1251 | 1278 | ||
1252 | 1279 | ||
@@ -1258,7 +1285,7 @@ host_enter () | |||
1258 | host_recv_method, host_recv_modifier, | 1285 | host_recv_method, host_recv_modifier, |
1259 | host_recv_data, host_recv_eom, NULL); | 1286 | host_recv_data, host_recv_eom, NULL); |
1260 | 1287 | ||
1261 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1288 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1262 | "Test #%u: Entering to place as host.\n", test); | 1289 | "Test #%u: Entering to place as host.\n", test); |
1263 | test = TEST_HOST_ENTER; | 1290 | test = TEST_HOST_ENTER; |
1264 | hst = GNUNET_SOCIAL_host_enter (app, host_ego, | 1291 | hst = GNUNET_SOCIAL_host_enter (app, host_ego, |
@@ -1273,19 +1300,14 @@ host_enter () | |||
1273 | 1300 | ||
1274 | 1301 | ||
1275 | static void | 1302 | static void |
1276 | id_host_created (void *cls, const char *emsg) | 1303 | start_app_if_ready () |
1277 | { | 1304 | { |
1278 | if (NULL != emsg) | 1305 | if (NULL == identity_host_ego || NULL == identity_guest_ego) |
1279 | { | 1306 | { |
1280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1307 | return; |
1281 | "Test #%u: Could not create host identity: %s\n", | ||
1282 | test, emsg); | ||
1283 | #if ! DEBUG_TEST_SOCIAL | ||
1284 | GNUNET_assert (0); | ||
1285 | #endif | ||
1286 | } | 1308 | } |
1287 | 1309 | app = GNUNET_SOCIAL_app_connect (cfg, | |
1288 | app = GNUNET_SOCIAL_app_connect (cfg, app_id, | 1310 | app_id, |
1289 | app_recv_ego, | 1311 | app_recv_ego, |
1290 | app_recv_host, | 1312 | app_recv_host, |
1291 | app_recv_guest, | 1313 | app_recv_guest, |
@@ -1298,6 +1320,35 @@ static void | |||
1298 | identity_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, | 1320 | identity_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, |
1299 | void **ctx, const char *name) | 1321 | void **ctx, const char *name) |
1300 | { | 1322 | { |
1323 | if (NULL != ego) | ||
1324 | { | ||
1325 | if (ego == identity_host_ego) | ||
1326 | { | ||
1327 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1328 | "Host ego deleted\n"); | ||
1329 | } | ||
1330 | else if (ego == identity_guest_ego) | ||
1331 | { | ||
1332 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1333 | "Guest ego deleted\n"); | ||
1334 | } | ||
1335 | else if (0 == strcmp (name, host_name)) | ||
1336 | { | ||
1337 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1338 | "Created ego %s\n", | ||
1339 | name); | ||
1340 | identity_host_ego = ego; | ||
1341 | start_app_if_ready (); | ||
1342 | } | ||
1343 | else if (0 == strcmp (name, guest_name)) | ||
1344 | { | ||
1345 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1346 | "Created guest ego %s\n", | ||
1347 | name); | ||
1348 | identity_guest_ego = ego; | ||
1349 | start_app_if_ready (); | ||
1350 | } | ||
1351 | } | ||
1301 | } | 1352 | } |
1302 | 1353 | ||
1303 | 1354 | ||
@@ -1326,8 +1377,9 @@ run (void *cls, | |||
1326 | 1377 | ||
1327 | id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL); | 1378 | id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL); |
1328 | 1379 | ||
1329 | test = TEST_HOST_CREATE; | 1380 | test = TEST_IDENTITIES_CREATE; |
1330 | GNUNET_IDENTITY_create (id, host_name, &id_host_created, NULL); | 1381 | GNUNET_IDENTITY_create (id, host_name, &id_host_created, NULL); |
1382 | GNUNET_IDENTITY_create (id, guest_name, &id_guest_created, NULL); | ||
1331 | } | 1383 | } |
1332 | 1384 | ||
1333 | 1385 | ||