diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-05-09 18:09:54 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-05-09 18:09:54 +0200 |
commit | 466c9bd9bc750b3c763d3ca3bcab1277ba73ee13 (patch) | |
tree | ef23a952e3f09d6f73f8998909f8379dbeaaf857 /src | |
parent | 4984ca8380195e69970ca14cbb0bc2bafe808d5d (diff) | |
download | gnunet-466c9bd9bc750b3c763d3ca3bcab1277ba73ee13.tar.gz gnunet-466c9bd9bc750b3c763d3ca3bcab1277ba73ee13.zip |
fix context for zone_to_name flat plugin
Diffstat (limited to 'src')
-rw-r--r-- | src/namestore/plugin_namestore_flat.c | 88 | ||||
-rw-r--r-- | src/namestore/test_namestore_api_monitoring_existing.c | 27 |
2 files changed, 53 insertions, 62 deletions
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c index df9f424a6..c464d4e68 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 | ||
@@ -670,17 +635,31 @@ namestore_flat_iterate_records (void *cls, | |||
670 | } | 635 | } |
671 | 636 | ||
672 | 637 | ||
638 | /** | ||
639 | * Closure for #zone_to_name. | ||
640 | */ | ||
641 | struct 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 | |||
673 | static int | 652 | static int |
674 | zone_to_name (void *cls, | 653 | zone_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 | ||
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c index 3e9e70923..449b36d65 100644 --- a/src/namestore/test_namestore_api_monitoring_existing.c +++ b/src/namestore/test_namestore_api_monitoring_existing.c | |||
@@ -337,16 +337,29 @@ run (void *cls, | |||
337 | /* name in different zone */ | 337 | /* name in different zone */ |
338 | GNUNET_asprintf(&s_name_3, "dummy3"); | 338 | GNUNET_asprintf(&s_name_3, "dummy3"); |
339 | s_rd_3 = create_record(1); | 339 | s_rd_3 = create_record(1); |
340 | GNUNET_assert (NULL != (ns_ops[2] = GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, | 340 | GNUNET_assert (NULL != (ns_ops[2] = |
341 | 1, s_rd_3, &put_cont, s_name_3))); | 341 | GNUNET_NAMESTORE_records_store (nsh, |
342 | privkey2, | ||
343 | s_name_3, | ||
344 | 1, | ||
345 | s_rd_3, | ||
346 | &put_cont, | ||
347 | s_name_3))); | ||
342 | 348 | ||
343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); | 349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
350 | "Created record 1\n"); | ||
344 | GNUNET_asprintf(&s_name_1, "dummy1"); | 351 | GNUNET_asprintf(&s_name_1, "dummy1"); |
345 | s_rd_1 = create_record(1); | 352 | s_rd_1 = create_record(1); |
346 | GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, | 353 | GNUNET_assert (NULL != (ns_ops[0] = |
347 | 1, s_rd_1, &put_cont, s_name_1))); | 354 | GNUNET_NAMESTORE_records_store(nsh, |
348 | 355 | privkey, | |
349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); | 356 | s_name_1, |
357 | 1, | ||
358 | s_rd_1, | ||
359 | &put_cont, | ||
360 | s_name_1))); | ||
361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
362 | "Created record 2 \n"); | ||
350 | GNUNET_asprintf(&s_name_2, "dummy2"); | 363 | GNUNET_asprintf(&s_name_2, "dummy2"); |
351 | s_rd_2 = create_record(1); | 364 | s_rd_2 = create_record(1); |
352 | GNUNET_assert (NULL != (ns_ops[1] = | 365 | GNUNET_assert (NULL != (ns_ops[1] = |