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