diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/testbed/testbed_api_statistics.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/testbed/testbed_api_statistics.c')
-rw-r--r-- | src/testbed/testbed_api_statistics.c | 204 |
1 files changed, 103 insertions, 101 deletions
diff --git a/src/testbed/testbed_api_statistics.c b/src/testbed/testbed_api_statistics.c index e7440dfa1..4858208cc 100644 --- a/src/testbed/testbed_api_statistics.c +++ b/src/testbed/testbed_api_statistics.c | |||
@@ -35,19 +35,20 @@ | |||
35 | * Generic logging shorthand | 35 | * Generic logging shorthand |
36 | */ | 36 | */ |
37 | #define LOG(kind, ...) \ | 37 | #define LOG(kind, ...) \ |
38 | GNUNET_log_from(kind, "testbed-api-statistics", __VA_ARGS__) | 38 | GNUNET_log_from (kind, "testbed-api-statistics", __VA_ARGS__) |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Debug logging shorthand | 41 | * Debug logging shorthand |
42 | */ | 42 | */ |
43 | #define LOG_DEBUG(...) \ | 43 | #define LOG_DEBUG(...) \ |
44 | LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 44 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Context information for use in GNUNET_TESTBED_get_statistics() | 48 | * Context information for use in GNUNET_TESTBED_get_statistics() |
49 | */ | 49 | */ |
50 | struct GetStatsContext { | 50 | struct GetStatsContext |
51 | { | ||
51 | /** | 52 | /** |
52 | * The main operation we generate while creating this context | 53 | * The main operation we generate while creating this context |
53 | */ | 54 | */ |
@@ -93,7 +94,7 @@ struct GetStatsContext { | |||
93 | /** | 94 | /** |
94 | * The task for calling the continuation callback | 95 | * The task for calling the continuation callback |
95 | */ | 96 | */ |
96 | struct GNUNET_SCHEDULER_Task * call_completion_task_id; | 97 | struct GNUNET_SCHEDULER_Task *call_completion_task_id; |
97 | 98 | ||
98 | /** | 99 | /** |
99 | * The number of peers present in the peers array. This number also | 100 | * The number of peers present in the peers array. This number also |
@@ -111,7 +112,8 @@ struct GetStatsContext { | |||
111 | /** | 112 | /** |
112 | * Context information with respect to a particular peer | 113 | * Context information with respect to a particular peer |
113 | */ | 114 | */ |
114 | struct PeerGetStatsContext { | 115 | struct PeerGetStatsContext |
116 | { | ||
115 | /** | 117 | /** |
116 | * The GetStatsContext which is associated with this context | 118 | * The GetStatsContext which is associated with this context |
117 | */ | 119 | */ |
@@ -125,7 +127,7 @@ struct PeerGetStatsContext { | |||
125 | /** | 127 | /** |
126 | * Task to mark the statistics service connect operation as done | 128 | * Task to mark the statistics service connect operation as done |
127 | */ | 129 | */ |
128 | struct GNUNET_SCHEDULER_Task * op_done_task_id; | 130 | struct GNUNET_SCHEDULER_Task *op_done_task_id; |
129 | 131 | ||
130 | /** | 132 | /** |
131 | * The index of this peer in the peers array of GetStatsContext | 133 | * The index of this peer in the peers array of GetStatsContext |
@@ -149,14 +151,14 @@ static struct OperationQueue *no_wait_queue; | |||
149 | * @param cls the GetStatsContext | 151 | * @param cls the GetStatsContext |
150 | */ | 152 | */ |
151 | static void | 153 | static void |
152 | call_completion_task(void *cls) | 154 | call_completion_task (void *cls) |
153 | { | 155 | { |
154 | struct GetStatsContext *sc = cls; | 156 | struct GetStatsContext *sc = cls; |
155 | 157 | ||
156 | GNUNET_assert(sc->call_completion_task_id != NULL); | 158 | GNUNET_assert (sc->call_completion_task_id != NULL); |
157 | sc->call_completion_task_id = NULL; | 159 | sc->call_completion_task_id = NULL; |
158 | LOG_DEBUG("Calling get_statistics() continuation callback\n"); | 160 | LOG_DEBUG ("Calling get_statistics() continuation callback\n"); |
159 | sc->cont(sc->cb_cls, sc->main_op, NULL); | 161 | sc->cont (sc->cb_cls, sc->main_op, NULL); |
160 | } | 162 | } |
161 | 163 | ||
162 | 164 | ||
@@ -167,7 +169,7 @@ call_completion_task(void *cls) | |||
167 | * @param cls the PeerGetStatsContext | 169 | * @param cls the PeerGetStatsContext |
168 | */ | 170 | */ |
169 | static void | 171 | static void |
170 | op_done_task(void *cls) | 172 | op_done_task (void *cls) |
171 | { | 173 | { |
172 | struct PeerGetStatsContext *peer_sc = cls; | 174 | struct PeerGetStatsContext *peer_sc = cls; |
173 | struct GetStatsContext *sc; | 175 | struct GetStatsContext *sc; |
@@ -176,8 +178,8 @@ op_done_task(void *cls) | |||
176 | sc = peer_sc->sc; | 178 | sc = peer_sc->sc; |
177 | peer_sc->op_done_task_id = NULL; | 179 | peer_sc->op_done_task_id = NULL; |
178 | op = &sc->ops[peer_sc->peer_index]; | 180 | op = &sc->ops[peer_sc->peer_index]; |
179 | GNUNET_assert(NULL != *op); | 181 | GNUNET_assert (NULL != *op); |
180 | GNUNET_TESTBED_operation_done(*op); | 182 | GNUNET_TESTBED_operation_done (*op); |
181 | *op = NULL; | 183 | *op = NULL; |
182 | } | 184 | } |
183 | 185 | ||
@@ -190,22 +192,22 @@ op_done_task(void *cls) | |||
190 | * successfully obtained, GNUNET_SYSERR if not. | 192 | * successfully obtained, GNUNET_SYSERR if not. |
191 | */ | 193 | */ |
192 | static void | 194 | static void |
193 | iteration_completion_cb(void *cls, int success) | 195 | iteration_completion_cb (void *cls, int success) |
194 | { | 196 | { |
195 | struct PeerGetStatsContext *peer_sc = cls; | 197 | struct PeerGetStatsContext *peer_sc = cls; |
196 | struct GetStatsContext *sc; | 198 | struct GetStatsContext *sc; |
197 | 199 | ||
198 | GNUNET_break(GNUNET_OK == success); | 200 | GNUNET_break (GNUNET_OK == success); |
199 | sc = peer_sc->sc; | 201 | sc = peer_sc->sc; |
200 | peer_sc->get_handle = NULL; | 202 | peer_sc->get_handle = NULL; |
201 | sc->num_completed++; | 203 | sc->num_completed++; |
202 | peer_sc->op_done_task_id = GNUNET_SCHEDULER_add_now(&op_done_task, peer_sc); | 204 | peer_sc->op_done_task_id = GNUNET_SCHEDULER_add_now (&op_done_task, peer_sc); |
203 | if (sc->num_completed == sc->num_peers) | 205 | if (sc->num_completed == sc->num_peers) |
204 | { | 206 | { |
205 | LOG_DEBUG("Scheduling to call iteration completion callback\n"); | 207 | LOG_DEBUG ("Scheduling to call iteration completion callback\n"); |
206 | sc->call_completion_task_id = | 208 | sc->call_completion_task_id = |
207 | GNUNET_SCHEDULER_add_now(&call_completion_task, sc); | 209 | GNUNET_SCHEDULER_add_now (&call_completion_task, sc); |
208 | } | 210 | } |
209 | } | 211 | } |
210 | 212 | ||
211 | 213 | ||
@@ -220,9 +222,9 @@ iteration_completion_cb(void *cls, int success) | |||
220 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | 222 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration |
221 | */ | 223 | */ |
222 | static int | 224 | static int |
223 | iterator_cb(void *cls, const char *subsystem, | 225 | iterator_cb (void *cls, const char *subsystem, |
224 | const char *name, uint64_t value, | 226 | const char *name, uint64_t value, |
225 | int is_persistent) | 227 | int is_persistent) |
226 | { | 228 | { |
227 | struct PeerGetStatsContext *peer_sc = cls; | 229 | struct PeerGetStatsContext *peer_sc = cls; |
228 | struct GetStatsContext *sc; | 230 | struct GetStatsContext *sc; |
@@ -231,12 +233,12 @@ iterator_cb(void *cls, const char *subsystem, | |||
231 | 233 | ||
232 | sc = peer_sc->sc; | 234 | sc = peer_sc->sc; |
233 | peer = sc->peers[peer_sc->peer_index]; | 235 | peer = sc->peers[peer_sc->peer_index]; |
234 | LOG_DEBUG("Peer %u: [%s,%s] -> %lu\n", peer_sc->peer_index, | 236 | LOG_DEBUG ("Peer %u: [%s,%s] -> %lu\n", peer_sc->peer_index, |
235 | subsystem, name, (unsigned long)value); | 237 | subsystem, name, (unsigned long) value); |
236 | ret = sc->proc(sc->cb_cls, peer, | 238 | ret = sc->proc (sc->cb_cls, peer, |
237 | subsystem, name, value, is_persistent); | 239 | subsystem, name, value, is_persistent); |
238 | if (GNUNET_SYSERR == ret) | 240 | if (GNUNET_SYSERR == ret) |
239 | LOG_DEBUG("Aborting iteration for peer %u\n", peer_sc->peer_index); | 241 | LOG_DEBUG ("Aborting iteration for peer %u\n", peer_sc->peer_index); |
240 | return ret; | 242 | return ret; |
241 | } | 243 | } |
242 | 244 | ||
@@ -251,21 +253,21 @@ iterator_cb(void *cls, const char *subsystem, | |||
251 | * operation has executed successfully. | 253 | * operation has executed successfully. |
252 | */ | 254 | */ |
253 | static void | 255 | static void |
254 | service_connect_comp(void *cls, | 256 | service_connect_comp (void *cls, |
255 | struct GNUNET_TESTBED_Operation *op, | 257 | struct GNUNET_TESTBED_Operation *op, |
256 | void *ca_result, | 258 | void *ca_result, |
257 | const char *emsg) | 259 | const char *emsg) |
258 | { | 260 | { |
259 | struct PeerGetStatsContext *peer_sc = cls; | 261 | struct PeerGetStatsContext *peer_sc = cls; |
260 | struct GNUNET_STATISTICS_Handle *h = ca_result; | 262 | struct GNUNET_STATISTICS_Handle *h = ca_result; |
261 | 263 | ||
262 | LOG_DEBUG("Retrieving statistics of peer %u\n", | 264 | LOG_DEBUG ("Retrieving statistics of peer %u\n", |
263 | peer_sc->peer_index); | 265 | peer_sc->peer_index); |
264 | peer_sc->get_handle = | 266 | peer_sc->get_handle = |
265 | GNUNET_STATISTICS_get(h, peer_sc->sc->subsystem, | 267 | GNUNET_STATISTICS_get (h, peer_sc->sc->subsystem, |
266 | peer_sc->sc->name, | 268 | peer_sc->sc->name, |
267 | &iteration_completion_cb, | 269 | &iteration_completion_cb, |
268 | iterator_cb, peer_sc); | 270 | iterator_cb, peer_sc); |
269 | } | 271 | } |
270 | 272 | ||
271 | 273 | ||
@@ -280,13 +282,13 @@ service_connect_comp(void *cls, | |||
280 | * @return service handle to return in 'op_result', NULL on error | 282 | * @return service handle to return in 'op_result', NULL on error |
281 | */ | 283 | */ |
282 | static void * | 284 | static void * |
283 | statistics_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 285 | statistics_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
284 | { | 286 | { |
285 | struct PeerGetStatsContext *peer_sc = cls; | 287 | struct PeerGetStatsContext *peer_sc = cls; |
286 | 288 | ||
287 | LOG_DEBUG("Connecting to statistics service of peer %u\n", | 289 | LOG_DEBUG ("Connecting to statistics service of peer %u\n", |
288 | peer_sc->peer_index); | 290 | peer_sc->peer_index); |
289 | return GNUNET_STATISTICS_create("<testbed-api>", cfg); | 291 | return GNUNET_STATISTICS_create ("<testbed-api>", cfg); |
290 | } | 292 | } |
291 | 293 | ||
292 | 294 | ||
@@ -297,20 +299,20 @@ statistics_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
297 | * @param op_result service handle returned from the connect adapter | 299 | * @param op_result service handle returned from the connect adapter |
298 | */ | 300 | */ |
299 | static void | 301 | static void |
300 | statistics_da(void *cls, void *op_result) | 302 | statistics_da (void *cls, void *op_result) |
301 | { | 303 | { |
302 | struct PeerGetStatsContext *peer_sc = cls; | 304 | struct PeerGetStatsContext *peer_sc = cls; |
303 | struct GNUNET_STATISTICS_Handle *sh = op_result; | 305 | struct GNUNET_STATISTICS_Handle *sh = op_result; |
304 | 306 | ||
305 | if (NULL != peer_sc->get_handle) | 307 | if (NULL != peer_sc->get_handle) |
306 | { | 308 | { |
307 | GNUNET_STATISTICS_get_cancel(peer_sc->get_handle); | 309 | GNUNET_STATISTICS_get_cancel (peer_sc->get_handle); |
308 | peer_sc->get_handle = NULL; | 310 | peer_sc->get_handle = NULL; |
309 | } | 311 | } |
310 | GNUNET_STATISTICS_destroy(sh, GNUNET_NO); | 312 | GNUNET_STATISTICS_destroy (sh, GNUNET_NO); |
311 | if (NULL != peer_sc->op_done_task_id) | 313 | if (NULL != peer_sc->op_done_task_id) |
312 | GNUNET_SCHEDULER_cancel(peer_sc->op_done_task_id); | 314 | GNUNET_SCHEDULER_cancel (peer_sc->op_done_task_id); |
313 | GNUNET_free(peer_sc); | 315 | GNUNET_free (peer_sc); |
314 | } | 316 | } |
315 | 317 | ||
316 | 318 | ||
@@ -320,33 +322,33 @@ statistics_da(void *cls, void *op_result) | |||
320 | * @param cls the GetStatsContext | 322 | * @param cls the GetStatsContext |
321 | */ | 323 | */ |
322 | static void | 324 | static void |
323 | opstart_get_stats(void *cls) | 325 | opstart_get_stats (void *cls) |
324 | { | 326 | { |
325 | struct GetStatsContext *sc = cls; | 327 | struct GetStatsContext *sc = cls; |
326 | struct PeerGetStatsContext *peer_sc; | 328 | struct PeerGetStatsContext *peer_sc; |
327 | unsigned int peer; | 329 | unsigned int peer; |
328 | 330 | ||
329 | LOG_DEBUG("Starting get_statistics operation\n"); | 331 | LOG_DEBUG ("Starting get_statistics operation\n"); |
330 | sc->ops = GNUNET_malloc(sc->num_peers * | 332 | sc->ops = GNUNET_malloc (sc->num_peers |
331 | sizeof(struct GNUNET_TESTBED_Operation *)); | 333 | * sizeof(struct GNUNET_TESTBED_Operation *)); |
332 | for (peer = 0; peer < sc->num_peers; peer++) | 334 | for (peer = 0; peer < sc->num_peers; peer++) |
335 | { | ||
336 | if (NULL == sc->peers[peer]) | ||
333 | { | 337 | { |
334 | if (NULL == sc->peers[peer]) | 338 | GNUNET_break (0); |
335 | { | 339 | continue; |
336 | GNUNET_break(0); | ||
337 | continue; | ||
338 | } | ||
339 | peer_sc = GNUNET_new(struct PeerGetStatsContext); | ||
340 | peer_sc->sc = sc; | ||
341 | peer_sc->peer_index = peer; | ||
342 | sc->ops[peer] = | ||
343 | GNUNET_TESTBED_service_connect(sc, sc->peers[peer], "statistics", | ||
344 | &service_connect_comp, | ||
345 | peer_sc, | ||
346 | &statistics_ca, | ||
347 | &statistics_da, | ||
348 | peer_sc); | ||
349 | } | 340 | } |
341 | peer_sc = GNUNET_new (struct PeerGetStatsContext); | ||
342 | peer_sc->sc = sc; | ||
343 | peer_sc->peer_index = peer; | ||
344 | sc->ops[peer] = | ||
345 | GNUNET_TESTBED_service_connect (sc, sc->peers[peer], "statistics", | ||
346 | &service_connect_comp, | ||
347 | peer_sc, | ||
348 | &statistics_ca, | ||
349 | &statistics_da, | ||
350 | peer_sc); | ||
351 | } | ||
350 | } | 352 | } |
351 | 353 | ||
352 | 354 | ||
@@ -356,31 +358,31 @@ opstart_get_stats(void *cls) | |||
356 | * @param cls the GetStatsContext | 358 | * @param cls the GetStatsContext |
357 | */ | 359 | */ |
358 | static void | 360 | static void |
359 | oprelease_get_stats(void *cls) | 361 | oprelease_get_stats (void *cls) |
360 | { | 362 | { |
361 | struct GetStatsContext *sc = cls; | 363 | struct GetStatsContext *sc = cls; |
362 | unsigned int peer; | 364 | unsigned int peer; |
363 | 365 | ||
364 | LOG_DEBUG("Cleaning up get_statistics operation\n"); | 366 | LOG_DEBUG ("Cleaning up get_statistics operation\n"); |
365 | if (NULL != sc->call_completion_task_id) | 367 | if (NULL != sc->call_completion_task_id) |
366 | GNUNET_SCHEDULER_cancel(sc->call_completion_task_id); | 368 | GNUNET_SCHEDULER_cancel (sc->call_completion_task_id); |
367 | if (NULL != sc->ops) | 369 | if (NULL != sc->ops) |
370 | { | ||
371 | for (peer = 0; peer < sc->num_peers; peer++) | ||
368 | { | 372 | { |
369 | for (peer = 0; peer < sc->num_peers; peer++) | 373 | if (NULL != sc->ops[peer]) |
370 | { | 374 | { |
371 | if (NULL != sc->ops[peer]) | 375 | GNUNET_TESTBED_operation_done (sc->ops[peer]); |
372 | { | 376 | sc->ops[peer] = NULL; |
373 | GNUNET_TESTBED_operation_done(sc->ops[peer]); | 377 | } |
374 | sc->ops[peer] = NULL; | ||
375 | } | ||
376 | } | ||
377 | GNUNET_free(sc->ops); | ||
378 | } | 378 | } |
379 | GNUNET_free_non_null(sc->subsystem); | 379 | GNUNET_free (sc->ops); |
380 | GNUNET_free_non_null(sc->name); | 380 | } |
381 | GNUNET_free(sc); | 381 | GNUNET_free_non_null (sc->subsystem); |
382 | GNUNET_free_non_null (sc->name); | ||
383 | GNUNET_free (sc); | ||
382 | if (GNUNET_YES == | 384 | if (GNUNET_YES == |
383 | GNUNET_TESTBED_operation_queue_destroy_empty_(no_wait_queue)) | 385 | GNUNET_TESTBED_operation_queue_destroy_empty_ (no_wait_queue)) |
384 | no_wait_queue = NULL; | 386 | no_wait_queue = NULL; |
385 | } | 387 | } |
386 | 388 | ||
@@ -399,33 +401,33 @@ oprelease_get_stats(void *cls) | |||
399 | * @return operation handle to cancel the operation | 401 | * @return operation handle to cancel the operation |
400 | */ | 402 | */ |
401 | struct GNUNET_TESTBED_Operation * | 403 | struct GNUNET_TESTBED_Operation * |
402 | GNUNET_TESTBED_get_statistics(unsigned int num_peers, | 404 | GNUNET_TESTBED_get_statistics (unsigned int num_peers, |
403 | struct GNUNET_TESTBED_Peer **peers, | 405 | struct GNUNET_TESTBED_Peer **peers, |
404 | const char *subsystem, const char *name, | 406 | const char *subsystem, const char *name, |
405 | GNUNET_TESTBED_StatisticsIterator proc, | 407 | GNUNET_TESTBED_StatisticsIterator proc, |
406 | GNUNET_TESTBED_OperationCompletionCallback cont, | 408 | GNUNET_TESTBED_OperationCompletionCallback cont, |
407 | void *cls) | 409 | void *cls) |
408 | { | 410 | { |
409 | struct GetStatsContext *sc; | 411 | struct GetStatsContext *sc; |
410 | 412 | ||
411 | GNUNET_assert(NULL != proc); | 413 | GNUNET_assert (NULL != proc); |
412 | GNUNET_assert(NULL != cont); | 414 | GNUNET_assert (NULL != cont); |
413 | if (NULL == no_wait_queue) | 415 | if (NULL == no_wait_queue) |
414 | no_wait_queue = GNUNET_TESTBED_operation_queue_create_ | 416 | no_wait_queue = GNUNET_TESTBED_operation_queue_create_ |
415 | (OPERATION_QUEUE_TYPE_FIXED, UINT_MAX); | 417 | (OPERATION_QUEUE_TYPE_FIXED, UINT_MAX); |
416 | sc = GNUNET_new(struct GetStatsContext); | 418 | sc = GNUNET_new (struct GetStatsContext); |
417 | sc->peers = peers; | 419 | sc->peers = peers; |
418 | sc->subsystem = (NULL == subsystem) ? NULL : GNUNET_strdup(subsystem); | 420 | sc->subsystem = (NULL == subsystem) ? NULL : GNUNET_strdup (subsystem); |
419 | sc->name = (NULL == name) ? NULL : GNUNET_strdup(name); | 421 | sc->name = (NULL == name) ? NULL : GNUNET_strdup (name); |
420 | sc->proc = proc; | 422 | sc->proc = proc; |
421 | sc->cont = cont; | 423 | sc->cont = cont; |
422 | sc->cb_cls = cls; | 424 | sc->cb_cls = cls; |
423 | sc->num_peers = num_peers; | 425 | sc->num_peers = num_peers; |
424 | sc->main_op = | 426 | sc->main_op = |
425 | GNUNET_TESTBED_operation_create_(sc, &opstart_get_stats, | 427 | GNUNET_TESTBED_operation_create_ (sc, &opstart_get_stats, |
426 | &oprelease_get_stats); | 428 | &oprelease_get_stats); |
427 | GNUNET_TESTBED_operation_queue_insert_(no_wait_queue, sc->main_op); | 429 | GNUNET_TESTBED_operation_queue_insert_ (no_wait_queue, sc->main_op); |
428 | GNUNET_TESTBED_operation_begin_wait_(sc->main_op); | 430 | GNUNET_TESTBED_operation_begin_wait_ (sc->main_op); |
429 | return sc->main_op; | 431 | return sc->main_op; |
430 | } | 432 | } |
431 | 433 | ||