aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/plugin_namestore_heap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/plugin_namestore_heap.c')
-rw-r--r--src/namestore/plugin_namestore_heap.c93
1 files changed, 44 insertions, 49 deletions
diff --git a/src/namestore/plugin_namestore_heap.c b/src/namestore/plugin_namestore_heap.c
index 78e99442c..01cf592ea 100644
--- a/src/namestore/plugin_namestore_heap.c
+++ b/src/namestore/plugin_namestore_heap.c
@@ -79,11 +79,42 @@ struct FlatFileEntry
79 */ 79 */
80 char *label; 80 char *label;
81 81
82
83}; 82};
84 83
85 84
86/** 85/**
86 * Hash contactenation of @a pkey and @a label into @a h
87 *
88 * @param pkey a key
89 * @param label a label
90 * @param h[out] initialized hash
91 */
92static void
93hash_pkey_and_label (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
94 const char *label,
95 struct GNUNET_HashCode *h)
96{
97 char *key;
98 size_t label_len;
99 size_t key_len;
100
101 label_len = strlen (label);
102 key_len = label_len + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
103 key = GNUNET_malloc (key_len);
104 GNUNET_memcpy (key,
105 label,
106 label_len);
107 GNUNET_memcpy (key + label_len,
108 pkey,
109 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
110 GNUNET_CRYPTO_hash (key,
111 key_len,
112 h);
113 GNUNET_free (key);
114}
115
116
117/**
87 * Initialize the database connections and associated 118 * Initialize the database connections and associated
88 * data structures (create tables and indices 119 * data structures (create tables and indices
89 * as needed as well). 120 * as needed as well).
@@ -262,23 +293,9 @@ database_setup (struct Plugin *plugin)
262 GNUNET_free (private_key); 293 GNUNET_free (private_key);
263 } 294 }
264 295
265 { 296 hash_pkey_and_label (&entry->private_key,
266 char *key; 297 label,
267 size_t key_len; 298 &hkey);
268
269 key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
270 key = GNUNET_malloc (strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
271 GNUNET_memcpy (key,
272 label,
273 strlen (label));
274 GNUNET_memcpy (key+strlen(label),
275 &entry->private_key,
276 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
277 GNUNET_CRYPTO_hash (key,
278 key_len,
279 &hkey);
280 GNUNET_free (key);
281 }
282 if (GNUNET_OK != 299 if (GNUNET_OK !=
283 GNUNET_CONTAINER_multihashmap_put (plugin->hm, 300 GNUNET_CONTAINER_multihashmap_put (plugin->hm,
284 &hkey, 301 &hkey,
@@ -425,24 +442,14 @@ namestore_heap_store_records (void *cls,
425{ 442{
426 struct Plugin *plugin = cls; 443 struct Plugin *plugin = cls;
427 uint64_t rvalue; 444 uint64_t rvalue;
428 size_t key_len;
429 char *key;
430 struct GNUNET_HashCode hkey; 445 struct GNUNET_HashCode hkey;
431 struct FlatFileEntry *entry; 446 struct FlatFileEntry *entry;
432 447
433 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 448 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
434 UINT64_MAX); 449 UINT64_MAX);
435 key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); 450 hash_pkey_and_label (zone_key,
436 key = GNUNET_malloc (key_len); 451 label,
437 GNUNET_memcpy (key, 452 &hkey);
438 label,
439 strlen (label));
440 GNUNET_memcpy (key + strlen(label),
441 zone_key,
442 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
443 GNUNET_CRYPTO_hash (key,
444 key_len,
445 &hkey);
446 GNUNET_CONTAINER_multihashmap_remove_all (plugin->hm, 453 GNUNET_CONTAINER_multihashmap_remove_all (plugin->hm,
447 &hkey); 454 &hkey);
448 if (0 == rd_count) 455 if (0 == rd_count)
@@ -501,27 +508,15 @@ namestore_heap_lookup_records (void *cls,
501 struct Plugin *plugin = cls; 508 struct Plugin *plugin = cls;
502 struct FlatFileEntry *entry; 509 struct FlatFileEntry *entry;
503 struct GNUNET_HashCode hkey; 510 struct GNUNET_HashCode hkey;
504 char *key;
505 size_t key_len;
506 511
507 if (NULL == zone) 512 if (NULL == zone)
508 { 513 {
509 GNUNET_break (0); 514 GNUNET_break (0);
510 return GNUNET_SYSERR; 515 return GNUNET_SYSERR;
511 } 516 }
512 key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); 517 hash_pkey_and_label (zone,
513 key = GNUNET_malloc (key_len); 518 label,
514 GNUNET_memcpy (key, 519 &hkey);
515 label,
516 strlen (label));
517 GNUNET_memcpy (key+strlen(label),
518 zone,
519 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
520 GNUNET_CRYPTO_hash (key,
521 key_len,
522 &hkey);
523 GNUNET_free (key);
524
525 entry = GNUNET_CONTAINER_multihashmap_get (plugin->hm, 520 entry = GNUNET_CONTAINER_multihashmap_get (plugin->hm,
526 &hkey); 521 &hkey);
527 522
@@ -529,7 +524,7 @@ namestore_heap_lookup_records (void *cls,
529 return GNUNET_NO; 524 return GNUNET_NO;
530 if (NULL != iter) 525 if (NULL != iter)
531 iter (iter_cls, 526 iter (iter_cls,
532 0, 527 1, /* zero is illegal */
533 &entry->private_key, 528 &entry->private_key,
534 entry->label, 529 entry->label,
535 entry->record_count, 530 entry->record_count,
@@ -609,7 +604,7 @@ iterate_zones (void *cls,
609 } 604 }
610 ic->iter (ic->iter_cls, 605 ic->iter (ic->iter_cls,
611 ic->pos, 606 ic->pos,
612 (NULL == ic->zone) 607 (NULL == ic->zone)
613 ? &entry->private_key 608 ? &entry->private_key
614 : ic->zone, 609 : ic->zone,
615 entry->label, 610 entry->label,
@@ -695,7 +690,7 @@ zone_to_name (void *cls,
695 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 690 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
696 { 691 {
697 ztn->iter (ztn->iter_cls, 692 ztn->iter (ztn->iter_cls,
698 0, 693 i + 1, /* zero is illegal! */
699 &entry->private_key, 694 &entry->private_key,
700 entry->label, 695 entry->label,
701 entry->record_count, 696 entry->record_count,