Make process_log more generic
[oweals/gnunet.git] / src / social / test_social.c
1 /*
2  * This file is part of GNUnet
3  * (C) 2013 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, 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_env_lib.h"
34 #include "gnunet_psyc_util_lib.h"
35 #include "gnunet_social_service.h"
36 #include "gnunet_core_service.h"
37 #include "gnunet_identity_service.h"
38
39 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
40
41 #define DATA2ARG(data) data, sizeof (data)
42
43 /**
44  * Return value from 'main'.
45  */
46 int res;
47
48 /**
49  * Handle for task for timeout termination.
50  */
51 GNUNET_SCHEDULER_TaskIdentifier end_badly_task;
52
53 const struct GNUNET_CONFIGURATION_Handle *cfg;
54
55 struct GNUNET_CORE_Handle *core;
56 struct GNUNET_PeerIdentity this_peer;
57
58 struct GNUNET_IDENTITY_Handle *id;
59
60 const struct GNUNET_IDENTITY_Ego *host_ego;
61 const struct GNUNET_IDENTITY_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_CRYPTO_EcdsaPublicKey guest_pub_key;
71
72 struct GNUNET_SOCIAL_Slicer *host_slicer;
73 struct GNUNET_SOCIAL_Slicer *guest_slicer;
74
75 struct GNUNET_SOCIAL_Host *hst;
76 struct GNUNET_SOCIAL_Guest *gst;
77
78 struct GuestEnterMessage
79 {
80   struct GNUNET_PSYC_Message *msg;
81   const char *method_name;
82   struct GNUNET_ENV_Environment *env;
83   void *data;
84   uint16_t data_size;
85 } guest_enter_msg;
86
87 struct TransmitClosure
88 {
89   struct GNUNET_SOCIAL_Announcement *host_ann;
90   struct GNUNET_SOCIAL_TalkRequest *guest_talk;
91   struct GNUNET_ENV_Environment *env;
92   char *data[16];
93   uint8_t data_delay[16];
94   uint8_t data_count;
95   uint8_t paused;
96   uint8_t n;
97 } tmit;
98
99 uint8_t join_req_count;
100 struct GNUNET_PSYC_Message *join_resp;
101
102 enum
103 {
104   TEST_NONE = 0,
105   TEST_HOST_ANSWER_DOOR_REFUSE      = 1,
106   TEST_GUEST_RECV_ENTRY_DCSN_REFUSE = 2,
107   TEST_HOST_ANSWER_DOOR_ADMIT       = 3,
108   TEST_GUEST_RECV_ENTRY_DCSN_ADMIT  = 4,
109   TEST_HOST_ANNOUNCE     = 5,
110   TEST_HOST_ANNOUNCE_END = 6,
111   TEST_GUEST_TALK        = 7,
112   TEST_GUEST_LEAVE       = 8,
113   TEST_HOST_LEAVE        = 9,
114 } test;
115
116
117 void
118 guest_enter ();
119
120
121 void
122 guest_talk ();
123
124
125 void
126 host_announce2 ();
127
128
129 /**
130  * Clean up all resources used.
131  */
132 void
133 cleanup ()
134 {
135   if (NULL != core)
136   {
137     GNUNET_CORE_disconnect (core);
138     core = NULL;
139   }
140
141   if (NULL != id)
142   {
143     GNUNET_IDENTITY_disconnect (id);
144     id = NULL;
145   }
146
147   if (NULL != gst)
148   {
149     GNUNET_SOCIAL_guest_leave (gst, GNUNET_NO, NULL, NULL);
150     gst = NULL;
151   }
152   if (NULL != hst)
153   {
154     GNUNET_SOCIAL_host_leave (hst, GNUNET_NO, NULL, NULL);
155     hst = NULL;
156   }
157   GNUNET_SCHEDULER_shutdown ();
158 }
159
160
161 /**
162  * Terminate the test case (failure).
163  *
164  * @param cls NULL
165  * @param tc scheduler context
166  */
167 void
168 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
169 {
170   res = 1;
171   cleanup ();
172   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test FAILED.\n");
173 }
174
175
176 /**
177  * Terminate the test case (success).
178  *
179  * @param cls NULL
180  * @param tc scheduler context
181  */
182 void
183 end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
184 {
185   res = 0;
186   cleanup ();
187   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test PASSED.\n");
188 }
189
190
191 /**
192  * Finish the test case (successfully).
193  */
194 void
195 end ()
196 {
197   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending tests.\n");
198
199   if (end_badly_task != GNUNET_SCHEDULER_NO_TASK)
200   {
201     GNUNET_SCHEDULER_cancel (end_badly_task);
202     end_badly_task = GNUNET_SCHEDULER_NO_TASK;
203   }
204   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
205                                 &end_normally, NULL);
206 }
207
208
209 static void
210 transmit_resume (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
211 {
212   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission resumed.\n");
213   struct TransmitClosure *tmit = cls;
214   if (NULL != tmit->host_ann)
215     GNUNET_SOCIAL_host_announce_resume (tmit->host_ann);
216   else
217     GNUNET_SOCIAL_guest_talk_resume (tmit->guest_talk);
218 }
219
220
221 int
222 notify_data (void *cls, uint16_t *data_size, void *data)
223 {
224   struct TransmitClosure *tmit = cls;
225   if (NULL != tmit->env)
226   {
227     GNUNET_ENV_environment_destroy (tmit->env);
228     tmit->env = NULL;
229   }
230   if (0 == tmit->data_count)
231   {
232     *data_size = 0;
233     return GNUNET_YES;
234   }
235
236   uint16_t size = strlen (tmit->data[tmit->n]) + 1;
237   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
238               "Transmit notify data: %u bytes available, "
239               "processing fragment %u/%u (size %u).\n",
240               *data_size, tmit->n + 1, tmit->data_count, size);
241   if (*data_size < size)
242   {
243     *data_size = 0;
244     GNUNET_assert (0);
245     return GNUNET_SYSERR;
246   }
247
248   if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n])
249   {
250     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission paused.\n");
251     tmit->paused = GNUNET_YES;
252     GNUNET_SCHEDULER_add_delayed (
253       GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
254                                      tmit->data_delay[tmit->n]),
255       &transmit_resume, tmit);
256     *data_size = 0;
257     return GNUNET_NO;
258   }
259   tmit->paused = GNUNET_NO;
260
261   *data_size = size;
262   memcpy (data, tmit->data[tmit->n], size);
263
264   return ++tmit->n < tmit->data_count ? GNUNET_NO : GNUNET_YES;
265 }
266
267
268 void host_left ()
269 {
270   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
271               "The host has left the place.\n");
272   GNUNET_SOCIAL_slicer_destroy (host_slicer);
273   host_slicer = NULL;
274   hst = NULL;
275
276   end ();
277 }
278
279
280 void
281 schedule_host_leave (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
282 {
283   test = TEST_HOST_LEAVE;
284   GNUNET_SOCIAL_host_leave (hst, GNUNET_NO, &host_left, NULL);
285 }
286
287
288 void
289 host_farewell (void *cls,
290                struct GNUNET_SOCIAL_Nym *nym,
291                struct GNUNET_ENV_Environment *env,
292                size_t variable_count,
293                struct GNUNET_ENV_Modifier *variables)
294 {
295   // FIXME: this function is not called yet
296
297   struct GNUNET_CRYPTO_EcdsaPublicKey *
298     nym_key = GNUNET_SOCIAL_nym_get_key (nym);
299   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
300               "Nym %s has left the place.\n",
301               GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key));
302   GNUNET_assert (0 == memcmp (&guest_pub_key, nym_key, sizeof (*nym_key)));
303
304   GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL);
305 }
306
307
308 void
309 guest_left (void *cls)
310 {
311   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
312               "The guest has left the place.\n");
313   GNUNET_SOCIAL_slicer_destroy (guest_slicer);
314   guest_slicer = NULL;
315   gst = NULL;
316
317   GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL);
318 }
319
320
321 void
322 guest_leave()
323 {
324   test = TEST_GUEST_LEAVE;
325   /* FIXME test keep_active */
326   GNUNET_SOCIAL_guest_leave (gst, GNUNET_NO, &guest_left, NULL);
327 }
328
329
330
331 void
332 guest_recv_method (void *cls,
333                   const struct GNUNET_PSYC_MessageMethod *meth,
334                   uint64_t message_id,
335                   uint32_t flags,
336                   const struct GNUNET_SOCIAL_Nym *nym,
337                   const char *method_name)
338 {
339   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
340               "Test #%u: Guest received method for message ID %" PRIu64 ":\n"
341               "%s\n",
342               test, message_id, method_name);
343   /* FIXME: check message */
344 }
345
346
347 void
348 guest_recv_modifier (void *cls,
349                     const struct GNUNET_PSYC_MessageModifier *mod,
350                     uint64_t message_id,
351                     enum GNUNET_ENV_Operator oper,
352                     const char *name,
353                     const void *value,
354                     uint16_t value_size)
355 {
356   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
357               "Test #%u: Guest received modifier for message ID %" PRIu64 ":\n"
358               "%c%s: %.*s\n",
359               test, message_id, oper, name, value_size, value);
360 }
361
362
363 void
364 guest_recv_data (void *cls,
365                 const struct GNUNET_MessageHeader *msg,
366                 uint64_t message_id,
367                 uint64_t data_offset,
368                 const void *data,
369                 uint16_t data_size)
370 {
371   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
372               "Test #%u: Guest received data for message ID %" PRIu64 ":\n"
373               "%.*s\n",
374               test, message_id, data_size, data);
375 }
376
377
378 void
379 guest_recv_eom (void *cls,
380                const struct GNUNET_MessageHeader *msg,
381                uint64_t message_id,
382                uint8_t cancelled)
383 {
384   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
385               "Test #%u: Guest received end of message ID %" PRIu64
386               ", cancelled: %u\n",
387               test, message_id, cancelled);
388
389   switch (test)
390   {
391   case TEST_HOST_ANNOUNCE:
392     test = TEST_HOST_ANNOUNCE_END;
393     break;
394
395   case TEST_HOST_ANNOUNCE_END:
396     guest_talk ();
397     break;
398
399   default:
400     GNUNET_assert (0);
401   }
402 }
403
404
405 void
406 host_recv_method (void *cls,
407                   const struct GNUNET_PSYC_MessageMethod *meth,
408                   uint64_t message_id,
409                   uint32_t flags,
410                   const struct GNUNET_SOCIAL_Nym *nym,
411                   const char *method_name)
412 {
413   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
414               "Test #%u: Host received method for message ID %" PRIu64 ":\n"
415               "%s\n",
416               test, message_id, method_name);
417   /* FIXME: check message */
418 }
419
420
421 void
422 host_recv_modifier (void *cls,
423                     const struct GNUNET_PSYC_MessageModifier *mod,
424                     uint64_t message_id,
425                     enum GNUNET_ENV_Operator oper,
426                     const char *name,
427                     const void *value,
428                     uint16_t value_size)
429 {
430   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
431               "Test #%u: Host received modifier for message ID %" PRIu64 ":\n"
432               "%c%s: %.*s\n",
433               test, message_id, oper, name, value_size, value);
434 }
435
436
437 void
438 host_recv_data (void *cls,
439                 const struct GNUNET_MessageHeader *msg,
440                 uint64_t message_id,
441                 uint64_t data_offset,
442                 const void *data,
443                 uint16_t data_size)
444 {
445   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
446               "Test #%u: Host received data for message ID %" PRIu64 ":\n"
447               "%.*s\n",
448               test, message_id, data_size, data);
449 }
450
451
452 void
453 host_recv_eom (void *cls,
454                const struct GNUNET_MessageHeader *msg,
455                uint64_t message_id,
456                uint8_t cancelled)
457 {
458   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
459               "Test #%u: Host received end of message ID %" PRIu64
460               ", cancelled: %u\n",
461               test, message_id, cancelled);
462
463   switch (test)
464   {
465   case TEST_HOST_ANNOUNCE:
466     test = TEST_HOST_ANNOUNCE_END;
467     //host_announce2 ();
468     break;
469
470   case TEST_HOST_ANNOUNCE_END:
471     guest_talk ();
472     break;
473
474   case TEST_GUEST_TALK:
475     guest_leave ();
476     break;
477
478   default:
479     GNUNET_assert (0);
480   }
481 }
482
483
484 void
485 guest_talk ()
486 {
487   test = TEST_GUEST_TALK;
488
489   tmit = (struct TransmitClosure) {};
490   tmit.env = GNUNET_ENV_environment_create ();
491   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
492                               "_bar_foo", DATA2ARG ("one two three"));
493   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
494                               "_bar_baz", DATA2ARG ("four five"));
495   tmit.data[0] = "zzz xxx yyy";
496   tmit.data[1] = "zyx wvu tsr qpo";
497   tmit.data[2] = "testing ten nine eight";
498   tmit.data_count = 3;
499
500   tmit.guest_talk
501     = GNUNET_SOCIAL_guest_talk (gst, "_message_guest", tmit.env,
502                                 &notify_data, &tmit,
503                                 GNUNET_SOCIAL_TALK_NONE);
504 }
505
506 void
507 host_announce ()
508 {
509   test = TEST_HOST_ANNOUNCE;
510
511   tmit = (struct TransmitClosure) {};
512   tmit.env = GNUNET_ENV_environment_create ();
513   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
514                               "_foo", DATA2ARG ("bar baz"));
515   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
516                               "_foo_bar", DATA2ARG ("foo bar"));
517   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
518                               "_foo_bar_baz", DATA2ARG ("foo bar baz"));
519   tmit.data[0] = "aaa bbb ccc";
520   tmit.data[1] = "abc def ghi jkl";
521   tmit.data[2] = "testing one two three";
522   tmit.data[3] = "four five";
523   tmit.data_count = 4;
524
525   tmit.host_ann
526     = GNUNET_SOCIAL_host_announce (hst, "_message_host", tmit.env,
527                                    &notify_data, &tmit,
528                                    GNUNET_SOCIAL_ANNOUNCE_NONE);
529 }
530
531 void
532 host_announce2 ()
533 {
534   test = TEST_HOST_ANNOUNCE;
535
536   tmit = (struct TransmitClosure) {};
537   tmit.env = GNUNET_ENV_environment_create ();
538   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
539                               "_foo2", DATA2ARG ("BAR BAZ"));
540   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
541                               "_foo2_bar", DATA2ARG ("FOO BAR"));
542   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
543                               "_foo2_bar", DATA2ARG ("FOO BAR BAZ"));
544   tmit.data[0] = "AAA BBB CCC";
545   tmit.data[1] = "ABC DEF GHI JKL";
546   tmit.data[2] = "TESTING ONE TWO THREE";
547   tmit.data_count = 3;
548
549   tmit.host_ann
550     = GNUNET_SOCIAL_host_announce (hst, "_message_host_two", tmit.env,
551                                    &notify_data, &tmit,
552                                    GNUNET_SOCIAL_ANNOUNCE_NONE);
553 }
554
555
556 void
557 guest_recv_entry_decision (void *cls,
558                            int is_admitted,
559                            const struct GNUNET_PSYC_Message *entry_resp)
560 {
561   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
562               "Guest received entry decision (try %u): %d.\n",
563               join_req_count, is_admitted);
564
565   if (NULL != entry_resp)
566   {
567     struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create ();
568     const char *method_name = NULL;
569     const void *data = NULL;
570     uint16_t data_size = 0;
571     GNUNET_PSYC_message_parse (entry_resp, &method_name, env, &data, &data_size);
572
573     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
574                 "%s\n%.*s\n",
575                 method_name, data_size, data);
576     /* FIXME: check response message */
577   }
578
579   switch (test)
580   {
581   case TEST_GUEST_RECV_ENTRY_DCSN_REFUSE:
582     GNUNET_assert (GNUNET_NO == is_admitted);
583     guest_enter ();
584     break;
585
586   case TEST_GUEST_RECV_ENTRY_DCSN_ADMIT:
587     GNUNET_assert (GNUNET_YES == is_admitted);
588     host_announce ();
589     break;
590
591   default:
592     GNUNET_assert (0);
593   }
594 }
595
596
597 void
598 host_answer_door (void *cls,
599                   struct GNUNET_SOCIAL_Nym *nym,
600                   const char *method_name,
601                   struct GNUNET_ENV_Environment *env,
602                   size_t data_size,
603                   const void *data)
604 {
605   join_req_count++;
606
607   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
608                 "Host received entry request from guest (try %u).\n",
609                 join_req_count);
610   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
611               "%s\n%.*s\n",
612               method_name, data_size, data);
613
614   switch (test)
615   {
616   case TEST_HOST_ANSWER_DOOR_REFUSE:
617     test = TEST_GUEST_RECV_ENTRY_DCSN_REFUSE;
618     join_resp = GNUNET_PSYC_message_create ("_refuse_nym", env,
619                                             DATA2ARG ("Go away!"));
620     GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_NO, join_resp);
621     break;
622
623   case TEST_HOST_ANSWER_DOOR_ADMIT:
624     test = TEST_GUEST_RECV_ENTRY_DCSN_ADMIT;
625     join_resp = GNUNET_PSYC_message_create ("_admit_nym", env,
626                                             DATA2ARG ("Welcome, nym!"));
627     GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp);
628     break;
629
630   default:
631     GNUNET_assert (0);
632   }
633 }
634
635
636 void
637 guest_recv_local_enter (void *cls, int result, uint64_t max_message_id)
638 {
639   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Guest entered to local place.\n");
640
641 }
642
643
644 void
645 guest_enter ()
646 {
647   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering to place as guest.\n");
648
649   struct GuestEnterMessage *emsg = &guest_enter_msg;
650
651   emsg->method_name = "_request_enter";
652   emsg->env = GNUNET_ENV_environment_create ();
653   GNUNET_ENV_environment_add (emsg->env, GNUNET_ENV_OP_ASSIGN,
654                               "_abc", "abc def", 7);
655   GNUNET_ENV_environment_add (emsg->env, GNUNET_ENV_OP_ASSIGN,
656                               "_abc_def", "abc def ghi", 11);
657   emsg->data = "let me in";
658   emsg->data_size = strlen (emsg->data) + 1;
659   emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
660                                           emsg->data, emsg->data_size);
661
662   gst = GNUNET_SOCIAL_guest_enter (cfg, guest_ego, &place_pub_key,
663                                    &this_peer, 0, NULL, emsg->msg,
664                                    guest_slicer, &guest_recv_local_enter,
665                                    &guest_recv_entry_decision, NULL);
666 }
667
668
669 void id_guest_ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
670 {
671   GNUNET_assert (NULL != ego);
672   guest_ego = ego;
673
674   guest_slicer = GNUNET_SOCIAL_slicer_create ();
675   GNUNET_SOCIAL_slicer_add (guest_slicer, "",
676                             &guest_recv_method, &guest_recv_modifier,
677                             &guest_recv_data, &guest_recv_eom, NULL);
678   test = TEST_HOST_ANSWER_DOOR_ADMIT;
679   //host_announce ();
680   guest_enter ();
681 }
682
683
684 void id_guest_created (void *cls, const char *emsg)
685 {
686   if (NULL != emsg)
687   {
688     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
689                 "Could not create guest identity: %s\n", emsg);
690 #if ! DEBUG_TEST_SOCIAL
691     GNUNET_assert (0);
692 #endif
693   }
694
695  GNUNET_IDENTITY_ego_lookup (cfg, guest_name, &id_guest_ego_cb, NULL);
696 }
697
698
699 void host_entered (void *cls, int result, uint64_t max_message_id)
700 {
701   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Host entered to place.\n");
702
703   GNUNET_IDENTITY_create (id, guest_name, &id_guest_created, NULL);
704 }
705
706
707 void id_host_ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
708 {
709   GNUNET_assert (NULL != ego);
710   host_ego = ego;
711
712   host_slicer = GNUNET_SOCIAL_slicer_create ();
713   GNUNET_SOCIAL_slicer_add (host_slicer, "",
714                             &host_recv_method, &host_recv_modifier,
715                             &host_recv_data, &host_recv_eom, NULL);
716
717   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering to place as host.\n");
718   hst = GNUNET_SOCIAL_host_enter (cfg, host_ego, place_key,
719                                   GNUNET_PSYC_CHANNEL_PRIVATE, host_slicer,
720                                   &host_entered, &host_answer_door,
721                                   &host_farewell, NULL);
722 }
723
724
725 void id_host_created (void *cls, const char *emsg)
726 {
727   if (NULL != emsg)
728   {
729     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
730                 "Could not create host identity: %s\n", emsg);
731 #if ! DEBUG_TEST_SOCIAL
732     GNUNET_assert (0);
733 #endif
734   }
735
736   GNUNET_IDENTITY_ego_lookup (cfg, host_name, &id_host_ego_cb, NULL);
737 }
738
739
740 void identity_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego,
741                       void **ctx, const char *name)
742 {
743
744 }
745
746
747 void
748 core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity)
749 {
750   this_peer = *my_identity;
751
752   id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL);
753   GNUNET_IDENTITY_create (id, host_name, &id_host_created, NULL);
754 }
755
756
757 /**
758  * Main function of the test, run from scheduler.
759  *
760  * @param cls NULL
761  * @param cfg configuration we use (also to connect to Social service)
762  * @param peer handle to access more of the peer (not used)
763  */
764 void
765 #if DEBUG_TEST_SOCIAL
766 run (void *cls, char *const *args, const char *cfgfile,
767      const struct GNUNET_CONFIGURATION_Handle *c)
768 #else
769 run (void *cls,
770      const struct GNUNET_CONFIGURATION_Handle *c,
771      struct GNUNET_TESTING_Peer *peer)
772 #endif
773 {
774   cfg = c;
775   end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
776
777   place_key = GNUNET_CRYPTO_eddsa_key_create ();
778   guest_key = GNUNET_CRYPTO_ecdsa_key_create ();
779
780   GNUNET_CRYPTO_eddsa_key_get_public (place_key, &place_pub_key);
781   GNUNET_CRYPTO_ecdsa_key_get_public (guest_key, &guest_pub_key);
782
783   core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL,
784                               NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
785 }
786
787
788 int
789 main (int argc, char *argv[])
790 {
791   res = 1;
792 #if DEBUG_TEST_SOCIAL
793   const struct GNUNET_GETOPT_CommandLineOption opts[] = {
794     GNUNET_GETOPT_OPTION_END
795   };
796   if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-social",
797                                        "test-social [options]",
798                                        opts, &run, NULL))
799     return 1;
800 #else
801   if (0 != GNUNET_TESTING_peer_run ("test-social", "test_social.conf", &run, NULL))
802     return 1;
803 #endif
804   return res;
805 }
806
807 /* end of test_social.c */