-rps: logging
[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   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
467               "Got app ego notification: %p %s %s\n",
468               ego, name,
469               GNUNET_CRYPTO_ecdsa_public_key_to_string (ego_pub_key));
470
471   if (NULL != strstr (name, host_name) && TEST_HOST_CREATE == test)
472   {
473     host_ego = ego;
474     host_pub_key = *(GNUNET_SOCIAL_ego_get_pub_key (host_ego));
475     GNUNET_assert (TEST_HOST_CREATE == test);
476     host_enter ();
477   }
478   else if (NULL != strstr (name, guest_name))
479   {
480     guest_ego = ego;
481
482     if (TEST_GUEST_CREATE == test)
483       guest_init ();
484   }
485 }
486
487
488 static void
489 schedule_reconnect (void *cls)
490 {
491   test = TEST_RECONNECT;
492
493   GNUNET_SOCIAL_host_disconnect (hst, NULL, NULL);
494   GNUNET_SOCIAL_guest_disconnect (gst, NULL, NULL);
495   hst = NULL;
496   gst = NULL;
497
498   GNUNET_SOCIAL_app_disconnect (app, NULL, NULL);
499   app = GNUNET_SOCIAL_app_connect (cfg, app_id,
500                                    app_recv_ego,
501                                    app_recv_host,
502                                    app_recv_guest,
503                                    app_connected,
504                                    NULL);
505 }
506
507
508 static void
509 host_recv_zone_add_place_result (void *cls, int64_t result,
510                                  const void *data, uint16_t data_size)
511 {
512   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
513               "Test #%u: Zone add place result: %" PRId64 " (%.*s).\n",
514               test, result, data_size, (const char *) data);
515   GNUNET_assert (GNUNET_YES == result);
516
517   GNUNET_assert (GNUNET_YES == is_guest_nym_added);
518   guest_enter_by_name ();
519 }
520
521
522 static void
523 zone_add_place ()
524 {
525   test = TEST_ZONE_ADD_PLACE;
526   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
527               "Test #%u: Adding place to zone.\n", test);
528
529   GNUNET_SOCIAL_zone_add_place (app, host_ego, "home", "let.me*in!",
530                                 &place_pub_key, &this_peer, 1, &this_peer,
531                                 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
532                                 host_recv_zone_add_place_result, app);
533 }
534
535
536 static void
537 host_farewell (void *cls,
538                const struct GNUNET_SOCIAL_Nym *nym,
539                struct GNUNET_PSYC_Environment *env)
540 {
541   const struct GNUNET_CRYPTO_EcdsaPublicKey *
542     nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym);
543
544   char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
545   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
546               "Farewell: nym %s (%s) has left the place.\n",
547               GNUNET_h2s (GNUNET_SOCIAL_nym_get_pub_key_hash (nym)), str);
548   GNUNET_free (str);
549   GNUNET_assert (1 == GNUNET_PSYC_env_get_count (env));
550   if (0 != memcmp (&guest_pub_key, nym_key, sizeof (*nym_key)))
551   {
552     str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&guest_pub_key);
553     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
554                 "Farewell: nym does not match guest: %s\n", str);
555     GNUNET_free (str);
556     GNUNET_assert (0);
557   }
558   zone_add_place ();
559 }
560
561
562 static void
563 guest_left (void *cls)
564 {
565   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
566               "The guest has left the place.\n");
567 }
568
569
570 static void
571 guest_leave()
572 {
573   if (test < TEST_RECONNECT)
574     test = TEST_GUEST_LEAVE;
575   else
576     test = TEST_GUEST_LEAVE2;
577
578   struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
579   GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
580                        "_notice_place_leave", DATA2ARG ("Leaving."));
581   GNUNET_SOCIAL_guest_leave (gst, env, &guest_left, NULL);
582   GNUNET_PSYC_env_destroy (env);
583   gst = NULL;
584   gst_plc = NULL;
585 }
586
587
588 static void
589 schedule_guest_leave (void *cls)
590 {
591   guest_leave ();
592 }
593
594
595 static void
596 guest_look_for_result (void *cls,
597                        int64_t result_code,
598                        const void *data,
599                        uint16_t data_size)
600 {
601   struct ResultClosure *rcls = cls;
602   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
603               "guest_look_for_result: %" PRId64 "\n", result_code);
604   GNUNET_assert (GNUNET_OK == result_code);
605   GNUNET_assert (3 == rcls->n);
606   GNUNET_free (rcls);
607   GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
608 }
609
610
611 static void
612 guest_look_for_var (void *cls,
613                    const struct GNUNET_MessageHeader *mod,
614                    const char *name,
615                    const void *value,
616                    uint32_t value_size,
617                    uint32_t full_value_size)
618 {
619   struct ResultClosure *rcls = cls;
620   rcls->n++;
621   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
622               "guest_look_for_var: %s\n%.*s\n",
623               name, value_size, (const char *) value);
624 }
625
626
627 static void
628 guest_look_for ()
629 {
630   test = TEST_GUEST_LOOK_FOR;
631   struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls));
632   GNUNET_SOCIAL_place_look_for (gst_plc, "_foo", guest_look_for_var, guest_look_for_result, rcls);
633 }
634
635
636 static void
637 guest_look_at_result (void *cls, int64_t result_code,
638                       const void *data, uint16_t data_size)
639 {
640   struct ResultClosure *rcls = cls;
641
642   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
643               "guest_look_at_result: %" PRId64 "\n", result_code);
644   GNUNET_assert (GNUNET_OK == result_code);
645   GNUNET_assert (1 == rcls->n);
646   GNUNET_free (rcls);
647   guest_look_for ();
648 }
649
650
651 static void
652 guest_look_at_var (void *cls,
653                    const struct GNUNET_MessageHeader *mod,
654                    const char *name,
655                    const void *value,
656                    uint32_t value_size,
657                    uint32_t full_value_size)
658 {
659   struct ResultClosure *rcls = cls;
660   rcls->n++;
661
662   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
663               "guest_look_at_var: %s\n%.*s\n",
664               name, value_size, (const char *) value);
665 }
666
667
668 static void
669 guest_look_at ()
670 {
671   test = TEST_GUEST_LOOK_AT;
672   struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls));
673   GNUNET_SOCIAL_place_look_at (gst_plc, "_foo_bar", guest_look_at_var, guest_look_at_result, rcls);
674 }
675
676
677 static void
678 guest_recv_history_replay_latest_result (void *cls, int64_t result,
679                                          const void *data, uint16_t data_size)
680 {
681   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
682               "Test #%u: Guest received latest history replay result "
683               "(%" PRIu32 " messages, %" PRId64 " fragments):\n"
684               "%.*s\n",
685               test, counter, result, data_size, (const char *) data);
686   //GNUNET_assert (2 == counter); /* message count */
687   //GNUNET_assert (7 == result); /* fragment count */
688
689   guest_look_at ();
690 }
691
692
693 static void
694 guest_history_replay_latest ()
695 {
696   test = TEST_GUEST_HISTORY_REPLAY_LATEST;
697   counter = 0;
698   GNUNET_SOCIAL_place_history_replay_latest (gst_plc, 3, "",
699                                              GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
700                                              guest_slicer,
701                                              &guest_recv_history_replay_latest_result,
702                                              NULL);
703 }
704
705
706 static void
707 guest_recv_history_replay_result (void *cls, int64_t result,
708                                   const void *data, uint16_t data_size)
709 {
710   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
711               "Test #%u: Guest received history replay result: %" PRId64 "\n"
712               "%.*s\n",
713               test, result, data_size, (const char *) data);
714 //  GNUNET_assert (2 == counter); /* message count */
715 //  GNUNET_assert (7 == result); /* fragment count */
716
717   guest_history_replay_latest ();
718 }
719
720
721 static void
722 guest_history_replay ()
723 {
724   test = TEST_GUEST_HISTORY_REPLAY;
725   counter = 0;
726   GNUNET_SOCIAL_place_history_replay (gst_plc, 1, 3, "",
727                                       GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
728                                       guest_slicer,
729                                       &guest_recv_history_replay_result,
730                                       NULL);
731 }
732
733
734 static void
735 guest_recv_method (void *cls,
736                    const struct GNUNET_PSYC_MessageHeader *msg,
737                    const struct GNUNET_PSYC_MessageMethod *meth,
738                    uint64_t message_id,
739                    const char *method_name)
740 {
741   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
742               "Test #%u: Guest received method for message ID %" PRIu64 ":\n"
743               "%s (flags: %x)\n",
744               test, message_id, method_name, ntohl (meth->flags));
745   /** @todo FIXME: check message */
746 }
747
748
749 static void
750 guest_recv_modifier (void *cls,
751                      const struct GNUNET_PSYC_MessageHeader *msg,
752                      const struct GNUNET_MessageHeader *pmsg,
753                      uint64_t message_id,
754                      enum GNUNET_PSYC_Operator oper,
755                      const char *name,
756                      const void *value,
757                      uint16_t value_size,
758                      uint16_t full_value_size)
759 {
760   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
761               "Test #%u: Guest received modifier for message ID %" PRIu64 ":\n"
762               "%c%s: %.*s (size: %u)\n",
763               test, message_id, oper, name, value_size, (const char *) value, value_size);
764   /** @todo FIXME: check modifier */
765 }
766
767 static void
768 guest_recv_mod_foo_bar (void *cls,
769                         const struct GNUNET_PSYC_MessageHeader *msg,
770                         const struct GNUNET_MessageHeader *pmsg,
771                         uint64_t message_id,
772                         enum GNUNET_PSYC_Operator oper,
773                         const char *name,
774                         const void *value,
775                         uint16_t value_size,
776                         uint16_t full_value_size)
777 {
778   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
779               "Test #%u: Guest received modifier matching _foo_bar for message ID %" PRIu64 ":\n"
780               "%c%s: %.*s (size: %u)\n",
781               test, message_id, oper, name, value_size, (const char *) value, value_size);
782   struct ResultClosure *rc = cls;
783   rc->n++;
784   /** @todo FIXME: check modifier */
785 }
786
787
788 static void
789 guest_recv_data (void *cls,
790                  const struct GNUNET_PSYC_MessageHeader *msg,
791                  const struct GNUNET_MessageHeader *pmsg,
792                  uint64_t message_id,
793                  const void *data,
794                  uint16_t data_size)
795 {
796   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
797               "Test #%u: Guest received data for message ID %" PRIu64 ":\n"
798               "%.*s\n",
799               test, message_id, data_size, (const char *) data);
800   /** @todo FIXME: check data */
801 }
802
803
804 static void
805 guest_recv_eom (void *cls,
806                 const struct GNUNET_PSYC_MessageHeader *msg,
807                 const struct GNUNET_MessageHeader *pmsg,
808                 uint64_t message_id,
809                 uint8_t is_cancelled)
810 {
811   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
812               "Test #%u: Guest received end of message ID %" PRIu64
813               ", cancelled: %u\n",
814               test, message_id, is_cancelled);
815
816   switch (test)
817   {
818   case TEST_HOST_ANNOUNCE:
819     test = TEST_HOST_ANNOUNCE_END;
820     break;
821
822   case TEST_HOST_ANNOUNCE_END:
823     guest_talk ();
824     break;
825
826   case TEST_HOST_ANNOUNCE2:
827     test = TEST_HOST_ANNOUNCE2_END;
828     break;
829
830   case TEST_HOST_ANNOUNCE2_END:
831     guest_history_replay ();
832     break;
833
834   case TEST_GUEST_HISTORY_REPLAY:
835   case TEST_GUEST_HISTORY_REPLAY_LATEST:
836     counter++;
837     break;
838
839   default:
840     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
841     GNUNET_assert (0);
842   }
843 }
844
845
846 static void
847 host_recv_method (void *cls,
848                   const struct GNUNET_PSYC_MessageHeader *msg,
849                   const struct GNUNET_PSYC_MessageMethod *meth,
850                   uint64_t message_id,
851                   const char *method_name)
852 {
853   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
854               "Test #%u: Host received method for message ID %" PRIu64 ":\n"
855               "%s\n",
856               test, message_id, method_name);
857   /** @todo FIXME: check message */
858 }
859
860
861 static void
862 host_recv_modifier (void *cls,
863                     const struct GNUNET_PSYC_MessageHeader *msg,
864                     const struct GNUNET_MessageHeader *pmsg,
865                     uint64_t message_id,
866                     enum GNUNET_PSYC_Operator oper,
867                     const char *name,
868                     const void *value,
869                     uint16_t value_size,
870                     uint16_t full_value_size)
871 {
872   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
873               "Test #%u: Host received modifier for message ID %" PRIu64 ":\n"
874               "%c%s: %.*s\n",
875               test, message_id, oper, name, value_size, (const char *) value);
876 }
877
878
879 static void
880 host_recv_data (void *cls,
881                 const struct GNUNET_PSYC_MessageHeader *msg,
882                 const struct GNUNET_MessageHeader *pmsg,
883                 uint64_t message_id,
884                 const void *data,
885                 uint16_t data_size)
886 {
887   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
888               "Test #%u: Host received data for message ID %" PRIu64 ":\n"
889               "%.*s\n",
890               test, message_id, data_size, (const char *) data);
891 }
892
893
894 static void
895 host_recv_eom (void *cls,
896                const struct GNUNET_PSYC_MessageHeader *msg,
897                const struct GNUNET_MessageHeader *pmsg,
898                uint64_t message_id,
899                uint8_t is_cancelled)
900 {
901   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
902               "Test #%u: Host received end of message ID %" PRIu64
903               ", cancelled: %u\n",
904               test, message_id, is_cancelled);
905
906   switch (test)
907   {
908   case TEST_HOST_ANNOUNCE:
909     test = TEST_HOST_ANNOUNCE_END;
910     break;
911
912   case TEST_HOST_ANNOUNCE_END:
913     guest_talk ();
914     break;
915
916   case TEST_HOST_ANNOUNCE2:
917     test = TEST_HOST_ANNOUNCE2_END;
918     break;
919
920   case TEST_HOST_ANNOUNCE2_END:
921     guest_history_replay ();
922     break;
923
924   case TEST_GUEST_TALK:
925     host_announce2 ();
926     break;
927
928   default:
929     if (TEST_GUEST_LEAVE <= test)
930       break;
931     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
932     GNUNET_assert (0);
933   }
934 }
935
936
937 static void
938 guest_talk ()
939 {
940   test = TEST_GUEST_TALK;
941
942   tmit = (struct TransmitClosure) {};
943   tmit.env = GNUNET_PSYC_env_create ();
944   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
945                        "_bar_foo", DATA2ARG ("one two three"));
946   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
947                        "_bar_baz", DATA2ARG ("four five"));
948   tmit.data[0] = "zzz xxx yyy ";
949   tmit.data[1] = "zyx wvu tsr qpo.\n";
950   tmit.data_delay[1] = 1;
951   tmit.data[2] = "testing ten nine eight.\n";
952   tmit.data_count = 3;
953
954   tmit.guest_talk
955     = GNUNET_SOCIAL_guest_talk (gst, "_converse_guest", tmit.env,
956                                 &notify_data, &tmit,
957                                 GNUNET_SOCIAL_TALK_NONE);
958 }
959
960
961 static void
962 host_announce ()
963 {
964   test = TEST_HOST_ANNOUNCE;
965
966   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
967               "Test #%u: Host announcement.\n", test);
968
969   tmit = (struct TransmitClosure) {};
970   tmit.env = GNUNET_PSYC_env_create ();
971   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
972                        "_foo", DATA2ARG ("bar baz"));
973   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
974                        "_foo_bar", DATA2ARG ("foo bar"));
975   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
976                        "_foo_bar_baz", DATA2ARG ("foo bar baz"));
977   tmit.data[0] = "aaa bbb ccc ";
978   tmit.data[1] = "abc def ghi jkl.\n";
979   tmit.data_delay[1] = 1;
980   tmit.data[2] = "testing one two three ";
981   tmit.data[3] = "four five.\n";
982   tmit.data_count = 4;
983
984   tmit.host_ann
985     = GNUNET_SOCIAL_host_announce (hst, "_converse_host", tmit.env,
986                                    &notify_data, &tmit,
987                                    GNUNET_SOCIAL_ANNOUNCE_NONE);
988 }
989
990
991 static void
992 host_announce2 ()
993 {
994   GNUNET_assert (2 == mod_foo_bar_rcls.n);
995   GNUNET_PSYC_slicer_modifier_remove (guest_slicer, "_foo_bar",
996                                       guest_recv_mod_foo_bar);
997
998   test = TEST_HOST_ANNOUNCE2;
999
1000   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1001               "Test #%u: Host announcement 2.\n", test);
1002
1003   tmit = (struct TransmitClosure) {};
1004   tmit.env = GNUNET_PSYC_env_create ();
1005   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
1006                        "_foo2", DATA2ARG ("BAR BAZ"));
1007   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
1008                        "_foo2_bar", DATA2ARG ("FOO BAR"));
1009   GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
1010                        "_foo2_bar", DATA2ARG ("FOO BAR BAZ"));
1011   tmit.data[0] = "AAA BBB CCC ";
1012   tmit.data[1] = "ABC DEF GHI JKL.\n";
1013   tmit.data[2] = "TESTING ONE TWO THREE.\n";
1014   tmit.data_count = 3;
1015
1016   tmit.host_ann
1017     = GNUNET_SOCIAL_host_announce (hst, "_converse_host_two", tmit.env,
1018                                    &notify_data, &tmit,
1019                                    GNUNET_SOCIAL_ANNOUNCE_NONE);
1020 }
1021
1022
1023 static void
1024 guest_recv_entry_decision (void *cls,
1025                            int is_admitted,
1026                            const struct GNUNET_PSYC_Message *entry_msg)
1027 {
1028   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1029               "Test #%u: Guest received entry decision (try %u): %d.\n",
1030               test, join_req_count, is_admitted);
1031
1032   if (NULL != entry_msg)
1033   {
1034     struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
1035     const char *method_name = NULL;
1036     const void *data = NULL;
1037     uint16_t data_size = 0;
1038     struct GNUNET_PSYC_MessageHeader *
1039       pmsg = GNUNET_PSYC_message_header_create_from_psyc (entry_msg);
1040     GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size);
1041     GNUNET_free (pmsg);
1042
1043     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1044                 "%s\n%.*s\n",
1045                 method_name, data_size, (const char *) data);
1046     /** @todo FIXME: check response message */
1047   }
1048
1049   switch (test)
1050   {
1051   case TEST_GUEST_RECV_ENTRY_DCSN_REFUSE:
1052     GNUNET_assert (GNUNET_NO == is_admitted);
1053     guest_enter ();
1054     break;
1055
1056   case TEST_GUEST_RECV_ENTRY_DCSN_ADMIT:
1057     GNUNET_assert (GNUNET_YES == is_admitted);
1058     host_announce ();
1059     break;
1060
1061   case TEST_GUEST_ENTER_BY_NAME:
1062     GNUNET_SCHEDULER_add_now (&schedule_reconnect, NULL);
1063     break;
1064
1065   default:
1066     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
1067     GNUNET_assert (0);
1068   }
1069 }
1070
1071
1072 static void
1073 host_answer_door (void *cls,
1074                   struct GNUNET_SOCIAL_Nym *nym,
1075                   const char *method_name,
1076                   struct GNUNET_PSYC_Environment *env,
1077                   const void *data,
1078                   size_t data_size)
1079 {
1080   join_req_count++;
1081
1082   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1083               "Test #%u: Host received entry request from guest (try %u).\n",
1084               test, join_req_count);
1085   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1086               "%s\n%.*s\n",
1087               method_name, data_size, (const char *) data);
1088
1089   switch (test)
1090   {
1091   case TEST_HOST_ANSWER_DOOR_REFUSE:
1092     test = TEST_GUEST_RECV_ENTRY_DCSN_REFUSE;
1093     join_resp = GNUNET_PSYC_message_create ("_notice_place_refuse", env,
1094                                             DATA2ARG ("Go away!"));
1095     GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_NO, join_resp);
1096     break;
1097
1098   case TEST_HOST_ANSWER_DOOR_ADMIT:
1099     test = TEST_GUEST_RECV_ENTRY_DCSN_ADMIT;
1100   case TEST_GUEST_ENTER_BY_NAME:
1101     join_resp = GNUNET_PSYC_message_create ("_notice_place_admit", env,
1102                                             DATA2ARG ("Welcome, nym!"));
1103     GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp);
1104     break;
1105
1106   default:
1107     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
1108     GNUNET_assert (0);
1109   }
1110 }
1111
1112
1113 static void
1114 guest_recv_local_enter (void *cls, int result,
1115                         const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
1116                         uint64_t max_message_id)
1117 {
1118   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1119               "Test #%u: Guest entered to local place: %d\n",
1120               test, result);
1121   GNUNET_assert (0 <= result);
1122 }
1123
1124
1125 static void
1126 guest_enter ()
1127 {
1128   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1129               "Test #%u: Entering to place as guest.\n", test);
1130
1131   struct GuestEnterMessage *emsg = &guest_enter_msg;
1132
1133   emsg->method_name = "_request_enter";
1134   emsg->env = GNUNET_PSYC_env_create ();
1135   GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
1136                        "_abc", "abc def", 7);
1137   GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
1138                        "_abc_def", "abc def ghi", 11);
1139   emsg->data = "let me in";
1140   emsg->data_size = strlen (emsg->data) + 1;
1141   emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
1142                                           emsg->data, emsg->data_size);
1143
1144   gst = GNUNET_SOCIAL_guest_enter (app, guest_ego, &place_pub_key,
1145                                    GNUNET_PSYC_SLAVE_JOIN_NONE,
1146                                    &this_peer, 0, NULL, emsg->msg, guest_slicer,
1147                                    guest_recv_local_enter,
1148                                    guest_recv_entry_decision, NULL);
1149   gst_plc = GNUNET_SOCIAL_guest_get_place (gst);
1150
1151   GNUNET_SOCIAL_place_msg_proc_set (gst_plc, "_converse",
1152                                     GNUNET_SOCIAL_MSG_PROC_SAVE);
1153 }
1154
1155
1156 static void
1157 guest_enter_by_name ()
1158 {
1159   test = TEST_GUEST_ENTER_BY_NAME;
1160   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1161               "Test #%u: Entering to place by name as guest.\n", test);
1162
1163   struct GuestEnterMessage *emsg = &guest_enter_msg;
1164
1165   emsg->method_name = "_request_enter";
1166   emsg->env = GNUNET_PSYC_env_create ();
1167   GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
1168                        "_abc", "abc def", 7);
1169   GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
1170                        "_abc_def", "abc def ghi", 11);
1171   emsg->data = "let me in";
1172   emsg->data_size = strlen (emsg->data) + 1;
1173   emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
1174                                           emsg->data, emsg->data_size);
1175
1176   gst = GNUNET_SOCIAL_guest_enter_by_name (app, guest_ego,
1177                                            "home.host.gnu", "let.me*in!",
1178                                            emsg->msg, guest_slicer,
1179                                            guest_recv_local_enter,
1180                                            guest_recv_entry_decision, NULL);
1181   gst_plc = GNUNET_SOCIAL_guest_get_place (gst);
1182 }
1183
1184
1185 static void
1186 app_recv_zone_add_nym_result (void *cls, int64_t result,
1187                               const void *data, uint16_t data_size)
1188 {
1189   GNUNET_assert (GNUNET_YES == result);
1190   is_guest_nym_added = GNUNET_YES;
1191 }
1192
1193
1194 static void
1195 guest_init ()
1196 {
1197   guest_pub_key = *(GNUNET_SOCIAL_ego_get_pub_key (guest_ego));
1198
1199   guest_slicer = GNUNET_PSYC_slicer_create ();
1200   GNUNET_PSYC_slicer_method_add (guest_slicer, "", NULL,
1201                                  guest_recv_method, guest_recv_modifier,
1202                                  guest_recv_data, guest_recv_eom, NULL);
1203   GNUNET_PSYC_slicer_modifier_add (guest_slicer, "_foo_bar",
1204                                    guest_recv_mod_foo_bar, &mod_foo_bar_rcls);
1205   test = TEST_HOST_ANSWER_DOOR_ADMIT;
1206
1207   GNUNET_SOCIAL_zone_add_nym (app, guest_ego, "host", &host_pub_key,
1208                               GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
1209                               app_recv_zone_add_nym_result, NULL);
1210   guest_enter ();
1211 }
1212
1213
1214 static void
1215 id_guest_created (void *cls, const char *emsg)
1216 {
1217   if (NULL != emsg)
1218   {
1219     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1220                 "Could not create guest identity: %s\n", emsg);
1221 #if ! DEBUG_TEST_SOCIAL
1222     GNUNET_assert (0);
1223 #endif
1224   }
1225   if (NULL != guest_ego)
1226     guest_init ();
1227 }
1228
1229
1230 static void
1231 host_entered (void *cls, int result,
1232               const struct GNUNET_CRYPTO_EddsaPublicKey *home_pub_key,
1233               uint64_t max_message_id)
1234 {
1235   place_pub_key = *home_pub_key;
1236   GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
1237   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1238               "Host entered to place %s\n", GNUNET_h2s (&place_pub_hash));
1239
1240   test = TEST_GUEST_CREATE;
1241   GNUNET_IDENTITY_create (id, guest_name, &id_guest_created, NULL);
1242 }
1243
1244
1245 static void
1246 host_enter ()
1247 {
1248   host_slicer = GNUNET_PSYC_slicer_create ();
1249   GNUNET_PSYC_slicer_method_add (host_slicer, "", NULL,
1250                                  host_recv_method, host_recv_modifier,
1251                                  host_recv_data, host_recv_eom, NULL);
1252
1253   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering to place as host.\n");
1254   test = TEST_HOST_ENTER;
1255   hst = GNUNET_SOCIAL_host_enter (app, host_ego,
1256                                   GNUNET_PSYC_CHANNEL_PRIVATE,
1257                                   host_slicer, host_entered,
1258                                   host_answer_door, host_farewell, NULL);
1259   hst_plc = GNUNET_SOCIAL_host_get_place (hst);
1260
1261   GNUNET_SOCIAL_place_msg_proc_set (hst_plc, "_converse",
1262                                     GNUNET_SOCIAL_MSG_PROC_RELAY);
1263 }
1264
1265
1266 static void
1267 id_host_created (void *cls, const char *emsg)
1268 {
1269   if (NULL != core)
1270   {
1271     GNUNET_CORE_disconnect (core);
1272     core = NULL;
1273   }
1274
1275   if (NULL != emsg)
1276   {
1277     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1278                 "Could not create host identity: %s\n", emsg);
1279 #if ! DEBUG_TEST_SOCIAL
1280     GNUNET_assert (0);
1281 #endif
1282   }
1283
1284   app = GNUNET_SOCIAL_app_connect (cfg, app_id,
1285                                    app_recv_ego,
1286                                    app_recv_host,
1287                                    app_recv_guest,
1288                                    app_connected,
1289                                    NULL);
1290 }
1291
1292
1293 static void
1294 identity_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego,
1295                  void **ctx, const char *name)
1296 {
1297 }
1298
1299
1300 static void
1301 core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity)
1302 {
1303   this_peer = *my_identity;
1304   id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL);
1305
1306   test = TEST_HOST_CREATE;
1307   GNUNET_IDENTITY_create (id, host_name, &id_host_created, NULL);
1308 }
1309
1310
1311 /**
1312  * Main function of the test, run from scheduler.
1313  *
1314  * @param cls NULL
1315  * @param cfg configuration we use (also to connect to Social service)
1316  * @param peer handle to access more of the peer (not used)
1317  */
1318 static void
1319 #if DEBUG_TEST_SOCIAL
1320 run (void *cls, char *const *args, const char *cfgfile,
1321      const struct GNUNET_CONFIGURATION_Handle *c)
1322 #else
1323 run (void *cls,
1324      const struct GNUNET_CONFIGURATION_Handle *c,
1325      struct GNUNET_TESTING_Peer *peer)
1326 #endif
1327 {
1328   cfg = c;
1329   end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1330                                                  &end_badly, NULL);
1331
1332   core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL,
1333                               NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
1334 }
1335
1336
1337 int
1338 main (int argc, char *argv[])
1339 {
1340   res = 1;
1341 #if DEBUG_TEST_SOCIAL
1342   const struct GNUNET_GETOPT_CommandLineOption opts[] = {
1343     GNUNET_GETOPT_OPTION_END
1344   };
1345   if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-social",
1346                                        "test-social [options]",
1347                                        opts, &run, NULL))
1348     return 1;
1349 #else
1350   if (0 != GNUNET_TESTING_peer_run ("test-social", "test_social.conf", &run, NULL))
1351     return 1;
1352 #endif
1353   return res;
1354 }
1355
1356 /* end of test_social.c */