aboutsummaryrefslogtreecommitdiff
path: root/src/chat
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-02-15 15:31:09 +0000
committerChristian Grothoff <christian@grothoff.org>2011-02-15 15:31:09 +0000
commitf35db2c258aa7bc869473de13085bfaca9520ab9 (patch)
treea9458ce6f3b1cb3efe44e8fca2e56a3bbcb913d1 /src/chat
parent38d121662a466fd857e2da150833522d36130c52 (diff)
downloadgnunet-f35db2c258aa7bc869473de13085bfaca9520ab9.tar.gz
gnunet-f35db2c258aa7bc869473de13085bfaca9520ab9.zip
oops
Diffstat (limited to 'src/chat')
-rw-r--r--src/chat/test_chat.c630
-rw-r--r--src/chat/test_chat_data.conf37
-rw-r--r--src/chat/test_chat_peer1.conf72
-rw-r--r--src/chat/test_chat_peer2.conf72
-rw-r--r--src/chat/test_chat_peer3.conf72
-rw-r--r--src/chat/test_chat_private.c693
6 files changed, 1576 insertions, 0 deletions
diff --git a/src/chat/test_chat.c b/src/chat/test_chat.c
new file mode 100644
index 000000000..8b96e6a58
--- /dev/null
+++ b/src/chat/test_chat.c
@@ -0,0 +1,630 @@
1/*
2 This file is part of GNUnet.
3 (C) 2005, 2006, 2007, 2008, 2011 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file chat/test_chat.c
23 * @brief base test case for the chat library
24 * @author Christian Grothoff
25 * @author Nathan Evans
26 * @author Vitaly Minko
27 *
28 * This test case serves as a base for simple chatting, anonymous chatting,
29 * authenticated chatting and acknowledgements test cases. Based on the
30 * executable being run the correct test case will be performed. Private
31 * chatting is covered by a separate test case since it requires 3 users.
32 */
33
34#include "platform.h"
35#include "gnunet_crypto_lib.h"
36#include "gnunet_util_lib.h"
37#include "gnunet_arm_service.h"
38#include "gnunet_chat_service.h"
39
40#define VERBOSE GNUNET_NO
41
42#define START_ARM GNUNET_YES
43
44/**
45 * How long until we give up on passing the test?
46 */
47#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
48
49struct PeerContext
50{
51 struct GNUNET_CONFIGURATION_Handle *cfg;
52#if START_ARM
53 struct GNUNET_OS_Process *arm_proc;
54#endif
55};
56
57struct Wanted
58{
59 struct GNUNET_CONTAINER_MetaData *meta;
60
61 GNUNET_HashCode *sender;
62
63 char *msg;
64
65 const char *me;
66
67 enum GNUNET_CHAT_MsgOptions opt;
68
69 uint32_t sequence_number;
70
71 struct GNUNET_TIME_Absolute timestamp;
72
73 GNUNET_SCHEDULER_Task next_task;
74
75 void *next_task_cls;
76
77};
78
79static struct PeerContext p1;
80
81static struct PeerContext p2;
82
83static GNUNET_HashCode alice;
84
85static GNUNET_HashCode bob;
86
87static struct GNUNET_CHAT_Room *alice_room;
88
89static struct GNUNET_CHAT_Room *bob_room;
90
91static struct GNUNET_CONTAINER_MetaData *alice_meta;
92
93static struct GNUNET_CONTAINER_MetaData *bob_meta;
94
95static struct Wanted alice_wanted;
96
97static struct Wanted bob_wanted;
98
99static GNUNET_SCHEDULER_TaskIdentifier kill_task;
100
101static GNUNET_SCHEDULER_TaskIdentifier wait_task;
102
103static int err;
104
105static int is_ready;
106
107static int is_p2p;
108
109static int is_ackn;
110
111static int is_anon;
112
113static int is_auth;
114
115
116static void
117setup_peer (struct PeerContext *p, const char *cfgname)
118{
119 p->cfg = GNUNET_CONFIGURATION_create ();
120#if START_ARM
121 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
122 "gnunet-service-arm",
123#if VERBOSE
124 "-L", "DEBUG",
125#endif
126 "-c", cfgname, NULL);
127#endif
128 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
129}
130
131
132static void
133stop_arm (struct PeerContext *p)
134{
135#if START_ARM
136 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
137 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
138 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
139 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
141 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc));
142 GNUNET_OS_process_close (p->arm_proc);
143 p->arm_proc = NULL;
144#endif
145 GNUNET_CONFIGURATION_destroy (p->cfg);
146}
147
148
149static void
150abort_test (void *cls,
151 const struct GNUNET_SCHEDULER_TaskContext *tc)
152{
153 if (alice_room != NULL)
154 {
155 GNUNET_CHAT_leave_room (alice_room);
156 alice_room = NULL;
157 }
158 if (bob_room != NULL)
159 {
160 GNUNET_CHAT_leave_room (bob_room);
161 bob_room = NULL;
162 }
163 err = 1;
164}
165
166
167static void
168timeout_kill (void *cls,
169 const struct GNUNET_SCHEDULER_TaskContext *tc)
170{
171#if VERBOSE
172 printf ("Timed out, stopping the test.\n");
173#endif
174 kill_task = GNUNET_SCHEDULER_NO_TASK;
175 if (wait_task != GNUNET_SCHEDULER_NO_TASK)
176 {
177 GNUNET_SCHEDULER_cancel (wait_task);
178 wait_task = GNUNET_SCHEDULER_NO_TASK;
179 }
180 GNUNET_SCHEDULER_add_continuation (&abort_test, NULL,
181 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
182}
183
184
185static int
186join_cb (void *cls)
187{
188 struct Wanted *want = cls;
189
190#if VERBOSE
191 printf ("%s has joined\n", want->me);
192#endif
193 if (NULL != want->next_task)
194 GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
195 return GNUNET_OK;
196}
197
198
199static int
200member_list_cb (void *cls,
201 const struct GNUNET_CONTAINER_MetaData *member_info,
202 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id,
203 enum GNUNET_CHAT_MsgOptions options)
204{
205 struct Wanted *want = cls;
206 GNUNET_HashCode sender;
207
208#if VERBOSE
209 printf ("%s - told that %s has %s\n",
210 want->me,
211 member_info == NULL ? NULL
212 : GNUNET_CONTAINER_meta_data_get_by_type (member_info,
213 EXTRACTOR_METATYPE_TITLE),
214 member_info == NULL ? "left" : "joined");
215#endif
216 GNUNET_CRYPTO_hash (member_id,
217 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
218 &sender);
219 if ((0 == memcmp (&sender, want->sender,
220 sizeof (GNUNET_HashCode))) &&
221 (((member_info == NULL) &&
222 (want->meta == NULL)) ||
223 ((member_info != NULL) &&
224 (want->meta != NULL) &&
225 (GNUNET_CONTAINER_meta_data_test_equal (member_info,
226 want->meta)))) &&
227 (options == want->opt))
228 {
229 if (NULL != want->next_task)
230 GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
231 }
232 else
233 {
234 GNUNET_SCHEDULER_cancel (kill_task);
235 kill_task = GNUNET_SCHEDULER_NO_TASK;
236 GNUNET_SCHEDULER_add_now (&abort_test, NULL);
237 }
238 return GNUNET_OK;
239}
240
241
242static int
243receive_cb (void *cls,
244 struct GNUNET_CHAT_Room *room,
245 const GNUNET_HashCode *sender,
246 const struct GNUNET_CONTAINER_MetaData *meta,
247 const char *message,
248 struct GNUNET_TIME_Absolute timestamp,
249 enum GNUNET_CHAT_MsgOptions options)
250{
251 struct Wanted *want = cls;
252
253#if VERBOSE
254 printf ("%s - told that %s said %s\n",
255 want->me,
256 meta == NULL ? NULL
257 : GNUNET_CONTAINER_meta_data_get_by_type (meta,
258 EXTRACTOR_METATYPE_TITLE),
259 message);
260#endif
261 if ((0 == strcmp (message, want->msg)) &&
262 (((sender == NULL) && (want->sender == NULL)) ||
263 ((sender != NULL) && (want->sender != NULL) &&
264 (0 == memcmp (sender, want->sender,
265 sizeof (GNUNET_HashCode))))) &&
266 (GNUNET_CONTAINER_meta_data_test_equal (meta, want->meta)) &&
267 (options == want->opt) &&
268 /* Not == since the library sets the actual timestamp, so it may be
269 * slightly greater
270 */
271 (timestamp.abs_value >= want->timestamp.abs_value))
272 {
273 if (NULL != want->next_task)
274 GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
275 }
276 else
277 {
278 GNUNET_SCHEDULER_cancel (kill_task);
279 kill_task = GNUNET_SCHEDULER_NO_TASK;
280 GNUNET_SCHEDULER_add_now (&abort_test, NULL);
281 }
282 return GNUNET_OK;
283}
284
285
286static int
287confirmation_cb (void *cls,
288 struct GNUNET_CHAT_Room *room,
289 uint32_t orig_seq_number,
290 struct GNUNET_TIME_Absolute timestamp,
291 const GNUNET_HashCode *receiver)
292{
293 struct Wanted *want = cls;
294
295#if VERBOSE
296 printf ("%s - told that %s acknowledged message #%d\n",
297 want->me,
298 GNUNET_CONTAINER_meta_data_get_by_type (want->meta,
299 EXTRACTOR_METATYPE_TITLE),
300 orig_seq_number);
301#endif
302 if ((0 == memcmp (receiver, want->sender,
303 sizeof (GNUNET_HashCode))) &&
304 (orig_seq_number == want->sequence_number) &&
305 (timestamp.abs_value >= want->timestamp.abs_value))
306 {
307 if (NULL != want->next_task)
308 GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
309 }
310 else
311 {
312 GNUNET_SCHEDULER_cancel (kill_task);
313 kill_task = GNUNET_SCHEDULER_NO_TASK;
314 GNUNET_SCHEDULER_add_now (&abort_test, NULL);
315 }
316 return GNUNET_OK;
317}
318
319
320static void
321wait_until_ready (void *cls,
322 const struct GNUNET_SCHEDULER_TaskContext *tc)
323{
324 GNUNET_SCHEDULER_Task task = cls;
325
326#if VERBOSE
327 printf ("Waiting...\n");
328#endif
329 if (is_ready)
330 {
331 wait_task = GNUNET_SCHEDULER_NO_TASK;
332 GNUNET_SCHEDULER_add_now (task, NULL);
333 }
334 else
335 wait_task =
336 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
337 50),
338 &wait_until_ready,
339 task);
340}
341
342
343static void
344disconnect_alice (void *cls,
345 const struct GNUNET_SCHEDULER_TaskContext *tc)
346{
347#if VERBOSE
348 printf ("Alice is leaving.\n");
349#endif
350 if (is_p2p)
351 stop_arm (&p2);
352 GNUNET_CHAT_leave_room (alice_room);
353 alice_room = NULL;
354 GNUNET_SCHEDULER_cancel (kill_task);
355 kill_task = GNUNET_SCHEDULER_NO_TASK;
356}
357
358
359static void
360disconnect_bob (void *cls,
361 const struct GNUNET_SCHEDULER_TaskContext *tc)
362{
363#if VERBOSE
364 printf ("Bod is leaving.\n");
365#endif
366 alice_wanted.meta = NULL;
367 alice_wanted.sender = &bob;
368 alice_wanted.msg = NULL;
369 alice_wanted.opt = 0;
370 alice_wanted.next_task = &disconnect_alice;
371 alice_wanted.next_task_cls = NULL;
372 GNUNET_CHAT_leave_room (bob_room);
373 bob_room = NULL;
374}
375
376
377static void
378set_ready (void *cls,
379 const struct GNUNET_SCHEDULER_TaskContext *tc)
380{
381 is_ready = GNUNET_YES;
382}
383
384
385static void
386send_to_alice (void *cls,
387 const struct GNUNET_SCHEDULER_TaskContext *tc)
388{
389#if VERBOSE
390 printf ("Bob says 'Hi!'\n");
391#endif
392
393 alice_wanted.meta = bob_meta;
394 alice_wanted.sender = &bob;
395 alice_wanted.msg = "Hi Alice!";
396 alice_wanted.opt = GNUNET_CHAT_MSG_OPTION_NONE;
397 alice_wanted.timestamp = GNUNET_TIME_absolute_get ();
398 alice_wanted.next_task = &disconnect_bob;
399 alice_wanted.next_task_cls = NULL;
400 GNUNET_CHAT_send_message (bob_room,
401 "Hi Alice!",
402 GNUNET_CHAT_MSG_OPTION_NONE,
403 NULL,
404 NULL);
405}
406
407
408static void
409send_to_bob (void *cls,
410 const struct GNUNET_SCHEDULER_TaskContext *tc)
411{
412 enum GNUNET_CHAT_MsgOptions options;
413 uint32_t *seq = NULL;
414
415#if VERBOSE
416 printf ("Alice says 'Hi!'\n");
417#endif
418 if (is_ackn)
419 {
420 options = GNUNET_CHAT_MSG_ACKNOWLEDGED;
421 alice_wanted.meta = bob_meta;
422 alice_wanted.sender = &bob;
423 alice_wanted.timestamp = GNUNET_TIME_absolute_get ();
424 alice_wanted.next_task = &disconnect_bob;
425 alice_wanted.next_task_cls = NULL;
426 bob_wanted.meta = alice_meta;
427 bob_wanted.sender = &alice;
428 bob_wanted.next_task = NULL;
429 seq = &(alice_wanted.sequence_number);
430 }
431 else if (is_anon)
432 {
433 options = GNUNET_CHAT_MSG_ANONYMOUS;
434 bob_wanted.meta = NULL;
435 bob_wanted.sender = NULL;
436 bob_wanted.next_task = &disconnect_bob;
437 }
438 else if (is_auth)
439 {
440 options = GNUNET_CHAT_MSG_AUTHENTICATED;
441 bob_wanted.meta = alice_meta;
442 bob_wanted.sender = &alice;
443 bob_wanted.next_task = &disconnect_bob;
444 }
445 else
446 {
447 options = GNUNET_CHAT_MSG_OPTION_NONE;
448 bob_wanted.meta = alice_meta;
449 bob_wanted.sender = &alice;
450 bob_wanted.next_task = &send_to_alice;
451 }
452 bob_wanted.msg = "Hi Bob!";
453 bob_wanted.opt = options;
454 bob_wanted.timestamp = GNUNET_TIME_absolute_get ();
455 bob_wanted.next_task_cls = NULL;
456 GNUNET_CHAT_send_message (alice_room, "Hi Bob!", options, NULL, seq);
457}
458
459
460static void
461prepare_for_alice_task (void *cls,
462 const struct GNUNET_SCHEDULER_TaskContext *tc)
463{
464 bob_wanted.meta = alice_meta;
465 bob_wanted.sender = &alice;
466 bob_wanted.msg = NULL;
467 bob_wanted.opt = -1;
468 bob_wanted.next_task = &set_ready;
469 bob_wanted.next_task_cls = NULL;
470}
471
472
473static void
474join_bob_task (void *cls,
475 const struct GNUNET_SCHEDULER_TaskContext *tc)
476{
477#if VERBOSE
478 printf ("Bob joining\n");
479#endif
480 alice_wanted.meta = bob_meta;
481 alice_wanted.sender = &bob;
482 alice_wanted.msg = NULL;
483 alice_wanted.opt = -1;
484 alice_wanted.next_task = &wait_until_ready;
485 alice_wanted.next_task_cls = &send_to_bob;
486 bob_wanted.next_task = &prepare_for_alice_task;
487 bob_wanted.next_task_cls = NULL;
488 is_ready = GNUNET_NO;
489 bob_room =
490 GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta,
491 "test", -1,
492 &join_cb, &bob_wanted,
493 &receive_cb, &bob_wanted,
494 &member_list_cb, &bob_wanted,
495 &confirmation_cb, &bob_wanted,
496 &bob);
497 if (NULL == bob_room)
498 {
499 GNUNET_SCHEDULER_cancel (kill_task);
500 kill_task = GNUNET_SCHEDULER_NO_TASK;
501 GNUNET_CHAT_leave_room (alice_room);
502 alice_room = NULL;
503 err = 1;
504 }
505}
506
507
508static void
509join_alice_task (void *cls,
510 const struct GNUNET_SCHEDULER_TaskContext *tc)
511{
512#if VERBOSE
513 printf ("Alice joining\n");
514#endif
515 alice_wanted.next_task = &join_bob_task;
516 alice_wanted.next_task_cls = NULL;
517 alice_room =
518 GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta,
519 "test", -1,
520 &join_cb, &alice_wanted,
521 &receive_cb, &alice_wanted,
522 &member_list_cb, &alice_wanted,
523 &confirmation_cb, &alice_wanted,
524 &alice);
525 if (NULL == alice_room)
526 {
527 GNUNET_SCHEDULER_cancel (kill_task);
528 kill_task = GNUNET_SCHEDULER_NO_TASK;
529 err = 1;
530 }
531}
532
533
534static void
535run (void *cls,
536 char *const *args,
537 const char *cfgfile,
538 const struct GNUNET_CONFIGURATION_Handle *cfg)
539{
540 if (is_p2p)
541 {
542 setup_peer (&p1, "test_chat_peer1.conf");
543 setup_peer (&p2, "test_chat_peer2.conf");
544 }
545 else
546 setup_peer (&p1, "test_chat_data.conf");
547
548 memset (&alice_wanted, 0, sizeof (struct Wanted));
549 memset (&bob_wanted, 0, sizeof (struct Wanted));
550 alice_wanted.me = "Alice";
551 bob_wanted.me = "Bob";
552 alice_meta = GNUNET_CONTAINER_meta_data_create ();
553 GNUNET_CONTAINER_meta_data_insert (alice_meta,
554 "<gnunet>",
555 EXTRACTOR_METATYPE_TITLE,
556 EXTRACTOR_METAFORMAT_UTF8,
557 "text/plain",
558 "Alice",
559 strlen("Alice")+1);
560 bob_meta = GNUNET_CONTAINER_meta_data_create ();
561 GNUNET_CONTAINER_meta_data_insert (bob_meta,
562 "<gnunet>",
563 EXTRACTOR_METATYPE_TITLE,
564 EXTRACTOR_METAFORMAT_UTF8,
565 "text/plain",
566 "Bob",
567 strlen("Bob")+1);
568 kill_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
569 &timeout_kill,
570 NULL);
571 GNUNET_SCHEDULER_add_now (&join_alice_task, NULL);
572}
573
574
575int
576main (int argc, char *argv[])
577{
578 char *const argvx[] = {
579 "test-chat",
580 "-c",
581 "test_chat_data.conf",
582#if VERBOSE
583 "-L", "DEBUG",
584#endif
585 NULL
586 };
587 struct GNUNET_GETOPT_CommandLineOption options[] = {
588 GNUNET_GETOPT_OPTION_END
589 };
590
591 GNUNET_log_setup ("test_chat",
592#if VERBOSE
593 "DEBUG",
594#else
595 "WARNING",
596#endif
597 NULL);
598 if (strstr(argv[0], "p2p") != NULL)
599 {
600 is_p2p = GNUNET_YES;
601 }
602 if (strstr(argv[0], "acknowledgment") != NULL)
603 {
604 is_ackn = GNUNET_YES;
605 }
606 else if (strstr(argv[0], "anonymous") != NULL)
607 {
608 is_anon = GNUNET_YES;
609 }
610 else if (strstr(argv[0], "authentication") != NULL)
611 {
612 is_auth = GNUNET_YES;
613 }
614 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
615 argvx, "test-chat",
616 "nohelp", options, &run, NULL);
617 stop_arm (&p1);
618 GNUNET_CONTAINER_meta_data_destroy (alice_meta);
619 GNUNET_CONTAINER_meta_data_destroy (bob_meta);
620 if (is_p2p)
621 {
622 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/");
623 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/");
624 }
625 else
626 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat/");
627 return err;
628}
629
630/* end of test_chat.c */
diff --git a/src/chat/test_chat_data.conf b/src/chat/test_chat_data.conf
new file mode 100644
index 000000000..ec554d05e
--- /dev/null
+++ b/src/chat/test_chat_data.conf
@@ -0,0 +1,37 @@
1[PATHS]
2SERVICEHOME = /tmp/gnunet-test-chat/
3DEFAULTCONFIG = test_chat_data.conf
4
5[gnunetd]
6HOSTKEY = $SERVICEHOME/.hostkey
7
8[resolver]
9PORT = 42464
10HOSTNAME = localhost
11
12[transport]
13PORT = 42465
14PLUGINS =
15
16[arm]
17PORT = 42466
18HOSTNAME = localhost
19DEFAULTSERVICES = core chat
20
21[peerinfo]
22PORT = 42469
23HOSTNAME = localhost
24
25[core]
26PORT = 42470
27HOSTNAME = localhost
28
29[chat]
30PORT = 42471
31HOSTNAME = localhost
32HOME = $SERVICEHOME
33CONFIG = $DEFAULTCONFIG
34BINARY = gnunet-service-chat
35
36[testing]
37WEAKRANDOM = YES
diff --git a/src/chat/test_chat_peer1.conf b/src/chat/test_chat_peer1.conf
new file mode 100644
index 000000000..f9c9637c2
--- /dev/null
+++ b/src/chat/test_chat_peer1.conf
@@ -0,0 +1,72 @@
1[PATHS]
2SERVICEHOME = /tmp/gnunet-test-chat-peer-1/
3DEFAULTCONFIG = test_chat_peer1.conf
4
5[gnunetd]
6HOSTKEY = $SERVICEHOME/.hostkey
7
8[hostlist]
9HTTPPORT = 31000
10OPTIONS = -p
11
12[resolver]
13PORT = 31001
14HOSTNAME = localhost
15UNIXPATH = /tmp/gnunet-chat-p1-service-resolver.sock
16
17[transport]
18PORT = 31002
19UNIXPATH = /tmp/gnunet-chat-p1-service-transport.sock
20PLUGINS = tcp
21
22[transport-tcp]
23PORT = 31003
24
25[arm]
26PORT = 31004
27UNIXPATH = /tmp/gnunet-chat-p1-service-arm.sock
28HOSTNAME = localhost
29DEFAULTSERVICES = resolver transport core topology hostlist statistics chat
30
31[core]
32PORT = 31005
33UNIXPATH = /tmp/gnunet-chat-p1-service-core.sock
34HOSTNAME = localhost
35
36[topology]
37MINIMUM-FRIENDS = 0
38FRIENDS-ONLY = NO
39AUTOCONNECT = YES
40TARGET-CONNECTION-COUNT = 16
41FRIENDS = $SERVICEHOME/friends
42CONFIG = $DEFAULTCONFIG
43BINARY = gnunet-daemon-topology
44
45[peerinfo]
46PORT = 31006
47UNIXPATH = /tmp/gnunet-chat-p1-service-peerinfo.sock
48HOSTNAME = localhost
49
50[statistics]
51PORT = 31007
52HOSTNAME = localhost
53UNIXPATH = /tmp/gnunet-chat-p1-service-statistics.sock
54
55[chat]
56PORT = 31008
57HOSTNAME = localhost
58HOME = $SERVICEHOME
59CONFIG = $DEFAULTCONFIG
60BINARY = gnunet-service-chat
61
62[testing]
63WEAKRANDOM = YES
64
65[fs]
66AUTOSTART = NO
67
68[datastore]
69AUTOSTART = NO
70
71[dht]
72AUTOSTART = NO
diff --git a/src/chat/test_chat_peer2.conf b/src/chat/test_chat_peer2.conf
new file mode 100644
index 000000000..3f8551406
--- /dev/null
+++ b/src/chat/test_chat_peer2.conf
@@ -0,0 +1,72 @@
1[PATHS]
2SERVICEHOME = /tmp/gnunet-test-chat-peer-2/
3DEFAULTCONFIG = test_chat_peer2.conf
4
5[gnunetd]
6HOSTKEY = $SERVICEHOME/.hostkey
7
8[hostlist]
9SERVERS = http://localhost:31000/
10OPTIONS = -b
11
12[resolver]
13PORT = 32001
14HOSTNAME = localhost
15UNIXPATH = /tmp/gnunet-chat-p2-service-resolver.sock
16
17[transport]
18PORT = 32002
19UNIXPATH = /tmp/gnunet-chat-p2-service-transport.sock
20PLUGINS = tcp
21
22[transport-tcp]
23PORT = 32003
24
25[arm]
26PORT = 32004
27UNIXPATH = /tmp/gnunet-chat-p2-service-arm.sock
28HOSTNAME = localhost
29DEFAULTSERVICES = resolver transport core topology hostlist statistics chat
30
31[core]
32PORT = 32005
33UNIXPATH = /tmp/gnunet-chat-p2-service-core.sock
34HOSTNAME = localhost
35
36[topology]
37MINIMUM-FRIENDS = 0
38FRIENDS-ONLY = NO
39AUTOCONNECT = YES
40TARGET-CONNECTION-COUNT = 16
41FRIENDS = $SERVICEHOME/friends
42CONFIG = $DEFAULTCONFIG
43BINARY = gnunet-daemon-topology
44
45[peerinfo]
46PORT = 32006
47UNIXPATH = /tmp/gnunet-chat-p2-service-peerinfo.sock
48HOSTNAME = localhost
49
50[statistics]
51PORT = 32007
52HOSTNAME = localhost
53UNIXPATH = /tmp/gnunet-chat-p2-service-statistics.sock
54
55[chat]
56PORT = 32008
57HOSTNAME = localhost
58HOME = $SERVICEHOME
59CONFIG = $DEFAULTCONFIG
60BINARY = gnunet-service-chat
61
62[testing]
63WEAKRANDOM = YES
64
65[fs]
66AUTOSTART = NO
67
68[datastore]
69AUTOSTART = NO
70
71[dht]
72AUTOSTART = NO
diff --git a/src/chat/test_chat_peer3.conf b/src/chat/test_chat_peer3.conf
new file mode 100644
index 000000000..127df72c7
--- /dev/null
+++ b/src/chat/test_chat_peer3.conf
@@ -0,0 +1,72 @@
1[PATHS]
2SERVICEHOME = /tmp/gnunet-test-chat-peer-3/
3DEFAULTCONFIG = test_chat_peer3.conf
4
5[gnunetd]
6HOSTKEY = $SERVICEHOME/.hostkey
7
8[hostlist]
9SERVERS = http://localhost:31000/
10OPTIONS = -b
11
12[resolver]
13PORT = 33001
14HOSTNAME = localhost
15UNIXPATH = /tmp/gnunet-chat-p3-service-resolver.sock
16
17[transport]
18PORT = 33002
19UNIXPATH = /tmp/gnunet-chat-p3-service-transport.sock
20PLUGINS = tcp
21
22[transport-tcp]
23PORT = 33003
24
25[arm]
26PORT = 33004
27UNIXPATH = /tmp/gnunet-chat-p3-service-arm.sock
28HOSTNAME = localhost
29DEFAULTSERVICES = resolver transport core topology hostlist statistics chat
30
31[core]
32PORT = 33005
33UNIXPATH = /tmp/gnunet-chat-p3-service-core.sock
34HOSTNAME = localhost
35
36[topology]
37MINIMUM-FRIENDS = 0
38FRIENDS-ONLY = NO
39AUTOCONNECT = YES
40TARGET-CONNECTION-COUNT = 16
41FRIENDS = $SERVICEHOME/friends
42CONFIG = $DEFAULTCONFIG
43BINARY = gnunet-daemon-topology
44
45[peerinfo]
46PORT = 33006
47UNIXPATH = /tmp/gnunet-chat-p3-service-peerinfo.sock
48HOSTNAME = localhost
49
50[statistics]
51PORT = 33007
52HOSTNAME = localhost
53UNIXPATH = /tmp/gnunet-chat-p3-service-statistics.sock
54
55[chat]
56PORT = 33008
57HOSTNAME = localhost
58HOME = $SERVICEHOME
59CONFIG = $DEFAULTCONFIG
60BINARY = gnunet-service-chat
61
62[testing]
63WEAKRANDOM = YES
64
65[fs]
66AUTOSTART = NO
67
68[datastore]
69AUTOSTART = NO
70
71[dht]
72AUTOSTART = NO
diff --git a/src/chat/test_chat_private.c b/src/chat/test_chat_private.c
new file mode 100644
index 000000000..7649bffe4
--- /dev/null
+++ b/src/chat/test_chat_private.c
@@ -0,0 +1,693 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file chat/test_chat_private.c
23 * @brief testcase for private chatting
24 * @author Vitaly Minko
25 */
26
27#include "platform.h"
28#include "gnunet_crypto_lib.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_arm_service.h"
31#include "gnunet_chat_service.h"
32
33#define VERBOSE GNUNET_NO
34
35#define START_ARM GNUNET_YES
36
37/**
38 * How long until we give up on passing the test?
39 */
40#define KILL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
41
42/**
43 * How long until we give up on receiving somebody else's private message?
44 */
45#define PM_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
46
47struct PeerContext
48{
49 struct GNUNET_CONFIGURATION_Handle *cfg;
50#if START_ARM
51 struct GNUNET_OS_Process *arm_proc;
52#endif
53};
54
55struct Wanted
56{
57 struct GNUNET_CONTAINER_MetaData *meta;
58
59 GNUNET_HashCode *sender;
60
61 /**
62 * Alternative meta/sender is used when we expect join/leave notification
63 * from two peers and don't know which one will come first.
64 */
65 struct GNUNET_CONTAINER_MetaData *meta2;
66
67 GNUNET_HashCode *sender2;
68
69 char *msg;
70
71 const char *me;
72
73 enum GNUNET_CHAT_MsgOptions opt;
74
75 struct GNUNET_TIME_Absolute timestamp;
76
77 GNUNET_SCHEDULER_Task next_task;
78
79 void *next_task_cls;
80
81};
82
83static struct PeerContext p1;
84
85static struct PeerContext p2;
86
87static struct PeerContext p3;
88
89static GNUNET_HashCode alice;
90
91static GNUNET_HashCode bob;
92
93static GNUNET_HashCode carol;
94
95static struct GNUNET_CHAT_Room *alice_room;
96
97static struct GNUNET_CHAT_Room *bob_room;
98
99static struct GNUNET_CHAT_Room *carol_room;
100
101static struct GNUNET_CONTAINER_MetaData *alice_meta;
102
103static struct GNUNET_CONTAINER_MetaData *bob_meta;
104
105static struct GNUNET_CONTAINER_MetaData *carol_meta;
106
107static struct Wanted alice_wanted;
108
109static struct Wanted bob_wanted;
110
111static struct Wanted carol_wanted;
112
113static GNUNET_SCHEDULER_TaskIdentifier kill_task;
114
115static GNUNET_SCHEDULER_TaskIdentifier finish_task;
116
117static GNUNET_SCHEDULER_TaskIdentifier wait_task;
118
119static int err;
120
121static int alice_ready;
122
123static int bob_ready;
124
125static int is_p2p;
126
127struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *bob_public_key = NULL;
128
129
130static void
131setup_peer (struct PeerContext *p, const char *cfgname)
132{
133 p->cfg = GNUNET_CONFIGURATION_create ();
134#if START_ARM
135 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
136 "gnunet-service-arm",
137#if VERBOSE
138 "-L", "DEBUG",
139#endif
140 "-c", cfgname, NULL);
141#endif
142 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
143}
144
145
146static void
147stop_arm (struct PeerContext *p)
148{
149#if START_ARM
150 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
151 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
152 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
153 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
155 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc));
156 GNUNET_OS_process_close (p->arm_proc);
157 p->arm_proc = NULL;
158#endif
159 GNUNET_CONFIGURATION_destroy (p->cfg);
160}
161
162
163static void
164abort_test (void *cls,
165 const struct GNUNET_SCHEDULER_TaskContext *tc)
166{
167 if (alice_room != NULL)
168 {
169 GNUNET_CHAT_leave_room (alice_room);
170 alice_room = NULL;
171 }
172 if (bob_room != NULL)
173 {
174 GNUNET_CHAT_leave_room (bob_room);
175 bob_room = NULL;
176 }
177 if (carol_room != NULL)
178 {
179 GNUNET_CHAT_leave_room (carol_room);
180 carol_room = NULL;
181 }
182 err = 1;
183}
184
185
186static void
187timeout_kill (void *cls,
188 const struct GNUNET_SCHEDULER_TaskContext *tc)
189{
190#if VERBOSE
191 printf ("Timed out, stopping the test.\n");
192#endif
193 kill_task = GNUNET_SCHEDULER_NO_TASK;
194 if (wait_task != GNUNET_SCHEDULER_NO_TASK)
195 {
196 GNUNET_SCHEDULER_cancel (wait_task);
197 wait_task = GNUNET_SCHEDULER_NO_TASK;
198 }
199 GNUNET_SCHEDULER_add_continuation (&abort_test, NULL,
200 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
201}
202
203
204static int
205join_cb (void *cls)
206{
207 struct Wanted *want = cls;
208
209#if VERBOSE
210 printf ("%s has joined\n", want->me);
211#endif
212 if (NULL != want->next_task)
213 GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
214 return GNUNET_OK;
215}
216
217
218static int
219member_list_cb (void *cls,
220 const struct GNUNET_CONTAINER_MetaData *member_info,
221 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id,
222 enum GNUNET_CHAT_MsgOptions options)
223{
224 struct Wanted *want = cls;
225 GNUNET_HashCode sender;
226
227#if VERBOSE
228 printf ("%s - told that %s has %s\n",
229 want->me,
230 member_info == NULL ? NULL
231 : GNUNET_CONTAINER_meta_data_get_by_type (member_info,
232 EXTRACTOR_METATYPE_TITLE),
233 member_info == NULL ? "left" : "joined");
234#endif
235 GNUNET_CRYPTO_hash (member_id,
236 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
237 &sender);
238 /* entertain both primary and an alternative sender/meta */
239 if (((0 == memcmp (&sender, want->sender, sizeof (GNUNET_HashCode))) ||
240 ((want->sender2 != NULL) &&
241 (0 == memcmp (&sender, want->sender2, sizeof (GNUNET_HashCode))))) &&
242 (((member_info == NULL) && (want->meta == NULL)) ||
243 ((member_info != NULL) &&
244 (((want->meta != NULL) &&
245 GNUNET_CONTAINER_meta_data_test_equal (member_info,
246 want->meta)) ||
247 ((want->meta2 != NULL) &&
248 GNUNET_CONTAINER_meta_data_test_equal (member_info,
249 want->meta2))))) &&
250 (options == want->opt))
251 {
252 /* remember Bob's public key, we need it to send private message */
253 if (NULL == bob_public_key &&
254 (0 == memcmp (&bob, want->sender, sizeof (GNUNET_HashCode))))
255 bob_public_key =
256 GNUNET_memdup (member_id,
257 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
258 if (want->sender2 != NULL)
259 {
260 /* flush alternative sender */
261 if (0 == memcmp (&sender, want->sender, sizeof (GNUNET_HashCode)))
262 {
263 want->sender = want->sender2;
264 want->meta = want->meta2;
265 }
266 want->sender2 = NULL;
267 want->meta2 = NULL;
268 }
269 else
270 if (NULL != want->next_task)
271 GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
272 }
273 else
274 {
275 GNUNET_SCHEDULER_cancel (kill_task);
276 kill_task = GNUNET_SCHEDULER_NO_TASK;
277 GNUNET_SCHEDULER_add_now (&abort_test, NULL);
278 }
279 return GNUNET_OK;
280}
281
282
283static int
284receive_cb (void *cls,
285 struct GNUNET_CHAT_Room *room,
286 const GNUNET_HashCode *sender,
287 const struct GNUNET_CONTAINER_MetaData *meta,
288 const char *message,
289 struct GNUNET_TIME_Absolute timestamp,
290 enum GNUNET_CHAT_MsgOptions options)
291{
292 struct Wanted *want = cls;
293
294#if VERBOSE
295 printf ("%s - told that %s said '%s'\n",
296 want->me,
297 meta == NULL ? NULL
298 : GNUNET_CONTAINER_meta_data_get_by_type (meta,
299 EXTRACTOR_METATYPE_TITLE),
300 message);
301#endif
302
303 if ((want->msg != NULL) && (0 == strcmp (message, want->msg)) &&
304 (((sender == NULL) && (want->sender == NULL)) ||
305 ((sender != NULL) && (want->sender != NULL) &&
306 (0 == memcmp (sender, want->sender,
307 sizeof (GNUNET_HashCode))))) &&
308 (GNUNET_CONTAINER_meta_data_test_equal (meta, want->meta)) &&
309 (options == want->opt) &&
310 /* Not == since the library sets the actual timestamp, so it may be
311 * slightly greater
312 */
313 (timestamp.abs_value >= want->timestamp.abs_value))
314 {
315 if (NULL != want->next_task)
316 GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
317 }
318 else
319 {
320 GNUNET_SCHEDULER_cancel (kill_task);
321 kill_task = GNUNET_SCHEDULER_NO_TASK;
322 GNUNET_SCHEDULER_cancel (finish_task);
323 finish_task = GNUNET_SCHEDULER_NO_TASK;
324 GNUNET_SCHEDULER_add_now (&abort_test, NULL);
325 }
326 return GNUNET_OK;
327}
328
329
330static void
331wait_until_all_ready (void *cls,
332 const struct GNUNET_SCHEDULER_TaskContext *tc)
333{
334 GNUNET_SCHEDULER_Task task = cls;
335
336#if VERBOSE
337 printf ("Waiting...\n");
338#endif
339 if (alice_ready && bob_ready)
340 {
341 wait_task = GNUNET_SCHEDULER_NO_TASK;
342 GNUNET_SCHEDULER_add_now (task, NULL);
343 }
344 else
345 wait_task =
346 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
347 5000),
348 &wait_until_all_ready,
349 task);
350}
351
352
353static void
354set_alice_ready (void *cls,
355 const struct GNUNET_SCHEDULER_TaskContext *tc)
356{
357 alice_ready = GNUNET_YES;
358}
359
360
361static void
362set_bob_ready (void *cls,
363 const struct GNUNET_SCHEDULER_TaskContext *tc)
364{
365 bob_ready = GNUNET_YES;
366}
367
368
369static void
370disconnect_alice (void *cls,
371 const struct GNUNET_SCHEDULER_TaskContext *tc)
372{
373#if VERBOSE
374 printf ("Alice is leaving.\n");
375#endif
376 if (is_p2p)
377 stop_arm (&p2);
378 GNUNET_CHAT_leave_room (alice_room);
379 alice_room = NULL;
380 GNUNET_SCHEDULER_cancel (kill_task);
381 kill_task = GNUNET_SCHEDULER_NO_TASK;
382}
383
384
385static void
386disconnect_bob (void *cls,
387 const struct GNUNET_SCHEDULER_TaskContext *tc)
388{
389#if VERBOSE
390 printf ("Bod is leaving.\n");
391#endif
392 if (is_p2p)
393 stop_arm (&p3);
394 alice_wanted.meta = NULL;
395 alice_wanted.sender = &bob;
396 alice_wanted.msg = NULL;
397 alice_wanted.opt = 0;
398 alice_wanted.next_task = &disconnect_alice;
399 alice_wanted.next_task_cls = NULL;
400 GNUNET_CHAT_leave_room (bob_room);
401 bob_room = NULL;
402}
403
404
405static void
406disconnect_carol (void *cls,
407 const struct GNUNET_SCHEDULER_TaskContext *tc)
408{
409#if VERBOSE
410 printf ("Carol is leaving.\n");
411#endif
412 alice_wanted.meta = NULL;
413 alice_wanted.sender = &carol;
414 alice_wanted.msg = NULL;
415 alice_wanted.opt = 0;
416 alice_wanted.next_task = &set_alice_ready;
417 alice_wanted.next_task_cls = NULL;
418 alice_ready = GNUNET_NO;
419 bob_wanted.meta = NULL;
420 bob_wanted.sender = &carol;
421 bob_wanted.msg = NULL;
422 bob_wanted.opt = 0;
423 bob_wanted.next_task = &wait_until_all_ready;
424 bob_wanted.next_task_cls = &disconnect_bob;
425 bob_ready = GNUNET_YES;
426 GNUNET_CHAT_leave_room (carol_room);
427 carol_room = NULL;
428}
429
430
431static void
432send_from_alice_to_bob (void *cls,
433 const struct GNUNET_SCHEDULER_TaskContext *tc)
434{
435 uint32_t seq;
436
437#if VERBOSE
438 printf ("Alice says 'Hi!' to Bob\n");
439#endif
440 alice_ready = GNUNET_YES;
441 bob_ready = GNUNET_NO;
442 bob_wanted.meta = alice_meta;
443 bob_wanted.sender = &alice;
444 bob_wanted.msg = "Hi Bob!";
445 bob_wanted.opt = GNUNET_CHAT_MSG_PRIVATE;
446 bob_wanted.next_task = &set_bob_ready;
447 bob_wanted.next_task_cls = NULL;
448 /* Carol should not receive this message */
449 carol_wanted.meta = NULL;
450 carol_wanted.sender = NULL;
451 carol_wanted.msg = NULL;
452 carol_wanted.opt = 0;
453 carol_wanted.next_task = NULL;
454 carol_wanted.next_task_cls = NULL;
455 GNUNET_CHAT_send_message (alice_room,
456 "Hi Bob!",
457 GNUNET_CHAT_MSG_PRIVATE,
458 bob_public_key, &seq);
459 finish_task = GNUNET_SCHEDULER_add_delayed (PM_TIMEOUT,
460 &wait_until_all_ready,
461 &disconnect_carol);
462}
463
464
465static void
466prepare_bob_for_alice_task (void *cls,
467 const struct GNUNET_SCHEDULER_TaskContext *tc)
468{
469 bob_wanted.meta = alice_meta;
470 bob_wanted.sender = &alice;
471 bob_wanted.msg = NULL;
472 bob_wanted.opt = -1;
473 bob_wanted.next_task = &set_bob_ready;
474 bob_wanted.next_task_cls = NULL;
475}
476
477
478static void
479prepare_carol_for_alice_and_bob_task (void *cls,
480 const struct GNUNET_SCHEDULER_TaskContext *tc)
481{
482 carol_wanted.meta = alice_meta;
483 carol_wanted.sender = &alice;
484 /* set alternative meta/sender since we don't know from which peer
485 notification will come first */
486 carol_wanted.meta2 = bob_meta;
487 carol_wanted.sender2 = &bob;
488 carol_wanted.msg = NULL;
489 carol_wanted.opt = -1;
490 carol_wanted.next_task = &wait_until_all_ready;
491 carol_wanted.next_task_cls = &send_from_alice_to_bob;
492}
493
494
495static void
496join_carol_task (void *cls,
497 const struct GNUNET_SCHEDULER_TaskContext *tc)
498{
499#if VERBOSE
500 printf ("Carol joining\n");
501#endif
502 alice_wanted.meta = carol_meta;
503 alice_wanted.sender = &carol;
504 alice_wanted.msg = NULL;
505 alice_wanted.opt = -1;
506 alice_wanted.next_task = &set_alice_ready;
507 alice_wanted.next_task_cls = NULL;
508 alice_ready = GNUNET_NO;
509 bob_wanted.meta = carol_meta;
510 bob_wanted.sender = &carol;
511 bob_wanted.msg = NULL;
512 bob_wanted.opt = -1;
513 bob_wanted.next_task = &set_bob_ready;
514 bob_wanted.next_task_cls = NULL;
515 bob_ready = GNUNET_NO;
516 carol_wanted.next_task = &prepare_carol_for_alice_and_bob_task;
517 carol_wanted.next_task_cls = NULL;
518 carol_room =
519 GNUNET_CHAT_join_room (is_p2p ? p3.cfg : p1.cfg, "carol", carol_meta,
520 "test", -1,
521 &join_cb, &carol_wanted,
522 &receive_cb, &carol_wanted,
523 &member_list_cb, &carol_wanted,
524 NULL, NULL, &carol);
525 if (NULL == carol_room)
526 {
527 GNUNET_SCHEDULER_cancel (kill_task);
528 kill_task = GNUNET_SCHEDULER_NO_TASK;
529 GNUNET_CHAT_leave_room (alice_room);
530 alice_room = NULL;
531 GNUNET_CHAT_leave_room (bob_room);
532 bob_room = NULL;
533 err = 1;
534 }
535}
536
537
538static void
539join_bob_task (void *cls,
540 const struct GNUNET_SCHEDULER_TaskContext *tc)
541{
542#if VERBOSE
543 printf ("Bob joining\n");
544#endif
545 alice_wanted.meta = bob_meta;
546 alice_wanted.sender = &bob;
547 alice_wanted.msg = NULL;
548 alice_wanted.opt = -1;
549 alice_wanted.next_task = &wait_until_all_ready;
550 alice_wanted.next_task_cls = &join_carol_task;
551 alice_ready = GNUNET_YES;
552 bob_wanted.next_task = &prepare_bob_for_alice_task;
553 bob_wanted.next_task_cls = NULL;
554 bob_ready = GNUNET_NO;
555 bob_room =
556 GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta,
557 "test", -1,
558 &join_cb, &bob_wanted,
559 &receive_cb, &bob_wanted,
560 &member_list_cb, &bob_wanted,
561 NULL, NULL, &bob);
562 if (NULL == bob_room)
563 {
564 GNUNET_SCHEDULER_cancel (kill_task);
565 kill_task = GNUNET_SCHEDULER_NO_TASK;
566 GNUNET_CHAT_leave_room (alice_room);
567 alice_room = NULL;
568 err = 1;
569 }
570}
571
572
573static void
574join_alice_task (void *cls,
575 const struct GNUNET_SCHEDULER_TaskContext *tc)
576{
577#if VERBOSE
578 printf ("Alice joining\n");
579#endif
580 alice_wanted.next_task = &join_bob_task;
581 alice_wanted.next_task_cls = NULL;
582 alice_room =
583 GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta,
584 "test", -1,
585 &join_cb, &alice_wanted,
586 &receive_cb, &alice_wanted,
587 &member_list_cb, &alice_wanted,
588 NULL, NULL, &alice);
589 if (NULL == alice_room)
590 {
591 GNUNET_SCHEDULER_cancel (kill_task);
592 kill_task = GNUNET_SCHEDULER_NO_TASK;
593 err = 1;
594 }
595}
596
597
598static void
599run (void *cls,
600 char *const *args,
601 const char *cfgfile,
602 const struct GNUNET_CONFIGURATION_Handle *cfg)
603{
604 if (is_p2p)
605 {
606 setup_peer (&p1, "test_chat_peer1.conf");
607 setup_peer (&p2, "test_chat_peer2.conf");
608 setup_peer (&p3, "test_chat_peer3.conf");
609 }
610 else
611 setup_peer (&p1, "test_chat_data.conf");
612
613 memset (&alice_wanted, 0, sizeof (struct Wanted));
614 memset (&bob_wanted, 0, sizeof (struct Wanted));
615 memset (&carol_wanted, 0, sizeof (struct Wanted));
616 alice_wanted.me = "Alice";
617 bob_wanted.me = "Bob";
618 carol_wanted.me = "Carol";
619 alice_meta = GNUNET_CONTAINER_meta_data_create ();
620 GNUNET_CONTAINER_meta_data_insert (alice_meta,
621 "<gnunet>",
622 EXTRACTOR_METATYPE_TITLE,
623 EXTRACTOR_METAFORMAT_UTF8,
624 "text/plain",
625 "Alice",
626 strlen("Alice")+1);
627 bob_meta = GNUNET_CONTAINER_meta_data_create ();
628 GNUNET_CONTAINER_meta_data_insert (bob_meta,
629 "<gnunet>",
630 EXTRACTOR_METATYPE_TITLE,
631 EXTRACTOR_METAFORMAT_UTF8,
632 "text/plain",
633 "Bob",
634 strlen("Bob")+1);
635 carol_meta = GNUNET_CONTAINER_meta_data_create ();
636 GNUNET_CONTAINER_meta_data_insert (carol_meta,
637 "<gnunet>",
638 EXTRACTOR_METATYPE_TITLE,
639 EXTRACTOR_METAFORMAT_UTF8,
640 "text/plain",
641 "Carol",
642 strlen("Carol")+1);
643 kill_task = GNUNET_SCHEDULER_add_delayed (KILL_TIMEOUT, &timeout_kill, NULL);
644 GNUNET_SCHEDULER_add_now (&join_alice_task, NULL);
645}
646
647
648int
649main (int argc, char *argv[])
650{
651 char *const argvx[] = {
652 "test-chat",
653 "-c",
654 "test_chat_data.conf",
655#if VERBOSE
656 "-L", "DEBUG",
657#endif
658 NULL
659 };
660 struct GNUNET_GETOPT_CommandLineOption options[] = {
661 GNUNET_GETOPT_OPTION_END
662 };
663
664 GNUNET_log_setup ("test_chat",
665#if VERBOSE
666 "DEBUG",
667#else
668 "WARNING",
669#endif
670 NULL);
671 if (strstr(argv[0], "p2p") != NULL)
672 {
673 is_p2p = GNUNET_YES;
674 }
675 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
676 argvx, "test-chat",
677 "nohelp", options, &run, NULL);
678 stop_arm (&p1);
679 GNUNET_CONTAINER_meta_data_destroy (alice_meta);
680 GNUNET_CONTAINER_meta_data_destroy (bob_meta);
681 GNUNET_CONTAINER_meta_data_destroy (carol_meta);
682 if (is_p2p)
683 {
684 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/");
685 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/");
686 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-3/");
687 }
688 else
689 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat/");
690 return err;
691}
692
693/* end of test_chat_private.c */