psyc/social: local join flag; social service: leave place, save _file
[oweals/gnunet.git] / src / multicast / test_multicast.c
1 /*
2  * This file is part of GNUnet
3  * Copyright (C) 2013 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., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 /**
22  * @file multicast/test_multicast.c
23  * @brief Tests for the Multicast API.
24  * @author Gabor X Toth
25  */
26
27 #include <inttypes.h>
28
29 #include "platform.h"
30 #include "gnunet_crypto_lib.h"
31 #include "gnunet_common.h"
32 #include "gnunet_util_lib.h"
33 #include "gnunet_testing_lib.h"
34 #include "gnunet_core_service.h"
35 #include "gnunet_multicast_service.h"
36
37 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
38
39 /**
40  * Return value from 'main'.
41  */
42 static int res;
43
44 /**
45  * Handle for task for timeout termination.
46  */
47 static struct GNUNET_SCHEDULER_Task * end_badly_task;
48
49 static const struct GNUNET_CONFIGURATION_Handle *cfg;
50
51 struct GNUNET_CORE_Handle *core;
52 struct GNUNET_PeerIdentity this_peer;
53
54 struct GNUNET_MULTICAST_Origin *origin;
55 struct GNUNET_MULTICAST_Member *member;
56
57 struct GNUNET_CRYPTO_EddsaPrivateKey *group_key;
58 struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key;
59
60 struct GNUNET_CRYPTO_EcdsaPrivateKey *member_key;
61 struct GNUNET_CRYPTO_EcdsaPublicKey member_pub_key;
62
63 struct TransmitClosure {
64   struct GNUNET_MULTICAST_OriginTransmitHandle *orig_tmit;
65   struct GNUNET_MULTICAST_MemberTransmitHandle *mem_tmit;
66   char * data[16];
67   uint8_t data_delay[16];
68   uint8_t data_count;
69   uint8_t paused;
70   uint8_t n;
71 } tmit_cls;
72
73 struct OriginClosure {
74   uint8_t msgs_expected;
75   uint8_t n;
76 } origin_cls;
77
78 struct MemberClosure {
79   uint8_t msgs_expected;
80   size_t n;
81 } member_cls;
82
83 struct GNUNET_MessageHeader *join_req, *join_resp;
84
85 enum
86 {
87   TEST_NONE                = 0,
88   TEST_ORIGIN_START        = 1,
89   TEST_MEMBER_JOIN_REFUSE  = 2,
90   TEST_MEMBER_JOIN_ADMIT   = 3,
91   TEST_ORIGIN_TO_ALL       = 4,
92   TEST_ORIGIN_TO_ALL_RECV  = 5,
93   TEST_MEMBER_TO_ORIGIN    = 6,
94   TEST_MEMBER_REPLAY_ERROR = 7,
95   TEST_MEMBER_REPLAY_OK    = 8,
96   TEST_MEMBER_PART         = 9,
97   TEST_ORIGIN_STOP        = 10,
98 } test;
99
100 uint64_t replay_fragment_id;
101 uint64_t replay_flags;
102
103 static void
104 member_join (int t);
105
106
107 /**
108  * Clean up all resources used.
109  */
110 static void
111 cleanup ()
112 {
113   if (NULL != core)
114   {
115     GNUNET_CORE_disconnect (core);
116     core = NULL;
117   }
118   if (NULL != member)
119   {
120     GNUNET_MULTICAST_member_part (member, NULL, NULL);
121     member = NULL;
122   }
123   if (NULL != origin)
124   {
125     GNUNET_MULTICAST_origin_stop (origin, NULL, NULL);
126     origin = NULL;
127   }
128 }
129
130
131 /**
132  * Terminate the test case (failure).
133  *
134  * @param cls NULL
135  * @param tc scheduler context
136  */
137 static void
138 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
139 {
140   res = 1;
141   cleanup ();
142   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test FAILED.\n");
143 }
144
145
146 /**
147  * Terminate the test case (success).
148  *
149  * @param cls NULL
150  * @param tc scheduler context
151  */
152 static void
153 end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
154 {
155   res = 0;
156   cleanup ();
157   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test PASSED.\n");
158 }
159
160
161 /**
162  * Finish the test case (successfully).
163  */
164 static void
165 end ()
166 {
167   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending tests.\n");
168
169   if (end_badly_task != NULL)
170   {
171     GNUNET_SCHEDULER_cancel (end_badly_task);
172     end_badly_task = NULL;
173   }
174   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
175                                 &end_normally, NULL);
176 }
177
178
179 void
180 tmit_resume (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
181 {
182   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission resumed.\n");
183   struct TransmitClosure *tmit = cls;
184   if (NULL != tmit->orig_tmit)
185     GNUNET_MULTICAST_origin_to_all_resume (tmit->orig_tmit);
186   else if (NULL != tmit->mem_tmit)
187     GNUNET_MULTICAST_member_to_origin_resume (tmit->mem_tmit);
188 }
189
190
191 static int
192 tmit_notify (void *cls, size_t *data_size, void *data)
193 {
194   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
195               "Test #%u: origin_tmit_notify()\n", test);
196   struct TransmitClosure *tmit = cls;
197
198   if (0 == tmit->data_count)
199   {
200     *data_size = 0;
201     return GNUNET_YES;
202   }
203
204   uint16_t size = strlen (tmit->data[tmit->n]);
205   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
206               "Transmit notify data: %u bytes available, "
207               "processing fragment %u/%u (size %u).\n",
208               *data_size, tmit->n + 1, tmit->data_count, size);
209   if (*data_size < size)
210   {
211     *data_size = 0;
212     GNUNET_assert (0);
213     return GNUNET_SYSERR;
214   }
215
216   if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n])
217   {
218     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission paused.\n");
219     tmit->paused = GNUNET_YES;
220     GNUNET_SCHEDULER_add_delayed (
221       GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
222                                      tmit->data_delay[tmit->n]),
223       tmit_resume, tmit);
224     *data_size = 0;
225     return GNUNET_NO;
226   }
227   tmit->paused = GNUNET_NO;
228
229   *data_size = size;
230   memcpy (data, tmit->data[tmit->n], size);
231
232   return ++tmit->n < tmit->data_count ? GNUNET_NO : GNUNET_YES;
233 }
234
235
236 static void
237 member_recv_join_request (void *cls,
238                           const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
239                           const struct GNUNET_MessageHeader *join_msg,
240                           struct GNUNET_MULTICAST_JoinHandle *jh)
241 {
242   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
243               "Test #%u: member_recv_join_request()\n", test);
244 }
245
246
247 static void
248 origin_stopped (void *cls)
249 {
250   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
251               "Test #%u: origin_stopped()\n", test);
252   end ();
253 }
254
255
256 static void
257 schedule_origin_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
258 {
259   test = TEST_ORIGIN_STOP;
260   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
261               "Test #%u: origin_stop()\n", test);
262   GNUNET_MULTICAST_origin_stop (origin, origin_stopped, NULL);
263   origin = NULL;
264 }
265
266
267 static void
268 member_parted (void *cls)
269 {
270   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
271               "Test #%u: member_parted()\n", test);
272   member = NULL;
273
274   switch (test)
275   {
276   case TEST_MEMBER_JOIN_REFUSE:
277     member_join (TEST_MEMBER_JOIN_ADMIT);
278     break;
279
280   case TEST_MEMBER_PART:
281     GNUNET_SCHEDULER_add_now (schedule_origin_stop, NULL);
282     break;
283
284   default:
285     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
286                 "Invalid test #%d in member_recv_join_decision()\n", test);
287     GNUNET_assert (0);
288   }
289 }
290
291
292 static void
293 schedule_member_part (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
294 {
295   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
296               "Test #%u: schedule_member_part()\n", test);
297   GNUNET_MULTICAST_member_part (member, member_parted, NULL);
298 }
299
300
301 static void
302 member_part ()
303 {
304   test = TEST_MEMBER_PART;
305   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
306               "Test #%u: member_part()\n", test);
307   GNUNET_SCHEDULER_add_now (schedule_member_part, NULL);
308 }
309
310
311 static void
312 member_replay_ok ()
313 {
314   test = TEST_MEMBER_REPLAY_OK;
315   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
316               "Test #%u: member_replay_ok()\n", test);
317   replay_fragment_id = 1;
318   replay_flags = 1 | 1<<11;
319   GNUNET_MULTICAST_member_replay_fragment (member, replay_fragment_id,
320                                            replay_flags);
321 }
322
323
324 static void
325 member_replay_error ()
326 {
327   test = TEST_MEMBER_REPLAY_ERROR;
328   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
329               "Test #%u: member_replay_error()\n", test);
330   replay_fragment_id = 1234;
331   replay_flags = 11 | 1<<11;
332   GNUNET_MULTICAST_member_replay_fragment (member, replay_fragment_id,
333                                            replay_flags);
334 }
335
336
337 static void
338 origin_recv_replay_msg (void *cls,
339                         const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
340                         uint64_t message_id,
341                         uint64_t fragment_offset,
342                         uint64_t flags,
343                         struct GNUNET_MULTICAST_ReplayHandle *rh)
344 {
345   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
346               "Test #%u: origin_recv_replay_msg()\n", test);
347   GNUNET_assert (0);
348 }
349
350
351 static void
352 member_recv_replay_msg (void *cls,
353                         const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
354                         uint64_t message_id,
355                         uint64_t fragment_offset,
356                         uint64_t flags,
357                         struct GNUNET_MULTICAST_ReplayHandle *rh)
358 {
359   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
360               "Test #%u: member_recv_replay_msg()\n", test);
361   GNUNET_assert (0);
362 }
363
364
365 static void
366 origin_recv_replay_frag (void *cls,
367                          const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
368                          uint64_t fragment_id,
369                          uint64_t flags,
370                          struct GNUNET_MULTICAST_ReplayHandle *rh)
371 {
372   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
373               "Test #%u: origin_recv_replay_frag()"
374               " - fragment_id=%" PRIu64 " flags=%" PRIu64 "\n",
375               test, fragment_id, flags);
376   GNUNET_assert (replay_fragment_id == fragment_id && replay_flags == flags);
377   switch (test)
378   {
379   case TEST_MEMBER_REPLAY_ERROR:
380     GNUNET_MULTICAST_replay_response (rh, NULL, GNUNET_SYSERR);
381     member_replay_ok ();
382     break;
383
384   case TEST_MEMBER_REPLAY_OK:
385   {
386     struct GNUNET_MULTICAST_MessageHeader mmsg = {
387       .header = {
388         .type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE),
389         .size = htons (sizeof (mmsg)),
390       },
391       .fragment_id = GNUNET_htonll (1),
392       .message_id = GNUNET_htonll (1),
393       .fragment_offset = 0,
394       .group_generation = GNUNET_htonll (1),
395       .flags = 0,
396     };
397     member_cls.n = 0;
398     member_cls.msgs_expected = 1;
399     GNUNET_MULTICAST_replay_response (rh, &mmsg.header, GNUNET_MULTICAST_REC_OK);
400     GNUNET_MULTICAST_replay_response_end (rh);
401     break;
402   }
403
404   default:
405     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
406                 "Invalid test #%d in origin_recv_replay_frag()\n", test);
407     GNUNET_assert (0);
408   }
409 }
410
411
412 static void
413 member_recv_replay_frag (void *cls,
414                          const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
415                          uint64_t fragment_id,
416                          uint64_t flags,
417                          struct GNUNET_MULTICAST_ReplayHandle *rh)
418 {
419   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
420               "Test #%u: member_recv_replay_frag()\n", test);
421   GNUNET_assert (0);
422 }
423
424
425 static void
426 origin_recv_request (void *cls,
427                      const struct GNUNET_MULTICAST_RequestHeader *req)
428 {
429   struct OriginClosure *ocls = cls;
430   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
431               "Test #%u: origin_recv_request()\n", test);
432   if (++ocls->n != ocls->msgs_expected)
433     return;
434
435   GNUNET_assert (0 == memcmp (&req->member_key,
436                               &member_pub_key, sizeof (member_pub_key)));
437
438
439   // FIXME: check message content
440
441   member_replay_error ();
442 }
443
444
445 static void
446 member_to_origin ()
447 {
448   test = TEST_MEMBER_TO_ORIGIN;
449   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
450               "Test #%u: member_to_origin()\n", test);
451
452   struct TransmitClosure *tmit = &tmit_cls;
453   *tmit = (struct TransmitClosure) {};
454   tmit->data[0] = "abc def";
455   tmit->data[1] = "ghi jkl mno";
456   tmit->data_delay[1] = 2;
457   tmit->data[2] = "pqr stuw xyz";
458   tmit->data_count = 3;
459
460   origin_cls.n = 0;
461   origin_cls.msgs_expected = 1;
462
463   tmit->mem_tmit = GNUNET_MULTICAST_member_to_origin (member, 1,
464                                                       tmit_notify, tmit);
465 }
466
467
468 static void
469 member_recv_message (void *cls,
470                      const struct GNUNET_MULTICAST_MessageHeader *msg)
471 {
472   struct MemberClosure *mcls = cls;
473   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
474               "Test #%u: member_recv_message() %u/%u\n",
475               test, mcls->n + 1, mcls->msgs_expected);
476   if (++mcls->n != mcls->msgs_expected)
477     return;
478
479   // FIXME: check message content
480
481   switch (test)
482   {
483   case TEST_ORIGIN_TO_ALL_RECV:
484     member_to_origin ();
485     break;
486
487   case TEST_MEMBER_REPLAY_OK:
488     GNUNET_assert (replay_fragment_id == GNUNET_ntohll (msg->fragment_id));
489     member_part ();
490     break;
491
492   default:
493     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
494                 "Invalid test #%d in origin_recv_message()\n", test);
495     GNUNET_assert (0);
496   }
497 }
498
499
500 static void
501 origin_recv_message (void *cls,
502                      const struct GNUNET_MULTICAST_MessageHeader *msg)
503 {
504   struct OriginClosure *ocls = cls;
505   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
506               "Test #%u: origin_recv_message() %u/%u\n",
507               test, ocls->n + 1, ocls->msgs_expected);
508   if (++ocls->n != ocls->msgs_expected)
509     return;
510
511   // FIXME: check message content
512
513   switch (test)
514   {
515   case TEST_ORIGIN_TO_ALL:
516     test = TEST_ORIGIN_TO_ALL_RECV;
517     break;
518
519   default:
520     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
521                 "Invalid test #%d in origin_recv_message()\n", test);
522     GNUNET_assert (0);
523   }
524 }
525
526
527 static void
528 origin_to_all ()
529 {
530   test = TEST_ORIGIN_TO_ALL;
531   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
532               "Test #%u: origin_to_all()\n", test);
533
534   struct TransmitClosure *tmit = &tmit_cls;
535   *tmit = (struct TransmitClosure) {};
536   tmit->data[0] = "ABC DEF";
537   tmit->data[1] =  GNUNET_malloc (GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD + 1);
538   uint16_t i;
539   for (i = 0; i < GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD; i++)
540     tmit->data[1][i] = (0 == i % 10000) ? '0' + i / 10000 : '_';
541   tmit->data[2] = "GHI JKL MNO";
542   tmit->data_delay[2] = 2;
543   tmit->data[3] = "PQR STUW XYZ";
544   tmit->data_count = 4;
545
546   origin_cls.n = member_cls.n = 0;
547   origin_cls.msgs_expected = member_cls.msgs_expected = tmit->data_count;
548
549   tmit->orig_tmit = GNUNET_MULTICAST_origin_to_all (origin, 1, 1,
550                                                     tmit_notify, tmit);
551 }
552
553
554 static void
555 member_recv_join_decision (void *cls,
556                            int is_admitted,
557                            const struct GNUNET_PeerIdentity *peer,
558                            uint16_t relay_count,
559                            const struct GNUNET_PeerIdentity *relays,
560                            const struct GNUNET_MessageHeader *join_msg)
561 {
562   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
563               "Test #%u: member_recv_join_decision() - is_admitted: %d\n",
564               test, is_admitted);
565
566   GNUNET_assert (join_msg->size == join_resp->size);
567   GNUNET_assert (join_msg->type == join_resp->type);
568   GNUNET_assert (0 == memcmp (join_msg, join_resp, ntohs (join_resp->size)));
569
570   switch (test)
571   {
572   case TEST_MEMBER_JOIN_REFUSE:
573     GNUNET_assert (0 == relay_count);
574     GNUNET_SCHEDULER_add_now (schedule_member_part, NULL);
575     break;
576
577   case TEST_MEMBER_JOIN_ADMIT:
578     GNUNET_assert (1 == relay_count);
579     GNUNET_assert (0 == memcmp (relays, &this_peer, sizeof (this_peer)));
580     origin_to_all ();
581     break;
582
583   default:
584     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
585                 "Invalid test #%d in member_recv_join_decision()\n", test);
586     GNUNET_assert (0);
587   }
588 }
589
590
591 static void
592 origin_recv_join_request (void *cls,
593                           const struct GNUNET_CRYPTO_EcdsaPublicKey *mem_key,
594                           const struct GNUNET_MessageHeader *join_msg,
595                           struct GNUNET_MULTICAST_JoinHandle *jh)
596 {
597   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
598               "Test #%u: origin_recv_join_request()\n", test);
599
600   GNUNET_assert (0 == memcmp (mem_key, &member_pub_key, sizeof (member_pub_key)));
601   GNUNET_assert (join_msg->size == join_req->size);
602   GNUNET_assert (join_msg->type == join_req->type);
603   GNUNET_assert (0 == memcmp (join_msg, join_req, ntohs (join_req->size)));
604
605   char data[] = "here's the decision";
606   uint8_t data_size = strlen (data) + 1;
607   join_resp = GNUNET_malloc (sizeof (join_resp) + data_size);
608   join_resp->size = htons (sizeof (join_resp) + data_size);
609   join_resp->type = htons (456);
610   memcpy (&join_resp[1], data, data_size);
611
612   switch (test)
613   {
614   case TEST_MEMBER_JOIN_REFUSE:
615     GNUNET_MULTICAST_join_decision (jh, GNUNET_NO, 0, NULL, join_resp);
616     break;
617
618   case TEST_MEMBER_JOIN_ADMIT:
619     GNUNET_MULTICAST_join_decision (jh, GNUNET_YES, 1, &this_peer, join_resp);
620     break;
621
622   default:
623     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
624                 "Invalid test #%d in origin_recv_join_request()\n", test);
625     GNUNET_assert (0);
626     break;
627   }
628 }
629
630
631 static void
632 member_join (int t)
633 {
634   test = t;
635   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
636               "Test #%u: member_join()\n", test);
637
638   member_key = GNUNET_CRYPTO_ecdsa_key_create ();
639   GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key);
640
641   if (NULL != join_req)
642     GNUNET_free (join_req);
643
644   char data[] = "let me in!";
645   uint8_t data_size = strlen (data) + 1;
646   join_req = GNUNET_malloc (sizeof (join_req) + data_size);
647   join_req->size = htons (sizeof (join_req) + data_size);
648   join_req->type = htons (123);
649   memcpy (&join_req[1], data, data_size);
650
651   member = GNUNET_MULTICAST_member_join (cfg, &group_pub_key, member_key,
652                                          &this_peer, 1, &this_peer, join_req,
653                                          member_recv_join_request,
654                                          member_recv_join_decision,
655                                          member_recv_replay_frag,
656                                          member_recv_replay_msg,
657                                          member_recv_message,
658                                          &member_cls);
659 }
660
661
662 static void
663 origin_start ()
664 {
665   test = TEST_ORIGIN_START;
666   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
667               "Test #%u: origin_start()\n", test);
668
669   group_key = GNUNET_CRYPTO_eddsa_key_create ();
670   GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key);
671
672   origin = GNUNET_MULTICAST_origin_start (cfg, group_key, 0,
673                                           origin_recv_join_request,
674                                           origin_recv_replay_frag,
675                                           origin_recv_replay_msg,
676                                           origin_recv_request,
677                                           origin_recv_message,
678                                           &origin_cls);
679   member_join (TEST_MEMBER_JOIN_REFUSE);
680 }
681
682
683 static void
684 core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity)
685 {
686   this_peer = *my_identity;
687   origin_start ();
688 }
689
690
691 /**
692  * Main function of the test, run from scheduler.
693  *
694  * @param cls NULL
695  * @param cfg configuration we use (also to connect to Multicast service)
696  * @param peer handle to access more of the peer (not used)
697  */
698 static void
699 #if DEBUG_TEST_MULTICAST
700 run (void *cls, char *const *args, const char *cfgfile,
701      const struct GNUNET_CONFIGURATION_Handle *c)
702 #else
703 run (void *cls,
704      const struct GNUNET_CONFIGURATION_Handle *c,
705      struct GNUNET_TESTING_Peer *peer)
706 #endif
707 {
708   cfg = c;
709   end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
710
711   core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL,
712                               NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
713 }
714
715
716 int
717 main (int argc, char *argv[])
718 {
719   res = 1;
720 #if DEBUG_TEST_MULTICAST
721   const struct GNUNET_GETOPT_CommandLineOption opts[] = {
722     GNUNET_GETOPT_OPTION_END
723   };
724   if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-multicast",
725                                        "test-multicast [options]",
726                                        opts, &run, NULL))
727     return 1;
728 #else
729   if (0 != GNUNET_TESTING_peer_run ("test-multicast", "test_multicast.conf", &run, NULL))
730     return 1;
731 #endif
732   return res;
733 }
734
735 /* end of test_multicast.c */