- refactor kx sending, unify under send_kx
[oweals/gnunet.git] / src / social / test_social.c
1 /*
2  * This file is part of GNUnet
3  * Copyright (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 struct GNUNET_SCHEDULER_Task * 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 static void
118 guest_enter ();
119
120
121 static void
122 guest_talk ();
123
124
125 static void
126 host_announce2 ();
127
128
129 /**
130  * Clean up all resources used.
131  */
132 static 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 static 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 static 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 static void
195 end ()
196 {
197   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending tests.\n");
198
199   if (end_badly_task != NULL)
200   {
201     GNUNET_SCHEDULER_cancel (end_badly_task);
202     end_badly_task = NULL;
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 static 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 static void
269 host_left ()
270 {
271   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
272               "The host has left the place.\n");
273   GNUNET_SOCIAL_slicer_destroy (host_slicer);
274   host_slicer = NULL;
275   hst = NULL;
276
277   end ();
278 }
279
280
281 static void
282 schedule_host_leave (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
283 {
284   test = TEST_HOST_LEAVE;
285   GNUNET_SOCIAL_host_leave (hst, GNUNET_NO, &host_left, NULL);
286 }
287
288
289 static void
290 host_farewell (void *cls,
291                struct GNUNET_SOCIAL_Nym *nym,
292                struct GNUNET_ENV_Environment *env,
293                size_t variable_count,
294                struct GNUNET_ENV_Modifier *variables)
295 {
296   // FIXME: this function is not called yet
297   struct GNUNET_CRYPTO_EcdsaPublicKey *nym_key = GNUNET_SOCIAL_nym_get_key (nym);
298   char *str;
299
300   str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
301   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
302               "Nym %s has left the place.\n",
303               str);
304   GNUNET_free (str);
305   GNUNET_assert (0 == memcmp (&guest_pub_key, nym_key, sizeof (*nym_key)));
306
307   GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL);
308 }
309
310
311 static void
312 guest_left (void *cls)
313 {
314   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
315               "The guest has left the place.\n");
316   GNUNET_SOCIAL_slicer_destroy (guest_slicer);
317   guest_slicer = NULL;
318   gst = NULL;
319
320   GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL);
321 }
322
323
324 static void
325 guest_leave()
326 {
327   test = TEST_GUEST_LEAVE;
328   /* FIXME test keep_active */
329   GNUNET_SOCIAL_guest_leave (gst, GNUNET_NO, &guest_left, NULL);
330 }
331
332
333 static void
334 guest_recv_method (void *cls,
335                   const struct GNUNET_PSYC_MessageMethod *meth,
336                   uint64_t message_id,
337                   uint32_t flags,
338                   const struct GNUNET_SOCIAL_Nym *nym,
339                   const char *method_name)
340 {
341   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
342               "Test #%u: Guest received method for message ID %" PRIu64 ":\n"
343               "%s\n",
344               test, message_id, method_name);
345   /* FIXME: check message */
346 }
347
348
349 static void
350 guest_recv_modifier (void *cls,
351                     const struct GNUNET_PSYC_MessageModifier *mod,
352                     uint64_t message_id,
353                     enum GNUNET_ENV_Operator oper,
354                     const char *name,
355                     const void *value,
356                     uint16_t value_size)
357 {
358   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
359               "Test #%u: Guest received modifier for message ID %" PRIu64 ":\n"
360               "%c%s: %.*s\n",
361               test, message_id, oper, name, value_size, value);
362 }
363
364
365 static void
366 guest_recv_data (void *cls,
367                 const struct GNUNET_MessageHeader *msg,
368                 uint64_t message_id,
369                 uint64_t data_offset,
370                 const void *data,
371                 uint16_t data_size)
372 {
373   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
374               "Test #%u: Guest received data for message ID %" PRIu64 ":\n"
375               "%.*s\n",
376               test, message_id, data_size, data);
377 }
378
379
380 static void
381 guest_recv_eom (void *cls,
382                const struct GNUNET_MessageHeader *msg,
383                uint64_t message_id,
384                uint8_t cancelled)
385 {
386   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
387               "Test #%u: Guest received end of message ID %" PRIu64
388               ", cancelled: %u\n",
389               test, message_id, cancelled);
390
391   switch (test)
392   {
393   case TEST_HOST_ANNOUNCE:
394     test = TEST_HOST_ANNOUNCE_END;
395     break;
396
397   case TEST_HOST_ANNOUNCE_END:
398     guest_talk ();
399     break;
400
401   default:
402     GNUNET_assert (0);
403   }
404 }
405
406
407 static void
408 host_recv_method (void *cls,
409                   const struct GNUNET_PSYC_MessageMethod *meth,
410                   uint64_t message_id,
411                   uint32_t flags,
412                   const struct GNUNET_SOCIAL_Nym *nym,
413                   const char *method_name)
414 {
415   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
416               "Test #%u: Host received method for message ID %" PRIu64 ":\n"
417               "%s\n",
418               test, message_id, method_name);
419   /* FIXME: check message */
420 }
421
422
423 static void
424 host_recv_modifier (void *cls,
425                     const struct GNUNET_PSYC_MessageModifier *mod,
426                     uint64_t message_id,
427                     enum GNUNET_ENV_Operator oper,
428                     const char *name,
429                     const void *value,
430                     uint16_t value_size)
431 {
432   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
433               "Test #%u: Host received modifier for message ID %" PRIu64 ":\n"
434               "%c%s: %.*s\n",
435               test, message_id, oper, name, value_size, value);
436 }
437
438
439 static void
440 host_recv_data (void *cls,
441                 const struct GNUNET_MessageHeader *msg,
442                 uint64_t message_id,
443                 uint64_t data_offset,
444                 const void *data,
445                 uint16_t data_size)
446 {
447   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
448               "Test #%u: Host received data for message ID %" PRIu64 ":\n"
449               "%.*s\n",
450               test, message_id, data_size, data);
451 }
452
453
454 static void
455 host_recv_eom (void *cls,
456                const struct GNUNET_MessageHeader *msg,
457                uint64_t message_id,
458                uint8_t cancelled)
459 {
460   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
461               "Test #%u: Host received end of message ID %" PRIu64
462               ", cancelled: %u\n",
463               test, message_id, cancelled);
464
465   switch (test)
466   {
467   case TEST_HOST_ANNOUNCE:
468     test = TEST_HOST_ANNOUNCE_END;
469     //host_announce2 ();
470     break;
471
472   case TEST_HOST_ANNOUNCE_END:
473     guest_talk ();
474     break;
475
476   case TEST_GUEST_TALK:
477     guest_leave ();
478     break;
479
480   default:
481     GNUNET_assert (0);
482   }
483 }
484
485
486 static void
487 guest_talk ()
488 {
489   test = TEST_GUEST_TALK;
490
491   tmit = (struct TransmitClosure) {};
492   tmit.env = GNUNET_ENV_environment_create ();
493   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
494                               "_bar_foo", DATA2ARG ("one two three"));
495   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
496                               "_bar_baz", DATA2ARG ("four five"));
497   tmit.data[0] = "zzz xxx yyy";
498   tmit.data[1] = "zyx wvu tsr qpo";
499   tmit.data[2] = "testing ten nine eight";
500   tmit.data_count = 3;
501
502   tmit.guest_talk
503     = GNUNET_SOCIAL_guest_talk (gst, "_message_guest", tmit.env,
504                                 &notify_data, &tmit,
505                                 GNUNET_SOCIAL_TALK_NONE);
506 }
507
508
509 static void
510 host_announce ()
511 {
512   test = TEST_HOST_ANNOUNCE;
513
514   tmit = (struct TransmitClosure) {};
515   tmit.env = GNUNET_ENV_environment_create ();
516   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
517                               "_foo", DATA2ARG ("bar baz"));
518   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
519                               "_foo_bar", DATA2ARG ("foo bar"));
520   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
521                               "_foo_bar_baz", DATA2ARG ("foo bar baz"));
522   tmit.data[0] = "aaa bbb ccc";
523   tmit.data[1] = "abc def ghi jkl";
524   tmit.data[2] = "testing one two three";
525   tmit.data[3] = "four five";
526   tmit.data_count = 4;
527
528   tmit.host_ann
529     = GNUNET_SOCIAL_host_announce (hst, "_message_host", tmit.env,
530                                    &notify_data, &tmit,
531                                    GNUNET_SOCIAL_ANNOUNCE_NONE);
532 }
533
534
535 static void
536 host_announce2 ()
537 {
538   test = TEST_HOST_ANNOUNCE;
539
540   tmit = (struct TransmitClosure) {};
541   tmit.env = GNUNET_ENV_environment_create ();
542   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
543                               "_foo2", DATA2ARG ("BAR BAZ"));
544   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
545                               "_foo2_bar", DATA2ARG ("FOO BAR"));
546   GNUNET_ENV_environment_add (tmit.env, GNUNET_ENV_OP_ASSIGN,
547                               "_foo2_bar", DATA2ARG ("FOO BAR BAZ"));
548   tmit.data[0] = "AAA BBB CCC";
549   tmit.data[1] = "ABC DEF GHI JKL";
550   tmit.data[2] = "TESTING ONE TWO THREE";
551   tmit.data_count = 3;
552
553   tmit.host_ann
554     = GNUNET_SOCIAL_host_announce (hst, "_message_host_two", tmit.env,
555                                    &notify_data, &tmit,
556                                    GNUNET_SOCIAL_ANNOUNCE_NONE);
557 }
558
559
560 static void
561 guest_recv_entry_decision (void *cls,
562                            int is_admitted,
563                            const struct GNUNET_PSYC_Message *entry_resp)
564 {
565   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
566               "Guest received entry decision (try %u): %d.\n",
567               join_req_count, is_admitted);
568
569   if (NULL != entry_resp)
570   {
571     struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create ();
572     const char *method_name = NULL;
573     const void *data = NULL;
574     uint16_t data_size = 0;
575     GNUNET_PSYC_message_parse (entry_resp, &method_name, env, &data, &data_size);
576
577     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
578                 "%s\n%.*s\n",
579                 method_name, data_size, data);
580     /* FIXME: check response message */
581   }
582
583   switch (test)
584   {
585   case TEST_GUEST_RECV_ENTRY_DCSN_REFUSE:
586     GNUNET_assert (GNUNET_NO == is_admitted);
587     guest_enter ();
588     break;
589
590   case TEST_GUEST_RECV_ENTRY_DCSN_ADMIT:
591     GNUNET_assert (GNUNET_YES == is_admitted);
592     host_announce ();
593     break;
594
595   default:
596     GNUNET_assert (0);
597   }
598 }
599
600
601 static void
602 host_answer_door (void *cls,
603                   struct GNUNET_SOCIAL_Nym *nym,
604                   const char *method_name,
605                   struct GNUNET_ENV_Environment *env,
606                   size_t data_size,
607                   const void *data)
608 {
609   join_req_count++;
610
611   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
612                 "Host received entry request from guest (try %u).\n",
613                 join_req_count);
614   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
615               "%s\n%.*s\n",
616               method_name, data_size, data);
617
618   switch (test)
619   {
620   case TEST_HOST_ANSWER_DOOR_REFUSE:
621     test = TEST_GUEST_RECV_ENTRY_DCSN_REFUSE;
622     join_resp = GNUNET_PSYC_message_create ("_refuse_nym", env,
623                                             DATA2ARG ("Go away!"));
624     GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_NO, join_resp);
625     break;
626
627   case TEST_HOST_ANSWER_DOOR_ADMIT:
628     test = TEST_GUEST_RECV_ENTRY_DCSN_ADMIT;
629     join_resp = GNUNET_PSYC_message_create ("_admit_nym", env,
630                                             DATA2ARG ("Welcome, nym!"));
631     GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp);
632     break;
633
634   default:
635     GNUNET_assert (0);
636   }
637 }
638
639
640 static void
641 guest_recv_local_enter (void *cls, int result, uint64_t max_message_id)
642 {
643   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Guest entered to local place.\n");
644
645 }
646
647
648 static void
649 guest_enter ()
650 {
651   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering to place as guest.\n");
652
653   struct GuestEnterMessage *emsg = &guest_enter_msg;
654
655   emsg->method_name = "_request_enter";
656   emsg->env = GNUNET_ENV_environment_create ();
657   GNUNET_ENV_environment_add (emsg->env, GNUNET_ENV_OP_ASSIGN,
658                               "_abc", "abc def", 7);
659   GNUNET_ENV_environment_add (emsg->env, GNUNET_ENV_OP_ASSIGN,
660                               "_abc_def", "abc def ghi", 11);
661   emsg->data = "let me in";
662   emsg->data_size = strlen (emsg->data) + 1;
663   emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
664                                           emsg->data, emsg->data_size);
665
666   gst = GNUNET_SOCIAL_guest_enter (cfg, guest_ego, &place_pub_key,
667                                    &this_peer, 0, NULL, emsg->msg,
668                                    guest_slicer, &guest_recv_local_enter,
669                                    &guest_recv_entry_decision, NULL);
670 }
671
672
673 static void
674 id_guest_ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
675 {
676   GNUNET_assert (NULL != ego);
677   guest_ego = ego;
678
679   guest_slicer = GNUNET_SOCIAL_slicer_create ();
680   GNUNET_SOCIAL_slicer_add (guest_slicer, "",
681                             &guest_recv_method, &guest_recv_modifier,
682                             &guest_recv_data, &guest_recv_eom, NULL);
683   test = TEST_HOST_ANSWER_DOOR_ADMIT;
684   //host_announce ();
685   guest_enter ();
686 }
687
688
689 static void
690 id_guest_created (void *cls, const char *emsg)
691 {
692   if (NULL != emsg)
693   {
694     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
695                 "Could not create guest identity: %s\n", emsg);
696 #if ! DEBUG_TEST_SOCIAL
697     GNUNET_assert (0);
698 #endif
699   }
700
701  GNUNET_IDENTITY_ego_lookup (cfg, guest_name, &id_guest_ego_cb, NULL);
702 }
703
704
705 static void
706 host_entered (void *cls, int result, uint64_t max_message_id)
707 {
708   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Host entered to place.\n");
709
710   GNUNET_IDENTITY_create (id, guest_name, &id_guest_created, NULL);
711 }
712
713
714 static void
715 id_host_ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
716 {
717   GNUNET_assert (NULL != ego);
718   host_ego = ego;
719
720   host_slicer = GNUNET_SOCIAL_slicer_create ();
721   GNUNET_SOCIAL_slicer_add (host_slicer, "",
722                             &host_recv_method, &host_recv_modifier,
723                             &host_recv_data, &host_recv_eom, NULL);
724
725   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering to place as host.\n");
726   hst = GNUNET_SOCIAL_host_enter (cfg, host_ego, place_key,
727                                   GNUNET_PSYC_CHANNEL_PRIVATE, host_slicer,
728                                   &host_entered, &host_answer_door,
729                                   &host_farewell, NULL);
730 }
731
732
733 static void
734 id_host_created (void *cls, const char *emsg)
735 {
736   if (NULL != emsg)
737   {
738     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
739                 "Could not create host identity: %s\n", emsg);
740 #if ! DEBUG_TEST_SOCIAL
741     GNUNET_assert (0);
742 #endif
743   }
744
745   GNUNET_IDENTITY_ego_lookup (cfg, host_name, &id_host_ego_cb, NULL);
746 }
747
748
749 static void
750 identity_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego,
751                  void **ctx, const char *name)
752 {
753
754 }
755
756
757 static void
758 core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity)
759 {
760   this_peer = *my_identity;
761
762   id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL);
763   GNUNET_IDENTITY_create (id, host_name, &id_host_created, NULL);
764 }
765
766
767 /**
768  * Main function of the test, run from scheduler.
769  *
770  * @param cls NULL
771  * @param cfg configuration we use (also to connect to Social service)
772  * @param peer handle to access more of the peer (not used)
773  */
774 static void
775 #if DEBUG_TEST_SOCIAL
776 run (void *cls, char *const *args, const char *cfgfile,
777      const struct GNUNET_CONFIGURATION_Handle *c)
778 #else
779 run (void *cls,
780      const struct GNUNET_CONFIGURATION_Handle *c,
781      struct GNUNET_TESTING_Peer *peer)
782 #endif
783 {
784   cfg = c;
785   end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
786
787   place_key = GNUNET_CRYPTO_eddsa_key_create ();
788   guest_key = GNUNET_CRYPTO_ecdsa_key_create ();
789
790   GNUNET_CRYPTO_eddsa_key_get_public (place_key, &place_pub_key);
791   GNUNET_CRYPTO_ecdsa_key_get_public (guest_key, &guest_pub_key);
792
793   core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL,
794                               NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
795 }
796
797
798 int
799 main (int argc, char *argv[])
800 {
801   res = 1;
802 #if DEBUG_TEST_SOCIAL
803   const struct GNUNET_GETOPT_CommandLineOption opts[] = {
804     GNUNET_GETOPT_OPTION_END
805   };
806   if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-social",
807                                        "test-social [options]",
808                                        opts, &run, NULL))
809     return 1;
810 #else
811   if (0 != GNUNET_TESTING_peer_run ("test-social", "test_social.conf", &run, NULL))
812     return 1;
813 #endif
814   return res;
815 }
816
817 /* end of test_social.c */