diff options
Diffstat (limited to 'src/chat/test_chat.c')
-rw-r--r-- | src/chat/test_chat.c | 107 |
1 files changed, 42 insertions, 65 deletions
diff --git a/src/chat/test_chat.c b/src/chat/test_chat.c index 0953a895b..7cf8b19cf 100644 --- a/src/chat/test_chat.c +++ b/src/chat/test_chat.c | |||
@@ -118,12 +118,13 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
118 | { | 118 | { |
119 | p->cfg = GNUNET_CONFIGURATION_create (); | 119 | p->cfg = GNUNET_CONFIGURATION_create (); |
120 | #if START_ARM | 120 | #if START_ARM |
121 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 121 | p->arm_proc = |
122 | "gnunet-service-arm", | 122 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
123 | "gnunet-service-arm", | ||
123 | #if VERBOSE | 124 | #if VERBOSE |
124 | "-L", "DEBUG", | 125 | "-L", "DEBUG", |
125 | #endif | 126 | #endif |
126 | "-c", cfgname, NULL); | 127 | "-c", cfgname, NULL); |
127 | #endif | 128 | #endif |
128 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 129 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
129 | } | 130 | } |
@@ -137,8 +138,7 @@ stop_arm (struct PeerContext *p) | |||
137 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 138 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
138 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | 139 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
139 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 140 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 141 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", |
141 | "ARM process %u stopped\n", | ||
142 | GNUNET_OS_process_get_pid (p->arm_proc)); | 142 | GNUNET_OS_process_get_pid (p->arm_proc)); |
143 | GNUNET_OS_process_close (p->arm_proc); | 143 | GNUNET_OS_process_close (p->arm_proc); |
144 | p->arm_proc = NULL; | 144 | p->arm_proc = NULL; |
@@ -196,8 +196,7 @@ join_cb (void *cls) | |||
196 | 196 | ||
197 | 197 | ||
198 | static int | 198 | static int |
199 | member_list_cb (void *cls, | 199 | member_list_cb (void *cls, const struct GNUNET_CONTAINER_MetaData *member_info, |
200 | const struct GNUNET_CONTAINER_MetaData *member_info, | ||
201 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id, | 200 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id, |
202 | enum GNUNET_CHAT_MsgOptions options) | 201 | enum GNUNET_CHAT_MsgOptions options) |
203 | { | 202 | { |
@@ -205,24 +204,19 @@ member_list_cb (void *cls, | |||
205 | GNUNET_HashCode sender; | 204 | GNUNET_HashCode sender; |
206 | 205 | ||
207 | #if VERBOSE | 206 | #if VERBOSE |
208 | printf ("%s - told that %s has %s\n", | 207 | printf ("%s - told that %s has %s\n", want->me, |
209 | want->me, | 208 | member_info == |
210 | member_info == NULL ? NULL | 209 | NULL ? NULL : GNUNET_CONTAINER_meta_data_get_by_type (member_info, |
211 | : GNUNET_CONTAINER_meta_data_get_by_type (member_info, | 210 | EXTRACTOR_METATYPE_TITLE), |
212 | EXTRACTOR_METATYPE_TITLE), | ||
213 | member_info == NULL ? "left" : "joined"); | 211 | member_info == NULL ? "left" : "joined"); |
214 | #endif | 212 | #endif |
215 | GNUNET_CRYPTO_hash (member_id, | 213 | GNUNET_CRYPTO_hash (member_id, |
216 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 214 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
217 | &sender); | 215 | &sender); |
218 | if ((0 == memcmp (&sender, want->sender, | 216 | if ((0 == memcmp (&sender, want->sender, sizeof (GNUNET_HashCode))) && |
219 | sizeof (GNUNET_HashCode))) && | 217 | (((member_info == NULL) && (want->meta == NULL)) || |
220 | (((member_info == NULL) && | 218 | ((member_info != NULL) && (want->meta != NULL) && |
221 | (want->meta == NULL)) || | 219 | (GNUNET_CONTAINER_meta_data_test_equal (member_info, want->meta)))) && |
222 | ((member_info != NULL) && | ||
223 | (want->meta != NULL) && | ||
224 | (GNUNET_CONTAINER_meta_data_test_equal (member_info, | ||
225 | want->meta)))) && | ||
226 | (options == want->opt)) | 220 | (options == want->opt)) |
227 | { | 221 | { |
228 | if (NULL != want->next_task) | 222 | if (NULL != want->next_task) |
@@ -239,29 +233,24 @@ member_list_cb (void *cls, | |||
239 | 233 | ||
240 | 234 | ||
241 | static int | 235 | static int |
242 | receive_cb (void *cls, | 236 | receive_cb (void *cls, struct GNUNET_CHAT_Room *room, |
243 | struct GNUNET_CHAT_Room *room, | ||
244 | const GNUNET_HashCode * sender, | 237 | const GNUNET_HashCode * sender, |
245 | const struct GNUNET_CONTAINER_MetaData *meta, | 238 | const struct GNUNET_CONTAINER_MetaData *meta, const char *message, |
246 | const char *message, | ||
247 | struct GNUNET_TIME_Absolute timestamp, | 239 | struct GNUNET_TIME_Absolute timestamp, |
248 | enum GNUNET_CHAT_MsgOptions options) | 240 | enum GNUNET_CHAT_MsgOptions options) |
249 | { | 241 | { |
250 | struct Wanted *want = cls; | 242 | struct Wanted *want = cls; |
251 | 243 | ||
252 | #if VERBOSE | 244 | #if VERBOSE |
253 | printf ("%s - told that %s said %s\n", | 245 | printf ("%s - told that %s said %s\n", want->me, |
254 | want->me, | 246 | meta == NULL ? NULL : GNUNET_CONTAINER_meta_data_get_by_type (meta, |
255 | meta == NULL ? NULL | 247 | EXTRACTOR_METATYPE_TITLE), |
256 | : GNUNET_CONTAINER_meta_data_get_by_type (meta, | ||
257 | EXTRACTOR_METATYPE_TITLE), | ||
258 | message); | 248 | message); |
259 | #endif | 249 | #endif |
260 | if ((0 == strcmp (message, want->msg)) && | 250 | if ((0 == strcmp (message, want->msg)) && |
261 | (((sender == NULL) && (want->sender == NULL)) || | 251 | (((sender == NULL) && (want->sender == NULL)) || |
262 | ((sender != NULL) && (want->sender != NULL) && | 252 | ((sender != NULL) && (want->sender != NULL) && |
263 | (0 == memcmp (sender, want->sender, | 253 | (0 == memcmp (sender, want->sender, sizeof (GNUNET_HashCode))))) && |
264 | sizeof (GNUNET_HashCode))))) && | ||
265 | (GNUNET_CONTAINER_meta_data_test_equal (meta, want->meta)) && | 254 | (GNUNET_CONTAINER_meta_data_test_equal (meta, want->meta)) && |
266 | (options == want->opt) && | 255 | (options == want->opt) && |
267 | /* Not == since the library sets the actual timestamp, so it may be | 256 | /* Not == since the library sets the actual timestamp, so it may be |
@@ -283,8 +272,7 @@ receive_cb (void *cls, | |||
283 | 272 | ||
284 | 273 | ||
285 | static int | 274 | static int |
286 | confirmation_cb (void *cls, | 275 | confirmation_cb (void *cls, struct GNUNET_CHAT_Room *room, |
287 | struct GNUNET_CHAT_Room *room, | ||
288 | uint32_t orig_seq_number, | 276 | uint32_t orig_seq_number, |
289 | struct GNUNET_TIME_Absolute timestamp, | 277 | struct GNUNET_TIME_Absolute timestamp, |
290 | const GNUNET_HashCode * receiver) | 278 | const GNUNET_HashCode * receiver) |
@@ -292,14 +280,12 @@ confirmation_cb (void *cls, | |||
292 | struct Wanted *want = cls; | 280 | struct Wanted *want = cls; |
293 | 281 | ||
294 | #if VERBOSE | 282 | #if VERBOSE |
295 | printf ("%s - told that %s acknowledged message #%d\n", | 283 | printf ("%s - told that %s acknowledged message #%d\n", want->me, |
296 | want->me, | ||
297 | GNUNET_CONTAINER_meta_data_get_by_type (want->meta, | 284 | GNUNET_CONTAINER_meta_data_get_by_type (want->meta, |
298 | EXTRACTOR_METATYPE_TITLE), | 285 | EXTRACTOR_METATYPE_TITLE), |
299 | orig_seq_number); | 286 | orig_seq_number); |
300 | #endif | 287 | #endif |
301 | if ((0 == memcmp (receiver, want->sender, | 288 | if ((0 == memcmp (receiver, want->sender, sizeof (GNUNET_HashCode))) && |
302 | sizeof (GNUNET_HashCode))) && | ||
303 | (orig_seq_number == want->sequence_number) && | 289 | (orig_seq_number == want->sequence_number) && |
304 | (timestamp.abs_value >= want->timestamp.abs_value)) | 290 | (timestamp.abs_value >= want->timestamp.abs_value)) |
305 | { | 291 | { |
@@ -390,9 +376,8 @@ send_to_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
390 | alice_wanted.timestamp = GNUNET_TIME_absolute_get (); | 376 | alice_wanted.timestamp = GNUNET_TIME_absolute_get (); |
391 | alice_wanted.next_task = &disconnect_bob; | 377 | alice_wanted.next_task = &disconnect_bob; |
392 | alice_wanted.next_task_cls = NULL; | 378 | alice_wanted.next_task_cls = NULL; |
393 | GNUNET_CHAT_send_message (bob_room, | 379 | GNUNET_CHAT_send_message (bob_room, "Hi Alice!", GNUNET_CHAT_MSG_OPTION_NONE, |
394 | "Hi Alice!", | 380 | NULL, NULL); |
395 | GNUNET_CHAT_MSG_OPTION_NONE, NULL, NULL); | ||
396 | } | 381 | } |
397 | 382 | ||
398 | 383 | ||
@@ -476,11 +461,9 @@ join_bob_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
476 | bob_wanted.next_task_cls = NULL; | 461 | bob_wanted.next_task_cls = NULL; |
477 | is_ready = GNUNET_NO; | 462 | is_ready = GNUNET_NO; |
478 | bob_room = | 463 | bob_room = |
479 | GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta, | 464 | GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta, "test", |
480 | "test", -1, | 465 | -1, &join_cb, &bob_wanted, &receive_cb, |
481 | &join_cb, &bob_wanted, | 466 | &bob_wanted, &member_list_cb, &bob_wanted, |
482 | &receive_cb, &bob_wanted, | ||
483 | &member_list_cb, &bob_wanted, | ||
484 | &confirmation_cb, &bob_wanted, &bob); | 467 | &confirmation_cb, &bob_wanted, &bob); |
485 | if (NULL == bob_room) | 468 | if (NULL == bob_room) |
486 | { | 469 | { |
@@ -502,12 +485,10 @@ join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
502 | alice_wanted.next_task = &join_bob_task; | 485 | alice_wanted.next_task = &join_bob_task; |
503 | alice_wanted.next_task_cls = NULL; | 486 | alice_wanted.next_task_cls = NULL; |
504 | alice_room = | 487 | alice_room = |
505 | GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta, | 488 | GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta, "test", -1, &join_cb, |
506 | "test", -1, | 489 | &alice_wanted, &receive_cb, &alice_wanted, |
507 | &join_cb, &alice_wanted, | 490 | &member_list_cb, &alice_wanted, &confirmation_cb, |
508 | &receive_cb, &alice_wanted, | 491 | &alice_wanted, &alice); |
509 | &member_list_cb, &alice_wanted, | ||
510 | &confirmation_cb, &alice_wanted, &alice); | ||
511 | if (NULL == alice_room) | 492 | if (NULL == alice_room) |
512 | { | 493 | { |
513 | GNUNET_SCHEDULER_cancel (kill_task); | 494 | GNUNET_SCHEDULER_cancel (kill_task); |
@@ -518,9 +499,8 @@ join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
518 | 499 | ||
519 | 500 | ||
520 | static void | 501 | static void |
521 | run (void *cls, | 502 | run (void *cls, char *const *args, const char *cfgfile, |
522 | char *const *args, | 503 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
523 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
524 | { | 504 | { |
525 | if (is_p2p) | 505 | if (is_p2p) |
526 | { | 506 | { |
@@ -535,18 +515,15 @@ run (void *cls, | |||
535 | alice_wanted.me = "Alice"; | 515 | alice_wanted.me = "Alice"; |
536 | bob_wanted.me = "Bob"; | 516 | bob_wanted.me = "Bob"; |
537 | alice_meta = GNUNET_CONTAINER_meta_data_create (); | 517 | alice_meta = GNUNET_CONTAINER_meta_data_create (); |
538 | GNUNET_CONTAINER_meta_data_insert (alice_meta, | 518 | GNUNET_CONTAINER_meta_data_insert (alice_meta, "<gnunet>", |
539 | "<gnunet>", | ||
540 | EXTRACTOR_METATYPE_TITLE, | 519 | EXTRACTOR_METATYPE_TITLE, |
541 | EXTRACTOR_METAFORMAT_UTF8, | 520 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
542 | "text/plain", | ||
543 | "Alice", strlen ("Alice") + 1); | 521 | "Alice", strlen ("Alice") + 1); |
544 | bob_meta = GNUNET_CONTAINER_meta_data_create (); | 522 | bob_meta = GNUNET_CONTAINER_meta_data_create (); |
545 | GNUNET_CONTAINER_meta_data_insert (bob_meta, | 523 | GNUNET_CONTAINER_meta_data_insert (bob_meta, "<gnunet>", |
546 | "<gnunet>", | ||
547 | EXTRACTOR_METATYPE_TITLE, | 524 | EXTRACTOR_METATYPE_TITLE, |
548 | EXTRACTOR_METAFORMAT_UTF8, | 525 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
549 | "text/plain", "Bob", strlen ("Bob") + 1); | 526 | "Bob", strlen ("Bob") + 1); |
550 | kill_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill, NULL); | 527 | kill_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill, NULL); |
551 | GNUNET_SCHEDULER_add_now (&join_alice_task, NULL); | 528 | GNUNET_SCHEDULER_add_now (&join_alice_task, NULL); |
552 | } | 529 | } |
@@ -591,8 +568,8 @@ main (int argc, char *argv[]) | |||
591 | { | 568 | { |
592 | is_auth = GNUNET_YES; | 569 | is_auth = GNUNET_YES; |
593 | } | 570 | } |
594 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, | 571 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, |
595 | argvx, "test-chat", "nohelp", options, &run, NULL); | 572 | "test-chat", "nohelp", options, &run, NULL); |
596 | stop_arm (&p1); | 573 | stop_arm (&p1); |
597 | GNUNET_CONTAINER_meta_data_destroy (alice_meta); | 574 | GNUNET_CONTAINER_meta_data_destroy (alice_meta); |
598 | GNUNET_CONTAINER_meta_data_destroy (bob_meta); | 575 | GNUNET_CONTAINER_meta_data_destroy (bob_meta); |