aboutsummaryrefslogtreecommitdiff
path: root/src/set/gnunet-service-set.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/set/gnunet-service-set.c')
-rw-r--r--src/set/gnunet-service-set.c1843
1 files changed, 923 insertions, 920 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c
index 5becd7bd9..2dad49e6d 100644
--- a/src/set/gnunet-service-set.c
+++ b/src/set/gnunet-service-set.c
@@ -16,7 +16,7 @@
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 * @file set/gnunet-service-set.c 21 * @file set/gnunet-service-set.c
22 * @brief two-peer set operations 22 * @brief two-peer set operations
@@ -39,8 +39,7 @@
39/** 39/**
40 * Lazy copy requests made by a client. 40 * Lazy copy requests made by a client.
41 */ 41 */
42struct LazyCopyRequest 42struct LazyCopyRequest {
43{
44 /** 43 /**
45 * Kept in a DLL. 44 * Kept in a DLL.
46 */ 45 */
@@ -67,8 +66,7 @@ struct LazyCopyRequest
67 * A listener is inhabited by a client, and waits for evaluation 66 * A listener is inhabited by a client, and waits for evaluation
68 * requests from remote peers. 67 * requests from remote peers.
69 */ 68 */
70struct Listener 69struct Listener {
71{
72 /** 70 /**
73 * Listeners are held in a doubly linked list. 71 * Listeners are held in a doubly linked list.
74 */ 72 */
@@ -182,15 +180,15 @@ static uint32_t suggest_id;
182 * or NULL if there is none 180 * or NULL if there is none
183 */ 181 */
184static struct Operation * 182static struct Operation *
185get_incoming (uint32_t id) 183get_incoming(uint32_t id)
186{ 184{
187 for (struct Listener *listener = listener_head; NULL != listener; 185 for (struct Listener *listener = listener_head; NULL != listener;
188 listener = listener->next) 186 listener = listener->next)
189 { 187 {
190 for (struct Operation *op = listener->op_head; NULL != op; op = op->next) 188 for (struct Operation *op = listener->op_head; NULL != op; op = op->next)
191 if (op->suggest_id == id) 189 if (op->suggest_id == id)
192 return op; 190 return op;
193 } 191 }
194 return NULL; 192 return NULL;
195} 193}
196 194
@@ -201,33 +199,31 @@ get_incoming (uint32_t id)
201 * @param op remote request to destroy 199 * @param op remote request to destroy
202 */ 200 */
203static void 201static void
204incoming_destroy (struct Operation *op) 202incoming_destroy(struct Operation *op)
205{ 203{
206 struct Listener *listener; 204 struct Listener *listener;
207 205
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 206 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
209 "Destroying incoming operation %p\n", 207 "Destroying incoming operation %p\n",
210 op); 208 op);
211 if (NULL != (listener = op->listener)) 209 if (NULL != (listener = op->listener))
212 { 210 {
213 GNUNET_CONTAINER_DLL_remove (listener->op_head, listener->op_tail, op); 211 GNUNET_CONTAINER_DLL_remove(listener->op_head, listener->op_tail, op);
214 op->listener = NULL; 212 op->listener = NULL;
215 } 213 }
216 if (NULL != op->timeout_task) 214 if (NULL != op->timeout_task)
217 { 215 {
218 GNUNET_SCHEDULER_cancel (op->timeout_task); 216 GNUNET_SCHEDULER_cancel(op->timeout_task);
219 op->timeout_task = NULL; 217 op->timeout_task = NULL;
220 } 218 }
221 _GSS_operation_destroy2 (op); 219 _GSS_operation_destroy2(op);
222} 220}
223 221
224 222
225/** 223/**
226 * Context for the #garbage_collect_cb(). 224 * Context for the #garbage_collect_cb().
227 */ 225 */
228struct GarbageContext 226struct GarbageContext {
229{
230
231 /** 227 /**
232 * Map for which we are garbage collecting removed elements. 228 * Map for which we are garbage collecting removed elements.
233 */ 229 */
@@ -255,7 +251,7 @@ struct GarbageContext
255 * @return #GNUNET_OK (continue to iterate) 251 * @return #GNUNET_OK (continue to iterate)
256 */ 252 */
257static int 253static int
258garbage_collect_cb (void *cls, const struct GNUNET_HashCode *key, void *value) 254garbage_collect_cb(void *cls, const struct GNUNET_HashCode *key, void *value)
259{ 255{
260 //struct GarbageContext *gc = cls; 256 //struct GarbageContext *gc = cls;
261 //struct ElementEntry *ee = value; 257 //struct ElementEntry *ee = value;
@@ -283,23 +279,23 @@ garbage_collect_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
283 * @param set set to garbage collect 279 * @param set set to garbage collect
284 */ 280 */
285static void 281static void
286collect_generation_garbage (struct Set *set) 282collect_generation_garbage(struct Set *set)
287{ 283{
288 struct GarbageContext gc; 284 struct GarbageContext gc;
289 285
290 gc.min_op_generation = UINT_MAX; 286 gc.min_op_generation = UINT_MAX;
291 gc.max_op_generation = 0; 287 gc.max_op_generation = 0;
292 for (struct Operation *op = set->ops_head; NULL != op; op = op->next) 288 for (struct Operation *op = set->ops_head; NULL != op; op = op->next)
293 { 289 {
294 gc.min_op_generation = 290 gc.min_op_generation =
295 GNUNET_MIN (gc.min_op_generation, op->generation_created); 291 GNUNET_MIN(gc.min_op_generation, op->generation_created);
296 gc.max_op_generation = 292 gc.max_op_generation =
297 GNUNET_MAX (gc.max_op_generation, op->generation_created); 293 GNUNET_MAX(gc.max_op_generation, op->generation_created);
298 } 294 }
299 gc.map = set->content->elements; 295 gc.map = set->content->elements;
300 GNUNET_CONTAINER_multihashmap_iterate (set->content->elements, 296 GNUNET_CONTAINER_multihashmap_iterate(set->content->elements,
301 &garbage_collect_cb, 297 &garbage_collect_cb,
302 &gc); 298 &gc);
303} 299}
304 300
305 301
@@ -312,9 +308,9 @@ collect_generation_garbage (struct Set *set)
312 * @return #GNUNET_YES if @a generation is in any of the ranges 308 * @return #GNUNET_YES if @a generation is in any of the ranges
313 */ 309 */
314static int 310static int
315is_excluded_generation (unsigned int generation, 311is_excluded_generation(unsigned int generation,
316 struct GenerationRange *excluded, 312 struct GenerationRange *excluded,
317 unsigned int excluded_size) 313 unsigned int excluded_size)
318{ 314{
319 for (unsigned int i = 0; i < excluded_size; i++) 315 for (unsigned int i = 0; i < excluded_size; i++)
320 if ((generation >= excluded[i].start) && (generation < excluded[i].end)) 316 if ((generation >= excluded[i].start) && (generation < excluded[i].end))
@@ -333,57 +329,57 @@ is_excluded_generation (unsigned int generation,
333 * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not 329 * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not
334 */ 330 */
335static int 331static int
336is_element_of_generation (struct ElementEntry *ee, 332is_element_of_generation(struct ElementEntry *ee,
337 unsigned int query_generation, 333 unsigned int query_generation,
338 struct GenerationRange *excluded, 334 struct GenerationRange *excluded,
339 unsigned int excluded_size) 335 unsigned int excluded_size)
340{ 336{
341 struct MutationEvent *mut; 337 struct MutationEvent *mut;
342 int is_present; 338 int is_present;
343 339
344 GNUNET_assert (NULL != ee->mutations); 340 GNUNET_assert(NULL != ee->mutations);
345 if (GNUNET_YES == 341 if (GNUNET_YES ==
346 is_excluded_generation (query_generation, excluded, excluded_size)) 342 is_excluded_generation(query_generation, excluded, excluded_size))
347 { 343 {
348 GNUNET_break (0); 344 GNUNET_break(0);
349 return GNUNET_NO; 345 return GNUNET_NO;
350 } 346 }
351 347
352 is_present = GNUNET_NO; 348 is_present = GNUNET_NO;
353 349
354 /* Could be made faster with binary search, but lists 350 /* Could be made faster with binary search, but lists
355 are small, so why bother. */ 351 are small, so why bother. */
356 for (unsigned int i = 0; i < ee->mutations_size; i++) 352 for (unsigned int i = 0; i < ee->mutations_size; i++)
357 {
358 mut = &ee->mutations[i];
359
360 if (mut->generation > query_generation)
361 {
362 /* The mutation doesn't apply to our generation
363 anymore. We can'b break here, since mutations aren't
364 sorted by generation. */
365 continue;
366 }
367
368 if (GNUNET_YES ==
369 is_excluded_generation (mut->generation, excluded, excluded_size))
370 { 353 {
371 /* The generation is excluded (because it belongs to another 354 mut = &ee->mutations[i];
372 fork via a lazy copy) and thus mutations aren't considered 355
373 for membership testing. */ 356 if (mut->generation > query_generation)
374 continue; 357 {
358 /* The mutation doesn't apply to our generation
359 anymore. We can'b break here, since mutations aren't
360 sorted by generation. */
361 continue;
362 }
363
364 if (GNUNET_YES ==
365 is_excluded_generation(mut->generation, excluded, excluded_size))
366 {
367 /* The generation is excluded (because it belongs to another
368 fork via a lazy copy) and thus mutations aren't considered
369 for membership testing. */
370 continue;
371 }
372
373 /* This would be an inconsistency in how we manage mutations. */
374 if ((GNUNET_YES == is_present) && (GNUNET_YES == mut->added))
375 GNUNET_assert(0);
376 /* Likewise. */
377 if ((GNUNET_NO == is_present) && (GNUNET_NO == mut->added))
378 GNUNET_assert(0);
379
380 is_present = mut->added;
375 } 381 }
376 382
377 /* This would be an inconsistency in how we manage mutations. */
378 if ((GNUNET_YES == is_present) && (GNUNET_YES == mut->added))
379 GNUNET_assert (0);
380 /* Likewise. */
381 if ((GNUNET_NO == is_present) && (GNUNET_NO == mut->added))
382 GNUNET_assert (0);
383
384 is_present = mut->added;
385 }
386
387 return is_present; 383 return is_present;
388} 384}
389 385
@@ -396,12 +392,12 @@ is_element_of_generation (struct ElementEntry *ee,
396 * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not 392 * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not
397 */ 393 */
398int 394int
399_GSS_is_element_of_operation (struct ElementEntry *ee, struct Operation *op) 395_GSS_is_element_of_operation(struct ElementEntry *ee, struct Operation *op)
400{ 396{
401 return is_element_of_generation (ee, 397 return is_element_of_generation(ee,
402 op->generation_created, 398 op->generation_created,
403 op->set->excluded_generations, 399 op->set->excluded_generations,
404 op->set->excluded_generations_size); 400 op->set->excluded_generations_size);
405} 401}
406 402
407 403
@@ -419,37 +415,37 @@ _GSS_is_element_of_operation (struct ElementEntry *ee, struct Operation *op)
419 * @param gc #GNUNET_YES to perform garbage collection on the set 415 * @param gc #GNUNET_YES to perform garbage collection on the set
420 */ 416 */
421void 417void
422_GSS_operation_destroy (struct Operation *op, int gc) 418_GSS_operation_destroy(struct Operation *op, int gc)
423{ 419{
424 struct Set *set = op->set; 420 struct Set *set = op->set;
425 struct GNUNET_CADET_Channel *channel; 421 struct GNUNET_CADET_Channel *channel;
426 422
427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying operation %p\n", op); 423 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying operation %p\n", op);
428 GNUNET_assert (NULL == op->listener); 424 GNUNET_assert(NULL == op->listener);
429 if (NULL != op->state) 425 if (NULL != op->state)
430 { 426 {
431 set->vt->cancel (op); 427 set->vt->cancel(op);
432 op->state = NULL; 428 op->state = NULL;
433 } 429 }
434 if (NULL != set) 430 if (NULL != set)
435 { 431 {
436 GNUNET_CONTAINER_DLL_remove (set->ops_head, set->ops_tail, op); 432 GNUNET_CONTAINER_DLL_remove(set->ops_head, set->ops_tail, op);
437 op->set = NULL; 433 op->set = NULL;
438 } 434 }
439 if (NULL != op->context_msg) 435 if (NULL != op->context_msg)
440 { 436 {
441 GNUNET_free (op->context_msg); 437 GNUNET_free(op->context_msg);
442 op->context_msg = NULL; 438 op->context_msg = NULL;
443 } 439 }
444 if (NULL != (channel = op->channel)) 440 if (NULL != (channel = op->channel))
445 { 441 {
446 /* This will free op; called conditionally as this helper function 442 /* This will free op; called conditionally as this helper function
447 is also called from within the channel disconnect handler. */ 443 is also called from within the channel disconnect handler. */
448 op->channel = NULL; 444 op->channel = NULL;
449 GNUNET_CADET_channel_destroy (channel); 445 GNUNET_CADET_channel_destroy(channel);
450 } 446 }
451 if ((NULL != set) && (GNUNET_YES == gc)) 447 if ((NULL != set) && (GNUNET_YES == gc))
452 collect_generation_garbage (set); 448 collect_generation_garbage(set);
453 /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL, 449 /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL,
454 * there was a channel end handler that will free 'op' on the call stack. */ 450 * there was a channel end handler that will free 'op' on the call stack. */
455} 451}
@@ -464,14 +460,14 @@ _GSS_operation_destroy (struct Operation *op, int gc)
464 * @return @a `struct ClientState` 460 * @return @a `struct ClientState`
465 */ 461 */
466static void * 462static void *
467client_connect_cb (void *cls, 463client_connect_cb(void *cls,
468 struct GNUNET_SERVICE_Client *c, 464 struct GNUNET_SERVICE_Client *c,
469 struct GNUNET_MQ_Handle *mq) 465 struct GNUNET_MQ_Handle *mq)
470{ 466{
471 struct ClientState *cs; 467 struct ClientState *cs;
472 468
473 num_clients++; 469 num_clients++;
474 cs = GNUNET_new (struct ClientState); 470 cs = GNUNET_new(struct ClientState);
475 cs->client = c; 471 cs->client = c;
476 cs->mq = mq; 472 cs->mq = mq;
477 return cs; 473 return cs;
@@ -487,14 +483,14 @@ client_connect_cb (void *cls,
487 * @return #GNUNET_YES (continue to iterate) 483 * @return #GNUNET_YES (continue to iterate)
488 */ 484 */
489static int 485static int
490destroy_elements_iterator (void *cls, 486destroy_elements_iterator(void *cls,
491 const struct GNUNET_HashCode *key, 487 const struct GNUNET_HashCode *key,
492 void *value) 488 void *value)
493{ 489{
494 struct ElementEntry *ee = value; 490 struct ElementEntry *ee = value;
495 491
496 GNUNET_free_non_null (ee->mutations); 492 GNUNET_free_non_null(ee->mutations);
497 GNUNET_free (ee); 493 GNUNET_free(ee);
498 return GNUNET_YES; 494 return GNUNET_YES;
499} 495}
500 496
@@ -507,117 +503,117 @@ destroy_elements_iterator (void *cls,
507 * @param internal_cls the `struct ClientState` 503 * @param internal_cls the `struct ClientState`
508 */ 504 */
509static void 505static void
510client_disconnect_cb (void *cls, 506client_disconnect_cb(void *cls,
511 struct GNUNET_SERVICE_Client *client, 507 struct GNUNET_SERVICE_Client *client,
512 void *internal_cls) 508 void *internal_cls)
513{ 509{
514 struct ClientState *cs = internal_cls; 510 struct ClientState *cs = internal_cls;
515 struct Operation *op; 511 struct Operation *op;
516 struct Listener *listener; 512 struct Listener *listener;
517 struct Set *set; 513 struct Set *set;
518 514
519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, cleaning up\n"); 515 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, cleaning up\n");
520 if (NULL != (set = cs->set)) 516 if (NULL != (set = cs->set))
521 {
522 struct SetContent *content = set->content;
523 struct PendingMutation *pm;
524 struct PendingMutation *pm_current;
525 struct LazyCopyRequest *lcr;
526
527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying client's set\n");
528 /* Destroy pending set operations */
529 while (NULL != set->ops_head)
530 _GSS_operation_destroy (set->ops_head, GNUNET_NO);
531
532 /* Destroy operation-specific state */
533 GNUNET_assert (NULL != set->state);
534 set->vt->destroy_set (set->state);
535 set->state = NULL;
536
537 /* Clean up ongoing iterations */
538 if (NULL != set->iter)
539 { 517 {
540 GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter); 518 struct SetContent *content = set->content;
541 set->iter = NULL; 519 struct PendingMutation *pm;
542 set->iteration_id++; 520 struct PendingMutation *pm_current;
521 struct LazyCopyRequest *lcr;
522
523 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying client's set\n");
524 /* Destroy pending set operations */
525 while (NULL != set->ops_head)
526 _GSS_operation_destroy(set->ops_head, GNUNET_NO);
527
528 /* Destroy operation-specific state */
529 GNUNET_assert(NULL != set->state);
530 set->vt->destroy_set(set->state);
531 set->state = NULL;
532
533 /* Clean up ongoing iterations */
534 if (NULL != set->iter)
535 {
536 GNUNET_CONTAINER_multihashmap_iterator_destroy(set->iter);
537 set->iter = NULL;
538 set->iteration_id++;
539 }
540
541 /* discard any pending mutations that reference this set */
542 pm = content->pending_mutations_head;
543 while (NULL != pm)
544 {
545 pm_current = pm;
546 pm = pm->next;
547 if (pm_current->set == set)
548 {
549 GNUNET_CONTAINER_DLL_remove(content->pending_mutations_head,
550 content->pending_mutations_tail,
551 pm_current);
552 GNUNET_free(pm_current);
553 }
554 }
555
556 /* free set content (or at least decrement RC) */
557 set->content = NULL;
558 GNUNET_assert(0 != content->refcount);
559 content->refcount--;
560 if (0 == content->refcount)
561 {
562 GNUNET_assert(NULL != content->elements);
563 GNUNET_CONTAINER_multihashmap_iterate(content->elements,
564 &destroy_elements_iterator,
565 NULL);
566 GNUNET_CONTAINER_multihashmap_destroy(content->elements);
567 content->elements = NULL;
568 GNUNET_free(content);
569 }
570 GNUNET_free_non_null(set->excluded_generations);
571 set->excluded_generations = NULL;
572
573 /* remove set from pending copy requests */
574 lcr = lazy_copy_head;
575 while (NULL != lcr)
576 {
577 struct LazyCopyRequest *lcr_current = lcr;
578
579 lcr = lcr->next;
580 if (lcr_current->source_set == set)
581 {
582 GNUNET_CONTAINER_DLL_remove(lazy_copy_head,
583 lazy_copy_tail,
584 lcr_current);
585 GNUNET_free(lcr_current);
586 }
587 }
588 GNUNET_free(set);
543 } 589 }
544 590
545 /* discard any pending mutations that reference this set */
546 pm = content->pending_mutations_head;
547 while (NULL != pm)
548 {
549 pm_current = pm;
550 pm = pm->next;
551 if (pm_current->set == set)
552 {
553 GNUNET_CONTAINER_DLL_remove (content->pending_mutations_head,
554 content->pending_mutations_tail,
555 pm_current);
556 GNUNET_free (pm_current);
557 }
558 }
559
560 /* free set content (or at least decrement RC) */
561 set->content = NULL;
562 GNUNET_assert (0 != content->refcount);
563 content->refcount--;
564 if (0 == content->refcount)
565 {
566 GNUNET_assert (NULL != content->elements);
567 GNUNET_CONTAINER_multihashmap_iterate (content->elements,
568 &destroy_elements_iterator,
569 NULL);
570 GNUNET_CONTAINER_multihashmap_destroy (content->elements);
571 content->elements = NULL;
572 GNUNET_free (content);
573 }
574 GNUNET_free_non_null (set->excluded_generations);
575 set->excluded_generations = NULL;
576
577 /* remove set from pending copy requests */
578 lcr = lazy_copy_head;
579 while (NULL != lcr)
580 {
581 struct LazyCopyRequest *lcr_current = lcr;
582
583 lcr = lcr->next;
584 if (lcr_current->source_set == set)
585 {
586 GNUNET_CONTAINER_DLL_remove (lazy_copy_head,
587 lazy_copy_tail,
588 lcr_current);
589 GNUNET_free (lcr_current);
590 }
591 }
592 GNUNET_free (set);
593 }
594
595 if (NULL != (listener = cs->listener)) 591 if (NULL != (listener = cs->listener))
596 {
597 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying client's listener\n");
598 GNUNET_CADET_close_port (listener->open_port);
599 listener->open_port = NULL;
600 while (NULL != (op = listener->op_head))
601 { 592 {
602 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 593 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying client's listener\n");
603 "Destroying incoming operation `%u' from peer `%s'\n", 594 GNUNET_CADET_close_port(listener->open_port);
604 (unsigned int) op->client_request_id, 595 listener->open_port = NULL;
605 GNUNET_i2s (&op->peer)); 596 while (NULL != (op = listener->op_head))
606 incoming_destroy (op); 597 {
598 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
599 "Destroying incoming operation `%u' from peer `%s'\n",
600 (unsigned int)op->client_request_id,
601 GNUNET_i2s(&op->peer));
602 incoming_destroy(op);
603 }
604 GNUNET_CONTAINER_DLL_remove(listener_head, listener_tail, listener);
605 GNUNET_free(listener);
607 } 606 }
608 GNUNET_CONTAINER_DLL_remove (listener_head, listener_tail, listener); 607 GNUNET_free(cs);
609 GNUNET_free (listener);
610 }
611 GNUNET_free (cs);
612 num_clients--; 608 num_clients--;
613 if ((GNUNET_YES == in_shutdown) && (0 == num_clients)) 609 if ((GNUNET_YES == in_shutdown) && (0 == num_clients))
614 {
615 if (NULL != cadet)
616 { 610 {
617 GNUNET_CADET_disconnect (cadet); 611 if (NULL != cadet)
618 cadet = NULL; 612 {
613 GNUNET_CADET_disconnect(cadet);
614 cadet = NULL;
615 }
619 } 616 }
620 }
621} 617}
622 618
623 619
@@ -630,7 +626,7 @@ client_disconnect_cb (void *cls,
630 * #GNUNET_SYSERR to destroy the channel 626 * #GNUNET_SYSERR to destroy the channel
631 */ 627 */
632static int 628static int
633check_incoming_msg (void *cls, const struct OperationRequestMessage *msg) 629check_incoming_msg(void *cls, const struct OperationRequestMessage *msg)
634{ 630{
635 struct Operation *op = cls; 631 struct Operation *op = cls;
636 struct Listener *listener = op->listener; 632 struct Listener *listener = op->listener;
@@ -638,29 +634,29 @@ check_incoming_msg (void *cls, const struct OperationRequestMessage *msg)
638 634
639 /* double operation request */ 635 /* double operation request */
640 if (0 != op->suggest_id) 636 if (0 != op->suggest_id)
641 { 637 {
642 GNUNET_break_op (0); 638 GNUNET_break_op(0);
643 return GNUNET_SYSERR; 639 return GNUNET_SYSERR;
644 } 640 }
645 /* This should be equivalent to the previous condition, but can't hurt to check twice */ 641 /* This should be equivalent to the previous condition, but can't hurt to check twice */
646 if (NULL == op->listener) 642 if (NULL == op->listener)
647 { 643 {
648 GNUNET_break (0); 644 GNUNET_break(0);
649 return GNUNET_SYSERR; 645 return GNUNET_SYSERR;
650 } 646 }
651 if (listener->operation != 647 if (listener->operation !=
652 (enum GNUNET_SET_OperationType) ntohl (msg->operation)) 648 (enum GNUNET_SET_OperationType)ntohl(msg->operation))
653 { 649 {
654 GNUNET_break_op (0); 650 GNUNET_break_op(0);
655 return GNUNET_SYSERR; 651 return GNUNET_SYSERR;
656 } 652 }
657 nested_context = GNUNET_MQ_extract_nested_mh (msg); 653 nested_context = GNUNET_MQ_extract_nested_mh(msg);
658 if ((NULL != nested_context) && 654 if ((NULL != nested_context) &&
659 (ntohs (nested_context->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE)) 655 (ntohs(nested_context->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE))
660 { 656 {
661 GNUNET_break_op (0); 657 GNUNET_break_op(0);
662 return GNUNET_SYSERR; 658 return GNUNET_SYSERR;
663 } 659 }
664 return GNUNET_OK; 660 return GNUNET_OK;
665} 661}
666 662
@@ -683,7 +679,7 @@ check_incoming_msg (void *cls, const struct OperationRequestMessage *msg)
683 * #GNUNET_SYSERR to destroy the channel 679 * #GNUNET_SYSERR to destroy the channel
684 */ 680 */
685static void 681static void
686handle_incoming_msg (void *cls, const struct OperationRequestMessage *msg) 682handle_incoming_msg(void *cls, const struct OperationRequestMessage *msg)
687{ 683{
688 struct Operation *op = cls; 684 struct Operation *op = cls;
689 struct Listener *listener = op->listener; 685 struct Listener *listener = op->listener;
@@ -691,39 +687,39 @@ handle_incoming_msg (void *cls, const struct OperationRequestMessage *msg)
691 struct GNUNET_MQ_Envelope *env; 687 struct GNUNET_MQ_Envelope *env;
692 struct GNUNET_SET_RequestMessage *cmsg; 688 struct GNUNET_SET_RequestMessage *cmsg;
693 689
694 nested_context = GNUNET_MQ_extract_nested_mh (msg); 690 nested_context = GNUNET_MQ_extract_nested_mh(msg);
695 /* Make a copy of the nested_context (application-specific context 691 /* Make a copy of the nested_context (application-specific context
696 information that is opaque to set) so we can pass it to the 692 information that is opaque to set) so we can pass it to the
697 listener later on */ 693 listener later on */
698 if (NULL != nested_context) 694 if (NULL != nested_context)
699 op->context_msg = GNUNET_copy_message (nested_context); 695 op->context_msg = GNUNET_copy_message(nested_context);
700 op->remote_element_count = ntohl (msg->element_count); 696 op->remote_element_count = ntohl(msg->element_count);
701 GNUNET_log ( 697 GNUNET_log(
702 GNUNET_ERROR_TYPE_DEBUG, 698 GNUNET_ERROR_TYPE_DEBUG,
703 "Received P2P operation request (op %u, port %s) for active listener\n", 699 "Received P2P operation request (op %u, port %s) for active listener\n",
704 (uint32_t) ntohl (msg->operation), 700 (uint32_t)ntohl(msg->operation),
705 GNUNET_h2s (&op->listener->app_id)); 701 GNUNET_h2s(&op->listener->app_id));
706 GNUNET_assert (0 == op->suggest_id); 702 GNUNET_assert(0 == op->suggest_id);
707 if (0 == suggest_id) 703 if (0 == suggest_id)
708 suggest_id++; 704 suggest_id++;
709 op->suggest_id = suggest_id++; 705 op->suggest_id = suggest_id++;
710 GNUNET_assert (NULL != op->timeout_task); 706 GNUNET_assert(NULL != op->timeout_task);
711 GNUNET_SCHEDULER_cancel (op->timeout_task); 707 GNUNET_SCHEDULER_cancel(op->timeout_task);
712 op->timeout_task = NULL; 708 op->timeout_task = NULL;
713 env = GNUNET_MQ_msg_nested_mh (cmsg, 709 env = GNUNET_MQ_msg_nested_mh(cmsg,
714 GNUNET_MESSAGE_TYPE_SET_REQUEST, 710 GNUNET_MESSAGE_TYPE_SET_REQUEST,
715 op->context_msg); 711 op->context_msg);
716 GNUNET_log ( 712 GNUNET_log(
717 GNUNET_ERROR_TYPE_DEBUG, 713 GNUNET_ERROR_TYPE_DEBUG,
718 "Suggesting incoming request with accept id %u to listener %p of client %p\n", 714 "Suggesting incoming request with accept id %u to listener %p of client %p\n",
719 op->suggest_id, 715 op->suggest_id,
720 listener, 716 listener,
721 listener->cs); 717 listener->cs);
722 cmsg->accept_id = htonl (op->suggest_id); 718 cmsg->accept_id = htonl(op->suggest_id);
723 cmsg->peer_id = op->peer; 719 cmsg->peer_id = op->peer;
724 GNUNET_MQ_send (listener->cs->mq, env); 720 GNUNET_MQ_send(listener->cs->mq, env);
725 /* NOTE: GNUNET_CADET_receive_done() will be called in 721 /* NOTE: GNUNET_CADET_receive_done() will be called in
726 #handle_client_accept() */ 722 #handle_client_accept() */
727} 723}
728 724
729 725
@@ -734,61 +730,61 @@ handle_incoming_msg (void *cls, const struct OperationRequestMessage *msg)
734 * @param msg message specifying the change 730 * @param msg message specifying the change
735 */ 731 */
736static void 732static void
737execute_add (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) 733execute_add(struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
738{ 734{
739 struct GNUNET_SET_Element el; 735 struct GNUNET_SET_Element el;
740 struct ElementEntry *ee; 736 struct ElementEntry *ee;
741 struct GNUNET_HashCode hash; 737 struct GNUNET_HashCode hash;
742 738
743 GNUNET_assert (GNUNET_MESSAGE_TYPE_SET_ADD == ntohs (msg->header.type)); 739 GNUNET_assert(GNUNET_MESSAGE_TYPE_SET_ADD == ntohs(msg->header.type));
744 el.size = ntohs (msg->header.size) - sizeof (*msg); 740 el.size = ntohs(msg->header.size) - sizeof(*msg);
745 el.data = &msg[1]; 741 el.data = &msg[1];
746 el.element_type = ntohs (msg->element_type); 742 el.element_type = ntohs(msg->element_type);
747 GNUNET_SET_element_hash (&el, &hash); 743 GNUNET_SET_element_hash(&el, &hash);
748 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, &hash); 744 ee = GNUNET_CONTAINER_multihashmap_get(set->content->elements, &hash);
749 if (NULL == ee) 745 if (NULL == ee)
750 { 746 {
751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 747 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
752 "Client inserts element %s of size %u\n", 748 "Client inserts element %s of size %u\n",
753 GNUNET_h2s (&hash), 749 GNUNET_h2s(&hash),
754 el.size); 750 el.size);
755 ee = GNUNET_malloc (el.size + sizeof (*ee)); 751 ee = GNUNET_malloc(el.size + sizeof(*ee));
756 ee->element.size = el.size; 752 ee->element.size = el.size;
757 GNUNET_memcpy (&ee[1], el.data, el.size); 753 GNUNET_memcpy(&ee[1], el.data, el.size);
758 ee->element.data = &ee[1]; 754 ee->element.data = &ee[1];
759 ee->element.element_type = el.element_type; 755 ee->element.element_type = el.element_type;
760 ee->remote = GNUNET_NO; 756 ee->remote = GNUNET_NO;
761 ee->mutations = NULL; 757 ee->mutations = NULL;
762 ee->mutations_size = 0; 758 ee->mutations_size = 0;
763 ee->element_hash = hash; 759 ee->element_hash = hash;
764 GNUNET_break (GNUNET_YES == 760 GNUNET_break(GNUNET_YES ==
765 GNUNET_CONTAINER_multihashmap_put ( 761 GNUNET_CONTAINER_multihashmap_put(
766 set->content->elements, 762 set->content->elements,
767 &ee->element_hash, 763 &ee->element_hash,
768 ee, 764 ee,
769 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 765 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
770 } 766 }
771 else if (GNUNET_YES == 767 else if (GNUNET_YES ==
772 is_element_of_generation (ee, 768 is_element_of_generation(ee,
773 set->current_generation, 769 set->current_generation,
774 set->excluded_generations, 770 set->excluded_generations,
775 set->excluded_generations_size)) 771 set->excluded_generations_size))
776 { 772 {
777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 773 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
778 "Client inserted element %s of size %u twice (ignored)\n", 774 "Client inserted element %s of size %u twice (ignored)\n",
779 GNUNET_h2s (&hash), 775 GNUNET_h2s(&hash),
780 el.size); 776 el.size);
781 777
782 /* same element inserted twice */ 778 /* same element inserted twice */
783 return; 779 return;
784 } 780 }
785 781
786 { 782 {
787 struct MutationEvent mut = {.generation = set->current_generation, 783 struct MutationEvent mut = { .generation = set->current_generation,
788 .added = GNUNET_YES}; 784 .added = GNUNET_YES };
789 GNUNET_array_append (ee->mutations, ee->mutations_size, mut); 785 GNUNET_array_append(ee->mutations, ee->mutations_size, mut);
790 } 786 }
791 set->vt->add (set->state, ee); 787 set->vt->add(set->state, ee);
792} 788}
793 789
794 790
@@ -799,49 +795,49 @@ execute_add (struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
799 * @param msg message specifying the change 795 * @param msg message specifying the change
800 */ 796 */
801static void 797static void
802execute_remove (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) 798execute_remove(struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
803{ 799{
804 struct GNUNET_SET_Element el; 800 struct GNUNET_SET_Element el;
805 struct ElementEntry *ee; 801 struct ElementEntry *ee;
806 struct GNUNET_HashCode hash; 802 struct GNUNET_HashCode hash;
807 803
808 GNUNET_assert (GNUNET_MESSAGE_TYPE_SET_REMOVE == ntohs (msg->header.type)); 804 GNUNET_assert(GNUNET_MESSAGE_TYPE_SET_REMOVE == ntohs(msg->header.type));
809 el.size = ntohs (msg->header.size) - sizeof (*msg); 805 el.size = ntohs(msg->header.size) - sizeof(*msg);
810 el.data = &msg[1]; 806 el.data = &msg[1];
811 el.element_type = ntohs (msg->element_type); 807 el.element_type = ntohs(msg->element_type);
812 GNUNET_SET_element_hash (&el, &hash); 808 GNUNET_SET_element_hash(&el, &hash);
813 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, &hash); 809 ee = GNUNET_CONTAINER_multihashmap_get(set->content->elements, &hash);
814 if (NULL == ee) 810 if (NULL == ee)
815 { 811 {
816 /* Client tried to remove non-existing element. */ 812 /* Client tried to remove non-existing element. */
817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 813 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
818 "Client removes non-existing element of size %u\n", 814 "Client removes non-existing element of size %u\n",
819 el.size); 815 el.size);
820 return; 816 return;
821 } 817 }
822 if (GNUNET_NO == is_element_of_generation (ee, 818 if (GNUNET_NO == is_element_of_generation(ee,
823 set->current_generation, 819 set->current_generation,
824 set->excluded_generations, 820 set->excluded_generations,
825 set->excluded_generations_size)) 821 set->excluded_generations_size))
826 { 822 {
827 /* Client tried to remove element twice */ 823 /* Client tried to remove element twice */
828 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 824 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
829 "Client removed element of size %u twice (ignored)\n", 825 "Client removed element of size %u twice (ignored)\n",
830 el.size); 826 el.size);
831 return; 827 return;
832 } 828 }
833 else 829 else
834 { 830 {
835 struct MutationEvent mut = {.generation = set->current_generation, 831 struct MutationEvent mut = { .generation = set->current_generation,
836 .added = GNUNET_NO}; 832 .added = GNUNET_NO };
837 833
838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 834 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
839 "Client removes element of size %u\n", 835 "Client removes element of size %u\n",
840 el.size); 836 el.size);
841 837
842 GNUNET_array_append (ee->mutations, ee->mutations_size, mut); 838 GNUNET_array_append(ee->mutations, ee->mutations_size, mut);
843 } 839 }
844 set->vt->remove (set->state, ee); 840 set->vt->remove(set->state, ee);
845} 841}
846 842
847 843
@@ -852,19 +848,21 @@ execute_remove (struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
852 * @param msg specification of what to change 848 * @param msg specification of what to change
853 */ 849 */
854static void 850static void
855execute_mutation (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) 851execute_mutation(struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
856{ 852{
857 switch (ntohs (msg->header.type)) 853 switch (ntohs(msg->header.type))
858 { 854 {
859 case GNUNET_MESSAGE_TYPE_SET_ADD: 855 case GNUNET_MESSAGE_TYPE_SET_ADD:
860 execute_add (set, msg); 856 execute_add(set, msg);
861 break; 857 break;
862 case GNUNET_MESSAGE_TYPE_SET_REMOVE: 858
863 execute_remove (set, msg); 859 case GNUNET_MESSAGE_TYPE_SET_REMOVE:
864 break; 860 execute_remove(set, msg);
865 default: 861 break;
866 GNUNET_break (0); 862
867 } 863 default:
864 GNUNET_break(0);
865 }
868} 866}
869 867
870 868
@@ -875,24 +873,24 @@ execute_mutation (struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
875 * @param set the set to execute mutations on 873 * @param set the set to execute mutations on
876 */ 874 */
877static void 875static void
878execute_delayed_mutations (struct Set *set) 876execute_delayed_mutations(struct Set *set)
879{ 877{
880 struct PendingMutation *pm; 878 struct PendingMutation *pm;
881 879
882 if (0 != set->content->iterator_count) 880 if (0 != set->content->iterator_count)
883 return; /* still cannot do this */ 881 return; /* still cannot do this */
884 while (NULL != (pm = set->content->pending_mutations_head)) 882 while (NULL != (pm = set->content->pending_mutations_head))
885 { 883 {
886 GNUNET_CONTAINER_DLL_remove (set->content->pending_mutations_head, 884 GNUNET_CONTAINER_DLL_remove(set->content->pending_mutations_head,
887 set->content->pending_mutations_tail, 885 set->content->pending_mutations_tail,
888 pm); 886 pm);
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 887 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
890 "Executing pending mutation on %p.\n", 888 "Executing pending mutation on %p.\n",
891 pm->set); 889 pm->set);
892 execute_mutation (pm->set, pm->msg); 890 execute_mutation(pm->set, pm->msg);
893 GNUNET_free (pm->msg); 891 GNUNET_free(pm->msg);
894 GNUNET_free (pm); 892 GNUNET_free(pm);
895 } 893 }
896} 894}
897 895
898 896
@@ -910,48 +908,49 @@ execute_delayed_mutations (struct Set *set)
910 * @param set set that should send its next element to its client 908 * @param set set that should send its next element to its client
911 */ 909 */
912static void 910static void
913send_client_element (struct Set *set) 911send_client_element(struct Set *set)
914{ 912{
915 int ret; 913 int ret;
916 struct ElementEntry *ee; 914 struct ElementEntry *ee;
917 struct GNUNET_MQ_Envelope *ev; 915 struct GNUNET_MQ_Envelope *ev;
918 struct GNUNET_SET_IterResponseMessage *msg; 916 struct GNUNET_SET_IterResponseMessage *msg;
919 917
920 GNUNET_assert (NULL != set->iter); 918 GNUNET_assert(NULL != set->iter);
921 do 919 do
922 {
923 ret = GNUNET_CONTAINER_multihashmap_iterator_next (set->iter,
924 NULL,
925 (const void **) &ee);
926 if (GNUNET_NO == ret)
927 { 920 {
928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration on %p done.\n", set); 921 ret = GNUNET_CONTAINER_multihashmap_iterator_next(set->iter,
929 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_DONE); 922 NULL,
930 GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter); 923 (const void **)&ee);
931 set->iter = NULL; 924 if (GNUNET_NO == ret)
932 set->iteration_id++; 925 {
933 GNUNET_assert (set->content->iterator_count > 0); 926 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Iteration on %p done.\n", set);
934 set->content->iterator_count--; 927 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_ITER_DONE);
935 execute_delayed_mutations (set); 928 GNUNET_CONTAINER_multihashmap_iterator_destroy(set->iter);
936 GNUNET_MQ_send (set->cs->mq, ev); 929 set->iter = NULL;
937 return; 930 set->iteration_id++;
931 GNUNET_assert(set->content->iterator_count > 0);
932 set->content->iterator_count--;
933 execute_delayed_mutations(set);
934 GNUNET_MQ_send(set->cs->mq, ev);
935 return;
936 }
937 GNUNET_assert(NULL != ee);
938 } 938 }
939 GNUNET_assert (NULL != ee); 939 while (GNUNET_NO ==
940 } while (GNUNET_NO == 940 is_element_of_generation(ee,
941 is_element_of_generation (ee, 941 set->iter_generation,
942 set->iter_generation, 942 set->excluded_generations,
943 set->excluded_generations, 943 set->excluded_generations_size));
944 set->excluded_generations_size)); 944 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
945 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 945 "Sending iteration element on %p.\n",
946 "Sending iteration element on %p.\n", 946 set);
947 set); 947 ev = GNUNET_MQ_msg_extra(msg,
948 ev = GNUNET_MQ_msg_extra (msg, 948 ee->element.size,
949 ee->element.size, 949 GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT);
950 GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT); 950 GNUNET_memcpy(&msg[1], ee->element.data, ee->element.size);
951 GNUNET_memcpy (&msg[1], ee->element.data, ee->element.size); 951 msg->element_type = htons(ee->element.element_type);
952 msg->element_type = htons (ee->element.element_type); 952 msg->iteration_id = htons(set->iteration_id);
953 msg->iteration_id = htons (set->iteration_id); 953 GNUNET_MQ_send(set->cs->mq, ev);
954 GNUNET_MQ_send (set->cs->mq, ev);
955} 954}
956 955
957 956
@@ -965,36 +964,36 @@ send_client_element (struct Set *set)
965 * @param m message sent by the client 964 * @param m message sent by the client
966 */ 965 */
967static void 966static void
968handle_client_iterate (void *cls, const struct GNUNET_MessageHeader *m) 967handle_client_iterate(void *cls, const struct GNUNET_MessageHeader *m)
969{ 968{
970 struct ClientState *cs = cls; 969 struct ClientState *cs = cls;
971 struct Set *set; 970 struct Set *set;
972 971
973 if (NULL == (set = cs->set)) 972 if (NULL == (set = cs->set))
974 { 973 {
975 /* attempt to iterate over a non existing set */ 974 /* attempt to iterate over a non existing set */
976 GNUNET_break (0); 975 GNUNET_break(0);
977 GNUNET_SERVICE_client_drop (cs->client); 976 GNUNET_SERVICE_client_drop(cs->client);
978 return; 977 return;
979 } 978 }
980 if (NULL != set->iter) 979 if (NULL != set->iter)
981 { 980 {
982 /* Only one concurrent iterate-action allowed per set */ 981 /* Only one concurrent iterate-action allowed per set */
983 GNUNET_break (0); 982 GNUNET_break(0);
984 GNUNET_SERVICE_client_drop (cs->client); 983 GNUNET_SERVICE_client_drop(cs->client);
985 return; 984 return;
986 } 985 }
987 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 986 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
988 "Iterating set %p in gen %u with %u content elements\n", 987 "Iterating set %p in gen %u with %u content elements\n",
989 (void *) set, 988 (void *)set,
990 set->current_generation, 989 set->current_generation,
991 GNUNET_CONTAINER_multihashmap_size (set->content->elements)); 990 GNUNET_CONTAINER_multihashmap_size(set->content->elements));
992 GNUNET_SERVICE_client_continue (cs->client); 991 GNUNET_SERVICE_client_continue(cs->client);
993 set->content->iterator_count++; 992 set->content->iterator_count++;
994 set->iter = 993 set->iter =
995 GNUNET_CONTAINER_multihashmap_iterator_create (set->content->elements); 994 GNUNET_CONTAINER_multihashmap_iterator_create(set->content->elements);
996 set->iter_generation = set->current_generation; 995 set->iter_generation = set->current_generation;
997 send_client_element (set); 996 send_client_element(set);
998} 997}
999 998
1000 999
@@ -1007,51 +1006,53 @@ handle_client_iterate (void *cls, const struct GNUNET_MessageHeader *m)
1007 * @param m message sent by the client 1006 * @param m message sent by the client
1008 */ 1007 */
1009static void 1008static void
1010handle_client_create_set (void *cls, const struct GNUNET_SET_CreateMessage *msg) 1009handle_client_create_set(void *cls, const struct GNUNET_SET_CreateMessage *msg)
1011{ 1010{
1012 struct ClientState *cs = cls; 1011 struct ClientState *cs = cls;
1013 struct Set *set; 1012 struct Set *set;
1014 1013
1015 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1014 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1016 "Client created new set (operation %u)\n", 1015 "Client created new set (operation %u)\n",
1017 (uint32_t) ntohl (msg->operation)); 1016 (uint32_t)ntohl(msg->operation));
1018 if (NULL != cs->set) 1017 if (NULL != cs->set)
1019 { 1018 {
1020 /* There can only be one set per client */ 1019 /* There can only be one set per client */
1021 GNUNET_break (0); 1020 GNUNET_break(0);
1022 GNUNET_SERVICE_client_drop (cs->client); 1021 GNUNET_SERVICE_client_drop(cs->client);
1023 return; 1022 return;
1024 } 1023 }
1025 set = GNUNET_new (struct Set); 1024 set = GNUNET_new(struct Set);
1026 switch (ntohl (msg->operation)) 1025 switch (ntohl(msg->operation))
1027 { 1026 {
1028 case GNUNET_SET_OPERATION_INTERSECTION: 1027 case GNUNET_SET_OPERATION_INTERSECTION:
1029 set->vt = _GSS_intersection_vt (); 1028 set->vt = _GSS_intersection_vt();
1030 break; 1029 break;
1031 case GNUNET_SET_OPERATION_UNION: 1030
1032 set->vt = _GSS_union_vt (); 1031 case GNUNET_SET_OPERATION_UNION:
1033 break; 1032 set->vt = _GSS_union_vt();
1034 default: 1033 break;
1035 GNUNET_free (set); 1034
1036 GNUNET_break (0); 1035 default:
1037 GNUNET_SERVICE_client_drop (cs->client); 1036 GNUNET_free(set);
1038 return; 1037 GNUNET_break(0);
1039 } 1038 GNUNET_SERVICE_client_drop(cs->client);
1040 set->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation); 1039 return;
1041 set->state = set->vt->create (); 1040 }
1041 set->operation = (enum GNUNET_SET_OperationType)ntohl(msg->operation);
1042 set->state = set->vt->create();
1042 if (NULL == set->state) 1043 if (NULL == set->state)
1043 { 1044 {
1044 /* initialization failed (i.e. out of memory) */ 1045 /* initialization failed (i.e. out of memory) */
1045 GNUNET_free (set); 1046 GNUNET_free(set);
1046 GNUNET_SERVICE_client_drop (cs->client); 1047 GNUNET_SERVICE_client_drop(cs->client);
1047 return; 1048 return;
1048 } 1049 }
1049 set->content = GNUNET_new (struct SetContent); 1050 set->content = GNUNET_new(struct SetContent);
1050 set->content->refcount = 1; 1051 set->content->refcount = 1;
1051 set->content->elements = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); 1052 set->content->elements = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_YES);
1052 set->cs = cs; 1053 set->cs = cs;
1053 cs->set = set; 1054 cs->set = set;
1054 GNUNET_SERVICE_client_continue (cs->client); 1055 GNUNET_SERVICE_client_continue(cs->client);
1055} 1056}
1056 1057
1057 1058
@@ -1065,14 +1066,14 @@ handle_client_create_set (void *cls, const struct GNUNET_SET_CreateMessage *msg)
1065 * @param tc context information (why was this task triggered now) 1066 * @param tc context information (why was this task triggered now)
1066 */ 1067 */
1067static void 1068static void
1068incoming_timeout_cb (void *cls) 1069incoming_timeout_cb(void *cls)
1069{ 1070{
1070 struct Operation *op = cls; 1071 struct Operation *op = cls;
1071 1072
1072 op->timeout_task = NULL; 1073 op->timeout_task = NULL;
1073 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1074 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1074 "Remote peer's incoming request timed out\n"); 1075 "Remote peer's incoming request timed out\n");
1075 incoming_destroy (op); 1076 incoming_destroy(op);
1076} 1077}
1077 1078
1078 1079
@@ -1093,24 +1094,24 @@ incoming_timeout_cb (void *cls)
1093 * returns NULL on error 1094 * returns NULL on error
1094 */ 1095 */
1095static void * 1096static void *
1096channel_new_cb (void *cls, 1097channel_new_cb(void *cls,
1097 struct GNUNET_CADET_Channel *channel, 1098 struct GNUNET_CADET_Channel *channel,
1098 const struct GNUNET_PeerIdentity *source) 1099 const struct GNUNET_PeerIdentity *source)
1099{ 1100{
1100 struct Listener *listener = cls; 1101 struct Listener *listener = cls;
1101 struct Operation *op; 1102 struct Operation *op;
1102 1103
1103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New incoming channel\n"); 1104 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New incoming channel\n");
1104 op = GNUNET_new (struct Operation); 1105 op = GNUNET_new(struct Operation);
1105 op->listener = listener; 1106 op->listener = listener;
1106 op->peer = *source; 1107 op->peer = *source;
1107 op->channel = channel; 1108 op->channel = channel;
1108 op->mq = GNUNET_CADET_get_mq (op->channel); 1109 op->mq = GNUNET_CADET_get_mq(op->channel);
1109 op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 1110 op->salt = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1110 op->timeout_task = GNUNET_SCHEDULER_add_delayed (INCOMING_CHANNEL_TIMEOUT, 1111 op->timeout_task = GNUNET_SCHEDULER_add_delayed(INCOMING_CHANNEL_TIMEOUT,
1111 &incoming_timeout_cb, 1112 &incoming_timeout_cb,
1112 op); 1113 op);
1113 GNUNET_CONTAINER_DLL_insert (listener->op_head, listener->op_tail, op); 1114 GNUNET_CONTAINER_DLL_insert(listener->op_head, listener->op_tail, op);
1114 return op; 1115 return op;
1115} 1116}
1116 1117
@@ -1132,12 +1133,12 @@ channel_new_cb (void *cls,
1132 * @param channel connection to the other end (henceforth invalid) 1133 * @param channel connection to the other end (henceforth invalid)
1133 */ 1134 */
1134static void 1135static void
1135channel_end_cb (void *channel_ctx, const struct GNUNET_CADET_Channel *channel) 1136channel_end_cb(void *channel_ctx, const struct GNUNET_CADET_Channel *channel)
1136{ 1137{
1137 struct Operation *op = channel_ctx; 1138 struct Operation *op = channel_ctx;
1138 1139
1139 op->channel = NULL; 1140 op->channel = NULL;
1140 _GSS_operation_destroy2 (op); 1141 _GSS_operation_destroy2(op);
1141} 1142}
1142 1143
1143 1144
@@ -1147,28 +1148,28 @@ channel_end_cb (void *channel_ctx, const struct GNUNET_CADET_Channel *channel)
1147 * logic in the various places where it is called. 1148 * logic in the various places where it is called.
1148 */ 1149 */
1149void 1150void
1150_GSS_operation_destroy2 (struct Operation *op) 1151_GSS_operation_destroy2(struct Operation *op)
1151{ 1152{
1152 struct GNUNET_CADET_Channel *channel; 1153 struct GNUNET_CADET_Channel *channel;
1153 1154
1154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "channel_end_cb called\n"); 1155 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "channel_end_cb called\n");
1155 if (NULL != (channel = op->channel)) 1156 if (NULL != (channel = op->channel))
1156 { 1157 {
1157 /* This will free op; called conditionally as this helper function 1158 /* This will free op; called conditionally as this helper function
1158 is also called from within the channel disconnect handler. */ 1159 is also called from within the channel disconnect handler. */
1159 op->channel = NULL; 1160 op->channel = NULL;
1160 GNUNET_CADET_channel_destroy (channel); 1161 GNUNET_CADET_channel_destroy(channel);
1161 } 1162 }
1162 if (NULL != op->listener) 1163 if (NULL != op->listener)
1163 { 1164 {
1164 incoming_destroy (op); 1165 incoming_destroy(op);
1165 return; 1166 return;
1166 } 1167 }
1167 if (NULL != op->set) 1168 if (NULL != op->set)
1168 op->set->vt->channel_death (op); 1169 op->set->vt->channel_death(op);
1169 else 1170 else
1170 _GSS_operation_destroy (op, GNUNET_YES); 1171 _GSS_operation_destroy(op, GNUNET_YES);
1171 GNUNET_free (op); 1172 GNUNET_free(op);
1172} 1173}
1173 1174
1174 1175
@@ -1187,9 +1188,9 @@ _GSS_operation_destroy2 (struct Operation *op)
1187 * this value will be negative.. 1188 * this value will be negative..
1188 */ 1189 */
1189static void 1190static void
1190channel_window_cb (void *cls, 1191channel_window_cb(void *cls,
1191 const struct GNUNET_CADET_Channel *channel, 1192 const struct GNUNET_CADET_Channel *channel,
1192 int window_size) 1193 int window_size)
1193{ 1194{
1194 /* FIXME: not implemented, we could do flow control here... */ 1195 /* FIXME: not implemented, we could do flow control here... */
1195} 1196}
@@ -1202,102 +1203,102 @@ channel_window_cb (void *cls,
1202 * @param msg message sent by the client 1203 * @param msg message sent by the client
1203 */ 1204 */
1204static void 1205static void
1205handle_client_listen (void *cls, const struct GNUNET_SET_ListenMessage *msg) 1206handle_client_listen(void *cls, const struct GNUNET_SET_ListenMessage *msg)
1206{ 1207{
1207 struct ClientState *cs = cls; 1208 struct ClientState *cs = cls;
1208 struct GNUNET_MQ_MessageHandler cadet_handlers[] = 1209 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1209 {GNUNET_MQ_hd_var_size (incoming_msg, 1210 { GNUNET_MQ_hd_var_size(incoming_msg,
1210 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 1211 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST,
1211 struct OperationRequestMessage, 1212 struct OperationRequestMessage,
1212 NULL), 1213 NULL),
1213 GNUNET_MQ_hd_var_size (union_p2p_ibf, 1214 GNUNET_MQ_hd_var_size(union_p2p_ibf,
1214 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, 1215 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF,
1215 struct IBFMessage, 1216 struct IBFMessage,
1216 NULL), 1217 NULL),
1217 GNUNET_MQ_hd_var_size (union_p2p_elements, 1218 GNUNET_MQ_hd_var_size(union_p2p_elements,
1218 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 1219 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS,
1219 struct GNUNET_SET_ElementMessage, 1220 struct GNUNET_SET_ElementMessage,
1220 NULL), 1221 NULL),
1221 GNUNET_MQ_hd_var_size (union_p2p_offer, 1222 GNUNET_MQ_hd_var_size(union_p2p_offer,
1222 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, 1223 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER,
1224 struct GNUNET_MessageHeader,
1225 NULL),
1226 GNUNET_MQ_hd_var_size(union_p2p_inquiry,
1227 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY,
1228 struct InquiryMessage,
1229 NULL),
1230 GNUNET_MQ_hd_var_size(union_p2p_demand,
1231 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND,
1232 struct GNUNET_MessageHeader,
1233 NULL),
1234 GNUNET_MQ_hd_fixed_size(union_p2p_done,
1235 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE,
1223 struct GNUNET_MessageHeader, 1236 struct GNUNET_MessageHeader,
1224 NULL), 1237 NULL),
1225 GNUNET_MQ_hd_var_size (union_p2p_inquiry, 1238 GNUNET_MQ_hd_fixed_size(union_p2p_over,
1226 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, 1239 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER,
1227 struct InquiryMessage,
1228 NULL),
1229 GNUNET_MQ_hd_var_size (union_p2p_demand,
1230 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND,
1231 struct GNUNET_MessageHeader, 1240 struct GNUNET_MessageHeader,
1232 NULL), 1241 NULL),
1233 GNUNET_MQ_hd_fixed_size (union_p2p_done, 1242 GNUNET_MQ_hd_fixed_size(union_p2p_full_done,
1234 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, 1243 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE,
1235 struct GNUNET_MessageHeader, 1244 struct GNUNET_MessageHeader,
1236 NULL),
1237 GNUNET_MQ_hd_fixed_size (union_p2p_over,
1238 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER,
1239 struct GNUNET_MessageHeader,
1240 NULL),
1241 GNUNET_MQ_hd_fixed_size (union_p2p_full_done,
1242 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE,
1243 struct GNUNET_MessageHeader,
1244 NULL),
1245 GNUNET_MQ_hd_fixed_size (union_p2p_request_full,
1246 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL,
1247 struct GNUNET_MessageHeader,
1248 NULL),
1249 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
1250 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE,
1251 struct StrataEstimatorMessage,
1252 NULL), 1245 NULL),
1253 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, 1246 GNUNET_MQ_hd_fixed_size(union_p2p_request_full,
1254 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, 1247 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL,
1255 struct StrataEstimatorMessage, 1248 struct GNUNET_MessageHeader,
1256 NULL), 1249 NULL),
1257 GNUNET_MQ_hd_var_size (union_p2p_full_element, 1250 GNUNET_MQ_hd_var_size(union_p2p_strata_estimator,
1258 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, 1251 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE,
1259 struct GNUNET_SET_ElementMessage, 1252 struct StrataEstimatorMessage,
1253 NULL),
1254 GNUNET_MQ_hd_var_size(union_p2p_strata_estimator,
1255 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC,
1256 struct StrataEstimatorMessage,
1257 NULL),
1258 GNUNET_MQ_hd_var_size(union_p2p_full_element,
1259 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT,
1260 struct GNUNET_SET_ElementMessage,
1261 NULL),
1262 GNUNET_MQ_hd_fixed_size(intersection_p2p_element_info,
1263 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO,
1264 struct IntersectionElementInfoMessage,
1260 NULL), 1265 NULL),
1261 GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info, 1266 GNUNET_MQ_hd_var_size(intersection_p2p_bf,
1262 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, 1267 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF,
1263 struct IntersectionElementInfoMessage, 1268 struct BFMessage,
1264 NULL), 1269 NULL),
1265 GNUNET_MQ_hd_var_size (intersection_p2p_bf, 1270 GNUNET_MQ_hd_fixed_size(intersection_p2p_done,
1266 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, 1271 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE,
1267 struct BFMessage, 1272 struct IntersectionDoneMessage,
1268 NULL), 1273 NULL),
1269 GNUNET_MQ_hd_fixed_size (intersection_p2p_done, 1274 GNUNET_MQ_handler_end() };
1270 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE,
1271 struct IntersectionDoneMessage,
1272 NULL),
1273 GNUNET_MQ_handler_end ()};
1274 struct Listener *listener; 1275 struct Listener *listener;
1275 1276
1276 if (NULL != cs->listener) 1277 if (NULL != cs->listener)
1277 { 1278 {
1278 /* max. one active listener per client! */ 1279 /* max. one active listener per client! */
1279 GNUNET_break (0); 1280 GNUNET_break(0);
1280 GNUNET_SERVICE_client_drop (cs->client); 1281 GNUNET_SERVICE_client_drop(cs->client);
1281 return; 1282 return;
1282 } 1283 }
1283 listener = GNUNET_new (struct Listener); 1284 listener = GNUNET_new(struct Listener);
1284 listener->cs = cs; 1285 listener->cs = cs;
1285 cs->listener = listener; 1286 cs->listener = listener;
1286 listener->app_id = msg->app_id; 1287 listener->app_id = msg->app_id;
1287 listener->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation); 1288 listener->operation = (enum GNUNET_SET_OperationType)ntohl(msg->operation);
1288 GNUNET_CONTAINER_DLL_insert (listener_head, listener_tail, listener); 1289 GNUNET_CONTAINER_DLL_insert(listener_head, listener_tail, listener);
1289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1290 "New listener created (op %u, port %s)\n", 1291 "New listener created (op %u, port %s)\n",
1291 listener->operation, 1292 listener->operation,
1292 GNUNET_h2s (&listener->app_id)); 1293 GNUNET_h2s(&listener->app_id));
1293 listener->open_port = GNUNET_CADET_open_port (cadet, 1294 listener->open_port = GNUNET_CADET_open_port(cadet,
1294 &msg->app_id, 1295 &msg->app_id,
1295 &channel_new_cb, 1296 &channel_new_cb,
1296 listener, 1297 listener,
1297 &channel_window_cb, 1298 &channel_window_cb,
1298 &channel_end_cb, 1299 &channel_end_cb,
1299 cadet_handlers); 1300 cadet_handlers);
1300 GNUNET_SERVICE_client_continue (cs->client); 1301 GNUNET_SERVICE_client_continue(cs->client);
1301} 1302}
1302 1303
1303 1304
@@ -1309,28 +1310,28 @@ handle_client_listen (void *cls, const struct GNUNET_SET_ListenMessage *msg)
1309 * @param msg message sent by the client 1310 * @param msg message sent by the client
1310 */ 1311 */
1311static void 1312static void
1312handle_client_reject (void *cls, const struct GNUNET_SET_RejectMessage *msg) 1313handle_client_reject(void *cls, const struct GNUNET_SET_RejectMessage *msg)
1313{ 1314{
1314 struct ClientState *cs = cls; 1315 struct ClientState *cs = cls;
1315 struct Operation *op; 1316 struct Operation *op;
1316 1317
1317 op = get_incoming (ntohl (msg->accept_reject_id)); 1318 op = get_incoming(ntohl(msg->accept_reject_id));
1318 if (NULL == op) 1319 if (NULL == op)
1319 { 1320 {
1320 /* no matching incoming operation for this reject; 1321 /* no matching incoming operation for this reject;
1321 could be that the other peer already disconnected... */ 1322 could be that the other peer already disconnected... */
1322 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1323 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1323 "Client rejected unknown operation %u\n", 1324 "Client rejected unknown operation %u\n",
1324 (unsigned int) ntohl (msg->accept_reject_id)); 1325 (unsigned int)ntohl(msg->accept_reject_id));
1325 GNUNET_SERVICE_client_continue (cs->client); 1326 GNUNET_SERVICE_client_continue(cs->client);
1326 return; 1327 return;
1327 } 1328 }
1328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1329 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1329 "Peer request (op %u, app %s) rejected by client\n", 1330 "Peer request (op %u, app %s) rejected by client\n",
1330 op->listener->operation, 1331 op->listener->operation,
1331 GNUNET_h2s (&cs->listener->app_id)); 1332 GNUNET_h2s(&cs->listener->app_id));
1332 _GSS_operation_destroy2 (op); 1333 _GSS_operation_destroy2(op);
1333 GNUNET_SERVICE_client_continue (cs->client); 1334 GNUNET_SERVICE_client_continue(cs->client);
1334} 1335}
1335 1336
1336 1337
@@ -1341,7 +1342,7 @@ handle_client_reject (void *cls, const struct GNUNET_SET_RejectMessage *msg)
1341 * @param msg message sent by the client 1342 * @param msg message sent by the client
1342 */ 1343 */
1343static int 1344static int
1344check_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg) 1345check_client_mutation(void *cls, const struct GNUNET_SET_ElementMessage *msg)
1345{ 1346{
1346 /* NOTE: Technically, we should probably check with the 1347 /* NOTE: Technically, we should probably check with the
1347 block library whether the element we are given is well-formed */ 1348 block library whether the element we are given is well-formed */
@@ -1356,36 +1357,36 @@ check_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg)
1356 * @param msg message sent by the client 1357 * @param msg message sent by the client
1357 */ 1358 */
1358static void 1359static void
1359handle_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg) 1360handle_client_mutation(void *cls, const struct GNUNET_SET_ElementMessage *msg)
1360{ 1361{
1361 struct ClientState *cs = cls; 1362 struct ClientState *cs = cls;
1362 struct Set *set; 1363 struct Set *set;
1363 1364
1364 if (NULL == (set = cs->set)) 1365 if (NULL == (set = cs->set))
1365 { 1366 {
1366 /* client without a set requested an operation */ 1367 /* client without a set requested an operation */
1367 GNUNET_break (0); 1368 GNUNET_break(0);
1368 GNUNET_SERVICE_client_drop (cs->client); 1369 GNUNET_SERVICE_client_drop(cs->client);
1369 return; 1370 return;
1370 } 1371 }
1371 GNUNET_SERVICE_client_continue (cs->client); 1372 GNUNET_SERVICE_client_continue(cs->client);
1372 1373
1373 if (0 != set->content->iterator_count) 1374 if (0 != set->content->iterator_count)
1374 { 1375 {
1375 struct PendingMutation *pm; 1376 struct PendingMutation *pm;
1376 1377
1377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduling mutation on set\n"); 1378 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling mutation on set\n");
1378 pm = GNUNET_new (struct PendingMutation); 1379 pm = GNUNET_new(struct PendingMutation);
1379 pm->msg = 1380 pm->msg =
1380 (struct GNUNET_SET_ElementMessage *) GNUNET_copy_message (&msg->header); 1381 (struct GNUNET_SET_ElementMessage *)GNUNET_copy_message(&msg->header);
1381 pm->set = set; 1382 pm->set = set;
1382 GNUNET_CONTAINER_DLL_insert_tail (set->content->pending_mutations_head, 1383 GNUNET_CONTAINER_DLL_insert_tail(set->content->pending_mutations_head,
1383 set->content->pending_mutations_tail, 1384 set->content->pending_mutations_tail,
1384 pm); 1385 pm);
1385 return; 1386 return;
1386 } 1387 }
1387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing mutation on set\n"); 1388 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing mutation on set\n");
1388 execute_mutation (set, msg); 1389 execute_mutation(set, msg);
1389} 1390}
1390 1391
1391 1392
@@ -1396,26 +1397,26 @@ handle_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg)
1396 * @param set the set where we want to advance the generation 1397 * @param set the set where we want to advance the generation
1397 */ 1398 */
1398static void 1399static void
1399advance_generation (struct Set *set) 1400advance_generation(struct Set *set)
1400{ 1401{
1401 struct GenerationRange r; 1402 struct GenerationRange r;
1402 1403
1403 if (set->current_generation == set->content->latest_generation) 1404 if (set->current_generation == set->content->latest_generation)
1404 { 1405 {
1405 set->content->latest_generation++; 1406 set->content->latest_generation++;
1406 set->current_generation++; 1407 set->current_generation++;
1407 return; 1408 return;
1408 } 1409 }
1409 1410
1410 GNUNET_assert (set->current_generation < set->content->latest_generation); 1411 GNUNET_assert(set->current_generation < set->content->latest_generation);
1411 1412
1412 r.start = set->current_generation + 1; 1413 r.start = set->current_generation + 1;
1413 r.end = set->content->latest_generation + 1; 1414 r.end = set->content->latest_generation + 1;
1414 set->content->latest_generation = r.end; 1415 set->content->latest_generation = r.end;
1415 set->current_generation = r.end; 1416 set->current_generation = r.end;
1416 GNUNET_array_append (set->excluded_generations, 1417 GNUNET_array_append(set->excluded_generations,
1417 set->excluded_generations_size, 1418 set->excluded_generations_size,
1418 r); 1419 r);
1419} 1420}
1420 1421
1421 1422
@@ -1429,7 +1430,7 @@ advance_generation (struct Set *set)
1429 * @return #GNUNET_OK if the message is well-formed 1430 * @return #GNUNET_OK if the message is well-formed
1430 */ 1431 */
1431static int 1432static int
1432check_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg) 1433check_client_evaluate(void *cls, const struct GNUNET_SET_EvaluateMessage *msg)
1433{ 1434{
1434 /* FIXME: suboptimal, even if the context below could be NULL, 1435 /* FIXME: suboptimal, even if the context below could be NULL,
1435 there are malformed messages this does not check for... */ 1436 there are malformed messages this does not check for... */
@@ -1446,122 +1447,122 @@ check_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg)
1446 * @param msg message sent by the client 1447 * @param msg message sent by the client
1447 */ 1448 */
1448static void 1449static void
1449handle_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg) 1450handle_client_evaluate(void *cls, const struct GNUNET_SET_EvaluateMessage *msg)
1450{ 1451{
1451 struct ClientState *cs = cls; 1452 struct ClientState *cs = cls;
1452 struct Operation *op = GNUNET_new (struct Operation); 1453 struct Operation *op = GNUNET_new(struct Operation);
1453 const struct GNUNET_MQ_MessageHandler cadet_handlers[] = 1454 const struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1454 {GNUNET_MQ_hd_var_size (incoming_msg, 1455 { GNUNET_MQ_hd_var_size(incoming_msg,
1455 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 1456 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST,
1456 struct OperationRequestMessage, 1457 struct OperationRequestMessage,
1457 op), 1458 op),
1458 GNUNET_MQ_hd_var_size (union_p2p_ibf, 1459 GNUNET_MQ_hd_var_size(union_p2p_ibf,
1459 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, 1460 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF,
1460 struct IBFMessage, 1461 struct IBFMessage,
1461 op), 1462 op),
1462 GNUNET_MQ_hd_var_size (union_p2p_elements, 1463 GNUNET_MQ_hd_var_size(union_p2p_elements,
1463 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 1464 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS,
1464 struct GNUNET_SET_ElementMessage, 1465 struct GNUNET_SET_ElementMessage,
1465 op), 1466 op),
1466 GNUNET_MQ_hd_var_size (union_p2p_offer, 1467 GNUNET_MQ_hd_var_size(union_p2p_offer,
1467 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, 1468 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER,
1469 struct GNUNET_MessageHeader,
1470 op),
1471 GNUNET_MQ_hd_var_size(union_p2p_inquiry,
1472 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY,
1473 struct InquiryMessage,
1474 op),
1475 GNUNET_MQ_hd_var_size(union_p2p_demand,
1476 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND,
1477 struct GNUNET_MessageHeader,
1478 op),
1479 GNUNET_MQ_hd_fixed_size(union_p2p_done,
1480 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE,
1468 struct GNUNET_MessageHeader, 1481 struct GNUNET_MessageHeader,
1469 op), 1482 op),
1470 GNUNET_MQ_hd_var_size (union_p2p_inquiry, 1483 GNUNET_MQ_hd_fixed_size(union_p2p_over,
1471 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, 1484 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER,
1472 struct InquiryMessage,
1473 op),
1474 GNUNET_MQ_hd_var_size (union_p2p_demand,
1475 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND,
1476 struct GNUNET_MessageHeader, 1485 struct GNUNET_MessageHeader,
1477 op), 1486 op),
1478 GNUNET_MQ_hd_fixed_size (union_p2p_done, 1487 GNUNET_MQ_hd_fixed_size(union_p2p_full_done,
1479 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, 1488 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE,
1480 struct GNUNET_MessageHeader, 1489 struct GNUNET_MessageHeader,
1481 op),
1482 GNUNET_MQ_hd_fixed_size (union_p2p_over,
1483 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER,
1484 struct GNUNET_MessageHeader,
1485 op),
1486 GNUNET_MQ_hd_fixed_size (union_p2p_full_done,
1487 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE,
1488 struct GNUNET_MessageHeader,
1489 op),
1490 GNUNET_MQ_hd_fixed_size (union_p2p_request_full,
1491 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL,
1492 struct GNUNET_MessageHeader,
1493 op),
1494 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
1495 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE,
1496 struct StrataEstimatorMessage,
1497 op), 1490 op),
1498 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, 1491 GNUNET_MQ_hd_fixed_size(union_p2p_request_full,
1499 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, 1492 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL,
1500 struct StrataEstimatorMessage, 1493 struct GNUNET_MessageHeader,
1501 op), 1494 op),
1502 GNUNET_MQ_hd_var_size (union_p2p_full_element, 1495 GNUNET_MQ_hd_var_size(union_p2p_strata_estimator,
1503 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, 1496 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE,
1504 struct GNUNET_SET_ElementMessage, 1497 struct StrataEstimatorMessage,
1498 op),
1499 GNUNET_MQ_hd_var_size(union_p2p_strata_estimator,
1500 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC,
1501 struct StrataEstimatorMessage,
1502 op),
1503 GNUNET_MQ_hd_var_size(union_p2p_full_element,
1504 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT,
1505 struct GNUNET_SET_ElementMessage,
1506 op),
1507 GNUNET_MQ_hd_fixed_size(intersection_p2p_element_info,
1508 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO,
1509 struct IntersectionElementInfoMessage,
1505 op), 1510 op),
1506 GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info, 1511 GNUNET_MQ_hd_var_size(intersection_p2p_bf,
1507 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, 1512 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF,
1508 struct IntersectionElementInfoMessage, 1513 struct BFMessage,
1509 op), 1514 op),
1510 GNUNET_MQ_hd_var_size (intersection_p2p_bf, 1515 GNUNET_MQ_hd_fixed_size(intersection_p2p_done,
1511 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, 1516 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE,
1512 struct BFMessage, 1517 struct IntersectionDoneMessage,
1513 op), 1518 op),
1514 GNUNET_MQ_hd_fixed_size (intersection_p2p_done, 1519 GNUNET_MQ_handler_end() };
1515 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE,
1516 struct IntersectionDoneMessage,
1517 op),
1518 GNUNET_MQ_handler_end ()};
1519 struct Set *set; 1520 struct Set *set;
1520 const struct GNUNET_MessageHeader *context; 1521 const struct GNUNET_MessageHeader *context;
1521 1522
1522 if (NULL == (set = cs->set)) 1523 if (NULL == (set = cs->set))
1523 { 1524 {
1524 GNUNET_break (0); 1525 GNUNET_break(0);
1525 GNUNET_free (op); 1526 GNUNET_free(op);
1526 GNUNET_SERVICE_client_drop (cs->client); 1527 GNUNET_SERVICE_client_drop(cs->client);
1527 return; 1528 return;
1528 } 1529 }
1529 op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 1530 op->salt = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1530 op->peer = msg->target_peer; 1531 op->peer = msg->target_peer;
1531 op->result_mode = ntohl (msg->result_mode); 1532 op->result_mode = ntohl(msg->result_mode);
1532 op->client_request_id = ntohl (msg->request_id); 1533 op->client_request_id = ntohl(msg->request_id);
1533 op->byzantine = msg->byzantine; 1534 op->byzantine = msg->byzantine;
1534 op->byzantine_lower_bound = msg->byzantine_lower_bound; 1535 op->byzantine_lower_bound = msg->byzantine_lower_bound;
1535 op->force_full = msg->force_full; 1536 op->force_full = msg->force_full;
1536 op->force_delta = msg->force_delta; 1537 op->force_delta = msg->force_delta;
1537 context = GNUNET_MQ_extract_nested_mh (msg); 1538 context = GNUNET_MQ_extract_nested_mh(msg);
1538 1539
1539 /* Advance generation values, so that 1540 /* Advance generation values, so that
1540 mutations won't interfer with the running operation. */ 1541 mutations won't interfer with the running operation. */
1541 op->set = set; 1542 op->set = set;
1542 op->generation_created = set->current_generation; 1543 op->generation_created = set->current_generation;
1543 advance_generation (set); 1544 advance_generation(set);
1544 GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op); 1545 GNUNET_CONTAINER_DLL_insert(set->ops_head, set->ops_tail, op);
1545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1546 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1546 "Creating new CADET channel to port %s for set operation type %u\n", 1547 "Creating new CADET channel to port %s for set operation type %u\n",
1547 GNUNET_h2s (&msg->app_id), 1548 GNUNET_h2s(&msg->app_id),
1548 set->operation); 1549 set->operation);
1549 op->channel = GNUNET_CADET_channel_create (cadet, 1550 op->channel = GNUNET_CADET_channel_create(cadet,
1550 op, 1551 op,
1551 &msg->target_peer, 1552 &msg->target_peer,
1552 &msg->app_id, 1553 &msg->app_id,
1553 &channel_window_cb, 1554 &channel_window_cb,
1554 &channel_end_cb, 1555 &channel_end_cb,
1555 cadet_handlers); 1556 cadet_handlers);
1556 op->mq = GNUNET_CADET_get_mq (op->channel); 1557 op->mq = GNUNET_CADET_get_mq(op->channel);
1557 op->state = set->vt->evaluate (op, context); 1558 op->state = set->vt->evaluate(op, context);
1558 if (NULL == op->state) 1559 if (NULL == op->state)
1559 { 1560 {
1560 GNUNET_break (0); 1561 GNUNET_break(0);
1561 GNUNET_SERVICE_client_drop (cs->client); 1562 GNUNET_SERVICE_client_drop(cs->client);
1562 return; 1563 return;
1563 } 1564 }
1564 GNUNET_SERVICE_client_continue (cs->client); 1565 GNUNET_SERVICE_client_continue(cs->client);
1565} 1566}
1566 1567
1567 1568
@@ -1574,37 +1575,37 @@ handle_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg)
1574 * @param ack the message 1575 * @param ack the message
1575 */ 1576 */
1576static void 1577static void
1577handle_client_iter_ack (void *cls, const struct GNUNET_SET_IterAckMessage *ack) 1578handle_client_iter_ack(void *cls, const struct GNUNET_SET_IterAckMessage *ack)
1578{ 1579{
1579 struct ClientState *cs = cls; 1580 struct ClientState *cs = cls;
1580 struct Set *set; 1581 struct Set *set;
1581 1582
1582 if (NULL == (set = cs->set)) 1583 if (NULL == (set = cs->set))
1583 { 1584 {
1584 /* client without a set acknowledged receiving a value */ 1585 /* client without a set acknowledged receiving a value */
1585 GNUNET_break (0); 1586 GNUNET_break(0);
1586 GNUNET_SERVICE_client_drop (cs->client); 1587 GNUNET_SERVICE_client_drop(cs->client);
1587 return; 1588 return;
1588 } 1589 }
1589 if (NULL == set->iter) 1590 if (NULL == set->iter)
1590 { 1591 {
1591 /* client sent an ack, but we were not expecting one (as 1592 /* client sent an ack, but we were not expecting one (as
1592 set iteration has finished) */ 1593 set iteration has finished) */
1593 GNUNET_break (0); 1594 GNUNET_break(0);
1594 GNUNET_SERVICE_client_drop (cs->client); 1595 GNUNET_SERVICE_client_drop(cs->client);
1595 return; 1596 return;
1596 } 1597 }
1597 GNUNET_SERVICE_client_continue (cs->client); 1598 GNUNET_SERVICE_client_continue(cs->client);
1598 if (ntohl (ack->send_more)) 1599 if (ntohl(ack->send_more))
1599 { 1600 {
1600 send_client_element (set); 1601 send_client_element(set);
1601 } 1602 }
1602 else 1603 else
1603 { 1604 {
1604 GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter); 1605 GNUNET_CONTAINER_multihashmap_iterator_destroy(set->iter);
1605 set->iter = NULL; 1606 set->iter = NULL;
1606 set->iteration_id++; 1607 set->iteration_id++;
1607 } 1608 }
1608} 1609}
1609 1610
1610 1611
@@ -1615,8 +1616,8 @@ handle_client_iter_ack (void *cls, const struct GNUNET_SET_IterAckMessage *ack)
1615 * @param mh the message 1616 * @param mh the message
1616 */ 1617 */
1617static void 1618static void
1618handle_client_copy_lazy_prepare (void *cls, 1619handle_client_copy_lazy_prepare(void *cls,
1619 const struct GNUNET_MessageHeader *mh) 1620 const struct GNUNET_MessageHeader *mh)
1620{ 1621{
1621 struct ClientState *cs = cls; 1622 struct ClientState *cs = cls;
1622 struct Set *set; 1623 struct Set *set;
@@ -1625,22 +1626,22 @@ handle_client_copy_lazy_prepare (void *cls,
1625 struct GNUNET_SET_CopyLazyResponseMessage *resp_msg; 1626 struct GNUNET_SET_CopyLazyResponseMessage *resp_msg;
1626 1627
1627 if (NULL == (set = cs->set)) 1628 if (NULL == (set = cs->set))
1628 { 1629 {
1629 /* client without a set requested an operation */ 1630 /* client without a set requested an operation */
1630 GNUNET_break (0); 1631 GNUNET_break(0);
1631 GNUNET_SERVICE_client_drop (cs->client); 1632 GNUNET_SERVICE_client_drop(cs->client);
1632 return; 1633 return;
1633 } 1634 }
1634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1635 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1635 "Client requested creation of lazy copy\n"); 1636 "Client requested creation of lazy copy\n");
1636 cr = GNUNET_new (struct LazyCopyRequest); 1637 cr = GNUNET_new(struct LazyCopyRequest);
1637 cr->cookie = ++lazy_copy_cookie; 1638 cr->cookie = ++lazy_copy_cookie;
1638 cr->source_set = set; 1639 cr->source_set = set;
1639 GNUNET_CONTAINER_DLL_insert (lazy_copy_head, lazy_copy_tail, cr); 1640 GNUNET_CONTAINER_DLL_insert(lazy_copy_head, lazy_copy_tail, cr);
1640 ev = GNUNET_MQ_msg (resp_msg, GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE); 1641 ev = GNUNET_MQ_msg(resp_msg, GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE);
1641 resp_msg->cookie = cr->cookie; 1642 resp_msg->cookie = cr->cookie;
1642 GNUNET_MQ_send (set->cs->mq, ev); 1643 GNUNET_MQ_send(set->cs->mq, ev);
1643 GNUNET_SERVICE_client_continue (cs->client); 1644 GNUNET_SERVICE_client_continue(cs->client);
1644} 1645}
1645 1646
1646 1647
@@ -1651,7 +1652,7 @@ handle_client_copy_lazy_prepare (void *cls,
1651 * @param msg the message 1652 * @param msg the message
1652 */ 1653 */
1653static void 1654static void
1654handle_client_copy_lazy_connect ( 1655handle_client_copy_lazy_connect(
1655 void *cls, 1656 void *cls,
1656 const struct GNUNET_SET_CopyLazyConnectMessage *msg) 1657 const struct GNUNET_SET_CopyLazyConnectMessage *msg)
1657{ 1658{
@@ -1661,75 +1662,77 @@ handle_client_copy_lazy_connect (
1661 int found; 1662 int found;
1662 1663
1663 if (NULL != cs->set) 1664 if (NULL != cs->set)
1664 { 1665 {
1665 /* There can only be one set per client */ 1666 /* There can only be one set per client */
1666 GNUNET_break (0); 1667 GNUNET_break(0);
1667 GNUNET_SERVICE_client_drop (cs->client); 1668 GNUNET_SERVICE_client_drop(cs->client);
1668 return; 1669 return;
1669 } 1670 }
1670 found = GNUNET_NO; 1671 found = GNUNET_NO;
1671 for (cr = lazy_copy_head; NULL != cr; cr = cr->next) 1672 for (cr = lazy_copy_head; NULL != cr; cr = cr->next)
1672 {
1673 if (cr->cookie == msg->cookie)
1674 { 1673 {
1675 found = GNUNET_YES; 1674 if (cr->cookie == msg->cookie)
1676 break; 1675 {
1676 found = GNUNET_YES;
1677 break;
1678 }
1677 } 1679 }
1678 }
1679 if (GNUNET_NO == found) 1680 if (GNUNET_NO == found)
1680 { 1681 {
1681 /* client asked for copy with cookie we don't know */ 1682 /* client asked for copy with cookie we don't know */
1682 GNUNET_break (0); 1683 GNUNET_break(0);
1683 GNUNET_SERVICE_client_drop (cs->client); 1684 GNUNET_SERVICE_client_drop(cs->client);
1684 return; 1685 return;
1685 } 1686 }
1686 GNUNET_CONTAINER_DLL_remove (lazy_copy_head, lazy_copy_tail, cr); 1687 GNUNET_CONTAINER_DLL_remove(lazy_copy_head, lazy_copy_tail, cr);
1687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1688 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1688 "Client %p requested use of lazy copy\n", 1689 "Client %p requested use of lazy copy\n",
1689 cs); 1690 cs);
1690 set = GNUNET_new (struct Set); 1691 set = GNUNET_new(struct Set);
1691 switch (cr->source_set->operation) 1692 switch (cr->source_set->operation)
1692 { 1693 {
1693 case GNUNET_SET_OPERATION_INTERSECTION: 1694 case GNUNET_SET_OPERATION_INTERSECTION:
1694 set->vt = _GSS_intersection_vt (); 1695 set->vt = _GSS_intersection_vt();
1695 break; 1696 break;
1696 case GNUNET_SET_OPERATION_UNION: 1697
1697 set->vt = _GSS_union_vt (); 1698 case GNUNET_SET_OPERATION_UNION:
1698 break; 1699 set->vt = _GSS_union_vt();
1699 default: 1700 break;
1700 GNUNET_assert (0); 1701
1701 return; 1702 default:
1702 } 1703 GNUNET_assert(0);
1704 return;
1705 }
1703 1706
1704 if (NULL == set->vt->copy_state) 1707 if (NULL == set->vt->copy_state)
1705 { 1708 {
1706 /* Lazy copy not supported for this set operation */ 1709 /* Lazy copy not supported for this set operation */
1707 GNUNET_break (0); 1710 GNUNET_break(0);
1708 GNUNET_free (set); 1711 GNUNET_free(set);
1709 GNUNET_free (cr); 1712 GNUNET_free(cr);
1710 GNUNET_SERVICE_client_drop (cs->client); 1713 GNUNET_SERVICE_client_drop(cs->client);
1711 return; 1714 return;
1712 } 1715 }
1713 1716
1714 set->operation = cr->source_set->operation; 1717 set->operation = cr->source_set->operation;
1715 set->state = set->vt->copy_state (cr->source_set->state); 1718 set->state = set->vt->copy_state(cr->source_set->state);
1716 set->content = cr->source_set->content; 1719 set->content = cr->source_set->content;
1717 set->content->refcount++; 1720 set->content->refcount++;
1718 1721
1719 set->current_generation = cr->source_set->current_generation; 1722 set->current_generation = cr->source_set->current_generation;
1720 set->excluded_generations_size = cr->source_set->excluded_generations_size; 1723 set->excluded_generations_size = cr->source_set->excluded_generations_size;
1721 set->excluded_generations = 1724 set->excluded_generations =
1722 GNUNET_memdup (cr->source_set->excluded_generations, 1725 GNUNET_memdup(cr->source_set->excluded_generations,
1723 set->excluded_generations_size * 1726 set->excluded_generations_size *
1724 sizeof (struct GenerationRange)); 1727 sizeof(struct GenerationRange));
1725 1728
1726 /* Advance the generation of the new set, so that mutations to the 1729 /* Advance the generation of the new set, so that mutations to the
1727 of the cloned set and the source set are independent. */ 1730 of the cloned set and the source set are independent. */
1728 advance_generation (set); 1731 advance_generation(set);
1729 set->cs = cs; 1732 set->cs = cs;
1730 cs->set = set; 1733 cs->set = set;
1731 GNUNET_free (cr); 1734 GNUNET_free(cr);
1732 GNUNET_SERVICE_client_continue (cs->client); 1735 GNUNET_SERVICE_client_continue(cs->client);
1733} 1736}
1734 1737
1735 1738
@@ -1740,7 +1743,7 @@ handle_client_copy_lazy_connect (
1740 * @param msg the message 1743 * @param msg the message
1741 */ 1744 */
1742static void 1745static void
1743handle_client_cancel (void *cls, const struct GNUNET_SET_CancelMessage *msg) 1746handle_client_cancel(void *cls, const struct GNUNET_SET_CancelMessage *msg)
1744{ 1747{
1745 struct ClientState *cs = cls; 1748 struct ClientState *cs = cls;
1746 struct Set *set; 1749 struct Set *set;
@@ -1748,40 +1751,40 @@ handle_client_cancel (void *cls, const struct GNUNET_SET_CancelMessage *msg)
1748 int found; 1751 int found;
1749 1752
1750 if (NULL == (set = cs->set)) 1753 if (NULL == (set = cs->set))
1751 { 1754 {
1752 /* client without a set requested an operation */ 1755 /* client without a set requested an operation */
1753 GNUNET_break (0); 1756 GNUNET_break(0);
1754 GNUNET_SERVICE_client_drop (cs->client); 1757 GNUNET_SERVICE_client_drop(cs->client);
1755 return; 1758 return;
1756 } 1759 }
1757 found = GNUNET_NO; 1760 found = GNUNET_NO;
1758 for (op = set->ops_head; NULL != op; op = op->next) 1761 for (op = set->ops_head; NULL != op; op = op->next)
1759 {
1760 if (op->client_request_id == ntohl (msg->request_id))
1761 { 1762 {
1762 found = GNUNET_YES; 1763 if (op->client_request_id == ntohl(msg->request_id))
1763 break; 1764 {
1765 found = GNUNET_YES;
1766 break;
1767 }
1764 } 1768 }
1765 }
1766 if (GNUNET_NO == found) 1769 if (GNUNET_NO == found)
1767 { 1770 {
1768 /* It may happen that the operation was already destroyed due to 1771 /* It may happen that the operation was already destroyed due to
1769 * the other peer disconnecting. The client may not know about this 1772 * the other peer disconnecting. The client may not know about this
1770 * yet and try to cancel the (just barely non-existent) operation. 1773 * yet and try to cancel the (just barely non-existent) operation.
1771 * So this is not a hard error. 1774 * So this is not a hard error.
1772 */ 1775 */
1773 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1776 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1774 "Client canceled non-existent op %u\n", 1777 "Client canceled non-existent op %u\n",
1775 (uint32_t) ntohl (msg->request_id)); 1778 (uint32_t)ntohl(msg->request_id));
1776 } 1779 }
1777 else 1780 else
1778 { 1781 {
1779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1782 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1780 "Client requested cancel for op %u\n", 1783 "Client requested cancel for op %u\n",
1781 (uint32_t) ntohl (msg->request_id)); 1784 (uint32_t)ntohl(msg->request_id));
1782 _GSS_operation_destroy (op, GNUNET_YES); 1785 _GSS_operation_destroy(op, GNUNET_YES);
1783 } 1786 }
1784 GNUNET_SERVICE_client_continue (cs->client); 1787 GNUNET_SERVICE_client_continue(cs->client);
1785} 1788}
1786 1789
1787 1790
@@ -1794,7 +1797,7 @@ handle_client_cancel (void *cls, const struct GNUNET_SET_CancelMessage *msg)
1794 * @param msg the message 1797 * @param msg the message
1795 */ 1798 */
1796static void 1799static void
1797handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg) 1800handle_client_accept(void *cls, const struct GNUNET_SET_AcceptMessage *msg)
1798{ 1801{
1799 struct ClientState *cs = cls; 1802 struct ClientState *cs = cls;
1800 struct Set *set; 1803 struct Set *set;
@@ -1804,40 +1807,40 @@ handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg)
1804 struct Listener *listener; 1807 struct Listener *listener;
1805 1808
1806 if (NULL == (set = cs->set)) 1809 if (NULL == (set = cs->set))
1807 { 1810 {
1808 /* client without a set requested to accept */ 1811 /* client without a set requested to accept */
1809 GNUNET_break (0); 1812 GNUNET_break(0);
1810 GNUNET_SERVICE_client_drop (cs->client); 1813 GNUNET_SERVICE_client_drop(cs->client);
1811 return; 1814 return;
1812 } 1815 }
1813 op = get_incoming (ntohl (msg->accept_reject_id)); 1816 op = get_incoming(ntohl(msg->accept_reject_id));
1814 if (NULL == op) 1817 if (NULL == op)
1815 { 1818 {
1816 /* It is not an error if the set op does not exist -- it may 1819 /* It is not an error if the set op does not exist -- it may
1817 * have been destroyed when the partner peer disconnected. */ 1820 * have been destroyed when the partner peer disconnected. */
1818 GNUNET_log ( 1821 GNUNET_log(
1819 GNUNET_ERROR_TYPE_INFO, 1822 GNUNET_ERROR_TYPE_INFO,
1820 "Client %p accepted request %u of listener %p that is no longer active\n", 1823 "Client %p accepted request %u of listener %p that is no longer active\n",
1821 cs, 1824 cs,
1822 ntohl (msg->accept_reject_id), 1825 ntohl(msg->accept_reject_id),
1823 cs->listener); 1826 cs->listener);
1824 ev = GNUNET_MQ_msg (result_message, GNUNET_MESSAGE_TYPE_SET_RESULT); 1827 ev = GNUNET_MQ_msg(result_message, GNUNET_MESSAGE_TYPE_SET_RESULT);
1825 result_message->request_id = msg->request_id; 1828 result_message->request_id = msg->request_id;
1826 result_message->result_status = htons (GNUNET_SET_STATUS_FAILURE); 1829 result_message->result_status = htons(GNUNET_SET_STATUS_FAILURE);
1827 GNUNET_MQ_send (set->cs->mq, ev); 1830 GNUNET_MQ_send(set->cs->mq, ev);
1828 GNUNET_SERVICE_client_continue (cs->client); 1831 GNUNET_SERVICE_client_continue(cs->client);
1829 return; 1832 return;
1830 } 1833 }
1831 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1834 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1832 "Client accepting request %u\n", 1835 "Client accepting request %u\n",
1833 (uint32_t) ntohl (msg->accept_reject_id)); 1836 (uint32_t)ntohl(msg->accept_reject_id));
1834 listener = op->listener; 1837 listener = op->listener;
1835 op->listener = NULL; 1838 op->listener = NULL;
1836 GNUNET_CONTAINER_DLL_remove (listener->op_head, listener->op_tail, op); 1839 GNUNET_CONTAINER_DLL_remove(listener->op_head, listener->op_tail, op);
1837 op->set = set; 1840 op->set = set;
1838 GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op); 1841 GNUNET_CONTAINER_DLL_insert(set->ops_head, set->ops_tail, op);
1839 op->client_request_id = ntohl (msg->request_id); 1842 op->client_request_id = ntohl(msg->request_id);
1840 op->result_mode = ntohl (msg->result_mode); 1843 op->result_mode = ntohl(msg->result_mode);
1841 op->byzantine = msg->byzantine; 1844 op->byzantine = msg->byzantine;
1842 op->byzantine_lower_bound = msg->byzantine_lower_bound; 1845 op->byzantine_lower_bound = msg->byzantine_lower_bound;
1843 op->force_full = msg->force_full; 1846 op->force_full = msg->force_full;
@@ -1846,20 +1849,20 @@ handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg)
1846 /* Advance generation values, so that future mutations do not 1849 /* Advance generation values, so that future mutations do not
1847 interfer with the running operation. */ 1850 interfer with the running operation. */
1848 op->generation_created = set->current_generation; 1851 op->generation_created = set->current_generation;
1849 advance_generation (set); 1852 advance_generation(set);
1850 GNUNET_assert (NULL == op->state); 1853 GNUNET_assert(NULL == op->state);
1851 op->state = set->vt->accept (op); 1854 op->state = set->vt->accept(op);
1852 if (NULL == op->state) 1855 if (NULL == op->state)
1853 { 1856 {
1854 GNUNET_break (0); 1857 GNUNET_break(0);
1855 GNUNET_SERVICE_client_drop (cs->client); 1858 GNUNET_SERVICE_client_drop(cs->client);
1856 return; 1859 return;
1857 } 1860 }
1858 /* Now allow CADET to continue, as we did not do this in 1861 /* Now allow CADET to continue, as we did not do this in
1859 #handle_incoming_msg (as we wanted to first see if the 1862 #handle_incoming_msg (as we wanted to first see if the
1860 local client would accept the request). */ 1863 local client would accept the request). */
1861 GNUNET_CADET_receive_done (op->channel); 1864 GNUNET_CADET_receive_done(op->channel);
1862 GNUNET_SERVICE_client_continue (cs->client); 1865 GNUNET_SERVICE_client_continue(cs->client);
1863} 1866}
1864 1867
1865 1868
@@ -1869,20 +1872,20 @@ handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg)
1869 * @param cls closure, NULL 1872 * @param cls closure, NULL
1870 */ 1873 */
1871static void 1874static void
1872shutdown_task (void *cls) 1875shutdown_task(void *cls)
1873{ 1876{
1874 /* Delay actual shutdown to allow service to disconnect clients */ 1877 /* Delay actual shutdown to allow service to disconnect clients */
1875 in_shutdown = GNUNET_YES; 1878 in_shutdown = GNUNET_YES;
1876 if (0 == num_clients) 1879 if (0 == num_clients)
1877 {
1878 if (NULL != cadet)
1879 { 1880 {
1880 GNUNET_CADET_disconnect (cadet); 1881 if (NULL != cadet)
1881 cadet = NULL; 1882 {
1883 GNUNET_CADET_disconnect(cadet);
1884 cadet = NULL;
1885 }
1882 } 1886 }
1883 } 1887 GNUNET_STATISTICS_destroy(_GSS_statistics, GNUNET_YES);
1884 GNUNET_STATISTICS_destroy (_GSS_statistics, GNUNET_YES); 1888 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "handled shutdown request\n");
1885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handled shutdown request\n");
1886} 1889}
1887 1890
1888 1891
@@ -1895,85 +1898,85 @@ shutdown_task (void *cls)
1895 * @param service the initialized service 1898 * @param service the initialized service
1896 */ 1899 */
1897static void 1900static void
1898run (void *cls, 1901run(void *cls,
1899 const struct GNUNET_CONFIGURATION_Handle *cfg, 1902 const struct GNUNET_CONFIGURATION_Handle *cfg,
1900 struct GNUNET_SERVICE_Handle *service) 1903 struct GNUNET_SERVICE_Handle *service)
1901{ 1904{
1902 /* FIXME: need to modify SERVICE (!) API to allow 1905 /* FIXME: need to modify SERVICE (!) API to allow
1903 us to run a shutdown task *after* clients were 1906 us to run a shutdown task *after* clients were
1904 forcefully disconnected! */ 1907 forcefully disconnected! */
1905 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 1908 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
1906 _GSS_statistics = GNUNET_STATISTICS_create ("set", cfg); 1909 _GSS_statistics = GNUNET_STATISTICS_create("set", cfg);
1907 cadet = GNUNET_CADET_connect (cfg); 1910 cadet = GNUNET_CADET_connect(cfg);
1908 if (NULL == cadet) 1911 if (NULL == cadet)
1909 { 1912 {
1910 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1913 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1911 _ ("Could not connect to CADET service\n")); 1914 _("Could not connect to CADET service\n"));
1912 GNUNET_SCHEDULER_shutdown (); 1915 GNUNET_SCHEDULER_shutdown();
1913 return; 1916 return;
1914 } 1917 }
1915} 1918}
1916 1919
1917 1920
1918/** 1921/**
1919 * Define "main" method using service macro. 1922 * Define "main" method using service macro.
1920 */ 1923 */
1921GNUNET_SERVICE_MAIN ( 1924GNUNET_SERVICE_MAIN(
1922 "set", 1925 "set",
1923 GNUNET_SERVICE_OPTION_NONE, 1926 GNUNET_SERVICE_OPTION_NONE,
1924 &run, 1927 &run,
1925 &client_connect_cb, 1928 &client_connect_cb,
1926 &client_disconnect_cb, 1929 &client_disconnect_cb,
1927 NULL, 1930 NULL,
1928 GNUNET_MQ_hd_fixed_size (client_accept, 1931 GNUNET_MQ_hd_fixed_size(client_accept,
1929 GNUNET_MESSAGE_TYPE_SET_ACCEPT, 1932 GNUNET_MESSAGE_TYPE_SET_ACCEPT,
1930 struct GNUNET_SET_AcceptMessage, 1933 struct GNUNET_SET_AcceptMessage,
1931 NULL), 1934 NULL),
1932 GNUNET_MQ_hd_fixed_size (client_iter_ack, 1935 GNUNET_MQ_hd_fixed_size(client_iter_ack,
1933 GNUNET_MESSAGE_TYPE_SET_ITER_ACK, 1936 GNUNET_MESSAGE_TYPE_SET_ITER_ACK,
1934 struct GNUNET_SET_IterAckMessage, 1937 struct GNUNET_SET_IterAckMessage,
1935 NULL), 1938 NULL),
1936 GNUNET_MQ_hd_var_size (client_mutation, 1939 GNUNET_MQ_hd_var_size(client_mutation,
1937 GNUNET_MESSAGE_TYPE_SET_ADD, 1940 GNUNET_MESSAGE_TYPE_SET_ADD,
1938 struct GNUNET_SET_ElementMessage, 1941 struct GNUNET_SET_ElementMessage,
1939 NULL), 1942 NULL),
1940 GNUNET_MQ_hd_fixed_size (client_create_set, 1943 GNUNET_MQ_hd_fixed_size(client_create_set,
1941 GNUNET_MESSAGE_TYPE_SET_CREATE, 1944 GNUNET_MESSAGE_TYPE_SET_CREATE,
1942 struct GNUNET_SET_CreateMessage, 1945 struct GNUNET_SET_CreateMessage,
1943 NULL), 1946 NULL),
1944 GNUNET_MQ_hd_fixed_size (client_iterate, 1947 GNUNET_MQ_hd_fixed_size(client_iterate,
1945 GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST, 1948 GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST,
1946 struct GNUNET_MessageHeader, 1949 struct GNUNET_MessageHeader,
1947 NULL), 1950 NULL),
1948 GNUNET_MQ_hd_var_size (client_evaluate, 1951 GNUNET_MQ_hd_var_size(client_evaluate,
1949 GNUNET_MESSAGE_TYPE_SET_EVALUATE, 1952 GNUNET_MESSAGE_TYPE_SET_EVALUATE,
1950 struct GNUNET_SET_EvaluateMessage, 1953 struct GNUNET_SET_EvaluateMessage,
1951 NULL), 1954 NULL),
1952 GNUNET_MQ_hd_fixed_size (client_listen, 1955 GNUNET_MQ_hd_fixed_size(client_listen,
1953 GNUNET_MESSAGE_TYPE_SET_LISTEN, 1956 GNUNET_MESSAGE_TYPE_SET_LISTEN,
1954 struct GNUNET_SET_ListenMessage, 1957 struct GNUNET_SET_ListenMessage,
1955 NULL), 1958 NULL),
1956 GNUNET_MQ_hd_fixed_size (client_reject, 1959 GNUNET_MQ_hd_fixed_size(client_reject,
1957 GNUNET_MESSAGE_TYPE_SET_REJECT, 1960 GNUNET_MESSAGE_TYPE_SET_REJECT,
1958 struct GNUNET_SET_RejectMessage, 1961 struct GNUNET_SET_RejectMessage,
1959 NULL), 1962 NULL),
1960 GNUNET_MQ_hd_var_size (client_mutation, 1963 GNUNET_MQ_hd_var_size(client_mutation,
1961 GNUNET_MESSAGE_TYPE_SET_REMOVE, 1964 GNUNET_MESSAGE_TYPE_SET_REMOVE,
1962 struct GNUNET_SET_ElementMessage, 1965 struct GNUNET_SET_ElementMessage,
1963 NULL), 1966 NULL),
1964 GNUNET_MQ_hd_fixed_size (client_cancel, 1967 GNUNET_MQ_hd_fixed_size(client_cancel,
1965 GNUNET_MESSAGE_TYPE_SET_CANCEL, 1968 GNUNET_MESSAGE_TYPE_SET_CANCEL,
1966 struct GNUNET_SET_CancelMessage, 1969 struct GNUNET_SET_CancelMessage,
1967 NULL), 1970 NULL),
1968 GNUNET_MQ_hd_fixed_size (client_copy_lazy_prepare, 1971 GNUNET_MQ_hd_fixed_size(client_copy_lazy_prepare,
1969 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE, 1972 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE,
1970 struct GNUNET_MessageHeader, 1973 struct GNUNET_MessageHeader,
1971 NULL), 1974 NULL),
1972 GNUNET_MQ_hd_fixed_size (client_copy_lazy_connect, 1975 GNUNET_MQ_hd_fixed_size(client_copy_lazy_connect,
1973 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT, 1976 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT,
1974 struct GNUNET_SET_CopyLazyConnectMessage, 1977 struct GNUNET_SET_CopyLazyConnectMessage,
1975 NULL), 1978 NULL),
1976 GNUNET_MQ_handler_end ()); 1979 GNUNET_MQ_handler_end());
1977 1980
1978 1981
1979/* end of gnunet-service-set.c */ 1982/* end of gnunet-service-set.c */