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