aboutsummaryrefslogtreecommitdiff
path: root/src/set/test_set_intersection_result_full.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/set/test_set_intersection_result_full.c')
-rw-r--r--src/set/test_set_intersection_result_full.c388
1 files changed, 197 insertions, 191 deletions
diff --git a/src/set/test_set_intersection_result_full.c b/src/set/test_set_intersection_result_full.c
index 3f209668d..12ebcb64f 100644
--- a/src/set/test_set_intersection_result_full.c
+++ b/src/set/test_set_intersection_result_full.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file set/test_set_intersection_result_full.c 22 * @file set/test_set_intersection_result_full.c
@@ -54,90 +54,96 @@ static struct GNUNET_SET_OperationHandle *oh2;
54 54
55 55
56static void 56static void
57result_cb_set1 (void *cls, 57result_cb_set1(void *cls,
58 const struct GNUNET_SET_Element *element, 58 const struct GNUNET_SET_Element *element,
59 uint64_t current_size, 59 uint64_t current_size,
60 enum GNUNET_SET_Status status) 60 enum GNUNET_SET_Status status)
61{ 61{
62 static int count; 62 static int count;
63 63
64 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 64 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
65 "Processing result set 1 (%d)\n", 65 "Processing result set 1 (%d)\n",
66 status); 66 status);
67 switch (status) 67 switch (status)
68 { 68 {
69 case GNUNET_SET_STATUS_OK: 69 case GNUNET_SET_STATUS_OK:
70 count++; 70 count++;
71 break; 71 break;
72 case GNUNET_SET_STATUS_FAILURE: 72
73 oh1 = NULL; 73 case GNUNET_SET_STATUS_FAILURE:
74 ret = 1; 74 oh1 = NULL;
75 break; 75 ret = 1;
76 case GNUNET_SET_STATUS_DONE: 76 break;
77 oh1 = NULL; 77
78 GNUNET_assert (1 == count); 78 case GNUNET_SET_STATUS_DONE:
79 GNUNET_SET_destroy (set1); 79 oh1 = NULL;
80 set1 = NULL; 80 GNUNET_assert(1 == count);
81 if (NULL == set2) 81 GNUNET_SET_destroy(set1);
82 GNUNET_SCHEDULER_shutdown (); 82 set1 = NULL;
83 break; 83 if (NULL == set2)
84 default: 84 GNUNET_SCHEDULER_shutdown();
85 GNUNET_assert (0); 85 break;
86 } 86
87 default:
88 GNUNET_assert(0);
89 }
87} 90}
88 91
89 92
90static void 93static void
91result_cb_set2 (void *cls, 94result_cb_set2(void *cls,
92 const struct GNUNET_SET_Element *element, 95 const struct GNUNET_SET_Element *element,
93 uint64_t current_size, 96 uint64_t current_size,
94 enum GNUNET_SET_Status status) 97 enum GNUNET_SET_Status status)
95{ 98{
96 static int count; 99 static int count;
97 100
98 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 101 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
99 "Processing result set 2 (%d)\n", 102 "Processing result set 2 (%d)\n",
100 status); 103 status);
101 switch (status) 104 switch (status)
102 { 105 {
103 case GNUNET_SET_STATUS_OK: 106 case GNUNET_SET_STATUS_OK:
104 count++; 107 count++;
105 break; 108 break;
106 case GNUNET_SET_STATUS_FAILURE: 109
107 oh2 = NULL; 110 case GNUNET_SET_STATUS_FAILURE:
108 ret = 1; 111 oh2 = NULL;
109 break; 112 ret = 1;
110 case GNUNET_SET_STATUS_DONE: 113 break;
111 oh2 = NULL; 114
112 GNUNET_assert (1 == count); 115 case GNUNET_SET_STATUS_DONE:
113 GNUNET_SET_destroy (set2); 116 oh2 = NULL;
114 set2 = NULL; 117 GNUNET_assert(1 == count);
115 if (NULL == set1) 118 GNUNET_SET_destroy(set2);
116 GNUNET_SCHEDULER_shutdown (); 119 set2 = NULL;
117 break; 120 if (NULL == set1)
118 default: 121 GNUNET_SCHEDULER_shutdown();
119 GNUNET_assert (0); 122 break;
120 } 123
124 default:
125 GNUNET_assert(0);
126 }
121} 127}
122 128
123 129
124static void 130static void
125listen_cb (void *cls, 131listen_cb(void *cls,
126 const struct GNUNET_PeerIdentity *other_peer, 132 const struct GNUNET_PeerIdentity *other_peer,
127 const struct GNUNET_MessageHeader *context_msg, 133 const struct GNUNET_MessageHeader *context_msg,
128 struct GNUNET_SET_Request *request) 134 struct GNUNET_SET_Request *request)
129{ 135{
130 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 136 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
131 "starting intersection by accepting and committing\n"); 137 "starting intersection by accepting and committing\n");
132 GNUNET_assert (NULL != context_msg); 138 GNUNET_assert(NULL != context_msg);
133 GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); 139 GNUNET_assert(ntohs(context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY);
134 oh2 = GNUNET_SET_accept (request, 140 oh2 = GNUNET_SET_accept(request,
135 GNUNET_SET_RESULT_FULL, 141 GNUNET_SET_RESULT_FULL,
136 (struct GNUNET_SET_Option[]) { 0 }, 142 (struct GNUNET_SET_Option[]) { 0 },
137 &result_cb_set2, 143 &result_cb_set2,
138 NULL); 144 NULL);
139 GNUNET_SET_commit (oh2, 145 GNUNET_SET_commit(oh2,
140 set2); 146 set2);
141} 147}
142 148
143 149
@@ -147,28 +153,28 @@ listen_cb (void *cls,
147 * @param cls closure, unused 153 * @param cls closure, unused
148 */ 154 */
149static void 155static void
150start (void *cls) 156start(void *cls)
151{ 157{
152 struct GNUNET_MessageHeader context_msg; 158 struct GNUNET_MessageHeader context_msg;
153 159
154 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 160 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
155 "starting listener\n"); 161 "starting listener\n");
156 context_msg.size = htons (sizeof context_msg); 162 context_msg.size = htons(sizeof context_msg);
157 context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY); 163 context_msg.type = htons(GNUNET_MESSAGE_TYPE_DUMMY);
158 listen_handle = GNUNET_SET_listen (config, 164 listen_handle = GNUNET_SET_listen(config,
159 GNUNET_SET_OPERATION_INTERSECTION, 165 GNUNET_SET_OPERATION_INTERSECTION,
160 &app_id, 166 &app_id,
161 &listen_cb, 167 &listen_cb,
162 NULL); 168 NULL);
163 oh1 = GNUNET_SET_prepare (&local_id, 169 oh1 = GNUNET_SET_prepare(&local_id,
164 &app_id, 170 &app_id,
165 &context_msg, 171 &context_msg,
166 GNUNET_SET_RESULT_FULL, 172 GNUNET_SET_RESULT_FULL,
167 (struct GNUNET_SET_Option[]) { 0 }, 173 (struct GNUNET_SET_Option[]) { 0 },
168 &result_cb_set1, 174 &result_cb_set1,
169 NULL); 175 NULL);
170 GNUNET_SET_commit (oh1, 176 GNUNET_SET_commit(oh1,
171 set1); 177 set1);
172} 178}
173 179
174 180
@@ -178,31 +184,31 @@ start (void *cls)
178 * @param cls closure, unused 184 * @param cls closure, unused
179 */ 185 */
180static void 186static void
181init_set2 (void *cls) 187init_set2(void *cls)
182{ 188{
183 struct GNUNET_SET_Element element; 189 struct GNUNET_SET_Element element;
184 190
185 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 191 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
186 "initializing set 2\n"); 192 "initializing set 2\n");
187 element.element_type = 0; 193 element.element_type = 0;
188 element.data = "hello"; 194 element.data = "hello";
189 element.size = strlen(element.data); 195 element.size = strlen(element.data);
190 GNUNET_SET_add_element (set2, 196 GNUNET_SET_add_element(set2,
191 &element, 197 &element,
192 NULL, 198 NULL,
193 NULL); 199 NULL);
194 element.data = "quux"; 200 element.data = "quux";
195 element.size = strlen(element.data); 201 element.size = strlen(element.data);
196 GNUNET_SET_add_element (set2, 202 GNUNET_SET_add_element(set2,
197 &element, 203 &element,
198 NULL, 204 NULL,
199 NULL); 205 NULL);
200 element.data = "baz"; 206 element.data = "baz";
201 element.size = strlen(element.data); 207 element.size = strlen(element.data);
202 GNUNET_SET_add_element (set2, 208 GNUNET_SET_add_element(set2,
203 &element, 209 &element,
204 &start, 210 &start,
205 NULL); 211 NULL);
206} 212}
207 213
208 214
@@ -210,73 +216,73 @@ init_set2 (void *cls)
210 * Initialize the first set, continue. 216 * Initialize the first set, continue.
211 */ 217 */
212static void 218static void
213init_set1 (void) 219init_set1(void)
214{ 220{
215 struct GNUNET_SET_Element element; 221 struct GNUNET_SET_Element element;
216 222
217 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 223 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
218 "initializing set 1\n"); 224 "initializing set 1\n");
219 element.element_type = 0; 225 element.element_type = 0;
220 element.data = "hello"; 226 element.data = "hello";
221 element.size = strlen(element.data); 227 element.size = strlen(element.data);
222 GNUNET_SET_add_element (set1, 228 GNUNET_SET_add_element(set1,
223 &element, 229 &element,
224 NULL, 230 NULL,
225 NULL); 231 NULL);
226 element.data = "bar"; 232 element.data = "bar";
227 element.size = strlen(element.data); 233 element.size = strlen(element.data);
228 GNUNET_SET_add_element (set1, 234 GNUNET_SET_add_element(set1,
229 &element, 235 &element,
230 &init_set2, 236 &init_set2,
231 NULL); 237 NULL);
232} 238}
233 239
234 240
235static int 241static int
236iter_cb (void *cls, 242iter_cb(void *cls,
237 const struct GNUNET_SET_Element *element) 243 const struct GNUNET_SET_Element *element)
238{ 244{
239 if (NULL == element) 245 if (NULL == element)
240 { 246 {
241 GNUNET_assert (iter_count == 3); 247 GNUNET_assert(iter_count == 3);
242 GNUNET_SET_destroy (cls); 248 GNUNET_SET_destroy(cls);
243 return GNUNET_YES; 249 return GNUNET_YES;
244 } 250 }
245 iter_count++; 251 iter_count++;
246 return GNUNET_YES; 252 return GNUNET_YES;
247} 253}
248 254
249 255
250static void 256static void
251test_iter () 257test_iter()
252{ 258{
253 struct GNUNET_SET_Element element; 259 struct GNUNET_SET_Element element;
254 struct GNUNET_SET_Handle *iter_set; 260 struct GNUNET_SET_Handle *iter_set;
255 261
256 iter_set = GNUNET_SET_create (config, 262 iter_set = GNUNET_SET_create(config,
257 GNUNET_SET_OPERATION_INTERSECTION); 263 GNUNET_SET_OPERATION_INTERSECTION);
258 element.element_type = 0; 264 element.element_type = 0;
259 element.data = "hello"; 265 element.data = "hello";
260 element.size = strlen(element.data); 266 element.size = strlen(element.data);
261 GNUNET_SET_add_element (iter_set, 267 GNUNET_SET_add_element(iter_set,
262 &element, 268 &element,
263 NULL, 269 NULL,
264 NULL); 270 NULL);
265 element.data = "bar"; 271 element.data = "bar";
266 element.size = strlen(element.data); 272 element.size = strlen(element.data);
267 GNUNET_SET_add_element (iter_set, 273 GNUNET_SET_add_element(iter_set,
268 &element, 274 &element,
269 NULL, 275 NULL,
270 NULL); 276 NULL);
271 element.data = "quux"; 277 element.data = "quux";
272 element.size = strlen(element.data); 278 element.size = strlen(element.data);
273 GNUNET_SET_add_element (iter_set, 279 GNUNET_SET_add_element(iter_set,
274 &element, 280 &element,
275 NULL, 281 NULL,
276 NULL); 282 NULL);
277 GNUNET_SET_iterate (iter_set, 283 GNUNET_SET_iterate(iter_set,
278 &iter_cb, 284 &iter_cb,
279 iter_set); 285 iter_set);
280} 286}
281 287
282 288
@@ -286,38 +292,38 @@ test_iter ()
286 * @param cls closure 292 * @param cls closure
287 */ 293 */
288static void 294static void
289do_shutdown (void *cls) 295do_shutdown(void *cls)
290{ 296{
291 if (NULL != tt) 297 if (NULL != tt)
292 { 298 {
293 GNUNET_SCHEDULER_cancel (tt); 299 GNUNET_SCHEDULER_cancel(tt);
294 tt = NULL; 300 tt = NULL;
295 } 301 }
296 if (NULL != oh1) 302 if (NULL != oh1)
297 { 303 {
298 GNUNET_SET_operation_cancel (oh1); 304 GNUNET_SET_operation_cancel(oh1);
299 oh1 = NULL; 305 oh1 = NULL;
300 } 306 }
301 if (NULL != oh2) 307 if (NULL != oh2)
302 { 308 {
303 GNUNET_SET_operation_cancel (oh2); 309 GNUNET_SET_operation_cancel(oh2);
304 oh2 = NULL; 310 oh2 = NULL;
305 } 311 }
306 if (NULL != set1) 312 if (NULL != set1)
307 { 313 {
308 GNUNET_SET_destroy (set1); 314 GNUNET_SET_destroy(set1);
309 set1 = NULL; 315 set1 = NULL;
310 } 316 }
311 if (NULL != set2) 317 if (NULL != set2)
312 { 318 {
313 GNUNET_SET_destroy (set2); 319 GNUNET_SET_destroy(set2);
314 set2 = NULL; 320 set2 = NULL;
315 } 321 }
316 if (NULL != listen_handle) 322 if (NULL != listen_handle)
317 { 323 {
318 GNUNET_SET_listen_cancel (listen_handle); 324 GNUNET_SET_listen_cancel(listen_handle);
319 listen_handle = NULL; 325 listen_handle = NULL;
320 } 326 }
321} 327}
322 328
323 329
@@ -327,12 +333,12 @@ do_shutdown (void *cls)
327 * @param cls closure 333 * @param cls closure
328 */ 334 */
329static void 335static void
330timeout_fail (void *cls) 336timeout_fail(void *cls)
331{ 337{
332 tt = NULL; 338 tt = NULL;
333 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 339 GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE,
334 "Testcase failed with timeout\n"); 340 "Testcase failed with timeout\n");
335 GNUNET_SCHEDULER_shutdown (); 341 GNUNET_SCHEDULER_shutdown();
336 ret = 1; 342 ret = 1;
337} 343}
338 344
@@ -346,41 +352,41 @@ timeout_fail (void *cls)
346 * @param peer identity of the peer that was created 352 * @param peer identity of the peer that was created
347 */ 353 */
348static void 354static void
349run (void *cls, 355run(void *cls,
350 const struct GNUNET_CONFIGURATION_Handle *cfg, 356 const struct GNUNET_CONFIGURATION_Handle *cfg,
351 struct GNUNET_TESTING_Peer *peer) 357 struct GNUNET_TESTING_Peer *peer)
352{ 358{
353 config = cfg; 359 config = cfg;
354 GNUNET_TESTING_peer_get_identity (peer, 360 GNUNET_TESTING_peer_get_identity(peer,
355 &local_id); 361 &local_id);
356 if (0) 362 if (0)
357 test_iter (); 363 test_iter();
358 364
359 tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), 365 tt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
360 &timeout_fail, 366 &timeout_fail,
361 NULL); 367 NULL);
362 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 368 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
363 NULL); 369 NULL);
364 370
365 set1 = GNUNET_SET_create (cfg, 371 set1 = GNUNET_SET_create(cfg,
366 GNUNET_SET_OPERATION_INTERSECTION); 372 GNUNET_SET_OPERATION_INTERSECTION);
367 set2 = GNUNET_SET_create (cfg, 373 set2 = GNUNET_SET_create(cfg,
368 GNUNET_SET_OPERATION_INTERSECTION); 374 GNUNET_SET_OPERATION_INTERSECTION);
369 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, 375 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK,
370 &app_id); 376 &app_id);
371 377
372 /* test the real set reconciliation */ 378 /* test the real set reconciliation */
373 init_set1 (); 379 init_set1();
374} 380}
375 381
376 382
377int 383int
378main (int argc, 384main(int argc,
379 char **argv) 385 char **argv)
380{ 386{
381 if (0 != GNUNET_TESTING_peer_run ("test_set_intersection_result_full", 387 if (0 != GNUNET_TESTING_peer_run("test_set_intersection_result_full",
382 "test_set.conf", 388 "test_set.conf",
383 &run, NULL)) 389 &run, NULL))
384 return 1; 390 return 1;
385 return ret; 391 return ret;
386} 392}