diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-21 18:29:03 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-21 18:29:03 +0000 |
commit | 3d7b29ec1c5d1c2de96cf4c9badaa112e86ef899 (patch) | |
tree | b586e13615fe58377cef5c0a238a677e5fd8f609 /src | |
parent | 1732154b8c021e7ee0e34c28cf3b1a843454727a (diff) | |
download | gnunet-3d7b29ec1c5d1c2de96cf4c9badaa112e86ef899.tar.gz gnunet-3d7b29ec1c5d1c2de96cf4c9badaa112e86ef899.zip |
update statistics API to use new MQ API style, also get rid of timeout argument
Diffstat (limited to 'src')
-rw-r--r-- | src/core/test_core_quota_compliance.c | 16 | ||||
-rw-r--r-- | src/datastore/gnunet-service-datastore.c | 35 | ||||
-rw-r--r-- | src/fs/perf_gnunet_service_fs_p2p.c | 2 | ||||
-rw-r--r-- | src/fs/perf_gnunet_service_fs_p2p_respect.c | 2 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_client.c | 36 | ||||
-rw-r--r-- | src/include/gnunet_statistics_service.h | 15 | ||||
-rw-r--r-- | src/include/gnunet_strings_lib.h | 2 | ||||
-rw-r--r-- | src/regex/gnunet-regex-profiler.c | 1 | ||||
-rw-r--r-- | src/set/gnunet-set-profiler.c | 5 | ||||
-rw-r--r-- | src/statistics/Makefile.am | 22 | ||||
-rw-r--r-- | src/statistics/gnunet-statistics.c | 88 | ||||
-rw-r--r-- | src/statistics/statistics_api.c | 934 | ||||
-rw-r--r-- | src/statistics/test_statistics_api.c | 86 | ||||
-rw-r--r-- | src/statistics/test_statistics_api_loop.c | 2 | ||||
-rw-r--r-- | src/testbed/testbed_api_statistics.c | 7 |
15 files changed, 616 insertions, 637 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index 59a3e8a7f..05b1ae3d9 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c | |||
@@ -242,29 +242,29 @@ measurement_stop (void *cls) | |||
242 | else | 242 | else |
243 | ok = 0; /* pass */ | 243 | ok = 0; /* pass */ |
244 | GNUNET_STATISTICS_get (p1.stats, "core", "# discarded CORE_SEND requests", | 244 | GNUNET_STATISTICS_get (p1.stats, "core", "# discarded CORE_SEND requests", |
245 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1); | 245 | NULL, &print_stat, &p1); |
246 | 246 | ||
247 | GNUNET_STATISTICS_get (p1.stats, "core", | 247 | GNUNET_STATISTICS_get (p1.stats, "core", |
248 | "# discarded CORE_SEND request bytes", | 248 | "# discarded CORE_SEND request bytes", |
249 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1); | 249 | NULL, &print_stat, &p1); |
250 | GNUNET_STATISTICS_get (p1.stats, "core", | 250 | GNUNET_STATISTICS_get (p1.stats, "core", |
251 | "# discarded lower priority CORE_SEND requests", | 251 | "# discarded lower priority CORE_SEND requests", |
252 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, NULL); | 252 | NULL, &print_stat, NULL); |
253 | GNUNET_STATISTICS_get (p1.stats, "core", | 253 | GNUNET_STATISTICS_get (p1.stats, "core", |
254 | "# discarded lower priority CORE_SEND request bytes", | 254 | "# discarded lower priority CORE_SEND request bytes", |
255 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1); | 255 | NULL, &print_stat, &p1); |
256 | GNUNET_STATISTICS_get (p2.stats, "core", "# discarded CORE_SEND requests", | 256 | GNUNET_STATISTICS_get (p2.stats, "core", "# discarded CORE_SEND requests", |
257 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); | 257 | NULL, &print_stat, &p2); |
258 | 258 | ||
259 | GNUNET_STATISTICS_get (p2.stats, "core", | 259 | GNUNET_STATISTICS_get (p2.stats, "core", |
260 | "# discarded CORE_SEND request bytes", | 260 | "# discarded CORE_SEND request bytes", |
261 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); | 261 | NULL, &print_stat, &p2); |
262 | GNUNET_STATISTICS_get (p2.stats, "core", | 262 | GNUNET_STATISTICS_get (p2.stats, "core", |
263 | "# discarded lower priority CORE_SEND requests", | 263 | "# discarded lower priority CORE_SEND requests", |
264 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); | 264 | NULL, &print_stat, &p2); |
265 | GNUNET_STATISTICS_get (p2.stats, "core", | 265 | GNUNET_STATISTICS_get (p2.stats, "core", |
266 | "# discarded lower priority CORE_SEND request bytes", | 266 | "# discarded lower priority CORE_SEND request bytes", |
267 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); | 267 | NULL, &print_stat, &p2); |
268 | 268 | ||
269 | if (ok != 0) | 269 | if (ok != 0) |
270 | kind = GNUNET_ERROR_TYPE_ERROR; | 270 | kind = GNUNET_ERROR_TYPE_ERROR; |
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index 64c3640ad..a67d1c772 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c | |||
@@ -54,6 +54,11 @@ | |||
54 | static char *quota_stat_name; | 54 | static char *quota_stat_name; |
55 | 55 | ||
56 | /** | 56 | /** |
57 | * Task to timeout stat GET. | ||
58 | */ | ||
59 | static struct GNUNET_SCHEDULER_Task *stat_timeout_task; | ||
60 | |||
61 | /** | ||
57 | * After how many payload-changing operations | 62 | * After how many payload-changing operations |
58 | * do we sync our statistics? | 63 | * do we sync our statistics? |
59 | */ | 64 | */ |
@@ -1526,8 +1531,12 @@ static void | |||
1526 | process_stat_done (void *cls, | 1531 | process_stat_done (void *cls, |
1527 | int success) | 1532 | int success) |
1528 | { | 1533 | { |
1529 | |||
1530 | stat_get = NULL; | 1534 | stat_get = NULL; |
1535 | if (NULL != stat_timeout_task) | ||
1536 | { | ||
1537 | GNUNET_SCHEDULER_cancel (stat_timeout_task); | ||
1538 | stat_timeout_task = NULL; | ||
1539 | } | ||
1531 | plugin = load_plugin (); | 1540 | plugin = load_plugin (); |
1532 | if (NULL == plugin) | 1541 | if (NULL == plugin) |
1533 | { | 1542 | { |
@@ -1576,6 +1585,20 @@ process_stat_done (void *cls, | |||
1576 | 1585 | ||
1577 | 1586 | ||
1578 | /** | 1587 | /** |
1588 | * Fetching stats took to long, run without. | ||
1589 | * | ||
1590 | * @param cls NULL | ||
1591 | */ | ||
1592 | static void | ||
1593 | stat_timeout (void *cls) | ||
1594 | { | ||
1595 | stat_timeout_task = NULL; | ||
1596 | GNUNET_STATISTICS_get_cancel (stat_get); | ||
1597 | process_stat_done (NULL, GNUNET_NO); | ||
1598 | } | ||
1599 | |||
1600 | |||
1601 | /** | ||
1579 | * Task run during shutdown. | 1602 | * Task run during shutdown. |
1580 | */ | 1603 | */ |
1581 | static void | 1604 | static void |
@@ -1617,6 +1640,11 @@ cleaning_task (void *cls) | |||
1617 | GNUNET_STATISTICS_get_cancel (stat_get); | 1640 | GNUNET_STATISTICS_get_cancel (stat_get); |
1618 | stat_get = NULL; | 1641 | stat_get = NULL; |
1619 | } | 1642 | } |
1643 | if (NULL != stat_timeout_task) | ||
1644 | { | ||
1645 | GNUNET_SCHEDULER_cancel (stat_timeout_task); | ||
1646 | stat_timeout_task = NULL; | ||
1647 | } | ||
1620 | GNUNET_free_non_null (plugin_name); | 1648 | GNUNET_free_non_null (plugin_name); |
1621 | plugin_name = NULL; | 1649 | plugin_name = NULL; |
1622 | if (last_sync > 0) | 1650 | if (last_sync > 0) |
@@ -1813,12 +1841,15 @@ run (void *cls, | |||
1813 | GNUNET_STATISTICS_get (stats, | 1841 | GNUNET_STATISTICS_get (stats, |
1814 | "datastore", | 1842 | "datastore", |
1815 | quota_stat_name, | 1843 | quota_stat_name, |
1816 | GNUNET_TIME_UNIT_SECONDS, | ||
1817 | &process_stat_done, | 1844 | &process_stat_done, |
1818 | &process_stat_in, | 1845 | &process_stat_in, |
1819 | NULL); | 1846 | NULL); |
1820 | if (NULL == stat_get) | 1847 | if (NULL == stat_get) |
1821 | process_stat_done (NULL, GNUNET_SYSERR); | 1848 | process_stat_done (NULL, GNUNET_SYSERR); |
1849 | else | ||
1850 | stat_timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
1851 | &stat_timeout, | ||
1852 | NULL); | ||
1822 | GNUNET_SERVER_disconnect_notify (server, | 1853 | GNUNET_SERVER_disconnect_notify (server, |
1823 | &cleanup_reservations, | 1854 | &cleanup_reservations, |
1824 | NULL); | 1855 | NULL); |
diff --git a/src/fs/perf_gnunet_service_fs_p2p.c b/src/fs/perf_gnunet_service_fs_p2p.c index 40b2b977b..5211beef8 100644 --- a/src/fs/perf_gnunet_service_fs_p2p.c +++ b/src/fs/perf_gnunet_service_fs_p2p.c | |||
@@ -213,7 +213,7 @@ stat_run (void *cls, | |||
213 | #else | 213 | #else |
214 | stats[sm->value].subsystem, stats[sm->value].name, | 214 | stats[sm->value].subsystem, stats[sm->value].name, |
215 | #endif | 215 | #endif |
216 | GNUNET_TIME_UNIT_FOREVER_REL, &get_done, &print_stat, | 216 | &get_done, &print_stat, |
217 | sm); | 217 | sm); |
218 | return; | 218 | return; |
219 | } | 219 | } |
diff --git a/src/fs/perf_gnunet_service_fs_p2p_respect.c b/src/fs/perf_gnunet_service_fs_p2p_respect.c index 2527c8978..8098afbe9 100644 --- a/src/fs/perf_gnunet_service_fs_p2p_respect.c +++ b/src/fs/perf_gnunet_service_fs_p2p_respect.c | |||
@@ -254,7 +254,7 @@ stat_run (void *cls, | |||
254 | #else | 254 | #else |
255 | stats[sm->value].subsystem, stats[sm->value].name, | 255 | stats[sm->value].subsystem, stats[sm->value].name, |
256 | #endif | 256 | #endif |
257 | GNUNET_TIME_UNIT_FOREVER_REL, &get_done, &print_stat, | 257 | &get_done, &print_stat, |
258 | sm); | 258 | sm); |
259 | return; | 259 | return; |
260 | } | 260 | } |
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c index 15a82c2d5..df0cabe1d 100644 --- a/src/hostlist/gnunet-daemon-hostlist_client.c +++ b/src/hostlist/gnunet-daemon-hostlist_client.c | |||
@@ -1265,8 +1265,14 @@ handler_advertisement (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1265 | * successfully obtained, #GNUNET_SYSERR if not. | 1265 | * successfully obtained, #GNUNET_SYSERR if not. |
1266 | */ | 1266 | */ |
1267 | static void | 1267 | static void |
1268 | primary_task (void *cls, int success) | 1268 | primary_task (void *cls, |
1269 | int success) | ||
1269 | { | 1270 | { |
1271 | if (NULL != ti_check_download) | ||
1272 | { | ||
1273 | GNUNET_SCHEDULER_cancel (ti_check_download); | ||
1274 | ti_check_download = NULL; | ||
1275 | } | ||
1270 | sget = NULL; | 1276 | sget = NULL; |
1271 | GNUNET_assert (NULL != stats); | 1277 | GNUNET_assert (NULL != stats); |
1272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1276,6 +1282,24 @@ primary_task (void *cls, int success) | |||
1276 | 1282 | ||
1277 | 1283 | ||
1278 | /** | 1284 | /** |
1285 | * Continuation called by the statistics code once | ||
1286 | * we go the stat. Initiates hostlist download scheduling. | ||
1287 | * | ||
1288 | * @param cls closure | ||
1289 | * @param success #GNUNET_OK if statistics were | ||
1290 | * successfully obtained, #GNUNET_SYSERR if not. | ||
1291 | */ | ||
1292 | static void | ||
1293 | stat_timeout_task (void *cls) | ||
1294 | { | ||
1295 | GNUNET_STATISTICS_get_cancel (sget); | ||
1296 | sget = NULL; | ||
1297 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, | ||
1298 | NULL); | ||
1299 | } | ||
1300 | |||
1301 | |||
1302 | /** | ||
1279 | * We've received the previous delay value from statistics. Remember it. | 1303 | * We've received the previous delay value from statistics. Remember it. |
1280 | * | 1304 | * |
1281 | * @param cls NULL, unused | 1305 | * @param cls NULL, unused |
@@ -1637,7 +1661,6 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1637 | sget = GNUNET_STATISTICS_get (stats, "hostlist", | 1661 | sget = GNUNET_STATISTICS_get (stats, "hostlist", |
1638 | gettext_noop | 1662 | gettext_noop |
1639 | ("# milliseconds between hostlist downloads"), | 1663 | ("# milliseconds between hostlist downloads"), |
1640 | GNUNET_TIME_UNIT_MINUTES, | ||
1641 | &primary_task, | 1664 | &primary_task, |
1642 | &process_stat, | 1665 | &process_stat, |
1643 | NULL); | 1666 | NULL); |
@@ -1645,7 +1668,14 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1645 | { | 1668 | { |
1646 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1669 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1647 | "Statistics request failed, scheduling hostlist download\n"); | 1670 | "Statistics request failed, scheduling hostlist download\n"); |
1648 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); | 1671 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, |
1672 | NULL); | ||
1673 | } | ||
1674 | else | ||
1675 | { | ||
1676 | ti_check_download = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | ||
1677 | &stat_timeout_task, | ||
1678 | NULL); | ||
1649 | } | 1679 | } |
1650 | return GNUNET_OK; | 1680 | return GNUNET_OK; |
1651 | } | 1681 | } |
diff --git a/src/include/gnunet_statistics_service.h b/src/include/gnunet_statistics_service.h index 715f06130..2765a07a9 100644 --- a/src/include/gnunet_statistics_service.h +++ b/src/include/gnunet_statistics_service.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2009-2013 GNUnet e.V. | 3 | Copyright (C) 2009-2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -138,14 +138,15 @@ GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle, | |||
138 | 138 | ||
139 | 139 | ||
140 | /** | 140 | /** |
141 | * Continuation called by #GNUNET_STATISTICS_get functions. | 141 | * Continuation called by #GNUNET_STATISTICS_get() functions. |
142 | * | 142 | * |
143 | * @param cls closure | 143 | * @param cls closure |
144 | * @param success #GNUNET_OK if statistics were | 144 | * @param success #GNUNET_OK if statistics were |
145 | * successfully obtained, #GNUNET_SYSERR if not. | 145 | * successfully obtained, #GNUNET_SYSERR if not. |
146 | */ | 146 | */ |
147 | typedef void (*GNUNET_STATISTICS_Callback) (void *cls, | 147 | typedef void |
148 | int success); | 148 | (*GNUNET_STATISTICS_Callback) (void *cls, |
149 | int success); | ||
149 | 150 | ||
150 | 151 | ||
151 | /** | 152 | /** |
@@ -160,8 +161,6 @@ struct GNUNET_STATISTICS_GetHandle; | |||
160 | * @param handle identification of the statistics service | 161 | * @param handle identification of the statistics service |
161 | * @param subsystem limit to the specified subsystem, NULL for all subsystems | 162 | * @param subsystem limit to the specified subsystem, NULL for all subsystems |
162 | * @param name name of the statistic value, NULL for all values | 163 | * @param name name of the statistic value, NULL for all values |
163 | * @param timeout after how long should we give up (and call | ||
164 | * notify with buf NULL and size 0)? | ||
165 | * @param cont continuation to call when done (can be NULL) | 164 | * @param cont continuation to call when done (can be NULL) |
166 | * This callback CANNOT destroy the statistics handle in the same call. | 165 | * This callback CANNOT destroy the statistics handle in the same call. |
167 | * @param proc function to call on each value | 166 | * @param proc function to call on each value |
@@ -172,9 +171,9 @@ struct GNUNET_STATISTICS_GetHandle * | |||
172 | GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | 171 | GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, |
173 | const char *subsystem, | 172 | const char *subsystem, |
174 | const char *name, | 173 | const char *name, |
175 | struct GNUNET_TIME_Relative timeout, | ||
176 | GNUNET_STATISTICS_Callback cont, | 174 | GNUNET_STATISTICS_Callback cont, |
177 | GNUNET_STATISTICS_Iterator proc, void *cls); | 175 | GNUNET_STATISTICS_Iterator proc, |
176 | void *cls); | ||
178 | 177 | ||
179 | 178 | ||
180 | /** | 179 | /** |
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h index 03276134c..15d4f57ac 100644 --- a/src/include/gnunet_strings_lib.h +++ b/src/include/gnunet_strings_lib.h | |||
@@ -222,7 +222,7 @@ GNUNET_STRINGS_buffer_fill (char *buffer, | |||
222 | * in the buffer and assign the count (varargs) of type "const char**" | 222 | * in the buffer and assign the count (varargs) of type "const char**" |
223 | * to the locations of the respective strings in the buffer. | 223 | * to the locations of the respective strings in the buffer. |
224 | * | 224 | * |
225 | * @param buffer the buffer to parse | 225 | * @param buffer the buffer to parse FIXME: not 'const', is it? |
226 | * @param size size of the @a buffer | 226 | * @param size size of the @a buffer |
227 | * @param count number of strings to locate | 227 | * @param count number of strings to locate |
228 | * @param ... pointers to where to store the strings | 228 | * @param ... pointers to where to store the strings |
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c index f65681848..2114e2cb1 100644 --- a/src/regex/gnunet-regex-profiler.c +++ b/src/regex/gnunet-regex-profiler.c | |||
@@ -663,7 +663,6 @@ stats_connect_cb (void *cls, | |||
663 | peer->stats_handle = ca_result; | 663 | peer->stats_handle = ca_result; |
664 | 664 | ||
665 | if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, NULL, NULL, | 665 | if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, NULL, NULL, |
666 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
667 | &stats_cb, | 666 | &stats_cb, |
668 | &stats_iterator, peer)) | 667 | &stats_iterator, peer)) |
669 | { | 668 | { |
diff --git a/src/set/gnunet-set-profiler.c b/src/set/gnunet-set-profiler.c index 6d97f0bb1..df9443529 100644 --- a/src/set/gnunet-set-profiler.c +++ b/src/set/gnunet-set-profiler.c | |||
@@ -149,8 +149,9 @@ check_all_done (void) | |||
149 | } | 149 | } |
150 | 150 | ||
151 | statistics_file = fopen (statistics_filename, "w"); | 151 | statistics_file = fopen (statistics_filename, "w"); |
152 | GNUNET_STATISTICS_get (statistics, NULL, NULL, GNUNET_TIME_UNIT_FOREVER_REL, | 152 | GNUNET_STATISTICS_get (statistics, NULL, NULL, |
153 | statistics_done, statistics_result, NULL); | 153 | &statistics_done, |
154 | &statistics_result, NULL); | ||
154 | } | 155 | } |
155 | 156 | ||
156 | 157 | ||
diff --git a/src/statistics/Makefile.am b/src/statistics/Makefile.am index 1168fd476..0907c4a37 100644 --- a/src/statistics/Makefile.am +++ b/src/statistics/Makefile.am | |||
@@ -2,7 +2,7 @@ | |||
2 | AM_CPPFLAGS = -I$(top_srcdir)/src/include | 2 | AM_CPPFLAGS = -I$(top_srcdir)/src/include |
3 | 3 | ||
4 | if MINGW | 4 | if MINGW |
5 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols | 5 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols |
6 | endif | 6 | endif |
7 | 7 | ||
8 | if USE_COVERAGE | 8 | if USE_COVERAGE |
@@ -26,23 +26,23 @@ libgnunetstatistics_la_LIBADD = \ | |||
26 | $(GN_LIBINTL) $(XLIB) | 26 | $(GN_LIBINTL) $(XLIB) |
27 | libgnunetstatistics_la_LDFLAGS = \ | 27 | libgnunetstatistics_la_LDFLAGS = \ |
28 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ | 28 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ |
29 | -version-info 1:3:1 | 29 | -version-info 2:0:0 |
30 | 30 | ||
31 | libexec_PROGRAMS = \ | 31 | libexec_PROGRAMS = \ |
32 | gnunet-service-statistics | 32 | gnunet-service-statistics |
33 | 33 | ||
34 | bin_PROGRAMS = \ | 34 | bin_PROGRAMS = \ |
35 | gnunet-statistics | 35 | gnunet-statistics |
36 | 36 | ||
37 | gnunet_statistics_SOURCES = \ | 37 | gnunet_statistics_SOURCES = \ |
38 | gnunet-statistics.c | 38 | gnunet-statistics.c |
39 | gnunet_statistics_LDADD = \ | 39 | gnunet_statistics_LDADD = \ |
40 | libgnunetstatistics.la \ | 40 | libgnunetstatistics.la \ |
41 | $(top_builddir)/src/util/libgnunetutil.la \ | 41 | $(top_builddir)/src/util/libgnunetutil.la \ |
42 | $(GN_LIBINTL) | 42 | $(GN_LIBINTL) |
43 | 43 | ||
44 | gnunet_service_statistics_SOURCES = \ | 44 | gnunet_service_statistics_SOURCES = \ |
45 | gnunet-service-statistics.c | 45 | gnunet-service-statistics.c |
46 | gnunet_service_statistics_LDADD = \ | 46 | gnunet_service_statistics_LDADD = \ |
47 | libgnunetstatistics.la \ | 47 | libgnunetstatistics.la \ |
48 | $(top_builddir)/src/util/libgnunetutil.la \ | 48 | $(top_builddir)/src/util/libgnunetutil.la \ |
@@ -52,7 +52,7 @@ check_PROGRAMS = \ | |||
52 | test_statistics_api \ | 52 | test_statistics_api \ |
53 | test_statistics_api_loop \ | 53 | test_statistics_api_loop \ |
54 | test_statistics_api_watch \ | 54 | test_statistics_api_watch \ |
55 | test_statistics_api_watch_zero_value | 55 | test_statistics_api_watch_zero_value |
56 | 56 | ||
57 | if ENABLE_TEST_RUN | 57 | if ENABLE_TEST_RUN |
58 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; | 58 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; |
@@ -63,25 +63,25 @@ test_statistics_api_SOURCES = \ | |||
63 | test_statistics_api.c | 63 | test_statistics_api.c |
64 | test_statistics_api_LDADD = \ | 64 | test_statistics_api_LDADD = \ |
65 | libgnunetstatistics.la \ | 65 | libgnunetstatistics.la \ |
66 | $(top_builddir)/src/util/libgnunetutil.la | 66 | $(top_builddir)/src/util/libgnunetutil.la |
67 | 67 | ||
68 | test_statistics_api_loop_SOURCES = \ | 68 | test_statistics_api_loop_SOURCES = \ |
69 | test_statistics_api_loop.c | 69 | test_statistics_api_loop.c |
70 | test_statistics_api_loop_LDADD = \ | 70 | test_statistics_api_loop_LDADD = \ |
71 | libgnunetstatistics.la \ | 71 | libgnunetstatistics.la \ |
72 | $(top_builddir)/src/util/libgnunetutil.la | 72 | $(top_builddir)/src/util/libgnunetutil.la |
73 | 73 | ||
74 | test_statistics_api_watch_SOURCES = \ | 74 | test_statistics_api_watch_SOURCES = \ |
75 | test_statistics_api_watch.c | 75 | test_statistics_api_watch.c |
76 | test_statistics_api_watch_LDADD = \ | 76 | test_statistics_api_watch_LDADD = \ |
77 | libgnunetstatistics.la \ | 77 | libgnunetstatistics.la \ |
78 | $(top_builddir)/src/util/libgnunetutil.la | 78 | $(top_builddir)/src/util/libgnunetutil.la |
79 | 79 | ||
80 | test_statistics_api_watch_zero_value_SOURCES = \ | 80 | test_statistics_api_watch_zero_value_SOURCES = \ |
81 | test_statistics_api_watch_zero_value.c | 81 | test_statistics_api_watch_zero_value.c |
82 | test_statistics_api_watch_zero_value_LDADD = \ | 82 | test_statistics_api_watch_zero_value_LDADD = \ |
83 | libgnunetstatistics.la \ | 83 | libgnunetstatistics.la \ |
84 | $(top_builddir)/src/util/libgnunetutil.la | 84 | $(top_builddir)/src/util/libgnunetutil.la |
85 | 85 | ||
86 | if HAVE_PYTHON | 86 | if HAVE_PYTHON |
87 | check_SCRIPTS = \ | 87 | check_SCRIPTS = \ |
@@ -101,5 +101,3 @@ test_gnunet_statistics.py: test_gnunet_statistics.py.in Makefile | |||
101 | EXTRA_DIST = \ | 101 | EXTRA_DIST = \ |
102 | test_statistics_api_data.conf \ | 102 | test_statistics_api_data.conf \ |
103 | test_gnunet_statistics.py.in | 103 | test_gnunet_statistics.py.in |
104 | |||
105 | |||
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c index f21da6059..192a450ac 100644 --- a/src/statistics/gnunet-statistics.c +++ b/src/statistics/gnunet-statistics.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include "gnunet_statistics_service.h" | 29 | #include "gnunet_statistics_service.h" |
30 | #include "statistics.h" | 30 | #include "statistics.h" |
31 | 31 | ||
32 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | ||
33 | 32 | ||
34 | /** | 33 | /** |
35 | * Final status code. | 34 | * Final status code. |
@@ -69,7 +68,7 @@ static char *remote_host; | |||
69 | /** | 68 | /** |
70 | * Remote host's port | 69 | * Remote host's port |
71 | */ | 70 | */ |
72 | static unsigned long long remote_port; | 71 | static unsigned long long remote_port; |
73 | 72 | ||
74 | /** | 73 | /** |
75 | * Value to set | 74 | * Value to set |
@@ -81,6 +80,11 @@ static unsigned long long set_val; | |||
81 | */ | 80 | */ |
82 | static int set_value; | 81 | static int set_value; |
83 | 82 | ||
83 | /** | ||
84 | * Handle for pending GET operation. | ||
85 | */ | ||
86 | static struct GNUNET_STATISTICS_GetHandle *gh; | ||
87 | |||
84 | 88 | ||
85 | /** | 89 | /** |
86 | * Callback function to process statistic values. | 90 | * Callback function to process statistic values. |
@@ -134,10 +138,11 @@ printer (void *cls, | |||
134 | * successfully obtained, #GNUNET_SYSERR if not. | 138 | * successfully obtained, #GNUNET_SYSERR if not. |
135 | */ | 139 | */ |
136 | static void | 140 | static void |
137 | cleanup (void *cls, int success) | 141 | cleanup (void *cls, |
142 | int success) | ||
138 | { | 143 | { |
139 | 144 | gh = NULL; | |
140 | if (success != GNUNET_OK) | 145 | if (GNUNET_OK != success) |
141 | { | 146 | { |
142 | if (NULL == remote_host) | 147 | if (NULL == remote_host) |
143 | FPRINTF (stderr, | 148 | FPRINTF (stderr, |
@@ -166,12 +171,21 @@ shutdown_task (void *cls) | |||
166 | 171 | ||
167 | if (NULL == h) | 172 | if (NULL == h) |
168 | return; | 173 | return; |
174 | if (NULL != gh) | ||
175 | { | ||
176 | GNUNET_STATISTICS_get_cancel (gh); | ||
177 | gh = NULL; | ||
178 | } | ||
169 | if ( (GNUNET_YES == watch) && | 179 | if ( (GNUNET_YES == watch) && |
170 | (NULL != subsystem) && | 180 | (NULL != subsystem) && |
171 | (NULL != name) ) | 181 | (NULL != name) ) |
172 | GNUNET_assert (GNUNET_OK == | 182 | GNUNET_assert (GNUNET_OK == |
173 | GNUNET_STATISTICS_watch_cancel (h, subsystem, name, &printer, h)); | 183 | GNUNET_STATISTICS_watch_cancel (h, |
174 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); | 184 | subsystem, |
185 | name, | ||
186 | &printer, h)); | ||
187 | GNUNET_STATISTICS_destroy (h, | ||
188 | GNUNET_NO); | ||
175 | h = NULL; | 189 | h = NULL; |
176 | } | 190 | } |
177 | 191 | ||
@@ -207,12 +221,17 @@ main_task (void *cls) | |||
207 | ret = 1; | 221 | ret = 1; |
208 | return; | 222 | return; |
209 | } | 223 | } |
210 | GNUNET_STATISTICS_set (h, name, (uint64_t) set_val, persistent); | 224 | GNUNET_STATISTICS_set (h, |
211 | GNUNET_STATISTICS_destroy (h, GNUNET_YES); | 225 | name, |
226 | (uint64_t) set_val, | ||
227 | persistent); | ||
228 | GNUNET_STATISTICS_destroy (h, | ||
229 | GNUNET_YES); | ||
212 | h = NULL; | 230 | h = NULL; |
213 | return; | 231 | return; |
214 | } | 232 | } |
215 | if (NULL == (h = GNUNET_STATISTICS_create ("gnunet-statistics", cfg))) | 233 | if (NULL == (h = GNUNET_STATISTICS_create ("gnunet-statistics", |
234 | cfg))) | ||
216 | { | 235 | { |
217 | ret = 1; | 236 | ret = 1; |
218 | return; | 237 | return; |
@@ -220,10 +239,12 @@ main_task (void *cls) | |||
220 | if (GNUNET_NO == watch) | 239 | if (GNUNET_NO == watch) |
221 | { | 240 | { |
222 | if (NULL == | 241 | if (NULL == |
223 | GNUNET_STATISTICS_get (h, subsystem, name, GET_TIMEOUT, | 242 | (gh = GNUNET_STATISTICS_get (h, |
224 | &cleanup, | 243 | subsystem, |
225 | &printer, h)) | 244 | name, |
226 | cleanup (h, GNUNET_SYSERR); | 245 | &cleanup, |
246 | &printer, h)) ) | ||
247 | cleanup (h, GNUNET_SYSERR); | ||
227 | } | 248 | } |
228 | else | 249 | else |
229 | { | 250 | { |
@@ -235,15 +256,21 @@ main_task (void *cls) | |||
235 | ret = 1; | 256 | ret = 1; |
236 | return; | 257 | return; |
237 | } | 258 | } |
238 | if (GNUNET_OK != GNUNET_STATISTICS_watch (h, subsystem, name, | 259 | if (GNUNET_OK != |
239 | &printer, h)) | 260 | GNUNET_STATISTICS_watch (h, |
261 | subsystem, | ||
262 | name, | ||
263 | &printer, h)) | ||
240 | { | 264 | { |
241 | fprintf (stderr, _("Failed to initialize watch routine\n")); | 265 | fprintf (stderr, |
242 | GNUNET_SCHEDULER_add_now (&shutdown_task, h); | 266 | _("Failed to initialize watch routine\n")); |
267 | GNUNET_SCHEDULER_add_now (&shutdown_task, | ||
268 | h); | ||
243 | return; | 269 | return; |
244 | } | 270 | } |
245 | } | 271 | } |
246 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, h); | 272 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
273 | h); | ||
247 | } | 274 | } |
248 | 275 | ||
249 | 276 | ||
@@ -291,11 +318,17 @@ resolver_test_task (void *cls, | |||
291 | 318 | ||
292 | /* Manipulate configuration */ | 319 | /* Manipulate configuration */ |
293 | GNUNET_CONFIGURATION_set_value_string (cfg, | 320 | GNUNET_CONFIGURATION_set_value_string (cfg, |
294 | "statistics", "UNIXPATH", ""); | 321 | "statistics", |
322 | "UNIXPATH", | ||
323 | ""); | ||
295 | GNUNET_CONFIGURATION_set_value_string (cfg, | 324 | GNUNET_CONFIGURATION_set_value_string (cfg, |
296 | "statistics", "HOSTNAME", remote_host); | 325 | "statistics", |
326 | "HOSTNAME", | ||
327 | remote_host); | ||
297 | GNUNET_CONFIGURATION_set_value_number (cfg, | 328 | GNUNET_CONFIGURATION_set_value_number (cfg, |
298 | "statistics", "PORT", remote_port); | 329 | "statistics", |
330 | "PORT", | ||
331 | remote_port); | ||
299 | GNUNET_SCHEDULER_add_now (&main_task, cfg); | 332 | GNUNET_SCHEDULER_add_now (&main_task, cfg); |
300 | } | 333 | } |
301 | 334 | ||
@@ -309,7 +342,9 @@ resolver_test_task (void *cls, | |||
309 | * @param cfg configuration | 342 | * @param cfg configuration |
310 | */ | 343 | */ |
311 | static void | 344 | static void |
312 | run (void *cls, char *const *args, const char *cfgfile, | 345 | run (void *cls, |
346 | char *const *args, | ||
347 | const char *cfgfile, | ||
313 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 348 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
314 | { | 349 | { |
315 | set_value = GNUNET_NO; | 350 | set_value = GNUNET_NO; |
@@ -324,7 +359,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
324 | set_value = GNUNET_YES; | 359 | set_value = GNUNET_YES; |
325 | } | 360 | } |
326 | if (NULL != remote_host) | 361 | if (NULL != remote_host) |
327 | GNUNET_CLIENT_service_test ("resolver", cfg, GNUNET_TIME_UNIT_SECONDS, | 362 | GNUNET_CLIENT_service_test ("resolver", |
363 | cfg, | ||
364 | GNUNET_TIME_UNIT_SECONDS, | ||
328 | &resolver_test_task, (void *) cfg); | 365 | &resolver_test_task, (void *) cfg); |
329 | else | 366 | else |
330 | GNUNET_SCHEDULER_add_now (&main_task, (void *) cfg); | 367 | GNUNET_SCHEDULER_add_now (&main_task, (void *) cfg); |
@@ -367,7 +404,8 @@ main (int argc, char *const *argv) | |||
367 | }; | 404 | }; |
368 | remote_port = 0; | 405 | remote_port = 0; |
369 | remote_host = NULL; | 406 | remote_host = NULL; |
370 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 407 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, |
408 | &argc, &argv)) | ||
371 | return 2; | 409 | return 2; |
372 | 410 | ||
373 | ret = (GNUNET_OK == | 411 | ret = (GNUNET_OK == |
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index 32b973eec..37aa99017 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010, 2011 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -88,7 +88,7 @@ struct GNUNET_STATISTICS_WatchEntry | |||
88 | GNUNET_STATISTICS_Iterator proc; | 88 | GNUNET_STATISTICS_Iterator proc; |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * Closure for proc | 91 | * Closure for @e proc |
92 | */ | 92 | */ |
93 | void *proc_cls; | 93 | void *proc_cls; |
94 | 94 | ||
@@ -137,7 +137,7 @@ struct GNUNET_STATISTICS_GetHandle | |||
137 | GNUNET_STATISTICS_Iterator proc; | 137 | GNUNET_STATISTICS_Iterator proc; |
138 | 138 | ||
139 | /** | 139 | /** |
140 | * Closure for proc and cont. | 140 | * Closure for @e proc and @e cont. |
141 | */ | 141 | */ |
142 | void *cls; | 142 | void *cls; |
143 | 143 | ||
@@ -147,11 +147,6 @@ struct GNUNET_STATISTICS_GetHandle | |||
147 | struct GNUNET_TIME_Absolute timeout; | 147 | struct GNUNET_TIME_Absolute timeout; |
148 | 148 | ||
149 | /** | 149 | /** |
150 | * Task run on timeout. | ||
151 | */ | ||
152 | struct GNUNET_SCHEDULER_Task * timeout_task; | ||
153 | |||
154 | /** | ||
155 | * Associated value. | 150 | * Associated value. |
156 | */ | 151 | */ |
157 | uint64_t value; | 152 | uint64_t value; |
@@ -167,7 +162,7 @@ struct GNUNET_STATISTICS_GetHandle | |||
167 | int aborted; | 162 | int aborted; |
168 | 163 | ||
169 | /** | 164 | /** |
170 | * Is this a GET, SET, UPDATE or WATCH? | 165 | * Is this a #ACTION_GET, #ACTION_SET, #ACTION_UPDATE or #ACTION_WATCH? |
171 | */ | 166 | */ |
172 | enum ActionType type; | 167 | enum ActionType type; |
173 | 168 | ||
@@ -195,14 +190,9 @@ struct GNUNET_STATISTICS_Handle | |||
195 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 190 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
196 | 191 | ||
197 | /** | 192 | /** |
198 | * Socket (if available). | 193 | * Message queue to the service. |
199 | */ | 194 | */ |
200 | struct GNUNET_CLIENT_Connection *client; | 195 | struct GNUNET_MQ_Handle *mq; |
201 | |||
202 | /** | ||
203 | * Currently pending transmission request. | ||
204 | */ | ||
205 | struct GNUNET_CLIENT_TransmitHandle *th; | ||
206 | 196 | ||
207 | /** | 197 | /** |
208 | * Head of the linked list of pending actions (first action | 198 | * Head of the linked list of pending actions (first action |
@@ -230,7 +220,7 @@ struct GNUNET_STATISTICS_Handle | |||
230 | /** | 220 | /** |
231 | * Task doing exponential back-off trying to reconnect. | 221 | * Task doing exponential back-off trying to reconnect. |
232 | */ | 222 | */ |
233 | struct GNUNET_SCHEDULER_Task * backoff_task; | 223 | struct GNUNET_SCHEDULER_Task *backoff_task; |
234 | 224 | ||
235 | /** | 225 | /** |
236 | * Time for next connect retry. | 226 | * Time for next connect retry. |
@@ -248,7 +238,7 @@ struct GNUNET_STATISTICS_Handle | |||
248 | uint64_t peak_rss; | 238 | uint64_t peak_rss; |
249 | 239 | ||
250 | /** | 240 | /** |
251 | * Size of the 'watches' array. | 241 | * Size of the @e watches array. |
252 | */ | 242 | */ |
253 | unsigned int watches_size; | 243 | unsigned int watches_size; |
254 | 244 | ||
@@ -321,6 +311,15 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h); | |||
321 | 311 | ||
322 | 312 | ||
323 | /** | 313 | /** |
314 | * Reconnect at a later time, respecting back-off. | ||
315 | * | ||
316 | * @param h statistics handle | ||
317 | */ | ||
318 | static void | ||
319 | reconnect_later (struct GNUNET_STATISTICS_Handle *h); | ||
320 | |||
321 | |||
322 | /** | ||
324 | * Transmit request to service that we want to watch | 323 | * Transmit request to service that we want to watch |
325 | * the development of a particular value. | 324 | * the development of a particular value. |
326 | * | 325 | * |
@@ -353,7 +352,8 @@ schedule_watch_request (struct GNUNET_STATISTICS_Handle *h, | |||
353 | ai->type = ACTION_WATCH; | 352 | ai->type = ACTION_WATCH; |
354 | ai->proc = watch->proc; | 353 | ai->proc = watch->proc; |
355 | ai->cls = watch->proc_cls; | 354 | ai->cls = watch->proc_cls; |
356 | GNUNET_CONTAINER_DLL_insert_tail (h->action_head, h->action_tail, | 355 | GNUNET_CONTAINER_DLL_insert_tail (h->action_head, |
356 | h->action_tail, | ||
357 | ai); | 357 | ai); |
358 | schedule_action (h); | 358 | schedule_action (h); |
359 | } | 359 | } |
@@ -367,11 +367,6 @@ schedule_watch_request (struct GNUNET_STATISTICS_Handle *h, | |||
367 | static void | 367 | static void |
368 | free_action_item (struct GNUNET_STATISTICS_GetHandle *gh) | 368 | free_action_item (struct GNUNET_STATISTICS_GetHandle *gh) |
369 | { | 369 | { |
370 | if (NULL != gh->timeout_task) | ||
371 | { | ||
372 | GNUNET_SCHEDULER_cancel (gh->timeout_task); | ||
373 | gh->timeout_task = NULL; | ||
374 | } | ||
375 | GNUNET_free_non_null (gh->subsystem); | 370 | GNUNET_free_non_null (gh->subsystem); |
376 | GNUNET_free_non_null (gh->name); | 371 | GNUNET_free_non_null (gh->name); |
377 | GNUNET_free (gh); | 372 | GNUNET_free (gh); |
@@ -388,11 +383,6 @@ do_disconnect (struct GNUNET_STATISTICS_Handle *h) | |||
388 | { | 383 | { |
389 | struct GNUNET_STATISTICS_GetHandle *c; | 384 | struct GNUNET_STATISTICS_GetHandle *c; |
390 | 385 | ||
391 | if (NULL != h->th) | ||
392 | { | ||
393 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); | ||
394 | h->th = NULL; | ||
395 | } | ||
396 | h->receiving = GNUNET_NO; | 386 | h->receiving = GNUNET_NO; |
397 | if (NULL != (c = h->current)) | 387 | if (NULL != (c = h->current)) |
398 | { | 388 | { |
@@ -400,393 +390,400 @@ do_disconnect (struct GNUNET_STATISTICS_Handle *h) | |||
400 | if ( (NULL != c->cont) && | 390 | if ( (NULL != c->cont) && |
401 | (GNUNET_YES != c->aborted) ) | 391 | (GNUNET_YES != c->aborted) ) |
402 | { | 392 | { |
403 | c->cont (c->cls, GNUNET_SYSERR); | 393 | c->cont (c->cls, |
394 | GNUNET_SYSERR); | ||
404 | c->cont = NULL; | 395 | c->cont = NULL; |
405 | } | 396 | } |
406 | free_action_item (c); | 397 | free_action_item (c); |
407 | } | 398 | } |
408 | if (NULL != h->client) | 399 | if (NULL != h->mq) |
409 | { | 400 | { |
410 | GNUNET_CLIENT_disconnect (h->client); | 401 | GNUNET_MQ_destroy (h->mq); |
411 | h->client = NULL; | 402 | h->mq = NULL; |
412 | } | 403 | } |
413 | } | 404 | } |
414 | 405 | ||
415 | 406 | ||
416 | /** | 407 | /** |
417 | * Try to (re)connect to the statistics service. | 408 | * Process a #GNUNET_MESSAGE_TYPE_STATISTICS_VALUE message. |
418 | * | 409 | * |
419 | * @param h statistics handle to reconnect | 410 | * @param cls statistics handle |
420 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. | 411 | * @param smsg message received from the service, never NULL |
412 | * @return #GNUNET_OK if the message was well-formed | ||
421 | */ | 413 | */ |
422 | static int | 414 | static int |
423 | try_connect (struct GNUNET_STATISTICS_Handle *h) | 415 | check_statistics_value (void *cls, |
416 | const struct GNUNET_STATISTICS_ReplyMessage *smsg) | ||
424 | { | 417 | { |
425 | struct GNUNET_STATISTICS_GetHandle *gh; | 418 | const char *service; |
426 | struct GNUNET_STATISTICS_GetHandle *gn; | 419 | const char *name; |
427 | unsigned int i; | 420 | uint16_t size; |
428 | 421 | ||
429 | if (NULL != h->backoff_task) | 422 | size = ntohs (smsg->header.size); |
430 | return GNUNET_NO; | 423 | size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage); |
431 | if (NULL != h->client) | 424 | if (size != |
432 | return GNUNET_YES; | 425 | GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], |
433 | h->client = GNUNET_CLIENT_connect ("statistics", h->cfg); | 426 | size, |
434 | if (NULL != h->client) | 427 | 2, |
428 | &service, | ||
429 | &name)) | ||
435 | { | 430 | { |
436 | gn = h->action_head; | 431 | GNUNET_break (0); |
437 | while (NULL != (gh = gn)) | 432 | return GNUNET_SYSERR; |
438 | { | ||
439 | gn = gh->next; | ||
440 | if (gh->type == ACTION_WATCH) | ||
441 | { | ||
442 | GNUNET_CONTAINER_DLL_remove (h->action_head, | ||
443 | h->action_tail, | ||
444 | gh); | ||
445 | free_action_item (gh); | ||
446 | } | ||
447 | } | ||
448 | for (i = 0; i < h->watches_size; i++) | ||
449 | { | ||
450 | if (NULL != h->watches[i]) | ||
451 | schedule_watch_request (h, h->watches[i]); | ||
452 | } | ||
453 | return GNUNET_YES; | ||
454 | } | 433 | } |
455 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 434 | return GNUNET_OK; |
456 | "Failed to connect to statistics service!\n"); | ||
457 | return GNUNET_NO; | ||
458 | } | 435 | } |
459 | 436 | ||
460 | 437 | ||
461 | /** | 438 | /** |
462 | * We've waited long enough, reconnect now. | 439 | * Process a #GNUNET_MESSAGE_TYPE_STATISTICS_VALUE message. |
463 | * | 440 | * |
464 | * @param cls the `struct GNUNET_STATISTICS_Handle` to reconnect | 441 | * @param cls statistics handle |
442 | * @param msg message received from the service, never NULL | ||
443 | * @return #GNUNET_OK if the message was well-formed | ||
465 | */ | 444 | */ |
466 | static void | 445 | static void |
467 | reconnect_task (void *cls) | 446 | handle_statistics_value (void *cls, |
447 | const struct GNUNET_STATISTICS_ReplyMessage *smsg) | ||
468 | { | 448 | { |
469 | struct GNUNET_STATISTICS_Handle *h = cls; | 449 | struct GNUNET_STATISTICS_Handle *h = cls; |
450 | const char *service; | ||
451 | const char *name; | ||
452 | uint16_t size; | ||
470 | 453 | ||
471 | h->backoff_task = NULL; | 454 | if (h->current->aborted) |
472 | schedule_action (h); | 455 | return; /* iteration aborted, don't bother */ |
456 | |||
457 | size = ntohs (smsg->header.size); | ||
458 | size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage); | ||
459 | GNUNET_assert (size == | ||
460 | GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], | ||
461 | size, | ||
462 | 2, | ||
463 | &service, | ||
464 | &name)); | ||
465 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
466 | "Received valid statistic on `%s:%s': %llu\n", | ||
467 | service, name, | ||
468 | GNUNET_ntohll (smsg->value)); | ||
469 | if (GNUNET_OK != | ||
470 | h->current->proc (h->current->cls, | ||
471 | service, | ||
472 | name, | ||
473 | GNUNET_ntohll (smsg->value), | ||
474 | 0 != | ||
475 | (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) | ||
476 | { | ||
477 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
478 | "Processing of remaining statistics aborted by client.\n"); | ||
479 | h->current->aborted = GNUNET_YES; | ||
480 | } | ||
473 | } | 481 | } |
474 | 482 | ||
475 | 483 | ||
476 | /** | 484 | /** |
477 | * Task used by 'reconnect_later' to shutdown the handle | 485 | * We have received a watch value from the service. Process it. |
478 | * | 486 | * |
479 | * @param cls the statistics handle | 487 | * @param cls statistics handle |
488 | * @param msg the watch value message | ||
480 | */ | 489 | */ |
481 | static void | 490 | static void |
482 | do_destroy (void *cls) | 491 | handle_statistics_watch_value (void *cls, |
492 | const struct GNUNET_STATISTICS_WatchValueMessage *wvm) | ||
483 | { | 493 | { |
484 | struct GNUNET_STATISTICS_Handle *h = cls; | 494 | struct GNUNET_STATISTICS_Handle *h = cls; |
495 | struct GNUNET_STATISTICS_WatchEntry *w; | ||
496 | uint32_t wid; | ||
485 | 497 | ||
486 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); | 498 | GNUNET_break (0 == ntohl (wvm->reserved)); |
499 | wid = ntohl (wvm->wid); | ||
500 | if (wid >= h->watches_size) | ||
501 | { | ||
502 | do_disconnect (h); | ||
503 | reconnect_later (h); | ||
504 | return; | ||
505 | } | ||
506 | w = h->watches[wid]; | ||
507 | if (NULL == w) | ||
508 | return; | ||
509 | (void) w->proc (w->proc_cls, | ||
510 | w->subsystem, | ||
511 | w->name, | ||
512 | GNUNET_ntohll (wvm->value), | ||
513 | 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); | ||
487 | } | 514 | } |
488 | 515 | ||
489 | 516 | ||
490 | /** | 517 | /** |
491 | * Reconnect at a later time, respecting back-off. | 518 | * Generic error handler, called with the appropriate error code and |
519 | * the same closure specified at the creation of the message queue. | ||
520 | * Not every message queue implementation supports an error handler. | ||
492 | * | 521 | * |
493 | * @param h statistics handle | 522 | * @param cls closure with the `struct GNUNET_STATISTICS_Handle *` |
523 | * @param error error code | ||
494 | */ | 524 | */ |
495 | static void | 525 | static void |
496 | reconnect_later (struct GNUNET_STATISTICS_Handle *h) | 526 | mq_error_handler (void *cls, |
527 | enum GNUNET_MQ_Error error) | ||
497 | { | 528 | { |
498 | int loss; | 529 | struct GNUNET_STATISTICS_Handle *h = cls; |
499 | struct GNUNET_STATISTICS_GetHandle *gh; | ||
500 | 530 | ||
501 | GNUNET_assert (NULL == h->backoff_task); | 531 | if (GNUNET_NO != h->do_destroy) |
502 | if (GNUNET_YES == h->do_destroy) | ||
503 | { | 532 | { |
504 | /* So we are shutting down and the service is not reachable. | ||
505 | * Chances are that it's down for good and we are not going to connect to | ||
506 | * it anymore. | ||
507 | * Give up and don't sync the rest of the data. | ||
508 | */ | ||
509 | loss = GNUNET_NO; | ||
510 | for (gh = h->action_head; NULL != gh; gh = gh->next) | ||
511 | if ( (gh->make_persistent) && (ACTION_SET == gh->type) ) | ||
512 | loss = GNUNET_YES; | ||
513 | if (GNUNET_YES == loss) | ||
514 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
515 | _("Could not save some persistent statistics\n")); | ||
516 | h->do_destroy = GNUNET_NO; | 533 | h->do_destroy = GNUNET_NO; |
517 | GNUNET_SCHEDULER_add_now (&do_destroy, h); | 534 | GNUNET_STATISTICS_destroy (h, |
535 | GNUNET_NO); | ||
518 | return; | 536 | return; |
519 | } | 537 | } |
520 | h->backoff_task = | 538 | do_disconnect (h); |
521 | GNUNET_SCHEDULER_add_delayed (h->backoff, &reconnect_task, h); | 539 | reconnect_later (h); |
522 | h->backoff = GNUNET_TIME_STD_BACKOFF (h->backoff); | ||
523 | } | 540 | } |
524 | 541 | ||
525 | 542 | ||
526 | /** | 543 | /** |
527 | * Process a #GNUNET_MESSAGE_TYPE_STATISTICS_VALUE message. | 544 | * Task used to destroy the statistics handle. |
528 | * | 545 | * |
529 | * @param h statistics handle | 546 | * @param cls the `struct GNUNET_STATISTICS_Handle` |
530 | * @param msg message received from the service, never NULL | ||
531 | * @return #GNUNET_OK if the message was well-formed | ||
532 | */ | 547 | */ |
533 | static int | 548 | static void |
534 | process_statistics_value_message (struct GNUNET_STATISTICS_Handle *h, | 549 | destroy_task (void *cls) |
535 | const struct GNUNET_MessageHeader *msg) | ||
536 | { | 550 | { |
537 | char *service; | 551 | struct GNUNET_STATISTICS_Handle *h = cls; |
538 | char *name; | ||
539 | const struct GNUNET_STATISTICS_ReplyMessage *smsg; | ||
540 | uint16_t size; | ||
541 | 552 | ||
542 | if (h->current->aborted) | 553 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); |
543 | { | 554 | } |
544 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 555 | |
545 | "Iteration was aborted, ignoring VALUE\n"); | 556 | |
546 | return GNUNET_OK; /* don't bother */ | 557 | /** |
547 | } | 558 | * Handle a #GNUNET_MESSAGE_TYPE_TEST (sic) message. We receive this |
548 | size = ntohs (msg->size); | 559 | * message at the end of the shutdown when the service confirms that |
549 | if (size < sizeof (struct GNUNET_STATISTICS_ReplyMessage)) | 560 | * all data has been written to disk. |
561 | * | ||
562 | * @param cls our `struct GNUNET_STATISTICS_Handle *` | ||
563 | * @param msg the message | ||
564 | */ | ||
565 | static void | ||
566 | handle_test (void *cls, | ||
567 | const struct GNUNET_MessageHeader *msg) | ||
568 | { | ||
569 | struct GNUNET_STATISTICS_Handle *h = cls; | ||
570 | |||
571 | if (GNUNET_SYSERR != h->do_destroy) | ||
550 | { | 572 | { |
573 | /* not in shutdown, why do we get 'TEST'? */ | ||
551 | GNUNET_break (0); | 574 | GNUNET_break (0); |
552 | return GNUNET_SYSERR; | 575 | do_disconnect (h); |
576 | reconnect_later (h); | ||
577 | return; | ||
553 | } | 578 | } |
554 | smsg = (const struct GNUNET_STATISTICS_ReplyMessage *) msg; | 579 | h->do_destroy = GNUNET_NO; |
555 | size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage); | 580 | GNUNET_SCHEDULER_add_now (&destroy_task, |
556 | if (size != | 581 | h); |
557 | GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], size, 2, | 582 | } |
558 | &service, &name)) | 583 | |
584 | |||
585 | /** | ||
586 | * Handle a #GNUNET_MESSAGE_TYPE_STATISTICS_END message. We receive | ||
587 | * this message in response to a query to indicate that there are no | ||
588 | * further matching results. | ||
589 | * | ||
590 | * @param cls our `struct GNUNET_STATISTICS_Handle *` | ||
591 | * @param msg the message | ||
592 | */ | ||
593 | static void | ||
594 | handle_statistics_end (void *cls, | ||
595 | const struct GNUNET_MessageHeader *msg) | ||
596 | { | ||
597 | struct GNUNET_STATISTICS_Handle *h = cls; | ||
598 | struct GNUNET_STATISTICS_GetHandle *c; | ||
599 | |||
600 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
601 | "Received end of statistics marker\n"); | ||
602 | if (NULL == (c = h->current)) | ||
559 | { | 603 | { |
560 | GNUNET_break (0); | 604 | GNUNET_break (0); |
561 | return GNUNET_SYSERR; | 605 | do_disconnect (h); |
606 | reconnect_later (h); | ||
607 | return; | ||
562 | } | 608 | } |
563 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 609 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
564 | "Received valid statistic on `%s:%s': %llu\n", | 610 | h->current = NULL; |
565 | service, name, | 611 | schedule_action (h); |
566 | GNUNET_ntohll (smsg->value)); | 612 | if (NULL != c->cont) |
567 | if (GNUNET_OK != | ||
568 | h->current->proc (h->current->cls, service, name, | ||
569 | GNUNET_ntohll (smsg->value), | ||
570 | 0 != | ||
571 | (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) | ||
572 | { | 613 | { |
573 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 614 | c->cont (c->cls, |
574 | "Processing of remaining statistics aborted by client.\n"); | 615 | GNUNET_OK); |
575 | h->current->aborted = GNUNET_YES; | 616 | c->cont = NULL; |
576 | } | 617 | } |
577 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 618 | free_action_item (c); |
578 | "VALUE processed successfully\n"); | ||
579 | return GNUNET_OK; | ||
580 | } | 619 | } |
581 | 620 | ||
582 | 621 | ||
583 | /** | 622 | /** |
584 | * We have received a watch value from the service. Process it. | 623 | * Try to (re)connect to the statistics service. |
585 | * | 624 | * |
586 | * @param h statistics handle | 625 | * @param h statistics handle to reconnect |
587 | * @param msg the watch value message | 626 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. |
588 | * @return #GNUNET_OK if the message was well-formed, #GNUNET_SYSERR if not, | ||
589 | * #GNUNET_NO if this watch has been cancelled | ||
590 | */ | 627 | */ |
591 | static int | 628 | static int |
592 | process_watch_value (struct GNUNET_STATISTICS_Handle *h, | 629 | try_connect (struct GNUNET_STATISTICS_Handle *h) |
593 | const struct GNUNET_MessageHeader *msg) | ||
594 | { | 630 | { |
595 | const struct GNUNET_STATISTICS_WatchValueMessage *wvm; | 631 | GNUNET_MQ_hd_fixed_size (test, |
596 | struct GNUNET_STATISTICS_WatchEntry *w; | 632 | GNUNET_MESSAGE_TYPE_TEST, |
597 | uint32_t wid; | 633 | struct GNUNET_MessageHeader); |
634 | GNUNET_MQ_hd_fixed_size (statistics_end, | ||
635 | GNUNET_MESSAGE_TYPE_STATISTICS_END, | ||
636 | struct GNUNET_MessageHeader); | ||
637 | GNUNET_MQ_hd_var_size (statistics_value, | ||
638 | GNUNET_MESSAGE_TYPE_STATISTICS_VALUE, | ||
639 | struct GNUNET_STATISTICS_ReplyMessage); | ||
640 | GNUNET_MQ_hd_fixed_size (statistics_watch_value, | ||
641 | GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE, | ||
642 | struct GNUNET_STATISTICS_WatchValueMessage); | ||
643 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
644 | make_test_handler (h), | ||
645 | make_statistics_end_handler (h), | ||
646 | make_statistics_value_handler (h), | ||
647 | make_statistics_watch_value_handler (h), | ||
648 | GNUNET_MQ_handler_end () | ||
649 | }; | ||
650 | struct GNUNET_STATISTICS_GetHandle *gh; | ||
651 | struct GNUNET_STATISTICS_GetHandle *gn; | ||
598 | 652 | ||
599 | if (sizeof (struct GNUNET_STATISTICS_WatchValueMessage) != ntohs (msg->size)) | 653 | if (NULL != h->backoff_task) |
654 | return GNUNET_NO; | ||
655 | if (NULL != h->mq) | ||
656 | return GNUNET_YES; | ||
657 | h->mq = GNUNET_CLIENT_connecT (h->cfg, | ||
658 | "statistics", | ||
659 | handlers, | ||
660 | &mq_error_handler, | ||
661 | h); | ||
662 | if (NULL == h->mq) | ||
600 | { | 663 | { |
601 | GNUNET_break (0); | 664 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
602 | return GNUNET_SYSERR; | 665 | "Failed to connect to statistics service!\n"); |
666 | return GNUNET_NO; | ||
603 | } | 667 | } |
604 | wvm = (const struct GNUNET_STATISTICS_WatchValueMessage *) msg; | 668 | gn = h->action_head; |
605 | GNUNET_break (0 == ntohl (wvm->reserved)); | 669 | while (NULL != (gh = gn)) |
606 | wid = ntohl (wvm->wid); | ||
607 | if (wid >= h->watches_size) | ||
608 | { | 670 | { |
609 | GNUNET_break (0); | 671 | gn = gh->next; |
610 | return GNUNET_SYSERR; | 672 | if (gh->type == ACTION_WATCH) |
673 | { | ||
674 | GNUNET_CONTAINER_DLL_remove (h->action_head, | ||
675 | h->action_tail, | ||
676 | gh); | ||
677 | free_action_item (gh); | ||
678 | } | ||
611 | } | 679 | } |
612 | w = h->watches[wid]; | 680 | for (unsigned int i = 0; i < h->watches_size; i++) |
613 | if (NULL == w) | 681 | if (NULL != h->watches[i]) |
614 | return GNUNET_NO; | 682 | schedule_watch_request (h, |
615 | (void) w->proc (w->proc_cls, w->subsystem, w->name, | 683 | h->watches[i]); |
616 | GNUNET_ntohll (wvm->value), | 684 | return GNUNET_YES; |
617 | 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); | ||
618 | return GNUNET_OK; | ||
619 | } | 685 | } |
620 | 686 | ||
621 | 687 | ||
622 | /** | 688 | /** |
623 | * Task used to destroy the statistics handle. | 689 | * We've waited long enough, reconnect now. |
624 | * | 690 | * |
625 | * @param cls the `struct GNUNET_STATISTICS_Handle` | 691 | * @param cls the `struct GNUNET_STATISTICS_Handle` to reconnect |
626 | */ | 692 | */ |
627 | static void | 693 | static void |
628 | destroy_task (void *cls) | 694 | reconnect_task (void *cls) |
629 | { | 695 | { |
630 | struct GNUNET_STATISTICS_Handle *h = cls; | 696 | struct GNUNET_STATISTICS_Handle *h = cls; |
631 | 697 | ||
632 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); | 698 | h->backoff_task = NULL; |
699 | schedule_action (h); | ||
633 | } | 700 | } |
634 | 701 | ||
635 | 702 | ||
636 | /** | 703 | /** |
637 | * Function called with messages from stats service. | 704 | * Task used by #reconnect_later() to shutdown the handle |
638 | * | 705 | * |
639 | * @param cls closure | 706 | * @param cls the statistics handle |
640 | * @param msg message received, NULL on timeout or fatal error | ||
641 | */ | 707 | */ |
642 | static void | 708 | static void |
643 | receive_stats (void *cls, | 709 | do_destroy (void *cls) |
644 | const struct GNUNET_MessageHeader *msg) | ||
645 | { | 710 | { |
646 | struct GNUNET_STATISTICS_Handle *h = cls; | 711 | struct GNUNET_STATISTICS_Handle *h = cls; |
647 | struct GNUNET_STATISTICS_GetHandle *c; | ||
648 | int ret; | ||
649 | 712 | ||
650 | if (NULL == msg) | 713 | GNUNET_STATISTICS_destroy (h, |
651 | { | 714 | GNUNET_NO); |
652 | LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 715 | } |
653 | "Error receiving statistics from service, is the service running?\n"); | 716 | |
654 | do_disconnect (h); | 717 | |
655 | reconnect_later (h); | 718 | /** |
656 | return; | 719 | * Reconnect at a later time, respecting back-off. |
657 | } | 720 | * |
658 | switch (ntohs (msg->type)) | 721 | * @param h statistics handle |
722 | */ | ||
723 | static void | ||
724 | reconnect_later (struct GNUNET_STATISTICS_Handle *h) | ||
725 | { | ||
726 | int loss; | ||
727 | struct GNUNET_STATISTICS_GetHandle *gh; | ||
728 | |||
729 | GNUNET_assert (NULL == h->backoff_task); | ||
730 | if (GNUNET_YES == h->do_destroy) | ||
659 | { | 731 | { |
660 | case GNUNET_MESSAGE_TYPE_TEST: | 732 | /* So we are shutting down and the service is not reachable. |
661 | if (GNUNET_SYSERR != h->do_destroy) | 733 | * Chances are that it's down for good and we are not going to connect to |
662 | { | 734 | * it anymore. |
663 | /* not in shutdown, why do we get 'TEST'? */ | 735 | * Give up and don't sync the rest of the data. |
664 | GNUNET_break (0); | 736 | */ |
665 | do_disconnect (h); | 737 | loss = GNUNET_NO; |
666 | reconnect_later (h); | 738 | for (gh = h->action_head; NULL != gh; gh = gh->next) |
667 | return; | 739 | if ( (gh->make_persistent) && (ACTION_SET == gh->type) ) |
668 | } | 740 | loss = GNUNET_YES; |
741 | if (GNUNET_YES == loss) | ||
742 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
743 | _("Could not save some persistent statistics\n")); | ||
669 | h->do_destroy = GNUNET_NO; | 744 | h->do_destroy = GNUNET_NO; |
670 | GNUNET_SCHEDULER_add_now (&destroy_task, h); | 745 | GNUNET_SCHEDULER_add_now (&do_destroy, |
671 | break; | 746 | h); |
672 | case GNUNET_MESSAGE_TYPE_STATISTICS_END: | ||
673 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
674 | "Received end of statistics marker\n"); | ||
675 | if (NULL == (c = h->current)) | ||
676 | { | ||
677 | GNUNET_break (0); | ||
678 | do_disconnect (h); | ||
679 | reconnect_later (h); | ||
680 | return; | ||
681 | } | ||
682 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | ||
683 | if (h->watches_size > 0) | ||
684 | { | ||
685 | GNUNET_CLIENT_receive (h->client, &receive_stats, h, | ||
686 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
687 | } | ||
688 | else | ||
689 | { | ||
690 | h->receiving = GNUNET_NO; | ||
691 | } | ||
692 | h->current = NULL; | ||
693 | schedule_action (h); | ||
694 | if (NULL != c->cont) | ||
695 | { | ||
696 | c->cont (c->cls, GNUNET_OK); | ||
697 | c->cont = NULL; | ||
698 | } | ||
699 | free_action_item (c); | ||
700 | return; | ||
701 | case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE: | ||
702 | if (GNUNET_OK != process_statistics_value_message (h, msg)) | ||
703 | { | ||
704 | do_disconnect (h); | ||
705 | reconnect_later (h); | ||
706 | return; | ||
707 | } | ||
708 | /* finally, look for more! */ | ||
709 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
710 | "Processing VALUE done, now reading more\n"); | ||
711 | GNUNET_CLIENT_receive (h->client, &receive_stats, h, | ||
712 | GNUNET_TIME_absolute_get_remaining (h-> | ||
713 | current->timeout)); | ||
714 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | ||
715 | return; | ||
716 | case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE: | ||
717 | if (GNUNET_OK != | ||
718 | (ret = process_watch_value (h, msg))) | ||
719 | { | ||
720 | do_disconnect (h); | ||
721 | if (GNUNET_NO == ret) | ||
722 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | ||
723 | reconnect_later (h); | ||
724 | return; | ||
725 | } | ||
726 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | ||
727 | GNUNET_assert (h->watches_size > 0); | ||
728 | GNUNET_CLIENT_receive (h->client, &receive_stats, h, | ||
729 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
730 | return; | ||
731 | default: | ||
732 | GNUNET_break (0); | ||
733 | do_disconnect (h); | ||
734 | reconnect_later (h); | ||
735 | return; | 747 | return; |
736 | } | 748 | } |
749 | h->backoff_task | ||
750 | = GNUNET_SCHEDULER_add_delayed (h->backoff, | ||
751 | &reconnect_task, | ||
752 | h); | ||
753 | h->backoff = GNUNET_TIME_STD_BACKOFF (h->backoff); | ||
737 | } | 754 | } |
738 | 755 | ||
739 | 756 | ||
757 | |||
740 | /** | 758 | /** |
741 | * Transmit a GET request (and if successful, start to receive | 759 | * Transmit a GET request (and if successful, start to receive |
742 | * the response). | 760 | * the response). |
743 | * | 761 | * |
744 | * @param handle statistics handle | 762 | * @param handle statistics handle |
745 | * @param size how many bytes can we write to @a buf | ||
746 | * @param buf where to write requests to the service | ||
747 | * @return number of bytes written to @a buf | ||
748 | */ | 763 | */ |
749 | static size_t | 764 | static void |
750 | transmit_get (struct GNUNET_STATISTICS_Handle *handle, | 765 | transmit_get (struct GNUNET_STATISTICS_Handle *handle) |
751 | size_t size, | ||
752 | void *buf) | ||
753 | { | 766 | { |
754 | struct GNUNET_STATISTICS_GetHandle *c; | 767 | struct GNUNET_STATISTICS_GetHandle *c; |
755 | struct GNUNET_MessageHeader *hdr; | 768 | struct GNUNET_MessageHeader *hdr; |
769 | struct GNUNET_MQ_Envelope *env; | ||
756 | size_t slen1; | 770 | size_t slen1; |
757 | size_t slen2; | 771 | size_t slen2; |
758 | uint16_t msize; | ||
759 | 772 | ||
760 | GNUNET_assert (NULL != (c = handle->current)); | 773 | GNUNET_assert (NULL != (c = handle->current)); |
761 | if (NULL == buf) | ||
762 | { | ||
763 | /* timeout / error */ | ||
764 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
765 | "Transmission of request for statistics failed!\n"); | ||
766 | do_disconnect (handle); | ||
767 | reconnect_later (handle); | ||
768 | return 0; | ||
769 | } | ||
770 | slen1 = strlen (c->subsystem) + 1; | 774 | slen1 = strlen (c->subsystem) + 1; |
771 | slen2 = strlen (c->name) + 1; | 775 | slen2 = strlen (c->name) + 1; |
772 | msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader); | 776 | env = GNUNET_MQ_msg_extra (hdr, |
773 | GNUNET_assert (msize <= size); | 777 | slen1 + slen2, |
774 | hdr = (struct GNUNET_MessageHeader *) buf; | 778 | GNUNET_MESSAGE_TYPE_STATISTICS_GET); |
775 | hdr->size = htons (msize); | ||
776 | hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET); | ||
777 | GNUNET_assert (slen1 + slen2 == | 779 | GNUNET_assert (slen1 + slen2 == |
778 | GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2, | 780 | GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], |
781 | slen1 + slen2, | ||
782 | 2, | ||
779 | c->subsystem, | 783 | c->subsystem, |
780 | c->name)); | 784 | c->name)); |
781 | if (GNUNET_YES != handle->receiving) | 785 | GNUNET_MQ_send (handle->mq, |
782 | { | 786 | env); |
783 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
784 | "Transmission of GET done, now reading response\n"); | ||
785 | handle->receiving = GNUNET_YES; | ||
786 | GNUNET_CLIENT_receive (handle->client, &receive_stats, handle, | ||
787 | GNUNET_TIME_absolute_get_remaining (c->timeout)); | ||
788 | } | ||
789 | return msize; | ||
790 | } | 787 | } |
791 | 788 | ||
792 | 789 | ||
@@ -795,53 +792,34 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, | |||
795 | * the response). | 792 | * the response). |
796 | * | 793 | * |
797 | * @param handle statistics handle | 794 | * @param handle statistics handle |
798 | * @param size how many bytes can we write to @a buf | ||
799 | * @param buf where to write requests to the service | ||
800 | * @return number of bytes written to @a buf | ||
801 | */ | 795 | */ |
802 | static size_t | 796 | static void |
803 | transmit_watch (struct GNUNET_STATISTICS_Handle *handle, | 797 | transmit_watch (struct GNUNET_STATISTICS_Handle *handle) |
804 | size_t size, | ||
805 | void *buf) | ||
806 | { | 798 | { |
807 | struct GNUNET_MessageHeader *hdr; | 799 | struct GNUNET_MessageHeader *hdr; |
800 | struct GNUNET_MQ_Envelope *env; | ||
808 | size_t slen1; | 801 | size_t slen1; |
809 | size_t slen2; | 802 | size_t slen2; |
810 | uint16_t msize; | ||
811 | 803 | ||
812 | if (NULL == buf) | ||
813 | { | ||
814 | /* timeout / error */ | ||
815 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
816 | "Transmission of request for statistics failed!\n"); | ||
817 | do_disconnect (handle); | ||
818 | reconnect_later (handle); | ||
819 | return 0; | ||
820 | } | ||
821 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 804 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
822 | "Transmitting watch request for `%s'\n", | 805 | "Transmitting watch request for `%s'\n", |
823 | handle->current->name); | 806 | handle->current->name); |
824 | slen1 = strlen (handle->current->subsystem) + 1; | 807 | slen1 = strlen (handle->current->subsystem) + 1; |
825 | slen2 = strlen (handle->current->name) + 1; | 808 | slen2 = strlen (handle->current->name) + 1; |
826 | msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader); | 809 | env = GNUNET_MQ_msg_extra (hdr, |
827 | GNUNET_assert (msize <= size); | 810 | slen1 + slen2, |
828 | hdr = (struct GNUNET_MessageHeader *) buf; | 811 | GNUNET_MESSAGE_TYPE_STATISTICS_WATCH); |
829 | hdr->size = htons (msize); | ||
830 | hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH); | ||
831 | GNUNET_assert (slen1 + slen2 == | 812 | GNUNET_assert (slen1 + slen2 == |
832 | GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2, | 813 | GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], |
814 | slen1 + slen2, | ||
815 | 2, | ||
833 | handle->current->subsystem, | 816 | handle->current->subsystem, |
834 | handle->current->name)); | 817 | handle->current->name)); |
835 | if (GNUNET_YES != handle->receiving) | 818 | GNUNET_MQ_send (handle->mq, |
836 | { | 819 | env); |
837 | handle->receiving = GNUNET_YES; | ||
838 | GNUNET_CLIENT_receive (handle->client, &receive_stats, handle, | ||
839 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
840 | } | ||
841 | GNUNET_assert (NULL == handle->current->cont); | 820 | GNUNET_assert (NULL == handle->current->cont); |
842 | free_action_item (handle->current); | 821 | free_action_item (handle->current); |
843 | handle->current = NULL; | 822 | handle->current = NULL; |
844 | return msize; | ||
845 | } | 823 | } |
846 | 824 | ||
847 | 825 | ||
@@ -849,39 +827,20 @@ transmit_watch (struct GNUNET_STATISTICS_Handle *handle, | |||
849 | * Transmit a SET/UPDATE request. | 827 | * Transmit a SET/UPDATE request. |
850 | * | 828 | * |
851 | * @param handle statistics handle | 829 | * @param handle statistics handle |
852 | * @param size how many bytes can we write to @a buf | ||
853 | * @param buf where to write requests to the service | ||
854 | * @return number of bytes written to @a buf | ||
855 | */ | 830 | */ |
856 | static size_t | 831 | static void |
857 | transmit_set (struct GNUNET_STATISTICS_Handle *handle, | 832 | transmit_set (struct GNUNET_STATISTICS_Handle *handle) |
858 | size_t size, | ||
859 | void *buf) | ||
860 | { | 833 | { |
861 | struct GNUNET_STATISTICS_SetMessage *r; | 834 | struct GNUNET_STATISTICS_SetMessage *r; |
835 | struct GNUNET_MQ_Envelope *env; | ||
862 | size_t slen; | 836 | size_t slen; |
863 | size_t nlen; | 837 | size_t nlen; |
864 | size_t nsize; | ||
865 | 838 | ||
866 | if (NULL == buf) | ||
867 | { | ||
868 | do_disconnect (handle); | ||
869 | reconnect_later (handle); | ||
870 | return 0; | ||
871 | } | ||
872 | slen = strlen (handle->current->subsystem) + 1; | 839 | slen = strlen (handle->current->subsystem) + 1; |
873 | nlen = strlen (handle->current->name) + 1; | 840 | nlen = strlen (handle->current->name) + 1; |
874 | nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen; | 841 | env = GNUNET_MQ_msg_extra (r, |
875 | if (size < nsize) | 842 | slen + nlen, |
876 | { | 843 | GNUNET_MESSAGE_TYPE_STATISTICS_SET); |
877 | GNUNET_break (0); | ||
878 | do_disconnect (handle); | ||
879 | reconnect_later (handle); | ||
880 | return 0; | ||
881 | } | ||
882 | r = buf; | ||
883 | r->header.size = htons (nsize); | ||
884 | r->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET); | ||
885 | r->flags = 0; | 844 | r->flags = 0; |
886 | r->value = GNUNET_htonll (handle->current->value); | 845 | r->value = GNUNET_htonll (handle->current->value); |
887 | if (handle->current->make_persistent) | 846 | if (handle->current->make_persistent) |
@@ -889,52 +848,17 @@ transmit_set (struct GNUNET_STATISTICS_Handle *handle, | |||
889 | if (handle->current->type == ACTION_UPDATE) | 848 | if (handle->current->type == ACTION_UPDATE) |
890 | r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE); | 849 | r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE); |
891 | GNUNET_assert (slen + nlen == | 850 | GNUNET_assert (slen + nlen == |
892 | GNUNET_STRINGS_buffer_fill ((char *) &r[1], slen + nlen, 2, | 851 | GNUNET_STRINGS_buffer_fill ((char *) &r[1], |
852 | slen + nlen, | ||
853 | 2, | ||
893 | handle->current->subsystem, | 854 | handle->current->subsystem, |
894 | handle->current->name)); | 855 | handle->current->name)); |
895 | GNUNET_assert (NULL == handle->current->cont); | 856 | GNUNET_assert (NULL == handle->current->cont); |
896 | free_action_item (handle->current); | 857 | free_action_item (handle->current); |
897 | handle->current = NULL; | 858 | handle->current = NULL; |
898 | update_memory_statistics (handle); | 859 | update_memory_statistics (handle); |
899 | return nsize; | 860 | GNUNET_MQ_send (handle->mq, |
900 | } | 861 | env); |
901 | |||
902 | |||
903 | /** | ||
904 | * Function called when we are ready to transmit a request to the service. | ||
905 | * | ||
906 | * @param cls the `struct GNUNET_STATISTICS_Handle` | ||
907 | * @param size how many bytes can we write to @a buf | ||
908 | * @param buf where to write requests to the service | ||
909 | * @return number of bytes written to @a buf | ||
910 | */ | ||
911 | static size_t | ||
912 | transmit_action (void *cls, size_t size, void *buf) | ||
913 | { | ||
914 | struct GNUNET_STATISTICS_Handle *h = cls; | ||
915 | size_t ret; | ||
916 | |||
917 | h->th = NULL; | ||
918 | ret = 0; | ||
919 | if (NULL != h->current) | ||
920 | switch (h->current->type) | ||
921 | { | ||
922 | case ACTION_GET: | ||
923 | ret = transmit_get (h, size, buf); | ||
924 | break; | ||
925 | case ACTION_SET: | ||
926 | case ACTION_UPDATE: | ||
927 | ret = transmit_set (h, size, buf); | ||
928 | break; | ||
929 | case ACTION_WATCH: | ||
930 | ret = transmit_watch (h, size, buf); | ||
931 | break; | ||
932 | default: | ||
933 | GNUNET_assert (0); | ||
934 | break; | ||
935 | } | ||
936 | schedule_action (h); | ||
937 | return ret; | ||
938 | } | 862 | } |
939 | 863 | ||
940 | 864 | ||
@@ -952,10 +876,10 @@ GNUNET_STATISTICS_create (const char *subsystem, | |||
952 | struct GNUNET_STATISTICS_Handle *ret; | 876 | struct GNUNET_STATISTICS_Handle *ret; |
953 | 877 | ||
954 | if (GNUNET_YES == | 878 | if (GNUNET_YES == |
955 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "statistics", "DISABLE")) | 879 | GNUNET_CONFIGURATION_get_value_yesno (cfg, |
880 | "statistics", | ||
881 | "DISABLE")) | ||
956 | return NULL; | 882 | return NULL; |
957 | GNUNET_assert (NULL != subsystem); | ||
958 | GNUNET_assert (NULL != cfg); | ||
959 | ret = GNUNET_new (struct GNUNET_STATISTICS_Handle); | 883 | ret = GNUNET_new (struct GNUNET_STATISTICS_Handle); |
960 | ret->cfg = cfg; | 884 | ret->cfg = cfg; |
961 | ret->subsystem = GNUNET_strdup (subsystem); | 885 | ret->subsystem = GNUNET_strdup (subsystem); |
@@ -978,8 +902,6 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, | |||
978 | { | 902 | { |
979 | struct GNUNET_STATISTICS_GetHandle *pos; | 903 | struct GNUNET_STATISTICS_GetHandle *pos; |
980 | struct GNUNET_STATISTICS_GetHandle *next; | 904 | struct GNUNET_STATISTICS_GetHandle *next; |
981 | struct GNUNET_TIME_Relative timeout; | ||
982 | int i; | ||
983 | 905 | ||
984 | if (NULL == h) | 906 | if (NULL == h) |
985 | return; | 907 | return; |
@@ -989,26 +911,19 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, | |||
989 | GNUNET_SCHEDULER_cancel (h->backoff_task); | 911 | GNUNET_SCHEDULER_cancel (h->backoff_task); |
990 | h->backoff_task = NULL; | 912 | h->backoff_task = NULL; |
991 | } | 913 | } |
992 | if (sync_first) | 914 | if ( (sync_first) && |
915 | (GNUNET_YES == try_connect (h)) ) | ||
993 | { | 916 | { |
994 | if (NULL != h->current) | 917 | if ( (NULL != h->current) && |
995 | { | 918 | (ACTION_GET == h->current->type) ) |
996 | if (ACTION_GET == h->current->type) | 919 | h->current->aborted = GNUNET_YES; |
997 | { | ||
998 | if (NULL != h->th) | ||
999 | { | ||
1000 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); | ||
1001 | h->th = NULL; | ||
1002 | } | ||
1003 | free_action_item (h->current); | ||
1004 | h->current = NULL; | ||
1005 | } | ||
1006 | } | ||
1007 | next = h->action_head; | 920 | next = h->action_head; |
1008 | while (NULL != (pos = next)) | 921 | while (NULL != (pos = next)) |
1009 | { | 922 | { |
1010 | next = pos->next; | 923 | next = pos->next; |
1011 | if (ACTION_GET == pos->type) | 924 | if ( (ACTION_GET == pos->type) || |
925 | (ACTION_WATCH == pos->type) || | ||
926 | (GNUNET_NO == pos->make_persistent) ) | ||
1012 | { | 927 | { |
1013 | GNUNET_CONTAINER_DLL_remove (h->action_head, | 928 | GNUNET_CONTAINER_DLL_remove (h->action_head, |
1014 | h->action_tail, | 929 | h->action_tail, |
@@ -1016,25 +931,11 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, | |||
1016 | free_action_item (pos); | 931 | free_action_item (pos); |
1017 | } | 932 | } |
1018 | } | 933 | } |
1019 | if ( (NULL == h->current) && | ||
1020 | (NULL != (h->current = h->action_head)) ) | ||
1021 | GNUNET_CONTAINER_DLL_remove (h->action_head, | ||
1022 | h->action_tail, | ||
1023 | h->current); | ||
1024 | h->do_destroy = GNUNET_YES; | 934 | h->do_destroy = GNUNET_YES; |
1025 | if ((NULL != h->current) && (NULL == h->th) && | 935 | schedule_action (h); |
1026 | (NULL != h->client)) | 936 | return; /* do not finish destruction just yet */ |
1027 | { | ||
1028 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); | ||
1029 | h->th = | ||
1030 | GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize, | ||
1031 | timeout, GNUNET_YES, | ||
1032 | &transmit_action, h); | ||
1033 | GNUNET_assert (NULL != h->th); | ||
1034 | } | ||
1035 | if (NULL != h->th) | ||
1036 | return; /* do not finish destruction just yet */ | ||
1037 | } | 937 | } |
938 | /* do clean up all */ | ||
1038 | while (NULL != (pos = h->action_head)) | 939 | while (NULL != (pos = h->action_head)) |
1039 | { | 940 | { |
1040 | GNUNET_CONTAINER_DLL_remove (h->action_head, | 941 | GNUNET_CONTAINER_DLL_remove (h->action_head, |
@@ -1043,7 +944,7 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, | |||
1043 | free_action_item (pos); | 944 | free_action_item (pos); |
1044 | } | 945 | } |
1045 | do_disconnect (h); | 946 | do_disconnect (h); |
1046 | for (i = 0; i < h->watches_size; i++) | 947 | for (unsigned int i = 0; i < h->watches_size; i++) |
1047 | { | 948 | { |
1048 | if (NULL == h->watches[i]) | 949 | if (NULL == h->watches[i]) |
1049 | continue; | 950 | continue; |
@@ -1051,53 +952,15 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, | |||
1051 | GNUNET_free (h->watches[i]->name); | 952 | GNUNET_free (h->watches[i]->name); |
1052 | GNUNET_free (h->watches[i]); | 953 | GNUNET_free (h->watches[i]); |
1053 | } | 954 | } |
1054 | GNUNET_array_grow (h->watches, h->watches_size, 0); | 955 | GNUNET_array_grow (h->watches, |
956 | h->watches_size, | ||
957 | 0); | ||
1055 | GNUNET_free (h->subsystem); | 958 | GNUNET_free (h->subsystem); |
1056 | GNUNET_free (h); | 959 | GNUNET_free (h); |
1057 | } | 960 | } |
1058 | 961 | ||
1059 | 962 | ||
1060 | /** | 963 | /** |
1061 | * Function called to transmit TEST message to service to | ||
1062 | * confirm that the service has received all of our 'SET' | ||
1063 | * messages (during statistics disconnect/shutdown). | ||
1064 | * | ||
1065 | * @param cls the `struct GNUNET_STATISTICS_Handle` | ||
1066 | * @param size how many bytes can we write to @a buf | ||
1067 | * @param buf where to write requests to the service | ||
1068 | * @return number of bytes written to @a buf | ||
1069 | */ | ||
1070 | static size_t | ||
1071 | transmit_test_on_shutdown (void *cls, | ||
1072 | size_t size, | ||
1073 | void *buf) | ||
1074 | { | ||
1075 | struct GNUNET_STATISTICS_Handle *h = cls; | ||
1076 | struct GNUNET_MessageHeader hdr; | ||
1077 | |||
1078 | h->th = NULL; | ||
1079 | if (NULL == buf) | ||
1080 | { | ||
1081 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1082 | _("Failed to receive acknowledgement from statistics service, some statistics might have been lost!\n")); | ||
1083 | h->do_destroy = GNUNET_NO; | ||
1084 | GNUNET_SCHEDULER_add_now (&destroy_task, h); | ||
1085 | return 0; | ||
1086 | } | ||
1087 | hdr.type = htons (GNUNET_MESSAGE_TYPE_TEST); | ||
1088 | hdr.size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
1089 | memcpy (buf, &hdr, sizeof (hdr)); | ||
1090 | if (GNUNET_YES != h->receiving) | ||
1091 | { | ||
1092 | h->receiving = GNUNET_YES; | ||
1093 | GNUNET_CLIENT_receive (h->client, &receive_stats, h, | ||
1094 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1095 | } | ||
1096 | return sizeof (struct GNUNET_MessageHeader); | ||
1097 | } | ||
1098 | |||
1099 | |||
1100 | /** | ||
1101 | * Schedule the next action to be performed. | 964 | * Schedule the next action to be performed. |
1102 | * | 965 | * |
1103 | * @param h statistics handle | 966 | * @param h statistics handle |
@@ -1105,76 +968,61 @@ transmit_test_on_shutdown (void *cls, | |||
1105 | static void | 968 | static void |
1106 | schedule_action (struct GNUNET_STATISTICS_Handle *h) | 969 | schedule_action (struct GNUNET_STATISTICS_Handle *h) |
1107 | { | 970 | { |
1108 | struct GNUNET_TIME_Relative timeout; | 971 | if (NULL != h->backoff_task) |
1109 | |||
1110 | if ( (NULL != h->th) || | ||
1111 | (NULL != h->backoff_task) ) | ||
1112 | return; /* action already pending */ | 972 | return; /* action already pending */ |
1113 | if (GNUNET_YES != try_connect (h)) | 973 | if (GNUNET_YES != try_connect (h)) |
1114 | { | 974 | { |
1115 | reconnect_later (h); | 975 | reconnect_later (h); |
1116 | return; | 976 | return; |
1117 | } | 977 | } |
1118 | if (NULL != h->current) | ||
1119 | return; /* action already pending */ | ||
1120 | /* schedule next action */ | 978 | /* schedule next action */ |
1121 | h->current = h->action_head; | 979 | while (NULL == h->current) |
1122 | if (NULL == h->current) | ||
1123 | { | 980 | { |
1124 | if (GNUNET_YES == h->do_destroy) | 981 | h->current = h->action_head; |
982 | if (NULL == h->current) | ||
1125 | { | 983 | { |
984 | struct GNUNET_MessageHeader *hdr; | ||
985 | struct GNUNET_MQ_Envelope *env; | ||
986 | |||
987 | if (GNUNET_YES != h->do_destroy) | ||
988 | return; /* nothing to do */ | ||
989 | /* let service know that we're done */ | ||
1126 | h->do_destroy = GNUNET_SYSERR; /* in 'TEST' mode */ | 990 | h->do_destroy = GNUNET_SYSERR; /* in 'TEST' mode */ |
1127 | h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, | 991 | env = GNUNET_MQ_msg (hdr, |
1128 | sizeof (struct GNUNET_MessageHeader), | 992 | GNUNET_MESSAGE_TYPE_TEST); |
1129 | SET_TRANSMIT_TIMEOUT, | 993 | GNUNET_MQ_send (h->mq, |
1130 | GNUNET_NO, | 994 | env); |
1131 | &transmit_test_on_shutdown, h); | 995 | return; |
996 | } | ||
997 | GNUNET_CONTAINER_DLL_remove (h->action_head, | ||
998 | h->action_tail, | ||
999 | h->current); | ||
1000 | switch (h->current->type) | ||
1001 | { | ||
1002 | case ACTION_GET: | ||
1003 | transmit_get (h); | ||
1004 | break; | ||
1005 | case ACTION_SET: | ||
1006 | case ACTION_UPDATE: | ||
1007 | transmit_set (h); | ||
1008 | break; | ||
1009 | case ACTION_WATCH: | ||
1010 | transmit_watch (h); | ||
1011 | break; | ||
1012 | default: | ||
1013 | GNUNET_assert (0); | ||
1014 | break; | ||
1132 | } | 1015 | } |
1133 | return; | ||
1134 | } | ||
1135 | GNUNET_CONTAINER_DLL_remove (h->action_head, h->action_tail, h->current); | ||
1136 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); | ||
1137 | if (NULL == | ||
1138 | (h->th = | ||
1139 | GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize, | ||
1140 | timeout, GNUNET_YES, | ||
1141 | &transmit_action, h))) | ||
1142 | { | ||
1143 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1144 | "Failed to transmit request to statistics service.\n"); | ||
1145 | do_disconnect (h); | ||
1146 | reconnect_later (h); | ||
1147 | } | 1016 | } |
1148 | } | 1017 | } |
1149 | 1018 | ||
1150 | 1019 | ||
1151 | /** | 1020 | /** |
1152 | * We have run into a timeout on a #GNUNET_STATISTICS_get() operation, | ||
1153 | * call the continuation. | ||
1154 | * | ||
1155 | * @param cls the `struct GNUNET_STATISTICS_GetHandle` | ||
1156 | */ | ||
1157 | static void | ||
1158 | run_get_timeout (void *cls) | ||
1159 | { | ||
1160 | struct GNUNET_STATISTICS_GetHandle *gh = cls; | ||
1161 | GNUNET_STATISTICS_Callback cont = gh->cont; | ||
1162 | void *cont_cls = gh->cls; | ||
1163 | |||
1164 | gh->timeout_task = NULL; | ||
1165 | GNUNET_STATISTICS_get_cancel (gh); | ||
1166 | cont (cont_cls, GNUNET_SYSERR); | ||
1167 | } | ||
1168 | |||
1169 | |||
1170 | /** | ||
1171 | * Get statistic from the peer. | 1021 | * Get statistic from the peer. |
1172 | * | 1022 | * |
1173 | * @param handle identification of the statistics service | 1023 | * @param handle identification of the statistics service |
1174 | * @param subsystem limit to the specified subsystem, NULL for our subsystem | 1024 | * @param subsystem limit to the specified subsystem, NULL for our subsystem |
1175 | * @param name name of the statistic value, NULL for all values | 1025 | * @param name name of the statistic value, NULL for all values |
1176 | * @param timeout after how long should we give up (and call | ||
1177 | * cont with an error code)? | ||
1178 | * @param cont continuation to call when done (can be NULL) | 1026 | * @param cont continuation to call when done (can be NULL) |
1179 | * This callback CANNOT destroy the statistics handle in the same call. | 1027 | * This callback CANNOT destroy the statistics handle in the same call. |
1180 | * @param proc function to call on each value | 1028 | * @param proc function to call on each value |
@@ -1183,10 +1031,11 @@ run_get_timeout (void *cls) | |||
1183 | */ | 1031 | */ |
1184 | struct GNUNET_STATISTICS_GetHandle * | 1032 | struct GNUNET_STATISTICS_GetHandle * |
1185 | GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | 1033 | GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, |
1186 | const char *subsystem, const char *name, | 1034 | const char *subsystem, |
1187 | struct GNUNET_TIME_Relative timeout, | 1035 | const char *name, |
1188 | GNUNET_STATISTICS_Callback cont, | 1036 | GNUNET_STATISTICS_Callback cont, |
1189 | GNUNET_STATISTICS_Iterator proc, void *cls) | 1037 | GNUNET_STATISTICS_Iterator proc, |
1038 | void *cls) | ||
1190 | { | 1039 | { |
1191 | size_t slen1; | 1040 | size_t slen1; |
1192 | size_t slen2; | 1041 | size_t slen2; |
@@ -1211,12 +1060,8 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | |||
1211 | ai->cont = cont; | 1060 | ai->cont = cont; |
1212 | ai->proc = proc; | 1061 | ai->proc = proc; |
1213 | ai->cls = cls; | 1062 | ai->cls = cls; |
1214 | ai->timeout = GNUNET_TIME_relative_to_absolute (timeout); | ||
1215 | ai->type = ACTION_GET; | 1063 | ai->type = ACTION_GET; |
1216 | ai->msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader); | 1064 | ai->msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader); |
1217 | ai->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, | ||
1218 | &run_get_timeout, | ||
1219 | ai); | ||
1220 | GNUNET_CONTAINER_DLL_insert_tail (handle->action_head, | 1065 | GNUNET_CONTAINER_DLL_insert_tail (handle->action_head, |
1221 | handle->action_tail, | 1066 | handle->action_tail, |
1222 | ai); | 1067 | ai); |
@@ -1236,23 +1081,18 @@ GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) | |||
1236 | { | 1081 | { |
1237 | if (NULL == gh) | 1082 | if (NULL == gh) |
1238 | return; | 1083 | return; |
1239 | if (NULL != gh->timeout_task) | ||
1240 | { | ||
1241 | GNUNET_SCHEDULER_cancel (gh->timeout_task); | ||
1242 | gh->timeout_task = NULL; | ||
1243 | } | ||
1244 | gh->cont = NULL; | 1084 | gh->cont = NULL; |
1245 | if (gh->sh->current == gh) | 1085 | if (gh->sh->current == gh) |
1246 | { | 1086 | { |
1247 | gh->aborted = GNUNET_YES; | 1087 | gh->aborted = GNUNET_YES; |
1088 | return; | ||
1248 | } | 1089 | } |
1249 | else | 1090 | GNUNET_CONTAINER_DLL_remove (gh->sh->action_head, |
1250 | { | 1091 | gh->sh->action_tail, |
1251 | GNUNET_CONTAINER_DLL_remove (gh->sh->action_head, gh->sh->action_tail, gh); | 1092 | gh); |
1252 | GNUNET_free (gh->name); | 1093 | GNUNET_free (gh->name); |
1253 | GNUNET_free (gh->subsystem); | 1094 | GNUNET_free (gh->subsystem); |
1254 | GNUNET_free (gh); | 1095 | GNUNET_free (gh); |
1255 | } | ||
1256 | } | 1096 | } |
1257 | 1097 | ||
1258 | 1098 | ||
@@ -1268,8 +1108,10 @@ GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) | |||
1268 | */ | 1108 | */ |
1269 | int | 1109 | int |
1270 | GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, | 1110 | GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, |
1271 | const char *subsystem, const char *name, | 1111 | const char *subsystem, |
1272 | GNUNET_STATISTICS_Iterator proc, void *proc_cls) | 1112 | const char *name, |
1113 | GNUNET_STATISTICS_Iterator proc, | ||
1114 | void *proc_cls) | ||
1273 | { | 1115 | { |
1274 | struct GNUNET_STATISTICS_WatchEntry *w; | 1116 | struct GNUNET_STATISTICS_WatchEntry *w; |
1275 | 1117 | ||
@@ -1280,8 +1122,11 @@ GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, | |||
1280 | w->name = GNUNET_strdup (name); | 1122 | w->name = GNUNET_strdup (name); |
1281 | w->proc = proc; | 1123 | w->proc = proc; |
1282 | w->proc_cls = proc_cls; | 1124 | w->proc_cls = proc_cls; |
1283 | GNUNET_array_append (handle->watches, handle->watches_size, w); | 1125 | GNUNET_array_append (handle->watches, |
1284 | schedule_watch_request (handle, w); | 1126 | handle->watches_size, |
1127 | w); | ||
1128 | schedule_watch_request (handle, | ||
1129 | w); | ||
1285 | return GNUNET_OK; | 1130 | return GNUNET_OK; |
1286 | } | 1131 | } |
1287 | 1132 | ||
@@ -1304,11 +1149,10 @@ GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle, | |||
1304 | void *proc_cls) | 1149 | void *proc_cls) |
1305 | { | 1150 | { |
1306 | struct GNUNET_STATISTICS_WatchEntry *w; | 1151 | struct GNUNET_STATISTICS_WatchEntry *w; |
1307 | unsigned int i; | ||
1308 | 1152 | ||
1309 | if (NULL == handle) | 1153 | if (NULL == handle) |
1310 | return GNUNET_SYSERR; | 1154 | return GNUNET_SYSERR; |
1311 | for (i=0;i<handle->watches_size;i++) | 1155 | for (unsigned int i=0;i<handle->watches_size;i++) |
1312 | { | 1156 | { |
1313 | w = handle->watches[i]; | 1157 | w = handle->watches[i]; |
1314 | if (NULL == w) | 1158 | if (NULL == w) |
@@ -1329,7 +1173,6 @@ GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle, | |||
1329 | } | 1173 | } |
1330 | 1174 | ||
1331 | 1175 | ||
1332 | |||
1333 | /** | 1176 | /** |
1334 | * Queue a request to change a statistic. | 1177 | * Queue a request to change a statistic. |
1335 | * | 1178 | * |
@@ -1421,7 +1264,8 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, | |||
1421 | ai->msize = nsize; | 1264 | ai->msize = nsize; |
1422 | ai->value = value; | 1265 | ai->value = value; |
1423 | ai->type = type; | 1266 | ai->type = type; |
1424 | GNUNET_CONTAINER_DLL_insert_tail (h->action_head, h->action_tail, | 1267 | GNUNET_CONTAINER_DLL_insert_tail (h->action_head, |
1268 | h->action_tail, | ||
1425 | ai); | 1269 | ai); |
1426 | schedule_action (h); | 1270 | schedule_action (h); |
1427 | } | 1271 | } |
@@ -1445,7 +1289,11 @@ GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, | |||
1445 | if (NULL == handle) | 1289 | if (NULL == handle) |
1446 | return; | 1290 | return; |
1447 | GNUNET_assert (GNUNET_NO == handle->do_destroy); | 1291 | GNUNET_assert (GNUNET_NO == handle->do_destroy); |
1448 | add_setter_action (handle, name, make_persistent, value, ACTION_SET); | 1292 | add_setter_action (handle, |
1293 | name, | ||
1294 | make_persistent, | ||
1295 | value, | ||
1296 | ACTION_SET); | ||
1449 | } | 1297 | } |
1450 | 1298 | ||
1451 | 1299 | ||
diff --git a/src/statistics/test_statistics_api.c b/src/statistics/test_statistics_api.c index fedc56c3b..0c7bb3488 100644 --- a/src/statistics/test_statistics_api.c +++ b/src/statistics/test_statistics_api.c | |||
@@ -31,11 +31,17 @@ static struct GNUNET_STATISTICS_Handle *h; | |||
31 | 31 | ||
32 | 32 | ||
33 | static int | 33 | static int |
34 | check_1 (void *cls, const char *subsystem, const char *name, uint64_t value, | 34 | check_1 (void *cls, |
35 | const char *subsystem, | ||
36 | const char *name, | ||
37 | uint64_t value, | ||
35 | int is_persistent) | 38 | int is_persistent) |
36 | { | 39 | { |
37 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received value %llu for `%s:%s\n", | 40 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
38 | (unsigned long long) value, subsystem, name); | 41 | "Received value %llu for `%s:%s\n", |
42 | (unsigned long long) value, | ||
43 | subsystem, | ||
44 | name); | ||
39 | GNUNET_assert (0 == strcmp (name, "test-1")); | 45 | GNUNET_assert (0 == strcmp (name, "test-1")); |
40 | GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); | 46 | GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); |
41 | GNUNET_assert (value == 1); | 47 | GNUNET_assert (value == 1); |
@@ -45,11 +51,17 @@ check_1 (void *cls, const char *subsystem, const char *name, uint64_t value, | |||
45 | 51 | ||
46 | 52 | ||
47 | static int | 53 | static int |
48 | check_2 (void *cls, const char *subsystem, const char *name, uint64_t value, | 54 | check_2 (void *cls, |
55 | const char *subsystem, | ||
56 | const char *name, | ||
57 | uint64_t value, | ||
49 | int is_persistent) | 58 | int is_persistent) |
50 | { | 59 | { |
51 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received value %llu for `%s:%s\n", | 60 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
52 | (unsigned long long) value, subsystem, name); | 61 | "Received value %llu for `%s:%s\n", |
62 | (unsigned long long) value, | ||
63 | subsystem, | ||
64 | name); | ||
53 | GNUNET_assert (0 == strcmp (name, "test-2")); | 65 | GNUNET_assert (0 == strcmp (name, "test-2")); |
54 | GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); | 66 | GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); |
55 | GNUNET_assert (value == 2); | 67 | GNUNET_assert (value == 2); |
@@ -59,11 +71,17 @@ check_2 (void *cls, const char *subsystem, const char *name, uint64_t value, | |||
59 | 71 | ||
60 | 72 | ||
61 | static int | 73 | static int |
62 | check_3 (void *cls, const char *subsystem, const char *name, uint64_t value, | 74 | check_3 (void *cls, |
75 | const char *subsystem, | ||
76 | const char *name, | ||
77 | uint64_t value, | ||
63 | int is_persistent) | 78 | int is_persistent) |
64 | { | 79 | { |
65 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received value %llu for `%s:%s\n", | 80 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
66 | (unsigned long long) value, subsystem, name); | 81 | "Received value %llu for `%s:%s\n", |
82 | (unsigned long long) value, | ||
83 | subsystem, | ||
84 | name); | ||
67 | GNUNET_assert (0 == strcmp (name, "test-3")); | 85 | GNUNET_assert (0 == strcmp (name, "test-3")); |
68 | GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); | 86 | GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); |
69 | GNUNET_assert (value == 3); | 87 | GNUNET_assert (value == 3); |
@@ -73,7 +91,8 @@ check_3 (void *cls, const char *subsystem, const char *name, uint64_t value, | |||
73 | 91 | ||
74 | 92 | ||
75 | static void | 93 | static void |
76 | next_fin (void *cls, int success) | 94 | next_fin (void *cls, |
95 | int success) | ||
77 | { | 96 | { |
78 | int *ok = cls; | 97 | int *ok = cls; |
79 | 98 | ||
@@ -87,16 +106,19 @@ static void | |||
87 | next (void *cls, int success) | 106 | next (void *cls, int success) |
88 | { | 107 | { |
89 | GNUNET_assert (success == GNUNET_OK); | 108 | GNUNET_assert (success == GNUNET_OK); |
90 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n"); | 109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
110 | "Issuing GET request\n"); | ||
91 | GNUNET_break (NULL != | 111 | GNUNET_break (NULL != |
92 | GNUNET_STATISTICS_get (h, NULL, "test-2", | 112 | GNUNET_STATISTICS_get (h, NULL, "test-2", |
93 | GNUNET_TIME_UNIT_SECONDS, &next_fin, | 113 | &next_fin, |
94 | &check_2, cls)); | 114 | &check_2, cls)); |
95 | } | 115 | } |
96 | 116 | ||
97 | 117 | ||
98 | static void | 118 | static void |
99 | run (void *cls, char *const *args, const char *cfgfile, | 119 | run (void *cls, |
120 | char *const *args, | ||
121 | const char *cfgfile, | ||
100 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 122 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
101 | { | 123 | { |
102 | h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); | 124 | h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); |
@@ -107,19 +129,23 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n"); | 129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n"); |
108 | GNUNET_break (NULL != | 130 | GNUNET_break (NULL != |
109 | GNUNET_STATISTICS_get (h, NULL, "test-1", | 131 | GNUNET_STATISTICS_get (h, NULL, "test-1", |
110 | GNUNET_TIME_UNIT_SECONDS, &next, | 132 | &next, |
111 | &check_1, cls)); | 133 | &check_1, cls)); |
112 | } | 134 | } |
113 | 135 | ||
114 | 136 | ||
115 | static void | 137 | static void |
116 | run_more (void *cls, char *const *args, const char *cfgfile, | 138 | run_more (void *cls, |
139 | char *const *args, | ||
140 | const char *cfgfile, | ||
117 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 141 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
118 | { | 142 | { |
119 | h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); | 143 | h = GNUNET_STATISTICS_create ("test-statistics-api", |
144 | cfg); | ||
120 | GNUNET_break (NULL != | 145 | GNUNET_break (NULL != |
121 | GNUNET_STATISTICS_get (h, NULL, "test-3", | 146 | GNUNET_STATISTICS_get (h, NULL, |
122 | GNUNET_TIME_UNIT_SECONDS, &next_fin, | 147 | "test-3", |
148 | &next_fin, | ||
123 | &check_3, cls)); | 149 | &check_3, cls)); |
124 | } | 150 | } |
125 | 151 | ||
@@ -128,7 +154,6 @@ int | |||
128 | main (int argc, char *argv_ign[]) | 154 | main (int argc, char *argv_ign[]) |
129 | { | 155 | { |
130 | int ok = 1; | 156 | int ok = 1; |
131 | |||
132 | char *const argv[] = { "test-statistics-api", | 157 | char *const argv[] = { "test-statistics-api", |
133 | "-c", | 158 | "-c", |
134 | "test_statistics_api_data.conf", | 159 | "test_statistics_api_data.conf", |
@@ -146,15 +171,19 @@ main (int argc, char *argv_ign[]) | |||
146 | NULL); | 171 | NULL); |
147 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics"); | 172 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics"); |
148 | proc = | 173 | proc = |
149 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 174 | GNUNET_OS_start_process (GNUNET_YES, |
175 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
150 | NULL, NULL, NULL, | 176 | NULL, NULL, NULL, |
151 | binary, | 177 | binary, |
152 | "gnunet-service-statistics", | 178 | "gnunet-service-statistics", |
153 | "-c", "test_statistics_api_data.conf", NULL); | 179 | "-c", "test_statistics_api_data.conf", NULL); |
154 | GNUNET_assert (NULL != proc); | 180 | GNUNET_assert (NULL != proc); |
155 | GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, &run, | 181 | GNUNET_PROGRAM_run (5, argv, |
182 | "test-statistics-api", "nohelp", | ||
183 | options, &run, | ||
156 | &ok); | 184 | &ok); |
157 | if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) | 185 | if (0 != GNUNET_OS_process_kill (proc, |
186 | GNUNET_TERM_SIG)) | ||
158 | { | 187 | { |
159 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 188 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
160 | ok = 1; | 189 | ok = 1; |
@@ -170,14 +199,19 @@ main (int argc, char *argv_ign[]) | |||
170 | ok = 1; | 199 | ok = 1; |
171 | /* restart to check persistence! */ | 200 | /* restart to check persistence! */ |
172 | proc = | 201 | proc = |
173 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 202 | GNUNET_OS_start_process (GNUNET_YES, |
203 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
174 | NULL, NULL, NULL, | 204 | NULL, NULL, NULL, |
175 | binary, | 205 | binary, |
176 | "gnunet-service-statistics", | 206 | "gnunet-service-statistics", |
177 | "-c", "test_statistics_api_data.conf", NULL); | 207 | "-c", "test_statistics_api_data.conf", |
178 | GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, | 208 | NULL); |
209 | GNUNET_PROGRAM_run (5, argv, | ||
210 | "test-statistics-api", "nohelp", | ||
211 | options, | ||
179 | &run_more, &ok); | 212 | &run_more, &ok); |
180 | if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) | 213 | if (0 != GNUNET_OS_process_kill (proc, |
214 | GNUNET_TERM_SIG)) | ||
181 | { | 215 | { |
182 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 216 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
183 | ok = 1; | 217 | ok = 1; |
diff --git a/src/statistics/test_statistics_api_loop.c b/src/statistics/test_statistics_api_loop.c index 64e6dec5f..a7e2cbab5 100644 --- a/src/statistics/test_statistics_api_loop.c +++ b/src/statistics/test_statistics_api_loop.c | |||
@@ -70,7 +70,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
70 | i = 0; | 70 | i = 0; |
71 | GNUNET_break (NULL != | 71 | GNUNET_break (NULL != |
72 | GNUNET_STATISTICS_get (h, NULL, "test-0", | 72 | GNUNET_STATISTICS_get (h, NULL, "test-0", |
73 | GNUNET_TIME_UNIT_MINUTES, &next, | 73 | &next, |
74 | &check_1, cls)); | 74 | &check_1, cls)); |
75 | } | 75 | } |
76 | 76 | ||
diff --git a/src/testbed/testbed_api_statistics.c b/src/testbed/testbed_api_statistics.c index a4778f84d..4fd117953 100644 --- a/src/testbed/testbed_api_statistics.c +++ b/src/testbed/testbed_api_statistics.c | |||
@@ -262,10 +262,11 @@ service_connect_comp (void *cls, | |||
262 | struct PeerGetStatsContext *peer_sc = cls; | 262 | struct PeerGetStatsContext *peer_sc = cls; |
263 | struct GNUNET_STATISTICS_Handle *h = ca_result; | 263 | struct GNUNET_STATISTICS_Handle *h = ca_result; |
264 | 264 | ||
265 | LOG_DEBUG ("Retrieving statistics of peer %u\n", peer_sc->peer_index); | 265 | LOG_DEBUG ("Retrieving statistics of peer %u\n", |
266 | peer_sc->peer_index); | ||
266 | peer_sc->get_handle = | 267 | peer_sc->get_handle = |
267 | GNUNET_STATISTICS_get (h, peer_sc->sc->subsystem, peer_sc->sc->name, | 268 | GNUNET_STATISTICS_get (h, peer_sc->sc->subsystem, |
268 | GNUNET_TIME_UNIT_FOREVER_REL, | 269 | peer_sc->sc->name, |
269 | &iteration_completion_cb, | 270 | &iteration_completion_cb, |
270 | iterator_cb, peer_sc); | 271 | iterator_cb, peer_sc); |
271 | } | 272 | } |