aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/statistics_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-05-06 18:37:04 +0000
committerChristian Grothoff <christian@grothoff.org>2012-05-06 18:37:04 +0000
commitbbb7d801bd99e9955b7f5529c9905428ce03cd92 (patch)
tree97523cc88e2c49b4494aaa4185190dae6bfa8eb2 /src/statistics/statistics_api.c
parente6b55e45670cb905a1fff70fbdbc48809a41315e (diff)
downloadgnunet-bbb7d801bd99e9955b7f5529c9905428ce03cd92.tar.gz
gnunet-bbb7d801bd99e9955b7f5529c9905428ce03cd92.zip
-fixing #2310
Diffstat (limited to 'src/statistics/statistics_api.c')
-rw-r--r--src/statistics/statistics_api.c83
1 files changed, 45 insertions, 38 deletions
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c
index 85eb569eb..0533ff950 100644
--- a/src/statistics/statistics_api.c
+++ b/src/statistics/statistics_api.c
@@ -280,8 +280,8 @@ schedule_watch_request (struct GNUNET_STATISTICS_Handle *h,
280 size_t nlen; 280 size_t nlen;
281 size_t nsize; 281 size_t nsize;
282 282
283 GNUNET_assert (h != NULL); 283 GNUNET_assert (NULL != h);
284 GNUNET_assert (watch != NULL); 284 GNUNET_assert (NULL != watch);
285 285
286 slen = strlen (watch->subsystem) + 1; 286 slen = strlen (watch->subsystem) + 1;
287 nlen = strlen (watch->name) + 1; 287 nlen = strlen (watch->name) + 1;
@@ -344,7 +344,7 @@ do_disconnect (struct GNUNET_STATISTICS_Handle *h)
344 if (NULL != (c = h->current)) 344 if (NULL != (c = h->current))
345 { 345 {
346 h->current = NULL; 346 h->current = NULL;
347 if (c->cont != NULL) 347 if (NULL != c->cont)
348 c->cont (c->cls, GNUNET_SYSERR); 348 c->cont (c->cls, GNUNET_SYSERR);
349 free_action_item (c); 349 free_action_item (c);
350 } 350 }
@@ -364,12 +364,12 @@ try_connect (struct GNUNET_STATISTICS_Handle *h)
364 struct GNUNET_STATISTICS_GetHandle *gn; 364 struct GNUNET_STATISTICS_GetHandle *gn;
365 unsigned int i; 365 unsigned int i;
366 366
367 if (h->backoff_task != GNUNET_SCHEDULER_NO_TASK) 367 if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task)
368 return GNUNET_NO; 368 return GNUNET_NO;
369 if (h->client != NULL) 369 if (NULL != h->client)
370 return GNUNET_YES; 370 return GNUNET_YES;
371 h->client = GNUNET_CLIENT_connect ("statistics", h->cfg); 371 h->client = GNUNET_CLIENT_connect ("statistics", h->cfg);
372 if (h->client != NULL) 372 if (NULL != h->client)
373 { 373 {
374 gn = h->action_head; 374 gn = h->action_head;
375 while (NULL != (gh = gn)) 375 while (NULL != (gh = gn))
@@ -440,7 +440,7 @@ reconnect_later (struct GNUNET_STATISTICS_Handle *h)
440 struct GNUNET_STATISTICS_GetHandle *gh; 440 struct GNUNET_STATISTICS_GetHandle *gh;
441 441
442 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->backoff_task); 442 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->backoff_task);
443 if (h->do_destroy) 443 if (GNUNET_YES == h->do_destroy)
444 { 444 {
445 /* So we are shutting down and the service is not reachable. 445 /* So we are shutting down and the service is not reachable.
446 * Chances are that it's down for good and we are not going to connect to 446 * Chances are that it's down for good and we are not going to connect to
@@ -449,7 +449,7 @@ reconnect_later (struct GNUNET_STATISTICS_Handle *h)
449 */ 449 */
450 loss = GNUNET_NO; 450 loss = GNUNET_NO;
451 for (gh = h->action_head; NULL != gh; gh = gh->next) 451 for (gh = h->action_head; NULL != gh; gh = gh->next)
452 if ( (gh->make_persistent) && (gh->type == ACTION_SET) ) 452 if ( (gh->make_persistent) && (ACTION_SET == gh->type) )
453 loss = GNUNET_YES; 453 loss = GNUNET_YES;
454 if (GNUNET_YES == loss) 454 if (GNUNET_YES == loss)
455 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 455 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -565,7 +565,7 @@ destroy_task (void *cls,
565{ 565{
566 struct GNUNET_STATISTICS_Handle *h = cls; 566 struct GNUNET_STATISTICS_Handle *h = cls;
567 567
568 GNUNET_STATISTICS_destroy (h, GNUNET_YES); 568 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
569} 569}
570 570
571 571
@@ -582,7 +582,7 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg)
582 struct GNUNET_STATISTICS_GetHandle *c; 582 struct GNUNET_STATISTICS_GetHandle *c;
583 int ret; 583 int ret;
584 584
585 if (msg == NULL) 585 if (NULL == msg)
586 { 586 {
587 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 587 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
588 "Error receiving statistics from service, is the service running?\n"); 588 "Error receiving statistics from service, is the service running?\n");
@@ -626,7 +626,7 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg)
626 } 626 }
627 h->current = NULL; 627 h->current = NULL;
628 schedule_action (h); 628 schedule_action (h);
629 if (c->cont != NULL) 629 if (NULL != c->cont)
630 c->cont (c->cls, GNUNET_OK); 630 c->cont (c->cls, GNUNET_OK);
631 free_action_item (c); 631 free_action_item (c);
632 return; 632 return;
@@ -688,7 +688,7 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
688 uint16_t msize; 688 uint16_t msize;
689 689
690 GNUNET_assert (NULL != (c = handle->current)); 690 GNUNET_assert (NULL != (c = handle->current));
691 if (buf == NULL) 691 if (NULL == buf)
692 { 692 {
693 /* timeout / error */ 693 /* timeout / error */
694 LOG (GNUNET_ERROR_TYPE_DEBUG, 694 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -737,7 +737,7 @@ transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
737 size_t slen2; 737 size_t slen2;
738 uint16_t msize; 738 uint16_t msize;
739 739
740 if (buf == NULL) 740 if (NULL == buf)
741 { 741 {
742 /* timeout / error */ 742 /* timeout / error */
743 LOG (GNUNET_ERROR_TYPE_DEBUG, 743 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -875,8 +875,8 @@ GNUNET_STATISTICS_create (const char *subsystem,
875{ 875{
876 struct GNUNET_STATISTICS_Handle *ret; 876 struct GNUNET_STATISTICS_Handle *ret;
877 877
878 GNUNET_assert (subsystem != NULL); 878 GNUNET_assert (NULL != subsystem);
879 GNUNET_assert (cfg != NULL); 879 GNUNET_assert (NULL != cfg);
880 ret = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_Handle)); 880 ret = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_Handle));
881 ret->cfg = cfg; 881 ret->cfg = cfg;
882 ret->subsystem = GNUNET_strdup (subsystem); 882 ret->subsystem = GNUNET_strdup (subsystem);
@@ -901,7 +901,7 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first)
901 struct GNUNET_TIME_Relative timeout; 901 struct GNUNET_TIME_Relative timeout;
902 int i; 902 int i;
903 903
904 if (h == NULL) 904 if (NULL == h)
905 return; 905 return;
906 GNUNET_assert (GNUNET_NO == h->do_destroy); // Don't call twice. 906 GNUNET_assert (GNUNET_NO == h->do_destroy); // Don't call twice.
907 if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task) 907 if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task)
@@ -913,7 +913,7 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first)
913 { 913 {
914 if (NULL != h->current) 914 if (NULL != h->current)
915 { 915 {
916 if (h->current->type == ACTION_GET) 916 if (ACTION_GET == h->current->type)
917 { 917 {
918 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); 918 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
919 h->th = NULL; 919 h->th = NULL;
@@ -925,7 +925,7 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first)
925 while (NULL != (pos = next)) 925 while (NULL != (pos = next))
926 { 926 {
927 next = pos->next; 927 next = pos->next;
928 if (pos->type == ACTION_GET) 928 if (ACTION_GET == pos->type)
929 { 929 {
930 GNUNET_CONTAINER_DLL_remove (h->action_head, 930 GNUNET_CONTAINER_DLL_remove (h->action_head,
931 h->action_tail, 931 h->action_tail,
@@ -939,7 +939,7 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first)
939 h->action_tail, 939 h->action_tail,
940 h->current); 940 h->current);
941 h->do_destroy = GNUNET_YES; 941 h->do_destroy = GNUNET_YES;
942 if ((h->current != NULL) && (h->th == NULL) && 942 if ((NULL != h->current) && (NULL == h->th) &&
943 (NULL != h->client)) 943 (NULL != h->client))
944 { 944 {
945 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); 945 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
@@ -992,6 +992,7 @@ transmit_test_on_shutdown (void *cls,
992 struct GNUNET_STATISTICS_Handle *h = cls; 992 struct GNUNET_STATISTICS_Handle *h = cls;
993 struct GNUNET_MessageHeader hdr; 993 struct GNUNET_MessageHeader hdr;
994 994
995 h->th = NULL;
995 if (NULL == buf) 996 if (NULL == buf)
996 { 997 {
997 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 998 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1004,6 +1005,12 @@ transmit_test_on_shutdown (void *cls,
1004 hdr.type = htons (GNUNET_MESSAGE_TYPE_TEST); 1005 hdr.type = htons (GNUNET_MESSAGE_TYPE_TEST);
1005 hdr.size = htons (sizeof (struct GNUNET_MessageHeader)); 1006 hdr.size = htons (sizeof (struct GNUNET_MessageHeader));
1006 memcpy (buf, &hdr, sizeof (hdr)); 1007 memcpy (buf, &hdr, sizeof (hdr));
1008 if (GNUNET_YES != h->receiving)
1009 {
1010 h->receiving = GNUNET_YES;
1011 GNUNET_CLIENT_receive (h->client, &receive_stats, h,
1012 GNUNET_TIME_UNIT_FOREVER_REL);
1013 }
1007 return sizeof (struct GNUNET_MessageHeader); 1014 return sizeof (struct GNUNET_MessageHeader);
1008} 1015}
1009 1016
@@ -1018,8 +1025,8 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h)
1018{ 1025{
1019 struct GNUNET_TIME_Relative timeout; 1026 struct GNUNET_TIME_Relative timeout;
1020 1027
1021 if ( (h->th != NULL) || 1028 if ( (NULL != h->th) ||
1022 (h->backoff_task != GNUNET_SCHEDULER_NO_TASK) ) 1029 (GNUNET_SCHEDULER_NO_TASK != h->backoff_task) )
1023 return; /* action already pending */ 1030 return; /* action already pending */
1024 if (GNUNET_YES != try_connect (h)) 1031 if (GNUNET_YES != try_connect (h))
1025 { 1032 {
@@ -1032,7 +1039,7 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h)
1032 h->current = h->action_head; 1039 h->current = h->action_head;
1033 if (NULL == h->current) 1040 if (NULL == h->current)
1034 { 1041 {
1035 if (h->do_destroy) 1042 if (GNUNET_YES == h->do_destroy)
1036 { 1043 {
1037 h->do_destroy = GNUNET_SYSERR; /* in 'TEST' mode */ 1044 h->do_destroy = GNUNET_SYSERR; /* in 'TEST' mode */
1038 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, 1045 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
@@ -1085,11 +1092,11 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
1085 1092
1086 if (NULL == handle) 1093 if (NULL == handle)
1087 return NULL; 1094 return NULL;
1088 GNUNET_assert (proc != NULL); 1095 GNUNET_assert (NULL != proc);
1089 GNUNET_assert (GNUNET_NO == handle->do_destroy); 1096 GNUNET_assert (GNUNET_NO == handle->do_destroy);
1090 if (subsystem == NULL) 1097 if (NULL == subsystem)
1091 subsystem = ""; 1098 subsystem = "";
1092 if (name == NULL) 1099 if (NULL == name)
1093 name = ""; 1100 name = "";
1094 slen1 = strlen (subsystem) + 1; 1101 slen1 = strlen (subsystem) + 1;
1095 slen2 = strlen (name) + 1; 1102 slen2 = strlen (name) + 1;
@@ -1154,7 +1161,7 @@ GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
1154{ 1161{
1155 struct GNUNET_STATISTICS_WatchEntry *w; 1162 struct GNUNET_STATISTICS_WatchEntry *w;
1156 1163
1157 if (handle == NULL) 1164 if (NULL == handle)
1158 return GNUNET_SYSERR; 1165 return GNUNET_SYSERR;
1159 w = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_WatchEntry)); 1166 w = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_WatchEntry));
1160 w->subsystem = GNUNET_strdup (subsystem); 1167 w->subsystem = GNUNET_strdup (subsystem);
@@ -1185,7 +1192,7 @@ GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle,
1185 struct GNUNET_STATISTICS_WatchEntry *w; 1192 struct GNUNET_STATISTICS_WatchEntry *w;
1186 unsigned int i; 1193 unsigned int i;
1187 1194
1188 if (handle == NULL) 1195 if (NULL == handle)
1189 return GNUNET_SYSERR; 1196 return GNUNET_SYSERR;
1190 for (i=0;i<handle->watches_size;i++) 1197 for (i=0;i<handle->watches_size;i++)
1191 { 1198 {
@@ -1228,8 +1235,8 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name,
1228 size_t nsize; 1235 size_t nsize;
1229 int64_t delta; 1236 int64_t delta;
1230 1237
1231 GNUNET_assert (h != NULL); 1238 GNUNET_assert (NULL != h);
1232 GNUNET_assert (name != NULL); 1239 GNUNET_assert (NULL != name);
1233 slen = strlen (h->subsystem) + 1; 1240 slen = strlen (h->subsystem) + 1;
1234 nlen = strlen (name) + 1; 1241 nlen = strlen (name) + 1;
1235 nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen; 1242 nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
@@ -1238,16 +1245,16 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name,
1238 GNUNET_break (0); 1245 GNUNET_break (0);
1239 return; 1246 return;
1240 } 1247 }
1241 for (ai = h->action_head; ai != NULL; ai = ai->next) 1248 for (ai = h->action_head; NULL != ai; ai = ai->next)
1242 { 1249 {
1243 if (! ( (0 == strcmp (ai->subsystem, h->subsystem)) && 1250 if (! ( (0 == strcmp (ai->subsystem, h->subsystem)) &&
1244 (0 == strcmp (ai->name, name)) && 1251 (0 == strcmp (ai->name, name)) &&
1245 ( (ai->type == ACTION_UPDATE) || 1252 ( (ACTION_UPDATE == ai->type) ||
1246 (ai->type == ACTION_SET) ) ) ) 1253 (ACTION_SET == ai->type) ) ) )
1247 continue; 1254 continue;
1248 if (ai->type == ACTION_SET) 1255 if (ACTION_SET == ai->type)
1249 { 1256 {
1250 if (type == ACTION_UPDATE) 1257 if (ACTION_UPDATE == type)
1251 { 1258 {
1252 delta = (int64_t) value; 1259 delta = (int64_t) value;
1253 if (delta > 0) 1260 if (delta > 0)
@@ -1272,7 +1279,7 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name,
1272 } 1279 }
1273 else 1280 else
1274 { 1281 {
1275 if (type == ACTION_UPDATE) 1282 if (ACTION_UPDATE == type)
1276 { 1283 {
1277 /* make delta cummulative */ 1284 /* make delta cummulative */
1278 delta = (int64_t) value; 1285 delta = (int64_t) value;
@@ -1318,7 +1325,7 @@ void
1318GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, 1325GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
1319 const char *name, uint64_t value, int make_persistent) 1326 const char *name, uint64_t value, int make_persistent)
1320{ 1327{
1321 if (handle == NULL) 1328 if (NULL == handle)
1322 return; 1329 return;
1323 GNUNET_assert (GNUNET_NO == handle->do_destroy); 1330 GNUNET_assert (GNUNET_NO == handle->do_destroy);
1324 add_setter_action (handle, name, make_persistent, value, ACTION_SET); 1331 add_setter_action (handle, name, make_persistent, value, ACTION_SET);
@@ -1338,9 +1345,9 @@ void
1338GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, 1345GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
1339 const char *name, int64_t delta, int make_persistent) 1346 const char *name, int64_t delta, int make_persistent)
1340{ 1347{
1341 if (handle == NULL) 1348 if (NULL == handle)
1342 return; 1349 return;
1343 if (delta == 0) 1350 if (0 == delta)
1344 return; 1351 return;
1345 GNUNET_assert (GNUNET_NO == handle->do_destroy); 1352 GNUNET_assert (GNUNET_NO == handle->do_destroy);
1346 add_setter_action (handle, name, make_persistent, (uint64_t) delta, 1353 add_setter_action (handle, name, make_persistent, (uint64_t) delta,