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