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