aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/plugin_namestore_flat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/plugin_namestore_flat.c')
-rw-r--r--src/namestore/plugin_namestore_flat.c96
1 files changed, 37 insertions, 59 deletions
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c
index bbb9e3c62..35d8424b4 100644
--- a/src/namestore/plugin_namestore_flat.c
+++ b/src/namestore/plugin_namestore_flat.c
@@ -49,41 +49,6 @@ struct Plugin
49 */ 49 */
50 struct GNUNET_CONTAINER_MultiHashMap *hm; 50 struct GNUNET_CONTAINER_MultiHashMap *hm;
51 51
52 /**
53 * Offset
54 */
55 uint32_t offset;
56
57 /**
58 * Target Offset
59 */
60 uint32_t target_offset;
61
62 /**
63 * Iterator closure
64 */
65 void *iter_cls;
66
67 /**
68 * Iterator
69 */
70 GNUNET_NAMESTORE_RecordIterator iter;
71
72 /**
73 * Zone to iterate
74 */
75 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iter_zone;
76
77 /**
78 * PKEY to look for in zone to name
79 */
80 const struct GNUNET_CRYPTO_EcdsaPublicKey *iter_pkey;
81
82 /**
83 * Iteration result found
84 */
85 int iter_result_found;
86
87}; 52};
88 53
89 54
@@ -364,10 +329,10 @@ store_and_free_entries (void *cls,
364 &record_data_b64); 329 &record_data_b64);
365 } 330 }
366 GNUNET_asprintf (&line, 331 GNUNET_asprintf (&line,
367 "%s,%lu,%u,%s,%s\n", 332 "%s,%llu,%u,%s,%s\n",
368 zone_private_key, 333 zone_private_key,
369 entry->rvalue, 334 (unsigned long long) entry->rvalue,
370 entry->record_count, 335 (unsigned int) entry->record_count,
371 record_data_b64, 336 record_data_b64,
372 entry->label); 337 entry->label);
373 GNUNET_free (record_data_b64); 338 GNUNET_free (record_data_b64);
@@ -608,7 +573,6 @@ iterate_zones (void *cls,
608 struct FlatFileEntry *entry = value; 573 struct FlatFileEntry *entry = value;
609 574
610 (void) key; 575 (void) key;
611 ic->pos++;
612 if (0 == ic->limit) 576 if (0 == ic->limit)
613 return GNUNET_NO; 577 return GNUNET_NO;
614 if ( (NULL != ic->zone) && 578 if ( (NULL != ic->zone) &&
@@ -616,6 +580,7 @@ iterate_zones (void *cls,
616 ic->zone, 580 ic->zone,
617 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ) 581 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
618 return GNUNET_YES; 582 return GNUNET_YES;
583 ic->pos++;
619 if (ic->offset > 0) 584 if (ic->offset > 0)
620 { 585 {
621 ic->offset--; 586 ic->offset--;
@@ -670,17 +635,31 @@ namestore_flat_iterate_records (void *cls,
670} 635}
671 636
672 637
638/**
639 * Closure for #zone_to_name.
640 */
641struct ZoneToNameContext
642{
643 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone;
644 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone;
645 GNUNET_NAMESTORE_RecordIterator iter;
646 void *iter_cls;
647
648 int result_found;
649};
650
651
673static int 652static int
674zone_to_name (void *cls, 653zone_to_name (void *cls,
675 const struct GNUNET_HashCode *key, 654 const struct GNUNET_HashCode *key,
676 void *value) 655 void *value)
677{ 656{
678 struct Plugin *plugin = cls; 657 struct ZoneToNameContext *ztn = cls;
679 struct FlatFileEntry *entry = value; 658 struct FlatFileEntry *entry = value;
680 659
681 (void) key; 660 (void) key;
682 if (0 != memcmp (entry->private_key, 661 if (0 != memcmp (entry->private_key,
683 plugin->iter_zone, 662 ztn->zone,
684 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 663 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
685 return GNUNET_YES; 664 return GNUNET_YES;
686 665
@@ -688,18 +667,17 @@ zone_to_name (void *cls,
688 { 667 {
689 if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type) 668 if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type)
690 continue; 669 continue;
691 if (0 == memcmp (plugin->iter_pkey, 670 if (0 == memcmp (ztn->value_zone,
692 entry->record_data[i].data, 671 entry->record_data[i].data,
693 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 672 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
694 { 673 {
695 plugin->iter (plugin->iter_cls, 674 ztn->iter (ztn->iter_cls,
696 0, 675 0,
697 entry->private_key, 676 entry->private_key,
698 entry->label, 677 entry->label,
699 entry->record_count, 678 entry->record_count,
700 entry->record_data); 679 entry->record_data);
701 plugin->iter_result_found = GNUNET_YES; 680 ztn->result_found = GNUNET_YES;
702
703 } 681 }
704 } 682 }
705 return GNUNET_YES; 683 return GNUNET_YES;
@@ -725,21 +703,21 @@ namestore_flat_zone_to_name (void *cls,
725 void *iter_cls) 703 void *iter_cls)
726{ 704{
727 struct Plugin *plugin = cls; 705 struct Plugin *plugin = cls;
706 struct ZoneToNameContext ztn = {
707 .iter = iter,
708 .iter_cls = iter_cls,
709 .zone = zone,
710 .value_zone = value_zone,
711 .result_found = GNUNET_NO
712 };
728 713
729 /* FIXME: maybe use separate closure to better handle
730 recursive calls? */
731 plugin->iter = iter;
732 plugin->iter_cls = iter_cls;
733 plugin->iter_zone = zone;
734 plugin->iter_pkey = value_zone;
735 plugin->iter_result_found = GNUNET_NO;
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
737 "Performing reverse lookup for `%s'\n", 715 "Performing reverse lookup for `%s'\n",
738 GNUNET_GNSRECORD_z2s (value_zone)); 716 GNUNET_GNSRECORD_z2s (value_zone));
739 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, 717 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm,
740 &zone_to_name, 718 &zone_to_name,
741 plugin); 719 &ztn);
742 return plugin->iter_result_found; 720 return ztn.result_found;
743} 721}
744 722
745 723