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