aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/plugin_datastore_heap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datastore/plugin_datastore_heap.c')
-rw-r--r--src/datastore/plugin_datastore_heap.c611
1 files changed, 313 insertions, 298 deletions
diff --git a/src/datastore/plugin_datastore_heap.c b/src/datastore/plugin_datastore_heap.c
index b7d73f0c4..4e48bfd4c 100644
--- a/src/datastore/plugin_datastore_heap.c
+++ b/src/datastore/plugin_datastore_heap.c
@@ -34,7 +34,8 @@
34/** 34/**
35 * A value that we are storing. 35 * A value that we are storing.
36 */ 36 */
37struct Value { 37struct Value
38{
38 /** 39 /**
39 * Key for the value. 40 * Key for the value.
40 */ 41 */
@@ -96,7 +97,8 @@ struct Value {
96/** 97/**
97 * We organize 0-anonymity values in arrays "by type". 98 * We organize 0-anonymity values in arrays "by type".
98 */ 99 */
99struct ZeroAnonByType { 100struct ZeroAnonByType
101{
100 /** 102 /**
101 * We keep these in a DLL. 103 * We keep these in a DLL.
102 */ 104 */
@@ -132,7 +134,8 @@ struct ZeroAnonByType {
132/** 134/**
133 * Context for all functions in this plugin. 135 * Context for all functions in this plugin.
134 */ 136 */
135struct Plugin { 137struct Plugin
138{
136 /** 139 /**
137 * Our execution environment. 140 * Our execution environment.
138 */ 141 */
@@ -178,7 +181,7 @@ struct Plugin {
178 * @return number of bytes used on disk 181 * @return number of bytes used on disk
179 */ 182 */
180static void 183static void
181heap_plugin_estimate_size(void *cls, unsigned long long *estimate) 184heap_plugin_estimate_size (void *cls, unsigned long long *estimate)
182{ 185{
183 struct Plugin *plugin = cls; 186 struct Plugin *plugin = cls;
184 187
@@ -190,7 +193,8 @@ heap_plugin_estimate_size(void *cls, unsigned long long *estimate)
190/** 193/**
191 * Closure for iterator for updating. 194 * Closure for iterator for updating.
192 */ 195 */
193struct UpdateContext { 196struct UpdateContext
197{
194 /** 198 /**
195 * Number of bytes in 'data'. 199 * Number of bytes in 'data'.
196 */ 200 */
@@ -232,25 +236,25 @@ struct UpdateContext {
232 * @return GNUNET_YES (continue iteration), GNUNET_NO if value was found 236 * @return GNUNET_YES (continue iteration), GNUNET_NO if value was found
233 */ 237 */
234static int 238static int
235update_iterator(void *cls, 239update_iterator (void *cls,
236 const struct GNUNET_HashCode *key, 240 const struct GNUNET_HashCode *key,
237 void *val) 241 void *val)
238{ 242{
239 struct UpdateContext *uc = cls; 243 struct UpdateContext *uc = cls;
240 struct Value *value = val; 244 struct Value *value = val;
241 245
242 if (value->size != uc->size) 246 if (value->size != uc->size)
243 return GNUNET_YES; 247 return GNUNET_YES;
244 if (0 != memcmp(value->data, uc->data, uc->size)) 248 if (0 != memcmp (value->data, uc->data, uc->size))
245 return GNUNET_YES; 249 return GNUNET_YES;
246 uc->expiration = GNUNET_TIME_absolute_max(value->expiration, 250 uc->expiration = GNUNET_TIME_absolute_max (value->expiration,
247 uc->expiration); 251 uc->expiration);
248 if (value->expiration.abs_value_us != uc->expiration.abs_value_us) 252 if (value->expiration.abs_value_us != uc->expiration.abs_value_us)
249 { 253 {
250 value->expiration = uc->expiration; 254 value->expiration = uc->expiration;
251 GNUNET_CONTAINER_heap_update_cost(value->expire_heap, 255 GNUNET_CONTAINER_heap_update_cost (value->expire_heap,
252 value->expiration.abs_value_us); 256 value->expiration.abs_value_us);
253 } 257 }
254 /* Saturating adds, don't overflow */ 258 /* Saturating adds, don't overflow */
255 if (value->priority > UINT32_MAX - uc->priority) 259 if (value->priority > UINT32_MAX - uc->priority)
256 value->priority = UINT32_MAX; 260 value->priority = UINT32_MAX;
@@ -281,88 +285,89 @@ update_iterator(void *cls,
281 * @param cont_cls continuation closure 285 * @param cont_cls continuation closure
282 */ 286 */
283static void 287static void
284heap_plugin_put(void *cls, 288heap_plugin_put (void *cls,
285 const struct GNUNET_HashCode *key, 289 const struct GNUNET_HashCode *key,
286 bool absent, 290 bool absent,
287 uint32_t size, 291 uint32_t size,
288 const void *data, 292 const void *data,
289 enum GNUNET_BLOCK_Type type, 293 enum GNUNET_BLOCK_Type type,
290 uint32_t priority, 294 uint32_t priority,
291 uint32_t anonymity, 295 uint32_t anonymity,
292 uint32_t replication, 296 uint32_t replication,
293 struct GNUNET_TIME_Absolute expiration, 297 struct GNUNET_TIME_Absolute expiration,
294 PluginPutCont cont, 298 PluginPutCont cont,
295 void *cont_cls) 299 void *cont_cls)
296{ 300{
297 struct Plugin *plugin = cls; 301 struct Plugin *plugin = cls;
298 struct Value *value; 302 struct Value *value;
299 303
300 if (!absent) 304 if (! absent)
305 {
306 struct UpdateContext uc;
307
308 uc.size = size;
309 uc.data = data;
310 uc.priority = priority;
311 uc.replication = replication;
312 uc.expiration = expiration;
313 uc.updated = false;
314 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->keyvalue,
315 key,
316 &update_iterator,
317 &uc);
318 if (uc.updated)
301 { 319 {
302 struct UpdateContext uc; 320 cont (cont_cls, key, size, GNUNET_NO, NULL);
303 321 return;
304 uc.size = size;
305 uc.data = data;
306 uc.priority = priority;
307 uc.replication = replication;
308 uc.expiration = expiration;
309 uc.updated = false;
310 GNUNET_CONTAINER_multihashmap_get_multiple(plugin->keyvalue,
311 key,
312 &update_iterator,
313 &uc);
314 if (uc.updated)
315 {
316 cont(cont_cls, key, size, GNUNET_NO, NULL);
317 return;
318 }
319 } 322 }
320 value = GNUNET_malloc(sizeof(struct Value) + size); 323 }
324 value = GNUNET_malloc (sizeof(struct Value) + size);
321 value->key = *key; 325 value->key = *key;
322 value->data = &value[1]; 326 value->data = &value[1];
323 value->expire_heap = GNUNET_CONTAINER_heap_insert(plugin->by_expiration, 327 value->expire_heap = GNUNET_CONTAINER_heap_insert (plugin->by_expiration,
324 value, 328 value,
325 expiration.abs_value_us); 329 expiration.abs_value_us);
326 value->replication_heap = GNUNET_CONTAINER_heap_insert(plugin->by_replication, 330 value->replication_heap = GNUNET_CONTAINER_heap_insert (
327 value, 331 plugin->by_replication,
328 replication); 332 value,
333 replication);
329 value->expiration = expiration; 334 value->expiration = expiration;
330 if (0 == anonymity) 335 if (0 == anonymity)
336 {
337 struct ZeroAnonByType *zabt;
338
339 for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next)
340 if (zabt->type == type)
341 break;
342 if (NULL == zabt)
331 { 343 {
332 struct ZeroAnonByType *zabt; 344 zabt = GNUNET_new (struct ZeroAnonByType);
333 345 zabt->type = type;
334 for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next) 346 GNUNET_CONTAINER_DLL_insert (plugin->zero_head,
335 if (zabt->type == type) 347 plugin->zero_tail,
336 break; 348 zabt);
337 if (NULL == zabt)
338 {
339 zabt = GNUNET_new(struct ZeroAnonByType);
340 zabt->type = type;
341 GNUNET_CONTAINER_DLL_insert(plugin->zero_head,
342 plugin->zero_tail,
343 zabt);
344 }
345 if (zabt->array_size == zabt->array_pos)
346 {
347 GNUNET_array_grow(zabt->array,
348 zabt->array_size,
349 zabt->array_size * 2 + 4);
350 }
351 value->zero_anon_offset = zabt->array_pos;
352 zabt->array[zabt->array_pos++] = value;
353 } 349 }
350 if (zabt->array_size == zabt->array_pos)
351 {
352 GNUNET_array_grow (zabt->array,
353 zabt->array_size,
354 zabt->array_size * 2 + 4);
355 }
356 value->zero_anon_offset = zabt->array_pos;
357 zabt->array[zabt->array_pos++] = value;
358 }
354 value->size = size; 359 value->size = size;
355 value->priority = priority; 360 value->priority = priority;
356 value->anonymity = anonymity; 361 value->anonymity = anonymity;
357 value->replication = replication; 362 value->replication = replication;
358 value->type = type; 363 value->type = type;
359 GNUNET_memcpy(&value[1], data, size); 364 GNUNET_memcpy (&value[1], data, size);
360 GNUNET_CONTAINER_multihashmap_put(plugin->keyvalue, 365 GNUNET_CONTAINER_multihashmap_put (plugin->keyvalue,
361 &value->key, 366 &value->key,
362 value, 367 value,
363 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 368 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
364 plugin->size += size; 369 plugin->size += size;
365 cont(cont_cls, key, size, GNUNET_OK, NULL); 370 cont (cont_cls, key, size, GNUNET_OK, NULL);
366} 371}
367 372
368 373
@@ -374,45 +379,49 @@ heap_plugin_put(void *cls,
374 * @param value value to delete 379 * @param value value to delete
375 */ 380 */
376static void 381static void
377delete_value(struct Plugin *plugin, 382delete_value (struct Plugin *plugin,
378 struct Value *value) 383 struct Value *value)
379{ 384{
380 GNUNET_assert(GNUNET_YES == 385 GNUNET_assert (GNUNET_YES ==
381 GNUNET_CONTAINER_multihashmap_remove(plugin->keyvalue, 386 GNUNET_CONTAINER_multihashmap_remove (plugin->keyvalue,
382 &value->key, 387 &value->key,
383 value)); 388 value));
384 GNUNET_assert(value == GNUNET_CONTAINER_heap_remove_node(value->expire_heap)); 389 GNUNET_assert (value == GNUNET_CONTAINER_heap_remove_node (
385 GNUNET_assert(value == GNUNET_CONTAINER_heap_remove_node(value->replication_heap)); 390 value->expire_heap));
391 GNUNET_assert (value == GNUNET_CONTAINER_heap_remove_node (
392 value->replication_heap));
386 if (0 == value->anonymity) 393 if (0 == value->anonymity)
394 {
395 struct ZeroAnonByType *zabt;
396
397 for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next)
398 if (zabt->type == value->type)
399 break;
400 GNUNET_assert (NULL != zabt);
401 zabt->array[value->zero_anon_offset] = zabt->array[--zabt->array_pos];
402 zabt->array[value->zero_anon_offset]->zero_anon_offset =
403 value->zero_anon_offset;
404 if (0 == zabt->array_pos)
387 { 405 {
388 struct ZeroAnonByType *zabt; 406 GNUNET_array_grow (zabt->array,
389 407 zabt->array_size,
390 for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next) 408 0);
391 if (zabt->type == value->type) 409 GNUNET_CONTAINER_DLL_remove (plugin->zero_head,
392 break; 410 plugin->zero_tail,
393 GNUNET_assert(NULL != zabt); 411 zabt);
394 zabt->array[value->zero_anon_offset] = zabt->array[--zabt->array_pos]; 412 GNUNET_free (zabt);
395 zabt->array[value->zero_anon_offset]->zero_anon_offset = value->zero_anon_offset;
396 if (0 == zabt->array_pos)
397 {
398 GNUNET_array_grow(zabt->array,
399 zabt->array_size,
400 0);
401 GNUNET_CONTAINER_DLL_remove(plugin->zero_head,
402 plugin->zero_tail,
403 zabt);
404 GNUNET_free(zabt);
405 }
406 } 413 }
414 }
407 plugin->size -= value->size; 415 plugin->size -= value->size;
408 GNUNET_free(value); 416 GNUNET_free (value);
409} 417}
410 418
411 419
412/** 420/**
413 * Closure for iterator called during 'get_key'. 421 * Closure for iterator called during 'get_key'.
414 */ 422 */
415struct GetContext { 423struct GetContext
424{
416 /** 425 /**
417 * Lowest uid to consider. 426 * Lowest uid to consider.
418 */ 427 */
@@ -444,9 +453,9 @@ struct GetContext {
444 * @return GNUNET_YES (continue iteration), GNUNET_NO if result was found 453 * @return GNUNET_YES (continue iteration), GNUNET_NO if result was found
445 */ 454 */
446static int 455static int
447get_iterator(void *cls, 456get_iterator (void *cls,
448 const struct GNUNET_HashCode *key, 457 const struct GNUNET_HashCode *key,
449 void *val) 458 void *val)
450{ 459{
451 struct GetContext *gc = cls; 460 struct GetContext *gc = cls;
452 struct Value *value = val; 461 struct Value *value = val;
@@ -455,11 +464,11 @@ get_iterator(void *cls,
455 (gc->type != value->type)) 464 (gc->type != value->type))
456 return GNUNET_OK; 465 return GNUNET_OK;
457 if (gc->random) 466 if (gc->random)
458 { 467 {
459 gc->value = value; 468 gc->value = value;
460 return GNUNET_NO; 469 return GNUNET_NO;
461 } 470 }
462 if ((uint64_t)(intptr_t)value < gc->next_uid) 471 if ((uint64_t) (intptr_t) value < gc->next_uid)
463 return GNUNET_OK; 472 return GNUNET_OK;
464 if ((NULL != gc->value) && 473 if ((NULL != gc->value) &&
465 (value > gc->value)) 474 (value > gc->value))
@@ -483,13 +492,13 @@ get_iterator(void *cls,
483 * @param proc_cls closure for @a proc 492 * @param proc_cls closure for @a proc
484 */ 493 */
485static void 494static void
486heap_plugin_get_key(void *cls, 495heap_plugin_get_key (void *cls,
487 uint64_t next_uid, 496 uint64_t next_uid,
488 bool random, 497 bool random,
489 const struct GNUNET_HashCode *key, 498 const struct GNUNET_HashCode *key,
490 enum GNUNET_BLOCK_Type type, 499 enum GNUNET_BLOCK_Type type,
491 PluginDatumProcessor proc, 500 PluginDatumProcessor proc,
492 void *proc_cls) 501 void *proc_cls)
493{ 502{
494 struct Plugin *plugin = cls; 503 struct Plugin *plugin = cls;
495 struct GetContext gc; 504 struct GetContext gc;
@@ -499,34 +508,34 @@ heap_plugin_get_key(void *cls,
499 gc.random = random; 508 gc.random = random;
500 gc.type = type; 509 gc.type = type;
501 if (NULL == key) 510 if (NULL == key)
502 { 511 {
503 GNUNET_CONTAINER_multihashmap_iterate(plugin->keyvalue, 512 GNUNET_CONTAINER_multihashmap_iterate (plugin->keyvalue,
504 &get_iterator, 513 &get_iterator,
505 &gc); 514 &gc);
506 } 515 }
507 else 516 else
508 { 517 {
509 GNUNET_CONTAINER_multihashmap_get_multiple(plugin->keyvalue, 518 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->keyvalue,
510 key, 519 key,
511 &get_iterator, 520 &get_iterator,
512 &gc); 521 &gc);
513 } 522 }
514 if (NULL == gc.value) 523 if (NULL == gc.value)
515 { 524 {
516 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 525 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
517 return; 526 return;
518 } 527 }
519 GNUNET_assert(GNUNET_OK == 528 GNUNET_assert (GNUNET_OK ==
520 proc(proc_cls, 529 proc (proc_cls,
521 &gc.value->key, 530 &gc.value->key,
522 gc.value->size, 531 gc.value->size,
523 &gc.value[1], 532 &gc.value[1],
524 gc.value->type, 533 gc.value->type,
525 gc.value->priority, 534 gc.value->priority,
526 gc.value->anonymity, 535 gc.value->anonymity,
527 gc.value->replication, 536 gc.value->replication,
528 gc.value->expiration, 537 gc.value->expiration,
529 (uint64_t)(intptr_t)gc.value)); 538 (uint64_t) (intptr_t) gc.value));
530} 539}
531 540
532 541
@@ -542,45 +551,47 @@ heap_plugin_get_key(void *cls,
542 * @param proc_cls closure for proc 551 * @param proc_cls closure for proc
543 */ 552 */
544static void 553static void
545heap_plugin_get_replication(void *cls, 554heap_plugin_get_replication (void *cls,
546 PluginDatumProcessor proc, 555 PluginDatumProcessor proc,
547 void *proc_cls) 556 void *proc_cls)
548{ 557{
549 struct Plugin *plugin = cls; 558 struct Plugin *plugin = cls;
550 struct Value *value; 559 struct Value *value;
551 560
552 value = GNUNET_CONTAINER_heap_remove_root(plugin->by_replication); 561 value = GNUNET_CONTAINER_heap_remove_root (plugin->by_replication);
553 if (NULL == value) 562 if (NULL == value)
554 { 563 {
555 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 564 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
556 return; 565 return;
557 } 566 }
558 if (value->replication > 0) 567 if (value->replication > 0)
559 { 568 {
560 value->replication--; 569 value->replication--;
561 value->replication_heap = GNUNET_CONTAINER_heap_insert(plugin->by_replication, 570 value->replication_heap = GNUNET_CONTAINER_heap_insert (
562 value, 571 plugin->by_replication,
563 value->replication); 572 value,
564 } 573 value->replication);
574 }
565 else 575 else
566 { 576 {
567 /* need a better way to pick a random item, replication level is always 0 */ 577 /* need a better way to pick a random item, replication level is always 0 */
568 value->replication_heap = GNUNET_CONTAINER_heap_insert(plugin->by_replication, 578 value->replication_heap = GNUNET_CONTAINER_heap_insert (
569 value, 579 plugin->by_replication,
570 value->replication); 580 value,
571 value = GNUNET_CONTAINER_heap_walk_get_next(plugin->by_replication); 581 value->replication);
572 } 582 value = GNUNET_CONTAINER_heap_walk_get_next (plugin->by_replication);
573 GNUNET_assert(GNUNET_OK == 583 }
574 proc(proc_cls, 584 GNUNET_assert (GNUNET_OK ==
575 &value->key, 585 proc (proc_cls,
576 value->size, 586 &value->key,
577 &value[1], 587 value->size,
578 value->type, 588 &value[1],
579 value->priority, 589 value->type,
580 value->anonymity, 590 value->priority,
581 value->replication, 591 value->anonymity,
582 value->expiration, 592 value->replication,
583 (uint64_t)(intptr_t)value)); 593 value->expiration,
594 (uint64_t) (intptr_t) value));
584} 595}
585 596
586 597
@@ -593,30 +604,30 @@ heap_plugin_get_replication(void *cls,
593 * @param proc_cls closure for proc 604 * @param proc_cls closure for proc
594 */ 605 */
595static void 606static void
596heap_plugin_get_expiration(void *cls, PluginDatumProcessor proc, 607heap_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
597 void *proc_cls) 608 void *proc_cls)
598{ 609{
599 struct Plugin *plugin = cls; 610 struct Plugin *plugin = cls;
600 struct Value *value; 611 struct Value *value;
601 612
602 value = GNUNET_CONTAINER_heap_peek(plugin->by_expiration); 613 value = GNUNET_CONTAINER_heap_peek (plugin->by_expiration);
603 if (NULL == value) 614 if (NULL == value)
604 { 615 {
605 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 616 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
606 return; 617 return;
607 } 618 }
608 if (GNUNET_NO == 619 if (GNUNET_NO ==
609 proc(proc_cls, 620 proc (proc_cls,
610 &value->key, 621 &value->key,
611 value->size, 622 value->size,
612 &value[1], 623 &value[1],
613 value->type, 624 value->type,
614 value->priority, 625 value->priority,
615 value->anonymity, 626 value->anonymity,
616 value->replication, 627 value->replication,
617 value->expiration, 628 value->expiration,
618 (uint64_t)(intptr_t)value)) 629 (uint64_t) (intptr_t) value))
619 delete_value(plugin, value); 630 delete_value (plugin, value);
620} 631}
621 632
622 633
@@ -632,45 +643,45 @@ heap_plugin_get_expiration(void *cls, PluginDatumProcessor proc,
632 * @param proc_cls closure for proc 643 * @param proc_cls closure for proc
633 */ 644 */
634static void 645static void
635heap_plugin_get_zero_anonymity(void *cls, uint64_t next_uid, 646heap_plugin_get_zero_anonymity (void *cls, uint64_t next_uid,
636 enum GNUNET_BLOCK_Type type, 647 enum GNUNET_BLOCK_Type type,
637 PluginDatumProcessor proc, void *proc_cls) 648 PluginDatumProcessor proc, void *proc_cls)
638{ 649{
639 struct Plugin *plugin = cls; 650 struct Plugin *plugin = cls;
640 struct ZeroAnonByType *zabt; 651 struct ZeroAnonByType *zabt;
641 struct Value *value = NULL; 652 struct Value *value = NULL;
642 653
643 for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next) 654 for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next)
655 {
656 if ((type != GNUNET_BLOCK_TYPE_ANY) &&
657 (type != zabt->type))
658 continue;
659 for (int i = 0; i < zabt->array_pos; ++i)
644 { 660 {
645 if ((type != GNUNET_BLOCK_TYPE_ANY) && 661 if ((uint64_t) (intptr_t) zabt->array[i] < next_uid)
646 (type != zabt->type)) 662 continue;
663 if ((NULL != value) &&
664 (zabt->array[i] > value))
647 continue; 665 continue;
648 for (int i = 0; i < zabt->array_pos; ++i) 666 value = zabt->array[i];
649 {
650 if ((uint64_t)(intptr_t)zabt->array[i] < next_uid)
651 continue;
652 if ((NULL != value) &&
653 (zabt->array[i] > value))
654 continue;
655 value = zabt->array[i];
656 }
657 } 667 }
668 }
658 if (NULL == value) 669 if (NULL == value)
659 { 670 {
660 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 671 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
661 return; 672 return;
662 } 673 }
663 GNUNET_assert(GNUNET_OK == 674 GNUNET_assert (GNUNET_OK ==
664 proc(proc_cls, 675 proc (proc_cls,
665 &value->key, 676 &value->key,
666 value->size, 677 value->size,
667 &value[1], 678 &value[1],
668 value->type, 679 value->type,
669 value->priority, 680 value->priority,
670 value->anonymity, 681 value->anonymity,
671 value->replication, 682 value->replication,
672 value->expiration, 683 value->expiration,
673 (uint64_t)(intptr_t)value)); 684 (uint64_t) (intptr_t) value));
674} 685}
675 686
676 687
@@ -678,7 +689,7 @@ heap_plugin_get_zero_anonymity(void *cls, uint64_t next_uid,
678 * Drop database. 689 * Drop database.
679 */ 690 */
680static void 691static void
681heap_plugin_drop(void *cls) 692heap_plugin_drop (void *cls)
682{ 693{
683 /* nothing needs to be done */ 694 /* nothing needs to be done */
684} 695}
@@ -687,7 +698,8 @@ heap_plugin_drop(void *cls)
687/** 698/**
688 * Closure for the 'return_value' function. 699 * Closure for the 'return_value' function.
689 */ 700 */
690struct GetAllContext { 701struct GetAllContext
702{
691 /** 703 /**
692 * Function to call. 704 * Function to call.
693 */ 705 */
@@ -709,15 +721,15 @@ struct GetAllContext {
709 * @return GNUNET_OK (continue to iterate) 721 * @return GNUNET_OK (continue to iterate)
710 */ 722 */
711static int 723static int
712return_value(void *cls, 724return_value (void *cls,
713 const struct GNUNET_HashCode *key, 725 const struct GNUNET_HashCode *key,
714 void *val) 726 void *val)
715{ 727{
716 struct GetAllContext *gac = cls; 728 struct GetAllContext *gac = cls;
717 729
718 gac->proc(gac->proc_cls, 730 gac->proc (gac->proc_cls,
719 key, 731 key,
720 1); 732 1);
721 return GNUNET_OK; 733 return GNUNET_OK;
722} 734}
723 735
@@ -730,26 +742,27 @@ return_value(void *cls,
730 * @param proc_cls closure for proc 742 * @param proc_cls closure for proc
731 */ 743 */
732static void 744static void
733heap_get_keys(void *cls, 745heap_get_keys (void *cls,
734 PluginKeyProcessor proc, 746 PluginKeyProcessor proc,
735 void *proc_cls) 747 void *proc_cls)
736{ 748{
737 struct Plugin *plugin = cls; 749 struct Plugin *plugin = cls;
738 struct GetAllContext gac; 750 struct GetAllContext gac;
739 751
740 gac.proc = proc; 752 gac.proc = proc;
741 gac.proc_cls = proc_cls; 753 gac.proc_cls = proc_cls;
742 GNUNET_CONTAINER_multihashmap_iterate(plugin->keyvalue, 754 GNUNET_CONTAINER_multihashmap_iterate (plugin->keyvalue,
743 &return_value, 755 &return_value,
744 &gac); 756 &gac);
745 proc(proc_cls, NULL, 0); 757 proc (proc_cls, NULL, 0);
746} 758}
747 759
748 760
749/** 761/**
750 * Closure for iterator called during 'remove_key'. 762 * Closure for iterator called during 'remove_key'.
751 */ 763 */
752struct RemoveContext { 764struct RemoveContext
765{
753 /** 766 /**
754 * Value found. 767 * Value found.
755 */ 768 */
@@ -776,16 +789,16 @@ struct RemoveContext {
776 * @return GNUNET_YES (continue iteration), GNUNET_NO if result was found 789 * @return GNUNET_YES (continue iteration), GNUNET_NO if result was found
777 */ 790 */
778static int 791static int
779remove_iterator(void *cls, 792remove_iterator (void *cls,
780 const struct GNUNET_HashCode *key, 793 const struct GNUNET_HashCode *key,
781 void *val) 794 void *val)
782{ 795{
783 struct RemoveContext *rc = cls; 796 struct RemoveContext *rc = cls;
784 struct Value *value = val; 797 struct Value *value = val;
785 798
786 if (value->size != rc->size) 799 if (value->size != rc->size)
787 return GNUNET_YES; 800 return GNUNET_YES;
788 if (0 != memcmp(value->data, rc->data, rc->size)) 801 if (0 != memcmp (value->data, rc->data, rc->size))
789 return GNUNET_YES; 802 return GNUNET_YES;
790 rc->value = value; 803 rc->value = value;
791 return GNUNET_NO; 804 return GNUNET_NO;
@@ -803,12 +816,12 @@ remove_iterator(void *cls,
803 * @param cont_cls continuation closure for @a cont 816 * @param cont_cls continuation closure for @a cont
804 */ 817 */
805static void 818static void
806heap_plugin_remove_key(void *cls, 819heap_plugin_remove_key (void *cls,
807 const struct GNUNET_HashCode *key, 820 const struct GNUNET_HashCode *key,
808 uint32_t size, 821 uint32_t size,
809 const void *data, 822 const void *data,
810 PluginRemoveCont cont, 823 PluginRemoveCont cont,
811 void *cont_cls) 824 void *cont_cls)
812{ 825{
813 struct Plugin *plugin = cls; 826 struct Plugin *plugin = cls;
814 struct RemoveContext rc; 827 struct RemoveContext rc;
@@ -816,26 +829,26 @@ heap_plugin_remove_key(void *cls,
816 rc.value = NULL; 829 rc.value = NULL;
817 rc.size = size; 830 rc.size = size;
818 rc.data = data; 831 rc.data = data;
819 GNUNET_CONTAINER_multihashmap_get_multiple(plugin->keyvalue, 832 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->keyvalue,
820 key, 833 key,
821 &remove_iterator, 834 &remove_iterator,
822 &rc); 835 &rc);
823 if (NULL == rc.value) 836 if (NULL == rc.value)
824 { 837 {
825 cont(cont_cls, 838 cont (cont_cls,
826 key, 839 key,
827 size, 840 size,
828 GNUNET_NO, 841 GNUNET_NO,
829 NULL); 842 NULL);
830 return; 843 return;
831 } 844 }
832 delete_value(plugin, 845 delete_value (plugin,
833 rc.value); 846 rc.value);
834 cont(cont_cls, 847 cont (cont_cls,
835 key, 848 key,
836 size, 849 size,
837 GNUNET_OK, 850 GNUNET_OK,
838 NULL); 851 NULL);
839} 852}
840 853
841 854
@@ -846,7 +859,7 @@ heap_plugin_remove_key(void *cls,
846 * @return our "struct Plugin*" 859 * @return our "struct Plugin*"
847 */ 860 */
848void * 861void *
849libgnunet_plugin_datastore_heap_init(void *cls) 862libgnunet_plugin_datastore_heap_init (void *cls)
850{ 863{
851 struct GNUNET_DATASTORE_PluginEnvironment *env = cls; 864 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
852 struct GNUNET_DATASTORE_PluginFunctions *api; 865 struct GNUNET_DATASTORE_PluginFunctions *api;
@@ -854,17 +867,19 @@ libgnunet_plugin_datastore_heap_init(void *cls)
854 unsigned long long esize; 867 unsigned long long esize;
855 868
856 if (GNUNET_OK != 869 if (GNUNET_OK !=
857 GNUNET_CONFIGURATION_get_value_number(env->cfg, 870 GNUNET_CONFIGURATION_get_value_number (env->cfg,
858 "datastore-heap", 871 "datastore-heap",
859 "HASHMAPSIZE", 872 "HASHMAPSIZE",
860 &esize)) 873 &esize))
861 esize = 128 * 1024; 874 esize = 128 * 1024;
862 plugin = GNUNET_new(struct Plugin); 875 plugin = GNUNET_new (struct Plugin);
863 plugin->env = env; 876 plugin->env = env;
864 plugin->keyvalue = GNUNET_CONTAINER_multihashmap_create(esize, GNUNET_YES); 877 plugin->keyvalue = GNUNET_CONTAINER_multihashmap_create (esize, GNUNET_YES);
865 plugin->by_expiration = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); 878 plugin->by_expiration = GNUNET_CONTAINER_heap_create (
866 plugin->by_replication = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MAX); 879 GNUNET_CONTAINER_HEAP_ORDER_MIN);
867 api = GNUNET_new(struct GNUNET_DATASTORE_PluginFunctions); 880 plugin->by_replication = GNUNET_CONTAINER_heap_create (
881 GNUNET_CONTAINER_HEAP_ORDER_MAX);
882 api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
868 api->cls = plugin; 883 api->cls = plugin;
869 api->estimate_size = &heap_plugin_estimate_size; 884 api->estimate_size = &heap_plugin_estimate_size;
870 api->put = &heap_plugin_put; 885 api->put = &heap_plugin_put;
@@ -875,8 +890,8 @@ libgnunet_plugin_datastore_heap_init(void *cls)
875 api->drop = &heap_plugin_drop; 890 api->drop = &heap_plugin_drop;
876 api->get_keys = &heap_get_keys; 891 api->get_keys = &heap_get_keys;
877 api->remove_key = &heap_plugin_remove_key; 892 api->remove_key = &heap_plugin_remove_key;
878 GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "heap", 893 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "heap",
879 _("Heap database running\n")); 894 _ ("Heap database running\n"));
880 return api; 895 return api;
881} 896}
882 897
@@ -890,14 +905,14 @@ libgnunet_plugin_datastore_heap_init(void *cls)
890 * @return GNUNET_OK (continue to iterate) 905 * @return GNUNET_OK (continue to iterate)
891 */ 906 */
892static int 907static int
893free_value(void *cls, 908free_value (void *cls,
894 const struct GNUNET_HashCode *key, 909 const struct GNUNET_HashCode *key,
895 void *val) 910 void *val)
896{ 911{
897 struct Plugin *plugin = cls; 912 struct Plugin *plugin = cls;
898 struct Value *value = val; 913 struct Value *value = val;
899 914
900 delete_value(plugin, value); 915 delete_value (plugin, value);
901 return GNUNET_OK; 916 return GNUNET_OK;
902} 917}
903 918
@@ -908,19 +923,19 @@ free_value(void *cls,
908 * @return always NULL 923 * @return always NULL
909 */ 924 */
910void * 925void *
911libgnunet_plugin_datastore_heap_done(void *cls) 926libgnunet_plugin_datastore_heap_done (void *cls)
912{ 927{
913 struct GNUNET_DATASTORE_PluginFunctions *api = cls; 928 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
914 struct Plugin *plugin = api->cls; 929 struct Plugin *plugin = api->cls;
915 930
916 GNUNET_CONTAINER_multihashmap_iterate(plugin->keyvalue, 931 GNUNET_CONTAINER_multihashmap_iterate (plugin->keyvalue,
917 &free_value, 932 &free_value,
918 plugin); 933 plugin);
919 GNUNET_CONTAINER_multihashmap_destroy(plugin->keyvalue); 934 GNUNET_CONTAINER_multihashmap_destroy (plugin->keyvalue);
920 GNUNET_CONTAINER_heap_destroy(plugin->by_expiration); 935 GNUNET_CONTAINER_heap_destroy (plugin->by_expiration);
921 GNUNET_CONTAINER_heap_destroy(plugin->by_replication); 936 GNUNET_CONTAINER_heap_destroy (plugin->by_replication);
922 GNUNET_free(plugin); 937 GNUNET_free (plugin);
923 GNUNET_free(api); 938 GNUNET_free (api);
924 return NULL; 939 return NULL;
925} 940}
926 941