aboutsummaryrefslogtreecommitdiff
path: root/src/social/test_social.c
blob: f424553d0188d1346a47847dbb4a43ea76b58e48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
/*
 * This file is part of GNUnet
 * Copyright (C) 2013 GNUnet e.V.
 *
 * GNUnet is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 3, or (at your
 * option) any later version.
 *
 * GNUnet is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNUnet; see the file COPYING.  If not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */
/**
 * @file social/test_social.c
 * @brief Tests for the Social API.
 * @author Gabor X Toth
 */

#include <inttypes.h>

#include "platform.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_common.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib.h"
#include "gnunet_psyc_util_lib.h"
#include "gnunet_social_service.h"
#include "gnunet_core_service.h"
#include "gnunet_identity_service.h"

#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)

#define DATA2ARG(data) data, sizeof (data)

/**
 * Return value from 'main'.
 */
int res;

struct GNUNET_SOCIAL_App *app;
const char *app_id = "test";

/**
 * Handle for task for timeout termination.
 */
struct GNUNET_SCHEDULER_Task * end_badly_task;

const struct GNUNET_CONFIGURATION_Handle *cfg;

struct GNUNET_CORE_Handle *core;
struct GNUNET_PeerIdentity this_peer;

struct GNUNET_IDENTITY_Handle *id;

const struct GNUNET_SOCIAL_Ego *host_ego;
const struct GNUNET_SOCIAL_Ego *guest_ego;

const char *host_name = "Host One";
const char *guest_name = "Guest One";

struct GNUNET_CRYPTO_EddsaPrivateKey *place_key;
struct GNUNET_CRYPTO_EcdsaPrivateKey *guest_key;

struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key;
struct GNUNET_HashCode place_pub_hash;

struct GNUNET_CRYPTO_EcdsaPublicKey guest_pub_key;
struct GNUNET_CRYPTO_EcdsaPublicKey host_pub_key;

struct GNUNET_PSYC_Slicer *host_slicer;
struct GNUNET_PSYC_Slicer *guest_slicer;

struct GNUNET_SOCIAL_Host *hst;
struct GNUNET_SOCIAL_Guest *gst;

struct GNUNET_SOCIAL_Place *hst_plc;
struct GNUNET_SOCIAL_Place *gst_plc;

struct GNUNET_SOCIAL_Nym *nym_eject;

struct GuestEnterMessage
{
  struct GNUNET_PSYC_Message *msg;
  const char *method_name;
  struct GNUNET_PSYC_Environment *env;
  void *data;
  uint16_t data_size;
} guest_enter_msg;

struct TransmitClosure
{
  struct GNUNET_SOCIAL_Announcement *host_ann;
  struct GNUNET_SOCIAL_TalkRequest *guest_talk;
  struct GNUNET_PSYC_Environment *env;
  char *data[16];
  uint8_t data_delay[16];
  uint8_t data_count;
  uint8_t paused;
  uint8_t n;
} tmit;

struct ResultClosure {
  uint32_t n;
} mod_foo_bar_rcls;

uint8_t join_req_count;
struct GNUNET_PSYC_Message *join_resp;

uint32_t counter;

uint8_t is_guest_nym_added = GNUNET_NO;
uint8_t is_host_reconnected = GNUNET_NO;
uint8_t is_guest_reconnected = GNUNET_NO;

enum
{
  TEST_NONE                         =  0,
  TEST_HOST_CREATE                  =  1,
  TEST_HOST_ENTER                   =  2,
  TEST_GUEST_CREATE                 =  3,
  TEST_GUEST_ENTER                  =  4,
  TEST_HOST_ANSWER_DOOR_REFUSE      =  5,
  TEST_GUEST_RECV_ENTRY_DCSN_REFUSE =  6,
  TEST_HOST_ANSWER_DOOR_ADMIT       =  7,
  TEST_GUEST_RECV_ENTRY_DCSN_ADMIT  =  8,
  TEST_HOST_ANNOUNCE   	            =  9,
  TEST_HOST_ANNOUNCE_END            = 10,
  TEST_HOST_ANNOUNCE2  	            = 11,
  TEST_HOST_ANNOUNCE2_END           = 12,
  TEST_GUEST_TALK                   = 13,
  TEST_GUEST_HISTORY_REPLAY         = 14,
  TEST_GUEST_HISTORY_REPLAY_LATEST  = 15,
  TEST_GUEST_LOOK_AT                = 16,
  TEST_GUEST_LOOK_FOR               = 17,
  TEST_GUEST_LEAVE                  = 18,
  TEST_ZONE_ADD_PLACE               = 19,
  TEST_GUEST_ENTER_BY_NAME          = 20,
  TEST_RECONNECT                    = 21,
  TEST_GUEST_LEAVE2                 = 22,
  TEST_HOST_LEAVE                   = 23,
} test;


static void
schedule_guest_leave (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);

static void
host_answer_door (void *cls,
                  struct GNUNET_SOCIAL_Nym *nym,
                  const char *method_name,
                  struct GNUNET_PSYC_Environment *env,
                  size_t data_size,
                  const void *data);

static void
host_enter ();

static void
guest_init ();

static void
guest_enter ();

static void
guest_enter_by_name ();

static void
guest_talk ();

static void
host_announce2 ();


/**
 * Clean up all resources used.
 */
static void
cleanup ()
{
  if (NULL != core)
  {
    GNUNET_CORE_disconnect (core);
    core = NULL;
  }

  if (NULL != id)
  {
    GNUNET_IDENTITY_disconnect (id);
    id = NULL;
  }

  if (NULL != guest_slicer)
  {
    GNUNET_PSYC_slicer_destroy (guest_slicer);
    guest_slicer = NULL;
  }

  if (NULL != host_slicer)
  {
    GNUNET_PSYC_slicer_destroy (host_slicer);
    host_slicer = NULL;
  }

  if (NULL != gst)
  {
    GNUNET_SOCIAL_guest_leave (gst, NULL, NULL, NULL);
    gst = NULL;
    gst_plc = NULL;
  }
  if (NULL != hst)
  {
    GNUNET_SOCIAL_host_leave (hst, NULL, NULL, NULL);
    hst = NULL;
    hst_plc = NULL;
  }
  GNUNET_SOCIAL_app_disconnect (app);
  GNUNET_SCHEDULER_shutdown ();
}


/**
 * Terminate the test case (failure).
 *
 * @param cls NULL
 * @param tc scheduler context
 */
static void
end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  res = 1;
  cleanup ();
  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test FAILED.\n");
}


/**
 * Terminate the test case (success).
 *
 * @param cls NULL
 * @param tc scheduler context
 */
static void
end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  res = 0;
  cleanup ();
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test PASSED.\n");
}


/**
 * Finish the test case (successfully).
 */
static void
end ()
{
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending tests.\n");

  if (end_badly_task != NULL)
  {
    GNUNET_SCHEDULER_cancel (end_badly_task);
    end_badly_task = NULL;
  }
  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
				&end_normally, NULL);
}


static void
transmit_resume (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission resumed.\n");
  struct TransmitClosure *tmit = cls;
  if (NULL != tmit->host_ann)
    GNUNET_SOCIAL_host_announce_resume (tmit->host_ann);
  else
    GNUNET_SOCIAL_guest_talk_resume (tmit->guest_talk);
}


static int
notify_data (void *cls, uint16_t *data_size, void *data)
{
  struct TransmitClosure *tmit = cls;
  if (NULL != tmit->env)
  {
    GNUNET_PSYC_env_destroy (tmit->env);
    tmit->env = NULL;
  }
  if (0 == tmit->data_count)
  {
    *data_size = 0;
    return GNUNET_YES;
  }

  uint16_t size = strlen (tmit->data[tmit->n]) + 1;
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Transmit notify data: %u bytes available, "
              "processing fragment %u/%u (size %u).\n",
              *data_size, tmit->n + 1, tmit->data_count, size);
  if (*data_size < size)
  {
    *data_size = 0;
    GNUNET_assert (0);
    return GNUNET_SYSERR;
  }

  if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n])
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission paused.\n");
    tmit->paused = GNUNET_YES;
    GNUNET_SCHEDULER_add_delayed (
      GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
                                     tmit->data_delay[tmit->n]),
      &transmit_resume, tmit);
    *data_size = 0;
    return GNUNET_NO;
  }
  tmit->paused = GNUNET_NO;

  *data_size = size;
  memcpy (data, tmit->data[tmit->n], size);

  return ++tmit->n < tmit->data_count ? GNUNET_NO : GNUNET_YES;
}


static void
host_left ()
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "The host has left the place.\n");
  end ();
}


static void
schedule_host_leave (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  test = TEST_HOST_LEAVE;
  GNUNET_SOCIAL_host_leave (hst, NULL, &host_left, NULL);
  hst = NULL;
  hst_plc = NULL;
}


static void
host_farewell2 (void *cls,
               const struct GNUNET_SOCIAL_Nym *nym,
               struct GNUNET_PSYC_Environment *env)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Nym left the place again.\n");
  GNUNET_SCHEDULER_add_now (schedule_host_leave, NULL);
}


static void
host_reconnected (void *cls, int result,
              const struct GNUNET_CRYPTO_EddsaPublicKey *home_pub_key,
              uint64_t max_message_id)
{
  place_pub_key = *home_pub_key;
  GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Host reconnected to place %s\n",
              test, GNUNET_h2s (&place_pub_hash));

  is_host_reconnected = GNUNET_YES;
  if (GNUNET_YES == is_guest_reconnected)
  {
    GNUNET_SCHEDULER_add_now (schedule_guest_leave, NULL);
  }
}


static void
guest_reconnected (void *cls, int result, uint64_t max_message_id)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Guest reconnected to place: %d\n",
              test, result);
  GNUNET_assert (0 <= result);

  is_guest_reconnected = GNUNET_YES;
  if (GNUNET_YES == is_host_reconnected)
  {
    GNUNET_SCHEDULER_add_now (schedule_guest_leave, NULL);
  }
}


static void
app_recv_host (void *cls,
               struct GNUNET_SOCIAL_HostConnection *hconn,
               struct GNUNET_SOCIAL_Ego *ego,
               const struct GNUNET_CRYPTO_EddsaPublicKey *host_pub_key,
               enum GNUNET_SOCIAL_PlaceState place_state)
{
  struct GNUNET_HashCode host_pub_hash;
  GNUNET_CRYPTO_hash (host_pub_key, sizeof (*host_pub_key), &host_pub_hash);

  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Got app host place notification: %s\n",
              GNUNET_h2s (&host_pub_hash));

  if (test == TEST_RECONNECT)
  {
    if (0 == memcmp (&place_pub_key, host_pub_key, sizeof (*host_pub_key)))
    {
      hst = GNUNET_SOCIAL_host_enter_reconnect (hconn, host_slicer, host_reconnected,
                                                host_answer_door, host_farewell2, NULL);
    }
  }
}


static void
app_recv_guest (void *cls,
                struct GNUNET_SOCIAL_GuestConnection *gconn,
                struct GNUNET_SOCIAL_Ego *ego,
                const struct GNUNET_CRYPTO_EddsaPublicKey *guest_pub_key,
                enum GNUNET_SOCIAL_PlaceState place_state)
{
  struct GNUNET_HashCode guest_pub_hash;
  GNUNET_CRYPTO_hash (guest_pub_key, sizeof (*guest_pub_key), &guest_pub_hash);

  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Got app guest place notification: %s\n",
              GNUNET_h2s (&guest_pub_hash));

  if (test == TEST_RECONNECT)
  {
    if (0 == memcmp (&place_pub_key, guest_pub_key, sizeof (*guest_pub_key)))
    {
      gst = GNUNET_SOCIAL_guest_enter_reconnect (gconn, GNUNET_PSYC_SLAVE_JOIN_NONE,
                                                 guest_slicer, guest_reconnected, NULL);
    }
  }
}


static void
app_recv_ego (void *cls,
              struct GNUNET_SOCIAL_Ego *ego,
              const struct GNUNET_CRYPTO_EcdsaPublicKey *ego_pub_key,
              const char *name)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Got app ego notification: %p %s %s\n",
              ego, name,
              GNUNET_CRYPTO_ecdsa_public_key_to_string (ego_pub_key));

  if (NULL != strstr (name, host_name) && TEST_HOST_CREATE == test)
  {
    host_ego = ego;
    host_pub_key = *(GNUNET_SOCIAL_ego_get_pub_key (host_ego));
    GNUNET_assert (TEST_HOST_CREATE == test);
    host_enter ();
  }
  else if (NULL != strstr (name, guest_name))
  {
    guest_ego = ego;

    if (TEST_GUEST_CREATE == test)
      guest_init ();
  }
}


static void
schedule_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  test = TEST_RECONNECT;

  GNUNET_SOCIAL_host_disconnect (hst, NULL, NULL);
  GNUNET_SOCIAL_guest_disconnect (gst, NULL, NULL);
  hst = NULL;
  gst = NULL;

  GNUNET_SOCIAL_app_disconnect (app);
  app = GNUNET_SOCIAL_app_connect (cfg, app_id,
                                   app_recv_ego,
                                   app_recv_host,
                                   app_recv_guest,
                                   NULL);
}


static void
host_recv_zone_add_place_result (void *cls, int64_t result,
                                 const void *data, uint16_t data_size)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Zone add place result: %d (%.*s).\n",
              test, result, data_size, data);
  GNUNET_assert (GNUNET_YES == result);

  GNUNET_assert (GNUNET_YES == is_guest_nym_added);
  guest_enter_by_name ();
}


static void
zone_add_place ()
{
  test = TEST_ZONE_ADD_PLACE;
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Adding place to zone.\n", test);

  GNUNET_SOCIAL_zone_add_place (app, host_ego, "home", "let.me*in!",
                                &place_pub_key, &this_peer, 1, &this_peer,
                                GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
                                host_recv_zone_add_place_result, app);
}


static void
host_farewell (void *cls,
               const struct GNUNET_SOCIAL_Nym *nym,
               struct GNUNET_PSYC_Environment *env)
{
  const struct GNUNET_CRYPTO_EcdsaPublicKey *
    nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym);

  char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Farewell: nym %s (%s) has left the place.\n",
              GNUNET_h2s (GNUNET_SOCIAL_nym_get_pub_key_hash (nym)), str);
  GNUNET_free (str);
  GNUNET_assert (1 == GNUNET_PSYC_env_get_count (env));
  if (0 != memcmp (&guest_pub_key, nym_key, sizeof (*nym_key)))
  {
    str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&guest_pub_key);
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Farewell: nym does not match guest: %s\n", str);
    GNUNET_free (str);
    GNUNET_assert (0);
  }
  zone_add_place ();
}


static void
guest_left (void *cls)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "The guest has left the place.\n");
}


static void
guest_leave()
{
  if (test < TEST_RECONNECT)
    test = TEST_GUEST_LEAVE;
  else
    test = TEST_GUEST_LEAVE2;

  struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
  GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
                       "_message", DATA2ARG ("Leaving."));
  GNUNET_SOCIAL_guest_leave (gst, env, &guest_left, NULL);
  GNUNET_PSYC_env_destroy (env);
  gst = NULL;
  gst_plc = NULL;
}


static void
schedule_guest_leave (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  guest_leave ();
}


static void
guest_look_for_result (void *cls, int64_t result_code,
                      const void *data, uint16_t data_size)
{
  struct ResultClosure *rcls = cls;
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "guest_look_for_result: %d\n", result_code);
  GNUNET_assert (GNUNET_OK == result_code);
  GNUNET_assert (3 == rcls->n);
  GNUNET_free (rcls);
  GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
}


static void
guest_look_for_var (void *cls,
                   const struct GNUNET_MessageHeader *mod,
                   const char *name,
                   const void *value,
                   uint32_t value_size,
                   uint32_t full_value_size)
{
  struct ResultClosure *rcls = cls;
  rcls->n++;
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "guest_look_for_var: %s\n%.*s\n",
              name, value_size, value);
}


static void
guest_look_for ()
{
  test = TEST_GUEST_LOOK_FOR;
  struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls));
  GNUNET_SOCIAL_place_look_for (gst_plc, "_foo", guest_look_for_var, guest_look_for_result, rcls);
}


static void
guest_look_at_result (void *cls, int64_t result_code,
                      const void *data, uint16_t data_size)
{
  struct ResultClosure *rcls = cls;

  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "guest_look_at_result: %d\n", result_code);
  GNUNET_assert (GNUNET_OK == result_code);
  GNUNET_assert (1 == rcls->n);
  GNUNET_free (rcls);
  guest_look_for ();
}


static void
guest_look_at_var (void *cls,
                   const struct GNUNET_MessageHeader *mod,
                   const char *name,
                   const void *value,
                   uint32_t value_size,
                   uint32_t full_value_size)
{
  struct ResultClosure *rcls = cls;
  rcls->n++;

  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "guest_look_at_var: %s\n%.*s\n",
              name, value_size, value);
}


static void
guest_look_at ()
{
  test = TEST_GUEST_LOOK_AT;
  struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls));
  GNUNET_SOCIAL_place_look_at (gst_plc, "_foo_bar", guest_look_at_var, guest_look_at_result, rcls);
}


static void
guest_recv_history_replay_latest_result (void *cls, int64_t result,
                                         const void *data, uint16_t data_size)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Guest received latest history replay result: %" PRId64 "\n"
              "%.*s\n",
              test, result, data_size, data);
  GNUNET_assert (2 == counter); /* message count */
  GNUNET_assert (7 == result); /* fragment count */

  guest_look_at ();
}


static void
guest_history_replay_latest ()
{
  test = TEST_GUEST_HISTORY_REPLAY_LATEST;
  counter = 0;
  GNUNET_SOCIAL_place_history_replay_latest (gst_plc, 3, "",
                                             GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
                                             guest_slicer,
                                             &guest_recv_history_replay_latest_result,
                                             NULL);
}


static void
guest_recv_history_replay_result (void *cls, int64_t result,
                                  const void *data, uint16_t data_size)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Guest received history replay result: %" PRId64 "\n"
              "%.*s\n",
              test, result, data_size, data);
  GNUNET_assert (2 == counter); /* message count */
  GNUNET_assert (7 == result); /* fragment count */

  guest_history_replay_latest ();
}


static void
guest_history_replay ()
{
  test = TEST_GUEST_HISTORY_REPLAY;
  counter = 0;
  GNUNET_SOCIAL_place_history_replay (gst_plc, 1, 3, "",
                                      GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
                                      guest_slicer,
                                      &guest_recv_history_replay_result,
                                      NULL);
}


static void
guest_recv_method (void *cls,
                  const struct GNUNET_PSYC_MessageMethod *meth,
                  uint64_t message_id,
                  uint32_t flags,
                  const struct GNUNET_CRYPTO_EcdsaPublicKey *nym_pub_key,
                  const char *method_name)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Guest received method for message ID %" PRIu64 ":\n"
              "%s (flags: %x)\n",
              test, message_id, method_name, flags);
  /** @todo FIXME: check message */
}


static void
guest_recv_modifier (void *cls,
                     const struct GNUNET_MessageHeader *msg,
                     uint64_t message_id,
                     enum GNUNET_PSYC_Operator oper,
                     const char *name,
                     const void *value,
                     uint16_t value_size,
                     uint16_t full_value_size)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Guest received modifier for message ID %" PRIu64 ":\n"
              "%c%s: %.*s (size: %u)\n",
              test, message_id, oper, name, value_size, value, value_size);
  /** @todo FIXME: check modifier */
}

static void
guest_recv_mod_foo_bar (void *cls,
                        const struct GNUNET_MessageHeader *msg,
                        uint64_t message_id,
                        enum GNUNET_PSYC_Operator oper,
                        const char *name,
                        const void *value,
                        uint16_t value_size,
                        uint16_t full_value_size)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Guest received modifier matching _foo_bar for message ID %" PRIu64 ":\n"
              "%c%s: %.*s (size: %u)\n",
              test, message_id, oper, name, value_size, value, value_size);
  struct ResultClosure *rc = cls;
  rc->n++;
  /** @todo FIXME: check modifier */
}


static void
guest_recv_data (void *cls,
                const struct GNUNET_MessageHeader *msg,
                uint64_t message_id,
                uint64_t data_offset,
                const void *data,
                uint16_t data_size)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Guest received data for message ID %" PRIu64 ":\n"
              "%.*s\n",
              test, message_id, data_size, data);
  /** @todo FIXME: check data */
}


static void
guest_recv_eom (void *cls,
               const struct GNUNET_MessageHeader *msg,
               uint64_t message_id,
               uint8_t cancelled)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Guest received end of message ID %" PRIu64
              ", cancelled: %u\n",
              test, message_id, cancelled);

  switch (test)
  {
  case TEST_HOST_ANNOUNCE:
    test = TEST_HOST_ANNOUNCE_END;
    break;

  case TEST_HOST_ANNOUNCE_END:
    host_announce2 ();
    break;

  case TEST_HOST_ANNOUNCE2:
    test = TEST_HOST_ANNOUNCE2_END;
    break;

  case TEST_HOST_ANNOUNCE2_END:
    guest_talk ();
    break;

  case TEST_GUEST_HISTORY_REPLAY:
  case TEST_GUEST_HISTORY_REPLAY_LATEST:
    counter++;
    break;

  default:
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
    GNUNET_assert (0);
  }
}


static void
host_recv_method (void *cls,
                  const struct GNUNET_PSYC_MessageMethod *meth,
                  uint64_t message_id,
                  uint32_t flags,
                  const struct GNUNET_CRYPTO_EcdsaPublicKey *nym_pub_key,
                  const char *method_name)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Host received method for message ID %" PRIu64 ":\n"
              "%s\n",
              test, message_id, method_name);
  /** @todo FIXME: check message */
}


static void
host_recv_modifier (void *cls,
                    const struct GNUNET_MessageHeader *msg,
                    uint64_t message_id,
                    enum GNUNET_PSYC_Operator oper,
                    const char *name,
                    const void *value,
                    uint16_t value_size,
                    uint16_t full_value_size)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Host received modifier for message ID %" PRIu64 ":\n"
              "%c%s: %.*s\n",
              test, message_id, oper, name, value_size, value);
}


static void
host_recv_data (void *cls,
                const struct GNUNET_MessageHeader *msg,
                uint64_t message_id,
                uint64_t data_offset,
                const void *data,
                uint16_t data_size)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Host received data for message ID %" PRIu64 ":\n"
              "%.*s\n",
              test, message_id, data_size, data);
}


static void
host_recv_eom (void *cls,
               const struct GNUNET_MessageHeader *msg,
               uint64_t message_id,
               uint8_t cancelled)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Host received end of message ID %" PRIu64
              ", cancelled: %u\n",
              test, message_id, cancelled);

  switch (test)
  {
  case TEST_HOST_ANNOUNCE:
    test = TEST_HOST_ANNOUNCE_END;
    break;

  case TEST_HOST_ANNOUNCE_END:
    host_announce2 ();
    break;

  case TEST_HOST_ANNOUNCE2:
    test = TEST_HOST_ANNOUNCE2_END;
    break;

  case TEST_HOST_ANNOUNCE2_END:
    guest_talk ();
    break;

  case TEST_GUEST_TALK:
    guest_history_replay ();
    break;

  default:
    if (TEST_GUEST_LEAVE <= test)
      break;
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
    GNUNET_assert (0);
  }
}


static void
guest_talk ()
{
  test = TEST_GUEST_TALK;

  tmit = (struct TransmitClosure) {};
  tmit.env = GNUNET_PSYC_env_create ();
  GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
                       "_bar_foo", DATA2ARG ("one two three"));
  GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
                       "_bar_baz", DATA2ARG ("four five"));
  tmit.data[0] = "zzz xxx yyy";
  tmit.data[1] = "zyx wvu tsr qpo";
  tmit.data_delay[1] = 1;
  tmit.data[2] = "testing ten nine eight";
  tmit.data_count = 3;

  tmit.guest_talk
    = GNUNET_SOCIAL_guest_talk (gst, "_message_guest", tmit.env,
                                &notify_data, &tmit,
                                GNUNET_SOCIAL_TALK_NONE);
}


static void
host_announce ()
{
  test = TEST_HOST_ANNOUNCE;

  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Host announcement.\n", test);

  tmit = (struct TransmitClosure) {};
  tmit.env = GNUNET_PSYC_env_create ();
  GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
                       "_foo", DATA2ARG ("bar baz"));
  GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
                       "_foo_bar", DATA2ARG ("foo bar"));
  GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
                       "_foo_bar_baz", DATA2ARG ("foo bar baz"));
  tmit.data[0] = "aaa bbb ccc";
  tmit.data[1] = "abc def ghi jkl";
  tmit.data_delay[1] = 1;
  tmit.data[2] = "testing one two three";
  tmit.data[3] = "four five";
  tmit.data_count = 4;

  tmit.host_ann
    = GNUNET_SOCIAL_host_announce (hst, "_message_host", tmit.env,
                                   &notify_data, &tmit,
                                   GNUNET_SOCIAL_ANNOUNCE_NONE);
}


static void
host_announce2 ()
{
  GNUNET_assert (2 == mod_foo_bar_rcls.n);
  GNUNET_PSYC_slicer_modifier_remove (guest_slicer, "_foo_bar",
                                      guest_recv_mod_foo_bar);

  test = TEST_HOST_ANNOUNCE2;

  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Host announcement 2.\n", test);

  tmit = (struct TransmitClosure) {};
  tmit.env = GNUNET_PSYC_env_create ();
  GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
                       "_foo2", DATA2ARG ("BAR BAZ"));
  GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
                       "_foo2_bar", DATA2ARG ("FOO BAR"));
  GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
                       "_foo2_bar", DATA2ARG ("FOO BAR BAZ"));
  tmit.data[0] = "AAA BBB CCC";
  tmit.data[1] = "ABC DEF GHI JKL";
  tmit.data[2] = "TESTING ONE TWO THREE";
  tmit.data_count = 3;

  tmit.host_ann
    = GNUNET_SOCIAL_host_announce (hst, "_message_host_two", tmit.env,
                                   &notify_data, &tmit,
                                   GNUNET_SOCIAL_ANNOUNCE_NONE);
}


static void
guest_recv_entry_decision (void *cls,
                           int is_admitted,
                           const struct GNUNET_PSYC_Message *entry_msg)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Guest received entry decision (try %u): %d.\n",
              test, join_req_count, is_admitted);

  if (NULL != entry_msg)
  {
    struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
    const char *method_name = NULL;
    const void *data = NULL;
    uint16_t data_size = 0;
    struct GNUNET_PSYC_MessageHeader *
      pmsg = GNUNET_PSYC_message_header_create_from_psyc (entry_msg);
    GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size);
    GNUNET_free (pmsg);

    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "%s\n%.*s\n",
                method_name, data_size, data);
    /** @todo FIXME: check response message */
  }

  switch (test)
  {
  case TEST_GUEST_RECV_ENTRY_DCSN_REFUSE:
    GNUNET_assert (GNUNET_NO == is_admitted);
    guest_enter ();
    break;

  case TEST_GUEST_RECV_ENTRY_DCSN_ADMIT:
    GNUNET_assert (GNUNET_YES == is_admitted);
    host_announce ();
    break;

  case TEST_GUEST_ENTER_BY_NAME:
    GNUNET_SCHEDULER_add_now (schedule_reconnect, NULL);
    break;

  default:
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
    GNUNET_assert (0);
  }
}


static void
host_answer_door (void *cls,
                  struct GNUNET_SOCIAL_Nym *nym,
                  const char *method_name,
                  struct GNUNET_PSYC_Environment *env,
                  size_t data_size,
                  const void *data)
{
  join_req_count++;

  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Host received entry request from guest (try %u).\n",
              test, join_req_count);
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "%s\n%.*s\n",
              method_name, data_size, data);

  switch (test)
  {
  case TEST_HOST_ANSWER_DOOR_REFUSE:
    test = TEST_GUEST_RECV_ENTRY_DCSN_REFUSE;
    join_resp = GNUNET_PSYC_message_create ("_refuse_nym", env,
                                            DATA2ARG ("Go away!"));
    GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_NO, join_resp);
    break;

  case TEST_HOST_ANSWER_DOOR_ADMIT:
    test = TEST_GUEST_RECV_ENTRY_DCSN_ADMIT;
  case TEST_GUEST_ENTER_BY_NAME:
    join_resp = GNUNET_PSYC_message_create ("_admit_nym", env,
                                            DATA2ARG ("Welcome, nym!"));
    GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp);
    break;

  default:
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
    GNUNET_assert (0);
  }
}


static void
guest_recv_local_enter (void *cls, int result, uint64_t max_message_id)
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Guest entered to local place: %d\n",
              test, result);
  GNUNET_assert (0 <= result);
}


static void
guest_enter ()
{
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Entering to place as guest.\n", test);

  struct GuestEnterMessage *emsg = &guest_enter_msg;

  emsg->method_name = "_request_enter";
  emsg->env = GNUNET_PSYC_env_create ();
  GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
                       "_abc", "abc def", 7);
  GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
                       "_abc_def", "abc def ghi", 11);
  emsg->data = "let me in";
  emsg->data_size = strlen (emsg->data) + 1;
  emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
                                          emsg->data, emsg->data_size);

  gst = GNUNET_SOCIAL_guest_enter (app, guest_ego, &place_pub_key,
                                   GNUNET_PSYC_SLAVE_JOIN_NONE,
                                   &this_peer, 0, NULL, emsg->msg, guest_slicer,
                                   guest_recv_local_enter,
                                   guest_recv_entry_decision, NULL);
  gst_plc = GNUNET_SOCIAL_guest_get_place (gst);
}


static void
guest_enter_by_name ()
{
  test = TEST_GUEST_ENTER_BY_NAME;
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Test #%u: Entering to place by name as guest.\n", test);

  struct GuestEnterMessage *emsg = &guest_enter_msg;

  emsg->method_name = "_request_enter";
  emsg->env = GNUNET_PSYC_env_create ();
  GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
                       "_abc", "abc def", 7);
  GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
                       "_abc_def", "abc def ghi", 11);
  emsg->data = "let me in";
  emsg->data_size = strlen (emsg->data) + 1;
  emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
                                          emsg->data, emsg->data_size);

  gst = GNUNET_SOCIAL_guest_enter_by_name (app, guest_ego,
                                           "home.host.gnu", "let.me*in!",
                                           emsg->msg, guest_slicer,
                                           guest_recv_local_enter,
                                           guest_recv_entry_decision, NULL);
  gst_plc = GNUNET_SOCIAL_guest_get_place (gst);
}


static void
app_recv_zone_add_nym_result (void *cls, int64_t result,
                              const void *data, uint16_t data_size)
{
  GNUNET_assert (GNUNET_YES == result);
  is_guest_nym_added = GNUNET_YES;
}


static void
guest_init ()
{
  guest_pub_key = *(GNUNET_SOCIAL_ego_get_pub_key (guest_ego));

  guest_slicer = GNUNET_PSYC_slicer_create ();
  GNUNET_PSYC_slicer_method_add (guest_slicer, "",
                                 guest_recv_method, guest_recv_modifier,
                                 guest_recv_data, guest_recv_eom, NULL);
  GNUNET_PSYC_slicer_modifier_add (guest_slicer, "_foo_bar",
                                   guest_recv_mod_foo_bar, &mod_foo_bar_rcls);
  test = TEST_HOST_ANSWER_DOOR_ADMIT;

  GNUNET_SOCIAL_zone_add_nym (app, guest_ego, "host", &host_pub_key,
                              GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
                              app_recv_zone_add_nym_result, NULL);
  guest_enter ();
}


static void
id_guest_created (void *cls, const char *emsg)
{
  if (NULL != emsg)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Could not create guest identity: %s\n", emsg);
#if ! DEBUG_TEST_SOCIAL
    GNUNET_assert (0);
#endif
  }
  if (NULL != guest_ego)
    guest_init ();
}


static void
host_entered (void *cls, int result,
              const struct GNUNET_CRYPTO_EddsaPublicKey *home_pub_key,
              uint64_t max_message_id)
{
  place_pub_key = *home_pub_key;
  GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Host entered to place %s\n", GNUNET_h2s (&place_pub_hash));

  test = TEST_GUEST_CREATE;
  GNUNET_IDENTITY_create (id, guest_name, &id_guest_created, NULL);
}


static void
host_enter ()
{
  host_slicer = GNUNET_PSYC_slicer_create ();
  GNUNET_PSYC_slicer_method_add (host_slicer, "",
                                 &host_recv_method, &host_recv_modifier,
                                 &host_recv_data, &host_recv_eom, NULL);

  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Entering to place as host.\n");
  test = TEST_HOST_ENTER;
  hst = GNUNET_SOCIAL_host_enter (app, host_ego,
                                  GNUNET_PSYC_CHANNEL_PRIVATE,
                                  host_slicer, host_entered,
                                  host_answer_door, host_farewell, NULL);
  hst_plc = GNUNET_SOCIAL_host_get_place (hst);
}


static void
id_host_created (void *cls, const char *emsg)
{
  if (NULL != core)
  {
    GNUNET_CORE_disconnect (core);
    core = NULL;
  }

  if (NULL != emsg)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Could not create host identity: %s\n", emsg);
#if ! DEBUG_TEST_SOCIAL
    GNUNET_assert (0);
#endif
  }

  app = GNUNET_SOCIAL_app_connect (cfg, app_id,
                                   app_recv_ego,
                                   app_recv_host,
                                   app_recv_guest,
                                   NULL);
}


static void
identity_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego,
                 void **ctx, const char *name)
{
}


static void
core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity)
{
  this_peer = *my_identity;
  id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL);

  test = TEST_HOST_CREATE;
  GNUNET_IDENTITY_create (id, host_name, &id_host_created, NULL);
}


/**
 * Main function of the test, run from scheduler.
 *
 * @param cls NULL
 * @param cfg configuration we use (also to connect to Social service)
 * @param peer handle to access more of the peer (not used)
 */
static void
#if DEBUG_TEST_SOCIAL
run (void *cls, char *const *args, const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *c)
#else
run (void *cls,
     const struct GNUNET_CONFIGURATION_Handle *c,
     struct GNUNET_TESTING_Peer *peer)
#endif
{
  cfg = c;
  end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);

  core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL,
                              NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
}


int
main (int argc, char *argv[])
{
  res = 1;
#if DEBUG_TEST_SOCIAL
  const struct GNUNET_GETOPT_CommandLineOption opts[] = {
    GNUNET_GETOPT_OPTION_END
  };
  if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-social",
                                       "test-social [options]",
                                       opts, &run, NULL))
    return 1;
#else
  if (0 != GNUNET_TESTING_peer_run ("test-social", "test_social.conf", &run, NULL))
    return 1;
#endif
  return res;
}

/* end of test_social.c */