2 This file is part of GNUnet.
3 Copyright (C) 2012-2014 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file set/test_set_intersection_result_full.c
23 * @brief testcase for full result mode of the intersection set operation
24 * @author Christian Fuchs
25 * @author Christian Grothoff
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testing_lib.h"
30 #include "gnunet_set_service.h"
35 static struct GNUNET_PeerIdentity local_id;
37 static struct GNUNET_HashCode app_id;
39 static struct GNUNET_SET_Handle *set1;
41 static struct GNUNET_SET_Handle *set2;
43 static struct GNUNET_SET_ListenHandle *listen_handle;
45 static const struct GNUNET_CONFIGURATION_Handle *config;
47 static int iter_count;
49 static struct GNUNET_SCHEDULER_Task *tt;
51 static struct GNUNET_SET_OperationHandle *oh1;
53 static struct GNUNET_SET_OperationHandle *oh2;
57 result_cb_set1 (void *cls,
58 const struct GNUNET_SET_Element *element,
59 enum GNUNET_SET_Status status)
65 case GNUNET_SET_STATUS_OK:
68 case GNUNET_SET_STATUS_FAILURE:
72 case GNUNET_SET_STATUS_DONE:
74 GNUNET_assert (1 == count);
75 GNUNET_SET_destroy (set1);
85 result_cb_set2 (void *cls,
86 const struct GNUNET_SET_Element *element,
87 enum GNUNET_SET_Status status)
93 case GNUNET_SET_STATUS_OK:
96 case GNUNET_SET_STATUS_FAILURE:
100 case GNUNET_SET_STATUS_DONE:
102 GNUNET_assert (1 == count);
103 GNUNET_SET_destroy (set2);
113 listen_cb (void *cls,
114 const struct GNUNET_PeerIdentity *other_peer,
115 const struct GNUNET_MessageHeader *context_msg,
116 struct GNUNET_SET_Request *request)
118 GNUNET_assert (NULL != context_msg);
119 GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_TEST);
120 GNUNET_SET_listen_cancel (listen_handle);
121 listen_handle = NULL;
122 oh2 = GNUNET_SET_accept (request,
123 GNUNET_SET_RESULT_FULL,
126 GNUNET_SET_commit (oh2,
132 * Start the set operation.
134 * @param cls closure, unused
139 struct GNUNET_MessageHeader context_msg;
141 context_msg.size = htons (sizeof context_msg);
142 context_msg.type = htons (GNUNET_MESSAGE_TYPE_TEST);
143 listen_handle = GNUNET_SET_listen (config,
144 GNUNET_SET_OPERATION_INTERSECTION,
147 oh1 = GNUNET_SET_prepare (&local_id,
150 GNUNET_SET_RESULT_FULL,
153 GNUNET_SET_commit (oh1,
159 * Initialize the second set, continue
161 * @param cls closure, unused
164 init_set2 (void *cls)
166 struct GNUNET_SET_Element element;
168 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
169 "initializing set 2\n");
170 element.element_type = 0;
171 element.data = "hello";
172 element.size = strlen(element.data);
173 GNUNET_SET_add_element (set2, &element, NULL, NULL);
174 element.data = "quux";
175 element.size = strlen(element.data);
176 GNUNET_SET_add_element (set2, &element, NULL, NULL);
177 element.data = "baz";
178 element.size = strlen(element.data);
179 GNUNET_SET_add_element (set2, &element, &start, NULL);
184 * Initialize the first set, continue.
189 struct GNUNET_SET_Element element;
191 element.element_type = 0;
192 element.data = "hello";
193 element.size = strlen(element.data);
194 GNUNET_SET_add_element (set1, &element, NULL, NULL);
195 element.data = "bar";
196 element.size = strlen(element.data);
197 GNUNET_SET_add_element (set1, &element, &init_set2, NULL);
203 const struct GNUNET_SET_Element *element)
207 GNUNET_assert (iter_count == 3);
208 GNUNET_SET_destroy (cls);
219 struct GNUNET_SET_Element element;
220 struct GNUNET_SET_Handle *iter_set;
222 iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_INTERSECTION);
223 element.element_type = 0;
224 element.data = "hello";
225 element.size = strlen(element.data);
226 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
227 element.data = "bar";
228 element.size = strlen(element.data);
229 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
230 element.data = "quux";
231 element.size = strlen(element.data);
232 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
233 GNUNET_SET_iterate (iter_set,
240 * Function run on shutdown.
245 do_shutdown (void *cls)
249 GNUNET_SCHEDULER_cancel (tt);
254 GNUNET_SET_operation_cancel (oh1);
259 GNUNET_SET_operation_cancel (oh2);
264 GNUNET_SET_destroy (set1);
269 GNUNET_SET_destroy (set2);
272 if (NULL != listen_handle)
274 GNUNET_SET_listen_cancel (listen_handle);
275 listen_handle = NULL;
281 * Function run on timeout.
286 timeout_fail (void *cls)
289 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
290 "Testcase failed with timeout\n");
291 GNUNET_SCHEDULER_shutdown ();
297 * Signature of the 'main' function for a (single-peer) testcase that
298 * is run using 'GNUNET_TESTING_peer_run'.
301 * @param cfg configuration of the peer that was started
302 * @param peer identity of the peer that was created
306 const struct GNUNET_CONFIGURATION_Handle *cfg,
307 struct GNUNET_TESTING_Peer *peer)
310 GNUNET_TESTING_peer_get_identity (peer, &local_id);
313 tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
316 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
319 set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
320 set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
321 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
324 /* test the real set reconciliation */
330 main (int argc, char **argv)
332 if (0 != GNUNET_TESTING_peer_run ("test_set_api",