aboutsummaryrefslogtreecommitdiff
path: root/src/chat/test_chat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/chat/test_chat.c')
-rw-r--r--src/chat/test_chat.c97
1 files changed, 33 insertions, 64 deletions
diff --git a/src/chat/test_chat.c b/src/chat/test_chat.c
index 24a1e38da..78b31f1b1 100644
--- a/src/chat/test_chat.c
+++ b/src/chat/test_chat.c
@@ -37,10 +37,6 @@
37#include "gnunet_arm_service.h" 37#include "gnunet_arm_service.h"
38#include "gnunet_chat_service.h" 38#include "gnunet_chat_service.h"
39 39
40#define VERBOSE GNUNET_NO
41
42#define START_ARM GNUNET_YES
43
44/** 40/**
45 * How long until we give up on passing the test? 41 * How long until we give up on passing the test?
46 */ 42 */
@@ -49,9 +45,7 @@
49struct PeerContext 45struct PeerContext
50{ 46{
51 struct GNUNET_CONFIGURATION_Handle *cfg; 47 struct GNUNET_CONFIGURATION_Handle *cfg;
52#if START_ARM
53 struct GNUNET_OS_Process *arm_proc; 48 struct GNUNET_OS_Process *arm_proc;
54#endif
55}; 49};
56 50
57struct Wanted 51struct Wanted
@@ -120,12 +114,10 @@ setup_peer (struct PeerContext *p, const char *cfgname)
120 114
121 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 115 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
122 p->cfg = GNUNET_CONFIGURATION_create (); 116 p->cfg = GNUNET_CONFIGURATION_create ();
123#if START_ARM
124 p->arm_proc = 117 p->arm_proc =
125 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, binary, 118 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, binary,
126 "gnunet-service-arm", 119 "gnunet-service-arm",
127 "-c", cfgname, NULL); 120 "-c", cfgname, NULL);
128#endif
129 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 121 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
130 GNUNET_free (binary); 122 GNUNET_free (binary);
131} 123}
@@ -134,7 +126,6 @@ setup_peer (struct PeerContext *p, const char *cfgname)
134static void 126static void
135stop_arm (struct PeerContext *p) 127stop_arm (struct PeerContext *p)
136{ 128{
137#if START_ARM
138 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 129 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
139 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 130 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
140 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 131 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
@@ -143,7 +134,6 @@ stop_arm (struct PeerContext *p)
143 GNUNET_OS_process_get_pid (p->arm_proc)); 134 GNUNET_OS_process_get_pid (p->arm_proc));
144 GNUNET_OS_process_destroy (p->arm_proc); 135 GNUNET_OS_process_destroy (p->arm_proc);
145 p->arm_proc = NULL; 136 p->arm_proc = NULL;
146#endif
147 GNUNET_CONFIGURATION_destroy (p->cfg); 137 GNUNET_CONFIGURATION_destroy (p->cfg);
148} 138}
149 139
@@ -168,9 +158,8 @@ abort_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
168static void 158static void
169timeout_kill (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 159timeout_kill (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
170{ 160{
171#if VERBOSE 161 fprintf (stderr,
172 printf ("Timed out, stopping the test.\n"); 162 "Timed out, stopping the test.\n");
173#endif
174 kill_task = GNUNET_SCHEDULER_NO_TASK; 163 kill_task = GNUNET_SCHEDULER_NO_TASK;
175 if (wait_task != GNUNET_SCHEDULER_NO_TASK) 164 if (wait_task != GNUNET_SCHEDULER_NO_TASK)
176 { 165 {
@@ -187,9 +176,8 @@ join_cb (void *cls)
187{ 176{
188 struct Wanted *want = cls; 177 struct Wanted *want = cls;
189 178
190#if VERBOSE 179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
191 printf ("%s has joined\n", want->me); 180 "%s has joined\n", want->me);
192#endif
193 if (NULL != want->next_task) 181 if (NULL != want->next_task)
194 GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls); 182 GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
195 return GNUNET_OK; 183 return GNUNET_OK;
@@ -204,13 +192,12 @@ member_list_cb (void *cls, const struct GNUNET_CONTAINER_MetaData *member_info,
204 struct Wanted *want = cls; 192 struct Wanted *want = cls;
205 struct GNUNET_HashCode sender; 193 struct GNUNET_HashCode sender;
206 194
207#if VERBOSE 195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
208 printf ("%s - told that %s has %s\n", want->me, 196 "%s - told that %s has %s\n", want->me,
209 member_info == 197 member_info ==
210 NULL ? NULL : GNUNET_CONTAINER_meta_data_get_by_type (member_info, 198 NULL ? NULL : GNUNET_CONTAINER_meta_data_get_by_type (member_info,
211 EXTRACTOR_METATYPE_TITLE), 199 EXTRACTOR_METATYPE_TITLE),
212 member_info == NULL ? "left" : "joined"); 200 member_info == NULL ? "left" : "joined");
213#endif
214 GNUNET_CRYPTO_hash (member_id, 201 GNUNET_CRYPTO_hash (member_id,
215 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 202 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
216 &sender); 203 &sender);
@@ -242,12 +229,12 @@ receive_cb (void *cls, struct GNUNET_CHAT_Room *room,
242{ 229{
243 struct Wanted *want = cls; 230 struct Wanted *want = cls;
244 231
245#if VERBOSE 232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
246 printf ("%s - told that %s said %s\n", want->me, 233
247 meta == NULL ? NULL : GNUNET_CONTAINER_meta_data_get_by_type (meta, 234 "%s - told that %s said %s\n", want->me,
248 EXTRACTOR_METATYPE_TITLE), 235 meta == NULL ? NULL : GNUNET_CONTAINER_meta_data_get_by_type (meta,
249 message); 236 EXTRACTOR_METATYPE_TITLE),
250#endif 237 message);
251 if ((0 == strcmp (message, want->msg)) && 238 if ((0 == strcmp (message, want->msg)) &&
252 (((sender == NULL) && (want->sender == NULL)) || 239 (((sender == NULL) && (want->sender == NULL)) ||
253 ((sender != NULL) && (want->sender != NULL) && 240 ((sender != NULL) && (want->sender != NULL) &&
@@ -280,12 +267,11 @@ confirmation_cb (void *cls, struct GNUNET_CHAT_Room *room,
280{ 267{
281 struct Wanted *want = cls; 268 struct Wanted *want = cls;
282 269
283#if VERBOSE 270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
284 printf ("%s - told that %s acknowledged message #%d\n", want->me, 271 "%s - told that %s acknowledged message #%d\n", want->me,
285 GNUNET_CONTAINER_meta_data_get_by_type (want->meta, 272 GNUNET_CONTAINER_meta_data_get_by_type (want->meta,
286 EXTRACTOR_METATYPE_TITLE), 273 EXTRACTOR_METATYPE_TITLE),
287 orig_seq_number); 274 orig_seq_number);
288#endif
289 if ((0 == memcmp (receiver, want->sender, sizeof (struct GNUNET_HashCode))) && 275 if ((0 == memcmp (receiver, want->sender, sizeof (struct GNUNET_HashCode))) &&
290 (orig_seq_number == want->sequence_number) && 276 (orig_seq_number == want->sequence_number) &&
291 (timestamp.abs_value >= want->timestamp.abs_value)) 277 (timestamp.abs_value >= want->timestamp.abs_value))
@@ -308,9 +294,6 @@ wait_until_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
308{ 294{
309 GNUNET_SCHEDULER_Task task = cls; 295 GNUNET_SCHEDULER_Task task = cls;
310 296
311#if VERBOSE
312 printf ("Waiting...\n");
313#endif
314 if (is_ready) 297 if (is_ready)
315 { 298 {
316 wait_task = GNUNET_SCHEDULER_NO_TASK; 299 wait_task = GNUNET_SCHEDULER_NO_TASK;
@@ -327,9 +310,8 @@ wait_until_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
327static void 310static void
328disconnect_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 311disconnect_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
329{ 312{
330#if VERBOSE 313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
331 printf ("Alice is leaving.\n"); 314 "Alice is leaving.\n");
332#endif
333 if (is_p2p) 315 if (is_p2p)
334 stop_arm (&p2); 316 stop_arm (&p2);
335 GNUNET_CHAT_leave_room (alice_room); 317 GNUNET_CHAT_leave_room (alice_room);
@@ -342,9 +324,8 @@ disconnect_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
342static void 324static void
343disconnect_bob (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 325disconnect_bob (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
344{ 326{
345#if VERBOSE 327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
346 printf ("Bod is leaving.\n"); 328 "Bob is leaving.\n");
347#endif
348 alice_wanted.meta = NULL; 329 alice_wanted.meta = NULL;
349 alice_wanted.sender = &bob; 330 alice_wanted.sender = &bob;
350 alice_wanted.msg = NULL; 331 alice_wanted.msg = NULL;
@@ -366,10 +347,8 @@ set_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
366static void 347static void
367send_to_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 348send_to_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
368{ 349{
369#if VERBOSE 350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
370 printf ("Bob says 'Hi!'\n"); 351 "Bob says 'Hi!'\n");
371#endif
372
373 alice_wanted.meta = bob_meta; 352 alice_wanted.meta = bob_meta;
374 alice_wanted.sender = &bob; 353 alice_wanted.sender = &bob;
375 alice_wanted.msg = "Hi Alice!"; 354 alice_wanted.msg = "Hi Alice!";
@@ -388,9 +367,8 @@ send_to_bob (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
388 enum GNUNET_CHAT_MsgOptions options; 367 enum GNUNET_CHAT_MsgOptions options;
389 uint32_t *seq = NULL; 368 uint32_t *seq = NULL;
390 369
391#if VERBOSE 370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
392 printf ("Alice says 'Hi!'\n"); 371 "Alice says 'Hi!'\n");
393#endif
394 if (is_ackn) 372 if (is_ackn)
395 { 373 {
396 options = GNUNET_CHAT_MSG_ACKNOWLEDGED; 374 options = GNUNET_CHAT_MSG_ACKNOWLEDGED;
@@ -449,9 +427,8 @@ prepare_for_alice_task (void *cls,
449static void 427static void
450join_bob_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 428join_bob_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
451{ 429{
452#if VERBOSE 430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
453 printf ("Bob joining\n"); 431 "Bob joining\n");
454#endif
455 alice_wanted.meta = bob_meta; 432 alice_wanted.meta = bob_meta;
456 alice_wanted.sender = &bob; 433 alice_wanted.sender = &bob;
457 alice_wanted.msg = NULL; 434 alice_wanted.msg = NULL;
@@ -480,9 +457,8 @@ join_bob_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
480static void 457static void
481join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 458join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
482{ 459{
483#if VERBOSE 460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
484 printf ("Alice joining\n"); 461 "Alice joining\n");
485#endif
486 alice_wanted.next_task = &join_bob_task; 462 alice_wanted.next_task = &join_bob_task;
487 alice_wanted.next_task_cls = NULL; 463 alice_wanted.next_task_cls = NULL;
488 alice_room = 464 alice_room =
@@ -537,9 +513,6 @@ main (int argc, char *argv[])
537 "test-chat", 513 "test-chat",
538 "-c", 514 "-c",
539 "test_chat_data.conf", 515 "test_chat_data.conf",
540#if VERBOSE
541 "-L", "DEBUG",
542#endif
543 NULL 516 NULL
544 }; 517 };
545 struct GNUNET_GETOPT_CommandLineOption options[] = { 518 struct GNUNET_GETOPT_CommandLineOption options[] = {
@@ -547,11 +520,7 @@ main (int argc, char *argv[])
547 }; 520 };
548 521
549 GNUNET_log_setup ("test_chat", 522 GNUNET_log_setup ("test_chat",
550#if VERBOSE
551 "DEBUG",
552#else
553 "WARNING", 523 "WARNING",
554#endif
555 NULL); 524 NULL);
556 if (strstr (argv[0], "p2p") != NULL) 525 if (strstr (argv[0], "p2p") != NULL)
557 { 526 {