summaryrefslogtreecommitdiff
path: root/src/zonemaster/gnunet-service-zonemaster-monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/zonemaster/gnunet-service-zonemaster-monitor.c')
-rw-r--r--src/zonemaster/gnunet-service-zonemaster-monitor.c423
1 files changed, 211 insertions, 212 deletions
diff --git a/src/zonemaster/gnunet-service-zonemaster-monitor.c b/src/zonemaster/gnunet-service-zonemaster-monitor.c
index dfbd9cf03..3e1574238 100644
--- a/src/zonemaster/gnunet-service-zonemaster-monitor.c
+++ b/src/zonemaster/gnunet-service-zonemaster-monitor.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file zonemaster/gnunet-service-zonemaster-monitor.c 22 * @file zonemaster/gnunet-service-zonemaster-monitor.c
@@ -30,7 +30,7 @@
30#include "gnunet_statistics_service.h" 30#include "gnunet_statistics_service.h"
31 31
32 32
33#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) 33#define LOG_STRERROR_FILE(kind, syscall, filename) GNUNET_log_from_strerror_file(kind, "util", syscall, filename)
34 34
35 35
36/** 36/**
@@ -59,8 +59,7 @@
59/** 59/**
60 * Handle for DHT PUT activity triggered from the namestore monitor. 60 * Handle for DHT PUT activity triggered from the namestore monitor.
61 */ 61 */
62struct DhtPutActivity 62struct DhtPutActivity {
63{
64 /** 63 /**
65 * Kept in a DLL. 64 * Kept in a DLL.
66 */ 65 */
@@ -132,43 +131,43 @@ static int cache_keys;
132 * @param tc unused 131 * @param tc unused
133 */ 132 */
134static void 133static void
135shutdown_task (void *cls) 134shutdown_task(void *cls)
136{ 135{
137 struct DhtPutActivity *ma; 136 struct DhtPutActivity *ma;
138 137
139 (void) cls; 138 (void)cls;
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 139 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
141 "Shutting down!\n"); 140 "Shutting down!\n");
142 while (NULL != (ma = ma_head)) 141 while (NULL != (ma = ma_head))
143 { 142 {
144 GNUNET_DHT_put_cancel (ma->ph); 143 GNUNET_DHT_put_cancel(ma->ph);
145 ma_queue_length--; 144 ma_queue_length--;
146 GNUNET_CONTAINER_DLL_remove (ma_head, 145 GNUNET_CONTAINER_DLL_remove(ma_head,
147 ma_tail, 146 ma_tail,
148 ma); 147 ma);
149 GNUNET_free (ma); 148 GNUNET_free(ma);
150 } 149 }
151 if (NULL != statistics) 150 if (NULL != statistics)
152 { 151 {
153 GNUNET_STATISTICS_destroy (statistics, 152 GNUNET_STATISTICS_destroy(statistics,
154 GNUNET_NO); 153 GNUNET_NO);
155 statistics = NULL; 154 statistics = NULL;
156 } 155 }
157 if (NULL != zmon) 156 if (NULL != zmon)
158 { 157 {
159 GNUNET_NAMESTORE_zone_monitor_stop (zmon); 158 GNUNET_NAMESTORE_zone_monitor_stop(zmon);
160 zmon = NULL; 159 zmon = NULL;
161 } 160 }
162 if (NULL != namestore_handle) 161 if (NULL != namestore_handle)
163 { 162 {
164 GNUNET_NAMESTORE_disconnect (namestore_handle); 163 GNUNET_NAMESTORE_disconnect(namestore_handle);
165 namestore_handle = NULL; 164 namestore_handle = NULL;
166 } 165 }
167 if (NULL != dht_handle) 166 if (NULL != dht_handle)
168 { 167 {
169 GNUNET_DHT_disconnect (dht_handle); 168 GNUNET_DHT_disconnect(dht_handle);
170 dht_handle = NULL; 169 dht_handle = NULL;
171 } 170 }
172} 171}
173 172
174 173
@@ -179,17 +178,17 @@ shutdown_task (void *cls)
179 * @param cls a `struct DhtPutActivity` 178 * @param cls a `struct DhtPutActivity`
180 */ 179 */
181static void 180static void
182dht_put_monitor_continuation (void *cls) 181dht_put_monitor_continuation(void *cls)
183{ 182{
184 struct DhtPutActivity *ma = cls; 183 struct DhtPutActivity *ma = cls;
185 184
186 GNUNET_NAMESTORE_zone_monitor_next (zmon, 185 GNUNET_NAMESTORE_zone_monitor_next(zmon,
187 1); 186 1);
188 ma_queue_length--; 187 ma_queue_length--;
189 GNUNET_CONTAINER_DLL_remove (ma_head, 188 GNUNET_CONTAINER_DLL_remove(ma_head,
190 ma_tail, 189 ma_tail,
191 ma); 190 ma);
192 GNUNET_free (ma); 191 GNUNET_free(ma);
193} 192}
194 193
195 194
@@ -204,24 +203,24 @@ dht_put_monitor_continuation (void *cls)
204 * @return number of records written to @a rd_public 203 * @return number of records written to @a rd_public
205 */ 204 */
206static unsigned int 205static unsigned int
207convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd, 206convert_records_for_export(const struct GNUNET_GNSRECORD_Data *rd,
208 unsigned int rd_count, 207 unsigned int rd_count,
209 struct GNUNET_GNSRECORD_Data *rd_public) 208 struct GNUNET_GNSRECORD_Data *rd_public)
210{ 209{
211 struct GNUNET_TIME_Absolute now; 210 struct GNUNET_TIME_Absolute now;
212 unsigned int rd_public_count; 211 unsigned int rd_public_count;
213 212
214 rd_public_count = 0; 213 rd_public_count = 0;
215 now = GNUNET_TIME_absolute_get (); 214 now = GNUNET_TIME_absolute_get();
216 for (unsigned int i=0;i<rd_count;i++) 215 for (unsigned int i = 0; i < rd_count; i++)
217 { 216 {
218 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) 217 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
219 continue; 218 continue;
220 if ( (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) && 219 if ((0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
221 (rd[i].expiration_time < now.abs_value_us) ) 220 (rd[i].expiration_time < now.abs_value_us))
222 continue; /* record already expired, skip it */ 221 continue; /* record already expired, skip it */
223 rd_public[rd_public_count++] = rd[i]; 222 rd_public[rd_public_count++] = rd[i];
224 } 223 }
225 return rd_public_count; 224 return rd_public_count;
226} 225}
227 226
@@ -237,11 +236,11 @@ convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
237 * @return DHT PUT handle, NULL on error 236 * @return DHT PUT handle, NULL on error
238 */ 237 */
239static struct GNUNET_DHT_PutHandle * 238static struct GNUNET_DHT_PutHandle *
240perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, 239perform_dht_put(const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
241 const char *label, 240 const char *label,
242 const struct GNUNET_GNSRECORD_Data *rd_public, 241 const struct GNUNET_GNSRECORD_Data *rd_public,
243 unsigned int rd_public_count, 242 unsigned int rd_public_count,
244 struct DhtPutActivity *ma) 243 struct DhtPutActivity *ma)
245{ 244{
246 struct GNUNET_GNSRECORD_Block *block; 245 struct GNUNET_GNSRECORD_Block *block;
247 struct GNUNET_HashCode query; 246 struct GNUNET_HashCode query;
@@ -249,52 +248,52 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
249 size_t block_size; 248 size_t block_size;
250 struct GNUNET_DHT_PutHandle *ret; 249 struct GNUNET_DHT_PutHandle *ret;
251 250
252 expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count, 251 expire = GNUNET_GNSRECORD_record_get_expiration_time(rd_public_count,
253 rd_public); 252 rd_public);
254 if (cache_keys) 253 if (cache_keys)
255 block = GNUNET_GNSRECORD_block_create2 (key, 254 block = GNUNET_GNSRECORD_block_create2(key,
256 expire,
257 label,
258 rd_public,
259 rd_public_count);
260 else
261 block = GNUNET_GNSRECORD_block_create (key,
262 expire, 255 expire,
263 label, 256 label,
264 rd_public, 257 rd_public,
265 rd_public_count); 258 rd_public_count);
259 else
260 block = GNUNET_GNSRECORD_block_create(key,
261 expire,
262 label,
263 rd_public,
264 rd_public_count);
266 if (NULL == block) 265 if (NULL == block)
267 { 266 {
268 GNUNET_break (0); 267 GNUNET_break(0);
269 return NULL; /* whoops */ 268 return NULL; /* whoops */
270 } 269 }
271 block_size = ntohl (block->purpose.size) 270 block_size = ntohl(block->purpose.size)
272 + sizeof (struct GNUNET_CRYPTO_EcdsaSignature) 271 + sizeof(struct GNUNET_CRYPTO_EcdsaSignature)
273 + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); 272 + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey);
274 GNUNET_GNSRECORD_query_from_private_key (key, 273 GNUNET_GNSRECORD_query_from_private_key(key,
275 label, 274 label,
276 &query); 275 &query);
277 GNUNET_STATISTICS_update (statistics, 276 GNUNET_STATISTICS_update(statistics,
278 "DHT put operations initiated", 277 "DHT put operations initiated",
279 1, 278 1,
280 GNUNET_NO); 279 GNUNET_NO);
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 280 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
282 "Storing %u record(s) for label `%s' in DHT with expiration `%s' under key %s\n", 281 "Storing %u record(s) for label `%s' in DHT with expiration `%s' under key %s\n",
283 rd_public_count, 282 rd_public_count,
284 label, 283 label,
285 GNUNET_STRINGS_absolute_time_to_string (expire), 284 GNUNET_STRINGS_absolute_time_to_string(expire),
286 GNUNET_h2s (&query)); 285 GNUNET_h2s(&query));
287 ret = GNUNET_DHT_put (dht_handle, 286 ret = GNUNET_DHT_put(dht_handle,
288 &query, 287 &query,
289 DHT_GNS_REPLICATION_LEVEL, 288 DHT_GNS_REPLICATION_LEVEL,
290 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 289 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
291 GNUNET_BLOCK_TYPE_GNS_NAMERECORD, 290 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
292 block_size, 291 block_size,
293 block, 292 block,
294 expire, 293 expire,
295 &dht_put_monitor_continuation, 294 &dht_put_monitor_continuation,
296 ma); 295 ma);
297 GNUNET_free (block); 296 GNUNET_free(block);
298 return ret; 297 return ret;
299} 298}
300 299
@@ -310,69 +309,69 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
310 * @param rd array of records with data to store 309 * @param rd array of records with data to store
311 */ 310 */
312static void 311static void
313handle_monitor_event (void *cls, 312handle_monitor_event(void *cls,
314 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 313 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
315 const char *label, 314 const char *label,
316 unsigned int rd_count, 315 unsigned int rd_count,
317 const struct GNUNET_GNSRECORD_Data *rd) 316 const struct GNUNET_GNSRECORD_Data *rd)
318{ 317{
319 struct GNUNET_GNSRECORD_Data rd_public[rd_count]; 318 struct GNUNET_GNSRECORD_Data rd_public[rd_count];
320 unsigned int rd_public_count; 319 unsigned int rd_public_count;
321 struct DhtPutActivity *ma; 320 struct DhtPutActivity *ma;
322 321
323 (void) cls; 322 (void)cls;
324 GNUNET_STATISTICS_update (statistics, 323 GNUNET_STATISTICS_update(statistics,
325 "Namestore monitor events received", 324 "Namestore monitor events received",
326 1, 325 1,
327 GNUNET_NO); 326 GNUNET_NO);
328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 327 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
329 "Received %u records for label `%s' via namestore monitor\n", 328 "Received %u records for label `%s' via namestore monitor\n",
330 rd_count, 329 rd_count,
331 label); 330 label);
332 /* filter out records that are not public, and convert to 331 /* filter out records that are not public, and convert to
333 absolute expiration time. */ 332 absolute expiration time. */
334 rd_public_count = convert_records_for_export (rd, 333 rd_public_count = convert_records_for_export(rd,
335 rd_count, 334 rd_count,
336 rd_public); 335 rd_public);
337 if (0 == rd_public_count) 336 if (0 == rd_public_count)
338 { 337 {
339 GNUNET_NAMESTORE_zone_monitor_next (zmon, 338 GNUNET_NAMESTORE_zone_monitor_next(zmon,
340 1); 339 1);
341 return; /* nothing to do */ 340 return; /* nothing to do */
342 } 341 }
343 ma = GNUNET_new (struct DhtPutActivity); 342 ma = GNUNET_new(struct DhtPutActivity);
344 ma->start_date = GNUNET_TIME_absolute_get (); 343 ma->start_date = GNUNET_TIME_absolute_get();
345 ma->ph = perform_dht_put (zone, 344 ma->ph = perform_dht_put(zone,
346 label, 345 label,
347 rd, 346 rd,
348 rd_count, 347 rd_count,
349 ma); 348 ma);
350 if (NULL == ma->ph) 349 if (NULL == ma->ph)
351 { 350 {
352 /* PUT failed, do not remember operation */ 351 /* PUT failed, do not remember operation */
353 GNUNET_free (ma); 352 GNUNET_free(ma);
354 GNUNET_NAMESTORE_zone_monitor_next (zmon, 353 GNUNET_NAMESTORE_zone_monitor_next(zmon,
355 1); 354 1);
356 return; 355 return;
357 } 356 }
358 GNUNET_CONTAINER_DLL_insert_tail (ma_head, 357 GNUNET_CONTAINER_DLL_insert_tail(ma_head,
359 ma_tail, 358 ma_tail,
360 ma); 359 ma);
361 ma_queue_length++; 360 ma_queue_length++;
362 if (ma_queue_length > DHT_QUEUE_LIMIT) 361 if (ma_queue_length > DHT_QUEUE_LIMIT)
363 { 362 {
364 ma = ma_head; 363 ma = ma_head;
365 GNUNET_CONTAINER_DLL_remove (ma_head, 364 GNUNET_CONTAINER_DLL_remove(ma_head,
366 ma_tail, 365 ma_tail,
367 ma); 366 ma);
368 GNUNET_DHT_put_cancel (ma->ph); 367 GNUNET_DHT_put_cancel(ma->ph);
369 ma_queue_length--; 368 ma_queue_length--;
370 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 369 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
371 "DHT PUT unconfirmed after %s, aborting PUT\n", 370 "DHT PUT unconfirmed after %s, aborting PUT\n",
372 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (ma->start_date), 371 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(ma->start_date),
373 GNUNET_YES)); 372 GNUNET_YES));
374 GNUNET_free (ma); 373 GNUNET_free(ma);
375 } 374 }
376} 375}
377 376
378 377
@@ -383,13 +382,13 @@ handle_monitor_event (void *cls,
383 * @param cls NULL 382 * @param cls NULL
384 */ 383 */
385static void 384static void
386handle_monitor_error (void *cls) 385handle_monitor_error(void *cls)
387{ 386{
388 (void) cls; 387 (void)cls;
389 GNUNET_STATISTICS_update (statistics, 388 GNUNET_STATISTICS_update(statistics,
390 "Namestore monitor errors encountered", 389 "Namestore monitor errors encountered",
391 1, 390 1,
392 GNUNET_NO); 391 GNUNET_NO);
393} 392}
394 393
395 394
@@ -401,65 +400,65 @@ handle_monitor_error (void *cls)
401 * @param c configuration to use 400 * @param c configuration to use
402 */ 401 */
403static void 402static void
404run (void *cls, 403run(void *cls,
405 const struct GNUNET_CONFIGURATION_Handle *c, 404 const struct GNUNET_CONFIGURATION_Handle *c,
406 struct GNUNET_SERVICE_Handle *service) 405 struct GNUNET_SERVICE_Handle *service)
407{ 406{
408 unsigned long long max_parallel_bg_queries = 128; 407 unsigned long long max_parallel_bg_queries = 128;
409 408
410 (void) cls; 409 (void)cls;
411 (void) service; 410 (void)service;
412 namestore_handle = GNUNET_NAMESTORE_connect (c); 411 namestore_handle = GNUNET_NAMESTORE_connect(c);
413 if (NULL == namestore_handle) 412 if (NULL == namestore_handle)
414 { 413 {
415 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 414 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
416 _("Failed to connect to the namestore!\n")); 415 _("Failed to connect to the namestore!\n"));
417 GNUNET_SCHEDULER_shutdown (); 416 GNUNET_SCHEDULER_shutdown();
418 return; 417 return;
419 } 418 }
420 cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c, 419 cache_keys = GNUNET_CONFIGURATION_get_value_yesno(c,
421 "namestore", 420 "namestore",
422 "CACHE_KEYS"); 421 "CACHE_KEYS");
423 if (GNUNET_OK == 422 if (GNUNET_OK ==
424 GNUNET_CONFIGURATION_get_value_number (c, 423 GNUNET_CONFIGURATION_get_value_number(c,
425 "zonemaster", 424 "zonemaster",
426 "MAX_PARALLEL_BACKGROUND_QUERIES", 425 "MAX_PARALLEL_BACKGROUND_QUERIES",
427 &max_parallel_bg_queries)) 426 &max_parallel_bg_queries))
428 { 427 {
429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 428 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
430 "Number of allowed parallel background queries: %llu\n", 429 "Number of allowed parallel background queries: %llu\n",
431 max_parallel_bg_queries); 430 max_parallel_bg_queries);
432 } 431 }
433 if (0 == max_parallel_bg_queries) 432 if (0 == max_parallel_bg_queries)
434 max_parallel_bg_queries = 1; 433 max_parallel_bg_queries = 1;
435 dht_handle = GNUNET_DHT_connect (c, 434 dht_handle = GNUNET_DHT_connect(c,
436 (unsigned int) max_parallel_bg_queries); 435 (unsigned int)max_parallel_bg_queries);
437 if (NULL == dht_handle) 436 if (NULL == dht_handle)
438 { 437 {
439 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 438 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
440 _("Could not connect to DHT!\n")); 439 _("Could not connect to DHT!\n"));
441 GNUNET_SCHEDULER_add_now (&shutdown_task, 440 GNUNET_SCHEDULER_add_now(&shutdown_task,
442 NULL); 441 NULL);
443 return; 442 return;
444 } 443 }
445 444
446 /* Schedule periodic put for our records. */ 445 /* Schedule periodic put for our records. */
447 statistics = GNUNET_STATISTICS_create ("zonemaster-mon", 446 statistics = GNUNET_STATISTICS_create("zonemaster-mon",
448 c); 447 c);
449 zmon = GNUNET_NAMESTORE_zone_monitor_start (c, 448 zmon = GNUNET_NAMESTORE_zone_monitor_start(c,
450 NULL, 449 NULL,
451 GNUNET_NO, 450 GNUNET_NO,
452 &handle_monitor_error, 451 &handle_monitor_error,
453 NULL, 452 NULL,
454 &handle_monitor_event, 453 &handle_monitor_event,
455 NULL, 454 NULL,
456 NULL /* sync_cb */, 455 NULL /* sync_cb */,
457 NULL); 456 NULL);
458 GNUNET_NAMESTORE_zone_monitor_next (zmon, 457 GNUNET_NAMESTORE_zone_monitor_next(zmon,
459 NAMESTORE_QUEUE_LIMIT - 1); 458 NAMESTORE_QUEUE_LIMIT - 1);
460 GNUNET_break (NULL != zmon); 459 GNUNET_break(NULL != zmon);
461 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 460 GNUNET_SCHEDULER_add_shutdown(&shutdown_task,
462 NULL); 461 NULL);
463} 462}
464 463
465 464
@@ -467,13 +466,13 @@ run (void *cls,
467 * Define "main" method using service macro. 466 * Define "main" method using service macro.
468 */ 467 */
469GNUNET_SERVICE_MAIN 468GNUNET_SERVICE_MAIN
470("zonemaster-monitor", 469 ("zonemaster-monitor",
471 GNUNET_SERVICE_OPTION_NONE, 470 GNUNET_SERVICE_OPTION_NONE,
472 &run, 471 &run,
473 NULL, 472 NULL,
474 NULL, 473 NULL,
475 NULL, 474 NULL,
476 GNUNET_MQ_handler_end()); 475 GNUNET_MQ_handler_end());
477 476
478 477
479/* end of gnunet-service-zonemaster-monitor.c */ 478/* end of gnunet-service-zonemaster-monitor.c */