diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-23 14:22:34 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-23 14:22:34 +0000 |
commit | 5742938289524f4c5fba7883742e4dd69cccf11d (patch) | |
tree | e16fea8b9d778f9825f897237b0c1880305776a0 /src/arm/test_exponential_backoff.c | |
parent | f3edb5a8d6ba6f43f5df18f2e98bc1dae90c9d7a (diff) | |
download | gnunet-5742938289524f4c5fba7883742e4dd69cccf11d.tar.gz gnunet-5742938289524f4c5fba7883742e4dd69cccf11d.zip |
refactoring ARM api to use new MQ
Diffstat (limited to 'src/arm/test_exponential_backoff.c')
-rw-r--r-- | src/arm/test_exponential_backoff.c | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c index 3f33c91e6..8135f5157 100644 --- a/src/arm/test_exponential_backoff.c +++ b/src/arm/test_exponential_backoff.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 GNUnet e.V. | 3 | Copyright (C) 2009, 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 |
@@ -70,7 +70,9 @@ static char *killLogFileName; | |||
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | 72 | ||
73 | typedef void (*GNUNET_CLIENT_ShutdownTask) (void *cls, int reason); | 73 | typedef void |
74 | (*GNUNET_CLIENT_ShutdownTask) (void *cls, int reason); | ||
75 | |||
74 | 76 | ||
75 | /** | 77 | /** |
76 | * Context for handling the shutdown of a service. | 78 | * Context for handling the shutdown of a service. |
@@ -118,7 +120,8 @@ struct ShutdownContext | |||
118 | * @param msg NULL, indicating socket closure. | 120 | * @param msg NULL, indicating socket closure. |
119 | */ | 121 | */ |
120 | static void | 122 | static void |
121 | service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg) | 123 | service_shutdown_handler (void *cls, |
124 | const struct GNUNET_MessageHeader *msg) | ||
122 | { | 125 | { |
123 | struct ShutdownContext *shutdown_ctx = cls; | 126 | struct ShutdownContext *shutdown_ctx = cls; |
124 | 127 | ||
@@ -147,7 +150,8 @@ service_shutdown_cancel (void *cls) | |||
147 | { | 150 | { |
148 | struct ShutdownContext *shutdown_ctx = cls; | 151 | struct ShutdownContext *shutdown_ctx = cls; |
149 | 152 | ||
150 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "service_shutdown_cancel called!\n"); | 153 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
154 | "service_shutdown_cancel called!\n"); | ||
151 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR); | 155 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR); |
152 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock); | 156 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock); |
153 | GNUNET_free (shutdown_ctx); | 157 | GNUNET_free (shutdown_ctx); |
@@ -207,8 +211,9 @@ write_shutdown (void *cls, size_t size, void *buf) | |||
207 | */ | 211 | */ |
208 | static void | 212 | static void |
209 | do_nothing_service_shutdown (struct GNUNET_CLIENT_Connection *sock, | 213 | do_nothing_service_shutdown (struct GNUNET_CLIENT_Connection *sock, |
210 | struct GNUNET_TIME_Relative timeout, | 214 | struct GNUNET_TIME_Relative timeout, |
211 | GNUNET_CLIENT_ShutdownTask cont, void *cont_cls) | 215 | GNUNET_CLIENT_ShutdownTask cont, |
216 | void *cont_cls) | ||
212 | { | 217 | { |
213 | struct ShutdownContext *shutdown_ctx; | 218 | struct ShutdownContext *shutdown_ctx; |
214 | 219 | ||
@@ -266,7 +271,10 @@ kill_task (void *cbData) | |||
266 | else if (trialCount == 13) | 271 | else if (trialCount == 13) |
267 | { | 272 | { |
268 | GNUNET_CLIENT_disconnect (doNothingConnection); | 273 | GNUNET_CLIENT_disconnect (doNothingConnection); |
269 | GNUNET_ARM_request_service_stop (arm, SERVICE, TIMEOUT, NULL, NULL); | 274 | GNUNET_ARM_request_service_stop (arm, |
275 | SERVICE, | ||
276 | NULL, | ||
277 | NULL); | ||
270 | if (waitedFor_prev.rel_value_us >= waitedFor.rel_value_us) | 278 | if (waitedFor_prev.rel_value_us >= waitedFor.rel_value_us) |
271 | ok = 9; | 279 | ok = 9; |
272 | else | 280 | else |
@@ -284,15 +292,14 @@ kill_task (void *cbData) | |||
284 | static void | 292 | static void |
285 | trigger_disconnect (void *cls) | 293 | trigger_disconnect (void *cls) |
286 | { | 294 | { |
287 | GNUNET_ARM_disconnect_and_free (arm); | 295 | GNUNET_ARM_disconnect (arm); |
288 | GNUNET_ARM_monitor_disconnect_and_free (mon); | 296 | GNUNET_ARM_monitor_stop (mon); |
289 | } | 297 | } |
290 | 298 | ||
291 | 299 | ||
292 | static void | 300 | static void |
293 | arm_stop_cb (void *cls, | 301 | arm_stop_cb (void *cls, |
294 | enum GNUNET_ARM_RequestStatus status, | 302 | enum GNUNET_ARM_RequestStatus status, |
295 | const char *servicename, | ||
296 | enum GNUNET_ARM_Result result) | 303 | enum GNUNET_ARM_Result result) |
297 | { | 304 | { |
298 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 305 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
@@ -303,14 +310,19 @@ arm_stop_cb (void *cls, | |||
303 | 310 | ||
304 | 311 | ||
305 | static void | 312 | static void |
306 | srv_status (void *cls, const char *service, enum GNUNET_ARM_ServiceStatus status) | 313 | srv_status (void *cls, |
314 | const char *service, | ||
315 | enum GNUNET_ARM_ServiceStatus status) | ||
307 | { | 316 | { |
308 | LOG ("Service %s is %u, phase %u\n", service, status, phase); | 317 | LOG ("Service %s is %u, phase %u\n", service, status, phase); |
309 | if (status == GNUNET_ARM_SERVICE_MONITORING_STARTED) | 318 | if (status == GNUNET_ARM_SERVICE_MONITORING_STARTED) |
310 | { | 319 | { |
311 | phase++; | 320 | phase++; |
312 | GNUNET_ARM_request_service_start (arm, SERVICE, | 321 | GNUNET_ARM_request_service_start (arm, |
313 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, TIMEOUT, NULL, NULL); | 322 | SERVICE, |
323 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
324 | NULL, | ||
325 | NULL); | ||
314 | return; | 326 | return; |
315 | } | 327 | } |
316 | if (phase == 1) | 328 | if (phase == 1) |
@@ -322,7 +334,8 @@ srv_status (void *cls, const char *service, enum GNUNET_ARM_ServiceStatus status | |||
322 | phase++; | 334 | phase++; |
323 | ok = 1; | 335 | ok = 1; |
324 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 336 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
325 | &kill_task, NULL); | 337 | &kill_task, |
338 | NULL); | ||
326 | } | 339 | } |
327 | else if ((phase == 2) && (strcasecmp (SERVICE, service) == 0)) | 340 | else if ((phase == 2) && (strcasecmp (SERVICE, service) == 0)) |
328 | { | 341 | { |
@@ -337,14 +350,19 @@ srv_status (void *cls, const char *service, enum GNUNET_ARM_ServiceStatus status | |||
337 | else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14)) | 350 | else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14)) |
338 | { | 351 | { |
339 | phase++; | 352 | phase++; |
340 | GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL); | 353 | GNUNET_ARM_request_service_stop (arm, |
354 | "arm", | ||
355 | &arm_stop_cb, | ||
356 | NULL); | ||
341 | } | 357 | } |
342 | } | 358 | } |
343 | } | 359 | } |
344 | 360 | ||
345 | 361 | ||
346 | static void | 362 | static void |
347 | arm_start_cb (void *cls, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result) | 363 | arm_start_cb (void *cls, |
364 | enum GNUNET_ARM_RequestStatus status, | ||
365 | enum GNUNET_ARM_Result result) | ||
348 | { | 366 | { |
349 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 367 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
350 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); | 368 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); |
@@ -355,26 +373,34 @@ arm_start_cb (void *cls, enum GNUNET_ARM_RequestStatus status, const char *servi | |||
355 | 373 | ||
356 | 374 | ||
357 | static void | 375 | static void |
358 | task (void *cls, char *const *args, const char *cfgfile, | 376 | task (void *cls, |
377 | char *const *args, | ||
378 | const char *cfgfile, | ||
359 | const struct GNUNET_CONFIGURATION_Handle *c) | 379 | const struct GNUNET_CONFIGURATION_Handle *c) |
360 | { | 380 | { |
361 | cfg = c; | 381 | cfg = c; |
362 | arm = GNUNET_ARM_connect (cfg, NULL, NULL); | 382 | arm = GNUNET_ARM_connect (cfg, NULL, NULL); |
363 | if (NULL != arm) | 383 | if (NULL != arm) |
364 | { | 384 | { |
365 | mon = GNUNET_ARM_monitor (cfg, &srv_status, NULL); | 385 | mon = GNUNET_ARM_monitor_start (cfg, &srv_status, NULL); |
366 | if (NULL != mon) | 386 | if (NULL != mon) |
367 | { | 387 | { |
368 | #if START_ARM | 388 | #if START_ARM |
369 | GNUNET_ARM_request_service_start (arm, "arm", | 389 | GNUNET_ARM_request_service_start (arm, |
370 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, GNUNET_TIME_UNIT_ZERO, arm_start_cb, NULL); | 390 | "arm", |
391 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
392 | &arm_start_cb, | ||
393 | NULL); | ||
371 | #else | 394 | #else |
372 | arm_start_cb (NULL, arm, GNUNET_ARM_REQUEST_SENT_OK, "arm", GNUNET_ARM_SERVICE_STARTING); | 395 | arm_start_cb (NULL, |
396 | arm, | ||
397 | GNUNET_ARM_REQUEST_SENT_OK, | ||
398 | GNUNET_ARM_SERVICE_STARTING); | ||
373 | #endif | 399 | #endif |
374 | } | 400 | } |
375 | else | 401 | else |
376 | { | 402 | { |
377 | GNUNET_ARM_disconnect_and_free (arm); | 403 | GNUNET_ARM_disconnect (arm); |
378 | arm = NULL; | 404 | arm = NULL; |
379 | } | 405 | } |
380 | } | 406 | } |