diff options
Diffstat (limited to 'src/arm/arm_api.c')
-rw-r--r-- | src/arm/arm_api.c | 508 |
1 files changed, 246 insertions, 262 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index 4114b8528..0db9e5c3e 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c | |||
@@ -106,61 +106,58 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
106 | struct ShutdownContext *shutdown_ctx = cls; | 106 | struct ShutdownContext *shutdown_ctx = cls; |
107 | 107 | ||
108 | if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES)) | 108 | if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES)) |
109 | { | 109 | { |
110 | #if DEBUG_ARM | 110 | #if DEBUG_ARM |
111 | /* Means the other side closed the connection and never confirmed a shutdown */ | 111 | /* Means the other side closed the connection and never confirmed a shutdown */ |
112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
113 | "Service handle shutdown before ACK!\n"); | 113 | "Service handle shutdown before ACK!\n"); |
114 | #endif | 114 | #endif |
115 | if (shutdown_ctx->cont != NULL) | 115 | if (shutdown_ctx->cont != NULL) |
116 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR); | 116 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR); |
117 | GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task); | 117 | GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task); |
118 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 118 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
119 | GNUNET_free(shutdown_ctx); | 119 | GNUNET_free (shutdown_ctx); |
120 | } | 120 | } |
121 | else if ((msg == NULL) && (shutdown_ctx->confirmed == GNUNET_YES)) | 121 | else if ((msg == NULL) && (shutdown_ctx->confirmed == GNUNET_YES)) |
122 | { | 122 | { |
123 | #if DEBUG_ARM | 123 | #if DEBUG_ARM |
124 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n"); |
125 | "Service shutdown complete.\n"); | ||
126 | #endif | 125 | #endif |
127 | if (shutdown_ctx->cont != NULL) | 126 | if (shutdown_ctx->cont != NULL) |
128 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_NO); | 127 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_NO); |
129 | 128 | ||
130 | GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task); | 129 | GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task); |
131 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 130 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
132 | GNUNET_free(shutdown_ctx); | 131 | GNUNET_free (shutdown_ctx); |
133 | } | 132 | } |
134 | else | 133 | else |
134 | { | ||
135 | GNUNET_assert (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader)); | ||
136 | switch (ntohs (msg->type)) | ||
135 | { | 137 | { |
136 | GNUNET_assert(ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader)); | 138 | case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK: |
137 | switch (ntohs(msg->type)) | ||
138 | { | ||
139 | case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK: | ||
140 | #if DEBUG_ARM | 139 | #if DEBUG_ARM |
141 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
142 | "Received confirmation for service shutdown.\n"); | 141 | "Received confirmation for service shutdown.\n"); |
143 | #endif | 142 | #endif |
144 | shutdown_ctx->confirmed = GNUNET_YES; | 143 | shutdown_ctx->confirmed = GNUNET_YES; |
145 | GNUNET_CLIENT_receive (shutdown_ctx->sock, | 144 | GNUNET_CLIENT_receive (shutdown_ctx->sock, |
146 | &service_shutdown_handler, | 145 | &service_shutdown_handler, |
147 | shutdown_ctx, | 146 | shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL); |
148 | GNUNET_TIME_UNIT_FOREVER_REL); | 147 | break; |
149 | break; | 148 | default: /* Fall through */ |
150 | default: /* Fall through */ | ||
151 | #if DEBUG_ARM | 149 | #if DEBUG_ARM |
152 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown refused!\n"); |
153 | "Service shutdown refused!\n"); | ||
154 | #endif | 151 | #endif |
155 | if (shutdown_ctx->cont != NULL) | 152 | if (shutdown_ctx->cont != NULL) |
156 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES); | 153 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_YES); |
157 | 154 | ||
158 | GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task); | 155 | GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task); |
159 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 156 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
160 | GNUNET_free(shutdown_ctx); | 157 | GNUNET_free (shutdown_ctx); |
161 | break; | 158 | break; |
162 | } | ||
163 | } | 159 | } |
160 | } | ||
164 | } | 161 | } |
165 | 162 | ||
166 | /** | 163 | /** |
@@ -169,16 +166,18 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
169 | * @param cls closure | 166 | * @param cls closure |
170 | * @param tc context information (why was this task triggered now) | 167 | * @param tc context information (why was this task triggered now) |
171 | */ | 168 | */ |
172 | void service_shutdown_cancel (void *cls, | 169 | void |
173 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 170 | service_shutdown_cancel (void *cls, |
171 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
174 | { | 172 | { |
175 | struct ShutdownContext *shutdown_ctx = cls; | 173 | struct ShutdownContext *shutdown_ctx = cls; |
174 | |||
176 | #if DEBUG_ARM | 175 | #if DEBUG_ARM |
177 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "service_shutdown_cancel called!\n"); | 176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "service_shutdown_cancel called!\n"); |
178 | #endif | 177 | #endif |
179 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR); | 178 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR); |
180 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 179 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
181 | GNUNET_free(shutdown_ctx); | 180 | GNUNET_free (shutdown_ctx); |
182 | } | 181 | } |
183 | 182 | ||
184 | 183 | ||
@@ -198,21 +197,22 @@ write_shutdown (void *cls, size_t size, void *buf) | |||
198 | struct ShutdownContext *shutdown_ctx = cls; | 197 | struct ShutdownContext *shutdown_ctx = cls; |
199 | 198 | ||
200 | if (size < sizeof (struct GNUNET_MessageHeader)) | 199 | if (size < sizeof (struct GNUNET_MessageHeader)) |
201 | { | 200 | { |
202 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 201 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
203 | _("Failed to transmit shutdown request to client.\n")); | 202 | _("Failed to transmit shutdown request to client.\n")); |
204 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR); | 203 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR); |
205 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 204 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
206 | GNUNET_free(shutdown_ctx); | 205 | GNUNET_free (shutdown_ctx); |
207 | return 0; /* client disconnected */ | 206 | return 0; /* client disconnected */ |
208 | } | 207 | } |
209 | 208 | ||
210 | GNUNET_CLIENT_receive (shutdown_ctx->sock, | 209 | GNUNET_CLIENT_receive (shutdown_ctx->sock, |
211 | &service_shutdown_handler, shutdown_ctx, | 210 | &service_shutdown_handler, shutdown_ctx, |
212 | GNUNET_TIME_UNIT_FOREVER_REL); | 211 | GNUNET_TIME_UNIT_FOREVER_REL); |
213 | shutdown_ctx->cancel_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining(shutdown_ctx->timeout), | 212 | shutdown_ctx->cancel_task = |
214 | &service_shutdown_cancel, | 213 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining |
215 | shutdown_ctx); | 214 | (shutdown_ctx->timeout), |
215 | &service_shutdown_cancel, shutdown_ctx); | ||
216 | msg = (struct GNUNET_MessageHeader *) buf; | 216 | msg = (struct GNUNET_MessageHeader *) buf; |
217 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN); | 217 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN); |
218 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 218 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
@@ -235,22 +235,22 @@ write_shutdown (void *cls, size_t size, void *buf) | |||
235 | */ | 235 | */ |
236 | static void | 236 | static void |
237 | arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock, | 237 | arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock, |
238 | struct GNUNET_TIME_Relative timeout, | 238 | struct GNUNET_TIME_Relative timeout, |
239 | GNUNET_CLIENT_ShutdownTask cont, | 239 | GNUNET_CLIENT_ShutdownTask cont, void *cont_cls) |
240 | void *cont_cls) | ||
241 | { | 240 | { |
242 | struct ShutdownContext *shutdown_ctx; | 241 | struct ShutdownContext *shutdown_ctx; |
243 | shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext)); | 242 | |
243 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); | ||
244 | shutdown_ctx->cont = cont; | 244 | shutdown_ctx->cont = cont; |
245 | shutdown_ctx->cont_cls = cont_cls; | 245 | shutdown_ctx->cont_cls = cont_cls; |
246 | shutdown_ctx->sock = sock; | 246 | shutdown_ctx->sock = sock; |
247 | shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute(timeout); | 247 | shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
248 | GNUNET_CLIENT_notify_transmit_ready (sock, | 248 | GNUNET_CLIENT_notify_transmit_ready (sock, |
249 | sizeof (struct | 249 | sizeof (struct |
250 | GNUNET_MessageHeader), | 250 | GNUNET_MessageHeader), |
251 | timeout, | 251 | timeout, |
252 | GNUNET_YES, | 252 | GNUNET_YES, |
253 | &write_shutdown, shutdown_ctx); | 253 | &write_shutdown, shutdown_ctx); |
254 | } | 254 | } |
255 | 255 | ||
256 | 256 | ||
@@ -266,7 +266,7 @@ arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock, | |||
266 | */ | 266 | */ |
267 | struct GNUNET_ARM_Handle * | 267 | struct GNUNET_ARM_Handle * |
268 | GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 268 | GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
269 | const char *service) | 269 | const char *service) |
270 | { | 270 | { |
271 | struct GNUNET_ARM_Handle *ret; | 271 | struct GNUNET_ARM_Handle *ret; |
272 | 272 | ||
@@ -351,8 +351,7 @@ struct RequestContext | |||
351 | * @param tc why were we called (reason says if ARM is running) | 351 | * @param tc why were we called (reason says if ARM is running) |
352 | */ | 352 | */ |
353 | static void | 353 | static void |
354 | arm_service_report (void *cls, | 354 | arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
355 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
356 | { | 355 | { |
357 | struct RequestContext *pos = cls; | 356 | struct RequestContext *pos = cls; |
358 | struct GNUNET_OS_Process *proc; | 357 | struct GNUNET_OS_Process *proc; |
@@ -362,111 +361,91 @@ arm_service_report (void *cls, | |||
362 | char *lopostfix; | 361 | char *lopostfix; |
363 | 362 | ||
364 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | 363 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) |
365 | { | 364 | { |
366 | #if DEBUG_ARM | 365 | #if DEBUG_ARM |
367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
368 | "Looks like `%s' is already running.\n", | 367 | "Looks like `%s' is already running.\n", "gnunet-service-arm"); |
369 | "gnunet-service-arm"); | ||
370 | #endif | 368 | #endif |
371 | /* arm is running! */ | 369 | /* arm is running! */ |
372 | if (pos->callback != NULL) | 370 | if (pos->callback != NULL) |
373 | pos->callback (pos->cls, GNUNET_YES); | 371 | pos->callback (pos->cls, GNUNET_YES); |
374 | GNUNET_free (pos); | 372 | GNUNET_free (pos); |
375 | return; | 373 | return; |
376 | } | 374 | } |
377 | #if DEBUG_ARM | 375 | #if DEBUG_ARM |
378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 376 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
379 | "Looks like `%s' is not running, will start it.\n", | 377 | "Looks like `%s' is not running, will start it.\n", |
380 | "gnunet-service-arm"); | 378 | "gnunet-service-arm"); |
381 | #endif | 379 | #endif |
382 | if (GNUNET_OK != | 380 | if (GNUNET_OK != |
383 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, | 381 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, |
384 | "arm", "PREFIX", &loprefix)) | 382 | "arm", "PREFIX", &loprefix)) |
385 | loprefix = GNUNET_strdup (""); | 383 | loprefix = GNUNET_strdup (""); |
386 | if (GNUNET_OK != | 384 | if (GNUNET_OK != |
387 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, | 385 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, |
388 | "arm", "OPTIONS", &lopostfix)) | 386 | "arm", "OPTIONS", &lopostfix)) |
389 | lopostfix = GNUNET_strdup (""); | 387 | lopostfix = GNUNET_strdup (""); |
390 | if (GNUNET_OK != | 388 | if (GNUNET_OK != |
391 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, | 389 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, |
392 | "arm", | 390 | "arm", "BINARY", &binary)) |
393 | "BINARY", | 391 | { |
394 | &binary)) | 392 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
395 | { | 393 | _ |
396 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 394 | ("Configuration failes to specify option `%s' in section `%s'!\n"), |
397 | _("Configuration failes to specify option `%s' in section `%s'!\n"), | 395 | "BINARY", "arm"); |
398 | "BINARY", | 396 | if (pos->callback != NULL) |
399 | "arm"); | 397 | pos->callback (pos->cls, GNUNET_SYSERR); |
400 | if (pos->callback != NULL) | 398 | GNUNET_free (pos); |
401 | pos->callback (pos->cls, GNUNET_SYSERR); | 399 | GNUNET_free (loprefix); |
402 | GNUNET_free (pos); | 400 | GNUNET_free (lopostfix); |
403 | GNUNET_free (loprefix); | 401 | return; |
404 | GNUNET_free (lopostfix); | 402 | } |
405 | return; | ||
406 | } | ||
407 | if (GNUNET_OK != | 403 | if (GNUNET_OK != |
408 | GNUNET_CONFIGURATION_get_value_filename (pos->h->cfg, | 404 | GNUNET_CONFIGURATION_get_value_filename (pos->h->cfg, |
409 | "arm", "CONFIG", &config)) | 405 | "arm", "CONFIG", &config)) |
410 | { | 406 | { |
411 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 407 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
412 | _("Configuration fails to specify option `%s' in section `%s'!\n"), | 408 | _ |
413 | "CONFIG", | 409 | ("Configuration fails to specify option `%s' in section `%s'!\n"), |
414 | "arm"); | 410 | "CONFIG", "arm"); |
415 | if (pos->callback != NULL) | 411 | if (pos->callback != NULL) |
416 | pos->callback (pos->cls, GNUNET_SYSERR); | 412 | pos->callback (pos->cls, GNUNET_SYSERR); |
417 | GNUNET_free (binary); | 413 | GNUNET_free (binary); |
418 | GNUNET_free (pos); | 414 | GNUNET_free (pos); |
419 | GNUNET_free (loprefix); | 415 | GNUNET_free (loprefix); |
420 | GNUNET_free (lopostfix); | 416 | GNUNET_free (lopostfix); |
421 | return; | 417 | return; |
422 | } | 418 | } |
423 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (pos->h->cfg, | 419 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (pos->h->cfg, "TESTING", "WEAKRANDOM")) && (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pos->h->cfg, "TESTING", "WEAKRANDOM")) && (GNUNET_NO == GNUNET_CONFIGURATION_have_value (pos->h->cfg, "TESTING", "HOSTFILE")) /* Means we are ONLY running locally */ |
424 | "TESTING", | 420 | ) |
425 | "WEAKRANDOM")) && | 421 | { |
426 | (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pos->h->cfg, | 422 | /* we're clearly running a test, don't daemonize */ |
427 | "TESTING", | 423 | proc = do_start_process (NULL, loprefix, binary, "-c", config, |
428 | "WEAKRANDOM")) && | ||
429 | (GNUNET_NO == GNUNET_CONFIGURATION_have_value (pos->h->cfg, | ||
430 | "TESTING", | ||
431 | "HOSTFILE")) /* Means we are ONLY running locally */ | ||
432 | ) | ||
433 | { | ||
434 | /* we're clearly running a test, don't daemonize */ | ||
435 | proc = do_start_process (NULL, | ||
436 | loprefix, | ||
437 | binary, | ||
438 | "-c", config, | ||
439 | #if DEBUG_ARM | 424 | #if DEBUG_ARM |
440 | "-L", "DEBUG", | 425 | "-L", "DEBUG", |
441 | #endif | 426 | #endif |
442 | /* no daemonization! */ | 427 | /* no daemonization! */ |
443 | lopostfix, | 428 | lopostfix, NULL); |
444 | NULL); | 429 | } |
445 | } | ||
446 | else | 430 | else |
447 | { | 431 | { |
448 | proc = do_start_process (NULL, | 432 | proc = do_start_process (NULL, loprefix, binary, "-c", config, |
449 | loprefix, | ||
450 | binary, | ||
451 | "-c", config, | ||
452 | #if DEBUG_ARM | 433 | #if DEBUG_ARM |
453 | "-L", "DEBUG", | 434 | "-L", "DEBUG", |
454 | #endif | 435 | #endif |
455 | "-d", | 436 | "-d", lopostfix, NULL); |
456 | lopostfix, | 437 | } |
457 | NULL); | ||
458 | } | ||
459 | GNUNET_free (binary); | 438 | GNUNET_free (binary); |
460 | GNUNET_free (config); | 439 | GNUNET_free (config); |
461 | GNUNET_free (loprefix); | 440 | GNUNET_free (loprefix); |
462 | GNUNET_free (lopostfix); | 441 | GNUNET_free (lopostfix); |
463 | if (proc == NULL) | 442 | if (proc == NULL) |
464 | { | 443 | { |
465 | if (pos->callback != NULL) | 444 | if (pos->callback != NULL) |
466 | pos->callback (pos->cls, GNUNET_SYSERR); | 445 | pos->callback (pos->cls, GNUNET_SYSERR); |
467 | GNUNET_free (pos); | 446 | GNUNET_free (pos); |
468 | return; | 447 | return; |
469 | } | 448 | } |
470 | if (pos->callback != NULL) | 449 | if (pos->callback != NULL) |
471 | pos->callback (pos->cls, GNUNET_YES); | 450 | pos->callback (pos->cls, GNUNET_YES); |
472 | GNUNET_free (proc); | 451 | GNUNET_free (proc); |
@@ -488,44 +467,41 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg) | |||
488 | int ret; | 467 | int ret; |
489 | 468 | ||
490 | if (msg == NULL) | 469 | if (msg == NULL) |
491 | { | 470 | { |
492 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 471 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
493 | _("Error receiving response to `%s' request from ARM for service `%s'\n"), | 472 | _ |
494 | (sc->type == GNUNET_MESSAGE_TYPE_ARM_START) | 473 | ("Error receiving response to `%s' request from ARM for service `%s'\n"), |
495 | ? "START" | 474 | (sc->type == GNUNET_MESSAGE_TYPE_ARM_START) ? "START" : "STOP", |
496 | : "STOP", | 475 | (const char *) &sc[1]); |
497 | (const char*) &sc[1]); | 476 | GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO); |
498 | GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO); | 477 | sc->h->client = GNUNET_CLIENT_connect ("arm", sc->h->cfg); |
499 | sc->h->client = GNUNET_CLIENT_connect ("arm", | 478 | GNUNET_assert (NULL != sc->h->client); |
500 | sc->h->cfg); | 479 | GNUNET_CLIENT_ignore_shutdown (sc->h->client, GNUNET_YES); |
501 | GNUNET_assert (NULL != sc->h->client); | 480 | if (sc->callback != NULL) |
502 | GNUNET_CLIENT_ignore_shutdown (sc->h->client, GNUNET_YES); | 481 | sc->callback (sc->cls, GNUNET_SYSERR); |
503 | if (sc->callback != NULL) | 482 | GNUNET_free (sc); |
504 | sc->callback (sc->cls, GNUNET_SYSERR); | 483 | return; |
505 | GNUNET_free (sc); | 484 | } |
506 | return; | ||
507 | } | ||
508 | #if DEBUG_ARM | 485 | #if DEBUG_ARM |
509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 486 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
510 | "Received response from ARM for service `%s': %u\n", | 487 | "Received response from ARM for service `%s': %u\n", |
511 | (const char*) &sc[1], | 488 | (const char *) &sc[1], ntohs (msg->type)); |
512 | ntohs(msg->type)); | ||
513 | #endif | 489 | #endif |
514 | switch (ntohs (msg->type)) | 490 | switch (ntohs (msg->type)) |
515 | { | 491 | { |
516 | case GNUNET_MESSAGE_TYPE_ARM_IS_UP: | 492 | case GNUNET_MESSAGE_TYPE_ARM_IS_UP: |
517 | ret = GNUNET_YES; | 493 | ret = GNUNET_YES; |
518 | break; | 494 | break; |
519 | case GNUNET_MESSAGE_TYPE_ARM_IS_DOWN: | 495 | case GNUNET_MESSAGE_TYPE_ARM_IS_DOWN: |
520 | ret = GNUNET_NO; | 496 | ret = GNUNET_NO; |
521 | break; | 497 | break; |
522 | case GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN: | 498 | case GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN: |
523 | ret = GNUNET_SYSERR; | 499 | ret = GNUNET_SYSERR; |
524 | break; | 500 | break; |
525 | default: | 501 | default: |
526 | GNUNET_break (0); | 502 | GNUNET_break (0); |
527 | ret = GNUNET_SYSERR; | 503 | ret = GNUNET_SYSERR; |
528 | } | 504 | } |
529 | if (sc->callback != NULL) | 505 | if (sc->callback != NULL) |
530 | sc->callback (sc->cls, ret); | 506 | sc->callback (sc->cls, ret); |
531 | GNUNET_free (sc); | 507 | GNUNET_free (sc); |
@@ -544,7 +520,7 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg) | |||
544 | */ | 520 | */ |
545 | static void | 521 | static void |
546 | change_service (struct GNUNET_ARM_Handle *h, | 522 | change_service (struct GNUNET_ARM_Handle *h, |
547 | const char *service_name, | 523 | const char *service_name, |
548 | struct GNUNET_TIME_Relative timeout, | 524 | struct GNUNET_TIME_Relative timeout, |
549 | GNUNET_ARM_Callback cb, void *cb_cls, uint16_t type) | 525 | GNUNET_ARM_Callback cb, void *cb_cls, uint16_t type) |
550 | { | 526 | { |
@@ -553,19 +529,19 @@ change_service (struct GNUNET_ARM_Handle *h, | |||
553 | struct GNUNET_MessageHeader *msg; | 529 | struct GNUNET_MessageHeader *msg; |
554 | 530 | ||
555 | slen = strlen (service_name) + 1; | 531 | slen = strlen (service_name) + 1; |
556 | if (slen + sizeof (struct GNUNET_MessageHeader) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 532 | if (slen + sizeof (struct GNUNET_MessageHeader) >= |
557 | { | 533 | GNUNET_SERVER_MAX_MESSAGE_SIZE) |
558 | GNUNET_break (0); | 534 | { |
559 | if (cb != NULL) | 535 | GNUNET_break (0); |
560 | cb (cb_cls, GNUNET_NO); | 536 | if (cb != NULL) |
561 | return; | 537 | cb (cb_cls, GNUNET_NO); |
562 | } | 538 | return; |
539 | } | ||
563 | #if DEBUG_ARM | 540 | #if DEBUG_ARM |
564 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 541 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
565 | (type == GNUNET_MESSAGE_TYPE_ARM_START) | 542 | (type == GNUNET_MESSAGE_TYPE_ARM_START) |
566 | ? _("Requesting start of service `%s'.\n") | 543 | ? _("Requesting start of service `%s'.\n") |
567 | : _("Requesting termination of service `%s'.\n"), | 544 | : _("Requesting termination of service `%s'.\n"), service_name); |
568 | service_name); | ||
569 | #endif | 545 | #endif |
570 | sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen); | 546 | sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen); |
571 | sctx->h = h; | 547 | sctx->h = h; |
@@ -580,23 +556,26 @@ change_service (struct GNUNET_ARM_Handle *h, | |||
580 | memcpy (&msg[1], service_name, slen); | 556 | memcpy (&msg[1], service_name, slen); |
581 | if (GNUNET_OK != | 557 | if (GNUNET_OK != |
582 | GNUNET_CLIENT_transmit_and_get_response (sctx->h->client, | 558 | GNUNET_CLIENT_transmit_and_get_response (sctx->h->client, |
583 | msg, | 559 | msg, |
584 | GNUNET_TIME_absolute_get_remaining (sctx->timeout), | 560 | GNUNET_TIME_absolute_get_remaining |
585 | GNUNET_YES, | 561 | (sctx->timeout), GNUNET_YES, |
586 | &handle_response, | 562 | &handle_response, sctx)) |
587 | sctx)) | 563 | { |
588 | { | 564 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
589 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 565 | (type == GNUNET_MESSAGE_TYPE_ARM_START) |
590 | (type == GNUNET_MESSAGE_TYPE_ARM_START) | 566 | ? |
591 | ? _("Error while trying to transmit request to start `%s' to ARM\n") | 567 | _ |
592 | : _("Error while trying to transmit request to stop `%s' to ARM\n"), | 568 | ("Error while trying to transmit request to start `%s' to ARM\n") |
593 | (const char*) &service_name); | 569 | : |
594 | if (cb != NULL) | 570 | _ |
595 | cb (cb_cls, GNUNET_SYSERR); | 571 | ("Error while trying to transmit request to stop `%s' to ARM\n"), |
596 | GNUNET_free (sctx); | 572 | (const char *) &service_name); |
597 | GNUNET_free (msg); | 573 | if (cb != NULL) |
598 | return; | 574 | cb (cb_cls, GNUNET_SYSERR); |
599 | } | 575 | GNUNET_free (sctx); |
576 | GNUNET_free (msg); | ||
577 | return; | ||
578 | } | ||
600 | GNUNET_free (msg); | 579 | GNUNET_free (msg); |
601 | } | 580 | } |
602 | 581 | ||
@@ -612,7 +591,7 @@ change_service (struct GNUNET_ARM_Handle *h, | |||
612 | */ | 591 | */ |
613 | void | 592 | void |
614 | GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, | 593 | GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, |
615 | const char *service_name, | 594 | const char *service_name, |
616 | struct GNUNET_TIME_Relative timeout, | 595 | struct GNUNET_TIME_Relative timeout, |
617 | GNUNET_ARM_Callback cb, void *cb_cls) | 596 | GNUNET_ARM_Callback cb, void *cb_cls) |
618 | { | 597 | { |
@@ -623,39 +602,42 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, | |||
623 | #if DEBUG_ARM | 602 | #if DEBUG_ARM |
624 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 603 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
625 | _("Asked to start service `%s' within %llu ms\n"), service_name, | 604 | _("Asked to start service `%s' within %llu ms\n"), service_name, |
626 | (unsigned long long) timeout.rel_value); | 605 | (unsigned long long) timeout.rel_value); |
627 | #endif | 606 | #endif |
628 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 607 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
629 | _("Asked to start service `%s' within %llu ms\n"), service_name, | 608 | _("Asked to start service `%s' within %llu ms\n"), service_name, |
630 | (unsigned long long) timeout.rel_value); | 609 | (unsigned long long) timeout.rel_value); |
631 | if (0 == strcasecmp ("arm", service_name)) | 610 | if (0 == strcasecmp ("arm", service_name)) |
632 | { | 611 | { |
633 | slen = strlen ("arm") + 1; | 612 | slen = strlen ("arm") + 1; |
634 | sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen); | 613 | sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen); |
635 | sctx->h = h; | 614 | sctx->h = h; |
636 | sctx->callback = cb; | 615 | sctx->callback = cb; |
637 | sctx->cls = cb_cls; | 616 | sctx->cls = cb_cls; |
638 | sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 617 | sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
639 | memcpy (&sctx[1], service_name, slen); | 618 | memcpy (&sctx[1], service_name, slen); |
640 | GNUNET_CLIENT_service_test ("arm", | 619 | GNUNET_CLIENT_service_test ("arm", |
641 | h->cfg, timeout, &arm_service_report, sctx); | 620 | h->cfg, timeout, &arm_service_report, sctx); |
642 | return; | 621 | return; |
643 | } | 622 | } |
644 | if (h->client == NULL) | 623 | if (h->client == NULL) |
624 | { | ||
625 | client = GNUNET_CLIENT_connect ("arm", h->cfg); | ||
626 | if (client == NULL) | ||
645 | { | 627 | { |
646 | client = GNUNET_CLIENT_connect ("arm", h->cfg); | 628 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
647 | if (client == NULL) | 629 | "arm_api, GNUNET_CLIENT_connect returned NULL\n"); |
648 | { | 630 | cb (cb_cls, GNUNET_SYSERR); |
649 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "arm_api, GNUNET_CLIENT_connect returned NULL\n"); | 631 | return; |
650 | cb (cb_cls, GNUNET_SYSERR); | ||
651 | return; | ||
652 | } | ||
653 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "arm_api, GNUNET_CLIENT_connect returned non-NULL\n"); | ||
654 | GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES); | ||
655 | h->client = client; | ||
656 | } | 632 | } |
657 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "arm_api, h->client non-NULL\n"); | 633 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
658 | change_service (h, service_name, timeout, cb, cb_cls, GNUNET_MESSAGE_TYPE_ARM_START); | 634 | "arm_api, GNUNET_CLIENT_connect returned non-NULL\n"); |
635 | GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES); | ||
636 | h->client = client; | ||
637 | } | ||
638 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "arm_api, h->client non-NULL\n"); | ||
639 | change_service (h, service_name, timeout, cb, cb_cls, | ||
640 | GNUNET_MESSAGE_TYPE_ARM_START); | ||
659 | } | 641 | } |
660 | 642 | ||
661 | /** | 643 | /** |
@@ -666,15 +648,15 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, | |||
666 | * @param reason reason for callback, GNUNET_NO if arm is shutdown | 648 | * @param reason reason for callback, GNUNET_NO if arm is shutdown |
667 | * GNUNET_YES if arm remains running, and GNUNET_SYSERR on error | 649 | * GNUNET_YES if arm remains running, and GNUNET_SYSERR on error |
668 | */ | 650 | */ |
669 | void arm_shutdown_callback (void *cls, | 651 | void |
670 | int reason) | 652 | arm_shutdown_callback (void *cls, int reason) |
671 | { | 653 | { |
672 | struct ARM_ShutdownContext *arm_shutdown_ctx = cls; | 654 | struct ARM_ShutdownContext *arm_shutdown_ctx = cls; |
673 | 655 | ||
674 | if (arm_shutdown_ctx->cb != NULL) | 656 | if (arm_shutdown_ctx->cb != NULL) |
675 | arm_shutdown_ctx->cb (arm_shutdown_ctx->cb_cls, reason); | 657 | arm_shutdown_ctx->cb (arm_shutdown_ctx->cb_cls, reason); |
676 | 658 | ||
677 | GNUNET_free(arm_shutdown_ctx); | 659 | GNUNET_free (arm_shutdown_ctx); |
678 | } | 660 | } |
679 | 661 | ||
680 | 662 | ||
@@ -698,28 +680,30 @@ GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h, | |||
698 | 680 | ||
699 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 681 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
700 | _("Stopping service `%s' within %llu ms\n"), service_name, | 682 | _("Stopping service `%s' within %llu ms\n"), service_name, |
701 | (unsigned long long) timeout.rel_value); | 683 | (unsigned long long) timeout.rel_value); |
702 | if (h->client == NULL) | 684 | if (h->client == NULL) |
685 | { | ||
686 | client = GNUNET_CLIENT_connect ("arm", h->cfg); | ||
687 | if (client == NULL) | ||
703 | { | 688 | { |
704 | client = GNUNET_CLIENT_connect ("arm", h->cfg); | 689 | cb (cb_cls, GNUNET_SYSERR); |
705 | if (client == NULL) | ||
706 | { | ||
707 | cb (cb_cls, GNUNET_SYSERR); | ||
708 | return; | ||
709 | } | ||
710 | GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES); | ||
711 | h->client = client; | ||
712 | } | ||
713 | if (0 == strcasecmp ("arm", service_name)) | ||
714 | { | ||
715 | arm_shutdown_ctx = GNUNET_malloc(sizeof(struct ARM_ShutdownContext)); | ||
716 | arm_shutdown_ctx->cb = cb; | ||
717 | arm_shutdown_ctx->cb_cls = cb_cls; | ||
718 | arm_service_shutdown (h->client, timeout, &arm_shutdown_callback, arm_shutdown_ctx); | ||
719 | h->client = NULL; | ||
720 | return; | 690 | return; |
721 | } | 691 | } |
722 | change_service (h, service_name, timeout, cb, cb_cls, GNUNET_MESSAGE_TYPE_ARM_STOP); | 692 | GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES); |
693 | h->client = client; | ||
694 | } | ||
695 | if (0 == strcasecmp ("arm", service_name)) | ||
696 | { | ||
697 | arm_shutdown_ctx = GNUNET_malloc (sizeof (struct ARM_ShutdownContext)); | ||
698 | arm_shutdown_ctx->cb = cb; | ||
699 | arm_shutdown_ctx->cb_cls = cb_cls; | ||
700 | arm_service_shutdown (h->client, timeout, &arm_shutdown_callback, | ||
701 | arm_shutdown_ctx); | ||
702 | h->client = NULL; | ||
703 | return; | ||
704 | } | ||
705 | change_service (h, service_name, timeout, cb, cb_cls, | ||
706 | GNUNET_MESSAGE_TYPE_ARM_STOP); | ||
723 | } | 707 | } |
724 | 708 | ||
725 | 709 | ||