diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-04 20:31:16 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-04 20:31:16 +0900 |
commit | 4aeb9686fb4bd0fa686d1aa8c99211312726fcf0 (patch) | |
tree | 22c4b918f5881cf9dc19b58644b6d28f41fc850e /src/zonemaster | |
parent | 34ae70a81bbfddc877593079e2e5f94f179deffc (diff) | |
download | gnunet-4aeb9686fb4bd0fa686d1aa8c99211312726fcf0.tar.gz gnunet-4aeb9686fb4bd0fa686d1aa8c99211312726fcf0.zip |
NAMESTORE: Move Namecache block refresh into zonemonitor
Diffstat (limited to 'src/zonemaster')
-rw-r--r-- | src/zonemaster/Makefile.am | 2 | ||||
-rw-r--r-- | src/zonemaster/gnunet-service-zonemaster-monitor.c | 177 | ||||
-rw-r--r-- | src/zonemaster/gnunet-service-zonemaster.c | 189 |
3 files changed, 355 insertions, 13 deletions
diff --git a/src/zonemaster/Makefile.am b/src/zonemaster/Makefile.am index f2d569c75..90b70f58a 100644 --- a/src/zonemaster/Makefile.am +++ b/src/zonemaster/Makefile.am | |||
@@ -28,6 +28,7 @@ gnunet_service_zonemaster_LDADD = \ | |||
28 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 28 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
29 | $(top_builddir)/src/util/libgnunetutil.la \ | 29 | $(top_builddir)/src/util/libgnunetutil.la \ |
30 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | 30 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
31 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ | ||
31 | $(GN_LIBINTL) | 32 | $(GN_LIBINTL) |
32 | 33 | ||
33 | 34 | ||
@@ -40,4 +41,5 @@ gnunet_service_zonemaster_monitor_LDADD = \ | |||
40 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 41 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
41 | $(top_builddir)/src/util/libgnunetutil.la \ | 42 | $(top_builddir)/src/util/libgnunetutil.la \ |
42 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | 43 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
44 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ | ||
43 | $(GN_LIBINTL) | 45 | $(GN_LIBINTL) |
diff --git a/src/zonemaster/gnunet-service-zonemaster-monitor.c b/src/zonemaster/gnunet-service-zonemaster-monitor.c index 08749bede..d2bc5e89d 100644 --- a/src/zonemaster/gnunet-service-zonemaster-monitor.c +++ b/src/zonemaster/gnunet-service-zonemaster-monitor.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_dht_service.h" | 28 | #include "gnunet_dht_service.h" |
29 | #include "gnunet_namestore_service.h" | 29 | #include "gnunet_namestore_service.h" |
30 | #include "gnunet_namecache_service.h" | ||
30 | #include "gnunet_statistics_service.h" | 31 | #include "gnunet_statistics_service.h" |
31 | 32 | ||
32 | #define LOG_STRERROR_FILE(kind, syscall, \ | 33 | #define LOG_STRERROR_FILE(kind, syscall, \ |
@@ -83,6 +84,28 @@ struct DhtPutActivity | |||
83 | struct GNUNET_TIME_Absolute start_date; | 84 | struct GNUNET_TIME_Absolute start_date; |
84 | }; | 85 | }; |
85 | 86 | ||
87 | /** | ||
88 | * Pending operation on the namecache. | ||
89 | */ | ||
90 | struct CacheOperation | ||
91 | { | ||
92 | /** | ||
93 | * Kept in a DLL. | ||
94 | */ | ||
95 | struct CacheOperation *prev; | ||
96 | |||
97 | /** | ||
98 | * Kept in a DLL. | ||
99 | */ | ||
100 | struct CacheOperation *next; | ||
101 | |||
102 | /** | ||
103 | * Handle to namecache queue. | ||
104 | */ | ||
105 | struct GNUNET_NAMECACHE_QueueEntry *qe; | ||
106 | |||
107 | }; | ||
108 | |||
86 | 109 | ||
87 | /** | 110 | /** |
88 | * Handle to the statistics service | 111 | * Handle to the statistics service |
@@ -115,6 +138,18 @@ static struct DhtPutActivity *ma_head; | |||
115 | static struct DhtPutActivity *ma_tail; | 138 | static struct DhtPutActivity *ma_tail; |
116 | 139 | ||
117 | /** | 140 | /** |
141 | * Our handle to the namecache service | ||
142 | */ | ||
143 | static struct GNUNET_NAMECACHE_Handle *namecache; | ||
144 | |||
145 | /** | ||
146 | * Use the namecache? Doing so creates additional cryptographic | ||
147 | * operations whenever we touch a record. | ||
148 | */ | ||
149 | static int disable_namecache; | ||
150 | |||
151 | |||
152 | /** | ||
118 | * Number of entries in the DHT queue #ma_head. | 153 | * Number of entries in the DHT queue #ma_head. |
119 | */ | 154 | */ |
120 | static unsigned int ma_queue_length; | 155 | static unsigned int ma_queue_length; |
@@ -125,6 +160,16 @@ static unsigned int ma_queue_length; | |||
125 | */ | 160 | */ |
126 | static int cache_keys; | 161 | static int cache_keys; |
127 | 162 | ||
163 | /** | ||
164 | * Head of cop DLL. | ||
165 | */ | ||
166 | static struct CacheOperation *cop_head; | ||
167 | |||
168 | /** | ||
169 | * Tail of cop DLL. | ||
170 | */ | ||
171 | static struct CacheOperation *cop_tail; | ||
172 | |||
128 | 173 | ||
129 | /** | 174 | /** |
130 | * Task run during shutdown. | 175 | * Task run during shutdown. |
@@ -136,10 +181,20 @@ static void | |||
136 | shutdown_task (void *cls) | 181 | shutdown_task (void *cls) |
137 | { | 182 | { |
138 | struct DhtPutActivity *ma; | 183 | struct DhtPutActivity *ma; |
184 | struct CacheOperation *cop; | ||
185 | |||
139 | 186 | ||
140 | (void) cls; | 187 | (void) cls; |
141 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
142 | "Shutting down!\n"); | 189 | "Shutting down!\n"); |
190 | while (NULL != (cop = cop_head)) | ||
191 | { | ||
192 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
193 | "Aborting incomplete namecache operation\n"); | ||
194 | GNUNET_NAMECACHE_cancel (cop->qe); | ||
195 | GNUNET_CONTAINER_DLL_remove (cop_head, cop_tail, cop); | ||
196 | GNUNET_free (cop); | ||
197 | } | ||
143 | while (NULL != (ma = ma_head)) | 198 | while (NULL != (ma = ma_head)) |
144 | { | 199 | { |
145 | GNUNET_DHT_put_cancel (ma->ph); | 200 | GNUNET_DHT_put_cancel (ma->ph); |
@@ -165,6 +220,11 @@ shutdown_task (void *cls) | |||
165 | GNUNET_NAMESTORE_disconnect (namestore_handle); | 220 | GNUNET_NAMESTORE_disconnect (namestore_handle); |
166 | namestore_handle = NULL; | 221 | namestore_handle = NULL; |
167 | } | 222 | } |
223 | if (NULL != namecache) | ||
224 | { | ||
225 | GNUNET_NAMECACHE_disconnect (namecache); | ||
226 | namecache = NULL; | ||
227 | } | ||
168 | if (NULL != dht_handle) | 228 | if (NULL != dht_handle) |
169 | { | 229 | { |
170 | GNUNET_DHT_disconnect (dht_handle); | 230 | GNUNET_DHT_disconnect (dht_handle); |
@@ -172,6 +232,66 @@ shutdown_task (void *cls) | |||
172 | } | 232 | } |
173 | } | 233 | } |
174 | 234 | ||
235 | /** | ||
236 | * Cache operation complete, clean up. | ||
237 | * | ||
238 | * @param cls the `struct CacheOperation` | ||
239 | * @param success success | ||
240 | * @param emsg error messages | ||
241 | */ | ||
242 | static void | ||
243 | finish_cache_operation (void *cls, int32_t success, const char *emsg) | ||
244 | { | ||
245 | struct CacheOperation *cop = cls; | ||
246 | |||
247 | if (NULL != emsg) | ||
248 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
249 | _ ("Failed to replicate block in namecache: %s\n"), | ||
250 | emsg); | ||
251 | else | ||
252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CACHE operation completed\n"); | ||
253 | GNUNET_CONTAINER_DLL_remove (cop_head, cop_tail, cop); | ||
254 | GNUNET_free (cop); | ||
255 | } | ||
256 | |||
257 | |||
258 | /** | ||
259 | * Refresh the (encrypted) block in the namecache. | ||
260 | * | ||
261 | * @param zone_key private key of the zone | ||
262 | * @param name label for the records | ||
263 | * @param rd_count number of records | ||
264 | * @param rd records stored under the given @a name | ||
265 | */ | ||
266 | static void | ||
267 | refresh_block (const struct GNUNET_GNSRECORD_Block *block) | ||
268 | { | ||
269 | struct CacheOperation *cop; | ||
270 | struct GNUNET_TIME_Absolute exp_time; | ||
271 | |||
272 | if (GNUNET_YES == disable_namecache) | ||
273 | { | ||
274 | GNUNET_STATISTICS_update (statistics, | ||
275 | "Namecache updates skipped (NC disabled)", | ||
276 | 1, | ||
277 | GNUNET_NO); | ||
278 | return; | ||
279 | } | ||
280 | GNUNET_assert (NULL != block); | ||
281 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Caching block in namecache\n"); | ||
282 | GNUNET_STATISTICS_update (statistics, | ||
283 | "Namecache updates pushed", | ||
284 | 1, | ||
285 | GNUNET_NO); | ||
286 | cop = GNUNET_new (struct CacheOperation); | ||
287 | GNUNET_CONTAINER_DLL_insert (cop_head, cop_tail, cop); | ||
288 | cop->qe = GNUNET_NAMECACHE_block_cache (namecache, | ||
289 | block, | ||
290 | &finish_cache_operation, | ||
291 | cop); | ||
292 | } | ||
293 | |||
294 | |||
175 | 295 | ||
176 | /** | 296 | /** |
177 | * Continuation called from DHT once the PUT operation triggered | 297 | * Continuation called from DHT once the PUT operation triggered |
@@ -207,15 +327,35 @@ dht_put_monitor_continuation (void *cls) | |||
207 | static struct GNUNET_DHT_PutHandle * | 327 | static struct GNUNET_DHT_PutHandle * |
208 | perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key, | 328 | perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key, |
209 | const char *label, | 329 | const char *label, |
210 | const struct GNUNET_GNSRECORD_Data *rd_public, | 330 | const struct GNUNET_GNSRECORD_Data *rd, |
211 | unsigned int rd_public_count, | 331 | unsigned int rd_count, |
212 | struct GNUNET_TIME_Absolute expire, | 332 | struct GNUNET_TIME_Absolute expire, |
213 | struct DhtPutActivity *ma) | 333 | struct DhtPutActivity *ma) |
214 | { | 334 | { |
335 | struct GNUNET_GNSRECORD_Data rd_public[rd_count]; | ||
215 | struct GNUNET_GNSRECORD_Block *block; | 336 | struct GNUNET_GNSRECORD_Block *block; |
337 | struct GNUNET_GNSRECORD_Block *block_priv; | ||
216 | struct GNUNET_HashCode query; | 338 | struct GNUNET_HashCode query; |
339 | struct GNUNET_TIME_Absolute expire_priv; | ||
217 | size_t block_size; | 340 | size_t block_size; |
341 | unsigned int rd_public_count = 0; | ||
218 | struct GNUNET_DHT_PutHandle *ret; | 342 | struct GNUNET_DHT_PutHandle *ret; |
343 | char *emsg; | ||
344 | |||
345 | if (GNUNET_OK != | ||
346 | GNUNET_GNSRECORD_normalize_record_set (label, | ||
347 | rd, | ||
348 | rd_count, | ||
349 | rd_public, | ||
350 | &rd_public_count, | ||
351 | &expire_priv, | ||
352 | GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE, | ||
353 | &emsg)) | ||
354 | { | ||
355 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
356 | "%s\n", emsg); | ||
357 | GNUNET_free (emsg); | ||
358 | } | ||
219 | 359 | ||
220 | if (cache_keys) | 360 | if (cache_keys) |
221 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create2 (key, | 361 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create2 (key, |
@@ -236,6 +376,15 @@ perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key, | |||
236 | GNUNET_break (0); | 376 | GNUNET_break (0); |
237 | return NULL; /* whoops */ | 377 | return NULL; /* whoops */ |
238 | } | 378 | } |
379 | if (rd_count != rd_public_count) | ||
380 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (key, | ||
381 | expire_priv, | ||
382 | label, | ||
383 | rd, | ||
384 | rd_count, | ||
385 | &block_priv)); | ||
386 | else | ||
387 | block_priv = block; | ||
239 | block_size = GNUNET_GNSRECORD_block_get_size (block); | 388 | block_size = GNUNET_GNSRECORD_block_get_size (block); |
240 | GNUNET_GNSRECORD_query_from_private_key (key, | 389 | GNUNET_GNSRECORD_query_from_private_key (key, |
241 | label, | 390 | label, |
@@ -260,6 +409,9 @@ perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key, | |||
260 | expire, | 409 | expire, |
261 | &dht_put_monitor_continuation, | 410 | &dht_put_monitor_continuation, |
262 | ma); | 411 | ma); |
412 | refresh_block (block_priv); | ||
413 | if (block != block_priv) | ||
414 | GNUNET_free (block_priv); | ||
263 | GNUNET_free (block); | 415 | GNUNET_free (block); |
264 | return ret; | 416 | return ret; |
265 | } | 417 | } |
@@ -379,6 +531,25 @@ run (void *cls, | |||
379 | GNUNET_SCHEDULER_shutdown (); | 531 | GNUNET_SCHEDULER_shutdown (); |
380 | return; | 532 | return; |
381 | } | 533 | } |
534 | disable_namecache = GNUNET_CONFIGURATION_get_value_yesno (c, | ||
535 | "namecache", | ||
536 | "DISABLE"); | ||
537 | if (GNUNET_NO == disable_namecache) | ||
538 | { | ||
539 | namecache = GNUNET_NAMECACHE_connect (c); | ||
540 | if (NULL == namecache) | ||
541 | { | ||
542 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
543 | _ ("Failed to connect to the namecache!\n")); | ||
544 | GNUNET_SCHEDULER_shutdown (); | ||
545 | return; | ||
546 | } | ||
547 | } | ||
548 | else | ||
549 | { | ||
550 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
551 | _ ("Namecache is disabled!\n")); | ||
552 | } | ||
382 | cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c, | 553 | cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c, |
383 | "namestore", | 554 | "namestore", |
384 | "CACHE_KEYS"); | 555 | "CACHE_KEYS"); |
@@ -417,7 +588,7 @@ run (void *cls, | |||
417 | NULL, | 588 | NULL, |
418 | NULL /* sync_cb */, | 589 | NULL /* sync_cb */, |
419 | NULL, | 590 | NULL, |
420 | GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE); | 591 | GNUNET_GNSRECORD_FILTER_NONE); |
421 | GNUNET_NAMESTORE_zone_monitor_next (zmon, | 592 | GNUNET_NAMESTORE_zone_monitor_next (zmon, |
422 | NAMESTORE_QUEUE_LIMIT - 1); | 593 | NAMESTORE_QUEUE_LIMIT - 1); |
423 | GNUNET_break (NULL != zmon); | 594 | GNUNET_break (NULL != zmon); |
diff --git a/src/zonemaster/gnunet-service-zonemaster.c b/src/zonemaster/gnunet-service-zonemaster.c index dba1b24ce..ded86c7fa 100644 --- a/src/zonemaster/gnunet-service-zonemaster.c +++ b/src/zonemaster/gnunet-service-zonemaster.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "gnunet_dnsparser_lib.h" | 28 | #include "gnunet_dnsparser_lib.h" |
29 | #include "gnunet_dht_service.h" | 29 | #include "gnunet_dht_service.h" |
30 | #include "gnunet_namestore_service.h" | 30 | #include "gnunet_namestore_service.h" |
31 | #include "gnunet_namecache_service.h" | ||
31 | #include "gnunet_statistics_service.h" | 32 | #include "gnunet_statistics_service.h" |
32 | 33 | ||
33 | #define LOG_STRERROR_FILE(kind, syscall, \ | 34 | #define LOG_STRERROR_FILE(kind, syscall, \ |
@@ -115,6 +116,28 @@ struct DhtPutActivity | |||
115 | struct GNUNET_TIME_Absolute start_date; | 116 | struct GNUNET_TIME_Absolute start_date; |
116 | }; | 117 | }; |
117 | 118 | ||
119 | /** | ||
120 | * Pending operation on the namecache. | ||
121 | */ | ||
122 | struct CacheOperation | ||
123 | { | ||
124 | /** | ||
125 | * Kept in a DLL. | ||
126 | */ | ||
127 | struct CacheOperation *prev; | ||
128 | |||
129 | /** | ||
130 | * Kept in a DLL. | ||
131 | */ | ||
132 | struct CacheOperation *next; | ||
133 | |||
134 | /** | ||
135 | * Handle to namecache queue. | ||
136 | */ | ||
137 | struct GNUNET_NAMECACHE_QueueEntry *qe; | ||
138 | |||
139 | }; | ||
140 | |||
118 | 141 | ||
119 | /** | 142 | /** |
120 | * Handle to the statistics service | 143 | * Handle to the statistics service |
@@ -132,6 +155,17 @@ static struct GNUNET_DHT_Handle *dht_handle; | |||
132 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | 155 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; |
133 | 156 | ||
134 | /** | 157 | /** |
158 | * Our handle to the namecache service | ||
159 | */ | ||
160 | static struct GNUNET_NAMECACHE_Handle *namecache; | ||
161 | |||
162 | /** | ||
163 | * Use the namecache? Doing so creates additional cryptographic | ||
164 | * operations whenever we touch a record. | ||
165 | */ | ||
166 | static int disable_namecache; | ||
167 | |||
168 | /** | ||
135 | * Handle to iterate over our authoritative zone in namestore | 169 | * Handle to iterate over our authoritative zone in namestore |
136 | */ | 170 | */ |
137 | static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; | 171 | static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; |
@@ -235,6 +269,16 @@ static int first_zone_iteration; | |||
235 | */ | 269 | */ |
236 | static int cache_keys; | 270 | static int cache_keys; |
237 | 271 | ||
272 | /** | ||
273 | * Head of cop DLL. | ||
274 | */ | ||
275 | static struct CacheOperation *cop_head; | ||
276 | |||
277 | /** | ||
278 | * Tail of cop DLL. | ||
279 | */ | ||
280 | static struct CacheOperation *cop_tail; | ||
281 | |||
238 | 282 | ||
239 | /** | 283 | /** |
240 | * Task run during shutdown. | 284 | * Task run during shutdown. |
@@ -246,10 +290,20 @@ static void | |||
246 | shutdown_task (void *cls) | 290 | shutdown_task (void *cls) |
247 | { | 291 | { |
248 | struct DhtPutActivity *ma; | 292 | struct DhtPutActivity *ma; |
293 | struct CacheOperation *cop; | ||
249 | 294 | ||
250 | (void) cls; | 295 | (void) cls; |
251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
252 | "Shutting down!\n"); | 297 | "Shutting down!\n"); |
298 | while (NULL != (cop = cop_head)) | ||
299 | { | ||
300 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
301 | "Aborting incomplete namecache operation\n"); | ||
302 | GNUNET_NAMECACHE_cancel (cop->qe); | ||
303 | GNUNET_CONTAINER_DLL_remove (cop_head, cop_tail, cop); | ||
304 | GNUNET_free (cop); | ||
305 | } | ||
306 | |||
253 | while (NULL != (ma = it_head)) | 307 | while (NULL != (ma = it_head)) |
254 | { | 308 | { |
255 | GNUNET_DHT_put_cancel (ma->ph); | 309 | GNUNET_DHT_put_cancel (ma->ph); |
@@ -281,13 +335,78 @@ shutdown_task (void *cls) | |||
281 | GNUNET_NAMESTORE_disconnect (namestore_handle); | 335 | GNUNET_NAMESTORE_disconnect (namestore_handle); |
282 | namestore_handle = NULL; | 336 | namestore_handle = NULL; |
283 | } | 337 | } |
284 | if (NULL != dht_handle) | 338 | if (NULL != namecache) |
339 | { | ||
340 | GNUNET_NAMECACHE_disconnect (namecache); | ||
341 | namecache = NULL; | ||
342 | } | ||
343 | if (NULL != dht_handle) | ||
285 | { | 344 | { |
286 | GNUNET_DHT_disconnect (dht_handle); | 345 | GNUNET_DHT_disconnect (dht_handle); |
287 | dht_handle = NULL; | 346 | dht_handle = NULL; |
288 | } | 347 | } |
289 | } | 348 | } |
290 | 349 | ||
350 | /** | ||
351 | * Cache operation complete, clean up. | ||
352 | * | ||
353 | * @param cls the `struct CacheOperation` | ||
354 | * @param success success | ||
355 | * @param emsg error messages | ||
356 | */ | ||
357 | static void | ||
358 | finish_cache_operation (void *cls, int32_t success, const char *emsg) | ||
359 | { | ||
360 | struct CacheOperation *cop = cls; | ||
361 | |||
362 | if (NULL != emsg) | ||
363 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
364 | _ ("Failed to replicate block in namecache: %s\n"), | ||
365 | emsg); | ||
366 | else | ||
367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CACHE operation completed\n"); | ||
368 | GNUNET_CONTAINER_DLL_remove (cop_head, cop_tail, cop); | ||
369 | GNUNET_free (cop); | ||
370 | } | ||
371 | |||
372 | |||
373 | /** | ||
374 | * Refresh the (encrypted) block in the namecache. | ||
375 | * | ||
376 | * @param zone_key private key of the zone | ||
377 | * @param name label for the records | ||
378 | * @param rd_count number of records | ||
379 | * @param rd records stored under the given @a name | ||
380 | */ | ||
381 | static void | ||
382 | refresh_block (const struct GNUNET_GNSRECORD_Block *block) | ||
383 | { | ||
384 | struct CacheOperation *cop; | ||
385 | struct GNUNET_TIME_Absolute exp_time; | ||
386 | |||
387 | if (GNUNET_YES == disable_namecache) | ||
388 | { | ||
389 | GNUNET_STATISTICS_update (statistics, | ||
390 | "Namecache updates skipped (NC disabled)", | ||
391 | 1, | ||
392 | GNUNET_NO); | ||
393 | return; | ||
394 | } | ||
395 | GNUNET_assert (NULL != block); | ||
396 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Caching block in namecache\n"); | ||
397 | GNUNET_STATISTICS_update (statistics, | ||
398 | "Namecache updates pushed", | ||
399 | 1, | ||
400 | GNUNET_NO); | ||
401 | cop = GNUNET_new (struct CacheOperation); | ||
402 | GNUNET_CONTAINER_DLL_insert (cop_head, cop_tail, cop); | ||
403 | cop->qe = GNUNET_NAMECACHE_block_cache (namecache, | ||
404 | block, | ||
405 | &finish_cache_operation, | ||
406 | cop); | ||
407 | } | ||
408 | |||
409 | |||
291 | 410 | ||
292 | /** | 411 | /** |
293 | * Method called periodically that triggers iteration over authoritative records | 412 | * Method called periodically that triggers iteration over authoritative records |
@@ -539,35 +658,68 @@ dht_put_continuation (void *cls) | |||
539 | static struct GNUNET_DHT_PutHandle * | 658 | static struct GNUNET_DHT_PutHandle * |
540 | perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key, | 659 | perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key, |
541 | const char *label, | 660 | const char *label, |
542 | const struct GNUNET_GNSRECORD_Data *rd_public, | 661 | const struct GNUNET_GNSRECORD_Data *rd, |
543 | unsigned int rd_public_count, | 662 | unsigned int rd_count, |
544 | const struct GNUNET_TIME_Absolute expire, | 663 | const struct GNUNET_TIME_Absolute expire, |
545 | struct DhtPutActivity *ma) | 664 | struct DhtPutActivity *ma) |
546 | { | 665 | { |
666 | struct GNUNET_GNSRECORD_Data rd_public[rd_count]; | ||
547 | struct GNUNET_GNSRECORD_Block *block; | 667 | struct GNUNET_GNSRECORD_Block *block; |
668 | struct GNUNET_GNSRECORD_Block *block_priv; | ||
548 | struct GNUNET_HashCode query; | 669 | struct GNUNET_HashCode query; |
670 | struct GNUNET_TIME_Absolute expire_priv; | ||
549 | size_t block_size; | 671 | size_t block_size; |
672 | unsigned int rd_public_count = 0; | ||
550 | struct GNUNET_DHT_PutHandle *ret; | 673 | struct GNUNET_DHT_PutHandle *ret; |
674 | char *emsg; | ||
675 | |||
676 | if (GNUNET_OK != | ||
677 | GNUNET_GNSRECORD_normalize_record_set (label, | ||
678 | rd, | ||
679 | rd_count, | ||
680 | rd_public, | ||
681 | &rd_public_count, | ||
682 | &expire_priv, | ||
683 | GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE, | ||
684 | &emsg)) | ||
685 | { | ||
686 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
687 | "%s\n", emsg); | ||
688 | GNUNET_free (emsg); | ||
689 | } | ||
551 | 690 | ||
552 | if (cache_keys) | 691 | if (cache_keys) |
692 | { | ||
553 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create2 (key, | 693 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create2 (key, |
554 | expire, | 694 | expire, |
555 | label, | 695 | label, |
556 | rd_public, | 696 | rd_public, |
557 | rd_public_count, | 697 | rd_public_count, |
558 | &block)); | 698 | &block)); |
699 | } | ||
559 | else | 700 | else |
560 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (key, | 701 | { |
561 | expire, | 702 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (key, |
562 | label, | 703 | expire, |
563 | rd_public, | 704 | label, |
564 | rd_public_count, | 705 | rd_public, |
565 | &block)); | 706 | rd_public_count, |
707 | &block)); | ||
708 | } | ||
566 | if (NULL == block) | 709 | if (NULL == block) |
567 | { | 710 | { |
568 | GNUNET_break (0); | 711 | GNUNET_break (0); |
569 | return NULL; /* whoops */ | 712 | return NULL; /* whoops */ |
570 | } | 713 | } |
714 | if (rd_count != rd_public_count) | ||
715 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (key, | ||
716 | expire_priv, | ||
717 | label, | ||
718 | rd, | ||
719 | rd_count, | ||
720 | &block_priv)); | ||
721 | else | ||
722 | block_priv = block; | ||
571 | block_size = GNUNET_GNSRECORD_block_get_size (block); | 723 | block_size = GNUNET_GNSRECORD_block_get_size (block); |
572 | GNUNET_GNSRECORD_query_from_private_key (key, | 724 | GNUNET_GNSRECORD_query_from_private_key (key, |
573 | label, | 725 | label, |
@@ -593,6 +745,9 @@ perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key, | |||
593 | expire, | 745 | expire, |
594 | &dht_put_continuation, | 746 | &dht_put_continuation, |
595 | ma); | 747 | ma); |
748 | refresh_block (block_priv); | ||
749 | if (block != block_priv) | ||
750 | GNUNET_free (block_priv); | ||
596 | GNUNET_free (block); | 751 | GNUNET_free (block); |
597 | return ret; | 752 | return ret; |
598 | } | 753 | } |
@@ -783,7 +938,7 @@ publish_zone_dht_start (void *cls) | |||
783 | NULL, | 938 | NULL, |
784 | &zone_iteration_finished, | 939 | &zone_iteration_finished, |
785 | NULL, | 940 | NULL, |
786 | GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE); | 941 | GNUNET_GNSRECORD_FILTER_NONE); |
787 | GNUNET_assert (NULL != namestore_iter); | 942 | GNUNET_assert (NULL != namestore_iter); |
788 | } | 943 | } |
789 | 944 | ||
@@ -816,6 +971,20 @@ run (void *cls, | |||
816 | GNUNET_SCHEDULER_shutdown (); | 971 | GNUNET_SCHEDULER_shutdown (); |
817 | return; | 972 | return; |
818 | } | 973 | } |
974 | disable_namecache = GNUNET_CONFIGURATION_get_value_yesno (c, | ||
975 | "namecache", | ||
976 | "DISABLE"); | ||
977 | if (GNUNET_NO == disable_namecache) | ||
978 | { | ||
979 | namecache = GNUNET_NAMECACHE_connect (c); | ||
980 | if (NULL == namecache) | ||
981 | { | ||
982 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
983 | _ ("Failed to connect to the namecache!\n")); | ||
984 | GNUNET_SCHEDULER_shutdown (); | ||
985 | return; | ||
986 | } | ||
987 | } | ||
819 | cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c, | 988 | cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c, |
820 | "namestore", | 989 | "namestore", |
821 | "CACHE_KEYS"); | 990 | "CACHE_KEYS"); |