aboutsummaryrefslogtreecommitdiff
path: root/src/arm/test_exponential_backoff.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arm/test_exponential_backoff.c')
-rw-r--r--src/arm/test_exponential_backoff.c37
1 files changed, 12 insertions, 25 deletions
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c
index dd32f6a5d..8e5ac9bc1 100644
--- a/src/arm/test_exponential_backoff.c
+++ b/src/arm/test_exponential_backoff.c
@@ -35,7 +35,6 @@
35#define SERVICE_TEST_TIMEOUT GNUNET_TIME_UNIT_FOREVER_REL 35#define SERVICE_TEST_TIMEOUT GNUNET_TIME_UNIT_FOREVER_REL
36#define FIVE_MILLISECONDS GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 5) 36#define FIVE_MILLISECONDS GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 5)
37 37
38static struct GNUNET_SCHEDULER_Handle *sched;
39static const struct GNUNET_CONFIGURATION_Handle *cfg; 38static const struct GNUNET_CONFIGURATION_Handle *cfg;
40static struct GNUNET_ARM_Handle *arm; 39static struct GNUNET_ARM_Handle *arm;
41static int ok = 1; 40static int ok = 1;
@@ -56,10 +55,6 @@ static char *killLogFileName;
56struct ShutdownContext 55struct ShutdownContext
57{ 56{
58 /** 57 /**
59 * Scheduler to be used to call continuation
60 */
61 struct GNUNET_SCHEDULER_Handle *sched;
62 /**
63 * Connection to the service that is being shutdown. 58 * Connection to the service that is being shutdown.
64 */ 59 */
65 struct GNUNET_CLIENT_Connection *sock; 60 struct GNUNET_CLIENT_Connection *sock;
@@ -114,7 +109,7 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
114 "Service handle shutdown before ACK!\n"); 109 "Service handle shutdown before ACK!\n");
115 if (shutdown_ctx->cont != NULL) 110 if (shutdown_ctx->cont != NULL)
116 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR); 111 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
117 GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->cancel_task); 112 GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
118 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); 113 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
119 GNUNET_free(shutdown_ctx); 114 GNUNET_free(shutdown_ctx);
120 } 115 }
@@ -127,7 +122,7 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
127 if (shutdown_ctx->cont != NULL) 122 if (shutdown_ctx->cont != NULL)
128 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_NO); 123 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_NO);
129 124
130 GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->cancel_task); 125 GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
131 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); 126 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
132 GNUNET_free(shutdown_ctx); 127 GNUNET_free(shutdown_ctx);
133 } 128 }
@@ -153,7 +148,7 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
153 if (shutdown_ctx->cont != NULL) 148 if (shutdown_ctx->cont != NULL)
154 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES); 149 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES);
155 150
156 GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->cancel_task); 151 GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
157 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); 152 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
158 GNUNET_free(shutdown_ctx); 153 GNUNET_free(shutdown_ctx);
159 break; 154 break;
@@ -206,8 +201,7 @@ write_shutdown (void *cls, size_t size, void *buf)
206 GNUNET_CLIENT_receive (shutdown_ctx->sock, 201 GNUNET_CLIENT_receive (shutdown_ctx->sock,
207 &service_shutdown_handler, shutdown_ctx, 202 &service_shutdown_handler, shutdown_ctx,
208 GNUNET_TIME_UNIT_FOREVER_REL); 203 GNUNET_TIME_UNIT_FOREVER_REL);
209 shutdown_ctx->cancel_task = GNUNET_SCHEDULER_add_delayed (shutdown_ctx->sched, 204 shutdown_ctx->cancel_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining(shutdown_ctx->timeout),
210 GNUNET_TIME_absolute_get_remaining(shutdown_ctx->timeout),
211 &service_shutdown_cancel, 205 &service_shutdown_cancel,
212 shutdown_ctx); 206 shutdown_ctx);
213 msg = (struct GNUNET_MessageHeader *) buf; 207 msg = (struct GNUNET_MessageHeader *) buf;
@@ -224,7 +218,6 @@ write_shutdown (void *cls, size_t size, void *buf)
224 * be used by the caller after this call 218 * be used by the caller after this call
225 * (calling this function frees "sock" after a while). 219 * (calling this function frees "sock" after a while).
226 * 220 *
227 * @param sched the scheduler to use for calling shutdown continuation
228 * @param sock the socket connected to the service 221 * @param sock the socket connected to the service
229 * @param timeout how long to wait before giving up on transmission 222 * @param timeout how long to wait before giving up on transmission
230 * @param cont continuation to call once the service is really down 223 * @param cont continuation to call once the service is really down
@@ -232,15 +225,13 @@ write_shutdown (void *cls, size_t size, void *buf)
232 * 225 *
233 */ 226 */
234static void 227static void
235arm_service_shutdown (struct GNUNET_SCHEDULER_Handle *sched, 228arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock,
236 struct GNUNET_CLIENT_Connection *sock,
237 struct GNUNET_TIME_Relative timeout, 229 struct GNUNET_TIME_Relative timeout,
238 GNUNET_CLIENT_ShutdownTask cont, 230 GNUNET_CLIENT_ShutdownTask cont,
239 void *cont_cls) 231 void *cont_cls)
240{ 232{
241 struct ShutdownContext *shutdown_ctx; 233 struct ShutdownContext *shutdown_ctx;
242 shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext)); 234 shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext));
243 shutdown_ctx->sched = sched;
244 shutdown_ctx->cont = cont; 235 shutdown_ctx->cont = cont;
245 shutdown_ctx->cont_cls = cont_cls; 236 shutdown_ctx->cont_cls = cont_cls;
246 shutdown_ctx->sock = sock; 237 shutdown_ctx->sock = sock;
@@ -274,7 +265,7 @@ do_nothing_notify (void *cls, int success)
274{ 265{
275 GNUNET_assert (success == GNUNET_YES); 266 GNUNET_assert (success == GNUNET_YES);
276 ok = 1; 267 ok = 1;
277 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_UNIT_SECONDS, 268 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
278 &kill_task, NULL); 269 &kill_task, NULL);
279} 270}
280 271
@@ -322,7 +313,7 @@ do_nothing_restarted_notify_task (void *cls,
322 trialCount); 313 trialCount);
323 } 314 }
324#endif 315#endif
325 GNUNET_SCHEDULER_add_now (sched, &kill_task, &a); 316 GNUNET_SCHEDULER_add_now (&kill_task, &a);
326} 317}
327 318
328 319
@@ -330,7 +321,7 @@ static void
330do_test (void *cbData, 321do_test (void *cbData,
331 const struct GNUNET_SCHEDULER_TaskContext *tc) 322 const struct GNUNET_SCHEDULER_TaskContext *tc)
332{ 323{
333 GNUNET_CLIENT_service_test(sched, "do-nothing", 324 GNUNET_CLIENT_service_test("do-nothing",
334 cfg, TIMEOUT, 325 cfg, TIMEOUT,
335 &do_nothing_restarted_notify_task, NULL); 326 &do_nothing_restarted_notify_task, NULL);
336} 327}
@@ -341,8 +332,7 @@ shutdown_cont (void *cls, int reason)
341{ 332{
342 trialCount++; 333 trialCount++;
343 startedWaitingAt = GNUNET_TIME_absolute_get(); 334 startedWaitingAt = GNUNET_TIME_absolute_get();
344 GNUNET_SCHEDULER_add_delayed (sched, 335 GNUNET_SCHEDULER_add_delayed (waitedFor,
345 waitedFor,
346 &do_test, 336 &do_test,
347 NULL); 337 NULL);
348} 338}
@@ -369,7 +359,7 @@ kill_task (void *cbData,
369 waitedFor.rel_value = 0; 359 waitedFor.rel_value = 0;
370 } 360 }
371 /* Connect to the doNothing task */ 361 /* Connect to the doNothing task */
372 doNothingConnection = GNUNET_CLIENT_connect (sched, "do-nothing", cfg); 362 doNothingConnection = GNUNET_CLIENT_connect ("do-nothing", cfg);
373#if LOG_BACKOFF 363#if LOG_BACKOFF
374 if (NULL == doNothingConnection) 364 if (NULL == doNothingConnection)
375 fprintf(killLogFilePtr, 365 fprintf(killLogFilePtr,
@@ -385,8 +375,7 @@ kill_task (void *cbData,
385 } 375 }
386 376
387 /* Use the created connection to kill the doNothingTask */ 377 /* Use the created connection to kill the doNothingTask */
388 arm_service_shutdown(sched, 378 arm_service_shutdown(doNothingConnection,
389 doNothingConnection,
390 TIMEOUT, 379 TIMEOUT,
391 &shutdown_cont, NULL); 380 &shutdown_cont, NULL);
392} 381}
@@ -394,15 +383,13 @@ kill_task (void *cbData,
394 383
395static void 384static void
396task (void *cls, 385task (void *cls,
397 struct GNUNET_SCHEDULER_Handle *s,
398 char *const *args, 386 char *const *args,
399 const char *cfgfile, 387 const char *cfgfile,
400 const struct GNUNET_CONFIGURATION_Handle *c) 388 const struct GNUNET_CONFIGURATION_Handle *c)
401{ 389{
402 cfg = c; 390 cfg = c;
403 sched = s;
404 391
405 arm = GNUNET_ARM_connect (cfg, sched, NULL); 392 arm = GNUNET_ARM_connect (cfg,NULL);
406#if START_ARM 393#if START_ARM
407 GNUNET_ARM_start_service (arm, "arm", GNUNET_TIME_UNIT_ZERO, &arm_notify, NULL); 394 GNUNET_ARM_start_service (arm, "arm", GNUNET_TIME_UNIT_ZERO, &arm_notify, NULL);
408#else 395#else