2 This file is part of GNUnet.
3 Copyright (C) 2004, 2009 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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;
45 static int global_ret;
48 * Did we get a HELLO callback for notification handle with friend HELLOS
51 static int res_cb_w_fo;
54 * Did we get a HELLO callback for notification handle without friend HELLOS
57 static int res_cb_wo_fo;
59 struct GNUNET_PeerIdentity pid;
61 struct GNUNET_SCHEDULER_Task *timeout_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);
91 GNUNET_PEERINFO_notify_cancel (pnc_w_fo);
93 if (NULL != pnc_wo_fo)
94 GNUNET_PEERINFO_notify_cancel (pnc_wo_fo);
96 GNUNET_PEERINFO_disconnect (h);
99 if (NULL != timeout_task)
101 GNUNET_SCHEDULER_cancel (timeout_task);
105 if ((GNUNET_YES == res_cb_w_fo) && (GNUNET_NO == res_cb_wo_fo))
113 address_generator (void *cls, size_t max, void *buf)
117 struct GNUNET_HELLO_Address address;
120 return GNUNET_SYSERR; /* Done */
121 memset (&address.peer, 0, sizeof(struct GNUNET_PeerIdentity));
122 address.address = "Address";
123 address.transport_name = "peerinfotest";
124 address.address_length = *agc;
125 ret = GNUNET_HELLO_add_address (&address,
126 GNUNET_TIME_relative_to_absolute (
127 GNUNET_TIME_UNIT_HOURS), buf, max);
134 process_w_fo (void *cls,
135 const struct GNUNET_PeerIdentity *peer,
136 const struct GNUNET_HELLO_Message *hello,
141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
142 _ ("Error in communication with PEERINFO service\n"));
143 GNUNET_SCHEDULER_add_now (&done, NULL);
149 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
150 "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s (peer),
151 (NULL != hello) ? "with" : "without");
156 if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello))
162 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n",
163 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ?
164 "friend only" : "public",
166 if (0 == GNUNET_memcmp (&pid, peer))
168 res_cb_w_fo = GNUNET_YES;
169 GNUNET_SCHEDULER_add_now (&done, NULL);
177 process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
178 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
182 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
183 _ ("Error in communication with PEERINFO service\n"));
184 GNUNET_SCHEDULER_add_now (&done, NULL);
190 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
191 "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s (peer),
192 (NULL != hello) ? "with" : "without");
197 if (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello))
203 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n",
204 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ?
205 "friend only" : "public",
207 if (0 == GNUNET_memcmp (&pid, peer))
210 res_cb_wo_fo = GNUNET_YES;
219 struct GNUNET_HELLO_Message *h2;
223 memset (&pid, 32, sizeof(pid));
224 h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc,
226 GNUNET_PEERINFO_add_peer (h, h2, NULL, 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 pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL);
239 pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL);
240 h = GNUNET_PEERINFO_connect (cfg);
241 GNUNET_assert (NULL != h);
247 main (int argc, char *argv[])
249 res_cb_w_fo = GNUNET_NO;
250 res_cb_wo_fo = GNUNET_NO;
252 if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only",
254 "test_peerinfo_api_data.conf",
261 /* end of test_peerinfo_api_notify_friend_only.c */