use c99
[oweals/gnunet.git] / src / social / test_social.c
1 /*
2  * This file is part of GNUnet
3  * Copyright (C) 2013 GNUnet e.V.
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  * @file social/test_social.c
22  * @brief Tests for the Social API.
23  * @author Gabor X Toth
24  */
25
26 #include <inttypes.h>
27
28 #include "platform.h"
29 #include "gnunet_crypto_lib.h"
30 #include "gnunet_common.h"
31 #include "gnunet_util_lib.h"
32 #include "gnunet_testing_lib.h"
33 #include "gnunet_psyc_util_lib.h"
34 #include "gnunet_social_service.h"
35 #include "gnunet_core_service.h"
36 #include "gnunet_identity_service.h"
37
38 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
39
40 #define DATA2ARG(data) data, sizeof (data)
41
42 /**
43  * Return value from 'main'.
44  */
45 int res;
46
47 struct GNUNET_SOCIAL_App *app;
48 const char *app_id = "test";
49
50 /**
51  * Handle for task for timeout termination.
52  */
53 struct GNUNET_SCHEDULER_Task *end_badly_task;
54
55 const struct GNUNET_CONFIGURATION_Handle *cfg;
56
57 struct GNUNET_CORE_Handle *core;
58 struct GNUNET_PeerIdentity this_peer;
59
60 struct GNUNET_IDENTITY_Handle *id;
61
62 const struct GNUNET_SOCIAL_Ego *host_ego;
63 const struct GNUNET_SOCIAL_Ego *guest_ego;
64
65 const char *host_name = "Host One";
66 const char *guest_name = "Guest One";
67
68 struct GNUNET_CRYPTO_EddsaPrivateKey *place_key;
69 struct GNUNET_CRYPTO_EcdsaPrivateKey *guest_key;
70
71 struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key;
72 struct GNUNET_HashCode place_pub_hash;
73
74 struct GNUNET_CRYPTO_EcdsaPublicKey guest_pub_key;
75 struct GNUNET_CRYPTO_EcdsaPublicKey host_pub_key;
76
77 struct GNUNET_PSYC_Slicer *host_slicer;
78 struct GNUNET_PSYC_Slicer *guest_slicer;
79
80 struct GNUNET_SOCIAL_Host *hst;
81 struct GNUNET_SOCIAL_Guest *gst;
82
83 struct GNUNET_SOCIAL_Place *hst_plc;
84 struct GNUNET_SOCIAL_Place *gst_plc;
85
86 struct GNUNET_SOCIAL_Nym *nym_eject;
87
88 struct GuestEnterMessage
89 {
90   struct GNUNET_PSYC_Message *msg;
91   const char *method_name;
92   struct GNUNET_PSYC_Environment *env;
93   void *data;
94   uint16_t data_size;
95 } guest_enter_msg;
96
97 struct TransmitClosure
98 {
99   struct GNUNET_SOCIAL_Announcement *host_ann;
100   struct GNUNET_SOCIAL_TalkRequest *guest_talk;
101   struct GNUNET_PSYC_Environment *env;
102   char *data[16];
103   uint8_t data_delay[16];
104   uint8_t data_count;
105   uint8_t paused;
106   uint8_t n;
107 } tmit;
108
109 struct ResultClosure {
110   uint32_t n;
111 } mod_foo_bar_rcls;
112
113 uint8_t join_req_count;
114 struct GNUNET_PSYC_Message *join_resp;
115
116 uint32_t counter;
117
118 uint8_t is_guest_nym_added = GNUNET_NO;
119 uint8_t is_host_reconnected = GNUNET_NO;
120 uint8_t is_guest_reconnected = GNUNET_NO;
121
122 enum
123 {
124   TEST_NONE                         =  0,
125   TEST_HOST_CREATE                  =  1,
126   TEST_HOST_ENTER                   =  2,
127   TEST_GUEST_CREATE                 =  3,
128   TEST_GUEST_ENTER                  =  4,
129   TEST_HOST_ANSWER_DOOR_REFUSE      =  5,
130   TEST_GUEST_RECV_ENTRY_DCSN_REFUSE =  6,
131   TEST_HOST_ANSWER_DOOR_ADMIT       =  7,
132   TEST_GUEST_RECV_ENTRY_DCSN_ADMIT  =  8,
133   TEST_HOST_ANNOUNCE                =  9,
134   TEST_HOST_ANNOUNCE_END            = 10,
135   TEST_GUEST_TALK                   = 11,
136   TEST_HOST_ANNOUNCE2               = 12,
137   TEST_HOST_ANNOUNCE2_END           = 13,
138   TEST_GUEST_HISTORY_REPLAY         = 14,
139   TEST_GUEST_HISTORY_REPLAY_LATEST  = 15,
140   TEST_GUEST_LOOK_AT                = 16,
141   TEST_GUEST_LOOK_FOR               = 17,
142   TEST_GUEST_LEAVE                  = 18,
143   TEST_ZONE_ADD_PLACE               = 19,
144   TEST_GUEST_ENTER_BY_NAME          = 20,
145   TEST_RECONNECT                    = 21,
146   TEST_GUEST_LEAVE2                 = 22,
147   TEST_HOST_LEAVE                   = 23,
148 } test;
149
150
151 static void
152 schedule_guest_leave (void *cls);
153
154
155 static void
156 host_answer_door (void *cls,
157                   struct GNUNET_SOCIAL_Nym *nym,
158                   const char *method_name,
159                   struct GNUNET_PSYC_Environment *env,
160                   const void *data,
161                   size_t data_size);
162
163 static void
164 host_enter ();
165
166 static void
167 guest_init ();
168
169 static void
170 guest_enter ();
171
172 static void
173 guest_enter_by_name ();
174
175 static void
176 guest_talk ();
177
178 static void
179 host_announce2 ();
180
181
182 /**
183  * Clean up all resources used.
184  */
185 static void
186 cleanup ()
187 {
188   if (NULL != core)
189   {
190     GNUNET_CORE_disconnect (core);
191     core = NULL;
192   }
193
194   if (NULL != id)
195   {
196     GNUNET_IDENTITY_disconnect (id);
197     id = NULL;
198   }
199
200   if (NULL != guest_slicer)
201   {
202     GNUNET_PSYC_slicer_destroy (guest_slicer);
203     guest_slicer = NULL;
204   }
205
206   if (NULL != host_slicer)
207   {
208     GNUNET_PSYC_slicer_destroy (host_slicer);
209     host_slicer = NULL;
210   }
211
212   if (NULL != gst)
213   {
214     GNUNET_SOCIAL_guest_leave (gst, NULL, NULL, NULL);
215     gst = NULL;
216     gst_plc = NULL;
217   }
218   if (NULL != hst)
219   {
220     GNUNET_SOCIAL_host_leave (hst, NULL, NULL, NULL);
221     hst = NULL;
222     hst_plc = NULL;
223   }
224   GNUNET_SOCIAL_app_disconnect (app, NULL, NULL);
225   GNUNET_SCHEDULER_shutdown ();
226 }
227
228
229 /**
230  * Terminate the test case (failure).
231  *
232  * @param cls NULL
233  */
234 static void
235 end_badly (void *cls)
236 {
237   res = 1;
238   cleanup ();
239   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test FAILED.\n");
240 }
241
242
243 /**
244  * Terminate the test case (success).
245  *
246  * @param cls NULL
247  */
248 static void
249 end_normally (void *cls)
250 {
251   res = 0;
252   cleanup ();
253   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test PASSED.\n");
254 }
255
256
257 /**
258  * Finish the test case (successfully).
259  */
260 static void
261 end ()
262 {
263   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending tests.\n");
264
265   if (end_badly_task != NULL)
266   {
267     GNUNET_SCHEDULER_cancel (end_badly_task);
268     end_badly_task = NULL;
269   }
270   GNUNET_SCHEDULER_add_now (&end_normally, NULL);
271 }
272
273
274 static void
275 transmit_resume (void *cls)
276 {
277   struct TransmitClosure *tmit = cls;
278
279   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
280               "Transmission resumed.\n");
281   if (NULL != tmit->host_ann)
282     GNUNET_SOCIAL_host_announce_resume (tmit->host_ann);
283   else
284     GNUNET_SOCIAL_guest_talk_resume (tmit->guest_talk);
285 }
286
287
288 static int
289 notify_data (void *cls, uint16_t *data_size, void *data)
290 {
291   struct TransmitClosure *tmit = cls;
292   if (NULL != tmit->env)
293   {
294     GNUNET_PSYC_env_destroy (tmit->env);
295     tmit->env = NULL;
296   }
297   if (0 == tmit->data_count)
298   {
299     *data_size = 0;
300     return GNUNET_YES;
301   }
302
303   uint16_t size = strlen (tmit->data[tmit->n]);
304   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
305               "Transmit notify data: %u bytes available, "
306               "processing fragment %u/%u (size %u).\n",
307               *data_size, tmit->n + 1, tmit->data_count, size);
308   if (*data_size < size)
309   {
310     *data_size = 0;
311     GNUNET_assert (0);
312     return GNUNET_SYSERR;
313   }
314
315   if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n])
316   {
317     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission paused.\n");
318     tmit->paused = GNUNET_YES;
319     GNUNET_SCHEDULER_add_delayed (
320       GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
321                                      tmit->data_delay[tmit->n]),
322       &transmit_resume, tmit);
323     *data_size = 0;
324     return GNUNET_NO;
325   }
326   tmit->paused = GNUNET_NO;
327
328   *data_size = size;
329   memcpy (data, tmit->data[tmit->n], size);
330
331   return ++tmit->n < tmit->data_count ? GNUNET_NO : GNUNET_YES;
332 }
333
334
335 static void
336 host_left ()
337 {
338   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
339               "The host has left the place.\n");
340   end ();
341 }
342
343
344 static void
345 schedule_host_leave (void *cls)
346 {
347   test = TEST_HOST_LEAVE;
348   GNUNET_SOCIAL_host_leave (hst, NULL, &host_left, NULL);
349   hst = NULL;
350   hst_plc = NULL;
351 }
352
353
354 static void
355 host_farewell2 (void *cls,
356                const struct GNUNET_SOCIAL_Nym *nym,
357                struct GNUNET_PSYC_Environment *env)
358 {
359   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
360               "Nym left the place again.\n");
361   GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL);
362 }
363
364
365 static void
366 host_reconnected (void *cls, int result,
367                   const struct GNUNET_CRYPTO_EddsaPublicKey *home_pub_key,
368                   uint64_t max_message_id)
369 {
370   place_pub_key = *home_pub_key;
371   GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
372   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
373               "Test #%u: Host reconnected to place %s\n",
374               test, GNUNET_h2s (&place_pub_hash));
375
376   is_host_reconnected = GNUNET_YES;
377   if (GNUNET_YES == is_guest_reconnected)
378   {
379     GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
380   }
381 }
382
383
384 static void
385 guest_reconnected (void *cls, int result,
386                    const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
387                    uint64_t max_message_id)
388 {
389   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
390               "Test #%u: Guest reconnected to place: %d\n",
391               test, result);
392   GNUNET_assert (0 <= result);
393
394   is_guest_reconnected = GNUNET_YES;
395   if (GNUNET_YES == is_host_reconnected)
396   {
397     GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
398   }
399 }
400
401
402 static void
403 app_connected (void *cls)
404 {
405   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
406               "App connected: %p\n", cls);
407 }
408
409
410 static void
411 app_recv_host (void *cls,
412                struct GNUNET_SOCIAL_HostConnection *hconn,
413                struct GNUNET_SOCIAL_Ego *ego,
414                const struct GNUNET_CRYPTO_EddsaPublicKey *host_pub_key,
415                enum GNUNET_SOCIAL_AppPlaceState place_state)
416 {
417   struct GNUNET_HashCode host_pub_hash;
418   GNUNET_CRYPTO_hash (host_pub_key, sizeof (*host_pub_key), &host_pub_hash);
419
420   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
421               "Got app host place notification: %s\n",
422               GNUNET_h2s (&host_pub_hash));
423
424   if (test == TEST_RECONNECT)
425   {
426     if (0 == memcmp (&place_pub_key, host_pub_key, sizeof (*host_pub_key)))
427     {
428       hst = GNUNET_SOCIAL_host_enter_reconnect (hconn, host_slicer, host_reconnected,
429                                                 host_answer_door, host_farewell2, NULL);
430     }
431   }
432 }
433
434
435 static void
436 app_recv_guest (void *cls,
437                 struct GNUNET_SOCIAL_GuestConnection *gconn,
438                 struct GNUNET_SOCIAL_Ego *ego,
439                 const struct GNUNET_CRYPTO_EddsaPublicKey *guest_pub_key,
440                 enum GNUNET_SOCIAL_AppPlaceState place_state)
441 {
442   struct GNUNET_HashCode guest_pub_hash;
443   GNUNET_CRYPTO_hash (guest_pub_key, sizeof (*guest_pub_key), &guest_pub_hash);
444
445   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
446               "Got app guest place notification: %s\n",
447               GNUNET_h2s (&guest_pub_hash));
448
449   if (test == TEST_RECONNECT)
450   {
451     if (0 == memcmp (&place_pub_key, guest_pub_key, sizeof (*guest_pub_key)))
452     {
453       gst = GNUNET_SOCIAL_guest_enter_reconnect (gconn, GNUNET_PSYC_SLAVE_JOIN_NONE,
454                                                  guest_slicer, guest_reconnected, NULL);
455     }
456   }
457 }
458
459
460 static void
461 app_recv_ego (void *cls,
462               struct GNUNET_SOCIAL_Ego *ego,
463               const struct GNUNET_CRYPTO_EcdsaPublicKey *ego_pub_key,
464               const char *name)
465 {
466   char *ego_pub_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (ego_pub_key);
467   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
468               "Got app ego notification: %p %s %s\n",
469               ego, name, ego_pub_str);
470   GNUNET_free (ego_pub_str);
471
472   if (NULL != strstr (name, host_name) && TEST_HOST_CREATE == test)
473   {
474     host_ego = ego;
475     host_pub_key = *(GNUNET_SOCIAL_ego_get_pub_key (host_ego));
476     GNUNET_assert (TEST_HOST_CREATE == test);
477     host_enter ();
478   }
479   else if (NULL != strstr (name, guest_name))
480   {
481     guest_ego = ego;
482
483     if (TEST_GUEST_CREATE == test)
484       guest_init ();
485   }
486 }
487
488
489 static void
490 schedule_reconnect (void *cls)
491 {
492   test = TEST_RECONNECT;
493
494   GNUNET_SOCIAL_host_disconnect (hst, NULL, NULL);
495   GNUNET_SOCIAL_guest_disconnect (gst, NULL, NULL);
496   hst = NULL;
497   gst = NULL;
498
499   GNUNET_SOCIAL_app_disconnect (app, NULL, NULL);
500   app = GNUNET_SOCIAL_app_connect (cfg, app_id,
501                                    app_recv_ego,
502                                    app_recv_host,
503                                    app_recv_guest,
504                                    app_connected,
505                                    NULL);
506 }
507
508
509 static void
510 host_recv_zone_add_place_result (void *cls, int64_t result,
511                                  const void *data, uint16_t data_size)
512 {
513   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
514               "Test #%u: Zone add place result: %" PRId64 " (%.*s).\n",
515               test, result, data_size, (const char *) data);
516   GNUNET_assert (GNUNET_YES == result);
517
518   GNUNET_assert (GNUNET_YES == is_guest_nym_added);
519   guest_enter_by_name ();
520 }
521
522
523 static void
524 zone_add_place ()
525 {
526   test = TEST_ZONE_ADD_PLACE;
527   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
528               "Test #%u: Adding place to zone.\n", test);
529
530   GNUNET_SOCIAL_zone_add_place (app, host_ego, "home", "let.me*in!",
531                                 &place_pub_key, &this_peer, 1, &this_peer,
532                                 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
533                                 host_recv_zone_add_place_result, app);
534 }
535
536
537 static void
538 host_farewell (void *cls,
539                const struct GNUNET_SOCIAL_Nym *nym,
540                struct GNUNET_PSYC_Environment *env)
541 {
542   const struct GNUNET_CRYPTO_EcdsaPublicKey *
543     nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym);
544
545   char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
546   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
547               "Farewell: nym %s (%s) has left the place.\n",
548               GNUNET_h2s (GNUNET_SOCIAL_nym_get_pub_key_hash (nym)), str);
549   GNUNET_free (str);
550   GNUNET_assert (1 == GNUNET_PSYC_env_get_count (env));
551   if (0 != memcmp (&guest_pub_key, nym_key, sizeof (*nym_key)))
552   {
553     str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&guest_pub_key);
554     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
555                 "Farewell: nym does not match guest: %s\n", str);
556     GNUNET_free (str);
557     GNUNET_assert (0);
558   }
559   zone_add_place ();
560 }
561
562
563 static void
564 guest_left (void *cls)
565 {
566   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
567               "The guest has left the place.\n");
568 }
569
570
571 static void
572 guest_leave()
573 {
574   if (test < TEST_RECONNECT)
575     test = TEST_GUEST_LEAVE;
576   else
577     test = TEST_GUEST_LEAVE2;
578
579   struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
580   GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
581                        "_notice_place_leave", DATA2ARG ("Leaving."));
582   GNUNET_SOCIAL_guest_leave (gst, env, &guest_left, NULL);
583   GNUNET_PSYC_env_destroy (env);
584   gst = NULL;
585   gst_plc = NULL;
586 }
587
588
589 static void
590 schedule_guest_leave (void *cls)
591 {
592   guest_leave ();
593 }
594
595
596 static void
597 guest_look_for_result (void *cls,
598                        int64_t result_code,
599                        const void *data,
600                        uint16_t data_size)
601 {
602   struct ResultClosure *rcls = cls;
603   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
604               "guest_look_for_result: %" PRId64 "\n", result_code);
605   GNUNET_assert (GNUNET_OK == result_code);
606   GNUNET_assert (3 == rcls->n);
607   GNUNET_free (rcls);
608   GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
609 }
610
611
612 static void
613 guest_look_for_var (void *cls,
614                    const struct GNUNET_MessageHeader *mod,
615                    const char *name,
616                    const void *value,
617                    uint32_t value_size,
618                    uint32_t full_value_size)
619 {
620   struct ResultClosure *rcls = cls;
621   rcls->n++;
622   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
623               "guest_look_for_var: %s\n%.*s\n",
624               name, value_size, (const char *) value);
625 }
626
627
628 static void
629 guest_look_for ()
630 {
631   test = TEST_GUEST_LOOK_FOR;
632   struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls));
633   GNUNET_SOCIAL_place_look_for (gst_plc, "_foo", guest_look_for_var, guest_look_for_result, rcls);
634 }
635
636
637 static void
638 guest_look_at_result (void *cls, int64_t result_code,
639                       const void *data, uint16_t data_size)
640 {
641   struct ResultClosure *rcls = cls;
642
643   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
644               "guest_look_at_result: %" PRId64 "\n", result_code);
645   GNUNET_assert (GNUNET_OK == result_code);
646   GNUNET_assert (1 == rcls->n);
647   GNUNET_free (rcls);
648   guest_look_for ();
649 }
650
651
652 static void
653 guest_look_at_var (void *cls,
654                    const struct GNUNET_MessageHeader *mod,
655                    const char *name,
656                    const void *value,
657                    uint32_t value_size,
658                    uint32_t full_value_size)
659 {
660   struct ResultClosure *rcls = cls;
661   rcls->n++;
662
663   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
664               "guest_look_at_var: %s\n%.*s\n",
665               name, value_size, (const char *) value);
666 }
667
668
669 static void
670 guest_look_at ()
671 {
672   test = TEST_GUEST_LOOK_AT;
673   struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls));
674   GNUNET_SOCIAL_place_look_at (gst_plc, "_foo_bar", guest_look_at_var, guest_look_at_result, rcls);
675 }
676
677
678 static void
679 guest_recv_history_replay_latest_result (void *cls, int64_t result,
680                                          const void *data, uint16_t data_size)
681 {
682   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
683               "Test #%u: Guest received latest history replay result "
684               "(%" PRIu32 " messages, %" PRId64 " fragments):\n"
685               "%.*s\n",
686               test, counter, result, data_size, (const char *) data);
687   //GNUNET_assert (2 == counter); /* message count */
688   //GNUNET_assert (7 == result); /* fragment count */
689
690   guest_look_at ();
691 }
692
693
694 static void
695 guest_history_replay_latest ()
696 {
697   test = TEST_GUEST_HISTORY_REPLAY_LATEST;
698   counter = 0;
699   GNUNET_SOCIAL_place_history_replay_latest (gst_plc, 3, "",
700                                              GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
701                                              guest_slicer,
702                                              &guest_recv_history_replay_latest_result,
703                                              NULL);
704 }
705
706
707 static void
708 guest_recv_history_replay_result (void *cls, int64_t result,
709                                   const void *data, uint16_t data_size)
710 {
711   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
712               "Test #%u: Guest received history replay result: %" PRId64 "\n"
713               "%.*s\n",
714               test, result, data_size, (const char *) data);
715 //  GNUNET_assert (2 == counter); /* message count */
716 //  GNUNET_assert (7 == result); /* fragment count */
717
718   guest_history_replay_latest ();
719 }
720
721
722 static void
723 guest_history_replay ()
724 {
725   test = TEST_GUEST_HISTORY_REPLAY;
726   counter = 0;
727   GNUNET_SOCIAL_place_history_replay (gst_plc, 1, 3, "",
728                                       GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
729                                       guest_slicer,
730                                       &guest_recv_history_replay_result,
731                                       NULL);
732 }
733
734
735 static void
736 guest_recv_method (void *cls,
737                    const struct GNUNET_PSYC_MessageHeader *msg,
738                    const struct GNUNET_PSYC_MessageMethod *meth,
739                    uint64_t message_id,
740                    const char *method_name)
741 {
742   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
743               "Test #%u: Guest received method for message ID %" PRIu64 ":\n"
744               "%s (flags: %x)\n",
745               test, message_id, method_name, ntohl (meth->flags));
746   /** @todo FIXME: check message */
747 }
748
749
750 static void
751 guest_recv_modifier (void *cls,
752                      const struct GNUNET_PSYC_MessageHeader *msg,
753                      const struct GNUNET_MessageHeader *pmsg,
754                      uint64_t message_id,
755                      enum GNUNET_PSYC_Operator oper,
756                      const char *name,
757                      const void *value,
758                      uint16_t value_size,
759                      uint16_t full_value_size)
760 {
761   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
762               "Test #%u: Guest received modifier for message ID %" PRIu64 ":\n"
763               "%c%s: %.*s (size: %u)\n",
764               test, message_id, oper, name, value_size, (const char *) value, value_size);
765   /** @todo FIXME: check modifier */
766 }
767
768 static void
769 guest_recv_mod_foo_bar (void *cls,
770                         const struct GNUNET_PSYC_MessageHeader *msg,
771                         const struct GNUNET_MessageHeader *pmsg,
772                         uint64_t message_id,
773                         enum GNUNET_PSYC_Operator oper,
774                         const char *name,
775                         const void *value,
776                         uint16_t value_size,
777                         uint16_t full_value_size)
778 {
779   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
780               "Test #%u: Guest received modifier matching _foo_bar for message ID %" PRIu64 ":\n"
781               "%c%s: %.*s (size: %u)\n",
782               test, message_id, oper, name, value_size, (const char *) value, value_size);
783   struct ResultClosure *rc = cls;
784   rc->n++;
785   /** @todo FIXME: check modifier */
786 }
787
788
789 static void
790 guest_recv_data (void *cls,
791                  const struct GNUNET_PSYC_MessageHeader *msg,
792                  const struct GNUNET_MessageHeader *pmsg,
793                  uint64_t message_id,
794                  const void *data,
795                  uint16_t data_size)
796 {
797   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
798               "Test #%u: Guest received data for message ID %" PRIu64 ":\n"
799               "%.*s\n",
800               test, message_id, data_size, (const char *) data);
801   /** @todo FIXME: check data */
802 }
803
804
805 static void
806 guest_recv_eom (void *cls,
807                 const struct GNUNET_PSYC_MessageHeader *msg,
808                 const struct GNUNET_MessageHeader *pmsg,
809                 uint64_t message_id,
810                 uint8_t is_cancelled)
811 {
812   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
813               "Test #%u: Guest received end of message ID %" PRIu64
814               ", cancelled: %u\n",
815               test, message_id, is_cancelled);
816
817   switch (test)
818   {
819   case TEST_HOST_ANNOUNCE:
820     test = TEST_HOST_ANNOUNCE_END;
821     break;
822
823   case TEST_HOST_ANNOUNCE_END:
824     guest_talk ();
825     break;
826
827   case TEST_HOST_ANNOUNCE2:
828     test = TEST_HOST_ANNOUNCE2_END;
829     break;
830
831   case TEST_HOST_ANNOUNCE2_END:
832     guest_history_replay ();
833     break;
834
835   case TEST_GUEST_HISTORY_REPLAY:
836   case TEST_GUEST_HISTORY_REPLAY_LATEST:
837     counter++;
838     break;
839
840   default:
841     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
842     GNUNET_assert (0);
843   }
844 }
845
846
847 static void
848 host_recv_method (void *cls,
849                   const struct GNUNET_PSYC_MessageHeader *msg,
850                   const struct GNUNET_PSYC_MessageMethod *meth,
851                   uint64_t message_id,
852                   const char *method_name)
853 {
854   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
855               "Test #%u: Host received method for message ID %" PRIu64 ":\n"
856               "%s\n",
857               test, message_id, method_name);
858   /** @todo FIXME: check message */
859 }
860
861
862 static void
863 host_recv_modifier (void *cls,
864                     const struct GNUNET_PSYC_MessageHeader *msg,
865                     const struct GNUNET_MessageHeader *pmsg,
866                     uint64_t message_id,
867                     enum GNUNET_PSYC_Operator oper,
868                     const char *name,
869                     const void *value,
870                     uint16_t value_size,
871                     uint16_t full_value_size)
872 {
873   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
874               "Test #%u: Host received modifier for message ID %" PRIu64 ":\n"
875               "%c%s: %.*s\n",
876               test, message_id, oper, name, value_size, (const char *) value);
877 }
878
879
880 static void
881 host_recv_data (void *cls,
882                 const struct GNUNET_PSYC_MessageHeader *msg,
883                 const struct GNUNET_MessageHeader *pmsg,
884                 uint64_t message_id,
885                 const void *data,
886                 uint16_t data_size)
887 {
888   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
889               "Test #%u: Host received data for message ID %" PRIu64 ":\n"
890               "%.*s\n",
891               test, message_id, data_size, (const char *) data);
892 }
893
894
895 static void
896 host_recv_eom (void *cls,
897                const struct GNUNET_PSYC_MessageHeader *msg,
898                const struct GNUNET_MessageHeader *pmsg,
899                uint64_t message_id,
900                uint8_t is_cancelled)
901 {
902   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
903               "Test #%u: Host received end of message ID %" PRIu64
904               ", cancelled: %u\n",
905               test, message_id, is_cancelled);
906
907   switch (test)
908   {
909   case TEST_HOST_ANNOUNCE:
910     test = TEST_HOST_ANNOUNCE_END;
911     break;
912
913   case TEST_HOST_ANNOUNCE_END:
914     guest_talk ();
915     break;
916
917   case TEST_HOST_ANNOUNCE2:
918     test = TEST_HOST_ANNOUNCE2_END;
919     break;
920
921   case TEST_HOST_ANNOUNCE2_END:
922     guest_history_replay ();
923     break;
924
925   case TEST_GUEST_TALK:
926     host_announce2 ();
927     break;
928
929   default:
930     if (TEST_GUEST_LEAVE <= test)
931       break;
932     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
933     GNUNET_assert (0);
934   }
935 }
936
937
938 static void
939 guest_talk ()
940 {
941   test = TEST_GUEST_TALK;
942
943   tmit = (struct TransmitClosure) {};
944   tmit.env = GNUNET_PSYC_env_create ();
945   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
946                        "_bar_foo", DATA2ARG ("one two three"));
947   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
948                        "_bar_baz", DATA2ARG ("four five"));
949   tmit.data[0] = "zzz xxx yyy ";
950   tmit.data[1] = "zyx wvu tsr qpo.\n";
951   tmit.data_delay[1] = 1;
952   tmit.data[2] = "testing ten nine eight.\n";
953   tmit.data_count = 3;
954
955   tmit.guest_talk
956     = GNUNET_SOCIAL_guest_talk (gst, "_converse_guest", tmit.env,
957                                 &notify_data, &tmit,
958                                 GNUNET_SOCIAL_TALK_NONE);
959 }
960
961
962 static void
963 host_announce ()
964 {
965   test = TEST_HOST_ANNOUNCE;
966
967   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
968               "Test #%u: Host announcement.\n", test);
969
970   tmit = (struct TransmitClosure) {};
971   tmit.env = GNUNET_PSYC_env_create ();
972   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
973                        "_foo", DATA2ARG ("bar baz"));
974   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
975                        "_foo_bar", DATA2ARG ("foo bar"));
976   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
977                        "_foo_bar_baz", DATA2ARG ("foo bar baz"));
978   tmit.data[0] = "aaa bbb ccc ";
979   tmit.data[1] = "abc def ghi jkl.\n";
980   tmit.data_delay[1] = 1;
981   tmit.data[2] = "testing one two three ";
982   tmit.data[3] = "four five.\n";
983   tmit.data_count = 4;
984
985   tmit.host_ann
986     = GNUNET_SOCIAL_host_announce (hst, "_converse_host", tmit.env,
987                                    &notify_data, &tmit,
988                                    GNUNET_SOCIAL_ANNOUNCE_NONE);
989 }
990
991
992 static void
993 host_announce2 ()
994 {
995   GNUNET_assert (2 == mod_foo_bar_rcls.n);
996   GNUNET_PSYC_slicer_modifier_remove (guest_slicer, "_foo_bar",
997                                       guest_recv_mod_foo_bar);
998
999   test = TEST_HOST_ANNOUNCE2;
1000
1001   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1002               "Test #%u: Host announcement 2.\n", test);
1003
1004   tmit = (struct TransmitClosure) {};
1005   tmit.env = GNUNET_PSYC_env_create ();
1006   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
1007                        "_foo2", DATA2ARG ("BAR BAZ"));
1008   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
1009                        "_foo2_bar", DATA2ARG ("FOO BAR"));
1010   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
1011                        "_foo2_bar", DATA2ARG ("FOO BAR BAZ"));
1012   tmit.data[0] = "AAA BBB CCC ";
1013   tmit.data[1] = "ABC DEF GHI JKL.\n";
1014   tmit.data[2] = "TESTING ONE TWO THREE.\n";
1015   tmit.data_count = 3;
1016
1017   tmit.host_ann
1018     = GNUNET_SOCIAL_host_announce (hst, "_converse_host_two", tmit.env,
1019                                    &notify_data, &tmit,
1020                                    GNUNET_SOCIAL_ANNOUNCE_NONE);
1021 }
1022
1023
1024 static void
1025 guest_recv_entry_decision (void *cls,
1026                            int is_admitted,
1027                            const struct GNUNET_PSYC_Message *entry_msg)
1028 {
1029   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1030               "Test #%u: Guest received entry decision (try %u): %d.\n",
1031               test, join_req_count, is_admitted);
1032
1033   if (NULL != entry_msg)
1034   {
1035     struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
1036     const char *method_name = NULL;
1037     const void *data = NULL;
1038     uint16_t data_size = 0;
1039     struct GNUNET_PSYC_MessageHeader *
1040       pmsg = GNUNET_PSYC_message_header_create_from_psyc (entry_msg);
1041     GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size);
1042     GNUNET_free (pmsg);
1043
1044     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1045                 "%s\n%.*s\n",
1046                 method_name, data_size, (const char *) data);
1047     /** @todo FIXME: check response message */
1048   }
1049
1050   switch (test)
1051   {
1052   case TEST_GUEST_RECV_ENTRY_DCSN_REFUSE:
1053     GNUNET_assert (GNUNET_NO == is_admitted);
1054     guest_enter ();
1055     break;
1056
1057   case TEST_GUEST_RECV_ENTRY_DCSN_ADMIT:
1058     GNUNET_assert (GNUNET_YES == is_admitted);
1059     host_announce ();
1060     break;
1061
1062   case TEST_GUEST_ENTER_BY_NAME:
1063     GNUNET_SCHEDULER_add_now (&schedule_reconnect, NULL);
1064     break;
1065
1066   default:
1067     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
1068     GNUNET_assert (0);
1069   }
1070 }
1071
1072
1073 static void
1074 host_answer_door (void *cls,
1075                   struct GNUNET_SOCIAL_Nym *nym,
1076                   const char *method_name,
1077                   struct GNUNET_PSYC_Environment *env,
1078                   const void *data,
1079                   size_t data_size)
1080 {
1081   join_req_count++;
1082
1083   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1084               "Test #%u: Host received entry request from guest (try %u).\n",
1085               test, join_req_count);
1086   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1087               "%s\n%.*s\n",
1088               method_name, data_size, (const char *) data);
1089
1090   switch (test)
1091   {
1092   case TEST_HOST_ANSWER_DOOR_REFUSE:
1093     test = TEST_GUEST_RECV_ENTRY_DCSN_REFUSE;
1094     join_resp = GNUNET_PSYC_message_create ("_notice_place_refuse", env,
1095                                             DATA2ARG ("Go away!"));
1096     GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_NO, join_resp);
1097     break;
1098
1099   case TEST_HOST_ANSWER_DOOR_ADMIT:
1100     test = TEST_GUEST_RECV_ENTRY_DCSN_ADMIT;
1101     // fall through
1102
1103   case TEST_GUEST_ENTER_BY_NAME:
1104     join_resp = GNUNET_PSYC_message_create ("_notice_place_admit", env,
1105                                             DATA2ARG ("Welcome, nym!"));
1106     GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp);
1107     break;
1108
1109   default:
1110     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
1111     GNUNET_assert (0);
1112   }
1113 }
1114
1115
1116 static void
1117 guest_recv_local_enter (void *cls, int result,
1118                         const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
1119                         uint64_t max_message_id)
1120 {
1121   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1122               "Test #%u: Guest entered to local place: %d\n",
1123               test, result);
1124   GNUNET_assert (0 <= result);
1125 }
1126
1127
1128 static void
1129 guest_enter ()
1130 {
1131   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1132               "Test #%u: Entering to place as guest.\n", test);
1133
1134   struct GuestEnterMessage *emsg = &guest_enter_msg;
1135
1136   emsg->method_name = "_request_enter";
1137   emsg->env = GNUNET_PSYC_env_create ();
1138   GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
1139                        "_abc", "abc def", 7);
1140   GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
1141                        "_abc_def", "abc def ghi", 11);
1142   emsg->data = "let me in";
1143   emsg->data_size = strlen (emsg->data) + 1;
1144   emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
1145                                           emsg->data, emsg->data_size);
1146
1147   gst = GNUNET_SOCIAL_guest_enter (app, guest_ego, &place_pub_key,
1148                                    GNUNET_PSYC_SLAVE_JOIN_NONE,
1149                                    &this_peer, 0, NULL, emsg->msg, guest_slicer,
1150                                    guest_recv_local_enter,
1151                                    guest_recv_entry_decision, NULL);
1152   gst_plc = GNUNET_SOCIAL_guest_get_place (gst);
1153
1154   GNUNET_SOCIAL_place_msg_proc_set (gst_plc, "_converse",
1155                                     GNUNET_SOCIAL_MSG_PROC_SAVE);
1156 }
1157
1158
1159 static void
1160 guest_enter_by_name ()
1161 {
1162   test = TEST_GUEST_ENTER_BY_NAME;
1163   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1164               "Test #%u: Entering to place by name as guest.\n", test);
1165
1166   struct GuestEnterMessage *emsg = &guest_enter_msg;
1167
1168   emsg->method_name = "_request_enter";
1169   emsg->env = GNUNET_PSYC_env_create ();
1170   GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
1171                        "_abc", "abc def", 7);
1172   GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
1173                        "_abc_def", "abc def ghi", 11);
1174   emsg->data = "let me in";
1175   emsg->data_size = strlen (emsg->data) + 1;
1176   emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
1177                                           emsg->data, emsg->data_size);
1178
1179   gst = GNUNET_SOCIAL_guest_enter_by_name (app, guest_ego,
1180                                            "home.host.gnu", "let.me*in!",
1181                                            emsg->msg, guest_slicer,
1182                                            guest_recv_local_enter,
1183                                            guest_recv_entry_decision, NULL);
1184   gst_plc = GNUNET_SOCIAL_guest_get_place (gst);
1185 }
1186
1187
1188 static void
1189 app_recv_zone_add_nym_result (void *cls, int64_t result,
1190                               const void *data, uint16_t data_size)
1191 {
1192   GNUNET_assert (GNUNET_YES == result);
1193   is_guest_nym_added = GNUNET_YES;
1194 }
1195
1196
1197 static void
1198 guest_init ()
1199 {
1200   guest_pub_key = *(GNUNET_SOCIAL_ego_get_pub_key (guest_ego));
1201
1202   guest_slicer = GNUNET_PSYC_slicer_create ();
1203   GNUNET_PSYC_slicer_method_add (guest_slicer, "", NULL,
1204                                  guest_recv_method, guest_recv_modifier,
1205                                  guest_recv_data, guest_recv_eom, NULL);
1206   GNUNET_PSYC_slicer_modifier_add (guest_slicer, "_foo_bar",
1207                                    guest_recv_mod_foo_bar, &mod_foo_bar_rcls);
1208   test = TEST_HOST_ANSWER_DOOR_ADMIT;
1209
1210   GNUNET_SOCIAL_zone_add_nym (app, guest_ego, "host", &host_pub_key,
1211                               GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
1212                               app_recv_zone_add_nym_result, NULL);
1213   guest_enter ();
1214 }
1215
1216
1217 static void
1218 id_guest_created (void *cls, const char *emsg)
1219 {
1220   if (NULL != emsg)
1221   {
1222     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1223                 "Could not create guest identity: %s\n", emsg);
1224 #if ! DEBUG_TEST_SOCIAL
1225     GNUNET_assert (0);
1226 #endif
1227   }
1228   if (NULL != guest_ego)
1229     guest_init ();
1230 }
1231
1232
1233 static void
1234 host_entered (void *cls, int result,
1235               const struct GNUNET_CRYPTO_EddsaPublicKey *home_pub_key,
1236               uint64_t max_message_id)
1237 {
1238   place_pub_key = *home_pub_key;
1239   GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
1240   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1241               "Host entered to place %s\n", GNUNET_h2s (&place_pub_hash));
1242
1243   test = TEST_GUEST_CREATE;
1244   GNUNET_IDENTITY_create (id, guest_name, &id_guest_created, NULL);
1245 }
1246
1247
1248 static void
1249 host_enter ()
1250 {
1251   host_slicer = GNUNET_PSYC_slicer_create ();
1252   GNUNET_PSYC_slicer_method_add (host_slicer, "", NULL,
1253                                  host_recv_method, host_recv_modifier,
1254                                  host_recv_data, host_recv_eom, NULL);
1255
1256   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering to place as host.\n");
1257   test = TEST_HOST_ENTER;
1258   hst = GNUNET_SOCIAL_host_enter (app, host_ego,
1259                                   GNUNET_PSYC_CHANNEL_PRIVATE,
1260                                   host_slicer, host_entered,
1261                                   host_answer_door, host_farewell, NULL);
1262   hst_plc = GNUNET_SOCIAL_host_get_place (hst);
1263
1264   GNUNET_SOCIAL_place_msg_proc_set (hst_plc, "_converse",
1265                                     GNUNET_SOCIAL_MSG_PROC_RELAY);
1266 }
1267
1268
1269 static void
1270 id_host_created (void *cls, const char *emsg)
1271 {
1272   if (NULL != core)
1273   {
1274     GNUNET_CORE_disconnect (core);
1275     core = NULL;
1276   }
1277
1278   if (NULL != emsg)
1279   {
1280     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1281                 "Could not create host identity: %s\n", emsg);
1282 #if ! DEBUG_TEST_SOCIAL
1283     GNUNET_assert (0);
1284 #endif
1285   }
1286
1287   app = GNUNET_SOCIAL_app_connect (cfg, app_id,
1288                                    app_recv_ego,
1289                                    app_recv_host,
1290                                    app_recv_guest,
1291                                    app_connected,
1292                                    NULL);
1293 }
1294
1295
1296 static void
1297 identity_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego,
1298                  void **ctx, const char *name)
1299 {
1300 }
1301
1302
1303 static void
1304 core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity)
1305 {
1306   this_peer = *my_identity;
1307   id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL);
1308
1309   test = TEST_HOST_CREATE;
1310   GNUNET_IDENTITY_create (id, host_name, &id_host_created, NULL);
1311 }
1312
1313
1314 /**
1315  * Main function of the test, run from scheduler.
1316  *
1317  * @param cls NULL
1318  * @param cfg configuration we use (also to connect to Social service)
1319  * @param peer handle to access more of the peer (not used)
1320  */
1321 static void
1322 #if DEBUG_TEST_SOCIAL
1323 run (void *cls, char *const *args, const char *cfgfile,
1324      const struct GNUNET_CONFIGURATION_Handle *c)
1325 #else
1326 run (void *cls,
1327      const struct GNUNET_CONFIGURATION_Handle *c,
1328      struct GNUNET_TESTING_Peer *peer)
1329 #endif
1330 {
1331   cfg = c;
1332   end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1333                                                  &end_badly, NULL);
1334
1335   core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL,
1336                               NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
1337 }
1338
1339
1340 int
1341 main (int argc, char *argv[])
1342 {
1343   res = 1;
1344 #if DEBUG_TEST_SOCIAL
1345   const struct GNUNET_GETOPT_CommandLineOption opts[] = {
1346     GNUNET_GETOPT_OPTION_END
1347   };
1348   if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-social",
1349                                        "test-social [options]",
1350                                        opts, &run, NULL))
1351     return 1;
1352 #else
1353   if (0 != GNUNET_TESTING_peer_run ("test-social", "test_social.conf", &run, NULL))
1354     return 1;
1355 #endif
1356   return res;
1357 }
1358
1359 /* end of test_social.c */