2 This file is part of GNUnet.
3 (C) 2004, 2009 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file peerinfo/test_peerinfo_api_notify_friend_only.c
23 * @brief testcase friend only HELLO restrictions in for peerinfo
24 * @author Christian Grothoff
25 * @author Matthias Wachs
28 * - test merging of HELLOs (add same peer twice...)
31 #include "gnunet_hello_lib.h"
32 #include "gnunet_util_lib.h"
33 #include "gnunet_peerinfo_service.h"
34 #include "gnunet_testing_lib.h"
37 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
39 static struct GNUNET_PEERINFO_Handle *h;
40 static struct GNUNET_PEERINFO_NotifyContext *pnc_w_fo;
41 static struct GNUNET_PEERINFO_NotifyContext *pnc_wo_fo;
43 static const struct GNUNET_CONFIGURATION_Handle *mycfg;
46 static int global_ret;
49 * Did we get a HELLO callback for notification handle with friend HELLOS
52 static int res_cb_w_fo;
55 * Did we get a HELLO callback for notification handle without friend HELLOS
58 static int res_cb_wo_fo;
60 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
64 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
66 timeout_task = GNUNET_SCHEDULER_NO_TASK;
68 if (NULL != pnc_wo_fo)
70 GNUNET_PEERINFO_notify_cancel (pnc_wo_fo);
75 GNUNET_PEERINFO_notify_cancel (pnc_w_fo);
80 GNUNET_PEERINFO_disconnect (h);
87 done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
90 GNUNET_PEERINFO_notify_cancel (pnc_w_fo);
92 if (NULL != pnc_wo_fo)
93 GNUNET_PEERINFO_notify_cancel (pnc_wo_fo);
95 GNUNET_PEERINFO_disconnect (h);
98 if (GNUNET_SCHEDULER_NO_TASK != timeout_task)
100 GNUNET_SCHEDULER_cancel (timeout_task);
101 timeout_task = GNUNET_SCHEDULER_NO_TASK;
104 if ((GNUNET_YES == res_cb_w_fo) && (GNUNET_NO == res_cb_wo_fo))
111 address_generator (void *cls, size_t max, void *buf)
115 struct GNUNET_HELLO_Address address;
119 memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity));
120 address.address = "Address";
121 address.transport_name = "peerinfotest";
122 address.address_length = *agc;
124 GNUNET_HELLO_add_address (&address,
125 GNUNET_TIME_relative_to_absolute
126 (GNUNET_TIME_UNIT_HOURS), buf, max);
132 process_w_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
133 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
138 _("Error in communication with PEERINFO service\n"));
139 GNUNET_SCHEDULER_add_now(&done, NULL);
148 if (GNUNET_NO == GNUNET_HELLO_is_friend_only(hello))
154 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO\n",
155 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public");
156 res_cb_w_fo = GNUNET_YES;
157 GNUNET_SCHEDULER_add_now(&done, NULL);
163 process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
164 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
168 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
169 _("Error in communication with PEERINFO service\n"));
170 GNUNET_SCHEDULER_add_now(&done, NULL);
181 if (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello))
187 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO\n",
188 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public");
189 res_cb_wo_fo = GNUNET_YES;
194 add_peer_done (void *cls, const char *emsg)
198 pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL);
199 pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL);
205 GNUNET_SCHEDULER_cancel (timeout_task);
206 timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
215 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
216 struct GNUNET_PeerIdentity pid;
217 struct GNUNET_HELLO_Message *h2;
221 memset (&pkey, 32, sizeof (pkey));
222 GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey);
223 h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc, GNUNET_YES);
224 GNUNET_PEERINFO_add_peer (h, h2, &add_peer_done, NULL);
233 const struct GNUNET_CONFIGURATION_Handle *cfg,
234 struct GNUNET_TESTING_Peer *peer)
236 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
238 h = GNUNET_PEERINFO_connect (cfg);
239 GNUNET_assert (NULL != h);
245 main (int argc, char *argv[])
247 res_cb_w_fo = GNUNET_NO;
248 res_cb_wo_fo = GNUNET_NO;
250 if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only",
252 "test_peerinfo_api_data.conf",
258 /* end of test_peerinfo_api_notify_friend_only.c */