diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-05-10 11:24:16 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-05-10 11:24:16 +0200 |
commit | 4fe4c850dec0aff53510de7fdd7fce5fa870ae40 (patch) | |
tree | 99a36e9a2c43bbce4a90d26eb16d7f68efc81ebe /src/zonemaster | |
parent | b3bb9dcb3225fbbd9f04cb8d97f2b876b35104fd (diff) | |
download | gnunet-4fe4c850dec0aff53510de7fdd7fce5fa870ae40.tar.gz gnunet-4fe4c850dec0aff53510de7fdd7fce5fa870ae40.zip |
separate zonemaster monitoring functionality from main iterate-and-publish operation
Diffstat (limited to 'src/zonemaster')
-rw-r--r-- | src/zonemaster/.gitignore | 1 | ||||
-rw-r--r-- | src/zonemaster/Makefile.am | 17 | ||||
-rw-r--r-- | src/zonemaster/gnunet-service-zonemaster-monitor.c | 484 | ||||
-rw-r--r-- | src/zonemaster/gnunet-service-zonemaster.c | 198 | ||||
-rw-r--r-- | src/zonemaster/zonemaster.conf.in | 17 |
5 files changed, 519 insertions, 198 deletions
diff --git a/src/zonemaster/.gitignore b/src/zonemaster/.gitignore index 1a0e22b66..cde57fa0a 100644 --- a/src/zonemaster/.gitignore +++ b/src/zonemaster/.gitignore | |||
@@ -1 +1,2 @@ | |||
1 | gnunet-service-zonemaster | 1 | gnunet-service-zonemaster |
2 | gnunet-service-zonemaster-monitor | ||
diff --git a/src/zonemaster/Makefile.am b/src/zonemaster/Makefile.am index 21f986498..b655b9ef3 100644 --- a/src/zonemaster/Makefile.am +++ b/src/zonemaster/Makefile.am | |||
@@ -1,5 +1,5 @@ | |||
1 | # This Makefile.am is in the public domain | 1 | # This Makefile.am is in the public domain |
2 | AM_CPPFLAGS = -I$(top_srcdir)/src/include | 2 | AM_CPPFLAGS = -I$(top_srcdir)/src/include |
3 | 3 | ||
4 | plugindir = $(libdir)/gnunet | 4 | plugindir = $(libdir)/gnunet |
5 | 5 | ||
@@ -20,11 +20,11 @@ if USE_COVERAGE | |||
20 | endif | 20 | endif |
21 | 21 | ||
22 | libexec_PROGRAMS = \ | 22 | libexec_PROGRAMS = \ |
23 | gnunet-service-zonemaster | 23 | gnunet-service-zonemaster \ |
24 | gnunet-service-zonemaster-monitor | ||
24 | 25 | ||
25 | gnunet_service_zonemaster_SOURCES = \ | 26 | gnunet_service_zonemaster_SOURCES = \ |
26 | gnunet-service-zonemaster.c | 27 | gnunet-service-zonemaster.c |
27 | |||
28 | gnunet_service_zonemaster_LDADD = \ | 28 | gnunet_service_zonemaster_LDADD = \ |
29 | $(top_builddir)/src/dht/libgnunetdht.la \ | 29 | $(top_builddir)/src/dht/libgnunetdht.la \ |
30 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 30 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
@@ -33,3 +33,14 @@ gnunet_service_zonemaster_LDADD = \ | |||
33 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | 33 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
34 | $(GN_LIBINTL) | 34 | $(GN_LIBINTL) |
35 | 35 | ||
36 | |||
37 | gnunet_service_zonemaster_monitor_SOURCES = \ | ||
38 | gnunet-service-zonemaster-monitor.c | ||
39 | |||
40 | gnunet_service_zonemaster_monitor_LDADD = \ | ||
41 | $(top_builddir)/src/dht/libgnunetdht.la \ | ||
42 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
43 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
44 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
45 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
46 | $(GN_LIBINTL) | ||
diff --git a/src/zonemaster/gnunet-service-zonemaster-monitor.c b/src/zonemaster/gnunet-service-zonemaster-monitor.c new file mode 100644 index 000000000..a0c178511 --- /dev/null +++ b/src/zonemaster/gnunet-service-zonemaster-monitor.c | |||
@@ -0,0 +1,484 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2012, 2013, 2014, 2017, 2018 GNUnet e.V. | ||
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., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file zonemaster/gnunet-service-zonemaster-monitor.c | ||
23 | * @brief monitor namestore changes and publish them immediately to GNUnet name system | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_dht_service.h" | ||
29 | #include "gnunet_namestore_service.h" | ||
30 | #include "gnunet_statistics_service.h" | ||
31 | |||
32 | |||
33 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) | ||
34 | |||
35 | |||
36 | /** | ||
37 | * How often should we (re)publish each record before | ||
38 | * it expires? | ||
39 | */ | ||
40 | #define PUBLISH_OPS_PER_EXPIRATION 4 | ||
41 | |||
42 | /** | ||
43 | * How many pending DHT operations do we allow at most? | ||
44 | */ | ||
45 | #define DHT_QUEUE_LIMIT 2000 | ||
46 | |||
47 | /** | ||
48 | * How many events may the namestore give us before it has to wait | ||
49 | * for us to keep up? | ||
50 | */ | ||
51 | #define NAMESTORE_QUEUE_LIMIT 50 | ||
52 | |||
53 | /** | ||
54 | * What replication level do we use for DHT PUT operations? | ||
55 | */ | ||
56 | #define DHT_GNS_REPLICATION_LEVEL 5 | ||
57 | |||
58 | |||
59 | /** | ||
60 | * Handle for DHT PUT activity triggered from the namestore monitor. | ||
61 | */ | ||
62 | struct DhtPutActivity | ||
63 | { | ||
64 | /** | ||
65 | * Kept in a DLL. | ||
66 | */ | ||
67 | struct DhtPutActivity *next; | ||
68 | |||
69 | /** | ||
70 | * Kept in a DLL. | ||
71 | */ | ||
72 | struct DhtPutActivity *prev; | ||
73 | |||
74 | /** | ||
75 | * Handle for the DHT PUT operation. | ||
76 | */ | ||
77 | struct GNUNET_DHT_PutHandle *ph; | ||
78 | |||
79 | /** | ||
80 | * When was this PUT initiated? | ||
81 | */ | ||
82 | struct GNUNET_TIME_Absolute start_date; | ||
83 | }; | ||
84 | |||
85 | |||
86 | /** | ||
87 | * Handle to the statistics service | ||
88 | */ | ||
89 | static struct GNUNET_STATISTICS_Handle *statistics; | ||
90 | |||
91 | /** | ||
92 | * Our handle to the DHT | ||
93 | */ | ||
94 | static struct GNUNET_DHT_Handle *dht_handle; | ||
95 | |||
96 | /** | ||
97 | * Our handle to the namestore service | ||
98 | */ | ||
99 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | ||
100 | |||
101 | /** | ||
102 | * Handle to monitor namestore changes to instant propagation. | ||
103 | */ | ||
104 | static struct GNUNET_NAMESTORE_ZoneMonitor *zmon; | ||
105 | |||
106 | /** | ||
107 | * Head of monitor activities; kept in a DLL. | ||
108 | */ | ||
109 | static struct DhtPutActivity *ma_head; | ||
110 | |||
111 | /** | ||
112 | * Tail of monitor activities; kept in a DLL. | ||
113 | */ | ||
114 | static struct DhtPutActivity *ma_tail; | ||
115 | |||
116 | /** | ||
117 | * Number of entries in the DHT queue #ma_head. | ||
118 | */ | ||
119 | static unsigned int ma_queue_length; | ||
120 | |||
121 | /** | ||
122 | * Optimize block insertion by caching map of private keys to | ||
123 | * public keys in memory? | ||
124 | */ | ||
125 | static int cache_keys; | ||
126 | |||
127 | |||
128 | /** | ||
129 | * Task run during shutdown. | ||
130 | * | ||
131 | * @param cls unused | ||
132 | * @param tc unused | ||
133 | */ | ||
134 | static void | ||
135 | shutdown_task (void *cls) | ||
136 | { | ||
137 | struct DhtPutActivity *ma; | ||
138 | |||
139 | (void) cls; | ||
140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
141 | "Shutting down!\n"); | ||
142 | while (NULL != (ma = ma_head)) | ||
143 | { | ||
144 | GNUNET_DHT_put_cancel (ma->ph); | ||
145 | ma_queue_length--; | ||
146 | GNUNET_CONTAINER_DLL_remove (ma_head, | ||
147 | ma_tail, | ||
148 | ma); | ||
149 | GNUNET_free (ma); | ||
150 | } | ||
151 | if (NULL != statistics) | ||
152 | { | ||
153 | GNUNET_STATISTICS_destroy (statistics, | ||
154 | GNUNET_NO); | ||
155 | statistics = NULL; | ||
156 | } | ||
157 | if (NULL != zmon) | ||
158 | { | ||
159 | GNUNET_NAMESTORE_zone_monitor_stop (zmon); | ||
160 | zmon = NULL; | ||
161 | } | ||
162 | if (NULL != namestore_handle) | ||
163 | { | ||
164 | GNUNET_NAMESTORE_disconnect (namestore_handle); | ||
165 | namestore_handle = NULL; | ||
166 | } | ||
167 | if (NULL != dht_handle) | ||
168 | { | ||
169 | GNUNET_DHT_disconnect (dht_handle); | ||
170 | dht_handle = NULL; | ||
171 | } | ||
172 | } | ||
173 | |||
174 | |||
175 | /** | ||
176 | * Continuation called from DHT once the PUT operation triggered | ||
177 | * by a monitor is done. | ||
178 | * | ||
179 | * @param cls a `struct DhtPutActivity` | ||
180 | */ | ||
181 | static void | ||
182 | dht_put_monitor_continuation (void *cls) | ||
183 | { | ||
184 | struct DhtPutActivity *ma = cls; | ||
185 | |||
186 | GNUNET_NAMESTORE_zone_monitor_next (zmon, | ||
187 | 1); | ||
188 | ma_queue_length--; | ||
189 | GNUNET_CONTAINER_DLL_remove (ma_head, | ||
190 | ma_tail, | ||
191 | ma); | ||
192 | GNUNET_free (ma); | ||
193 | } | ||
194 | |||
195 | |||
196 | /** | ||
197 | * Convert namestore records from the internal format to that | ||
198 | * suitable for publication (removes private records, converts | ||
199 | * to absolute expiration time). | ||
200 | * | ||
201 | * @param rd input records | ||
202 | * @param rd_count size of the @a rd and @a rd_public arrays | ||
203 | * @param rd_public where to write the converted records | ||
204 | * @return number of records written to @a rd_public | ||
205 | */ | ||
206 | static unsigned int | ||
207 | convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd, | ||
208 | unsigned int rd_count, | ||
209 | struct GNUNET_GNSRECORD_Data *rd_public) | ||
210 | { | ||
211 | struct GNUNET_TIME_Absolute now; | ||
212 | unsigned int rd_public_count; | ||
213 | |||
214 | rd_public_count = 0; | ||
215 | now = GNUNET_TIME_absolute_get (); | ||
216 | for (unsigned int i=0;i<rd_count;i++) | ||
217 | if (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) | ||
218 | { | ||
219 | rd_public[rd_public_count] = rd[i]; | ||
220 | if (rd_public[rd_public_count].expiration_time < now.abs_value_us) | ||
221 | { | ||
222 | /* record already expired, skip it */ | ||
223 | continue; | ||
224 | } | ||
225 | rd_public_count++; | ||
226 | } | ||
227 | return rd_public_count; | ||
228 | } | ||
229 | |||
230 | |||
231 | /** | ||
232 | * Store GNS records in the DHT. | ||
233 | * | ||
234 | * @param key key of the zone | ||
235 | * @param label label to store under | ||
236 | * @param rd_public public record data | ||
237 | * @param rd_public_count number of records in @a rd_public | ||
238 | * @param cont function to call with PUT result | ||
239 | * @param cont_cls closure for @a cont | ||
240 | * @return DHT PUT handle, NULL on error | ||
241 | */ | ||
242 | static struct GNUNET_DHT_PutHandle * | ||
243 | perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | ||
244 | const char *label, | ||
245 | const struct GNUNET_GNSRECORD_Data *rd_public, | ||
246 | unsigned int rd_public_count, | ||
247 | GNUNET_SCHEDULER_TaskCallback cont, | ||
248 | void *cont_cls) | ||
249 | { | ||
250 | struct GNUNET_GNSRECORD_Block *block; | ||
251 | struct GNUNET_HashCode query; | ||
252 | struct GNUNET_TIME_Absolute expire; | ||
253 | size_t block_size; | ||
254 | struct GNUNET_DHT_PutHandle *ret; | ||
255 | |||
256 | expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count, | ||
257 | rd_public); | ||
258 | if (cache_keys) | ||
259 | block = GNUNET_GNSRECORD_block_create2 (key, | ||
260 | expire, | ||
261 | label, | ||
262 | rd_public, | ||
263 | rd_public_count); | ||
264 | else | ||
265 | block = GNUNET_GNSRECORD_block_create (key, | ||
266 | expire, | ||
267 | label, | ||
268 | rd_public, | ||
269 | rd_public_count); | ||
270 | if (NULL == block) | ||
271 | { | ||
272 | GNUNET_break (0); | ||
273 | return NULL; /* whoops */ | ||
274 | } | ||
275 | block_size = ntohl (block->purpose.size) | ||
276 | + sizeof (struct GNUNET_CRYPTO_EcdsaSignature) | ||
277 | + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
278 | GNUNET_GNSRECORD_query_from_private_key (key, | ||
279 | label, | ||
280 | &query); | ||
281 | GNUNET_STATISTICS_update (statistics, | ||
282 | "DHT put operations initiated", | ||
283 | 1, | ||
284 | GNUNET_NO); | ||
285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
286 | "Storing %u record(s) for label `%s' in DHT with expiration `%s' under key %s\n", | ||
287 | rd_public_count, | ||
288 | label, | ||
289 | GNUNET_STRINGS_absolute_time_to_string (expire), | ||
290 | GNUNET_h2s (&query)); | ||
291 | ret = GNUNET_DHT_put (dht_handle, | ||
292 | &query, | ||
293 | DHT_GNS_REPLICATION_LEVEL, | ||
294 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
295 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | ||
296 | block_size, | ||
297 | block, | ||
298 | expire, | ||
299 | cont, | ||
300 | cont_cls); | ||
301 | GNUNET_free (block); | ||
302 | return ret; | ||
303 | } | ||
304 | |||
305 | |||
306 | /** | ||
307 | * Process a record that was stored in the namestore | ||
308 | * (invoked by the monitor). | ||
309 | * | ||
310 | * @param cls closure, NULL | ||
311 | * @param zone private key of the zone; NULL on disconnect | ||
312 | * @param label label of the records; NULL on disconnect | ||
313 | * @param rd_count number of entries in @a rd array, 0 if label was deleted | ||
314 | * @param rd array of records with data to store | ||
315 | */ | ||
316 | static void | ||
317 | handle_monitor_event (void *cls, | ||
318 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | ||
319 | const char *label, | ||
320 | unsigned int rd_count, | ||
321 | const struct GNUNET_GNSRECORD_Data *rd) | ||
322 | { | ||
323 | struct GNUNET_GNSRECORD_Data rd_public[rd_count]; | ||
324 | unsigned int rd_public_count; | ||
325 | struct DhtPutActivity *ma; | ||
326 | |||
327 | (void) cls; | ||
328 | GNUNET_STATISTICS_update (statistics, | ||
329 | "Namestore monitor events received", | ||
330 | 1, | ||
331 | GNUNET_NO); | ||
332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
333 | "Received %u records for label `%s' via namestore monitor\n", | ||
334 | rd_count, | ||
335 | label); | ||
336 | /* filter out records that are not public, and convert to | ||
337 | absolute expiration time. */ | ||
338 | rd_public_count = convert_records_for_export (rd, | ||
339 | rd_count, | ||
340 | rd_public); | ||
341 | if (0 == rd_public_count) | ||
342 | { | ||
343 | GNUNET_NAMESTORE_zone_monitor_next (zmon, | ||
344 | 1); | ||
345 | return; /* nothing to do */ | ||
346 | } | ||
347 | ma = GNUNET_new (struct DhtPutActivity); | ||
348 | ma->start_date = GNUNET_TIME_absolute_get (); | ||
349 | ma->ph = perform_dht_put (zone, | ||
350 | label, | ||
351 | rd, | ||
352 | rd_count, | ||
353 | &dht_put_monitor_continuation, | ||
354 | ma); | ||
355 | if (NULL == ma->ph) | ||
356 | { | ||
357 | /* PUT failed, do not remember operation */ | ||
358 | GNUNET_free (ma); | ||
359 | GNUNET_NAMESTORE_zone_monitor_next (zmon, | ||
360 | 1); | ||
361 | return; | ||
362 | } | ||
363 | GNUNET_CONTAINER_DLL_insert_tail (ma_head, | ||
364 | ma_tail, | ||
365 | ma); | ||
366 | ma_queue_length++; | ||
367 | if (ma_queue_length > DHT_QUEUE_LIMIT) | ||
368 | { | ||
369 | ma = ma_head; | ||
370 | GNUNET_CONTAINER_DLL_remove (ma_head, | ||
371 | ma_tail, | ||
372 | ma); | ||
373 | GNUNET_DHT_put_cancel (ma->ph); | ||
374 | ma_queue_length--; | ||
375 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
376 | "DHT PUT unconfirmed after %s, aborting PUT\n", | ||
377 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (ma->start_date), | ||
378 | GNUNET_YES)); | ||
379 | GNUNET_free (ma); | ||
380 | } | ||
381 | } | ||
382 | |||
383 | |||
384 | /** | ||
385 | * The zone monitor encountered an IPC error trying to to get in | ||
386 | * sync. Restart from the beginning. | ||
387 | * | ||
388 | * @param cls NULL | ||
389 | */ | ||
390 | static void | ||
391 | handle_monitor_error (void *cls) | ||
392 | { | ||
393 | (void) cls; | ||
394 | GNUNET_STATISTICS_update (statistics, | ||
395 | "Namestore monitor errors encountered", | ||
396 | 1, | ||
397 | GNUNET_NO); | ||
398 | } | ||
399 | |||
400 | |||
401 | /** | ||
402 | * Performe zonemaster duties: watch namestore, publish records. | ||
403 | * | ||
404 | * @param cls closure | ||
405 | * @param server the initialized server | ||
406 | * @param c configuration to use | ||
407 | */ | ||
408 | static void | ||
409 | run (void *cls, | ||
410 | const struct GNUNET_CONFIGURATION_Handle *c, | ||
411 | struct GNUNET_SERVICE_Handle *service) | ||
412 | { | ||
413 | unsigned long long max_parallel_bg_queries = 128; | ||
414 | |||
415 | (void) cls; | ||
416 | (void) service; | ||
417 | namestore_handle = GNUNET_NAMESTORE_connect (c); | ||
418 | if (NULL == namestore_handle) | ||
419 | { | ||
420 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
421 | _("Failed to connect to the namestore!\n")); | ||
422 | GNUNET_SCHEDULER_shutdown (); | ||
423 | return; | ||
424 | } | ||
425 | cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c, | ||
426 | "namestore", | ||
427 | "CACHE_KEYS"); | ||
428 | if (GNUNET_OK == | ||
429 | GNUNET_CONFIGURATION_get_value_number (c, | ||
430 | "zonemaster", | ||
431 | "MAX_PARALLEL_BACKGROUND_QUERIES", | ||
432 | &max_parallel_bg_queries)) | ||
433 | { | ||
434 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
435 | "Number of allowed parallel background queries: %llu\n", | ||
436 | max_parallel_bg_queries); | ||
437 | } | ||
438 | if (0 == max_parallel_bg_queries) | ||
439 | max_parallel_bg_queries = 1; | ||
440 | dht_handle = GNUNET_DHT_connect (c, | ||
441 | (unsigned int) max_parallel_bg_queries); | ||
442 | if (NULL == dht_handle) | ||
443 | { | ||
444 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
445 | _("Could not connect to DHT!\n")); | ||
446 | GNUNET_SCHEDULER_add_now (&shutdown_task, | ||
447 | NULL); | ||
448 | return; | ||
449 | } | ||
450 | |||
451 | /* Schedule periodic put for our records. */ | ||
452 | statistics = GNUNET_STATISTICS_create ("zonemaster-mon", | ||
453 | c); | ||
454 | zmon = GNUNET_NAMESTORE_zone_monitor_start (c, | ||
455 | NULL, | ||
456 | GNUNET_NO, | ||
457 | &handle_monitor_error, | ||
458 | NULL, | ||
459 | &handle_monitor_event, | ||
460 | NULL, | ||
461 | NULL /* sync_cb */, | ||
462 | NULL); | ||
463 | GNUNET_NAMESTORE_zone_monitor_next (zmon, | ||
464 | NAMESTORE_QUEUE_LIMIT - 1); | ||
465 | GNUNET_break (NULL != zmon); | ||
466 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
467 | NULL); | ||
468 | } | ||
469 | |||
470 | |||
471 | /** | ||
472 | * Define "main" method using service macro. | ||
473 | */ | ||
474 | GNUNET_SERVICE_MAIN | ||
475 | ("zonemaster-monitor", | ||
476 | GNUNET_SERVICE_OPTION_NONE, | ||
477 | &run, | ||
478 | NULL, | ||
479 | NULL, | ||
480 | NULL, | ||
481 | GNUNET_MQ_handler_end()); | ||
482 | |||
483 | |||
484 | /* end of gnunet-service-zonemaster-monitor.c */ | ||
diff --git a/src/zonemaster/gnunet-service-zonemaster.c b/src/zonemaster/gnunet-service-zonemaster.c index 8220e6eab..482d3a203 100644 --- a/src/zonemaster/gnunet-service-zonemaster.c +++ b/src/zonemaster/gnunet-service-zonemaster.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2012, 2013, 2014, 2017 GNUnet e.V. | 3 | Copyright (C) 2012, 2013, 2014, 2017, 2018 GNUnet e.V. |
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 |
@@ -29,8 +29,6 @@ | |||
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_statistics_service.h" | 31 | #include "gnunet_statistics_service.h" |
32 | #include "gnunet_namestore_plugin.h" | ||
33 | #include "gnunet_signatures.h" | ||
34 | 32 | ||
35 | 33 | ||
36 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) | 34 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) |
@@ -90,11 +88,6 @@ | |||
90 | #define LATE_ITERATION_SPEEDUP_FACTOR 2 | 88 | #define LATE_ITERATION_SPEEDUP_FACTOR 2 |
91 | 89 | ||
92 | /** | 90 | /** |
93 | * How long until a DHT PUT attempt should time out? | ||
94 | */ | ||
95 | #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | ||
96 | |||
97 | /** | ||
98 | * What replication level do we use for DHT PUT operations? | 91 | * What replication level do we use for DHT PUT operations? |
99 | */ | 92 | */ |
100 | #define DHT_GNS_REPLICATION_LEVEL 5 | 93 | #define DHT_GNS_REPLICATION_LEVEL 5 |
@@ -148,21 +141,6 @@ static struct GNUNET_NAMESTORE_Handle *namestore_handle; | |||
148 | static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; | 141 | static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; |
149 | 142 | ||
150 | /** | 143 | /** |
151 | * Handle to monitor namestore changes to instant propagation. | ||
152 | */ | ||
153 | static struct GNUNET_NAMESTORE_ZoneMonitor *zmon; | ||
154 | |||
155 | /** | ||
156 | * Head of monitor activities; kept in a DLL. | ||
157 | */ | ||
158 | static struct DhtPutActivity *ma_head; | ||
159 | |||
160 | /** | ||
161 | * Tail of monitor activities; kept in a DLL. | ||
162 | */ | ||
163 | static struct DhtPutActivity *ma_tail; | ||
164 | |||
165 | /** | ||
166 | * Head of iteration put activities; kept in a DLL. | 144 | * Head of iteration put activities; kept in a DLL. |
167 | */ | 145 | */ |
168 | static struct DhtPutActivity *it_head; | 146 | static struct DhtPutActivity *it_head; |
@@ -281,15 +259,6 @@ shutdown_task (void *cls) | |||
281 | (void) cls; | 259 | (void) cls; |
282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 260 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
283 | "Shutting down!\n"); | 261 | "Shutting down!\n"); |
284 | while (NULL != (ma = ma_head)) | ||
285 | { | ||
286 | GNUNET_DHT_put_cancel (ma->ph); | ||
287 | ma_queue_length--; | ||
288 | GNUNET_CONTAINER_DLL_remove (ma_head, | ||
289 | ma_tail, | ||
290 | ma); | ||
291 | GNUNET_free (ma); | ||
292 | } | ||
293 | while (NULL != (ma = it_head)) | 262 | while (NULL != (ma = it_head)) |
294 | { | 263 | { |
295 | GNUNET_DHT_put_cancel (ma->ph); | 264 | GNUNET_DHT_put_cancel (ma->ph); |
@@ -316,11 +285,6 @@ shutdown_task (void *cls) | |||
316 | GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter); | 285 | GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter); |
317 | namestore_iter = NULL; | 286 | namestore_iter = NULL; |
318 | } | 287 | } |
319 | if (NULL != zmon) | ||
320 | { | ||
321 | GNUNET_NAMESTORE_zone_monitor_stop (zmon); | ||
322 | zmon = NULL; | ||
323 | } | ||
324 | if (NULL != namestore_handle) | 288 | if (NULL != namestore_handle) |
325 | { | 289 | { |
326 | GNUNET_NAMESTORE_disconnect (namestore_handle); | 290 | GNUNET_NAMESTORE_disconnect (namestore_handle); |
@@ -362,27 +326,6 @@ publish_zone_dht_start (void *cls); | |||
362 | 326 | ||
363 | 327 | ||
364 | /** | 328 | /** |
365 | * Continuation called from DHT once the PUT operation triggered | ||
366 | * by a monitor is done. | ||
367 | * | ||
368 | * @param cls a `struct DhtPutActivity` | ||
369 | */ | ||
370 | static void | ||
371 | dht_put_monitor_continuation (void *cls) | ||
372 | { | ||
373 | struct DhtPutActivity *ma = cls; | ||
374 | |||
375 | GNUNET_NAMESTORE_zone_monitor_next (zmon, | ||
376 | 1); | ||
377 | ma_queue_length--; | ||
378 | GNUNET_CONTAINER_DLL_remove (ma_head, | ||
379 | ma_tail, | ||
380 | ma); | ||
381 | GNUNET_free (ma); | ||
382 | } | ||
383 | |||
384 | |||
385 | /** | ||
386 | * Calculate #target_iteration_velocity_per_record. | 329 | * Calculate #target_iteration_velocity_per_record. |
387 | */ | 330 | */ |
388 | static void | 331 | static void |
@@ -884,131 +827,6 @@ publish_zone_dht_start (void *cls) | |||
884 | 827 | ||
885 | 828 | ||
886 | /** | 829 | /** |
887 | * Process a record that was stored in the namestore | ||
888 | * (invoked by the monitor). | ||
889 | * | ||
890 | * @param cls closure, NULL | ||
891 | * @param zone private key of the zone; NULL on disconnect | ||
892 | * @param label label of the records; NULL on disconnect | ||
893 | * @param rd_count number of entries in @a rd array, 0 if label was deleted | ||
894 | * @param rd array of records with data to store | ||
895 | */ | ||
896 | static void | ||
897 | handle_monitor_event (void *cls, | ||
898 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | ||
899 | const char *label, | ||
900 | unsigned int rd_count, | ||
901 | const struct GNUNET_GNSRECORD_Data *rd) | ||
902 | { | ||
903 | struct GNUNET_GNSRECORD_Data rd_public[rd_count]; | ||
904 | unsigned int rd_public_count; | ||
905 | struct DhtPutActivity *ma; | ||
906 | |||
907 | (void) cls; | ||
908 | GNUNET_STATISTICS_update (statistics, | ||
909 | "Namestore monitor events received", | ||
910 | 1, | ||
911 | GNUNET_NO); | ||
912 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
913 | "Received %u records for label `%s' via namestore monitor\n", | ||
914 | rd_count, | ||
915 | label); | ||
916 | /* filter out records that are not public, and convert to | ||
917 | absolute expiration time. */ | ||
918 | rd_public_count = convert_records_for_export (rd, | ||
919 | rd_count, | ||
920 | rd_public); | ||
921 | if (0 == rd_public_count) | ||
922 | { | ||
923 | GNUNET_NAMESTORE_zone_monitor_next (zmon, | ||
924 | 1); | ||
925 | return; /* nothing to do */ | ||
926 | } | ||
927 | num_public_records++; | ||
928 | ma = GNUNET_new (struct DhtPutActivity); | ||
929 | ma->start_date = GNUNET_TIME_absolute_get (); | ||
930 | ma->ph = perform_dht_put (zone, | ||
931 | label, | ||
932 | rd, | ||
933 | rd_count, | ||
934 | &dht_put_monitor_continuation, | ||
935 | ma); | ||
936 | if (NULL == ma->ph) | ||
937 | { | ||
938 | /* PUT failed, do not remember operation */ | ||
939 | GNUNET_free (ma); | ||
940 | GNUNET_NAMESTORE_zone_monitor_next (zmon, | ||
941 | 1); | ||
942 | return; | ||
943 | } | ||
944 | GNUNET_CONTAINER_DLL_insert_tail (ma_head, | ||
945 | ma_tail, | ||
946 | ma); | ||
947 | ma_queue_length++; | ||
948 | if (ma_queue_length > DHT_QUEUE_LIMIT) | ||
949 | { | ||
950 | ma = ma_head; | ||
951 | GNUNET_CONTAINER_DLL_remove (ma_head, | ||
952 | ma_tail, | ||
953 | ma); | ||
954 | GNUNET_DHT_put_cancel (ma->ph); | ||
955 | ma_queue_length--; | ||
956 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
957 | "DHT PUT unconfirmed after %s, aborting PUT\n", | ||
958 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (ma->start_date), | ||
959 | GNUNET_YES)); | ||
960 | GNUNET_free (ma); | ||
961 | } | ||
962 | } | ||
963 | |||
964 | |||
965 | /** | ||
966 | * The zone monitor is now in SYNC with the current state of the | ||
967 | * name store. Start to perform periodic iterations. | ||
968 | * | ||
969 | * @param cls NULL | ||
970 | */ | ||
971 | static void | ||
972 | monitor_sync_event (void *cls) | ||
973 | { | ||
974 | (void) cls; | ||
975 | if ( (NULL == zone_publish_task) && | ||
976 | (NULL == namestore_iter) ) | ||
977 | zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, | ||
978 | NULL); | ||
979 | } | ||
980 | |||
981 | |||
982 | /** | ||
983 | * The zone monitor encountered an IPC error trying to to get in | ||
984 | * sync. Restart from the beginning. | ||
985 | * | ||
986 | * @param cls NULL | ||
987 | */ | ||
988 | static void | ||
989 | handle_monitor_error (void *cls) | ||
990 | { | ||
991 | (void) cls; | ||
992 | GNUNET_STATISTICS_update (statistics, | ||
993 | "Namestore monitor errors encountered", | ||
994 | 1, | ||
995 | GNUNET_NO); | ||
996 | if (NULL != zone_publish_task) | ||
997 | { | ||
998 | GNUNET_SCHEDULER_cancel (zone_publish_task); | ||
999 | zone_publish_task = NULL; | ||
1000 | } | ||
1001 | if (NULL != namestore_iter) | ||
1002 | { | ||
1003 | GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter); | ||
1004 | namestore_iter = NULL; | ||
1005 | } | ||
1006 | zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, | ||
1007 | NULL); | ||
1008 | } | ||
1009 | |||
1010 | |||
1011 | /** | ||
1012 | * Performe zonemaster duties: watch namestore, publish records. | 830 | * Performe zonemaster duties: watch namestore, publish records. |
1013 | * | 831 | * |
1014 | * @param cls closure | 832 | * @param cls closure |
@@ -1084,18 +902,8 @@ run (void *cls, | |||
1084 | "Target zone iteration velocity (μs)", | 902 | "Target zone iteration velocity (μs)", |
1085 | target_iteration_velocity_per_record.rel_value_us, | 903 | target_iteration_velocity_per_record.rel_value_us, |
1086 | GNUNET_NO); | 904 | GNUNET_NO); |
1087 | zmon = GNUNET_NAMESTORE_zone_monitor_start (c, | 905 | zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, |
1088 | NULL, | 906 | NULL); |
1089 | GNUNET_NO, | ||
1090 | &handle_monitor_error, | ||
1091 | NULL, | ||
1092 | &handle_monitor_event, | ||
1093 | NULL, | ||
1094 | &monitor_sync_event, | ||
1095 | NULL); | ||
1096 | GNUNET_NAMESTORE_zone_monitor_next (zmon, | ||
1097 | NAMESTORE_QUEUE_LIMIT - 1); | ||
1098 | GNUNET_break (NULL != zmon); | ||
1099 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 907 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
1100 | NULL); | 908 | NULL); |
1101 | } | 909 | } |
diff --git a/src/zonemaster/zonemaster.conf.in b/src/zonemaster/zonemaster.conf.in index 871eb9c8f..6179b87be 100644 --- a/src/zonemaster/zonemaster.conf.in +++ b/src/zonemaster/zonemaster.conf.in | |||
@@ -23,3 +23,20 @@ ZONE_PUBLISH_TIME_WINDOW = 4 h | |||
23 | # USE_CACHE = YES | 23 | # USE_CACHE = YES |
24 | 24 | ||
25 | # PREFIX = valgrind --leak-check=full --track-origins=yes | 25 | # PREFIX = valgrind --leak-check=full --track-origins=yes |
26 | |||
27 | |||
28 | |||
29 | [zonemaster-monitor] | ||
30 | AUTOSTART = @AUTOSTART@ | ||
31 | FORCESTART = YES | ||
32 | HOSTNAME = localhost | ||
33 | BINARY = gnunet-service-zonemaster-monitor | ||
34 | UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-zonemaster-monitor.sock | ||
35 | @JAVAPORT@PORT = 2124 | ||
36 | |||
37 | # Do we require users that want to access GNS to run this process | ||
38 | # (usually not a good idea) | ||
39 | UNIX_MATCH_UID = NO | ||
40 | |||
41 | # Do we require users that want to access GNS to be in the 'gnunet' group? | ||
42 | UNIX_MATCH_GID = NO | ||