2 This file is part of GNUnet.
3 Copyright (C) 2012-2014 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., 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;
51 result_cb_set1 (void *cls,
52 const struct GNUNET_SET_Element *element,
53 enum GNUNET_SET_Status status)
59 case GNUNET_SET_STATUS_OK:
62 case GNUNET_SET_STATUS_FAILURE:
65 case GNUNET_SET_STATUS_DONE:
66 GNUNET_assert (1 == count);
67 GNUNET_SET_destroy (set1);
76 result_cb_set2 (void *cls,
77 const struct GNUNET_SET_Element *element,
78 enum GNUNET_SET_Status status)
84 case GNUNET_SET_STATUS_OK:
87 case GNUNET_SET_STATUS_FAILURE:
90 case GNUNET_SET_STATUS_DONE:
91 GNUNET_assert (1 == count);
92 GNUNET_SET_destroy (set2);
101 listen_cb (void *cls,
102 const struct GNUNET_PeerIdentity *other_peer,
103 const struct GNUNET_MessageHeader *context_msg,
104 struct GNUNET_SET_Request *request)
106 struct GNUNET_SET_OperationHandle *oh;
108 GNUNET_assert (NULL != context_msg);
109 GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_TEST);
110 GNUNET_SET_listen_cancel (listen_handle);
111 oh = GNUNET_SET_accept (request,
112 GNUNET_SET_RESULT_FULL,
113 &result_cb_set2, NULL);
114 GNUNET_SET_commit (oh, set2);
119 * Start the set operation.
121 * @param cls closure, unused
126 struct GNUNET_SET_OperationHandle *oh;
127 struct GNUNET_MessageHeader context_msg;
129 context_msg.size = htons (sizeof context_msg);
130 context_msg.type = htons (GNUNET_MESSAGE_TYPE_TEST);
131 listen_handle = GNUNET_SET_listen (config,
132 GNUNET_SET_OPERATION_INTERSECTION,
135 oh = GNUNET_SET_prepare (&local_id,
138 GNUNET_SET_RESULT_FULL,
139 &result_cb_set1, NULL);
140 GNUNET_SET_commit (oh, set1);
145 * Initialize the second set, continue
147 * @param cls closure, unused
150 init_set2 (void *cls)
152 struct GNUNET_SET_Element element;
154 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
155 "initializing set 2\n");
156 element.element_type = 0;
157 element.data = "hello";
158 element.size = strlen(element.data);
159 GNUNET_SET_add_element (set2, &element, NULL, NULL);
160 element.data = "quux";
161 element.size = strlen(element.data);
162 GNUNET_SET_add_element (set2, &element, NULL, NULL);
163 element.data = "baz";
164 element.size = strlen(element.data);
165 GNUNET_SET_add_element (set2, &element, &start, NULL);
170 * Initialize the first set, continue.
175 struct GNUNET_SET_Element element;
177 element.element_type = 0;
178 element.data = "hello";
179 element.size = strlen(element.data);
180 GNUNET_SET_add_element (set1, &element, NULL, NULL);
181 element.data = "bar";
182 element.size = strlen(element.data);
183 GNUNET_SET_add_element (set1, &element, &init_set2, NULL);
189 const struct GNUNET_SET_Element *element)
193 GNUNET_assert (iter_count == 3);
194 GNUNET_SET_destroy (cls);
205 struct GNUNET_SET_Element element;
206 struct GNUNET_SET_Handle *iter_set;
208 iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_INTERSECTION);
209 element.element_type = 0;
210 element.data = "hello";
211 element.size = strlen(element.data);
212 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
213 element.data = "bar";
214 element.size = strlen(element.data);
215 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
216 element.data = "quux";
217 element.size = strlen(element.data);
218 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
219 GNUNET_SET_iterate (iter_set, &iter_cb, iter_set);
224 * Signature of the 'main' function for a (single-peer) testcase that
225 * is run using 'GNUNET_TESTING_peer_run'.
228 * @param cfg configuration of the peer that was started
229 * @param peer identity of the peer that was created
233 const struct GNUNET_CONFIGURATION_Handle *cfg,
234 struct GNUNET_TESTING_Peer *peer)
237 GNUNET_TESTING_peer_get_identity (peer, &local_id);
240 set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
241 set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
242 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &app_id);
244 /* test the real set reconciliation */
250 main (int argc, char **argv)
252 if (0 != GNUNET_TESTING_peer_run ("test_set_api",