aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/gnunet-service-statistics.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-04-18 09:55:09 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-04-18 09:55:09 +0000
commit9458bb0f06206d74f4e8e7a4cdadd0d2b579a340 (patch)
treed98aacdd61d673d8e302c152745a6e0330716d06 /src/statistics/gnunet-service-statistics.c
parenta5146a4cbe70177d9110553072d605ba151867be (diff)
downloadgnunet-9458bb0f06206d74f4e8e7a4cdadd0d2b579a340.tar.gz
gnunet-9458bb0f06206d74f4e8e7a4cdadd0d2b579a340.zip
fixing bug 2272: added functionality for watch to notifz about fresh created entries with value 0
Diffstat (limited to 'src/statistics/gnunet-service-statistics.c')
-rw-r--r--src/statistics/gnunet-service-statistics.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c
index a1a2c3abd..5b96edfa0 100644
--- a/src/statistics/gnunet-service-statistics.c
+++ b/src/statistics/gnunet-service-statistics.c
@@ -66,6 +66,12 @@ struct WatchEntry
66 */ 66 */
67 uint32_t wid; 67 uint32_t wid;
68 68
69 /**
70 * Is last_value valid
71 * GNUNET_NO : last_value is n/a, GNUNET_YES: last_value is valid
72 */
73 int last_value_set;
74
69}; 75};
70 76
71 77
@@ -152,6 +158,12 @@ struct StatsEntry
152 */ 158 */
153 int persistent; 159 int persistent;
154 160
161 /**
162 * Is this value set?
163 * GNUNET_NO : value is n/a, GNUNET_YES: value is valid
164 */
165 int set;
166
155}; 167};
156 168
157/** 169/**
@@ -462,8 +474,15 @@ notify_change (struct StatsEntry *se)
462 474
463 for (pos = se->we_head; NULL != pos; pos = pos->next) 475 for (pos = se->we_head; NULL != pos; pos = pos->next)
464 { 476 {
465 if (pos->last_value == se->value) 477 if (GNUNET_YES == pos->last_value_set)
466 continue; 478 {
479 if (pos->last_value == se->value)
480 continue;
481 }
482 else
483 {
484 pos->last_value_set = GNUNET_YES;
485 }
467 wvm.header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE); 486 wvm.header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE);
468 wvm.header.size = 487 wvm.header.size =
469 htons (sizeof (struct GNUNET_STATISTICS_WatchValueMessage)); 488 htons (sizeof (struct GNUNET_STATISTICS_WatchValueMessage));
@@ -499,6 +518,7 @@ handle_set (void *cls, struct GNUNET_SERVER_Client *client,
499 uint64_t value; 518 uint64_t value;
500 int64_t delta; 519 int64_t delta;
501 int changed; 520 int changed;
521 int initial_set;
502 522
503 if ( (NULL != client) && 523 if ( (NULL != client) &&
504 (NULL == make_client_entry (client)) ) 524 (NULL == make_client_entry (client)) )
@@ -532,6 +552,7 @@ handle_set (void *cls, struct GNUNET_SERVER_Client *client,
532 { 552 {
533 if (matches (pos, service, name)) 553 if (matches (pos, service, name))
534 { 554 {
555 initial_set = 0;
535 if ((flags & GNUNET_STATISTICS_SETFLAG_RELATIVE) == 0) 556 if ((flags & GNUNET_STATISTICS_SETFLAG_RELATIVE) == 0)
536 { 557 {
537 changed = (pos->value != value); 558 changed = (pos->value != value);
@@ -552,6 +573,11 @@ handle_set (void *cls, struct GNUNET_SERVER_Client *client,
552 pos->value += delta; 573 pos->value += delta;
553 } 574 }
554 } 575 }
576 if (GNUNET_NO == pos->set)
577 {
578 pos->set = GNUNET_YES;
579 initial_set = 1;
580 }
555 pos->msg->value = GNUNET_htonll (pos->value); 581 pos->msg->value = GNUNET_htonll (pos->value);
556 pos->msg->flags = msg->flags; 582 pos->msg->flags = msg->flags;
557 pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT)); 583 pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT));
@@ -565,7 +591,7 @@ handle_set (void *cls, struct GNUNET_SERVER_Client *client,
565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 591 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
566 "Statistic `%s:%s' updated to value %llu.\n", service, name, 592 "Statistic `%s:%s' updated to value %llu.\n", service, name,
567 pos->value); 593 pos->value);
568 if (changed) 594 if ((changed) || (1 == initial_set))
569 notify_change (pos); 595 notify_change (pos);
570 GNUNET_SERVER_receive_done (client, GNUNET_OK); 596 GNUNET_SERVER_receive_done (client, GNUNET_OK);
571 return; 597 return;
@@ -577,7 +603,14 @@ handle_set (void *cls, struct GNUNET_SERVER_Client *client,
577 pos->next = start; 603 pos->next = start;
578 if (((flags & GNUNET_STATISTICS_SETFLAG_RELATIVE) == 0) || 604 if (((flags & GNUNET_STATISTICS_SETFLAG_RELATIVE) == 0) ||
579 (0 < (int64_t) GNUNET_ntohll (msg->value))) 605 (0 < (int64_t) GNUNET_ntohll (msg->value)))
606 {
580 pos->value = GNUNET_ntohll (msg->value); 607 pos->value = GNUNET_ntohll (msg->value);
608 pos->set = GNUNET_YES;
609 }
610 else
611 {
612 pos->set = GNUNET_NO;
613 }
581 pos->uid = uidgen++; 614 pos->uid = uidgen++;
582 pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT)); 615 pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT));
583 pos->msg = (void *) &pos[1]; 616 pos->msg = (void *) &pos[1];
@@ -652,6 +685,7 @@ handle_watch (void *cls, struct GNUNET_SERVER_Client *client,
652 sizeof (struct GNUNET_STATISTICS_SetMessage) + size); 685 sizeof (struct GNUNET_STATISTICS_SetMessage) + size);
653 pos->next = start; 686 pos->next = start;
654 pos->uid = uidgen++; 687 pos->uid = uidgen++;
688 pos->set = GNUNET_NO;
655 pos->msg = (void *) &pos[1]; 689 pos->msg = (void *) &pos[1];
656 pos->msg->header.size = 690 pos->msg->header.size =
657 htons (sizeof (struct GNUNET_STATISTICS_SetMessage) + size); 691 htons (sizeof (struct GNUNET_STATISTICS_SetMessage) + size);
@@ -662,9 +696,13 @@ handle_watch (void *cls, struct GNUNET_SERVER_Client *client,
662 pos->name = &pos->service[slen]; 696 pos->name = &pos->service[slen];
663 memcpy ((void *) pos->name, name, strlen (name) + 1); 697 memcpy ((void *) pos->name, name, strlen (name) + 1);
664 start = pos; 698 start = pos;
699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
700 "New statistic on `%s:%s' with value %llu created.\n", service,
701 name, pos->value);
665 } 702 }
666 we = GNUNET_malloc (sizeof (struct WatchEntry)); 703 we = GNUNET_malloc (sizeof (struct WatchEntry));
667 we->client = client; 704 we->client = client;
705 we->last_value_set = GNUNET_NO;
668 GNUNET_SERVER_client_keep (client); 706 GNUNET_SERVER_client_keep (client);
669 we->wid = ce->max_wid++; 707 we->wid = ce->max_wid++;
670 GNUNET_CONTAINER_DLL_insert (pos->we_head, pos->we_tail, we); 708 GNUNET_CONTAINER_DLL_insert (pos->we_head, pos->we_tail, we);