diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/statistics/gnunet-service-statistics.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/statistics/gnunet-service-statistics.c')
-rw-r--r-- | src/statistics/gnunet-service-statistics.c | 853 |
1 files changed, 424 insertions, 429 deletions
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c index 18905f458..7d84f421e 100644 --- a/src/statistics/gnunet-service-statistics.c +++ b/src/statistics/gnunet-service-statistics.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 statistics/gnunet-service-statistics.c | 22 | * @file statistics/gnunet-service-statistics.c |
@@ -38,9 +38,7 @@ | |||
38 | /** | 38 | /** |
39 | * Watch entry. | 39 | * Watch entry. |
40 | */ | 40 | */ |
41 | struct WatchEntry | 41 | struct WatchEntry { |
42 | { | ||
43 | |||
44 | /** | 42 | /** |
45 | * Watch entries are kept in a linked list. | 43 | * Watch entries are kept in a linked list. |
46 | */ | 44 | */ |
@@ -84,8 +82,7 @@ struct SubsystemEntry; | |||
84 | /** | 82 | /** |
85 | * Entry in the statistics list. | 83 | * Entry in the statistics list. |
86 | */ | 84 | */ |
87 | struct StatsEntry | 85 | struct StatsEntry { |
88 | { | ||
89 | /** | 86 | /** |
90 | * This is a linked list. | 87 | * This is a linked list. |
91 | */ | 88 | */ |
@@ -144,8 +141,7 @@ struct StatsEntry | |||
144 | * We keep the statistics organized by subsystem for faster | 141 | * We keep the statistics organized by subsystem for faster |
145 | * lookup during SET operations. | 142 | * lookup during SET operations. |
146 | */ | 143 | */ |
147 | struct SubsystemEntry | 144 | struct SubsystemEntry { |
148 | { | ||
149 | /** | 145 | /** |
150 | * Subsystems are kept in a DLL. | 146 | * Subsystems are kept in a DLL. |
151 | */ | 147 | */ |
@@ -177,8 +173,7 @@ struct SubsystemEntry | |||
177 | /** | 173 | /** |
178 | * Client entry. | 174 | * Client entry. |
179 | */ | 175 | */ |
180 | struct ClientEntry | 176 | struct ClientEntry { |
181 | { | ||
182 | /** | 177 | /** |
183 | * Corresponding server handle. | 178 | * Corresponding server handle. |
184 | */ | 179 | */ |
@@ -241,7 +236,7 @@ static int in_shutdown; | |||
241 | * Write persistent statistics to disk. | 236 | * Write persistent statistics to disk. |
242 | */ | 237 | */ |
243 | static void | 238 | static void |
244 | save () | 239 | save() |
245 | { | 240 | { |
246 | struct SubsystemEntry *se; | 241 | struct SubsystemEntry *se; |
247 | struct StatsEntry *pos; | 242 | struct StatsEntry *pos; |
@@ -253,74 +248,74 @@ save () | |||
253 | size_t slen; | 248 | size_t slen; |
254 | struct GNUNET_STATISTICS_SetMessage *msg; | 249 | struct GNUNET_STATISTICS_SetMessage *msg; |
255 | 250 | ||
256 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, | 251 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, |
257 | "STATISTICS", | 252 | "STATISTICS", |
258 | "DATABASE", | 253 | "DATABASE", |
259 | &fn)) | 254 | &fn)) |
260 | { | 255 | { |
261 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 256 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
262 | "STATISTICS", | 257 | "STATISTICS", |
263 | "DATABASE"); | 258 | "DATABASE"); |
264 | return; | 259 | return; |
265 | } | 260 | } |
266 | (void) GNUNET_DISK_directory_create_for_file (fn); | 261 | (void)GNUNET_DISK_directory_create_for_file(fn); |
267 | wh = GNUNET_BIO_write_open (fn); | 262 | wh = GNUNET_BIO_write_open(fn); |
268 | total = 0; | 263 | total = 0; |
269 | while (NULL != (se = sub_head)) | 264 | while (NULL != (se = sub_head)) |
270 | { | ||
271 | GNUNET_CONTAINER_DLL_remove (sub_head, sub_tail, se); | ||
272 | slen = strlen (se->service) + 1; | ||
273 | while (NULL != (pos = se->stat_head)) | ||
274 | { | 265 | { |
275 | GNUNET_CONTAINER_DLL_remove (se->stat_head, se->stat_tail, pos); | 266 | GNUNET_CONTAINER_DLL_remove(sub_head, sub_tail, se); |
276 | if ((pos->persistent) && (NULL != wh)) | 267 | slen = strlen(se->service) + 1; |
277 | { | 268 | while (NULL != (pos = se->stat_head)) |
278 | nlen = strlen (pos->name) + 1; | ||
279 | size = sizeof (struct GNUNET_STATISTICS_SetMessage) + nlen + slen; | ||
280 | GNUNET_assert (size < UINT16_MAX); | ||
281 | msg = GNUNET_malloc (size); | ||
282 | |||
283 | msg->header.size = htons ((uint16_t) size); | ||
284 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET); | ||
285 | GNUNET_assert (nlen + slen == | ||
286 | GNUNET_STRINGS_buffer_fill ((char *) &msg[1], | ||
287 | nlen + slen, | ||
288 | 2, | ||
289 | se->service, | ||
290 | pos->name)); | ||
291 | msg->flags = | ||
292 | htonl (pos->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0); | ||
293 | msg->value = GNUNET_htonll (pos->value); | ||
294 | if (GNUNET_OK != GNUNET_BIO_write (wh, msg, size)) | ||
295 | { | 269 | { |
296 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); | 270 | GNUNET_CONTAINER_DLL_remove(se->stat_head, se->stat_tail, pos); |
297 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 271 | if ((pos->persistent) && (NULL != wh)) |
298 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn); | 272 | { |
299 | wh = NULL; | 273 | nlen = strlen(pos->name) + 1; |
274 | size = sizeof(struct GNUNET_STATISTICS_SetMessage) + nlen + slen; | ||
275 | GNUNET_assert(size < UINT16_MAX); | ||
276 | msg = GNUNET_malloc(size); | ||
277 | |||
278 | msg->header.size = htons((uint16_t)size); | ||
279 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_STATISTICS_SET); | ||
280 | GNUNET_assert(nlen + slen == | ||
281 | GNUNET_STRINGS_buffer_fill((char *)&msg[1], | ||
282 | nlen + slen, | ||
283 | 2, | ||
284 | se->service, | ||
285 | pos->name)); | ||
286 | msg->flags = | ||
287 | htonl(pos->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0); | ||
288 | msg->value = GNUNET_htonll(pos->value); | ||
289 | if (GNUNET_OK != GNUNET_BIO_write(wh, msg, size)) | ||
290 | { | ||
291 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "write", fn); | ||
292 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) | ||
293 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "close", fn); | ||
294 | wh = NULL; | ||
295 | } | ||
296 | else | ||
297 | { | ||
298 | total += size; | ||
299 | } | ||
300 | GNUNET_free(msg); | ||
301 | } | ||
302 | GNUNET_free(pos); | ||
300 | } | 303 | } |
301 | else | 304 | GNUNET_free(se); |
302 | { | ||
303 | total += size; | ||
304 | } | ||
305 | GNUNET_free (msg); | ||
306 | } | ||
307 | GNUNET_free (pos); | ||
308 | } | 305 | } |
309 | GNUNET_free (se); | ||
310 | } | ||
311 | if (NULL != wh) | 306 | if (NULL != wh) |
312 | { | 307 | { |
313 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 308 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
314 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn); | 309 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "close", fn); |
315 | if (0 == total) | 310 | if (0 == total) |
316 | GNUNET_break (0 == unlink (fn)); | 311 | GNUNET_break(0 == unlink(fn)); |
317 | else | 312 | else |
318 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 313 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
319 | _ ("Wrote %llu bytes of statistics to `%s'\n"), | 314 | _("Wrote %llu bytes of statistics to `%s'\n"), |
320 | total, | 315 | total, |
321 | fn); | 316 | fn); |
322 | } | 317 | } |
323 | GNUNET_free_non_null (fn); | 318 | GNUNET_free_non_null(fn); |
324 | } | 319 | } |
325 | 320 | ||
326 | 321 | ||
@@ -331,31 +326,31 @@ save () | |||
331 | * @param e value to transmit | 326 | * @param e value to transmit |
332 | */ | 327 | */ |
333 | static void | 328 | static void |
334 | transmit (struct ClientEntry *ce, const struct StatsEntry *e) | 329 | transmit(struct ClientEntry *ce, const struct StatsEntry *e) |
335 | { | 330 | { |
336 | struct GNUNET_MQ_Envelope *env; | 331 | struct GNUNET_MQ_Envelope *env; |
337 | struct GNUNET_STATISTICS_ReplyMessage *m; | 332 | struct GNUNET_STATISTICS_ReplyMessage *m; |
338 | size_t size; | 333 | size_t size; |
339 | 334 | ||
340 | size = strlen (e->subsystem->service) + 1 + strlen (e->name) + 1; | 335 | size = strlen(e->subsystem->service) + 1 + strlen(e->name) + 1; |
341 | GNUNET_assert (size < GNUNET_MAX_MESSAGE_SIZE); | 336 | GNUNET_assert(size < GNUNET_MAX_MESSAGE_SIZE); |
342 | env = GNUNET_MQ_msg_extra (m, size, GNUNET_MESSAGE_TYPE_STATISTICS_VALUE); | 337 | env = GNUNET_MQ_msg_extra(m, size, GNUNET_MESSAGE_TYPE_STATISTICS_VALUE); |
343 | m->uid = htonl (e->uid); | 338 | m->uid = htonl(e->uid); |
344 | if (e->persistent) | 339 | if (e->persistent) |
345 | m->uid |= htonl (GNUNET_STATISTICS_PERSIST_BIT); | 340 | m->uid |= htonl(GNUNET_STATISTICS_PERSIST_BIT); |
346 | m->value = GNUNET_htonll (e->value); | 341 | m->value = GNUNET_htonll(e->value); |
347 | GNUNET_assert (size == GNUNET_STRINGS_buffer_fill ((char *) &m[1], | 342 | GNUNET_assert(size == GNUNET_STRINGS_buffer_fill((char *)&m[1], |
348 | size, | 343 | size, |
349 | 2, | 344 | 2, |
350 | e->subsystem->service, | 345 | e->subsystem->service, |
351 | e->name)); | 346 | e->name)); |
352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 347 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
353 | "Transmitting value for `%s:%s' (%d): %llu\n", | 348 | "Transmitting value for `%s:%s' (%d): %llu\n", |
354 | e->subsystem->service, | 349 | e->subsystem->service, |
355 | e->name, | 350 | e->name, |
356 | e->persistent, | 351 | e->persistent, |
357 | (unsigned long long) e->value); | 352 | (unsigned long long)e->value); |
358 | GNUNET_MQ_send (ce->mq, env); | 353 | GNUNET_MQ_send(ce->mq, env); |
359 | } | 354 | } |
360 | 355 | ||
361 | 356 | ||
@@ -368,17 +363,17 @@ transmit (struct ClientEntry *ce, const struct StatsEntry *e) | |||
368 | * @return @a c | 363 | * @return @a c |
369 | */ | 364 | */ |
370 | static void * | 365 | static void * |
371 | client_connect_cb (void *cls, | 366 | client_connect_cb(void *cls, |
372 | struct GNUNET_SERVICE_Client *c, | 367 | struct GNUNET_SERVICE_Client *c, |
373 | struct GNUNET_MQ_Handle *mq) | 368 | struct GNUNET_MQ_Handle *mq) |
374 | { | 369 | { |
375 | struct ClientEntry *ce; | 370 | struct ClientEntry *ce; |
376 | 371 | ||
377 | ce = GNUNET_new (struct ClientEntry); | 372 | ce = GNUNET_new(struct ClientEntry); |
378 | ce->client = c; | 373 | ce->client = c; |
379 | ce->mq = mq; | 374 | ce->mq = mq; |
380 | client_count++; | 375 | client_count++; |
381 | GNUNET_notification_context_add (nc, mq); | 376 | GNUNET_notification_context_add(nc, mq); |
382 | return ce; | 377 | return ce; |
383 | } | 378 | } |
384 | 379 | ||
@@ -391,22 +386,22 @@ client_connect_cb (void *cls, | |||
391 | * @return #GNUNET_OK if @a message is well-formed | 386 | * @return #GNUNET_OK if @a message is well-formed |
392 | */ | 387 | */ |
393 | static int | 388 | static int |
394 | check_get (void *cls, const struct GNUNET_MessageHeader *message) | 389 | check_get(void *cls, const struct GNUNET_MessageHeader *message) |
395 | { | 390 | { |
396 | const char *service; | 391 | const char *service; |
397 | const char *name; | 392 | const char *name; |
398 | size_t size; | 393 | size_t size; |
399 | 394 | ||
400 | size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader); | 395 | size = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader); |
401 | if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], | 396 | if (size != GNUNET_STRINGS_buffer_tokenize((const char *)&message[1], |
402 | size, | 397 | size, |
403 | 2, | 398 | 2, |
404 | &service, | 399 | &service, |
405 | &name)) | 400 | &name)) |
406 | { | 401 | { |
407 | GNUNET_break (0); | 402 | GNUNET_break(0); |
408 | return GNUNET_SYSERR; | 403 | return GNUNET_SYSERR; |
409 | } | 404 | } |
410 | return GNUNET_OK; | 405 | return GNUNET_OK; |
411 | } | 406 | } |
412 | 407 | ||
@@ -418,7 +413,7 @@ check_get (void *cls, const struct GNUNET_MessageHeader *message) | |||
418 | * @param message the actual message | 413 | * @param message the actual message |
419 | */ | 414 | */ |
420 | static void | 415 | static void |
421 | handle_get (void *cls, const struct GNUNET_MessageHeader *message) | 416 | handle_get(void *cls, const struct GNUNET_MessageHeader *message) |
422 | { | 417 | { |
423 | struct ClientEntry *ce = cls; | 418 | struct ClientEntry *ce = cls; |
424 | struct GNUNET_MQ_Envelope *env; | 419 | struct GNUNET_MQ_Envelope *env; |
@@ -431,33 +426,33 @@ handle_get (void *cls, const struct GNUNET_MessageHeader *message) | |||
431 | struct StatsEntry *pos; | 426 | struct StatsEntry *pos; |
432 | size_t size; | 427 | size_t size; |
433 | 428 | ||
434 | size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader); | 429 | size = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader); |
435 | GNUNET_assert (size == | 430 | GNUNET_assert(size == |
436 | GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], | 431 | GNUNET_STRINGS_buffer_tokenize((const char *)&message[1], |
437 | size, | 432 | size, |
438 | 2, | 433 | 2, |
439 | &service, | 434 | &service, |
440 | &name)); | 435 | &name)); |
441 | slen = strlen (service); | 436 | slen = strlen(service); |
442 | nlen = strlen (name); | 437 | nlen = strlen(name); |
443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 438 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
444 | "Received request for statistics on `%s:%s'\n", | 439 | "Received request for statistics on `%s:%s'\n", |
445 | slen ? service : "*", | 440 | slen ? service : "*", |
446 | nlen ? name : "*"); | 441 | nlen ? name : "*"); |
447 | for (se = sub_head; NULL != se; se = se->next) | 442 | for (se = sub_head; NULL != se; se = se->next) |
448 | { | ||
449 | if (! ((0 == slen) || (0 == strcmp (service, se->service)))) | ||
450 | continue; | ||
451 | for (pos = se->stat_head; NULL != pos; pos = pos->next) | ||
452 | { | 443 | { |
453 | if (! ((0 == nlen) || (0 == strcmp (name, pos->name)))) | 444 | if (!((0 == slen) || (0 == strcmp(service, se->service)))) |
454 | continue; | 445 | continue; |
455 | transmit (ce, pos); | 446 | for (pos = se->stat_head; NULL != pos; pos = pos->next) |
447 | { | ||
448 | if (!((0 == nlen) || (0 == strcmp(name, pos->name)))) | ||
449 | continue; | ||
450 | transmit(ce, pos); | ||
451 | } | ||
456 | } | 452 | } |
457 | } | 453 | env = GNUNET_MQ_msg(end, GNUNET_MESSAGE_TYPE_STATISTICS_END); |
458 | env = GNUNET_MQ_msg (end, GNUNET_MESSAGE_TYPE_STATISTICS_END); | 454 | GNUNET_MQ_send(ce->mq, env); |
459 | GNUNET_MQ_send (ce->mq, env); | 455 | GNUNET_SERVICE_client_continue(ce->client); |
460 | GNUNET_SERVICE_client_continue (ce->client); | ||
461 | } | 456 | } |
462 | 457 | ||
463 | 458 | ||
@@ -467,32 +462,32 @@ handle_get (void *cls, const struct GNUNET_MessageHeader *message) | |||
467 | * @param se value that changed | 462 | * @param se value that changed |
468 | */ | 463 | */ |
469 | static void | 464 | static void |
470 | notify_change (struct StatsEntry *se) | 465 | notify_change(struct StatsEntry *se) |
471 | { | 466 | { |
472 | struct GNUNET_MQ_Envelope *env; | 467 | struct GNUNET_MQ_Envelope *env; |
473 | struct GNUNET_STATISTICS_WatchValueMessage *wvm; | 468 | struct GNUNET_STATISTICS_WatchValueMessage *wvm; |
474 | struct WatchEntry *pos; | 469 | struct WatchEntry *pos; |
475 | 470 | ||
476 | for (pos = se->we_head; NULL != pos; pos = pos->next) | 471 | for (pos = se->we_head; NULL != pos; pos = pos->next) |
477 | { | ||
478 | if (GNUNET_YES == pos->last_value_set) | ||
479 | { | ||
480 | if (pos->last_value == se->value) | ||
481 | continue; | ||
482 | } | ||
483 | else | ||
484 | { | 472 | { |
485 | pos->last_value_set = GNUNET_YES; | 473 | if (GNUNET_YES == pos->last_value_set) |
474 | { | ||
475 | if (pos->last_value == se->value) | ||
476 | continue; | ||
477 | } | ||
478 | else | ||
479 | { | ||
480 | pos->last_value_set = GNUNET_YES; | ||
481 | } | ||
482 | env = GNUNET_MQ_msg(wvm, GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE); | ||
483 | wvm->flags = | ||
484 | htonl(se->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0); | ||
485 | wvm->wid = htonl(pos->wid); | ||
486 | wvm->reserved = htonl(0); | ||
487 | wvm->value = GNUNET_htonll(se->value); | ||
488 | GNUNET_MQ_send(pos->ce->mq, env); | ||
489 | pos->last_value = se->value; | ||
486 | } | 490 | } |
487 | env = GNUNET_MQ_msg (wvm, GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE); | ||
488 | wvm->flags = | ||
489 | htonl (se->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0); | ||
490 | wvm->wid = htonl (pos->wid); | ||
491 | wvm->reserved = htonl (0); | ||
492 | wvm->value = GNUNET_htonll (se->value); | ||
493 | GNUNET_MQ_send (pos->ce->mq, env); | ||
494 | pos->last_value = se->value; | ||
495 | } | ||
496 | } | 491 | } |
497 | 492 | ||
498 | 493 | ||
@@ -505,7 +500,7 @@ notify_change (struct StatsEntry *se) | |||
505 | * @return subsystem entry, never NULL (subsystem entry is created if necessary) | 500 | * @return subsystem entry, never NULL (subsystem entry is created if necessary) |
506 | */ | 501 | */ |
507 | static struct SubsystemEntry * | 502 | static struct SubsystemEntry * |
508 | find_subsystem_entry (struct ClientEntry *ce, const char *service) | 503 | find_subsystem_entry(struct ClientEntry *ce, const char *service) |
509 | { | 504 | { |
510 | size_t slen; | 505 | size_t slen; |
511 | struct SubsystemEntry *se; | 506 | struct SubsystemEntry *se; |
@@ -514,24 +509,24 @@ find_subsystem_entry (struct ClientEntry *ce, const char *service) | |||
514 | se = ce->subsystem; | 509 | se = ce->subsystem; |
515 | else | 510 | else |
516 | se = NULL; | 511 | se = NULL; |
517 | if ((NULL == se) || (0 != strcmp (service, se->service))) | 512 | if ((NULL == se) || (0 != strcmp(service, se->service))) |
518 | { | 513 | { |
519 | for (se = sub_head; NULL != se; se = se->next) | 514 | for (se = sub_head; NULL != se; se = se->next) |
520 | if (0 == strcmp (service, se->service)) | 515 | if (0 == strcmp(service, se->service)) |
521 | break; | 516 | break; |
522 | if (NULL != ce) | 517 | if (NULL != ce) |
523 | ce->subsystem = se; | 518 | ce->subsystem = se; |
524 | } | 519 | } |
525 | if (NULL != se) | 520 | if (NULL != se) |
526 | return se; | 521 | return se; |
527 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 522 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
528 | "Allocating new subsystem entry `%s'\n", | 523 | "Allocating new subsystem entry `%s'\n", |
529 | service); | 524 | service); |
530 | slen = strlen (service) + 1; | 525 | slen = strlen(service) + 1; |
531 | se = GNUNET_malloc (sizeof (struct SubsystemEntry) + slen); | 526 | se = GNUNET_malloc(sizeof(struct SubsystemEntry) + slen); |
532 | GNUNET_memcpy (&se[1], service, slen); | 527 | GNUNET_memcpy(&se[1], service, slen); |
533 | se->service = (const char *) &se[1]; | 528 | se->service = (const char *)&se[1]; |
534 | GNUNET_CONTAINER_DLL_insert (sub_head, sub_tail, se); | 529 | GNUNET_CONTAINER_DLL_insert(sub_head, sub_tail, se); |
535 | if (NULL != ce) | 530 | if (NULL != ce) |
536 | ce->subsystem = se; | 531 | ce->subsystem = se; |
537 | return se; | 532 | return se; |
@@ -546,12 +541,12 @@ find_subsystem_entry (struct ClientEntry *ce, const char *service) | |||
546 | * @return statistis entry, or NULL if not found | 541 | * @return statistis entry, or NULL if not found |
547 | */ | 542 | */ |
548 | static struct StatsEntry * | 543 | static struct StatsEntry * |
549 | find_stat_entry (struct SubsystemEntry *se, const char *name) | 544 | find_stat_entry(struct SubsystemEntry *se, const char *name) |
550 | { | 545 | { |
551 | struct StatsEntry *pos; | 546 | struct StatsEntry *pos; |
552 | 547 | ||
553 | for (pos = se->stat_head; NULL != pos; pos = pos->next) | 548 | for (pos = se->stat_head; NULL != pos; pos = pos->next) |
554 | if (0 == strcmp (name, pos->name)) | 549 | if (0 == strcmp(name, pos->name)) |
555 | return pos; | 550 | return pos; |
556 | return NULL; | 551 | return NULL; |
557 | } | 552 | } |
@@ -565,22 +560,22 @@ find_stat_entry (struct SubsystemEntry *se, const char *name) | |||
565 | * @return #GNUNET_OK if message is well-formed | 560 | * @return #GNUNET_OK if message is well-formed |
566 | */ | 561 | */ |
567 | static int | 562 | static int |
568 | check_set (void *cls, const struct GNUNET_STATISTICS_SetMessage *msg) | 563 | check_set(void *cls, const struct GNUNET_STATISTICS_SetMessage *msg) |
569 | { | 564 | { |
570 | const char *service; | 565 | const char *service; |
571 | const char *name; | 566 | const char *name; |
572 | size_t msize; | 567 | size_t msize; |
573 | 568 | ||
574 | msize = ntohs (msg->header.size) - sizeof (*msg); | 569 | msize = ntohs(msg->header.size) - sizeof(*msg); |
575 | if (msize != GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1], | 570 | if (msize != GNUNET_STRINGS_buffer_tokenize((const char *)&msg[1], |
576 | msize, | 571 | msize, |
577 | 2, | 572 | 2, |
578 | &service, | 573 | &service, |
579 | &name)) | 574 | &name)) |
580 | { | 575 | { |
581 | GNUNET_break (0); | 576 | GNUNET_break(0); |
582 | return GNUNET_SYSERR; | 577 | return GNUNET_SYSERR; |
583 | } | 578 | } |
584 | return GNUNET_OK; | 579 | return GNUNET_OK; |
585 | } | 580 | } |
586 | 581 | ||
@@ -592,7 +587,7 @@ check_set (void *cls, const struct GNUNET_STATISTICS_SetMessage *msg) | |||
592 | * @param message the actual message | 587 | * @param message the actual message |
593 | */ | 588 | */ |
594 | static void | 589 | static void |
595 | handle_set (void *cls, const struct GNUNET_STATISTICS_SetMessage *msg) | 590 | handle_set(void *cls, const struct GNUNET_STATISTICS_SetMessage *msg) |
596 | { | 591 | { |
597 | struct ClientEntry *ce = cls; | 592 | struct ClientEntry *ce = cls; |
598 | const char *service; | 593 | const char *service; |
@@ -608,95 +603,95 @@ handle_set (void *cls, const struct GNUNET_STATISTICS_SetMessage *msg) | |||
608 | int changed; | 603 | int changed; |
609 | int initial_set; | 604 | int initial_set; |
610 | 605 | ||
611 | msize = ntohs (msg->header.size); | 606 | msize = ntohs(msg->header.size); |
612 | size = msize - sizeof (struct GNUNET_STATISTICS_SetMessage); | 607 | size = msize - sizeof(struct GNUNET_STATISTICS_SetMessage); |
613 | GNUNET_assert (size == GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1], | 608 | GNUNET_assert(size == GNUNET_STRINGS_buffer_tokenize((const char *)&msg[1], |
614 | size, | 609 | size, |
615 | 2, | 610 | 2, |
616 | &service, | 611 | &service, |
617 | &name)); | 612 | &name)); |
618 | se = find_subsystem_entry (ce, service); | 613 | se = find_subsystem_entry(ce, service); |
619 | flags = ntohl (msg->flags); | 614 | flags = ntohl(msg->flags); |
620 | value = GNUNET_ntohll (msg->value); | 615 | value = GNUNET_ntohll(msg->value); |
621 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 616 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
622 | "Received request to update statistic on `%s:%s' (%u) to/by %llu\n", | 617 | "Received request to update statistic on `%s:%s' (%u) to/by %llu\n", |
623 | service, | 618 | service, |
624 | name, | 619 | name, |
625 | (unsigned int) flags, | 620 | (unsigned int)flags, |
626 | (unsigned long long) value); | 621 | (unsigned long long)value); |
627 | pos = find_stat_entry (se, name); | 622 | pos = find_stat_entry(se, name); |
628 | if (NULL != pos) | 623 | if (NULL != pos) |
629 | { | ||
630 | initial_set = 0; | ||
631 | if (0 == (flags & GNUNET_STATISTICS_SETFLAG_RELATIVE)) | ||
632 | { | 624 | { |
633 | changed = (pos->value != value); | 625 | initial_set = 0; |
634 | pos->value = value; | 626 | if (0 == (flags & GNUNET_STATISTICS_SETFLAG_RELATIVE)) |
635 | } | 627 | { |
636 | else | 628 | changed = (pos->value != value); |
637 | { | 629 | pos->value = value; |
638 | delta = (int64_t) value; | 630 | } |
639 | if ((delta < 0) && (pos->value < -delta)) | ||
640 | { | ||
641 | changed = (0 != pos->value); | ||
642 | pos->value = 0; | ||
643 | } | ||
644 | else | 631 | else |
645 | { | 632 | { |
646 | changed = (0 != delta); | 633 | delta = (int64_t)value; |
647 | GNUNET_break ((delta <= 0) || (pos->value + delta > pos->value)); | 634 | if ((delta < 0) && (pos->value < -delta)) |
648 | pos->value += delta; | 635 | { |
649 | } | 636 | changed = (0 != pos->value); |
637 | pos->value = 0; | ||
638 | } | ||
639 | else | ||
640 | { | ||
641 | changed = (0 != delta); | ||
642 | GNUNET_break((delta <= 0) || (pos->value + delta > pos->value)); | ||
643 | pos->value += delta; | ||
644 | } | ||
645 | } | ||
646 | if (GNUNET_NO == pos->set) | ||
647 | { | ||
648 | pos->set = GNUNET_YES; | ||
649 | initial_set = 1; | ||
650 | } | ||
651 | pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT)); | ||
652 | if (pos != se->stat_head) | ||
653 | { | ||
654 | /* move to front for faster setting next time! */ | ||
655 | GNUNET_CONTAINER_DLL_remove(se->stat_head, se->stat_tail, pos); | ||
656 | GNUNET_CONTAINER_DLL_insert(se->stat_head, se->stat_tail, pos); | ||
657 | } | ||
658 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
659 | "Statistic `%s:%s' updated to value %llu (%d).\n", | ||
660 | service, | ||
661 | name, | ||
662 | (unsigned long long)pos->value, | ||
663 | pos->persistent); | ||
664 | if ((changed) || (1 == initial_set)) | ||
665 | notify_change(pos); | ||
666 | GNUNET_SERVICE_client_continue(ce->client); | ||
667 | return; | ||
650 | } | 668 | } |
651 | if (GNUNET_NO == pos->set) | 669 | /* not found, create a new entry */ |
670 | nlen = strlen(name) + 1; | ||
671 | pos = GNUNET_malloc(sizeof(struct StatsEntry) + nlen); | ||
672 | GNUNET_memcpy(&pos[1], name, nlen); | ||
673 | pos->name = (const char *)&pos[1]; | ||
674 | pos->subsystem = se; | ||
675 | if ((0 == (flags & GNUNET_STATISTICS_SETFLAG_RELATIVE)) || | ||
676 | (0 < (int64_t)GNUNET_ntohll(msg->value))) | ||
652 | { | 677 | { |
678 | pos->value = GNUNET_ntohll(msg->value); | ||
653 | pos->set = GNUNET_YES; | 679 | pos->set = GNUNET_YES; |
654 | initial_set = 1; | ||
655 | } | 680 | } |
656 | pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT)); | 681 | else |
657 | if (pos != se->stat_head) | ||
658 | { | 682 | { |
659 | /* move to front for faster setting next time! */ | 683 | pos->set = GNUNET_NO; |
660 | GNUNET_CONTAINER_DLL_remove (se->stat_head, se->stat_tail, pos); | ||
661 | GNUNET_CONTAINER_DLL_insert (se->stat_head, se->stat_tail, pos); | ||
662 | } | 684 | } |
663 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
664 | "Statistic `%s:%s' updated to value %llu (%d).\n", | ||
665 | service, | ||
666 | name, | ||
667 | (unsigned long long) pos->value, | ||
668 | pos->persistent); | ||
669 | if ((changed) || (1 == initial_set)) | ||
670 | notify_change (pos); | ||
671 | GNUNET_SERVICE_client_continue (ce->client); | ||
672 | return; | ||
673 | } | ||
674 | /* not found, create a new entry */ | ||
675 | nlen = strlen (name) + 1; | ||
676 | pos = GNUNET_malloc (sizeof (struct StatsEntry) + nlen); | ||
677 | GNUNET_memcpy (&pos[1], name, nlen); | ||
678 | pos->name = (const char *) &pos[1]; | ||
679 | pos->subsystem = se; | ||
680 | if ((0 == (flags & GNUNET_STATISTICS_SETFLAG_RELATIVE)) || | ||
681 | (0 < (int64_t) GNUNET_ntohll (msg->value))) | ||
682 | { | ||
683 | pos->value = GNUNET_ntohll (msg->value); | ||
684 | pos->set = GNUNET_YES; | ||
685 | } | ||
686 | else | ||
687 | { | ||
688 | pos->set = GNUNET_NO; | ||
689 | } | ||
690 | pos->uid = uidgen++; | 685 | pos->uid = uidgen++; |
691 | pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT)); | 686 | pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT)); |
692 | GNUNET_CONTAINER_DLL_insert (se->stat_head, se->stat_tail, pos); | 687 | GNUNET_CONTAINER_DLL_insert(se->stat_head, se->stat_tail, pos); |
693 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 688 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
694 | "New statistic on `%s:%s' with value %llu created.\n", | 689 | "New statistic on `%s:%s' with value %llu created.\n", |
695 | service, | 690 | service, |
696 | name, | 691 | name, |
697 | (unsigned long long) pos->value); | 692 | (unsigned long long)pos->value); |
698 | if (NULL != ce) | 693 | if (NULL != ce) |
699 | GNUNET_SERVICE_client_continue (ce->client); | 694 | GNUNET_SERVICE_client_continue(ce->client); |
700 | } | 695 | } |
701 | 696 | ||
702 | 697 | ||
@@ -708,22 +703,22 @@ handle_set (void *cls, const struct GNUNET_STATISTICS_SetMessage *msg) | |||
708 | * @return #GNUNET_OK if message is well-formed | 703 | * @return #GNUNET_OK if message is well-formed |
709 | */ | 704 | */ |
710 | static int | 705 | static int |
711 | check_watch (void *cls, const struct GNUNET_MessageHeader *message) | 706 | check_watch(void *cls, const struct GNUNET_MessageHeader *message) |
712 | { | 707 | { |
713 | size_t size; | 708 | size_t size; |
714 | const char *service; | 709 | const char *service; |
715 | const char *name; | 710 | const char *name; |
716 | 711 | ||
717 | size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader); | 712 | size = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader); |
718 | if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], | 713 | if (size != GNUNET_STRINGS_buffer_tokenize((const char *)&message[1], |
719 | size, | 714 | size, |
720 | 2, | 715 | 2, |
721 | &service, | 716 | &service, |
722 | &name)) | 717 | &name)) |
723 | { | 718 | { |
724 | GNUNET_break (0); | 719 | GNUNET_break(0); |
725 | return GNUNET_SYSERR; | 720 | return GNUNET_SYSERR; |
726 | } | 721 | } |
727 | return GNUNET_OK; | 722 | return GNUNET_OK; |
728 | } | 723 | } |
729 | 724 | ||
@@ -735,7 +730,7 @@ check_watch (void *cls, const struct GNUNET_MessageHeader *message) | |||
735 | * @param message the actual message | 730 | * @param message the actual message |
736 | */ | 731 | */ |
737 | static void | 732 | static void |
738 | handle_watch (void *cls, const struct GNUNET_MessageHeader *message) | 733 | handle_watch(void *cls, const struct GNUNET_MessageHeader *message) |
739 | { | 734 | { |
740 | struct ClientEntry *ce = cls; | 735 | struct ClientEntry *ce = cls; |
741 | const char *service; | 736 | const char *service; |
@@ -748,49 +743,49 @@ handle_watch (void *cls, const struct GNUNET_MessageHeader *message) | |||
748 | size_t nlen; | 743 | size_t nlen; |
749 | 744 | ||
750 | if (NULL == nc) | 745 | if (NULL == nc) |
751 | { | 746 | { |
752 | GNUNET_SERVICE_client_drop (ce->client); | 747 | GNUNET_SERVICE_client_drop(ce->client); |
753 | return; | 748 | return; |
754 | } | 749 | } |
755 | GNUNET_SERVICE_client_mark_monitor (ce->client); | 750 | GNUNET_SERVICE_client_mark_monitor(ce->client); |
756 | msize = ntohs (message->size); | 751 | msize = ntohs(message->size); |
757 | size = msize - sizeof (struct GNUNET_MessageHeader); | 752 | size = msize - sizeof(struct GNUNET_MessageHeader); |
758 | GNUNET_assert (size == | 753 | GNUNET_assert(size == |
759 | GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], | 754 | GNUNET_STRINGS_buffer_tokenize((const char *)&message[1], |
760 | size, | 755 | size, |
761 | 2, | 756 | 2, |
762 | &service, | 757 | &service, |
763 | &name)); | 758 | &name)); |
764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 759 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
765 | "Received request to watch statistic on `%s:%s'\n", | 760 | "Received request to watch statistic on `%s:%s'\n", |
766 | service, | 761 | service, |
767 | name); | 762 | name); |
768 | se = find_subsystem_entry (ce, service); | 763 | se = find_subsystem_entry(ce, service); |
769 | pos = find_stat_entry (se, name); | 764 | pos = find_stat_entry(se, name); |
770 | if (NULL == pos) | 765 | if (NULL == pos) |
771 | { | 766 | { |
772 | nlen = strlen (name) + 1; | 767 | nlen = strlen(name) + 1; |
773 | pos = GNUNET_malloc (sizeof (struct StatsEntry) + nlen); | 768 | pos = GNUNET_malloc(sizeof(struct StatsEntry) + nlen); |
774 | GNUNET_memcpy (&pos[1], name, nlen); | 769 | GNUNET_memcpy(&pos[1], name, nlen); |
775 | pos->name = (const char *) &pos[1]; | 770 | pos->name = (const char *)&pos[1]; |
776 | pos->subsystem = se; | 771 | pos->subsystem = se; |
777 | GNUNET_CONTAINER_DLL_insert (se->stat_head, se->stat_tail, pos); | 772 | GNUNET_CONTAINER_DLL_insert(se->stat_head, se->stat_tail, pos); |
778 | pos->uid = uidgen++; | 773 | pos->uid = uidgen++; |
779 | pos->set = GNUNET_NO; | 774 | pos->set = GNUNET_NO; |
780 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 775 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
781 | "New statistic on `%s:%s' with value %llu created.\n", | 776 | "New statistic on `%s:%s' with value %llu created.\n", |
782 | service, | 777 | service, |
783 | name, | 778 | name, |
784 | (unsigned long long) pos->value); | 779 | (unsigned long long)pos->value); |
785 | } | 780 | } |
786 | we = GNUNET_new (struct WatchEntry); | 781 | we = GNUNET_new(struct WatchEntry); |
787 | we->ce = ce; | 782 | we->ce = ce; |
788 | we->last_value_set = GNUNET_NO; | 783 | we->last_value_set = GNUNET_NO; |
789 | we->wid = ce->max_wid++; | 784 | we->wid = ce->max_wid++; |
790 | GNUNET_CONTAINER_DLL_insert (pos->we_head, pos->we_tail, we); | 785 | GNUNET_CONTAINER_DLL_insert(pos->we_head, pos->we_tail, we); |
791 | if (0 != pos->value) | 786 | if (0 != pos->value) |
792 | notify_change (pos); | 787 | notify_change(pos); |
793 | GNUNET_SERVICE_client_continue (ce->client); | 788 | GNUNET_SERVICE_client_continue(ce->client); |
794 | } | 789 | } |
795 | 790 | ||
796 | 791 | ||
@@ -803,15 +798,15 @@ handle_watch (void *cls, const struct GNUNET_MessageHeader *message) | |||
803 | * @param message the actual message | 798 | * @param message the actual message |
804 | */ | 799 | */ |
805 | static void | 800 | static void |
806 | handle_disconnect (void *cls, const struct GNUNET_MessageHeader *message) | 801 | handle_disconnect(void *cls, const struct GNUNET_MessageHeader *message) |
807 | { | 802 | { |
808 | struct ClientEntry *ce = cls; | 803 | struct ClientEntry *ce = cls; |
809 | struct GNUNET_MQ_Envelope *env; | 804 | struct GNUNET_MQ_Envelope *env; |
810 | struct GNUNET_MessageHeader *msg; | 805 | struct GNUNET_MessageHeader *msg; |
811 | 806 | ||
812 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM); | 807 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM); |
813 | GNUNET_MQ_send (ce->mq, env); | 808 | GNUNET_MQ_send(ce->mq, env); |
814 | GNUNET_SERVICE_client_continue (ce->client); | 809 | GNUNET_SERVICE_client_continue(ce->client); |
815 | } | 810 | } |
816 | 811 | ||
817 | 812 | ||
@@ -819,7 +814,7 @@ handle_disconnect (void *cls, const struct GNUNET_MessageHeader *message) | |||
819 | * Actually perform the shutdown. | 814 | * Actually perform the shutdown. |
820 | */ | 815 | */ |
821 | static void | 816 | static void |
822 | do_shutdown () | 817 | do_shutdown() |
823 | { | 818 | { |
824 | struct WatchEntry *we; | 819 | struct WatchEntry *we; |
825 | struct StatsEntry *pos; | 820 | struct StatsEntry *pos; |
@@ -827,26 +822,26 @@ do_shutdown () | |||
827 | 822 | ||
828 | if (NULL == nc) | 823 | if (NULL == nc) |
829 | return; | 824 | return; |
830 | save (); | 825 | save(); |
831 | GNUNET_notification_context_destroy (nc); | 826 | GNUNET_notification_context_destroy(nc); |
832 | nc = NULL; | 827 | nc = NULL; |
833 | GNUNET_assert (0 == client_count); | 828 | GNUNET_assert(0 == client_count); |
834 | while (NULL != (se = sub_head)) | 829 | while (NULL != (se = sub_head)) |
835 | { | ||
836 | GNUNET_CONTAINER_DLL_remove (sub_head, sub_tail, se); | ||
837 | while (NULL != (pos = se->stat_head)) | ||
838 | { | 830 | { |
839 | GNUNET_CONTAINER_DLL_remove (se->stat_head, se->stat_tail, pos); | 831 | GNUNET_CONTAINER_DLL_remove(sub_head, sub_tail, se); |
840 | while (NULL != (we = pos->we_head)) | 832 | while (NULL != (pos = se->stat_head)) |
841 | { | 833 | { |
842 | GNUNET_break (0); | 834 | GNUNET_CONTAINER_DLL_remove(se->stat_head, se->stat_tail, pos); |
843 | GNUNET_CONTAINER_DLL_remove (pos->we_head, pos->we_tail, we); | 835 | while (NULL != (we = pos->we_head)) |
844 | GNUNET_free (we); | 836 | { |
845 | } | 837 | GNUNET_break(0); |
846 | GNUNET_free (pos); | 838 | GNUNET_CONTAINER_DLL_remove(pos->we_head, pos->we_tail, we); |
839 | GNUNET_free(we); | ||
840 | } | ||
841 | GNUNET_free(pos); | ||
842 | } | ||
843 | GNUNET_free(se); | ||
847 | } | 844 | } |
848 | GNUNET_free (se); | ||
849 | } | ||
850 | } | 845 | } |
851 | 846 | ||
852 | 847 | ||
@@ -856,12 +851,12 @@ do_shutdown () | |||
856 | * @param cls unused | 851 | * @param cls unused |
857 | */ | 852 | */ |
858 | static void | 853 | static void |
859 | shutdown_task (void *cls) | 854 | shutdown_task(void *cls) |
860 | { | 855 | { |
861 | in_shutdown = GNUNET_YES; | 856 | in_shutdown = GNUNET_YES; |
862 | if (0 != client_count) | 857 | if (0 != client_count) |
863 | return; | 858 | return; |
864 | do_shutdown (); | 859 | do_shutdown(); |
865 | } | 860 | } |
866 | 861 | ||
867 | 862 | ||
@@ -873,9 +868,9 @@ shutdown_task (void *cls) | |||
873 | * @param app_cls the `struct ClientEntry *` | 868 | * @param app_cls the `struct ClientEntry *` |
874 | */ | 869 | */ |
875 | static void | 870 | static void |
876 | client_disconnect_cb (void *cls, | 871 | client_disconnect_cb(void *cls, |
877 | struct GNUNET_SERVICE_Client *client, | 872 | struct GNUNET_SERVICE_Client *client, |
878 | void *app_cls) | 873 | void *app_cls) |
879 | { | 874 | { |
880 | struct ClientEntry *ce = app_cls; | 875 | struct ClientEntry *ce = app_cls; |
881 | struct WatchEntry *we; | 876 | struct WatchEntry *we; |
@@ -885,23 +880,23 @@ client_disconnect_cb (void *cls, | |||
885 | 880 | ||
886 | client_count--; | 881 | client_count--; |
887 | for (se = sub_head; NULL != se; se = se->next) | 882 | for (se = sub_head; NULL != se; se = se->next) |
888 | { | ||
889 | for (pos = se->stat_head; NULL != pos; pos = pos->next) | ||
890 | { | 883 | { |
891 | wen = pos->we_head; | 884 | for (pos = se->stat_head; NULL != pos; pos = pos->next) |
892 | while (NULL != (we = wen)) | 885 | { |
893 | { | 886 | wen = pos->we_head; |
894 | wen = we->next; | 887 | while (NULL != (we = wen)) |
895 | if (we->ce != ce) | 888 | { |
896 | continue; | 889 | wen = we->next; |
897 | GNUNET_CONTAINER_DLL_remove (pos->we_head, pos->we_tail, we); | 890 | if (we->ce != ce) |
898 | GNUNET_free (we); | 891 | continue; |
899 | } | 892 | GNUNET_CONTAINER_DLL_remove(pos->we_head, pos->we_tail, we); |
893 | GNUNET_free(we); | ||
894 | } | ||
895 | } | ||
900 | } | 896 | } |
901 | } | 897 | GNUNET_free(ce); |
902 | GNUNET_free (ce); | ||
903 | if ((0 == client_count) && (GNUNET_YES == in_shutdown)) | 898 | if ((0 == client_count) && (GNUNET_YES == in_shutdown)) |
904 | do_shutdown (); | 899 | do_shutdown(); |
905 | } | 900 | } |
906 | 901 | ||
907 | 902 | ||
@@ -917,19 +912,19 @@ client_disconnect_cb (void *cls, | |||
917 | * #GNUNET_SYSERR to stop further processing with error | 912 | * #GNUNET_SYSERR to stop further processing with error |
918 | */ | 913 | */ |
919 | static int | 914 | static int |
920 | inject_message (void *cls, const struct GNUNET_MessageHeader *message) | 915 | inject_message(void *cls, const struct GNUNET_MessageHeader *message) |
921 | { | 916 | { |
922 | uint16_t msize = ntohs (message->size); | 917 | uint16_t msize = ntohs(message->size); |
923 | const struct GNUNET_STATISTICS_SetMessage *sm; | 918 | const struct GNUNET_STATISTICS_SetMessage *sm; |
924 | 919 | ||
925 | sm = (const struct GNUNET_STATISTICS_SetMessage *) message; | 920 | sm = (const struct GNUNET_STATISTICS_SetMessage *)message; |
926 | if ((sizeof (struct GNUNET_STATISTICS_SetMessage) > msize) || | 921 | if ((sizeof(struct GNUNET_STATISTICS_SetMessage) > msize) || |
927 | (GNUNET_OK != check_set (NULL, sm))) | 922 | (GNUNET_OK != check_set(NULL, sm))) |
928 | { | 923 | { |
929 | GNUNET_break (0); | 924 | GNUNET_break(0); |
930 | return GNUNET_SYSERR; | 925 | return GNUNET_SYSERR; |
931 | } | 926 | } |
932 | handle_set (NULL, sm); | 927 | handle_set(NULL, sm); |
933 | return GNUNET_OK; | 928 | return GNUNET_OK; |
934 | } | 929 | } |
935 | 930 | ||
@@ -939,7 +934,7 @@ inject_message (void *cls, const struct GNUNET_MessageHeader *message) | |||
939 | * format that we also use for setting the values over the network. | 934 | * format that we also use for setting the values over the network. |
940 | */ | 935 | */ |
941 | static void | 936 | static void |
942 | load () | 937 | load() |
943 | { | 938 | { |
944 | char *fn; | 939 | char *fn; |
945 | struct GNUNET_BIO_ReadHandle *rh; | 940 | struct GNUNET_BIO_ReadHandle *rh; |
@@ -947,51 +942,51 @@ load () | |||
947 | char *buf; | 942 | char *buf; |
948 | struct GNUNET_MessageStreamTokenizer *mst; | 943 | struct GNUNET_MessageStreamTokenizer *mst; |
949 | 944 | ||
950 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, | 945 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, |
951 | "STATISTICS", | 946 | "STATISTICS", |
952 | "DATABASE", | 947 | "DATABASE", |
953 | &fn)) | 948 | &fn)) |
954 | { | 949 | { |
955 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 950 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
956 | "STATISTICS", | 951 | "STATISTICS", |
957 | "DATABASE"); | 952 | "DATABASE"); |
958 | return; | 953 | return; |
959 | } | 954 | } |
960 | if ((GNUNET_OK != | 955 | if ((GNUNET_OK != |
961 | GNUNET_DISK_file_size (fn, &fsize, GNUNET_NO, GNUNET_YES)) || | 956 | GNUNET_DISK_file_size(fn, &fsize, GNUNET_NO, GNUNET_YES)) || |
962 | (0 == fsize)) | 957 | (0 == fsize)) |
963 | { | 958 | { |
964 | GNUNET_free (fn); | 959 | GNUNET_free(fn); |
965 | return; | 960 | return; |
966 | } | 961 | } |
967 | buf = GNUNET_malloc (fsize); | 962 | buf = GNUNET_malloc(fsize); |
968 | rh = GNUNET_BIO_read_open (fn); | 963 | rh = GNUNET_BIO_read_open(fn); |
969 | if (! rh) | 964 | if (!rh) |
970 | { | 965 | { |
971 | GNUNET_free (buf); | 966 | GNUNET_free(buf); |
972 | GNUNET_free (fn); | 967 | GNUNET_free(fn); |
973 | return; | 968 | return; |
974 | } | 969 | } |
975 | if (GNUNET_OK != GNUNET_BIO_read (rh, fn, buf, fsize)) | 970 | if (GNUNET_OK != GNUNET_BIO_read(rh, fn, buf, fsize)) |
976 | { | 971 | { |
977 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", fn); | 972 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "read", fn); |
978 | GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); | 973 | GNUNET_break(GNUNET_OK == GNUNET_BIO_read_close(rh, NULL)); |
979 | GNUNET_free (buf); | 974 | GNUNET_free(buf); |
980 | GNUNET_free (fn); | 975 | GNUNET_free(fn); |
981 | return; | 976 | return; |
982 | } | 977 | } |
983 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 978 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
984 | _ ("Loading %llu bytes of statistics from `%s'\n"), | 979 | _("Loading %llu bytes of statistics from `%s'\n"), |
985 | (unsigned long long) fsize, | 980 | (unsigned long long)fsize, |
986 | fn); | 981 | fn); |
987 | mst = GNUNET_MST_create (&inject_message, NULL); | 982 | mst = GNUNET_MST_create(&inject_message, NULL); |
988 | GNUNET_break ( | 983 | GNUNET_break( |
989 | GNUNET_OK == | 984 | GNUNET_OK == |
990 | GNUNET_MST_from_buffer (mst, buf, (size_t) fsize, GNUNET_YES, GNUNET_NO)); | 985 | GNUNET_MST_from_buffer(mst, buf, (size_t)fsize, GNUNET_YES, GNUNET_NO)); |
991 | GNUNET_MST_destroy (mst); | 986 | GNUNET_MST_destroy(mst); |
992 | GNUNET_free (buf); | 987 | GNUNET_free(buf); |
993 | GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); | 988 | GNUNET_break(GNUNET_OK == GNUNET_BIO_read_close(rh, NULL)); |
994 | GNUNET_free (fn); | 989 | GNUNET_free(fn); |
995 | } | 990 | } |
996 | 991 | ||
997 | 992 | ||
@@ -1003,44 +998,44 @@ load () | |||
1003 | * @param service the initialized service | 998 | * @param service the initialized service |
1004 | */ | 999 | */ |
1005 | static void | 1000 | static void |
1006 | run (void *cls, | 1001 | run(void *cls, |
1007 | const struct GNUNET_CONFIGURATION_Handle *c, | 1002 | const struct GNUNET_CONFIGURATION_Handle *c, |
1008 | struct GNUNET_SERVICE_Handle *service) | 1003 | struct GNUNET_SERVICE_Handle *service) |
1009 | { | 1004 | { |
1010 | cfg = c; | 1005 | cfg = c; |
1011 | nc = GNUNET_notification_context_create (16); | 1006 | nc = GNUNET_notification_context_create(16); |
1012 | load (); | 1007 | load(); |
1013 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 1008 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
1014 | } | 1009 | } |
1015 | 1010 | ||
1016 | 1011 | ||
1017 | /** | 1012 | /** |
1018 | * Define "main" method using service macro. | 1013 | * Define "main" method using service macro. |
1019 | */ | 1014 | */ |
1020 | GNUNET_SERVICE_MAIN ( | 1015 | GNUNET_SERVICE_MAIN( |
1021 | "statistics", | 1016 | "statistics", |
1022 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, | 1017 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, |
1023 | &run, | 1018 | &run, |
1024 | &client_connect_cb, | 1019 | &client_connect_cb, |
1025 | &client_disconnect_cb, | 1020 | &client_disconnect_cb, |
1026 | NULL, | 1021 | NULL, |
1027 | GNUNET_MQ_hd_var_size (set, | 1022 | GNUNET_MQ_hd_var_size(set, |
1028 | GNUNET_MESSAGE_TYPE_STATISTICS_SET, | 1023 | GNUNET_MESSAGE_TYPE_STATISTICS_SET, |
1029 | struct GNUNET_STATISTICS_SetMessage, | 1024 | struct GNUNET_STATISTICS_SetMessage, |
1030 | NULL), | 1025 | NULL), |
1031 | GNUNET_MQ_hd_var_size (get, | 1026 | GNUNET_MQ_hd_var_size(get, |
1032 | GNUNET_MESSAGE_TYPE_STATISTICS_GET, | 1027 | GNUNET_MESSAGE_TYPE_STATISTICS_GET, |
1033 | struct GNUNET_MessageHeader, | 1028 | struct GNUNET_MessageHeader, |
1034 | NULL), | 1029 | NULL), |
1035 | GNUNET_MQ_hd_var_size (watch, | 1030 | GNUNET_MQ_hd_var_size(watch, |
1036 | GNUNET_MESSAGE_TYPE_STATISTICS_WATCH, | 1031 | GNUNET_MESSAGE_TYPE_STATISTICS_WATCH, |
1037 | struct GNUNET_MessageHeader, | 1032 | struct GNUNET_MessageHeader, |
1038 | NULL), | 1033 | NULL), |
1039 | GNUNET_MQ_hd_fixed_size (disconnect, | 1034 | GNUNET_MQ_hd_fixed_size(disconnect, |
1040 | GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT, | 1035 | GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT, |
1041 | struct GNUNET_MessageHeader, | 1036 | struct GNUNET_MessageHeader, |
1042 | NULL), | 1037 | NULL), |
1043 | GNUNET_MQ_handler_end ()); | 1038 | GNUNET_MQ_handler_end()); |
1044 | 1039 | ||
1045 | 1040 | ||
1046 | #if defined(LINUX) && defined(__GLIBC__) | 1041 | #if defined(LINUX) && defined(__GLIBC__) |
@@ -1049,11 +1044,11 @@ GNUNET_SERVICE_MAIN ( | |||
1049 | /** | 1044 | /** |
1050 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | 1045 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. |
1051 | */ | 1046 | */ |
1052 | void __attribute__ ((constructor)) GNUNET_STATISTICS_memory_init () | 1047 | void __attribute__ ((constructor)) GNUNET_STATISTICS_memory_init() |
1053 | { | 1048 | { |
1054 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); | 1049 | mallopt(M_TRIM_THRESHOLD, 4 * 1024); |
1055 | mallopt (M_TOP_PAD, 1 * 1024); | 1050 | mallopt(M_TOP_PAD, 1 * 1024); |
1056 | malloc_trim (0); | 1051 | malloc_trim(0); |
1057 | } | 1052 | } |
1058 | #endif | 1053 | #endif |
1059 | 1054 | ||