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