diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-16 21:52:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-16 21:52:04 +0000 |
commit | dbc823a07a03e1085172038125b0edf15b0dc6fe (patch) | |
tree | 4e7c3bf60ce83e801c69a6566ea36d514b571cba | |
parent | eec0e5088ec9437f5c0cf9d3ffef87603ad2777a (diff) | |
download | gnunet-dbc823a07a03e1085172038125b0edf15b0dc6fe.tar.gz gnunet-dbc823a07a03e1085172038125b0edf15b0dc6fe.zip |
-finishing split of namestore into namestore and namecache (#3065) -- in theory; in practice, somehow something broke badly, so the tests are now failing
24 files changed, 447 insertions, 1795 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 6ee6d02ad..9a2573b91 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -165,6 +165,7 @@ gnunet_service_gns_LDADD = \ | |||
165 | $(top_builddir)/src/dns/libgnunetdnsparser.la \ | 165 | $(top_builddir)/src/dns/libgnunetdnsparser.la \ |
166 | $(top_builddir)/src/dns/libgnunetdnsstub.la \ | 166 | $(top_builddir)/src/dns/libgnunetdnsstub.la \ |
167 | $(top_builddir)/src/dht/libgnunetdht.la \ | 167 | $(top_builddir)/src/dht/libgnunetdht.la \ |
168 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ | ||
168 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | 169 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
169 | $(USE_VPN) \ | 170 | $(USE_VPN) \ |
170 | $(GN_LIBINTL) | 171 | $(GN_LIBINTL) |
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index ff574c3a1..53d6c11a4 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "gnunet_dns_service.h" | 28 | #include "gnunet_dns_service.h" |
29 | #include "gnunet_dnsparser_lib.h" | 29 | #include "gnunet_dnsparser_lib.h" |
30 | #include "gnunet_dht_service.h" | 30 | #include "gnunet_dht_service.h" |
31 | #include "gnunet_namecache_service.h" | ||
31 | #include "gnunet_namestore_service.h" | 32 | #include "gnunet_namestore_service.h" |
32 | #include "gnunet_gns_service.h" | 33 | #include "gnunet_gns_service.h" |
33 | #include "gnunet_statistics_service.h" | 34 | #include "gnunet_statistics_service.h" |
@@ -121,6 +122,11 @@ static struct GNUNET_DHT_PutHandle *active_put; | |||
121 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | 122 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; |
122 | 123 | ||
123 | /** | 124 | /** |
125 | * Our handle to the namecache service | ||
126 | */ | ||
127 | static struct GNUNET_NAMECACHE_Handle *namecache_handle; | ||
128 | |||
129 | /** | ||
124 | * Handle to iterate over our authoritative zone in namestore | 130 | * Handle to iterate over our authoritative zone in namestore |
125 | */ | 131 | */ |
126 | static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; | 132 | static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; |
@@ -231,6 +237,11 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
231 | GNUNET_NAMESTORE_disconnect (namestore_handle); | 237 | GNUNET_NAMESTORE_disconnect (namestore_handle); |
232 | namestore_handle = NULL; | 238 | namestore_handle = NULL; |
233 | } | 239 | } |
240 | if (NULL != namecache_handle) | ||
241 | { | ||
242 | GNUNET_NAMECACHE_disconnect (namecache_handle); | ||
243 | namecache_handle = NULL; | ||
244 | } | ||
234 | if (NULL != active_put) | 245 | if (NULL != active_put) |
235 | { | 246 | { |
236 | GNUNET_DHT_put_cancel (active_put); | 247 | GNUNET_DHT_put_cancel (active_put); |
@@ -645,6 +656,14 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
645 | GNUNET_SCHEDULER_shutdown (); | 656 | GNUNET_SCHEDULER_shutdown (); |
646 | return; | 657 | return; |
647 | } | 658 | } |
659 | namecache_handle = GNUNET_NAMECACHE_connect (c); | ||
660 | if (NULL == namecache_handle) | ||
661 | { | ||
662 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
663 | _("Failed to connect to the namecache!\n")); | ||
664 | GNUNET_SCHEDULER_shutdown (); | ||
665 | return; | ||
666 | } | ||
648 | 667 | ||
649 | put_interval = INITIAL_PUT_INTERVAL; | 668 | put_interval = INITIAL_PUT_INTERVAL; |
650 | zone_publish_time_window = DEFAULT_ZONE_PUBLISH_TIME_WINDOW; | 669 | zone_publish_time_window = DEFAULT_ZONE_PUBLISH_TIME_WINDOW; |
@@ -705,10 +724,14 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
705 | return; | 724 | return; |
706 | } | 725 | } |
707 | } | 726 | } |
708 | GNS_resolver_init (namestore_handle, dht_handle, | 727 | GNS_resolver_init (namestore_handle, |
728 | namecache_handle, | ||
729 | dht_handle, | ||
709 | c, | 730 | c, |
710 | max_parallel_bg_queries); | 731 | max_parallel_bg_queries); |
711 | GNS_shorten_init (namestore_handle, dht_handle); | 732 | GNS_shorten_init (namestore_handle, |
733 | namecache_handle, | ||
734 | dht_handle); | ||
712 | GNUNET_SERVER_disconnect_notify (server, | 735 | GNUNET_SERVER_disconnect_notify (server, |
713 | ¬ify_client_disconnect, | 736 | ¬ify_client_disconnect, |
714 | NULL); | 737 | NULL); |
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index e0d395a55..6ff2d8791 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include "gnunet_dnsstub_lib.h" | 35 | #include "gnunet_dnsstub_lib.h" |
36 | #include "gnunet_dht_service.h" | 36 | #include "gnunet_dht_service.h" |
37 | #include "gnunet_gnsrecord_lib.h" | 37 | #include "gnunet_gnsrecord_lib.h" |
38 | #include "gnunet_namecache_service.h" | ||
38 | #include "gnunet_namestore_service.h" | 39 | #include "gnunet_namestore_service.h" |
39 | #include "gnunet_dns_service.h" | 40 | #include "gnunet_dns_service.h" |
40 | #include "gnunet_resolver_service.h" | 41 | #include "gnunet_resolver_service.h" |
@@ -264,9 +265,9 @@ struct GNS_ResolverHandle | |||
264 | struct GNUNET_RESOLVER_RequestHandle *std_resolve; | 265 | struct GNUNET_RESOLVER_RequestHandle *std_resolve; |
265 | 266 | ||
266 | /** | 267 | /** |
267 | * Pending Namestore lookup task | 268 | * Pending Namecache lookup task |
268 | */ | 269 | */ |
269 | struct GNUNET_NAMESTORE_QueueEntry *namestore_qe; | 270 | struct GNUNET_NAMECACHE_QueueEntry *namecache_qe; |
270 | 271 | ||
271 | /** | 272 | /** |
272 | * Heap node associated with this lookup. Used to limit number of | 273 | * Heap node associated with this lookup. Used to limit number of |
@@ -353,7 +354,7 @@ struct CacheOps | |||
353 | /** | 354 | /** |
354 | * Pending Namestore caching task. | 355 | * Pending Namestore caching task. |
355 | */ | 356 | */ |
356 | struct GNUNET_NAMESTORE_QueueEntry *namestore_qe_cache; | 357 | struct GNUNET_NAMECACHE_QueueEntry *namecache_qe_cache; |
357 | 358 | ||
358 | }; | 359 | }; |
359 | 360 | ||
@@ -364,6 +365,11 @@ struct CacheOps | |||
364 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | 365 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; |
365 | 366 | ||
366 | /** | 367 | /** |
368 | * Our handle to the namecache service | ||
369 | */ | ||
370 | static struct GNUNET_NAMECACHE_Handle *namecache_handle; | ||
371 | |||
372 | /** | ||
367 | * Our handle to the vpn service | 373 | * Our handle to the vpn service |
368 | */ | 374 | */ |
369 | static struct GNUNET_VPN_Handle *vpn_handle; | 375 | static struct GNUNET_VPN_Handle *vpn_handle; |
@@ -1672,13 +1678,13 @@ handle_gns_resolution_result (void *cls, | |||
1672 | * @param emsg error message | 1678 | * @param emsg error message |
1673 | */ | 1679 | */ |
1674 | static void | 1680 | static void |
1675 | namestore_cache_continuation (void *cls, | 1681 | namecache_cache_continuation (void *cls, |
1676 | int32_t success, | 1682 | int32_t success, |
1677 | const char *emsg) | 1683 | const char *emsg) |
1678 | { | 1684 | { |
1679 | struct CacheOps *co = cls; | 1685 | struct CacheOps *co = cls; |
1680 | 1686 | ||
1681 | co->namestore_qe_cache = NULL; | 1687 | co->namecache_qe_cache = NULL; |
1682 | if (NULL != emsg) | 1688 | if (NULL != emsg) |
1683 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1689 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1684 | _("Failed to cache GNS resolution: %s\n"), | 1690 | _("Failed to cache GNS resolution: %s\n"), |
@@ -1765,9 +1771,9 @@ handle_dht_response (void *cls, | |||
1765 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1771 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1766 | "Caching response from the DHT in namestore\n"); | 1772 | "Caching response from the DHT in namestore\n"); |
1767 | co = GNUNET_new (struct CacheOps); | 1773 | co = GNUNET_new (struct CacheOps); |
1768 | co->namestore_qe_cache = GNUNET_NAMESTORE_block_cache (namestore_handle, | 1774 | co->namecache_qe_cache = GNUNET_NAMECACHE_block_cache (namecache_handle, |
1769 | block, | 1775 | block, |
1770 | &namestore_cache_continuation, | 1776 | &namecache_cache_continuation, |
1771 | co); | 1777 | co); |
1772 | GNUNET_CONTAINER_DLL_insert (co_head, | 1778 | GNUNET_CONTAINER_DLL_insert (co_head, |
1773 | co_tail, | 1779 | co_tail, |
@@ -1795,8 +1801,8 @@ handle_namestore_block_response (void *cls, | |||
1795 | GNUNET_GNSRECORD_query_from_public_key (auth, | 1801 | GNUNET_GNSRECORD_query_from_public_key (auth, |
1796 | label, | 1802 | label, |
1797 | &query); | 1803 | &query); |
1798 | GNUNET_assert (NULL != rh->namestore_qe); | 1804 | GNUNET_assert (NULL != rh->namecache_qe); |
1799 | rh->namestore_qe = NULL; | 1805 | rh->namecache_qe = NULL; |
1800 | if ( (GNUNET_NO == rh->only_cached) && | 1806 | if ( (GNUNET_NO == rh->only_cached) && |
1801 | ( (NULL == block) || | 1807 | ( (NULL == block) || |
1802 | (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) ) ) | 1808 | (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) ) ) |
@@ -1874,11 +1880,11 @@ recursive_gns_resolution_namestore (struct GNS_ResolverHandle *rh) | |||
1874 | GNUNET_GNSRECORD_query_from_public_key (&ac->authority_info.gns_authority, | 1880 | GNUNET_GNSRECORD_query_from_public_key (&ac->authority_info.gns_authority, |
1875 | ac->label, | 1881 | ac->label, |
1876 | &query); | 1882 | &query); |
1877 | rh->namestore_qe = GNUNET_NAMESTORE_lookup_block (namestore_handle, | 1883 | rh->namecache_qe = GNUNET_NAMECACHE_lookup_block (namecache_handle, |
1878 | &query, | 1884 | &query, |
1879 | &handle_namestore_block_response, | 1885 | &handle_namestore_block_response, |
1880 | rh); | 1886 | rh); |
1881 | GNUNET_assert (NULL != rh->namestore_qe); | 1887 | GNUNET_assert (NULL != rh->namecache_qe); |
1882 | } | 1888 | } |
1883 | 1889 | ||
1884 | 1890 | ||
@@ -2100,10 +2106,10 @@ GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh) | |||
2100 | GNUNET_DNSSTUB_resolve_cancel (rh->dns_request); | 2106 | GNUNET_DNSSTUB_resolve_cancel (rh->dns_request); |
2101 | rh->dns_request = NULL; | 2107 | rh->dns_request = NULL; |
2102 | } | 2108 | } |
2103 | if (NULL != rh->namestore_qe) | 2109 | if (NULL != rh->namecache_qe) |
2104 | { | 2110 | { |
2105 | GNUNET_NAMESTORE_cancel (rh->namestore_qe); | 2111 | GNUNET_NAMECACHE_cancel (rh->namecache_qe); |
2106 | rh->namestore_qe = NULL; | 2112 | rh->namecache_qe = NULL; |
2107 | } | 2113 | } |
2108 | if (NULL != rh->std_resolve) | 2114 | if (NULL != rh->std_resolve) |
2109 | { | 2115 | { |
@@ -2132,12 +2138,14 @@ GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh) | |||
2132 | * Initialize the resolver | 2138 | * Initialize the resolver |
2133 | * | 2139 | * |
2134 | * @param nh the namestore handle | 2140 | * @param nh the namestore handle |
2141 | * @param nc the namecache handle | ||
2135 | * @param dht the dht handle | 2142 | * @param dht the dht handle |
2136 | * @param c configuration handle | 2143 | * @param c configuration handle |
2137 | * @param max_bg_queries maximum number of parallel background queries in dht | 2144 | * @param max_bg_queries maximum number of parallel background queries in dht |
2138 | */ | 2145 | */ |
2139 | void | 2146 | void |
2140 | GNS_resolver_init (struct GNUNET_NAMESTORE_Handle *nh, | 2147 | GNS_resolver_init (struct GNUNET_NAMESTORE_Handle *nh, |
2148 | struct GNUNET_NAMECACHE_Handle *nc, | ||
2141 | struct GNUNET_DHT_Handle *dht, | 2149 | struct GNUNET_DHT_Handle *dht, |
2142 | const struct GNUNET_CONFIGURATION_Handle *c, | 2150 | const struct GNUNET_CONFIGURATION_Handle *c, |
2143 | unsigned long long max_bg_queries) | 2151 | unsigned long long max_bg_queries) |
@@ -2145,6 +2153,7 @@ GNS_resolver_init (struct GNUNET_NAMESTORE_Handle *nh, | |||
2145 | char *dns_ip; | 2153 | char *dns_ip; |
2146 | 2154 | ||
2147 | cfg = c; | 2155 | cfg = c; |
2156 | namecache_handle = nc; | ||
2148 | namestore_handle = nh; | 2157 | namestore_handle = nh; |
2149 | dht_handle = dht; | 2158 | dht_handle = dht; |
2150 | dht_lookup_heap = | 2159 | dht_lookup_heap = |
@@ -2185,7 +2194,7 @@ GNS_resolver_done () | |||
2185 | GNUNET_CONTAINER_DLL_remove (co_head, | 2194 | GNUNET_CONTAINER_DLL_remove (co_head, |
2186 | co_tail, | 2195 | co_tail, |
2187 | co); | 2196 | co); |
2188 | GNUNET_NAMESTORE_cancel (co->namestore_qe_cache); | 2197 | GNUNET_NAMECACHE_cancel (co->namecache_qe_cache); |
2189 | GNUNET_free (co); | 2198 | GNUNET_free (co); |
2190 | } | 2199 | } |
2191 | GNUNET_CONTAINER_heap_destroy (dht_lookup_heap); | 2200 | GNUNET_CONTAINER_heap_destroy (dht_lookup_heap); |
@@ -2195,6 +2204,7 @@ GNS_resolver_done () | |||
2195 | GNUNET_VPN_disconnect (vpn_handle); | 2204 | GNUNET_VPN_disconnect (vpn_handle); |
2196 | vpn_handle = NULL; | 2205 | vpn_handle = NULL; |
2197 | dht_handle = NULL; | 2206 | dht_handle = NULL; |
2207 | namecache_handle = NULL; | ||
2198 | namestore_handle = NULL; | 2208 | namestore_handle = NULL; |
2199 | } | 2209 | } |
2200 | 2210 | ||
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index 12d2eec11..7728c397d 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h | |||
@@ -26,19 +26,21 @@ | |||
26 | #define GNS_RESOLVER_H | 26 | #define GNS_RESOLVER_H |
27 | #include "gns.h" | 27 | #include "gns.h" |
28 | #include "gnunet_dht_service.h" | 28 | #include "gnunet_dht_service.h" |
29 | 29 | #include "gnunet_namecache_service.h" | |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * Initialize the resolver subsystem. | 32 | * Initialize the resolver subsystem. |
33 | * MUST be called before #GNS_resolver_lookup. | 33 | * MUST be called before #GNS_resolver_lookup. |
34 | * | 34 | * |
35 | * @param nh handle to the namestore | 35 | * @param nh handle to the namestore |
36 | * @param nc the namecache handle | ||
36 | * @param dht handle to the dht | 37 | * @param dht handle to the dht |
37 | * @param c configuration handle | 38 | * @param c configuration handle |
38 | * @param max_bg_queries maximum amount of background queries | 39 | * @param max_bg_queries maximum amount of background queries |
39 | */ | 40 | */ |
40 | void | 41 | void |
41 | GNS_resolver_init (struct GNUNET_NAMESTORE_Handle *nh, | 42 | GNS_resolver_init (struct GNUNET_NAMESTORE_Handle *nh, |
43 | struct GNUNET_NAMECACHE_Handle *nc, | ||
42 | struct GNUNET_DHT_Handle *dht, | 44 | struct GNUNET_DHT_Handle *dht, |
43 | const struct GNUNET_CONFIGURATION_Handle *c, | 45 | const struct GNUNET_CONFIGURATION_Handle *c, |
44 | unsigned long long max_bg_queries); | 46 | unsigned long long max_bg_queries); |
diff --git a/src/gns/gnunet-service-gns_shorten.c b/src/gns/gnunet-service-gns_shorten.c index 3e612e862..2f0bf9644 100644 --- a/src/gns/gnunet-service-gns_shorten.c +++ b/src/gns/gnunet-service-gns_shorten.c | |||
@@ -94,6 +94,11 @@ struct GetPseuAuthorityHandle | |||
94 | struct GNUNET_NAMESTORE_QueueEntry *namestore_task; | 94 | struct GNUNET_NAMESTORE_QueueEntry *namestore_task; |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * Handle to namecache request | ||
98 | */ | ||
99 | struct GNUNET_NAMECACHE_QueueEntry *namecache_task; | ||
100 | |||
101 | /** | ||
97 | * Task to abort DHT lookup operation. | 102 | * Task to abort DHT lookup operation. |
98 | */ | 103 | */ |
99 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; | 104 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; |
@@ -117,6 +122,11 @@ static struct GetPseuAuthorityHandle *gph_tail; | |||
117 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | 122 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; |
118 | 123 | ||
119 | /** | 124 | /** |
125 | * Our handle to the namecache service | ||
126 | */ | ||
127 | static struct GNUNET_NAMECACHE_Handle *namecache_handle; | ||
128 | |||
129 | /** | ||
120 | * Resolver handle to the dht | 130 | * Resolver handle to the dht |
121 | */ | 131 | */ |
122 | static struct GNUNET_DHT_Handle *dht_handle; | 132 | static struct GNUNET_DHT_Handle *dht_handle; |
@@ -140,6 +150,11 @@ free_get_pseu_authority_handle (struct GetPseuAuthorityHandle *gph) | |||
140 | GNUNET_NAMESTORE_cancel (gph->namestore_task); | 150 | GNUNET_NAMESTORE_cancel (gph->namestore_task); |
141 | gph->namestore_task = NULL; | 151 | gph->namestore_task = NULL; |
142 | } | 152 | } |
153 | if (NULL != gph->namecache_task) | ||
154 | { | ||
155 | GNUNET_NAMECACHE_cancel (gph->namecache_task); | ||
156 | gph->namecache_task = NULL; | ||
157 | } | ||
143 | if (GNUNET_SCHEDULER_NO_TASK != gph->timeout_task) | 158 | if (GNUNET_SCHEDULER_NO_TASK != gph->timeout_task) |
144 | { | 159 | { |
145 | GNUNET_SCHEDULER_cancel (gph->timeout_task); | 160 | GNUNET_SCHEDULER_cancel (gph->timeout_task); |
@@ -198,7 +213,7 @@ process_pseu_block_ns (void *cls, | |||
198 | struct GetPseuAuthorityHandle *gph = cls; | 213 | struct GetPseuAuthorityHandle *gph = cls; |
199 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 214 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
200 | 215 | ||
201 | gph->namestore_task = NULL; | 216 | gph->namecache_task = NULL; |
202 | if (NULL == block) | 217 | if (NULL == block) |
203 | { | 218 | { |
204 | process_pseu_lookup_ns (gph, 0, NULL); | 219 | process_pseu_lookup_ns (gph, 0, NULL); |
@@ -240,7 +255,7 @@ perform_pseu_lookup (struct GetPseuAuthorityHandle *gph, | |||
240 | GNUNET_GNSRECORD_query_from_public_key (&pub, | 255 | GNUNET_GNSRECORD_query_from_public_key (&pub, |
241 | label, | 256 | label, |
242 | &query); | 257 | &query); |
243 | gph->namestore_task = GNUNET_NAMESTORE_lookup_block (namestore_handle, | 258 | gph->namecache_task = GNUNET_NAMECACHE_lookup_block (namecache_handle, |
244 | &query, | 259 | &query, |
245 | &process_pseu_block_ns, | 260 | &process_pseu_block_ns, |
246 | gph); | 261 | gph); |
@@ -553,13 +568,16 @@ GNS_shorten_start (const char *original_label, | |||
553 | * Initialize the shortening subsystem | 568 | * Initialize the shortening subsystem |
554 | * | 569 | * |
555 | * @param nh the namestore handle | 570 | * @param nh the namestore handle |
571 | * @param nc the namecache handle | ||
556 | * @param dht the dht handle | 572 | * @param dht the dht handle |
557 | */ | 573 | */ |
558 | void | 574 | void |
559 | GNS_shorten_init (struct GNUNET_NAMESTORE_Handle *nh, | 575 | GNS_shorten_init (struct GNUNET_NAMESTORE_Handle *nh, |
576 | struct GNUNET_NAMECACHE_Handle *nc, | ||
560 | struct GNUNET_DHT_Handle *dht) | 577 | struct GNUNET_DHT_Handle *dht) |
561 | { | 578 | { |
562 | namestore_handle = nh; | 579 | namestore_handle = nh; |
580 | namecache_handle = nc; | ||
563 | dht_handle = dht; | 581 | dht_handle = dht; |
564 | } | 582 | } |
565 | 583 | ||
@@ -575,6 +593,7 @@ GNS_shorten_done () | |||
575 | free_get_pseu_authority_handle (gph_head); | 593 | free_get_pseu_authority_handle (gph_head); |
576 | dht_handle = NULL; | 594 | dht_handle = NULL; |
577 | namestore_handle = NULL; | 595 | namestore_handle = NULL; |
596 | namecache_handle = NULL; | ||
578 | } | 597 | } |
579 | 598 | ||
580 | /* end of gnunet-service-gns_shorten.c */ | 599 | /* end of gnunet-service-gns_shorten.c */ |
diff --git a/src/gns/gnunet-service-gns_shorten.h b/src/gns/gnunet-service-gns_shorten.h index 5f583eeb5..f99d465f9 100644 --- a/src/gns/gnunet-service-gns_shorten.h +++ b/src/gns/gnunet-service-gns_shorten.h | |||
@@ -26,6 +26,7 @@ | |||
26 | #define GNS_SHORTEN_H | 26 | #define GNS_SHORTEN_H |
27 | #include "gns.h" | 27 | #include "gns.h" |
28 | #include "gnunet_dht_service.h" | 28 | #include "gnunet_dht_service.h" |
29 | #include "gnunet_namecache_service.h" | ||
29 | #include "gnunet_namestore_service.h" | 30 | #include "gnunet_namestore_service.h" |
30 | 31 | ||
31 | 32 | ||
@@ -34,10 +35,12 @@ | |||
34 | * MUST be called before #GNS_shorten_start. | 35 | * MUST be called before #GNS_shorten_start. |
35 | * | 36 | * |
36 | * @param nh handle to the namestore | 37 | * @param nh handle to the namestore |
38 | * @param nc the namecache handle | ||
37 | * @param dht handle to the dht | 39 | * @param dht handle to the dht |
38 | */ | 40 | */ |
39 | void | 41 | void |
40 | GNS_shorten_init (struct GNUNET_NAMESTORE_Handle *nh, | 42 | GNS_shorten_init (struct GNUNET_NAMESTORE_Handle *nh, |
43 | struct GNUNET_NAMECACHE_Handle *nc, | ||
41 | struct GNUNET_DHT_Handle *dht); | 44 | struct GNUNET_DHT_Handle *dht); |
42 | 45 | ||
43 | 46 | ||
diff --git a/src/include/gnunet_namestore_plugin.h b/src/include/gnunet_namestore_plugin.h index 037c6927a..5c3298d98 100644 --- a/src/include/gnunet_namestore_plugin.h +++ b/src/include/gnunet_namestore_plugin.h | |||
@@ -39,16 +39,6 @@ extern "C" | |||
39 | 39 | ||
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Function called for matching blocks. | ||
43 | * | ||
44 | * @param cls closure | ||
45 | * @param block lookup result | ||
46 | */ | ||
47 | typedef void (*GNUNET_GNSRECORD_BlockCallback) (void *cls, | ||
48 | const struct GNUNET_GNSRECORD_Block *block); | ||
49 | |||
50 | |||
51 | /** | ||
52 | * Function called by for each matching record. | 42 | * Function called by for each matching record. |
53 | * | 43 | * |
54 | * @param cls closure | 44 | * @param cls closure |
@@ -76,34 +66,6 @@ struct GNUNET_NAMESTORE_PluginFunctions | |||
76 | void *cls; | 66 | void *cls; |
77 | 67 | ||
78 | /** | 68 | /** |
79 | * Cache a block in the datastore. Overwrites existing blocks | ||
80 | * for the same zone and label. | ||
81 | * | ||
82 | * @param cls closure (internal context for the plugin) | ||
83 | * @param block block to cache | ||
84 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
85 | */ | ||
86 | int (*cache_block) (void *cls, | ||
87 | const struct GNUNET_GNSRECORD_Block *block); | ||
88 | |||
89 | |||
90 | /** | ||
91 | * Get the block for a particular zone and label in the | ||
92 | * datastore. Will return at most one result to the iterator. | ||
93 | * | ||
94 | * @param cls closure (internal context for the plugin) | ||
95 | * @param query hash of public key derived from the zone and the label | ||
96 | * @param iter function to call with the result | ||
97 | * @param iter_cls closure for @a iter | ||
98 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | ||
99 | */ | ||
100 | int (*lookup_block) (void *cls, | ||
101 | const struct GNUNET_HashCode *query, | ||
102 | GNUNET_GNSRECORD_BlockCallback iter, void *iter_cls); | ||
103 | |||
104 | |||
105 | |||
106 | /** | ||
107 | * Store a record in the datastore for which we are the authority. | 69 | * Store a record in the datastore for which we are the authority. |
108 | * Removes any existing record in the same zone with the same name. | 70 | * Removes any existing record in the same zone with the same name. |
109 | * | 71 | * |
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index b37cecf50..36e912f51 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h | |||
@@ -96,23 +96,6 @@ typedef void (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls, | |||
96 | 96 | ||
97 | /** | 97 | /** |
98 | * Store an item in the namestore. If the item is already present, | 98 | * Store an item in the namestore. If the item is already present, |
99 | * it is replaced with the new record. | ||
100 | * | ||
101 | * @param h handle to the namestore | ||
102 | * @param block block to store | ||
103 | * @param cont continuation to call when done | ||
104 | * @param cont_cls closure for @a cont | ||
105 | * @return handle to abort the request | ||
106 | */ | ||
107 | struct GNUNET_NAMESTORE_QueueEntry * | ||
108 | GNUNET_NAMESTORE_block_cache (struct GNUNET_NAMESTORE_Handle *h, | ||
109 | const struct GNUNET_GNSRECORD_Block *block, | ||
110 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | ||
111 | void *cont_cls); | ||
112 | |||
113 | |||
114 | /** | ||
115 | * Store an item in the namestore. If the item is already present, | ||
116 | * it is replaced with the new record. Use an empty array to | 99 | * it is replaced with the new record. Use an empty array to |
117 | * remove all records under the given name. | 100 | * remove all records under the given name. |
118 | * | 101 | * |
@@ -135,33 +118,6 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
135 | void *cont_cls); | 118 | void *cont_cls); |
136 | 119 | ||
137 | 120 | ||
138 | /** | ||
139 | * Process a record that was stored in the namestore. | ||
140 | * | ||
141 | * @param cls closure | ||
142 | * @param block block that was stored in the namestore | ||
143 | */ | ||
144 | typedef void (*GNUNET_GNSRECORD_BlockProcessor) (void *cls, | ||
145 | const struct GNUNET_GNSRECORD_Block *block); | ||
146 | |||
147 | |||
148 | /** | ||
149 | * Get a result for a particular key from the namestore. The processor | ||
150 | * will only be called once. | ||
151 | * | ||
152 | * @param h handle to the namestore | ||
153 | * @param derived_hash hash of zone key combined with name to lookup | ||
154 | * then at the end once with NULL | ||
155 | * @param proc function to call on the matching block, or with | ||
156 | * NULL if there is no matching block | ||
157 | * @param proc_cls closure for @a proc | ||
158 | * @return a handle that can be used to cancel | ||
159 | */ | ||
160 | struct GNUNET_NAMESTORE_QueueEntry * | ||
161 | GNUNET_NAMESTORE_lookup_block (struct GNUNET_NAMESTORE_Handle *h, | ||
162 | const struct GNUNET_HashCode *derived_hash, | ||
163 | GNUNET_GNSRECORD_BlockProcessor proc, void *proc_cls); | ||
164 | |||
165 | 121 | ||
166 | /** | 122 | /** |
167 | * Process a record that was stored in the namestore. | 123 | * Process a record that was stored in the namestore. |
@@ -223,7 +179,7 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe); | |||
223 | * @param zone zone to access, NULL for all zones | 179 | * @param zone zone to access, NULL for all zones |
224 | * @param proc function to call on each name from the zone; it | 180 | * @param proc function to call on each name from the zone; it |
225 | * will be called repeatedly with a value (if available) | 181 | * will be called repeatedly with a value (if available) |
226 | * and always once at the end with a name of NULL. | 182 | * and always once at the end with a label of NULL. |
227 | * @param proc_cls closure for @a proc | 183 | * @param proc_cls closure for @a proc |
228 | * @return an iterator handle to use for iteration | 184 | * @return an iterator handle to use for iteration |
229 | */ | 185 | */ |
diff --git a/src/namecache/namecache.conf.in b/src/namecache/namecache.conf.in index 7464a9a9f..8bb0627dd 100644 --- a/src/namecache/namecache.conf.in +++ b/src/namecache/namecache.conf.in | |||
@@ -4,7 +4,7 @@ USER_SERVICE = YES | |||
4 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-namecache.sock | 4 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-namecache.sock |
5 | UNIX_MATCH_UID = NO | 5 | UNIX_MATCH_UID = NO |
6 | UNIX_MATCH_GID = YES | 6 | UNIX_MATCH_GID = YES |
7 | @UNIXONLY@ PORT = 2099 | 7 | @UNIXONLY@ PORT = 2113 |
8 | HOSTNAME = localhost | 8 | HOSTNAME = localhost |
9 | BINARY = gnunet-service-namecache | 9 | BINARY = gnunet-service-namecache |
10 | ACCEPT_FROM = 127.0.0.1; | 10 | ACCEPT_FROM = 127.0.0.1; |
diff --git a/src/namecache/namecache_api.c b/src/namecache/namecache_api.c index 942272b99..f3e78061d 100644 --- a/src/namecache/namecache_api.c +++ b/src/namecache/namecache_api.c | |||
@@ -31,7 +31,7 @@ | |||
31 | #include "gnunet_crypto_lib.h" | 31 | #include "gnunet_crypto_lib.h" |
32 | #include "gnunet_constants.h" | 32 | #include "gnunet_constants.h" |
33 | #include "gnunet_dnsparser_lib.h" | 33 | #include "gnunet_dnsparser_lib.h" |
34 | #include "gnunet_arm_service.h" | 34 | #include "gnunet_gnsrecord_lib.h" |
35 | #include "gnunet_signatures.h" | 35 | #include "gnunet_signatures.h" |
36 | #include "gnunet_namecache_service.h" | 36 | #include "gnunet_namecache_service.h" |
37 | #include "gnunet_namestore_service.h" | 37 | #include "gnunet_namestore_service.h" |
@@ -76,7 +76,7 @@ struct GNUNET_NAMECACHE_QueueEntry | |||
76 | /** | 76 | /** |
77 | * Function to call with the blocks we get back; or NULL. | 77 | * Function to call with the blocks we get back; or NULL. |
78 | */ | 78 | */ |
79 | GNUNET_GNSRECORD_BlockProcessor block_proc; | 79 | GNUNET_NAMECACHE_BlockProcessor block_proc; |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * Closure for @e block_proc. | 82 | * Closure for @e block_proc. |
@@ -683,7 +683,7 @@ GNUNET_NAMECACHE_block_cache (struct GNUNET_NAMECACHE_Handle *h, | |||
683 | struct GNUNET_NAMECACHE_QueueEntry * | 683 | struct GNUNET_NAMECACHE_QueueEntry * |
684 | GNUNET_NAMECACHE_lookup_block (struct GNUNET_NAMECACHE_Handle *h, | 684 | GNUNET_NAMECACHE_lookup_block (struct GNUNET_NAMECACHE_Handle *h, |
685 | const struct GNUNET_HashCode *derived_hash, | 685 | const struct GNUNET_HashCode *derived_hash, |
686 | GNUNET_GNSRECORD_BlockProcessor proc, void *proc_cls) | 686 | GNUNET_NAMECACHE_BlockProcessor proc, void *proc_cls) |
687 | { | 687 | { |
688 | struct GNUNET_NAMECACHE_QueueEntry *qe; | 688 | struct GNUNET_NAMECACHE_QueueEntry *qe; |
689 | struct PendingMessage *pe; | 689 | struct PendingMessage *pe; |
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index 11e23a790..52000014b 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -39,7 +39,6 @@ if HAVE_TESTING | |||
39 | TESTING_TESTS = \ | 39 | TESTING_TESTS = \ |
40 | test_namestore_api_store \ | 40 | test_namestore_api_store \ |
41 | test_namestore_api_store_update \ | 41 | test_namestore_api_store_update \ |
42 | test_namestore_api_cache_block \ | ||
43 | test_namestore_api_lookup_public \ | 42 | test_namestore_api_lookup_public \ |
44 | test_namestore_api_remove \ | 43 | test_namestore_api_remove \ |
45 | test_namestore_api_remove_not_existing_record \ | 44 | test_namestore_api_remove_not_existing_record \ |
@@ -123,6 +122,7 @@ gnunet_service_namestore_SOURCES = \ | |||
123 | gnunet-service-namestore.c | 122 | gnunet-service-namestore.c |
124 | 123 | ||
125 | gnunet_service_namestore_LDADD = \ | 124 | gnunet_service_namestore_LDADD = \ |
125 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ | ||
126 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 126 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
127 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 127 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
128 | $(top_builddir)/src/util/libgnunetutil.la \ | 128 | $(top_builddir)/src/util/libgnunetutil.la \ |
@@ -183,14 +183,7 @@ test_namestore_api_store_update_LDADD = \ | |||
183 | $(top_builddir)/src/testing/libgnunettesting.la \ | 183 | $(top_builddir)/src/testing/libgnunettesting.la \ |
184 | $(top_builddir)/src/util/libgnunetutil.la \ | 184 | $(top_builddir)/src/util/libgnunetutil.la \ |
185 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 185 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
186 | $(top_builddir)/src/namestore/libgnunetnamestore.la | 186 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ |
187 | |||
188 | test_namestore_api_cache_block_SOURCES = \ | ||
189 | test_namestore_api_cache_block.c | ||
190 | test_namestore_api_cache_block_LDADD = \ | ||
191 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
192 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
193 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
194 | $(top_builddir)/src/namestore/libgnunetnamestore.la | 187 | $(top_builddir)/src/namestore/libgnunetnamestore.la |
195 | 188 | ||
196 | test_namestore_api_lookup_public_SOURCES = \ | 189 | test_namestore_api_lookup_public_SOURCES = \ |
@@ -199,6 +192,7 @@ test_namestore_api_lookup_public_LDADD = \ | |||
199 | $(top_builddir)/src/testing/libgnunettesting.la \ | 192 | $(top_builddir)/src/testing/libgnunettesting.la \ |
200 | $(top_builddir)/src/util/libgnunetutil.la \ | 193 | $(top_builddir)/src/util/libgnunetutil.la \ |
201 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 194 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
195 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ | ||
202 | $(top_builddir)/src/namestore/libgnunetnamestore.la | 196 | $(top_builddir)/src/namestore/libgnunetnamestore.la |
203 | 197 | ||
204 | test_namestore_api_put_SOURCES = \ | 198 | test_namestore_api_put_SOURCES = \ |
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c index 198d0a9dc..4feb7fc05 100644 --- a/src/namestore/gnunet-namestore-fcfsd.c +++ b/src/namestore/gnunet-namestore-fcfsd.c | |||
@@ -132,6 +132,11 @@ struct Request | |||
132 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 132 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * Active iteration with the namestore. | ||
136 | */ | ||
137 | struct GNUNET_NAMESTORE_ZoneIterator *zi; | ||
138 | |||
139 | /** | ||
135 | * Current processing phase. | 140 | * Current processing phase. |
136 | */ | 141 | */ |
137 | enum Phase phase; | 142 | enum Phase phase; |
@@ -460,16 +465,14 @@ post_iterator (void *cls, | |||
460 | } | 465 | } |
461 | 466 | ||
462 | 467 | ||
463 | |||
464 | |||
465 | /** | 468 | /** |
466 | * Continuation called to notify client about result of the | 469 | * Continuation called to notify client about result of the |
467 | * operation. | 470 | * operation. |
468 | * | 471 | * |
469 | * @param cls closure | 472 | * @param cls closure |
470 | * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) | 473 | * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) |
471 | * GNUNET_NO if content was already there | 474 | * #GNUNET_NO if content was already there |
472 | * GNUNET_YES (or other positive value) on success | 475 | * #GNUNET_YES (or other positive value) on success |
473 | * @param emsg NULL on success, otherwise an error message | 476 | * @param emsg NULL on success, otherwise an error message |
474 | */ | 477 | */ |
475 | static void | 478 | static void |
@@ -500,7 +503,7 @@ put_continuation (void *cls, | |||
500 | * @param cls closure | 503 | * @param cls closure |
501 | * @param zone_key public key of the zone | 504 | * @param zone_key public key of the zone |
502 | * @param name name that is being mapped (at most 255 characters long) | 505 | * @param name name that is being mapped (at most 255 characters long) |
503 | * @param rd_count number of entries in 'rd' array | 506 | * @param rd_count number of entries in @a rd array |
504 | * @param rd array of records with data to store | 507 | * @param rd array of records with data to store |
505 | */ | 508 | */ |
506 | static void | 509 | static void |
@@ -541,84 +544,62 @@ zone_to_name_cb (void *cls, | |||
541 | 544 | ||
542 | 545 | ||
543 | /** | 546 | /** |
544 | * Process a record that was stored in the namestore. Used to check if | ||
545 | * the requested name already exists in the namestore. If not, | ||
546 | * proceed to check if the requested key already exists. | ||
547 | * | ||
548 | * @param cls closure | ||
549 | * @param rd_count number of entries in 'rd' array | ||
550 | * @param rd array of records with data to store | ||
551 | */ | ||
552 | static void | ||
553 | lookup_result_processor (void *cls, | ||
554 | unsigned int rd_count, | ||
555 | const struct GNUNET_GNSRECORD_Data *rd) | ||
556 | { | ||
557 | struct Request *request = cls; | ||
558 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | ||
559 | |||
560 | if (0 != rd_count) | ||
561 | { | ||
562 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
563 | _("Found %u existing records for domain `%s'\n"), | ||
564 | rd_count, | ||
565 | request->domain_name); | ||
566 | request->phase = RP_FAIL; | ||
567 | run_httpd_now (); | ||
568 | return; | ||
569 | } | ||
570 | if (GNUNET_OK != | ||
571 | GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, | ||
572 | strlen (request->public_key), | ||
573 | &pub)) | ||
574 | { | ||
575 | GNUNET_break (0); | ||
576 | request->phase = RP_FAIL; | ||
577 | run_httpd_now (); | ||
578 | return; | ||
579 | } | ||
580 | request->qe = GNUNET_NAMESTORE_zone_to_name (ns, | ||
581 | &fcfs_zone_pkey, | ||
582 | &pub, | ||
583 | &zone_to_name_cb, | ||
584 | request); | ||
585 | } | ||
586 | |||
587 | |||
588 | /** | ||
589 | * We got a block back from the namestore. Decrypt it | 547 | * We got a block back from the namestore. Decrypt it |
590 | * and continue to process the result. | 548 | * and continue to process the result. |
591 | * | 549 | * |
592 | * @param cls the 'struct Request' we are processing | 550 | * @param cls the 'struct Request' we are processing |
593 | * @param block block returned form namestore, NULL on error | 551 | * @param zone private key of the zone; NULL on disconnect |
552 | * @param label label of the records; NULL on disconnect | ||
553 | * @param rd_count number of entries in @a rd array, 0 if label was deleted | ||
554 | * @param rd array of records with data to store | ||
594 | */ | 555 | */ |
595 | static void | 556 | static void |
596 | lookup_block_processor (void *cls, | 557 | lookup_block_processor (void *cls, |
597 | const struct GNUNET_GNSRECORD_Block *block) | 558 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
559 | const char *label, | ||
560 | unsigned int rd_count, | ||
561 | const struct GNUNET_GNSRECORD_Data *rd) | ||
598 | { | 562 | { |
599 | struct Request *request = cls; | 563 | struct Request *request = cls; |
600 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 564 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
601 | 565 | ||
602 | request->qe = NULL; | 566 | request->qe = NULL; |
603 | if (NULL == block) | 567 | if (NULL == label) |
604 | { | 568 | { |
605 | lookup_result_processor (request, 0, NULL); | 569 | request->zi = NULL; |
570 | if (GNUNET_OK != | ||
571 | GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, | ||
572 | strlen (request->public_key), | ||
573 | &pub)) | ||
574 | { | ||
575 | GNUNET_break (0); | ||
576 | request->phase = RP_FAIL; | ||
577 | run_httpd_now (); | ||
578 | return; | ||
579 | } | ||
580 | request->qe = GNUNET_NAMESTORE_zone_to_name (ns, | ||
581 | &fcfs_zone_pkey, | ||
582 | &pub, | ||
583 | &zone_to_name_cb, | ||
584 | request); | ||
606 | return; | 585 | return; |
607 | } | 586 | } |
608 | GNUNET_CRYPTO_ecdsa_key_get_public (&fcfs_zone_pkey, | 587 | if (0 != strcmp (label, |
609 | &pub); | 588 | request->domain_name)) |
610 | if (GNUNET_OK != | ||
611 | GNUNET_GNSRECORD_block_decrypt (block, | ||
612 | &pub, | ||
613 | request->domain_name, | ||
614 | &lookup_result_processor, | ||
615 | request)) | ||
616 | { | 589 | { |
617 | GNUNET_break (0); | 590 | GNUNET_NAMESTORE_zone_iterator_next (request->zi); |
618 | request->phase = RP_FAIL; | ||
619 | run_httpd_now (); | ||
620 | return; | 591 | return; |
621 | } | 592 | } |
593 | GNUNET_NAMESTORE_zone_iteration_stop (request->zi); | ||
594 | request->zi = NULL; | ||
595 | GNUNET_break (0 != rd_count); | ||
596 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
597 | _("Found %u existing records for domain `%s'\n"), | ||
598 | rd_count, | ||
599 | request->domain_name); | ||
600 | request->phase = RP_FAIL; | ||
601 | run_httpd_now (); | ||
602 | return; | ||
622 | } | 603 | } |
623 | 604 | ||
624 | 605 | ||
@@ -638,7 +619,7 @@ lookup_block_processor (void *cls, | |||
638 | * data *will* be made available incrementally in | 619 | * data *will* be made available incrementally in |
639 | * upload_data) | 620 | * upload_data) |
640 | * @param upload_data_size set initially to the size of the | 621 | * @param upload_data_size set initially to the size of the |
641 | * upload_data provided; the method must update this | 622 | * @a upload_data provided; the method must update this |
642 | * value to the number of bytes NOT processed; | 623 | * value to the number of bytes NOT processed; |
643 | * @param ptr pointer to location where we store the 'struct Request' | 624 | * @param ptr pointer to location where we store the 'struct Request' |
644 | * @return MHD_YES if the connection was handled successfully, | 625 | * @return MHD_YES if the connection was handled successfully, |
@@ -657,9 +638,8 @@ create_response (void *cls, | |||
657 | { | 638 | { |
658 | struct MHD_Response *response; | 639 | struct MHD_Response *response; |
659 | struct Request *request; | 640 | struct Request *request; |
660 | int ret; | ||
661 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 641 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
662 | struct GNUNET_HashCode query; | 642 | int ret; |
663 | 643 | ||
664 | if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) || | 644 | if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) || |
665 | (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) ) | 645 | (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) ) |
@@ -709,8 +689,8 @@ create_response (void *cls, | |||
709 | } | 689 | } |
710 | if (GNUNET_OK != | 690 | if (GNUNET_OK != |
711 | GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, | 691 | GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, |
712 | strlen (request->public_key), | 692 | strlen (request->public_key), |
713 | &pub)) | 693 | &pub)) |
714 | { | 694 | { |
715 | /* parse error */ | 695 | /* parse error */ |
716 | return fill_s_reply ("Failed to parse given public key", | 696 | return fill_s_reply ("Failed to parse given public key", |
@@ -736,15 +716,11 @@ create_response (void *cls, | |||
736 | request, connection); | 716 | request, connection); |
737 | } | 717 | } |
738 | request->phase = RP_LOOKUP; | 718 | request->phase = RP_LOOKUP; |
739 | GNUNET_CRYPTO_ecdsa_key_get_public (&fcfs_zone_pkey, | 719 | /* FIXME: would be nice to have a more efficient API for this */ |
740 | &pub); | 720 | request->zi = GNUNET_NAMESTORE_zone_iteration_start (ns, |
741 | GNUNET_GNSRECORD_query_from_public_key (&pub, | 721 | &fcfs_zone_pkey, |
742 | request->domain_name, | 722 | &lookup_block_processor, |
743 | &query); | 723 | request); |
744 | request->qe = GNUNET_NAMESTORE_lookup_block (ns, | ||
745 | &query, | ||
746 | &lookup_block_processor, | ||
747 | request); | ||
748 | break; | 724 | break; |
749 | case RP_LOOKUP: | 725 | case RP_LOOKUP: |
750 | break; | 726 | break; |
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 45e721b89..3fa20a5e6 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -75,11 +75,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *add_qe_uri; | |||
75 | static struct GNUNET_NAMESTORE_QueueEntry *add_qe; | 75 | static struct GNUNET_NAMESTORE_QueueEntry *add_qe; |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Queue entry for the 'list' operation (in combination with a name). | ||
79 | */ | ||
80 | static struct GNUNET_NAMESTORE_QueueEntry *list_qe; | ||
81 | |||
82 | /** | ||
83 | * Queue entry for the 'reverse lookup' operation (in combination with a name). | 78 | * Queue entry for the 'reverse lookup' operation (in combination with a name). |
84 | */ | 79 | */ |
85 | static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe; | 80 | static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe; |
@@ -215,11 +210,6 @@ do_shutdown (void *cls, | |||
215 | GNUNET_NAMESTORE_cancel (add_qe); | 210 | GNUNET_NAMESTORE_cancel (add_qe); |
216 | add_qe = NULL; | 211 | add_qe = NULL; |
217 | } | 212 | } |
218 | if (NULL != list_qe) | ||
219 | { | ||
220 | GNUNET_NAMESTORE_cancel (list_qe); | ||
221 | list_qe = NULL; | ||
222 | } | ||
223 | if (NULL != add_qe_uri) | 213 | if (NULL != add_qe_uri) |
224 | { | 214 | { |
225 | GNUNET_NAMESTORE_cancel (add_qe_uri); | 215 | GNUNET_NAMESTORE_cancel (add_qe_uri); |
@@ -261,7 +251,6 @@ static void | |||
261 | test_finished () | 251 | test_finished () |
262 | { | 252 | { |
263 | if ( (NULL == add_qe) && | 253 | if ( (NULL == add_qe) && |
264 | (NULL == list_qe) && | ||
265 | (NULL == add_qe_uri) && | 254 | (NULL == add_qe_uri) && |
266 | (NULL == del_qe) && | 255 | (NULL == del_qe) && |
267 | (NULL == reverse_qe) && | 256 | (NULL == reverse_qe) && |
@@ -329,14 +318,14 @@ del_continuation (void *cls, | |||
329 | * | 318 | * |
330 | * @param cls closure | 319 | * @param cls closure |
331 | * @param zone_key private key of the zone | 320 | * @param zone_key private key of the zone |
332 | * @param name name that is being mapped (at most 255 characters long) | 321 | * @param rname name that is being mapped (at most 255 characters long) |
333 | * @param rd_len number of entries in @a rd array | 322 | * @param rd_len number of entries in @a rd array |
334 | * @param rd array of records with data to store | 323 | * @param rd array of records with data to store |
335 | */ | 324 | */ |
336 | static void | 325 | static void |
337 | display_record (void *cls, | 326 | display_record (void *cls, |
338 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 327 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
339 | const char *name, | 328 | const char *rname, |
340 | unsigned int rd_len, | 329 | unsigned int rd_len, |
341 | const struct GNUNET_GNSRECORD_Data *rd) | 330 | const struct GNUNET_GNSRECORD_Data *rd) |
342 | { | 331 | { |
@@ -347,15 +336,21 @@ display_record (void *cls, | |||
347 | struct GNUNET_TIME_Absolute at; | 336 | struct GNUNET_TIME_Absolute at; |
348 | struct GNUNET_TIME_Relative rt; | 337 | struct GNUNET_TIME_Relative rt; |
349 | 338 | ||
350 | if (NULL == name) | 339 | if (NULL == rname) |
351 | { | 340 | { |
352 | list_it = NULL; | 341 | list_it = NULL; |
353 | test_finished (); | 342 | test_finished (); |
354 | return; | 343 | return; |
355 | } | 344 | } |
345 | if ( (NULL != name) && | ||
346 | (0 != strcmp (name, rname)) ) | ||
347 | { | ||
348 | GNUNET_NAMESTORE_zone_iterator_next (list_it); | ||
349 | return; | ||
350 | } | ||
356 | FPRINTF (stdout, | 351 | FPRINTF (stdout, |
357 | "%s:\n", | 352 | "%s:\n", |
358 | name); | 353 | rname); |
359 | for (i=0;i<rd_len;i++) | 354 | for (i=0;i<rd_len;i++) |
360 | { | 355 | { |
361 | typestring = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); | 356 | typestring = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); |
@@ -466,89 +461,6 @@ get_existing_record (void *cls, | |||
466 | } | 461 | } |
467 | 462 | ||
468 | 463 | ||
469 | |||
470 | /** | ||
471 | * Process a record that was stored in the namestore in a block. | ||
472 | * | ||
473 | * @param cls closure, NULL | ||
474 | * @param rd_len number of entries in @a rd array | ||
475 | * @param rd array of records with data to store | ||
476 | */ | ||
477 | static void | ||
478 | display_records_from_block (void *cls, | ||
479 | unsigned int rd_len, | ||
480 | const struct GNUNET_GNSRECORD_Data *rd) | ||
481 | { | ||
482 | const char *typestring; | ||
483 | char *s; | ||
484 | unsigned int i; | ||
485 | |||
486 | if (0 == rd_len) | ||
487 | { | ||
488 | FPRINTF (stdout, | ||
489 | _("No records found for `%s'"), | ||
490 | name); | ||
491 | return; | ||
492 | } | ||
493 | FPRINTF (stdout, | ||
494 | "%s:\n", | ||
495 | name); | ||
496 | for (i=0;i<rd_len;i++) | ||
497 | { | ||
498 | typestring = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); | ||
499 | s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | ||
500 | rd[i].data, | ||
501 | rd[i].data_size); | ||
502 | if (NULL == s) | ||
503 | { | ||
504 | FPRINTF (stdout, _("\tCorrupt or unsupported record of type %u\n"), | ||
505 | (unsigned int) rd[i].record_type); | ||
506 | continue; | ||
507 | } | ||
508 | FPRINTF (stdout, | ||
509 | "\t%s: %s\n", | ||
510 | typestring, | ||
511 | s); | ||
512 | GNUNET_free (s); | ||
513 | } | ||
514 | FPRINTF (stdout, "%s", "\n"); | ||
515 | } | ||
516 | |||
517 | |||
518 | /** | ||
519 | * Display block obtained from listing (by name). | ||
520 | * | ||
521 | * @param cls NULL | ||
522 | * @param block NULL if not found | ||
523 | */ | ||
524 | static void | ||
525 | handle_block (void *cls, | ||
526 | const struct GNUNET_GNSRECORD_Block *block) | ||
527 | { | ||
528 | struct GNUNET_CRYPTO_EcdsaPublicKey zone_pubkey; | ||
529 | |||
530 | list_qe = NULL; | ||
531 | GNUNET_CRYPTO_ecdsa_key_get_public (&zone_pkey, | ||
532 | &zone_pubkey); | ||
533 | if (NULL == block) | ||
534 | { | ||
535 | fprintf (stderr, | ||
536 | "No matching block found\n"); | ||
537 | } | ||
538 | else if (GNUNET_OK != | ||
539 | GNUNET_GNSRECORD_block_decrypt (block, | ||
540 | &zone_pubkey, | ||
541 | name, | ||
542 | &display_records_from_block, | ||
543 | NULL)) | ||
544 | { | ||
545 | fprintf (stderr, | ||
546 | "Failed to decrypt block!\n"); | ||
547 | } | ||
548 | test_finished (); | ||
549 | } | ||
550 | |||
551 | |||
552 | /** | 464 | /** |
553 | * Function called with the result of our attempt to obtain a name for a given | 465 | * Function called with the result of our attempt to obtain a name for a given |
554 | * public key. | 466 | * public key. |
@@ -729,28 +641,10 @@ testservice_task (void *cls, | |||
729 | } | 641 | } |
730 | if (list) | 642 | if (list) |
731 | { | 643 | { |
732 | if (NULL == name) | 644 | list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, |
733 | { | 645 | &zone_pkey, |
734 | list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | 646 | &display_record, |
735 | &zone_pkey, | 647 | NULL); |
736 | &display_record, | ||
737 | NULL); | ||
738 | } | ||
739 | else | ||
740 | { | ||
741 | struct GNUNET_HashCode query; | ||
742 | struct GNUNET_CRYPTO_EcdsaPublicKey zone_pubkey; | ||
743 | |||
744 | GNUNET_CRYPTO_ecdsa_key_get_public (&zone_pkey, | ||
745 | &zone_pubkey); | ||
746 | GNUNET_GNSRECORD_query_from_public_key (&zone_pubkey, | ||
747 | name, | ||
748 | &query); | ||
749 | list_qe = GNUNET_NAMESTORE_lookup_block (ns, | ||
750 | &query, | ||
751 | &handle_block, | ||
752 | NULL); | ||
753 | } | ||
754 | } | 648 | } |
755 | if (NULL != reverse_pkey) | 649 | if (NULL != reverse_pkey) |
756 | { | 650 | { |
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 869be75d5..40a7ac790 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_dnsparser_lib.h" | 29 | #include "gnunet_dnsparser_lib.h" |
30 | #include "gnunet_namecache_service.h" | ||
30 | #include "gnunet_namestore_service.h" | 31 | #include "gnunet_namestore_service.h" |
31 | #include "gnunet_namestore_plugin.h" | 32 | #include "gnunet_namestore_plugin.h" |
32 | #include "gnunet_signatures.h" | 33 | #include "gnunet_signatures.h" |
@@ -165,11 +166,49 @@ struct ZoneMonitor | |||
165 | 166 | ||
166 | 167 | ||
167 | /** | 168 | /** |
169 | * Pending operation on the namecache. | ||
170 | */ | ||
171 | struct CacheOperation | ||
172 | { | ||
173 | |||
174 | /** | ||
175 | * Kept in a DLL. | ||
176 | */ | ||
177 | struct CacheOperation *prev; | ||
178 | |||
179 | /** | ||
180 | * Kept in a DLL. | ||
181 | */ | ||
182 | struct CacheOperation *next; | ||
183 | |||
184 | /** | ||
185 | * Handle to namecache queue. | ||
186 | */ | ||
187 | struct GNUNET_NAMECACHE_QueueEntry *qe; | ||
188 | |||
189 | /** | ||
190 | * Client to notify about the result. | ||
191 | */ | ||
192 | struct GNUNET_SERVER_Client *client; | ||
193 | |||
194 | /** | ||
195 | * Client's request ID. | ||
196 | */ | ||
197 | uint32_t rid; | ||
198 | }; | ||
199 | |||
200 | |||
201 | /** | ||
168 | * Configuration handle. | 202 | * Configuration handle. |
169 | */ | 203 | */ |
170 | static const struct GNUNET_CONFIGURATION_Handle *GSN_cfg; | 204 | static const struct GNUNET_CONFIGURATION_Handle *GSN_cfg; |
171 | 205 | ||
172 | /** | 206 | /** |
207 | * Namecache handle. | ||
208 | */ | ||
209 | static struct GNUNET_NAMECACHE_Handle *namecache; | ||
210 | |||
211 | /** | ||
173 | * Database handle | 212 | * Database handle |
174 | */ | 213 | */ |
175 | static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database; | 214 | static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database; |
@@ -195,6 +234,16 @@ static struct NamestoreClient *client_head; | |||
195 | static struct NamestoreClient *client_tail; | 234 | static struct NamestoreClient *client_tail; |
196 | 235 | ||
197 | /** | 236 | /** |
237 | * Head of cop DLL. | ||
238 | */ | ||
239 | static struct CacheOperation *cop_head; | ||
240 | |||
241 | /** | ||
242 | * Tail of cop DLL. | ||
243 | */ | ||
244 | static struct CacheOperation *cop_tail; | ||
245 | |||
246 | /** | ||
198 | * First active zone monitor. | 247 | * First active zone monitor. |
199 | */ | 248 | */ |
200 | static struct ZoneMonitor *monitor_head; | 249 | static struct ZoneMonitor *monitor_head; |
@@ -222,6 +271,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
222 | { | 271 | { |
223 | struct ZoneIteration *no; | 272 | struct ZoneIteration *no; |
224 | struct NamestoreClient *nc; | 273 | struct NamestoreClient *nc; |
274 | struct CacheOperation *cop; | ||
225 | 275 | ||
226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 276 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
227 | "Stopping namestore service\n"); | 277 | "Stopping namestore service\n"); |
@@ -230,6 +280,16 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
230 | GNUNET_SERVER_notification_context_destroy (snc); | 280 | GNUNET_SERVER_notification_context_destroy (snc); |
231 | snc = NULL; | 281 | snc = NULL; |
232 | } | 282 | } |
283 | while (NULL != (cop = cop_head)) | ||
284 | { | ||
285 | GNUNET_NAMECACHE_cancel (cop->qe); | ||
286 | GNUNET_CONTAINER_DLL_remove (cop_head, | ||
287 | cop_tail, | ||
288 | cop); | ||
289 | GNUNET_free (cop); | ||
290 | } | ||
291 | GNUNET_NAMECACHE_disconnect (namecache); | ||
292 | namecache = NULL; | ||
233 | while (NULL != (nc = client_head)) | 293 | while (NULL != (nc = client_head)) |
234 | { | 294 | { |
235 | while (NULL != (no = nc->op_head)) | 295 | while (NULL != (no = nc->op_head)) |
@@ -266,6 +326,7 @@ client_disconnect_notification (void *cls, | |||
266 | struct ZoneIteration *no; | 326 | struct ZoneIteration *no; |
267 | struct NamestoreClient *nc; | 327 | struct NamestoreClient *nc; |
268 | struct ZoneMonitor *zm; | 328 | struct ZoneMonitor *zm; |
329 | struct CacheOperation *cop; | ||
269 | 330 | ||
270 | if (NULL == client) | 331 | if (NULL == client) |
271 | return; | 332 | return; |
@@ -297,6 +358,9 @@ client_disconnect_notification (void *cls, | |||
297 | break; | 358 | break; |
298 | } | 359 | } |
299 | } | 360 | } |
361 | for (cop = cop_head; NULL != cop; cop = cop->next) | ||
362 | if (client == cop->client) | ||
363 | cop->client = NULL; | ||
300 | } | 364 | } |
301 | 365 | ||
302 | 366 | ||
@@ -328,175 +392,6 @@ client_lookup (struct GNUNET_SERVER_Client *client) | |||
328 | 392 | ||
329 | 393 | ||
330 | /** | 394 | /** |
331 | * Context for name lookups passed from #handle_lookup_block to | ||
332 | * #handle_lookup_block_it as closure | ||
333 | */ | ||
334 | struct LookupBlockContext | ||
335 | { | ||
336 | /** | ||
337 | * The client to send the response to | ||
338 | */ | ||
339 | struct NamestoreClient *nc; | ||
340 | |||
341 | /** | ||
342 | * Operation id for the name lookup | ||
343 | */ | ||
344 | uint32_t request_id; | ||
345 | |||
346 | }; | ||
347 | |||
348 | |||
349 | /** | ||
350 | * A #GNUNET_GNSRECORD_BlockCallback for name lookups in #handle_lookup_block | ||
351 | * | ||
352 | * @param cls a `struct LookupNameContext *` with information about the request | ||
353 | * @param block the block | ||
354 | */ | ||
355 | static void | ||
356 | handle_lookup_block_it (void *cls, | ||
357 | const struct GNUNET_GNSRECORD_Block *block) | ||
358 | { | ||
359 | struct LookupBlockContext *lnc = cls; | ||
360 | struct LookupBlockResponseMessage *r; | ||
361 | size_t esize; | ||
362 | |||
363 | esize = ntohl (block->purpose.size) | ||
364 | - sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
365 | - sizeof (struct GNUNET_TIME_AbsoluteNBO); | ||
366 | r = GNUNET_malloc (sizeof (struct LookupBlockResponseMessage) + esize); | ||
367 | r->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK_RESPONSE); | ||
368 | r->gns_header.header.size = htons (sizeof (struct LookupBlockResponseMessage) + esize); | ||
369 | r->gns_header.r_id = htonl (lnc->request_id); | ||
370 | r->expire = block->expiration_time; | ||
371 | r->signature = block->signature; | ||
372 | r->derived_key = block->derived_key; | ||
373 | memcpy (&r[1], &block[1], esize); | ||
374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
375 | "Sending `%s' message with expiration time %s\n", | ||
376 | "NAMESTORE_LOOKUP_BLOCK_RESPONSE", | ||
377 | GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (r->expire))); | ||
378 | GNUNET_SERVER_notification_context_unicast (snc, | ||
379 | lnc->nc->client, | ||
380 | &r->gns_header.header, | ||
381 | GNUNET_NO); | ||
382 | GNUNET_free (r); | ||
383 | } | ||
384 | |||
385 | |||
386 | /** | ||
387 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK message | ||
388 | * | ||
389 | * @param cls unused | ||
390 | * @param client client sending the message | ||
391 | * @param message message of type 'struct LookupNameMessage' | ||
392 | */ | ||
393 | static void | ||
394 | handle_lookup_block (void *cls, | ||
395 | struct GNUNET_SERVER_Client *client, | ||
396 | const struct GNUNET_MessageHeader *message) | ||
397 | { | ||
398 | const struct LookupBlockMessage *ln_msg; | ||
399 | struct LookupBlockContext lnc; | ||
400 | struct NamestoreClient *nc; | ||
401 | struct LookupBlockResponseMessage zir_end; | ||
402 | int ret; | ||
403 | |||
404 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
405 | "Received `%s' message\n", | ||
406 | "NAMESTORE_LOOKUP_BLOCK"); | ||
407 | nc = client_lookup(client); | ||
408 | ln_msg = (const struct LookupBlockMessage *) message; | ||
409 | lnc.request_id = ntohl (ln_msg->gns_header.r_id); | ||
410 | lnc.nc = nc; | ||
411 | if (GNUNET_SYSERR == | ||
412 | (ret = GSN_database->lookup_block (GSN_database->cls, | ||
413 | &ln_msg->query, | ||
414 | &handle_lookup_block_it, &lnc))) | ||
415 | { | ||
416 | /* internal error (in database plugin); might be best to just hang up on | ||
417 | plugin rather than to signal that there are 'no' results, which | ||
418 | might also be false... */ | ||
419 | GNUNET_break (0); | ||
420 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
421 | return; | ||
422 | } | ||
423 | if (0 == ret) | ||
424 | { | ||
425 | /* no records match at all, generate empty response */ | ||
426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
427 | "Sending empty `%s' message\n", | ||
428 | "NAMESTORE_LOOKUP_BLOCK_RESPONSE"); | ||
429 | memset (&zir_end, 0, sizeof (zir_end)); | ||
430 | zir_end.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK_RESPONSE); | ||
431 | zir_end.gns_header.header.size = htons (sizeof (struct LookupBlockResponseMessage)); | ||
432 | zir_end.gns_header.r_id = ln_msg->gns_header.r_id; | ||
433 | GNUNET_SERVER_notification_context_unicast (snc, | ||
434 | client, | ||
435 | &zir_end.gns_header.header, | ||
436 | GNUNET_NO); | ||
437 | |||
438 | } | ||
439 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
440 | } | ||
441 | |||
442 | |||
443 | /** | ||
444 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE message | ||
445 | * | ||
446 | * @param cls unused | ||
447 | * @param client client sending the message | ||
448 | * @param message message of type 'struct BlockCacheMessage' | ||
449 | */ | ||
450 | static void | ||
451 | handle_block_cache (void *cls, | ||
452 | struct GNUNET_SERVER_Client *client, | ||
453 | const struct GNUNET_MessageHeader *message) | ||
454 | { | ||
455 | struct NamestoreClient *nc; | ||
456 | const struct BlockCacheMessage *rp_msg; | ||
457 | struct BlockCacheResponseMessage rpr_msg; | ||
458 | struct GNUNET_GNSRECORD_Block *block; | ||
459 | size_t esize; | ||
460 | int res; | ||
461 | |||
462 | nc = client_lookup (client); | ||
463 | if (ntohs (message->size) < sizeof (struct BlockCacheMessage)) | ||
464 | { | ||
465 | GNUNET_break (0); | ||
466 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
467 | return; | ||
468 | } | ||
469 | rp_msg = (const struct BlockCacheMessage *) message; | ||
470 | esize = ntohs (rp_msg->gns_header.header.size) - sizeof (struct BlockCacheMessage); | ||
471 | block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block) + esize); | ||
472 | block->signature = rp_msg->signature; | ||
473 | block->derived_key = rp_msg->derived_key; | ||
474 | block->purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + | ||
475 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + | ||
476 | esize); | ||
477 | block->expiration_time = rp_msg->expire; | ||
478 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
479 | "Received `%s' message with expiration time %s\n", | ||
480 | "NAMESTORE_BLOCK_CACHE", | ||
481 | GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (block->expiration_time))); | ||
482 | memcpy (&block[1], &rp_msg[1], esize); | ||
483 | res = GSN_database->cache_block (GSN_database->cls, | ||
484 | block); | ||
485 | GNUNET_free (block); | ||
486 | |||
487 | rpr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE_RESPONSE); | ||
488 | rpr_msg.gns_header.header.size = htons (sizeof (struct BlockCacheResponseMessage)); | ||
489 | rpr_msg.gns_header.r_id = rp_msg->gns_header.r_id; | ||
490 | rpr_msg.op_result = htonl (res); | ||
491 | GNUNET_SERVER_notification_context_unicast (snc, | ||
492 | nc->client, | ||
493 | &rpr_msg.gns_header.header, | ||
494 | GNUNET_NO); | ||
495 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
496 | } | ||
497 | |||
498 | |||
499 | /** | ||
500 | * Generate a 'struct LookupNameResponseMessage' and send it to the | 395 | * Generate a 'struct LookupNameResponseMessage' and send it to the |
501 | * given client using the given notification context. | 396 | * given client using the given notification context. |
502 | * | 397 | * |
@@ -554,21 +449,84 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc, | |||
554 | 449 | ||
555 | 450 | ||
556 | /** | 451 | /** |
452 | * Send response to the store request to the client. | ||
453 | * | ||
454 | * @param client client to talk to | ||
455 | * @param res status of the operation | ||
456 | * @param rid client's request ID | ||
457 | */ | ||
458 | static void | ||
459 | send_store_response (struct GNUNET_SERVER_Client *client, | ||
460 | int res, | ||
461 | uint32_t rid) | ||
462 | { | ||
463 | struct RecordStoreResponseMessage rcr_msg; | ||
464 | |||
465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
466 | "Sending `%s' message\n", | ||
467 | "RECORD_STORE_RESPONSE"); | ||
468 | rcr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); | ||
469 | rcr_msg.gns_header.header.size = htons (sizeof (struct RecordStoreResponseMessage)); | ||
470 | rcr_msg.gns_header.r_id = htonl (rid); | ||
471 | rcr_msg.op_result = htonl (res); | ||
472 | GNUNET_SERVER_notification_context_unicast (snc, client, | ||
473 | &rcr_msg.gns_header.header, | ||
474 | GNUNET_NO); | ||
475 | |||
476 | } | ||
477 | |||
478 | |||
479 | /** | ||
480 | * Cache operation complete, clean up. | ||
481 | * | ||
482 | * @param cls the `struct CacheOperation` | ||
483 | */ | ||
484 | static void | ||
485 | finish_cache_operation (void *cls, | ||
486 | int32_t success, | ||
487 | const char *emsg) | ||
488 | { | ||
489 | struct CacheOperation *cop = cls; | ||
490 | |||
491 | if (NULL != emsg) | ||
492 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
493 | _("Failed to replicate block in namecache: %s\n"), | ||
494 | emsg); | ||
495 | else | ||
496 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
497 | "CACHE operation completed\n"); | ||
498 | GNUNET_CONTAINER_DLL_remove (cop_head, | ||
499 | cop_tail, | ||
500 | cop); | ||
501 | if (NULL != cop->client) | ||
502 | send_store_response (cop->client, | ||
503 | success, | ||
504 | cop->rid); | ||
505 | GNUNET_free (cop); | ||
506 | } | ||
507 | |||
508 | |||
509 | /** | ||
557 | * We just touched the plaintext information about a name in our zone; | 510 | * We just touched the plaintext information about a name in our zone; |
558 | * refresh the corresponding (encrypted) block in the namestore. | 511 | * refresh the corresponding (encrypted) block in the namestore. |
559 | * | 512 | * |
513 | * @param client client responsible for the request | ||
514 | * @param rid request ID of the client | ||
560 | * @param zone_key private key of the zone | 515 | * @param zone_key private key of the zone |
561 | * @param name label for the records | 516 | * @param name label for the records |
562 | * @param rd_count number of records | 517 | * @param rd_count number of records |
563 | * @param rd records stored under the given @a name | 518 | * @param rd records stored under the given @a name |
564 | */ | 519 | */ |
565 | static void | 520 | static void |
566 | refresh_block (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 521 | refresh_block (struct GNUNET_SERVER_Client *client, |
522 | uint32_t rid, | ||
523 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | ||
567 | const char *name, | 524 | const char *name, |
568 | unsigned int rd_count, | 525 | unsigned int rd_count, |
569 | const struct GNUNET_GNSRECORD_Data *rd) | 526 | const struct GNUNET_GNSRECORD_Data *rd) |
570 | { | 527 | { |
571 | struct GNUNET_GNSRECORD_Block *block; | 528 | struct GNUNET_GNSRECORD_Block *block; |
529 | struct CacheOperation *cop; | ||
572 | 530 | ||
573 | if (0 == rd_count) | 531 | if (0 == rd_count) |
574 | block = GNUNET_GNSRECORD_block_create (zone_key, | 532 | block = GNUNET_GNSRECORD_block_create (zone_key, |
@@ -581,13 +539,17 @@ refresh_block (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | |||
581 | rd), | 539 | rd), |
582 | name, | 540 | name, |
583 | rd, rd_count); | 541 | rd, rd_count); |
584 | if (GNUNET_OK != | 542 | |
585 | GSN_database->cache_block (GSN_database->cls, | 543 | cop = GNUNET_new (struct CacheOperation); |
586 | block)) | 544 | cop->client = client; |
587 | { | 545 | cop->rid = rid; |
588 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 546 | GNUNET_CONTAINER_DLL_insert (cop_head, |
589 | _("Failed to cache encrypted block of my own zone!\n")); | 547 | cop_tail, |
590 | } | 548 | cop); |
549 | cop->qe = GNUNET_NAMECACHE_block_cache (namecache, | ||
550 | block, | ||
551 | &finish_cache_operation, | ||
552 | cop); | ||
591 | GNUNET_free (block); | 553 | GNUNET_free (block); |
592 | } | 554 | } |
593 | 555 | ||
@@ -601,12 +563,10 @@ refresh_block (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | |||
601 | */ | 563 | */ |
602 | static void | 564 | static void |
603 | handle_record_store (void *cls, | 565 | handle_record_store (void *cls, |
604 | struct GNUNET_SERVER_Client *client, | 566 | struct GNUNET_SERVER_Client *client, |
605 | const struct GNUNET_MessageHeader *message) | 567 | const struct GNUNET_MessageHeader *message) |
606 | { | 568 | { |
607 | struct NamestoreClient *nc; | ||
608 | const struct RecordStoreMessage *rp_msg; | 569 | const struct RecordStoreMessage *rp_msg; |
609 | struct RecordStoreResponseMessage rcr_msg; | ||
610 | size_t name_len; | 570 | size_t name_len; |
611 | size_t msg_size; | 571 | size_t msg_size; |
612 | size_t msg_size_exp; | 572 | size_t msg_size_exp; |
@@ -629,7 +589,6 @@ handle_record_store (void *cls, | |||
629 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 589 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
630 | return; | 590 | return; |
631 | } | 591 | } |
632 | nc = client_lookup (client); | ||
633 | rp_msg = (const struct RecordStoreMessage *) message; | 592 | rp_msg = (const struct RecordStoreMessage *) message; |
634 | rid = ntohl (rp_msg->gns_header.r_id); | 593 | rid = ntohl (rp_msg->gns_header.r_id); |
635 | name_len = ntohs (rp_msg->name_len); | 594 | name_len = ntohs (rp_msg->name_len); |
@@ -705,10 +664,6 @@ handle_record_store (void *cls, | |||
705 | rd_count, rd); | 664 | rd_count, rd); |
706 | if (GNUNET_OK == res) | 665 | if (GNUNET_OK == res) |
707 | { | 666 | { |
708 | refresh_block (&rp_msg->private_key, | ||
709 | conv_name, | ||
710 | rd_count, rd); | ||
711 | |||
712 | for (zm = monitor_head; NULL != zm; zm = zm->next) | 667 | for (zm = monitor_head; NULL != zm; zm = zm->next) |
713 | if (0 == memcmp (&rp_msg->private_key, &zm->zone, | 668 | if (0 == memcmp (&rp_msg->private_key, &zm->zone, |
714 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | 669 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) |
@@ -721,19 +676,17 @@ handle_record_store (void *cls, | |||
721 | } | 676 | } |
722 | GNUNET_free (conv_name); | 677 | GNUNET_free (conv_name); |
723 | } | 678 | } |
679 | if (GNUNET_OK == res) | ||
680 | { | ||
681 | refresh_block (client, rid, | ||
682 | &rp_msg->private_key, | ||
683 | conv_name, | ||
684 | rd_count, rd); | ||
685 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
686 | return; | ||
687 | } | ||
724 | } | 688 | } |
725 | 689 | send_store_response (client, res, rid); | |
726 | /* Send response */ | ||
727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
728 | "Sending `%s' message\n", | ||
729 | "RECORD_STORE_RESPONSE"); | ||
730 | rcr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); | ||
731 | rcr_msg.gns_header.header.size = htons (sizeof (struct RecordStoreResponseMessage)); | ||
732 | rcr_msg.gns_header.r_id = htonl (rid); | ||
733 | rcr_msg.op_result = htonl (res); | ||
734 | GNUNET_SERVER_notification_context_unicast (snc, nc->client, | ||
735 | &rcr_msg.gns_header.header, | ||
736 | GNUNET_NO); | ||
737 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 690 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
738 | } | 691 | } |
739 | 692 | ||
@@ -976,7 +929,8 @@ zone_iteraterate_proc (void *cls, | |||
976 | break; | 929 | break; |
977 | } | 930 | } |
978 | if (GNUNET_YES == do_refresh_block) | 931 | if (GNUNET_YES == do_refresh_block) |
979 | refresh_block (zone_key, | 932 | refresh_block (NULL, 0, |
933 | zone_key, | ||
980 | name, | 934 | name, |
981 | rd_count, | 935 | rd_count, |
982 | rd); | 936 | rd); |
@@ -1299,10 +1253,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1299 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1253 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1300 | { | 1254 | { |
1301 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 1255 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
1302 | {&handle_lookup_block, NULL, | ||
1303 | GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK, sizeof (struct LookupBlockMessage)}, | ||
1304 | {&handle_block_cache, NULL, | ||
1305 | GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE, 0}, | ||
1306 | {&handle_record_store, NULL, | 1256 | {&handle_record_store, NULL, |
1307 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE, 0}, | 1257 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE, 0}, |
1308 | {&handle_zone_to_name, NULL, | 1258 | {&handle_zone_to_name, NULL, |
@@ -1322,7 +1272,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1322 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n"); | 1272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n"); |
1323 | GSN_cfg = cfg; | 1273 | GSN_cfg = cfg; |
1324 | monitor_nc = GNUNET_SERVER_notification_context_create (server, 1); | 1274 | monitor_nc = GNUNET_SERVER_notification_context_create (server, 1); |
1325 | 1275 | namecache = GNUNET_NAMECACHE_connect (cfg); | |
1326 | /* Loading database plugin */ | 1276 | /* Loading database plugin */ |
1327 | if (GNUNET_OK != | 1277 | if (GNUNET_OK != |
1328 | GNUNET_CONFIGURATION_get_value_string (cfg, "namestore", "database", | 1278 | GNUNET_CONFIGURATION_get_value_string (cfg, "namestore", "database", |
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 03e40ca17..efdc3005b 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -83,16 +83,6 @@ struct GNUNET_NAMESTORE_QueueEntry | |||
83 | void *proc_cls; | 83 | void *proc_cls; |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * Function to call with the blocks we get back; or NULL. | ||
87 | */ | ||
88 | GNUNET_GNSRECORD_BlockProcessor block_proc; | ||
89 | |||
90 | /** | ||
91 | * Closure for @e block_proc. | ||
92 | */ | ||
93 | void *block_proc_cls; | ||
94 | |||
95 | /** | ||
96 | * The operation id this zone iteration operation has | 86 | * The operation id this zone iteration operation has |
97 | */ | 87 | */ |
98 | uint32_t op_id; | 88 | uint32_t op_id; |
@@ -259,91 +249,6 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h); | |||
259 | 249 | ||
260 | /** | 250 | /** |
261 | * Handle an incoming message of type | 251 | * Handle an incoming message of type |
262 | * #GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK_RESPONSE. | ||
263 | * | ||
264 | * @param qe the respective entry in the message queue | ||
265 | * @param msg the message we received | ||
266 | * @param size the message size | ||
267 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and we did NOT notify the client | ||
268 | */ | ||
269 | static int | ||
270 | handle_lookup_block_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | ||
271 | const struct LookupBlockResponseMessage *msg, | ||
272 | size_t size) | ||
273 | { | ||
274 | struct GNUNET_GNSRECORD_Block *block; | ||
275 | char buf[size + sizeof (struct GNUNET_GNSRECORD_Block) | ||
276 | - sizeof (struct LookupBlockResponseMessage)]; | ||
277 | |||
278 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
279 | "Received `%s'\n", | ||
280 | "LOOKUP_BLOCK_RESPONSE"); | ||
281 | if (0 == GNUNET_TIME_absolute_ntoh (msg->expire).abs_value_us) | ||
282 | { | ||
283 | /* no match found */ | ||
284 | if (NULL != qe->block_proc) | ||
285 | qe->block_proc (qe->block_proc_cls, NULL); | ||
286 | return GNUNET_OK; | ||
287 | } | ||
288 | |||
289 | block = (struct GNUNET_GNSRECORD_Block *) buf; | ||
290 | block->signature = msg->signature; | ||
291 | block->derived_key = msg->derived_key; | ||
292 | block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | ||
293 | block->purpose.size = htonl (size - sizeof (struct LookupBlockResponseMessage) + | ||
294 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + | ||
295 | sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)); | ||
296 | block->expiration_time = msg->expire; | ||
297 | memcpy (&block[1], | ||
298 | &msg[1], | ||
299 | size - sizeof (struct LookupBlockResponseMessage)); | ||
300 | if (GNUNET_OK != | ||
301 | GNUNET_GNSRECORD_block_verify (block)) | ||
302 | { | ||
303 | GNUNET_break (0); | ||
304 | return GNUNET_SYSERR; | ||
305 | } | ||
306 | if (NULL != qe->block_proc) | ||
307 | qe->block_proc (qe->block_proc_cls, block); | ||
308 | else | ||
309 | GNUNET_break (0); | ||
310 | return GNUNET_OK; | ||
311 | } | ||
312 | |||
313 | |||
314 | /** | ||
315 | * Handle an incoming message of type | ||
316 | * #GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE_RESPONSE | ||
317 | * | ||
318 | * @param qe the respective entry in the message queue | ||
319 | * @param msg the message we received | ||
320 | * @param size the message size | ||
321 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and we did NOT notify the client | ||
322 | */ | ||
323 | static int | ||
324 | handle_block_cache_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | ||
325 | const struct BlockCacheResponseMessage *msg, | ||
326 | size_t size) | ||
327 | { | ||
328 | int res; | ||
329 | |||
330 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
331 | "Received `%s'\n", | ||
332 | "BLOCK_CACHE_RESPONSE"); | ||
333 | res = ntohl (msg->op_result); | ||
334 | /* TODO: add actual error message from namestore to response... */ | ||
335 | if (NULL != qe->cont) | ||
336 | qe->cont (qe->cont_cls, | ||
337 | res, | ||
338 | (GNUNET_OK == res) ? | ||
339 | NULL | ||
340 | : _("Namestore failed to cache block")); | ||
341 | return GNUNET_OK; | ||
342 | } | ||
343 | |||
344 | |||
345 | /** | ||
346 | * Handle an incoming message of type | ||
347 | * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE | 252 | * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE |
348 | * | 253 | * |
349 | * @param qe the respective entry in the message queue | 254 | * @param qe the respective entry in the message queue |
@@ -536,20 +441,6 @@ manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
536 | /* handle different message type */ | 441 | /* handle different message type */ |
537 | switch (type) | 442 | switch (type) |
538 | { | 443 | { |
539 | case GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK_RESPONSE: | ||
540 | if (size < sizeof (struct LookupBlockResponseMessage)) | ||
541 | { | ||
542 | GNUNET_break (0); | ||
543 | return GNUNET_SYSERR; | ||
544 | } | ||
545 | return handle_lookup_block_response (qe, (const struct LookupBlockResponseMessage *) msg, size); | ||
546 | case GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE_RESPONSE: | ||
547 | if (size != sizeof (struct BlockCacheResponseMessage)) | ||
548 | { | ||
549 | GNUNET_break (0); | ||
550 | return GNUNET_SYSERR; | ||
551 | } | ||
552 | return handle_block_cache_response (qe, (const struct BlockCacheResponseMessage *) msg, size); | ||
553 | case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE: | 444 | case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE: |
554 | if (size != sizeof (struct RecordStoreResponseMessage)) | 445 | if (size != sizeof (struct RecordStoreResponseMessage)) |
555 | { | 446 | { |
@@ -1010,64 +901,6 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h) | |||
1010 | 901 | ||
1011 | /** | 902 | /** |
1012 | * Store an item in the namestore. If the item is already present, | 903 | * Store an item in the namestore. If the item is already present, |
1013 | * it is replaced with the new record. | ||
1014 | * | ||
1015 | * @param h handle to the namestore | ||
1016 | * @param block block to store | ||
1017 | * @param cont continuation to call when done | ||
1018 | * @param cont_cls closure for cont | ||
1019 | * @return handle to abort the request | ||
1020 | */ | ||
1021 | struct GNUNET_NAMESTORE_QueueEntry * | ||
1022 | GNUNET_NAMESTORE_block_cache (struct GNUNET_NAMESTORE_Handle *h, | ||
1023 | const struct GNUNET_GNSRECORD_Block *block, | ||
1024 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | ||
1025 | void *cont_cls) | ||
1026 | { | ||
1027 | struct GNUNET_NAMESTORE_QueueEntry *qe; | ||
1028 | struct PendingMessage *pe; | ||
1029 | struct BlockCacheMessage *msg; | ||
1030 | uint32_t rid; | ||
1031 | size_t blen; | ||
1032 | size_t msg_size; | ||
1033 | |||
1034 | GNUNET_assert (NULL != h); | ||
1035 | blen = ntohl (block->purpose.size) | ||
1036 | - sizeof (struct GNUNET_TIME_AbsoluteNBO) | ||
1037 | - sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose); | ||
1038 | rid = get_op_id (h); | ||
1039 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); | ||
1040 | qe->nsh = h; | ||
1041 | qe->cont = cont; | ||
1042 | qe->cont_cls = cont_cls; | ||
1043 | qe->op_id = rid; | ||
1044 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); | ||
1045 | |||
1046 | /* setup msg */ | ||
1047 | msg_size = sizeof (struct BlockCacheMessage) + blen; | ||
1048 | pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); | ||
1049 | pe->size = msg_size; | ||
1050 | msg = (struct BlockCacheMessage *) &pe[1]; | ||
1051 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE); | ||
1052 | msg->gns_header.header.size = htons (msg_size); | ||
1053 | msg->gns_header.r_id = htonl (rid); | ||
1054 | msg->expire = block->expiration_time; | ||
1055 | msg->signature = block->signature; | ||
1056 | msg->derived_key = block->derived_key; | ||
1057 | memcpy (&msg[1], &block[1], blen); | ||
1058 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1059 | "Sending `%s' message with size %u and expiration %s\n", | ||
1060 | "NAMESTORE_BLOCK_CACHE", | ||
1061 | (unsigned int) msg_size, | ||
1062 | GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (msg->expire))); | ||
1063 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); | ||
1064 | do_transmit (h); | ||
1065 | return qe; | ||
1066 | } | ||
1067 | |||
1068 | |||
1069 | /** | ||
1070 | * Store an item in the namestore. If the item is already present, | ||
1071 | * it is replaced with the new record. Use an empty array to | 904 | * it is replaced with the new record. Use an empty array to |
1072 | * remove all records under the given name. | 905 | * remove all records under the given name. |
1073 | * | 906 | * |
@@ -1149,55 +982,6 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
1149 | 982 | ||
1150 | 983 | ||
1151 | /** | 984 | /** |
1152 | * Get a result for a particular key from the namestore. The processor | ||
1153 | * will only be called once. | ||
1154 | * | ||
1155 | * @param h handle to the namestore | ||
1156 | * @param derived_hash hash of zone key combined with name to lookup | ||
1157 | * @param proc function to call on the matching block, or with | ||
1158 | * NULL if there is no matching block | ||
1159 | * @param proc_cls closure for proc | ||
1160 | * @return a handle that can be used to cancel | ||
1161 | */ | ||
1162 | struct GNUNET_NAMESTORE_QueueEntry * | ||
1163 | GNUNET_NAMESTORE_lookup_block (struct GNUNET_NAMESTORE_Handle *h, | ||
1164 | const struct GNUNET_HashCode *derived_hash, | ||
1165 | GNUNET_GNSRECORD_BlockProcessor proc, void *proc_cls) | ||
1166 | { | ||
1167 | struct GNUNET_NAMESTORE_QueueEntry *qe; | ||
1168 | struct PendingMessage *pe; | ||
1169 | struct LookupBlockMessage *msg; | ||
1170 | size_t msg_size; | ||
1171 | uint32_t rid; | ||
1172 | |||
1173 | GNUNET_assert (NULL != h); | ||
1174 | GNUNET_assert (NULL != derived_hash); | ||
1175 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1176 | "Looking for block under %s\n", | ||
1177 | GNUNET_h2s (derived_hash)); | ||
1178 | rid = get_op_id(h); | ||
1179 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); | ||
1180 | qe->nsh = h; | ||
1181 | qe->block_proc = proc; | ||
1182 | qe->block_proc_cls = proc_cls; | ||
1183 | qe->op_id = rid; | ||
1184 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); | ||
1185 | |||
1186 | msg_size = sizeof (struct LookupBlockMessage); | ||
1187 | pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); | ||
1188 | pe->size = msg_size; | ||
1189 | msg = (struct LookupBlockMessage *) &pe[1]; | ||
1190 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK); | ||
1191 | msg->gns_header.header.size = htons (msg_size); | ||
1192 | msg->gns_header.r_id = htonl (rid); | ||
1193 | msg->query = *derived_hash; | ||
1194 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); | ||
1195 | do_transmit (h); | ||
1196 | return qe; | ||
1197 | } | ||
1198 | |||
1199 | |||
1200 | /** | ||
1201 | * Look for an existing PKEY delegation record for a given public key. | 985 | * Look for an existing PKEY delegation record for a given public key. |
1202 | * Returns at most one result to the processor. | 986 | * Returns at most one result to the processor. |
1203 | * | 987 | * |
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index e5cb75eb4..e84413400 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c | |||
@@ -81,12 +81,6 @@ create_indices (PGconn * dbh) | |||
81 | /* create indices */ | 81 | /* create indices */ |
82 | if ( (GNUNET_OK != | 82 | if ( (GNUNET_OK != |
83 | GNUNET_POSTGRES_exec (dbh, | 83 | GNUNET_POSTGRES_exec (dbh, |
84 | "CREATE INDEX ir_query_hash ON ns096blocks (query,expiration_time)")) || | ||
85 | (GNUNET_OK != | ||
86 | GNUNET_POSTGRES_exec (dbh, | ||
87 | "CREATE INDEX ir_block_expiration ON ns096blocks (expiration_time)")) || | ||
88 | (GNUNET_OK != | ||
89 | GNUNET_POSTGRES_exec (dbh, | ||
90 | "CREATE INDEX ir_pkey_reverse ON ns097records (zone_private_key,pkey)")) || | 84 | "CREATE INDEX ir_pkey_reverse ON ns097records (zone_private_key,pkey)")) || |
91 | (GNUNET_OK != | 85 | (GNUNET_OK != |
92 | GNUNET_POSTGRES_exec (dbh, | 86 | GNUNET_POSTGRES_exec (dbh, |
@@ -159,69 +153,10 @@ database_setup (struct Plugin *plugin) | |||
159 | plugin->dbh = NULL; | 153 | plugin->dbh = NULL; |
160 | return GNUNET_SYSERR; | 154 | return GNUNET_SYSERR; |
161 | } | 155 | } |
162 | 156 | create_indices (plugin->dbh); | |
163 | |||
164 | if (GNUNET_YES == | ||
165 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, | ||
166 | "namestore-postgres", | ||
167 | "TEMPORARY_TABLE")) | ||
168 | { | ||
169 | res = | ||
170 | PQexec (plugin->dbh, | ||
171 | "CREATE TEMPORARY TABLE ns096blocks (" | ||
172 | " query BYTEA NOT NULL DEFAULT ''," | ||
173 | " block BYTEA NOT NULL DEFAULT ''," | ||
174 | " expiration_time BIGINT NOT NULL DEFAULT 0" | ||
175 | ")" "WITH OIDS"); | ||
176 | } | ||
177 | else | ||
178 | { | ||
179 | res = | ||
180 | PQexec (plugin->dbh, | ||
181 | "CREATE TABLE ns096blocks (" | ||
182 | " query BYTEA NOT NULL DEFAULT ''," | ||
183 | " block BYTEA NOT NULL DEFAULT ''," | ||
184 | " expiration_time BIGINT NOT NULL DEFAULT 0" | ||
185 | ")" "WITH OIDS"); | ||
186 | } | ||
187 | if ( (NULL == res) || | ||
188 | ((PQresultStatus (res) != PGRES_COMMAND_OK) && | ||
189 | (0 != strcmp ("42P07", /* duplicate table */ | ||
190 | PQresultErrorField | ||
191 | (res, | ||
192 | PG_DIAG_SQLSTATE))))) | ||
193 | { | ||
194 | (void) GNUNET_POSTGRES_check_result (plugin->dbh, res, | ||
195 | PGRES_COMMAND_OK, "CREATE TABLE", | ||
196 | "ns096blocks"); | ||
197 | PQfinish (plugin->dbh); | ||
198 | plugin->dbh = NULL; | ||
199 | return GNUNET_SYSERR; | ||
200 | } | ||
201 | if (PQresultStatus (res) == PGRES_COMMAND_OK) | ||
202 | create_indices (plugin->dbh); | ||
203 | PQclear (res); | ||
204 | 157 | ||
205 | if ((GNUNET_OK != | 158 | if ((GNUNET_OK != |
206 | GNUNET_POSTGRES_prepare (plugin->dbh, | 159 | GNUNET_POSTGRES_prepare (plugin->dbh, |
207 | "cache_block", | ||
208 | "INSERT INTO ns096blocks (query, block, expiration_time) VALUES " | ||
209 | "($1, $2, $3)", 3)) || | ||
210 | (GNUNET_OK != | ||
211 | GNUNET_POSTGRES_prepare (plugin->dbh, | ||
212 | "expire_blocks", | ||
213 | "DELETE FROM ns096blocks WHERE expiration_time<$1", 1)) || | ||
214 | (GNUNET_OK != | ||
215 | GNUNET_POSTGRES_prepare (plugin->dbh, | ||
216 | "delete_block", | ||
217 | "DELETE FROM ns096blocks WHERE query=$1 AND expiration_time<=$2", 2)) || | ||
218 | (GNUNET_OK != | ||
219 | GNUNET_POSTGRES_prepare (plugin->dbh, | ||
220 | "lookup_block", | ||
221 | "SELECT block FROM ns096blocks WHERE query=$1" | ||
222 | " ORDER BY expiration_time DESC LIMIT 1", 1)) || | ||
223 | (GNUNET_OK != | ||
224 | GNUNET_POSTGRES_prepare (plugin->dbh, | ||
225 | "store_records", | 160 | "store_records", |
226 | "INSERT INTO ns097records (zone_private_key, pkey, rvalue, record_count, record_data, label) VALUES " | 161 | "INSERT INTO ns097records (zone_private_key, pkey, rvalue, record_count, record_data, label) VALUES " |
227 | "($1, $2, $3, $4, $5, $6)", 6)) || | 162 | "($1, $2, $3, $4, $5, $6)", 6)) || |
@@ -254,202 +189,6 @@ database_setup (struct Plugin *plugin) | |||
254 | 189 | ||
255 | 190 | ||
256 | /** | 191 | /** |
257 | * Removes any expired block. | ||
258 | * | ||
259 | * @param plugin the plugin | ||
260 | */ | ||
261 | static void | ||
262 | namestore_postgres_expire_blocks (struct Plugin *plugin) | ||
263 | { | ||
264 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | ||
265 | struct GNUNET_TIME_AbsoluteNBO now_be = GNUNET_TIME_absolute_hton (now); | ||
266 | const char *paramValues[] = { | ||
267 | (const char *) &now_be | ||
268 | }; | ||
269 | int paramLengths[] = { | ||
270 | sizeof (now_be) | ||
271 | }; | ||
272 | const int paramFormats[] = { 1 }; | ||
273 | PGresult *res; | ||
274 | |||
275 | res = | ||
276 | PQexecPrepared (plugin->dbh, "expire_blocks", 1, | ||
277 | paramValues, paramLengths, paramFormats, 1); | ||
278 | if (GNUNET_OK != | ||
279 | GNUNET_POSTGRES_check_result (plugin->dbh, | ||
280 | res, | ||
281 | PGRES_COMMAND_OK, | ||
282 | "PQexecPrepared", | ||
283 | "expire_blocks")) | ||
284 | return; | ||
285 | PQclear (res); | ||
286 | } | ||
287 | |||
288 | |||
289 | /** | ||
290 | * Delete older block in the datastore. | ||
291 | * | ||
292 | * @param the plugin | ||
293 | * @param query query for the block | ||
294 | * @param expiration time how old does the block have to be for deletion | ||
295 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
296 | */ | ||
297 | static void | ||
298 | delete_old_block (struct Plugin *plugin, | ||
299 | const struct GNUNET_HashCode *query, | ||
300 | struct GNUNET_TIME_AbsoluteNBO expiration_time) | ||
301 | { | ||
302 | const char *paramValues[] = { | ||
303 | (const char *) query, | ||
304 | (const char *) &expiration_time | ||
305 | }; | ||
306 | int paramLengths[] = { | ||
307 | sizeof (*query), | ||
308 | sizeof (expiration_time) | ||
309 | }; | ||
310 | const int paramFormats[] = { 1, 1 }; | ||
311 | PGresult *res; | ||
312 | |||
313 | res = | ||
314 | PQexecPrepared (plugin->dbh, "delete_block", 2, | ||
315 | paramValues, paramLengths, paramFormats, 1); | ||
316 | if (GNUNET_OK != | ||
317 | GNUNET_POSTGRES_check_result (plugin->dbh, | ||
318 | res, | ||
319 | PGRES_COMMAND_OK, | ||
320 | "PQexecPrepared", | ||
321 | "delete_block")) | ||
322 | return; | ||
323 | PQclear (res); | ||
324 | } | ||
325 | |||
326 | |||
327 | /** | ||
328 | * Cache a block in the datastore. | ||
329 | * | ||
330 | * @param cls closure (internal context for the plugin) | ||
331 | * @param block block to cache | ||
332 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
333 | */ | ||
334 | static int | ||
335 | namestore_postgres_cache_block (void *cls, | ||
336 | const struct GNUNET_GNSRECORD_Block *block) | ||
337 | { | ||
338 | struct Plugin *plugin = cls; | ||
339 | struct GNUNET_HashCode query; | ||
340 | size_t block_size = ntohl (block->purpose.size) + | ||
341 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + | ||
342 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature); | ||
343 | const char *paramValues[] = { | ||
344 | (const char *) &query, | ||
345 | (const char *) block, | ||
346 | (const char *) &block->expiration_time | ||
347 | }; | ||
348 | int paramLengths[] = { | ||
349 | sizeof (query), | ||
350 | (int) block_size, | ||
351 | sizeof (block->expiration_time) | ||
352 | }; | ||
353 | const int paramFormats[] = { 1, 1, 1 }; | ||
354 | PGresult *res; | ||
355 | |||
356 | namestore_postgres_expire_blocks (plugin); | ||
357 | GNUNET_CRYPTO_hash (&block->derived_key, | ||
358 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), | ||
359 | &query); | ||
360 | if (block_size > 64 * 65536) | ||
361 | { | ||
362 | GNUNET_break (0); | ||
363 | return GNUNET_SYSERR; | ||
364 | } | ||
365 | delete_old_block (plugin, &query, block->expiration_time); | ||
366 | |||
367 | res = | ||
368 | PQexecPrepared (plugin->dbh, "cache_block", 3, | ||
369 | paramValues, paramLengths, paramFormats, 1); | ||
370 | if (GNUNET_OK != | ||
371 | GNUNET_POSTGRES_check_result (plugin->dbh, | ||
372 | res, | ||
373 | PGRES_COMMAND_OK, | ||
374 | "PQexecPrepared", | ||
375 | "cache_block")) | ||
376 | return GNUNET_SYSERR; | ||
377 | PQclear (res); | ||
378 | return GNUNET_OK; | ||
379 | } | ||
380 | |||
381 | |||
382 | /** | ||
383 | * Get the block for a particular zone and label in the | ||
384 | * datastore. Will return at most one result to the iterator. | ||
385 | * | ||
386 | * @param cls closure (internal context for the plugin) | ||
387 | * @param query hash of public key derived from the zone and the label | ||
388 | * @param iter function to call with the result | ||
389 | * @param iter_cls closure for @a iter | ||
390 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | ||
391 | */ | ||
392 | static int | ||
393 | namestore_postgres_lookup_block (void *cls, | ||
394 | const struct GNUNET_HashCode *query, | ||
395 | GNUNET_GNSRECORD_BlockCallback iter, void *iter_cls) | ||
396 | { | ||
397 | struct Plugin *plugin = cls; | ||
398 | const char *paramValues[] = { | ||
399 | (const char *) query | ||
400 | }; | ||
401 | int paramLengths[] = { | ||
402 | sizeof (*query) | ||
403 | }; | ||
404 | const int paramFormats[] = { 1 }; | ||
405 | PGresult *res; | ||
406 | unsigned int cnt; | ||
407 | size_t bsize; | ||
408 | const struct GNUNET_GNSRECORD_Block *block; | ||
409 | |||
410 | res = PQexecPrepared (plugin->dbh, | ||
411 | "lookup_block", 1, | ||
412 | paramValues, paramLengths, paramFormats, | ||
413 | 1); | ||
414 | if (GNUNET_OK != | ||
415 | GNUNET_POSTGRES_check_result (plugin->dbh, res, PGRES_TUPLES_OK, | ||
416 | "PQexecPrepared", | ||
417 | "lookup_block")) | ||
418 | { | ||
419 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
420 | "Failing lookup (postgres error)\n"); | ||
421 | return GNUNET_SYSERR; | ||
422 | } | ||
423 | if (0 == (cnt = PQntuples (res))) | ||
424 | { | ||
425 | /* no result */ | ||
426 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
427 | "Ending iteration (no more results)\n"); | ||
428 | PQclear (res); | ||
429 | return GNUNET_NO; | ||
430 | } | ||
431 | GNUNET_assert (1 == cnt); | ||
432 | GNUNET_assert (1 != PQnfields (res)); | ||
433 | bsize = PQgetlength (res, 0, 0); | ||
434 | block = (const struct GNUNET_GNSRECORD_Block *) PQgetvalue (res, 0, 0); | ||
435 | if ( (bsize < sizeof (*block)) || | ||
436 | (bsize != ntohl (block->purpose.size) + | ||
437 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + | ||
438 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature)) ) | ||
439 | { | ||
440 | GNUNET_break (0); | ||
441 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
442 | "Failing lookup (corrupt block)\n"); | ||
443 | PQclear (res); | ||
444 | return GNUNET_SYSERR; | ||
445 | } | ||
446 | iter (iter_cls, block); | ||
447 | PQclear (res); | ||
448 | return GNUNET_OK; | ||
449 | } | ||
450 | |||
451 | |||
452 | /** | ||
453 | * Store a record in the datastore. Removes any existing record in the | 192 | * Store a record in the datastore. Removes any existing record in the |
454 | * same zone with the same name. | 193 | * same zone with the same name. |
455 | * | 194 | * |
@@ -773,8 +512,6 @@ libgnunet_plugin_namestore_postgres_init (void *cls) | |||
773 | } | 512 | } |
774 | api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions); | 513 | api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions); |
775 | api->cls = &plugin; | 514 | api->cls = &plugin; |
776 | api->cache_block = &namestore_postgres_cache_block; | ||
777 | api->lookup_block = &namestore_postgres_lookup_block; | ||
778 | api->store_records = &namestore_postgres_store_records; | 515 | api->store_records = &namestore_postgres_store_records; |
779 | api->iterate_records = &namestore_postgres_iterate_records; | 516 | api->iterate_records = &namestore_postgres_iterate_records; |
780 | api->zone_to_name = &namestore_postgres_zone_to_name; | 517 | api->zone_to_name = &namestore_postgres_zone_to_name; |
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index ce7be2a20..2cf604dbd 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c | |||
@@ -73,26 +73,6 @@ struct Plugin | |||
73 | sqlite3 *dbh; | 73 | sqlite3 *dbh; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * Precompiled SQL for caching a block | ||
77 | */ | ||
78 | sqlite3_stmt *cache_block; | ||
79 | |||
80 | /** | ||
81 | * Precompiled SQL for deleting an older block | ||
82 | */ | ||
83 | sqlite3_stmt *delete_block; | ||
84 | |||
85 | /** | ||
86 | * Precompiled SQL for looking up a block | ||
87 | */ | ||
88 | sqlite3_stmt *lookup_block; | ||
89 | |||
90 | /** | ||
91 | * Precompiled SQL for removing expired blocks | ||
92 | */ | ||
93 | sqlite3_stmt *expire_blocks; | ||
94 | |||
95 | /** | ||
96 | * Precompiled SQL to store records. | 76 | * Precompiled SQL to store records. |
97 | */ | 77 | */ |
98 | sqlite3_stmt *store_records; | 78 | sqlite3_stmt *store_records; |
@@ -153,12 +133,6 @@ create_indices (sqlite3 * dbh) | |||
153 | { | 133 | { |
154 | /* create indices */ | 134 | /* create indices */ |
155 | if ( (SQLITE_OK != | 135 | if ( (SQLITE_OK != |
156 | sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_query_hash ON ns096blocks (query,expiration_time)", | ||
157 | NULL, NULL, NULL)) || | ||
158 | (SQLITE_OK != | ||
159 | sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_block_expiration ON ns096blocks (expiration_time)", | ||
160 | NULL, NULL, NULL)) || | ||
161 | (SQLITE_OK != | ||
162 | sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_pkey_reverse ON ns097records (zone_private_key,pkey)", | 136 | sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_pkey_reverse ON ns097records (zone_private_key,pkey)", |
163 | NULL, NULL, NULL)) || | 137 | NULL, NULL, NULL)) || |
164 | (SQLITE_OK != | 138 | (SQLITE_OK != |
@@ -255,27 +229,7 @@ database_setup (struct Plugin *plugin) | |||
255 | CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS)); | 229 | CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS)); |
256 | 230 | ||
257 | 231 | ||
258 | /* Create tables */ | 232 | /* Create table */ |
259 | CHECK (SQLITE_OK == | ||
260 | sq_prepare (plugin->dbh, | ||
261 | "SELECT 1 FROM sqlite_master WHERE tbl_name = 'ns096blocks'", | ||
262 | &stmt)); | ||
263 | if ((sqlite3_step (stmt) == SQLITE_DONE) && | ||
264 | (sqlite3_exec | ||
265 | (plugin->dbh, | ||
266 | "CREATE TABLE ns096blocks (" | ||
267 | " query BLOB NOT NULL DEFAULT ''," | ||
268 | " block BLOB NOT NULL DEFAULT ''," | ||
269 | " expiration_time INT8 NOT NULL DEFAULT 0" | ||
270 | ")", | ||
271 | NULL, NULL, NULL) != SQLITE_OK)) | ||
272 | { | ||
273 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); | ||
274 | sqlite3_finalize (stmt); | ||
275 | return GNUNET_SYSERR; | ||
276 | } | ||
277 | sqlite3_finalize (stmt); | ||
278 | |||
279 | CHECK (SQLITE_OK == | 233 | CHECK (SQLITE_OK == |
280 | sq_prepare (plugin->dbh, | 234 | sq_prepare (plugin->dbh, |
281 | "SELECT 1 FROM sqlite_master WHERE tbl_name = 'ns097records'", | 235 | "SELECT 1 FROM sqlite_master WHERE tbl_name = 'ns097records'", |
@@ -303,22 +257,6 @@ database_setup (struct Plugin *plugin) | |||
303 | 257 | ||
304 | if ((sq_prepare | 258 | if ((sq_prepare |
305 | (plugin->dbh, | 259 | (plugin->dbh, |
306 | "INSERT INTO ns096blocks (query,block,expiration_time) VALUES (?, ?, ?)", | ||
307 | &plugin->cache_block) != SQLITE_OK) || | ||
308 | (sq_prepare | ||
309 | (plugin->dbh, | ||
310 | "DELETE FROM ns096blocks WHERE expiration_time<?", | ||
311 | &plugin->expire_blocks) != SQLITE_OK) || | ||
312 | (sq_prepare | ||
313 | (plugin->dbh, | ||
314 | "DELETE FROM ns096blocks WHERE query=? AND expiration_time<=?", | ||
315 | &plugin->delete_block) != SQLITE_OK) || | ||
316 | (sq_prepare | ||
317 | (plugin->dbh, | ||
318 | "SELECT block FROM ns096blocks WHERE query=? ORDER BY expiration_time DESC LIMIT 1", | ||
319 | &plugin->lookup_block) != SQLITE_OK) || | ||
320 | (sq_prepare | ||
321 | (plugin->dbh, | ||
322 | "INSERT INTO ns097records (zone_private_key, pkey, rvalue, record_count, record_data, label)" | 260 | "INSERT INTO ns097records (zone_private_key, pkey, rvalue, record_count, record_data, label)" |
323 | " VALUES (?, ?, ?, ?, ?, ?)", | 261 | " VALUES (?, ?, ?, ?, ?, ?)", |
324 | &plugin->store_records) != SQLITE_OK) || | 262 | &plugin->store_records) != SQLITE_OK) || |
@@ -361,14 +299,6 @@ database_shutdown (struct Plugin *plugin) | |||
361 | int result; | 299 | int result; |
362 | sqlite3_stmt *stmt; | 300 | sqlite3_stmt *stmt; |
363 | 301 | ||
364 | if (NULL != plugin->cache_block) | ||
365 | sqlite3_finalize (plugin->cache_block); | ||
366 | if (NULL != plugin->lookup_block) | ||
367 | sqlite3_finalize (plugin->lookup_block); | ||
368 | if (NULL != plugin->expire_blocks) | ||
369 | sqlite3_finalize (plugin->expire_blocks); | ||
370 | if (NULL != plugin->delete_block) | ||
371 | sqlite3_finalize (plugin->delete_block); | ||
372 | if (NULL != plugin->store_records) | 302 | if (NULL != plugin->store_records) |
373 | sqlite3_finalize (plugin->store_records); | 303 | sqlite3_finalize (plugin->store_records); |
374 | if (NULL != plugin->delete_records) | 304 | if (NULL != plugin->delete_records) |
@@ -405,246 +335,6 @@ database_shutdown (struct Plugin *plugin) | |||
405 | 335 | ||
406 | 336 | ||
407 | /** | 337 | /** |
408 | * Removes any expired block. | ||
409 | * | ||
410 | * @param plugin the plugin | ||
411 | */ | ||
412 | static void | ||
413 | namestore_sqlite_expire_blocks (struct Plugin *plugin) | ||
414 | { | ||
415 | struct GNUNET_TIME_Absolute now; | ||
416 | int n; | ||
417 | |||
418 | now = GNUNET_TIME_absolute_get (); | ||
419 | if (SQLITE_OK != sqlite3_bind_int64 (plugin->expire_blocks, | ||
420 | 1, now.abs_value_us)) | ||
421 | { | ||
422 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
423 | "sqlite3_bind_XXXX"); | ||
424 | if (SQLITE_OK != sqlite3_reset (plugin->expire_blocks)) | ||
425 | LOG_SQLITE (plugin, | ||
426 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
427 | "sqlite3_reset"); | ||
428 | return; | ||
429 | } | ||
430 | n = sqlite3_step (plugin->expire_blocks); | ||
431 | if (SQLITE_OK != sqlite3_reset (plugin->expire_blocks)) | ||
432 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
433 | "sqlite3_reset"); | ||
434 | switch (n) | ||
435 | { | ||
436 | case SQLITE_DONE: | ||
437 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Records expired\n"); | ||
438 | return; | ||
439 | case SQLITE_BUSY: | ||
440 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | ||
441 | "sqlite3_step"); | ||
442 | return; | ||
443 | default: | ||
444 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
445 | "sqlite3_step"); | ||
446 | return; | ||
447 | } | ||
448 | } | ||
449 | |||
450 | |||
451 | /** | ||
452 | * Cache a block in the datastore. | ||
453 | * | ||
454 | * @param cls closure (internal context for the plugin) | ||
455 | * @param block block to cache | ||
456 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
457 | */ | ||
458 | static int | ||
459 | namestore_sqlite_cache_block (void *cls, | ||
460 | const struct GNUNET_GNSRECORD_Block *block) | ||
461 | { | ||
462 | struct Plugin *plugin = cls; | ||
463 | struct GNUNET_HashCode query; | ||
464 | struct GNUNET_TIME_Absolute expiration; | ||
465 | int64_t dval; | ||
466 | size_t block_size; | ||
467 | int n; | ||
468 | |||
469 | namestore_sqlite_expire_blocks (plugin); | ||
470 | GNUNET_CRYPTO_hash (&block->derived_key, | ||
471 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), | ||
472 | &query); | ||
473 | expiration = GNUNET_TIME_absolute_ntoh (block->expiration_time); | ||
474 | dval = (int64_t) expiration.abs_value_us; | ||
475 | if (dval < 0) | ||
476 | dval = INT64_MAX; | ||
477 | block_size = ntohl (block->purpose.size) + | ||
478 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + | ||
479 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature); | ||
480 | if (block_size > 64 * 65536) | ||
481 | { | ||
482 | GNUNET_break (0); | ||
483 | return GNUNET_SYSERR; | ||
484 | } | ||
485 | |||
486 | /* delete old version of the block */ | ||
487 | if ( (SQLITE_OK != | ||
488 | sqlite3_bind_blob (plugin->delete_block, 1, | ||
489 | &query, sizeof (struct GNUNET_HashCode), | ||
490 | SQLITE_STATIC)) || | ||
491 | (SQLITE_OK != | ||
492 | sqlite3_bind_int64 (plugin->delete_block, | ||
493 | 2, dval)) ) | ||
494 | { | ||
495 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
496 | "sqlite3_bind_XXXX"); | ||
497 | if (SQLITE_OK != sqlite3_reset (plugin->delete_block)) | ||
498 | LOG_SQLITE (plugin, | ||
499 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
500 | "sqlite3_reset"); | ||
501 | return GNUNET_SYSERR; | ||
502 | } | ||
503 | n = sqlite3_step (plugin->delete_block); | ||
504 | switch (n) | ||
505 | { | ||
506 | case SQLITE_DONE: | ||
507 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Old block deleted\n"); | ||
508 | break; | ||
509 | case SQLITE_BUSY: | ||
510 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | ||
511 | "sqlite3_step"); | ||
512 | break; | ||
513 | default: | ||
514 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
515 | "sqlite3_step"); | ||
516 | break; | ||
517 | } | ||
518 | if (SQLITE_OK != sqlite3_reset (plugin->delete_block)) | ||
519 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
520 | "sqlite3_reset"); | ||
521 | |||
522 | /* insert new version of the block */ | ||
523 | if ((SQLITE_OK != | ||
524 | sqlite3_bind_blob (plugin->cache_block, 1, | ||
525 | &query, sizeof (struct GNUNET_HashCode), | ||
526 | SQLITE_STATIC)) || | ||
527 | (SQLITE_OK != | ||
528 | sqlite3_bind_blob (plugin->cache_block, 2, | ||
529 | block, block_size, | ||
530 | SQLITE_STATIC)) || | ||
531 | (SQLITE_OK != | ||
532 | sqlite3_bind_int64 (plugin->cache_block, 3, | ||
533 | dval))) | ||
534 | { | ||
535 | LOG_SQLITE (plugin, | ||
536 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
537 | "sqlite3_bind_XXXX"); | ||
538 | if (SQLITE_OK != sqlite3_reset (plugin->cache_block)) | ||
539 | LOG_SQLITE (plugin, | ||
540 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
541 | "sqlite3_reset"); | ||
542 | return GNUNET_SYSERR; | ||
543 | |||
544 | } | ||
545 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
546 | "Caching block under derived key `%s'\n", | ||
547 | GNUNET_h2s_full (&query)); | ||
548 | n = sqlite3_step (plugin->cache_block); | ||
549 | if (SQLITE_OK != sqlite3_reset (plugin->cache_block)) | ||
550 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
551 | "sqlite3_reset"); | ||
552 | switch (n) | ||
553 | { | ||
554 | case SQLITE_DONE: | ||
555 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
556 | "Record stored\n"); | ||
557 | return GNUNET_OK; | ||
558 | case SQLITE_BUSY: | ||
559 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | ||
560 | "sqlite3_step"); | ||
561 | return GNUNET_NO; | ||
562 | default: | ||
563 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
564 | "sqlite3_step"); | ||
565 | return GNUNET_SYSERR; | ||
566 | } | ||
567 | } | ||
568 | |||
569 | |||
570 | /** | ||
571 | * Get the block for a particular zone and label in the | ||
572 | * datastore. Will return at most one result to the iterator. | ||
573 | * | ||
574 | * @param cls closure (internal context for the plugin) | ||
575 | * @param query hash of public key derived from the zone and the label | ||
576 | * @param iter function to call with the result | ||
577 | * @param iter_cls closure for @a iter | ||
578 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | ||
579 | */ | ||
580 | static int | ||
581 | namestore_sqlite_lookup_block (void *cls, | ||
582 | const struct GNUNET_HashCode *query, | ||
583 | GNUNET_GNSRECORD_BlockCallback iter, void *iter_cls) | ||
584 | { | ||
585 | struct Plugin *plugin = cls; | ||
586 | int ret; | ||
587 | int sret; | ||
588 | size_t block_size; | ||
589 | const struct GNUNET_GNSRECORD_Block *block; | ||
590 | |||
591 | if (SQLITE_OK != sqlite3_bind_blob (plugin->lookup_block, 1, | ||
592 | query, sizeof (struct GNUNET_HashCode), | ||
593 | SQLITE_STATIC)) | ||
594 | { | ||
595 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
596 | "sqlite3_bind_XXXX"); | ||
597 | if (SQLITE_OK != sqlite3_reset (plugin->lookup_block)) | ||
598 | LOG_SQLITE (plugin, | ||
599 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
600 | "sqlite3_reset"); | ||
601 | return GNUNET_SYSERR; | ||
602 | } | ||
603 | ret = GNUNET_NO; | ||
604 | if (SQLITE_ROW == (sret = sqlite3_step (plugin->lookup_block))) | ||
605 | { | ||
606 | block = sqlite3_column_blob (plugin->lookup_block, 0); | ||
607 | block_size = sqlite3_column_bytes (plugin->lookup_block, 0); | ||
608 | if ( (block_size < sizeof (struct GNUNET_GNSRECORD_Block)) || | ||
609 | (ntohl (block->purpose.size) + | ||
610 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + | ||
611 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature) != block_size) ) | ||
612 | { | ||
613 | GNUNET_break (0); | ||
614 | ret = GNUNET_SYSERR; | ||
615 | } | ||
616 | else | ||
617 | { | ||
618 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
619 | "Found block under derived key `%s'\n", | ||
620 | GNUNET_h2s_full (query)); | ||
621 | iter (iter_cls, block); | ||
622 | ret = GNUNET_YES; | ||
623 | } | ||
624 | } | ||
625 | else | ||
626 | { | ||
627 | if (SQLITE_DONE != sret) | ||
628 | { | ||
629 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step"); | ||
630 | ret = GNUNET_SYSERR; | ||
631 | } | ||
632 | else | ||
633 | { | ||
634 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
635 | "No block found under derived key `%s'\n", | ||
636 | GNUNET_h2s_full (query)); | ||
637 | } | ||
638 | } | ||
639 | if (SQLITE_OK != sqlite3_reset (plugin->lookup_block)) | ||
640 | LOG_SQLITE (plugin, | ||
641 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
642 | "sqlite3_reset"); | ||
643 | return ret; | ||
644 | } | ||
645 | |||
646 | |||
647 | /** | ||
648 | * Store a record in the datastore. Removes any existing record in the | 338 | * Store a record in the datastore. Removes any existing record in the |
649 | * same zone with the same name. | 339 | * same zone with the same name. |
650 | * | 340 | * |
@@ -965,8 +655,6 @@ libgnunet_plugin_namestore_sqlite_init (void *cls) | |||
965 | } | 655 | } |
966 | api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions); | 656 | api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions); |
967 | api->cls = &plugin; | 657 | api->cls = &plugin; |
968 | api->cache_block = &namestore_sqlite_cache_block; | ||
969 | api->lookup_block = &namestore_sqlite_lookup_block; | ||
970 | api->store_records = &namestore_sqlite_store_records; | 658 | api->store_records = &namestore_sqlite_store_records; |
971 | api->iterate_records = &namestore_sqlite_iterate_records; | 659 | api->iterate_records = &namestore_sqlite_iterate_records; |
972 | api->zone_to_name = &namestore_sqlite_zone_to_name; | 660 | api->zone_to_name = &namestore_sqlite_zone_to_name; |
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf index 8e797e994..1478d185b 100644 --- a/src/namestore/test_namestore_api.conf +++ b/src/namestore/test_namestore_api.conf | |||
@@ -3,7 +3,7 @@ GNUNET_TEST_HOME = /tmp/test-gnunet-namestore/ | |||
3 | 3 | ||
4 | [arm] | 4 | [arm] |
5 | PORT = 12000 | 5 | PORT = 12000 |
6 | DEFAULTSERVICES = namestore | 6 | DEFAULTSERVICES = namecache namestore |
7 | 7 | ||
8 | [namestore] | 8 | [namestore] |
9 | #PREFIX = valgrind | 9 | #PREFIX = valgrind |
diff --git a/src/namestore/test_namestore_api_cache_block.c b/src/namestore/test_namestore_api_cache_block.c deleted file mode 100644 index de0ae75ee..000000000 --- a/src/namestore/test_namestore_api_cache_block.c +++ /dev/null | |||
@@ -1,239 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file namestore/test_namestore_api.c | ||
22 | * @brief testcase for namestore_api.c: store a record and perform a lookup | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_namestore_service.h" | ||
26 | #include "gnunet_testing_lib.h" | ||
27 | |||
28 | #define TEST_RECORD_TYPE 1234 | ||
29 | |||
30 | #define TEST_RECORD_DATALEN 123 | ||
31 | |||
32 | #define TEST_RECORD_DATA 'a' | ||
33 | |||
34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) | ||
35 | |||
36 | |||
37 | static struct GNUNET_NAMESTORE_Handle *nsh; | ||
38 | |||
39 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | ||
40 | |||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | ||
42 | |||
43 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | ||
44 | |||
45 | static int res; | ||
46 | |||
47 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | ||
48 | |||
49 | |||
50 | static void | ||
51 | cleanup () | ||
52 | { | ||
53 | if (NULL != nsh) | ||
54 | { | ||
55 | GNUNET_NAMESTORE_disconnect (nsh); | ||
56 | nsh = NULL; | ||
57 | } | ||
58 | if (NULL != privkey) | ||
59 | { | ||
60 | GNUNET_free (privkey); | ||
61 | privkey = NULL; | ||
62 | } | ||
63 | GNUNET_SCHEDULER_shutdown (); | ||
64 | } | ||
65 | |||
66 | |||
67 | /** | ||
68 | * Re-establish the connection to the service. | ||
69 | * | ||
70 | * @param cls handle to use to re-connect. | ||
71 | * @param tc scheduler context | ||
72 | */ | ||
73 | static void | ||
74 | endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
75 | { | ||
76 | if (NULL != nsqe) | ||
77 | { | ||
78 | GNUNET_NAMESTORE_cancel (nsqe); | ||
79 | nsqe = NULL; | ||
80 | } | ||
81 | cleanup (); | ||
82 | res = 1; | ||
83 | } | ||
84 | |||
85 | |||
86 | static void | ||
87 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
88 | { | ||
89 | cleanup (); | ||
90 | res = 0; | ||
91 | } | ||
92 | |||
93 | |||
94 | static void | ||
95 | rd_decrypt_cb (void *cls, | ||
96 | unsigned int rd_count, | ||
97 | const struct GNUNET_GNSRECORD_Data *rd) | ||
98 | { | ||
99 | char rd_cmp_data[TEST_RECORD_DATALEN]; | ||
100 | |||
101 | GNUNET_assert (1 == rd_count); | ||
102 | GNUNET_assert (NULL != rd); | ||
103 | |||
104 | memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN); | ||
105 | |||
106 | GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); | ||
107 | GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); | ||
108 | GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)); | ||
109 | |||
110 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
111 | "Block was decrypted successfully \n"); | ||
112 | |||
113 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
114 | } | ||
115 | |||
116 | static void | ||
117 | name_lookup_proc (void *cls, | ||
118 | const struct GNUNET_GNSRECORD_Block *block) | ||
119 | { | ||
120 | const char *name = cls; | ||
121 | nsqe = NULL; | ||
122 | |||
123 | GNUNET_assert (NULL != cls); | ||
124 | |||
125 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
126 | { | ||
127 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
128 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | ||
129 | } | ||
130 | |||
131 | if (NULL == block) | ||
132 | { | ||
133 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
134 | _("Namestore returned no block\n")); | ||
135 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
136 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
137 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
138 | return; | ||
139 | } | ||
140 | |||
141 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
142 | "Namestore returned block, decrypting \n"); | ||
143 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, | ||
144 | &pubkey, name, &rd_decrypt_cb, (void *) name)); | ||
145 | } | ||
146 | |||
147 | static void | ||
148 | cache_cont (void *cls, int32_t success, const char *emsg) | ||
149 | { | ||
150 | const char *name = cls; | ||
151 | struct GNUNET_HashCode derived_hash; | ||
152 | |||
153 | GNUNET_assert (NULL != cls); | ||
154 | |||
155 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
156 | "Name store cached record for `%s': %s\n", | ||
157 | name, | ||
158 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | ||
159 | |||
160 | /* Create derived hash */ | ||
161 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash); | ||
162 | |||
163 | nsqe = GNUNET_NAMESTORE_lookup_block (nsh, &derived_hash, | ||
164 | &name_lookup_proc, (void *) name); | ||
165 | } | ||
166 | |||
167 | |||
168 | static void | ||
169 | run (void *cls, | ||
170 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
171 | struct GNUNET_TESTING_Peer *peer) | ||
172 | { | ||
173 | struct GNUNET_GNSRECORD_Data rd; | ||
174 | struct GNUNET_GNSRECORD_Block *block; | ||
175 | char *hostkey_file; | ||
176 | const char * name = "dummy.dummy.gnunet"; | ||
177 | |||
178 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
179 | &endbadly, NULL); | ||
180 | GNUNET_asprintf (&hostkey_file, | ||
181 | "zonefiles%s%s", | ||
182 | DIR_SEPARATOR_STR, | ||
183 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | ||
185 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | ||
186 | GNUNET_free (hostkey_file); | ||
187 | GNUNET_assert (privkey != NULL); | ||
188 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | ||
189 | |||
190 | |||
191 | rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; | ||
192 | rd.record_type = TEST_RECORD_TYPE; | ||
193 | rd.data_size = TEST_RECORD_DATALEN; | ||
194 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); | ||
195 | memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); | ||
196 | block = GNUNET_GNSRECORD_block_create (privkey, | ||
197 | GNUNET_TIME_UNIT_FOREVER_ABS, name, &rd, 1 ); | ||
198 | if (NULL == block) | ||
199 | { | ||
200 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
201 | _("Namestore cannot cache no block\n")); | ||
202 | } | ||
203 | |||
204 | nsh = GNUNET_NAMESTORE_connect (cfg); | ||
205 | if (NULL == nsh) | ||
206 | { | ||
207 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
208 | _("Namestore cannot connect to namestore\n")); | ||
209 | } | ||
210 | GNUNET_break (NULL != nsh); | ||
211 | |||
212 | nsqe = GNUNET_NAMESTORE_block_cache (nsh, block , &cache_cont, (void *) name); | ||
213 | if (NULL == nsqe) | ||
214 | { | ||
215 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
216 | _("Namestore cannot cache no block\n")); | ||
217 | } | ||
218 | |||
219 | GNUNET_free ((void *)rd.data); | ||
220 | } | ||
221 | |||
222 | |||
223 | int | ||
224 | main (int argc, char *argv[]) | ||
225 | { | ||
226 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-namestore/"); | ||
227 | res = 1; | ||
228 | if (0 != | ||
229 | GNUNET_TESTING_service_run ("test-namestore-api", | ||
230 | "namestore", | ||
231 | "test_namestore_api.conf", | ||
232 | &run, | ||
233 | NULL)) | ||
234 | return 1; | ||
235 | return res; | ||
236 | } | ||
237 | |||
238 | |||
239 | /* end of test_namestore_api_cache_block.c */ | ||
diff --git a/src/namestore/test_namestore_api_lookup_public.c b/src/namestore/test_namestore_api_lookup_public.c index 97de58a6c..10bfefbed 100644 --- a/src/namestore/test_namestore_api_lookup_public.c +++ b/src/namestore/test_namestore_api_lookup_public.c | |||
@@ -22,6 +22,7 @@ | |||
22 | * @brief testcase for namestore_api.c: store a record and perform a lookup | 22 | * @brief testcase for namestore_api.c: store a record and perform a lookup |
23 | */ | 23 | */ |
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_namecache_service.h" | ||
25 | #include "gnunet_namestore_service.h" | 26 | #include "gnunet_namestore_service.h" |
26 | #include "gnunet_testing_lib.h" | 27 | #include "gnunet_testing_lib.h" |
27 | 28 | ||
@@ -36,6 +37,8 @@ | |||
36 | 37 | ||
37 | static struct GNUNET_NAMESTORE_Handle *nsh; | 38 | static struct GNUNET_NAMESTORE_Handle *nsh; |
38 | 39 | ||
40 | static struct GNUNET_NAMECACHE_Handle *nch; | ||
41 | |||
39 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | 42 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; |
40 | 43 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 44 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
@@ -46,6 +49,8 @@ static int res; | |||
46 | 49 | ||
47 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | 50 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; |
48 | 51 | ||
52 | static struct GNUNET_NAMECACHE_QueueEntry *ncqe; | ||
53 | |||
49 | 54 | ||
50 | static void | 55 | static void |
51 | cleanup () | 56 | cleanup () |
@@ -55,6 +60,11 @@ cleanup () | |||
55 | GNUNET_NAMESTORE_disconnect (nsh); | 60 | GNUNET_NAMESTORE_disconnect (nsh); |
56 | nsh = NULL; | 61 | nsh = NULL; |
57 | } | 62 | } |
63 | if (NULL != nch) | ||
64 | { | ||
65 | GNUNET_NAMECACHE_disconnect (nch); | ||
66 | nch = NULL; | ||
67 | } | ||
58 | if (NULL != privkey) | 68 | if (NULL != privkey) |
59 | { | 69 | { |
60 | GNUNET_free (privkey); | 70 | GNUNET_free (privkey); |
@@ -78,6 +88,11 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
78 | GNUNET_NAMESTORE_cancel (nsqe); | 88 | GNUNET_NAMESTORE_cancel (nsqe); |
79 | nsqe = NULL; | 89 | nsqe = NULL; |
80 | } | 90 | } |
91 | if (NULL != ncqe) | ||
92 | { | ||
93 | GNUNET_NAMECACHE_cancel (ncqe); | ||
94 | ncqe = NULL; | ||
95 | } | ||
81 | cleanup (); | 96 | cleanup (); |
82 | res = 1; | 97 | res = 1; |
83 | } | 98 | } |
@@ -113,13 +128,14 @@ rd_decrypt_cb (void *cls, | |||
113 | GNUNET_SCHEDULER_add_now (&end, NULL); | 128 | GNUNET_SCHEDULER_add_now (&end, NULL); |
114 | } | 129 | } |
115 | 130 | ||
131 | |||
116 | static void | 132 | static void |
117 | name_lookup_proc (void *cls, | 133 | name_lookup_proc (void *cls, |
118 | const struct GNUNET_GNSRECORD_Block *block) | 134 | const struct GNUNET_GNSRECORD_Block *block) |
119 | { | 135 | { |
120 | const char *name = cls; | 136 | const char *name = cls; |
121 | nsqe = NULL; | ||
122 | 137 | ||
138 | ncqe = NULL; | ||
123 | GNUNET_assert (NULL != cls); | 139 | GNUNET_assert (NULL != cls); |
124 | 140 | ||
125 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | 141 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -144,6 +160,7 @@ name_lookup_proc (void *cls, | |||
144 | &pubkey, name, &rd_decrypt_cb, (void *) name)); | 160 | &pubkey, name, &rd_decrypt_cb, (void *) name)); |
145 | } | 161 | } |
146 | 162 | ||
163 | |||
147 | static void | 164 | static void |
148 | put_cont (void *cls, int32_t success, const char *emsg) | 165 | put_cont (void *cls, int32_t success, const char *emsg) |
149 | { | 166 | { |
@@ -151,8 +168,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
151 | struct GNUNET_HashCode derived_hash; | 168 | struct GNUNET_HashCode derived_hash; |
152 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 169 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
153 | 170 | ||
171 | nsqe = NULL; | ||
154 | GNUNET_assert (NULL != cls); | 172 | GNUNET_assert (NULL != cls); |
155 | |||
156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
157 | "Name store added record for `%s': %s\n", | 174 | "Name store added record for `%s': %s\n", |
158 | name, | 175 | name, |
@@ -162,8 +179,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
162 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | 179 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); |
163 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash); | 180 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash); |
164 | 181 | ||
165 | nsqe = GNUNET_NAMESTORE_lookup_block (nsh, &derived_hash, | 182 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, |
166 | &name_lookup_proc, (void *) name); | 183 | &name_lookup_proc, (void *) name); |
167 | } | 184 | } |
168 | 185 | ||
169 | 186 | ||
@@ -196,7 +213,9 @@ run (void *cls, | |||
196 | memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); | 213 | memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); |
197 | 214 | ||
198 | nsh = GNUNET_NAMESTORE_connect (cfg); | 215 | nsh = GNUNET_NAMESTORE_connect (cfg); |
216 | nch = GNUNET_NAMECACHE_connect (cfg); | ||
199 | GNUNET_break (NULL != nsh); | 217 | GNUNET_break (NULL != nsh); |
218 | GNUNET_break (NULL != nch); | ||
200 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | 219 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, |
201 | 1, &rd, &put_cont, (void *) name); | 220 | 1, &rd, &put_cont, (void *) name); |
202 | if (NULL == nsqe) | 221 | if (NULL == nsqe) |
diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c index 8605a3a00..7e3af8290 100644 --- a/src/namestore/test_namestore_api_remove.c +++ b/src/namestore/test_namestore_api_remove.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -42,8 +42,6 @@ static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | |||
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 43 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
44 | 44 | ||
45 | static struct GNUNET_HashCode derived_hash; | ||
46 | |||
47 | static int res; | 45 | static int res; |
48 | 46 | ||
49 | static int removed; | 47 | static int removed; |
@@ -119,72 +117,6 @@ remove_cont (void *cls, | |||
119 | 117 | ||
120 | 118 | ||
121 | static void | 119 | static void |
122 | rd_decrypt_cb (void *cls, | ||
123 | unsigned int rd_count, | ||
124 | const struct GNUNET_GNSRECORD_Data *rd) | ||
125 | { | ||
126 | const char *name = cls; | ||
127 | char rd_cmp_data[TEST_RECORD_DATALEN]; | ||
128 | |||
129 | GNUNET_assert (GNUNET_NO == removed); | ||
130 | GNUNET_assert (1 == rd_count); | ||
131 | GNUNET_assert (NULL != rd); | ||
132 | memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN); | ||
133 | |||
134 | GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); | ||
135 | GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); | ||
136 | GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)); | ||
137 | |||
138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
139 | "Block was decrypted successfully, removing records \n"); | ||
140 | |||
141 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | ||
142 | 0, NULL, &remove_cont, (void *) name); | ||
143 | } | ||
144 | |||
145 | |||
146 | static void | ||
147 | name_lookup_proc (void *cls, | ||
148 | const struct GNUNET_GNSRECORD_Block *block) | ||
149 | { | ||
150 | const char *name = cls; | ||
151 | nsqe = NULL; | ||
152 | |||
153 | if (removed && (NULL == block)) | ||
154 | { | ||
155 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
156 | { | ||
157 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
158 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | ||
159 | } | ||
160 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
161 | return; | ||
162 | } | ||
163 | GNUNET_assert (NULL != cls); | ||
164 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
165 | { | ||
166 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
167 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | ||
168 | } | ||
169 | |||
170 | if (NULL == block) | ||
171 | { | ||
172 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
173 | _("Namestore returned no block\n")); | ||
174 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
175 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
176 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
177 | return; | ||
178 | } | ||
179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
180 | "Namestore returned block, decrypting \n"); | ||
181 | GNUNET_assert (GNUNET_OK == | ||
182 | GNUNET_GNSRECORD_block_decrypt (block, | ||
183 | &pubkey, name, &rd_decrypt_cb, (void *) name)); | ||
184 | } | ||
185 | |||
186 | |||
187 | static void | ||
188 | put_cont (void *cls, int32_t success, | 120 | put_cont (void *cls, int32_t success, |
189 | const char *emsg) | 121 | const char *emsg) |
190 | { | 122 | { |
@@ -207,24 +139,8 @@ put_cont (void *cls, int32_t success, | |||
207 | "Name store added record for `%s': %s\n", | 139 | "Name store added record for `%s': %s\n", |
208 | name, | 140 | name, |
209 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 141 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
210 | 142 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | |
211 | /* Create derived hash */ | 143 | 0, NULL, &remove_cont, (void *) name); |
212 | GNUNET_GNSRECORD_query_from_private_key (privkey, | ||
213 | name, | ||
214 | &derived_hash); | ||
215 | |||
216 | nsqe = GNUNET_NAMESTORE_lookup_block (nsh, &derived_hash, | ||
217 | &name_lookup_proc, (void *) name); | ||
218 | if (NULL == nsqe) | ||
219 | { | ||
220 | GNUNET_break (0); | ||
221 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
222 | _("Namestore cannot perform lookup\n")); | ||
223 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
224 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
225 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
226 | return; | ||
227 | } | ||
228 | } | 144 | } |
229 | 145 | ||
230 | 146 | ||
diff --git a/src/namestore/test_namestore_api_store.c b/src/namestore/test_namestore_api_store.c index 99d245d00..711a160d6 100644 --- a/src/namestore/test_namestore_api_store.c +++ b/src/namestore/test_namestore_api_store.c | |||
@@ -18,8 +18,8 @@ | |||
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file namestore/test_namestore_api.c | 21 | * @file namestore/test_namestore_api_store.c |
22 | * @brief testcase for namestore_api.c: store a record and perform a lookup | 22 | * @brief testcase for namestore_api.c: store a record |
23 | */ | 23 | */ |
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_namestore_service.h" | 25 | #include "gnunet_namestore_service.h" |
@@ -92,76 +92,17 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
92 | 92 | ||
93 | 93 | ||
94 | static void | 94 | static void |
95 | rd_decrypt_cb (void *cls, | ||
96 | unsigned int rd_count, | ||
97 | const struct GNUNET_GNSRECORD_Data *rd) | ||
98 | { | ||
99 | char rd_cmp_data[TEST_RECORD_DATALEN]; | ||
100 | |||
101 | GNUNET_assert (1 == rd_count); | ||
102 | GNUNET_assert (NULL != rd); | ||
103 | |||
104 | memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN); | ||
105 | |||
106 | GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); | ||
107 | GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); | ||
108 | GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)); | ||
109 | |||
110 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
111 | "Block was decrypted successfully \n"); | ||
112 | |||
113 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
114 | } | ||
115 | |||
116 | static void | ||
117 | name_lookup_proc (void *cls, | ||
118 | const struct GNUNET_GNSRECORD_Block *block) | ||
119 | { | ||
120 | const char *name = cls; | ||
121 | nsqe = NULL; | ||
122 | |||
123 | GNUNET_assert (NULL != cls); | ||
124 | |||
125 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
126 | { | ||
127 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
128 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | ||
129 | } | ||
130 | |||
131 | if (NULL == block) | ||
132 | { | ||
133 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
134 | _("Namestore returned no block\n")); | ||
135 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
136 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
137 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
138 | return; | ||
139 | } | ||
140 | |||
141 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
142 | "Namestore returned block, decrypting \n"); | ||
143 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, | ||
144 | &pubkey, name, &rd_decrypt_cb, (void *) name)); | ||
145 | } | ||
146 | |||
147 | static void | ||
148 | put_cont (void *cls, int32_t success, const char *emsg) | 95 | put_cont (void *cls, int32_t success, const char *emsg) |
149 | { | 96 | { |
150 | const char *name = cls; | 97 | const char *name = cls; |
151 | struct GNUNET_HashCode derived_hash; | ||
152 | 98 | ||
99 | nsqe = NULL; | ||
153 | GNUNET_assert (NULL != cls); | 100 | GNUNET_assert (NULL != cls); |
154 | |||
155 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
156 | "Name store added record for `%s': %s\n", | 102 | "Name store added record for `%s': %s\n", |
157 | name, | 103 | name, |
158 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 104 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
159 | 105 | GNUNET_SCHEDULER_add_now (&end, NULL); | |
160 | /* Create derived hash */ | ||
161 | GNUNET_GNSRECORD_query_from_private_key (privkey, name, &derived_hash); | ||
162 | |||
163 | nsqe = GNUNET_NAMESTORE_lookup_block (nsh, &derived_hash, | ||
164 | &name_lookup_proc, (void *) name); | ||
165 | } | 106 | } |
166 | 107 | ||
167 | 108 | ||
@@ -222,4 +163,4 @@ main (int argc, char *argv[]) | |||
222 | } | 163 | } |
223 | 164 | ||
224 | 165 | ||
225 | /* end of test_namestore_api.c */ | 166 | /* end of test_namestore_api_store.c */ |
diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c index 4a0a36bb8..1440addbe 100644 --- a/src/namestore/test_namestore_api_store_update.c +++ b/src/namestore/test_namestore_api_store_update.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * @author Matthias Wachs | 23 | * @author Matthias Wachs |
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_namecache_service.h" | ||
26 | #include "gnunet_namestore_service.h" | 27 | #include "gnunet_namestore_service.h" |
27 | #include "gnunet_testing_lib.h" | 28 | #include "gnunet_testing_lib.h" |
28 | 29 | ||
@@ -44,6 +45,8 @@ | |||
44 | 45 | ||
45 | static struct GNUNET_NAMESTORE_Handle *nsh; | 46 | static struct GNUNET_NAMESTORE_Handle *nsh; |
46 | 47 | ||
48 | static struct GNUNET_NAMECACHE_Handle *nch; | ||
49 | |||
47 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | 50 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; |
48 | 51 | ||
49 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 52 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
@@ -56,6 +59,8 @@ static int update_performed; | |||
56 | 59 | ||
57 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | 60 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; |
58 | 61 | ||
62 | static struct GNUNET_NAMECACHE_QueueEntry *ncqe; | ||
63 | |||
59 | static const char * name = "dummy.dummy.gnunet"; | 64 | static const char * name = "dummy.dummy.gnunet"; |
60 | 65 | ||
61 | 66 | ||
@@ -67,6 +72,11 @@ cleanup () | |||
67 | GNUNET_NAMESTORE_disconnect (nsh); | 72 | GNUNET_NAMESTORE_disconnect (nsh); |
68 | nsh = NULL; | 73 | nsh = NULL; |
69 | } | 74 | } |
75 | if (NULL != nch) | ||
76 | { | ||
77 | GNUNET_NAMECACHE_disconnect (nch); | ||
78 | nch = NULL; | ||
79 | } | ||
70 | if (NULL != privkey) | 80 | if (NULL != privkey) |
71 | { | 81 | { |
72 | GNUNET_free (privkey); | 82 | GNUNET_free (privkey); |
@@ -91,6 +101,11 @@ endbadly (void *cls, | |||
91 | GNUNET_NAMESTORE_cancel (nsqe); | 101 | GNUNET_NAMESTORE_cancel (nsqe); |
92 | nsqe = NULL; | 102 | nsqe = NULL; |
93 | } | 103 | } |
104 | if (NULL != ncqe) | ||
105 | { | ||
106 | GNUNET_NAMECACHE_cancel (ncqe); | ||
107 | ncqe = NULL; | ||
108 | } | ||
94 | cleanup (); | 109 | cleanup (); |
95 | res = 1; | 110 | res = 1; |
96 | } | 111 | } |
@@ -161,10 +176,9 @@ name_lookup_proc (void *cls, | |||
161 | const struct GNUNET_GNSRECORD_Block *block) | 176 | const struct GNUNET_GNSRECORD_Block *block) |
162 | { | 177 | { |
163 | const char *name = cls; | 178 | const char *name = cls; |
164 | nsqe = NULL; | ||
165 | 179 | ||
180 | ncqe = NULL; | ||
166 | GNUNET_assert (NULL != cls); | 181 | GNUNET_assert (NULL != cls); |
167 | |||
168 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | 182 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) |
169 | { | 183 | { |
170 | GNUNET_SCHEDULER_cancel (endbadly_task); | 184 | GNUNET_SCHEDULER_cancel (endbadly_task); |
@@ -194,18 +208,16 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
194 | const char *name = cls; | 208 | const char *name = cls; |
195 | struct GNUNET_HashCode derived_hash; | 209 | struct GNUNET_HashCode derived_hash; |
196 | 210 | ||
211 | nsqe = NULL; | ||
197 | GNUNET_assert (NULL != cls); | 212 | GNUNET_assert (NULL != cls); |
198 | |||
199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
200 | "Name store added record for `%s': %s\n", | 214 | "Name store added record for `%s': %s\n", |
201 | name, | 215 | name, |
202 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 216 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
203 | |||
204 | /* Create derived hash */ | 217 | /* Create derived hash */ |
205 | GNUNET_GNSRECORD_query_from_private_key (privkey, name, &derived_hash); | 218 | GNUNET_GNSRECORD_query_from_private_key (privkey, name, &derived_hash); |
206 | 219 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, | |
207 | nsqe = GNUNET_NAMESTORE_lookup_block (nsh, &derived_hash, | 220 | &name_lookup_proc, (void *) name); |
208 | &name_lookup_proc, (void *) name); | ||
209 | } | 221 | } |
210 | 222 | ||
211 | 223 | ||
@@ -239,6 +251,8 @@ run (void *cls, | |||
239 | 251 | ||
240 | nsh = GNUNET_NAMESTORE_connect (cfg); | 252 | nsh = GNUNET_NAMESTORE_connect (cfg); |
241 | GNUNET_break (NULL != nsh); | 253 | GNUNET_break (NULL != nsh); |
254 | nch = GNUNET_NAMECACHE_connect (cfg); | ||
255 | GNUNET_break (NULL != nch); | ||
242 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, | 256 | nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, |
243 | 1, &rd, &put_cont, (void *) name); | 257 | 1, &rd, &put_cont, (void *) name); |
244 | if (NULL == nsqe) | 258 | if (NULL == nsqe) |
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c index 92fb43a28..f7e4fe489 100644 --- a/src/namestore/test_namestore_api_zone_iteration.c +++ b/src/namestore/test_namestore_api_zone_iteration.c | |||
@@ -66,16 +66,16 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3; | |||
66 | static void | 66 | static void |
67 | endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 67 | endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
68 | { | 68 | { |
69 | if (NULL != zi) | 69 | if (NULL != zi) |
70 | { | 70 | { |
71 | GNUNET_NAMESTORE_zone_iteration_stop (zi); | 71 | GNUNET_NAMESTORE_zone_iteration_stop (zi); |
72 | zi = NULL; | 72 | zi = NULL; |
73 | } | 73 | } |
74 | |||
75 | if (nsh != NULL) | 74 | if (nsh != NULL) |
75 | { | ||
76 | GNUNET_NAMESTORE_disconnect (nsh); | 76 | GNUNET_NAMESTORE_disconnect (nsh); |
77 | nsh = NULL; | 77 | nsh = NULL; |
78 | 78 | } | |
79 | GNUNET_free_non_null(s_name_1); | 79 | GNUNET_free_non_null(s_name_1); |
80 | GNUNET_free_non_null(s_name_2); | 80 | GNUNET_free_non_null(s_name_2); |
81 | GNUNET_free_non_null(s_name_3); | 81 | GNUNET_free_non_null(s_name_3); |
@@ -110,12 +110,11 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
110 | static void | 110 | static void |
111 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 111 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
112 | { | 112 | { |
113 | if (NULL != zi) | 113 | if (NULL != zi) |
114 | { | 114 | { |
115 | GNUNET_NAMESTORE_zone_iteration_stop (zi); | 115 | GNUNET_NAMESTORE_zone_iteration_stop (zi); |
116 | zi = NULL; | 116 | zi = NULL; |
117 | } | 117 | } |
118 | |||
119 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | 118 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) |
120 | { | 119 | { |
121 | GNUNET_SCHEDULER_cancel (endbadly_task); | 120 | GNUNET_SCHEDULER_cancel (endbadly_task); |
@@ -156,12 +155,13 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
156 | 155 | ||
157 | static void | 156 | static void |
158 | zone_proc (void *cls, | 157 | zone_proc (void *cls, |
159 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 158 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
160 | const char *label, | 159 | const char *label, |
161 | unsigned int rd_count, | 160 | unsigned int rd_count, |
162 | const struct GNUNET_GNSRECORD_Data *rd) | 161 | const struct GNUNET_GNSRECORD_Data *rd) |
163 | { | 162 | { |
164 | int failed = GNUNET_NO; | 163 | int failed = GNUNET_NO; |
164 | |||
165 | if ((zone == NULL) && (label == NULL)) | 165 | if ((zone == NULL) && (label == NULL)) |
166 | { | 166 | { |
167 | GNUNET_break (3 == returned_records); | 167 | GNUNET_break (3 == returned_records); |
@@ -175,90 +175,88 @@ zone_proc (void *cls, | |||
175 | 175 | ||
176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
177 | "Received last result, iteration done after receing %u results\n", | 177 | "Received last result, iteration done after receing %u results\n", |
178 | returned_records ); | 178 | returned_records); |
179 | GNUNET_SCHEDULER_add_now (&end, NULL); | 179 | GNUNET_SCHEDULER_add_now (&end, NULL); |
180 | return; | 180 | return; |
181 | } | 181 | } |
182 | else | 182 | if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) |
183 | { | 183 | { |
184 | if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | 184 | if (0 == strcmp (label, s_name_1)) |
185 | { | 185 | { |
186 | if (0 == strcmp (label, s_name_1)) | 186 | if (rd_count == 1) |
187 | { | 187 | { |
188 | if (rd_count == 1) | 188 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1)) |
189 | { | ||
190 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1)) | ||
191 | { | ||
192 | failed = GNUNET_YES; | ||
193 | GNUNET_break (0); | ||
194 | } | ||
195 | } | ||
196 | else | ||
197 | { | 189 | { |
198 | failed = GNUNET_YES; | 190 | failed = GNUNET_YES; |
199 | GNUNET_break (0); | 191 | GNUNET_break (0); |
200 | } | 192 | } |
201 | } | 193 | } |
202 | else if (0 == strcmp (label, s_name_2)) | 194 | else |
203 | { | 195 | { |
204 | if (rd_count == 1) | 196 | failed = GNUNET_YES; |
205 | { | 197 | GNUNET_break (0); |
206 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2)) | 198 | } |
207 | { | 199 | } |
208 | failed = GNUNET_YES; | 200 | else if (0 == strcmp (label, s_name_2)) |
209 | GNUNET_break (0); | 201 | { |
210 | } | 202 | if (rd_count == 1) |
211 | } | 203 | { |
212 | else | 204 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2)) |
213 | { | 205 | { |
214 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
215 | "Received invalid record count\n"); | ||
216 | failed = GNUNET_YES; | 206 | failed = GNUNET_YES; |
217 | GNUNET_break (0); | 207 | GNUNET_break (0); |
218 | } | 208 | } |
219 | } | 209 | } |
220 | else | 210 | else |
221 | { | 211 | { |
222 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 212 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
223 | "Comparing result failed: got name `%s' for first zone\n", label); | 213 | "Received invalid record count\n"); |
224 | failed = GNUNET_YES; | 214 | failed = GNUNET_YES; |
225 | GNUNET_break (0); | 215 | GNUNET_break (0); |
226 | } | 216 | } |
227 | } | 217 | } |
228 | else if (0 == memcmp (zone, privkey2, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | 218 | else |
229 | { | 219 | { |
230 | if (0 == strcmp (label, s_name_3)) | 220 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
221 | "Comparing result failed: got name `%s' for first zone\n", label); | ||
222 | failed = GNUNET_YES; | ||
223 | GNUNET_break (0); | ||
224 | } | ||
225 | } | ||
226 | else if (0 == memcmp (zone, privkey2, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | ||
227 | { | ||
228 | if (0 == strcmp (label, s_name_3)) | ||
229 | { | ||
230 | if (rd_count == 1) | ||
231 | { | 231 | { |
232 | if (rd_count == 1) | 232 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_3)) |
233 | { | 233 | { |
234 | if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_3)) | ||
235 | { | ||
236 | failed = GNUNET_YES; | ||
237 | GNUNET_break (0); | ||
238 | } | ||
239 | } | ||
240 | else | ||
241 | { | ||
242 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
243 | "Received invalid record count\n"); | ||
244 | failed = GNUNET_YES; | 234 | failed = GNUNET_YES; |
245 | GNUNET_break (0); | 235 | GNUNET_break (0); |
246 | } | 236 | } |
247 | } | 237 | } |
248 | else | 238 | else |
249 | { | 239 | { |
250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 240 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
251 | "Comparing result failed: got name `%s' for first zone\n", label); | 241 | "Received invalid record count\n"); |
252 | failed = GNUNET_YES; | 242 | failed = GNUNET_YES; |
253 | GNUNET_break (0); | 243 | GNUNET_break (0); |
254 | } | 244 | } |
255 | } | 245 | } |
256 | else | 246 | else |
257 | { | 247 | { |
258 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received invalid zone\n"); | 248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
249 | "Comparing result failed: got name `%s' for first zone\n", label); | ||
259 | failed = GNUNET_YES; | 250 | failed = GNUNET_YES; |
260 | GNUNET_break (0); | 251 | GNUNET_break (0); |
261 | } | 252 | } |
253 | } | ||
254 | else | ||
255 | { | ||
256 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
257 | "Received invalid zone\n"); | ||
258 | failed = GNUNET_YES; | ||
259 | GNUNET_break (0); | ||
262 | } | 260 | } |
263 | 261 | ||
264 | if (failed == GNUNET_NO) | 262 | if (failed == GNUNET_NO) |
@@ -302,10 +300,10 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
302 | res = 1; | 300 | res = 1; |
303 | returned_records = 0; | 301 | returned_records = 0; |
304 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); | 302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); |
305 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, | 303 | zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, |
306 | NULL, | 304 | NULL, |
307 | &zone_proc, | 305 | &zone_proc, |
308 | NULL); | 306 | NULL); |
309 | if (zi == NULL) | 307 | if (zi == NULL) |
310 | { | 308 | { |
311 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); | 309 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); |
@@ -394,22 +392,26 @@ empty_zone_proc (void *cls, | |||
394 | 392 | ||
395 | GNUNET_asprintf(&s_name_1, "dummy1"); | 393 | GNUNET_asprintf(&s_name_1, "dummy1"); |
396 | s_rd_1 = create_record(1); | 394 | s_rd_1 = create_record(1); |
397 | GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, | 395 | GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_1, |
398 | 1, s_rd_1, &put_cont, NULL); | 396 | 1, s_rd_1, |
397 | &put_cont, NULL); | ||
399 | 398 | ||
400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); | 399 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
400 | "Created record 2 \n"); | ||
401 | GNUNET_asprintf(&s_name_2, "dummy2"); | 401 | GNUNET_asprintf(&s_name_2, "dummy2"); |
402 | s_rd_2 = create_record(1); | 402 | s_rd_2 = create_record(1); |
403 | GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2, | 403 | GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_2, |
404 | 1, s_rd_2, &put_cont, NULL); | 404 | 1, s_rd_2, &put_cont, NULL); |
405 | 405 | ||
406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n"); | 406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
407 | "Created record 3\n"); | ||
407 | 408 | ||
408 | /* name in different zone */ | 409 | /* name in different zone */ |
409 | GNUNET_asprintf(&s_name_3, "dummy3"); | 410 | GNUNET_asprintf(&s_name_3, "dummy3"); |
410 | s_rd_3 = create_record(1); | 411 | s_rd_3 = create_record(1); |
411 | GNUNET_NAMESTORE_records_store(nsh, privkey2, s_name_3, | 412 | GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, |
412 | 1, s_rd_3, &put_cont, NULL); | 413 | 1, s_rd_3, |
414 | &put_cont, NULL); | ||
413 | } | 415 | } |
414 | 416 | ||
415 | 417 | ||