aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/gnunet-service-statistics.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/statistics/gnunet-service-statistics.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/statistics/gnunet-service-statistics.c')
-rw-r--r--src/statistics/gnunet-service-statistics.c92
1 files changed, 43 insertions, 49 deletions
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c
index 5e0be1183..3305dc6f4 100644
--- a/src/statistics/gnunet-service-statistics.c
+++ b/src/statistics/gnunet-service-statistics.c
@@ -181,8 +181,8 @@ load (struct GNUNET_SERVER_Handle *server)
181 char *buf; 181 char *buf;
182 struct GNUNET_SERVER_MessageStreamTokenizer *mst; 182 struct GNUNET_SERVER_MessageStreamTokenizer *mst;
183 183
184 fn = GNUNET_DISK_get_home_filename (cfg, 184 fn = GNUNET_DISK_get_home_filename (cfg, "statistics", "statistics.data",
185 "statistics", "statistics.data", NULL); 185 NULL);
186 if (fn == NULL) 186 if (fn == NULL)
187 return; 187 return;
188 if ((0 != stat (fn, &sb)) || (sb.st_size == 0)) 188 if ((0 != stat (fn, &sb)) || (sb.st_size == 0))
@@ -209,10 +209,8 @@ load (struct GNUNET_SERVER_Handle *server)
209 (unsigned long long) sb.st_size, fn); 209 (unsigned long long) sb.st_size, fn);
210 mst = GNUNET_SERVER_mst_create (&inject_message, server); 210 mst = GNUNET_SERVER_mst_create (&inject_message, server);
211 GNUNET_break (GNUNET_OK == 211 GNUNET_break (GNUNET_OK ==
212 GNUNET_SERVER_mst_receive (mst, 212 GNUNET_SERVER_mst_receive (mst, NULL, buf, sb.st_size,
213 NULL, 213 GNUNET_YES, GNUNET_NO));
214 buf,
215 sb.st_size, GNUNET_YES, GNUNET_NO));
216 GNUNET_SERVER_mst_destroy (mst); 214 GNUNET_SERVER_mst_destroy (mst);
217 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_unmap (mh)); 215 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_unmap (mh));
218 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); 216 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));
@@ -232,12 +230,12 @@ save ()
232 unsigned long long total; 230 unsigned long long total;
233 231
234 fh = NULL; 232 fh = NULL;
235 fn = GNUNET_DISK_get_home_filename (cfg, 233 fn = GNUNET_DISK_get_home_filename (cfg, "statistics", "statistics.data",
236 "statistics", "statistics.data", NULL); 234 NULL);
237 if (fn != NULL) 235 if (fn != NULL)
238 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_WRITE 236 fh = GNUNET_DISK_file_open (fn,
239 | GNUNET_DISK_OPEN_CREATE | 237 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE
240 GNUNET_DISK_OPEN_TRUNCATE, 238 | GNUNET_DISK_OPEN_TRUNCATE,
241 GNUNET_DISK_PERM_USER_READ | 239 GNUNET_DISK_PERM_USER_READ |
242 GNUNET_DISK_PERM_USER_WRITE); 240 GNUNET_DISK_PERM_USER_WRITE);
243 total = 0; 241 total = 0;
@@ -292,13 +290,13 @@ transmit (struct GNUNET_SERVER_Client *client, const struct StatsEntry *e)
292 m->uid |= htonl (GNUNET_STATISTICS_PERSIST_BIT); 290 m->uid |= htonl (GNUNET_STATISTICS_PERSIST_BIT);
293 m->value = GNUNET_htonll (e->value); 291 m->value = GNUNET_htonll (e->value);
294 size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage); 292 size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage);
295 GNUNET_assert (size == GNUNET_STRINGS_buffer_fill ((char *) &m[1], 293 GNUNET_assert (size ==
296 size, 294 GNUNET_STRINGS_buffer_fill ((char *) &m[1], size, 2,
297 2, e->service, e->name)); 295 e->service, e->name));
298#if DEBUG_STATISTICS 296#if DEBUG_STATISTICS
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
300 "Transmitting value for `%s:%s' (%d): %llu\n", 298 "Transmitting value for `%s:%s' (%d): %llu\n", e->service,
301 e->service, e->name, e->persistent, e->value); 299 e->name, e->persistent, e->value);
302#endif 300#endif
303 GNUNET_SERVER_notification_context_unicast (nc, client, &m->header, 301 GNUNET_SERVER_notification_context_unicast (nc, client, &m->header,
304 GNUNET_NO); 302 GNUNET_NO);
@@ -312,9 +310,8 @@ transmit (struct GNUNET_SERVER_Client *client, const struct StatsEntry *e)
312static int 310static int
313matches (const struct StatsEntry *e, const char *service, const char *name) 311matches (const struct StatsEntry *e, const char *service, const char *name)
314{ 312{
315 return ((0 == strlen (service)) || 313 return ((0 == strlen (service)) || (0 == strcmp (service, e->service))) &&
316 (0 == strcmp (service, e->service))) 314 ((0 == strlen (name)) || (0 == strcmp (name, e->name)));
317 && ((0 == strlen (name)) || (0 == strcmp (name, e->name)));
318} 315}
319 316
320 317
@@ -350,8 +347,7 @@ make_client_entry (struct GNUNET_SERVER_Client *client)
350 * GNUNET_SYSERR to close it (signal serious error) 347 * GNUNET_SYSERR to close it (signal serious error)
351 */ 348 */
352static void 349static void
353handle_get (void *cls, 350handle_get (void *cls, struct GNUNET_SERVER_Client *client,
354 struct GNUNET_SERVER_Client *client,
355 const struct GNUNET_MessageHeader *message) 351 const struct GNUNET_MessageHeader *message)
356{ 352{
357 struct GNUNET_MessageHeader end; 353 struct GNUNET_MessageHeader end;
@@ -363,8 +359,9 @@ handle_get (void *cls,
363 if (client != NULL) 359 if (client != NULL)
364 make_client_entry (client); 360 make_client_entry (client);
365 size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader); 361 size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader);
366 if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], 362 if (size !=
367 size, 2, &service, &name)) 363 GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], size, 2,
364 &service, &name))
368 { 365 {
369 GNUNET_break (0); 366 GNUNET_break (0);
370 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 367 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -407,9 +404,8 @@ notify_change (struct StatsEntry *se)
407 wvm.wid = htonl (pos->wid); 404 wvm.wid = htonl (pos->wid);
408 wvm.reserved = htonl (0); 405 wvm.reserved = htonl (0);
409 wvm.value = GNUNET_htonll (se->value); 406 wvm.value = GNUNET_htonll (se->value);
410 GNUNET_SERVER_notification_context_unicast (nc, 407 GNUNET_SERVER_notification_context_unicast (nc, pos->client, &wvm.header,
411 pos->client, 408 GNUNET_NO);
412 &wvm.header, GNUNET_NO);
413 pos->last_value = se->value; 409 pos->last_value = se->value;
414 } 410 }
415 pos = pos->next; 411 pos = pos->next;
@@ -424,8 +420,7 @@ notify_change (struct StatsEntry *se)
424 * @param message the actual message 420 * @param message the actual message
425 */ 421 */
426static void 422static void
427handle_set (void *cls, 423handle_set (void *cls, struct GNUNET_SERVER_Client *client,
428 struct GNUNET_SERVER_Client *client,
429 const struct GNUNET_MessageHeader *message) 424 const struct GNUNET_MessageHeader *message)
430{ 425{
431 char *service; 426 char *service;
@@ -452,8 +447,9 @@ handle_set (void *cls,
452 size = msize - sizeof (struct GNUNET_STATISTICS_SetMessage); 447 size = msize - sizeof (struct GNUNET_STATISTICS_SetMessage);
453 msg = (const struct GNUNET_STATISTICS_SetMessage *) message; 448 msg = (const struct GNUNET_STATISTICS_SetMessage *) message;
454 449
455 if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1], 450 if (size !=
456 size, 2, &service, &name)) 451 GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1], size, 2, &service,
452 &name))
457 { 453 {
458 GNUNET_break (0); 454 GNUNET_break (0);
459 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 455 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -504,8 +500,8 @@ handle_set (void *cls,
504 } 500 }
505#if DEBUG_STATISTICS 501#if DEBUG_STATISTICS
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
507 "Statistic `%s:%s' updated to value %llu.\n", 503 "Statistic `%s:%s' updated to value %llu.\n", service, name,
508 service, name, pos->value); 504 pos->value);
509#endif 505#endif
510 if (changed) 506 if (changed)
511 notify_change (pos); 507 notify_change (pos);
@@ -530,8 +526,8 @@ handle_set (void *cls,
530 start = pos; 526 start = pos;
531#if DEBUG_STATISTICS 527#if DEBUG_STATISTICS
532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
533 "New statistic on `%s:%s' with value %llu created.\n", 529 "New statistic on `%s:%s' with value %llu created.\n", service,
534 service, name, pos->value); 530 name, pos->value);
535#endif 531#endif
536 GNUNET_SERVER_receive_done (client, GNUNET_OK); 532 GNUNET_SERVER_receive_done (client, GNUNET_OK);
537} 533}
@@ -545,8 +541,7 @@ handle_set (void *cls,
545 * @param message the actual message 541 * @param message the actual message
546 */ 542 */
547static void 543static void
548handle_watch (void *cls, 544handle_watch (void *cls, struct GNUNET_SERVER_Client *client,
549 struct GNUNET_SERVER_Client *client,
550 const struct GNUNET_MessageHeader *message) 545 const struct GNUNET_MessageHeader *message)
551{ 546{
552 char *service; 547 char *service;
@@ -567,8 +562,9 @@ handle_watch (void *cls,
567 return; 562 return;
568 } 563 }
569 size = msize - sizeof (struct GNUNET_MessageHeader); 564 size = msize - sizeof (struct GNUNET_MessageHeader);
570 if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], 565 if (size !=
571 size, 2, &service, &name)) 566 GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], size, 2,
567 &service, &name))
572 { 568 {
573 GNUNET_break (0); 569 GNUNET_break (0);
574 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 570 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -576,8 +572,8 @@ handle_watch (void *cls,
576 } 572 }
577#if DEBUG_STATISTICS 573#if DEBUG_STATISTICS
578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
579 "Received request to watch statistic on `%s:%s'\n", 575 "Received request to watch statistic on `%s:%s'\n", service,
580 service, name); 576 name);
581#endif 577#endif
582 pos = start; 578 pos = start;
583 while (pos != NULL) 579 while (pos != NULL)
@@ -588,8 +584,9 @@ handle_watch (void *cls,
588 } 584 }
589 if (pos == NULL) 585 if (pos == NULL)
590 { 586 {
591 pos = GNUNET_malloc (sizeof (struct StatsEntry) + 587 pos =
592 sizeof (struct GNUNET_STATISTICS_SetMessage) + size); 588 GNUNET_malloc (sizeof (struct StatsEntry) +
589 sizeof (struct GNUNET_STATISTICS_SetMessage) + size);
593 pos->next = start; 590 pos->next = start;
594 pos->uid = uidgen++; 591 pos->uid = uidgen++;
595 pos->msg = (void *) &pos[1]; 592 pos->msg = (void *) &pos[1];
@@ -702,8 +699,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
702 * @param c configuration to use 699 * @param c configuration to use
703 */ 700 */
704static void 701static void
705run (void *cls, 702run (void *cls, struct GNUNET_SERVER_Handle *server,
706 struct GNUNET_SERVER_Handle *server,
707 const struct GNUNET_CONFIGURATION_Handle *c) 703 const struct GNUNET_CONFIGURATION_Handle *c)
708{ 704{
709 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 705 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -717,8 +713,8 @@ run (void *cls,
717 nc = GNUNET_SERVER_notification_context_create (server, 16); 713 nc = GNUNET_SERVER_notification_context_create (server, 16);
718 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 714 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
719 load (server); 715 load (server);
720 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 716 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
721 &shutdown_task, NULL); 717 NULL);
722} 718}
723 719
724 720
@@ -733,9 +729,7 @@ int
733main (int argc, char *const *argv) 729main (int argc, char *const *argv)
734{ 730{
735 return (GNUNET_OK == 731 return (GNUNET_OK ==
736 GNUNET_SERVICE_run (argc, 732 GNUNET_SERVICE_run (argc, argv, "statistics",
737 argv,
738 "statistics",
739 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; 733 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
740} 734}
741 735