aboutsummaryrefslogtreecommitdiff
path: root/src/arm
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-06-19 21:22:43 +0200
committerChristian Grothoff <christian@grothoff.org>2019-06-19 21:22:43 +0200
commit9baf882d7642f8aeac734ffd16c8e94bd409a41b (patch)
tree27884f88a164e065e599da385fc38a034f65c65c /src/arm
parent33e87eb7680148006b7c9fc8f89040ad104597ea (diff)
downloadgnunet-9baf882d7642f8aeac734ffd16c8e94bd409a41b.tar.gz
gnunet-9baf882d7642f8aeac734ffd16c8e94bd409a41b.zip
fix socket cmp, fix compiler warnings about unused args
Diffstat (limited to 'src/arm')
-rw-r--r--src/arm/arm_api.c287
-rw-r--r--src/arm/arm_monitor_api.c55
-rw-r--r--src/arm/mockup-service.c49
3 files changed, 154 insertions, 237 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index c8103c877..bf0acbcb9 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -30,7 +30,7 @@
30#include "gnunet_protocols.h" 30#include "gnunet_protocols.h"
31#include "arm.h" 31#include "arm.h"
32 32
33#define LOG(kind,...) GNUNET_log_from (kind, "arm-api",__VA_ARGS__) 33#define LOG(kind, ...) GNUNET_log_from (kind, "arm-api", __VA_ARGS__)
34 34
35 35
36/** 36/**
@@ -156,7 +156,6 @@ struct GNUNET_ARM_Handle
156 * Have we detected that ARM is up? 156 * Have we detected that ARM is up?
157 */ 157 */
158 int currently_up; 158 int currently_up;
159
160}; 159};
161 160
162 161
@@ -204,27 +203,19 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h)
204 h->currently_up = GNUNET_NO; 203 h->currently_up = GNUNET_NO;
205 GNUNET_assert (NULL == h->reconnect_task); 204 GNUNET_assert (NULL == h->reconnect_task);
206 h->reconnect_task = 205 h->reconnect_task =
207 GNUNET_SCHEDULER_add_delayed (h->retry_backoff, 206 GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_task, h);
208 &reconnect_arm_task,
209 h);
210 while (NULL != (op = h->operation_pending_head)) 207 while (NULL != (op = h->operation_pending_head))
211 { 208 {
212 if (NULL != op->result_cont) 209 if (NULL != op->result_cont)
213 op->result_cont (op->cont_cls, 210 op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0);
214 GNUNET_ARM_REQUEST_DISCONNECTED,
215 0);
216 if (NULL != op->list_cont) 211 if (NULL != op->list_cont)
217 op->list_cont (op->cont_cls, 212 op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL);
218 GNUNET_ARM_REQUEST_DISCONNECTED,
219 0,
220 NULL);
221 GNUNET_ARM_operation_cancel (op); 213 GNUNET_ARM_operation_cancel (op);
222 } 214 }
223 GNUNET_assert (NULL == h->operation_pending_head); 215 GNUNET_assert (NULL == h->operation_pending_head);
224 h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); 216 h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff);
225 if (NULL != h->conn_status) 217 if (NULL != h->conn_status)
226 h->conn_status (h->conn_status_cls, 218 h->conn_status (h->conn_status_cls, GNUNET_NO);
227 GNUNET_NO);
228} 219}
229 220
230 221
@@ -236,12 +227,12 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h)
236 * @return NULL if not found 227 * @return NULL if not found
237 */ 228 */
238static struct GNUNET_ARM_Operation * 229static struct GNUNET_ARM_Operation *
239find_op_by_id (struct GNUNET_ARM_Handle *h, 230find_op_by_id (struct GNUNET_ARM_Handle *h, uint64_t id)
240 uint64_t id)
241{ 231{
242 struct GNUNET_ARM_Operation *result; 232 struct GNUNET_ARM_Operation *result;
243 233
244 for (result = h->operation_pending_head; NULL != result; result = result->next) 234 for (result = h->operation_pending_head; NULL != result;
235 result = result->next)
245 if (id == result->id) 236 if (id == result->id)
246 return result; 237 return result;
247 return NULL; 238 return NULL;
@@ -255,8 +246,7 @@ find_op_by_id (struct GNUNET_ARM_Handle *h,
255 * @param res the message received from the arm service 246 * @param res the message received from the arm service
256 */ 247 */
257static void 248static void
258handle_arm_result (void *cls, 249handle_arm_result (void *cls, const struct GNUNET_ARM_ResultMessage *res)
259 const struct GNUNET_ARM_ResultMessage *res)
260{ 250{
261 struct GNUNET_ARM_Handle *h = cls; 251 struct GNUNET_ARM_Handle *h = cls;
262 struct GNUNET_ARM_Operation *op; 252 struct GNUNET_ARM_Operation *op;
@@ -266,8 +256,7 @@ handle_arm_result (void *cls,
266 void *result_cont_cls; 256 void *result_cont_cls;
267 257
268 id = GNUNET_ntohll (res->arm_msg.request_id); 258 id = GNUNET_ntohll (res->arm_msg.request_id);
269 op = find_op_by_id (h, 259 op = find_op_by_id (h, id);
270 id);
271 if (NULL == op) 260 if (NULL == op)
272 { 261 {
273 LOG (GNUNET_ERROR_TYPE_DEBUG, 262 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -277,8 +266,7 @@ handle_arm_result (void *cls,
277 } 266 }
278 267
279 result = (enum GNUNET_ARM_Result) ntohl (res->result); 268 result = (enum GNUNET_ARM_Result) ntohl (res->result);
280 if ( (GNUNET_YES == op->is_arm_stop) && 269 if ((GNUNET_YES == op->is_arm_stop) && (GNUNET_ARM_RESULT_STOPPING == result))
281 (GNUNET_ARM_RESULT_STOPPING == result) )
282 { 270 {
283 /* special case: if we are stopping 'gnunet-service-arm', we do not just 271 /* special case: if we are stopping 'gnunet-service-arm', we do not just
284 wait for the result message, but also wait for the service to close 272 wait for the result message, but also wait for the service to close
@@ -289,8 +277,8 @@ handle_arm_result (void *cls,
289 { 277 {
290 GNUNET_break (0); 278 GNUNET_break (0);
291 op->result_cont (h->thm->cont_cls, 279 op->result_cont (h->thm->cont_cls,
292 GNUNET_ARM_REQUEST_SENT_OK, 280 GNUNET_ARM_REQUEST_SENT_OK,
293 GNUNET_ARM_RESULT_IS_NOT_KNOWN); 281 GNUNET_ARM_RESULT_IS_NOT_KNOWN);
294 GNUNET_free (h->thm); 282 GNUNET_free (h->thm);
295 } 283 }
296 GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, 284 GNUNET_CONTAINER_DLL_remove (h->operation_pending_head,
@@ -303,9 +291,7 @@ handle_arm_result (void *cls,
303 result_cont_cls = op->cont_cls; 291 result_cont_cls = op->cont_cls;
304 GNUNET_ARM_operation_cancel (op); 292 GNUNET_ARM_operation_cancel (op);
305 if (NULL != result_cont) 293 if (NULL != result_cont)
306 result_cont (result_cont_cls, 294 result_cont (result_cont_cls, GNUNET_ARM_REQUEST_SENT_OK, result);
307 GNUNET_ARM_REQUEST_SENT_OK,
308 result);
309} 295}
310 296
311 297
@@ -325,6 +311,7 @@ check_arm_list_result (void *cls,
325 uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof (*lres); 311 uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof (*lres);
326 uint16_t size_check; 312 uint16_t size_check;
327 313
314 (void) cls;
328 size_check = 0; 315 size_check = 0;
329 for (unsigned int i = 0; i < rcount; i++) 316 for (unsigned int i = 0; i < rcount; i++)
330 { 317 {
@@ -361,8 +348,7 @@ handle_arm_list_result (void *cls,
361 uint64_t id; 348 uint64_t id;
362 349
363 id = GNUNET_ntohll (lres->arm_msg.request_id); 350 id = GNUNET_ntohll (lres->arm_msg.request_id);
364 op = find_op_by_id (h, 351 op = find_op_by_id (h, id);
365 id);
366 if (NULL == op) 352 if (NULL == op)
367 { 353 {
368 LOG (GNUNET_ERROR_TYPE_DEBUG, 354 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -373,9 +359,7 @@ handle_arm_list_result (void *cls,
373 size_check = 0; 359 size_check = 0;
374 for (unsigned int i = 0; i < rcount; i++) 360 for (unsigned int i = 0; i < rcount; i++)
375 { 361 {
376 const char *end = memchr (pos, 362 const char *end = memchr (pos, 0, msize - size_check);
377 0,
378 msize - size_check);
379 363
380 /* Assert, as this was already checked in #check_arm_list_result() */ 364 /* Assert, as this was already checked in #check_arm_list_result() */
381 GNUNET_assert (NULL != end); 365 GNUNET_assert (NULL != end);
@@ -384,10 +368,7 @@ handle_arm_list_result (void *cls,
384 pos = end + 1; 368 pos = end + 1;
385 } 369 }
386 if (NULL != op->list_cont) 370 if (NULL != op->list_cont)
387 op->list_cont (op->cont_cls, 371 op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, rcount, list);
388 GNUNET_ARM_REQUEST_SENT_OK,
389 rcount,
390 list);
391 GNUNET_ARM_operation_cancel (op); 372 GNUNET_ARM_operation_cancel (op);
392} 373}
393 374
@@ -399,19 +380,17 @@ handle_arm_list_result (void *cls,
399 * @param msg message received 380 * @param msg message received
400 */ 381 */
401static void 382static void
402handle_confirm (void *cls, 383handle_confirm (void *cls, const struct GNUNET_MessageHeader *msg)
403 const struct GNUNET_MessageHeader *msg)
404{ 384{
405 struct GNUNET_ARM_Handle *h = cls; 385 struct GNUNET_ARM_Handle *h = cls;
406 386
407 LOG (GNUNET_ERROR_TYPE_DEBUG, 387 (void) msg;
408 "Got confirmation from ARM that we are up!\n"); 388 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got confirmation from ARM that we are up!\n");
409 if (GNUNET_NO == h->currently_up) 389 if (GNUNET_NO == h->currently_up)
410 { 390 {
411 h->currently_up = GNUNET_YES; 391 h->currently_up = GNUNET_YES;
412 if (NULL != h->conn_status) 392 if (NULL != h->conn_status)
413 h->conn_status (h->conn_status_cls, 393 h->conn_status (h->conn_status_cls, GNUNET_YES);
414 GNUNET_YES);
415 } 394 }
416} 395}
417 396
@@ -425,19 +404,19 @@ handle_confirm (void *cls,
425 * @param error error code 404 * @param error error code
426 */ 405 */
427static void 406static void
428mq_error_handler (void *cls, 407mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
429 enum GNUNET_MQ_Error error)
430{ 408{
431 struct GNUNET_ARM_Handle *h = cls; 409 struct GNUNET_ARM_Handle *h = cls;
432 struct GNUNET_ARM_Operation *op; 410 struct GNUNET_ARM_Operation *op;
433 411
412 (void) error;
434 h->currently_up = GNUNET_NO; 413 h->currently_up = GNUNET_NO;
435 if (NULL != (op = h->thm)) 414 if (NULL != (op = h->thm))
436 { 415 {
437 h->thm = NULL; 416 h->thm = NULL;
438 op->result_cont (op->cont_cls, 417 op->result_cont (op->cont_cls,
439 GNUNET_ARM_REQUEST_SENT_OK, 418 GNUNET_ARM_REQUEST_SENT_OK,
440 GNUNET_ARM_RESULT_STOPPED); 419 GNUNET_ARM_RESULT_STOPPED);
441 GNUNET_free (op); 420 GNUNET_free (op);
442 } 421 }
443 reconnect_arm_later (h); 422 reconnect_arm_later (h);
@@ -453,47 +432,37 @@ mq_error_handler (void *cls,
453static int 432static int
454reconnect_arm (struct GNUNET_ARM_Handle *h) 433reconnect_arm (struct GNUNET_ARM_Handle *h)
455{ 434{
456 struct GNUNET_MQ_MessageHandler handlers[] = { 435 struct GNUNET_MQ_MessageHandler handlers[] =
457 GNUNET_MQ_hd_fixed_size (arm_result, 436 {GNUNET_MQ_hd_fixed_size (arm_result,
458 GNUNET_MESSAGE_TYPE_ARM_RESULT, 437 GNUNET_MESSAGE_TYPE_ARM_RESULT,
459 struct GNUNET_ARM_ResultMessage, 438 struct GNUNET_ARM_ResultMessage,
460 h), 439 h),
461 GNUNET_MQ_hd_var_size (arm_list_result, 440 GNUNET_MQ_hd_var_size (arm_list_result,
462 GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, 441 GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT,
463 struct GNUNET_ARM_ListResultMessage, 442 struct GNUNET_ARM_ListResultMessage,
464 h), 443 h),
465 GNUNET_MQ_hd_fixed_size (confirm, 444 GNUNET_MQ_hd_fixed_size (confirm,
466 GNUNET_MESSAGE_TYPE_ARM_TEST, 445 GNUNET_MESSAGE_TYPE_ARM_TEST,
467 struct GNUNET_MessageHeader, 446 struct GNUNET_MessageHeader,
468 h), 447 h),
469 GNUNET_MQ_handler_end () 448 GNUNET_MQ_handler_end ()};
470 };
471 struct GNUNET_MessageHeader *test; 449 struct GNUNET_MessageHeader *test;
472 struct GNUNET_MQ_Envelope *env; 450 struct GNUNET_MQ_Envelope *env;
473 451
474 if (NULL != h->mq) 452 if (NULL != h->mq)
475 return GNUNET_OK; 453 return GNUNET_OK;
476 GNUNET_assert (GNUNET_NO == h->currently_up); 454 GNUNET_assert (GNUNET_NO == h->currently_up);
477 h->mq = GNUNET_CLIENT_connect (h->cfg, 455 h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h);
478 "arm",
479 handlers,
480 &mq_error_handler,
481 h);
482 if (NULL == h->mq) 456 if (NULL == h->mq)
483 { 457 {
484 LOG (GNUNET_ERROR_TYPE_DEBUG, 458 LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CLIENT_connect returned NULL\n");
485 "GNUNET_CLIENT_connect returned NULL\n");
486 if (NULL != h->conn_status) 459 if (NULL != h->conn_status)
487 h->conn_status (h->conn_status_cls, 460 h->conn_status (h->conn_status_cls, GNUNET_SYSERR);
488 GNUNET_SYSERR);
489 return GNUNET_SYSERR; 461 return GNUNET_SYSERR;
490 } 462 }
491 LOG (GNUNET_ERROR_TYPE_DEBUG, 463 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending TEST message to ARM\n");
492 "Sending TEST message to ARM\n"); 464 env = GNUNET_MQ_msg (test, GNUNET_MESSAGE_TYPE_ARM_TEST);
493 env = GNUNET_MQ_msg (test, 465 GNUNET_MQ_send (h->mq, env);
494 GNUNET_MESSAGE_TYPE_ARM_TEST);
495 GNUNET_MQ_send (h->mq,
496 env);
497 return GNUNET_OK; 466 return GNUNET_OK;
498} 467}
499 468
@@ -512,7 +481,7 @@ reconnect_arm (struct GNUNET_ARM_Handle *h)
512struct GNUNET_ARM_Handle * 481struct GNUNET_ARM_Handle *
513GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 482GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
514 GNUNET_ARM_ConnectionStatusCallback conn_status, 483 GNUNET_ARM_ConnectionStatusCallback conn_status,
515 void *conn_status_cls) 484 void *conn_status_cls)
516{ 485{
517 struct GNUNET_ARM_Handle *h; 486 struct GNUNET_ARM_Handle *h;
518 487
@@ -539,22 +508,16 @@ GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h)
539{ 508{
540 struct GNUNET_ARM_Operation *op; 509 struct GNUNET_ARM_Operation *op;
541 510
542 LOG (GNUNET_ERROR_TYPE_DEBUG, 511 LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n");
543 "Disconnecting from ARM service\n");
544 while (NULL != (op = h->operation_pending_head)) 512 while (NULL != (op = h->operation_pending_head))
545 { 513 {
546 GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, 514 GNUNET_CONTAINER_DLL_remove (h->operation_pending_head,
547 h->operation_pending_tail, 515 h->operation_pending_tail,
548 op); 516 op);
549 if (NULL != op->result_cont) 517 if (NULL != op->result_cont)
550 op->result_cont (op->cont_cls, 518 op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0);
551 GNUNET_ARM_REQUEST_DISCONNECTED,
552 0);
553 if (NULL != op->list_cont) 519 if (NULL != op->list_cont)
554 op->list_cont (op->cont_cls, 520 op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL);
555 GNUNET_ARM_REQUEST_DISCONNECTED,
556 0,
557 NULL);
558 if (NULL != op->async) 521 if (NULL != op->async)
559 { 522 {
560 GNUNET_SCHEDULER_cancel (op->async); 523 GNUNET_SCHEDULER_cancel (op->async);
@@ -596,60 +559,43 @@ start_arm_service (struct GNUNET_ARM_Handle *h,
596 char *loprefix; 559 char *loprefix;
597 char *lopostfix; 560 char *lopostfix;
598 561
599 if (GNUNET_OK != 562 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg,
600 GNUNET_CONFIGURATION_get_value_string (h->cfg, 563 "arm",
601 "arm", 564 "PREFIX",
602 "PREFIX", 565 &loprefix))
603 &loprefix))
604 loprefix = GNUNET_strdup (""); 566 loprefix = GNUNET_strdup ("");
605 else 567 else
606 loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, 568 loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, loprefix);
607 loprefix); 569 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg,
608 if (GNUNET_OK != 570 "arm",
609 GNUNET_CONFIGURATION_get_value_string (h->cfg, 571 "OPTIONS",
610 "arm", 572 &lopostfix))
611 "OPTIONS",
612 &lopostfix))
613 lopostfix = GNUNET_strdup (""); 573 lopostfix = GNUNET_strdup ("");
614 else 574 else
615 lopostfix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, 575 lopostfix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, lopostfix);
616 lopostfix);
617 if (GNUNET_OK != 576 if (GNUNET_OK !=
618 GNUNET_CONFIGURATION_get_value_string (h->cfg, 577 GNUNET_CONFIGURATION_get_value_string (h->cfg, "arm", "BINARY", &cbinary))
619 "arm",
620 "BINARY",
621 &cbinary))
622 { 578 {
623 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, 579 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, "arm", "BINARY");
624 "arm",
625 "BINARY");
626 GNUNET_free (loprefix); 580 GNUNET_free (loprefix);
627 GNUNET_free (lopostfix); 581 GNUNET_free (lopostfix);
628 return GNUNET_ARM_RESULT_IS_NOT_KNOWN; 582 return GNUNET_ARM_RESULT_IS_NOT_KNOWN;
629 } 583 }
630 if (GNUNET_OK != 584 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg,
631 GNUNET_CONFIGURATION_get_value_filename (h->cfg, 585 "arm",
632 "arm", 586 "CONFIG",
633 "CONFIG", 587 &config))
634 &config))
635 config = NULL; 588 config = NULL;
636 binary = GNUNET_OS_get_libexec_binary_path (cbinary); 589 binary = GNUNET_OS_get_libexec_binary_path (cbinary);
637 GNUNET_asprintf (&quotedbinary, 590 GNUNET_asprintf (&quotedbinary, "\"%s\"", binary);
638 "\"%s\"",
639 binary);
640 GNUNET_free (cbinary); 591 GNUNET_free (cbinary);
641 if ( (GNUNET_YES == 592 if ((GNUNET_YES ==
642 GNUNET_CONFIGURATION_have_value (h->cfg, 593 GNUNET_CONFIGURATION_have_value (h->cfg, "TESTING", "WEAKRANDOM")) &&
643 "TESTING", 594 (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (h->cfg,
644 "WEAKRANDOM")) && 595 "TESTING",
645 (GNUNET_YES == 596 "WEAKRANDOM")) &&
646 GNUNET_CONFIGURATION_get_value_yesno (h->cfg, 597 (GNUNET_NO ==
647 "TESTING", 598 GNUNET_CONFIGURATION_have_value (h->cfg, "TESTING", "HOSTFILE")))
648 "WEAKRANDOM")) &&
649 (GNUNET_NO ==
650 GNUNET_CONFIGURATION_have_value (h->cfg,
651 "TESTING",
652 "HOSTFILE")))
653 { 599 {
654 /* Means we are ONLY running locally */ 600 /* Means we are ONLY running locally */
655 /* we're clearly running a test, don't daemonize */ 601 /* we're clearly running a test, don't daemonize */
@@ -668,7 +614,8 @@ start_arm_service (struct GNUNET_ARM_Handle *h,
668 NULL, 614 NULL,
669 loprefix, 615 loprefix,
670 quotedbinary, 616 quotedbinary,
671 "-c", config, 617 "-c",
618 config,
672 /* no daemonization! */ 619 /* no daemonization! */
673 lopostfix, 620 lopostfix,
674 NULL); 621 NULL);
@@ -683,14 +630,15 @@ start_arm_service (struct GNUNET_ARM_Handle *h,
683 quotedbinary, 630 quotedbinary,
684 "-d", /* do daemonize */ 631 "-d", /* do daemonize */
685 lopostfix, 632 lopostfix,
686 NULL); 633 NULL);
687 else 634 else
688 proc = GNUNET_OS_start_process_s (GNUNET_NO, 635 proc = GNUNET_OS_start_process_s (GNUNET_NO,
689 std_inheritance, 636 std_inheritance,
690 NULL, 637 NULL,
691 loprefix, 638 loprefix,
692 quotedbinary, 639 quotedbinary,
693 "-c", config, 640 "-c",
641 config,
694 "-d", /* do daemonize */ 642 "-d", /* do daemonize */
695 lopostfix, 643 lopostfix,
696 NULL); 644 NULL);
@@ -744,7 +692,7 @@ static struct GNUNET_ARM_Operation *
744change_service (struct GNUNET_ARM_Handle *h, 692change_service (struct GNUNET_ARM_Handle *h,
745 const char *service_name, 693 const char *service_name,
746 GNUNET_ARM_ResultCallback cb, 694 GNUNET_ARM_ResultCallback cb,
747 void *cb_cls, 695 void *cb_cls,
748 uint16_t type) 696 uint16_t type)
749{ 697{
750 struct GNUNET_ARM_Operation *op; 698 struct GNUNET_ARM_Operation *op;
@@ -753,8 +701,7 @@ change_service (struct GNUNET_ARM_Handle *h,
753 struct GNUNET_ARM_Message *msg; 701 struct GNUNET_ARM_Message *msg;
754 702
755 slen = strlen (service_name) + 1; 703 slen = strlen (service_name) + 1;
756 if (slen + sizeof (struct GNUNET_ARM_Message) >= 704 if (slen + sizeof (struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE)
757 GNUNET_MAX_MESSAGE_SIZE)
758 { 705 {
759 GNUNET_break (0); 706 GNUNET_break (0);
760 return NULL; 707 return NULL;
@@ -769,16 +716,11 @@ change_service (struct GNUNET_ARM_Handle *h,
769 GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, 716 GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head,
770 h->operation_pending_tail, 717 h->operation_pending_tail,
771 op); 718 op);
772 env = GNUNET_MQ_msg_extra (msg, 719 env = GNUNET_MQ_msg_extra (msg, slen, type);
773 slen,
774 type);
775 msg->reserved = htonl (0); 720 msg->reserved = htonl (0);
776 msg->request_id = GNUNET_htonll (op->id); 721 msg->request_id = GNUNET_htonll (op->id);
777 GNUNET_memcpy (&msg[1], 722 GNUNET_memcpy (&msg[1], service_name, slen);
778 service_name, 723 GNUNET_MQ_send (h->mq, env);
779 slen);
780 GNUNET_MQ_send (h->mq,
781 env);
782 return op; 724 return op;
783} 725}
784 726
@@ -802,10 +744,8 @@ notify_running (void *cls)
802 op->result_cont (op->cont_cls, 744 op->result_cont (op->cont_cls,
803 GNUNET_ARM_REQUEST_SENT_OK, 745 GNUNET_ARM_REQUEST_SENT_OK,
804 GNUNET_ARM_RESULT_IS_STARTED_ALREADY); 746 GNUNET_ARM_RESULT_IS_STARTED_ALREADY);
805 if ( (GNUNET_YES == h->currently_up) && 747 if ((GNUNET_YES == h->currently_up) && (NULL != h->conn_status))
806 (NULL != h->conn_status) ) 748 h->conn_status (h->conn_status_cls, GNUNET_YES);
807 h->conn_status (h->conn_status_cls,
808 GNUNET_YES);
809 GNUNET_free (op); 749 GNUNET_free (op);
810} 750}
811 751
@@ -846,20 +786,18 @@ notify_starting (void *cls)
846 * @return handle for the operation, NULL on error 786 * @return handle for the operation, NULL on error
847 */ 787 */
848struct GNUNET_ARM_Operation * 788struct GNUNET_ARM_Operation *
849GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, 789GNUNET_ARM_request_service_start (
850 const char *service_name, 790 struct GNUNET_ARM_Handle *h,
851 enum GNUNET_OS_InheritStdioFlags std_inheritance, 791 const char *service_name,
852 GNUNET_ARM_ResultCallback cont, 792 enum GNUNET_OS_InheritStdioFlags std_inheritance,
853 void *cont_cls) 793 GNUNET_ARM_ResultCallback cont,
794 void *cont_cls)
854{ 795{
855 struct GNUNET_ARM_Operation *op; 796 struct GNUNET_ARM_Operation *op;
856 enum GNUNET_ARM_Result ret; 797 enum GNUNET_ARM_Result ret;
857 798
858 LOG (GNUNET_ERROR_TYPE_DEBUG, 799 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting service `%s'\n", service_name);
859 "Starting service `%s'\n", 800 if (0 != strcasecmp ("arm", service_name))
860 service_name);
861 if (0 != strcasecmp ("arm",
862 service_name))
863 return change_service (h, 801 return change_service (h,
864 service_name, 802 service_name,
865 cont, 803 cont,
@@ -874,8 +812,7 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
874 */ 812 */
875 if (GNUNET_YES == h->currently_up) 813 if (GNUNET_YES == h->currently_up)
876 { 814 {
877 LOG (GNUNET_ERROR_TYPE_DEBUG, 815 LOG (GNUNET_ERROR_TYPE_DEBUG, "ARM is already running\n");
878 "ARM is already running\n");
879 op = GNUNET_new (struct GNUNET_ARM_Operation); 816 op = GNUNET_new (struct GNUNET_ARM_Operation);
880 op->h = h; 817 op->h = h;
881 op->result_cont = cont; 818 op->result_cont = cont;
@@ -883,8 +820,7 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
883 GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, 820 GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head,
884 h->operation_pending_tail, 821 h->operation_pending_tail,
885 op); 822 op);
886 op->async = GNUNET_SCHEDULER_add_now (&notify_running, 823 op->async = GNUNET_SCHEDULER_add_now (&notify_running, op);
887 op);
888 return op; 824 return op;
889 } 825 }
890 /* This is an inherently uncertain choice, as it is of course 826 /* This is an inherently uncertain choice, as it is of course
@@ -893,10 +829,8 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
893 are unlikely to hammer 'gnunet-arm -s' on a busy system, 829 are unlikely to hammer 'gnunet-arm -s' on a busy system,
894 the above check should catch 99.99% of the cases where ARM 830 the above check should catch 99.99% of the cases where ARM
895 is already running. */ 831 is already running. */
896 LOG (GNUNET_ERROR_TYPE_DEBUG, 832 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting ARM service\n");
897 "Starting ARM service\n"); 833 ret = start_arm_service (h, std_inheritance);
898 ret = start_arm_service (h,
899 std_inheritance);
900 if (GNUNET_ARM_RESULT_STARTING == ret) 834 if (GNUNET_ARM_RESULT_STARTING == ret)
901 reconnect_arm (h); 835 reconnect_arm (h);
902 op = GNUNET_new (struct GNUNET_ARM_Operation); 836 op = GNUNET_new (struct GNUNET_ARM_Operation);
@@ -907,8 +841,7 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
907 h->operation_pending_tail, 841 h->operation_pending_tail,
908 op); 842 op);
909 op->starting_ret = ret; 843 op->starting_ret = ret;
910 op->async = GNUNET_SCHEDULER_add_now (&notify_starting, 844 op->async = GNUNET_SCHEDULER_add_now (&notify_starting, op);
911 op);
912 return op; 845 return op;
913} 846}
914 847
@@ -929,15 +862,13 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
929 */ 862 */
930struct GNUNET_ARM_Operation * 863struct GNUNET_ARM_Operation *
931GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, 864GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
932 const char *service_name, 865 const char *service_name,
933 GNUNET_ARM_ResultCallback cont, 866 GNUNET_ARM_ResultCallback cont,
934 void *cont_cls) 867 void *cont_cls)
935{ 868{
936 struct GNUNET_ARM_Operation *op; 869 struct GNUNET_ARM_Operation *op;
937 870
938 LOG (GNUNET_ERROR_TYPE_DEBUG, 871 LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping service `%s'\n", service_name);
939 "Stopping service `%s'\n",
940 service_name);
941 op = change_service (h, 872 op = change_service (h,
942 service_name, 873 service_name,
943 cont, 874 cont,
@@ -947,8 +878,7 @@ GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
947 return NULL; 878 return NULL;
948 /* If the service is ARM, set a flag as we will use MQ errors 879 /* If the service is ARM, set a flag as we will use MQ errors
949 to detect that the process is really gone. */ 880 to detect that the process is really gone. */
950 if (0 == strcasecmp (service_name, 881 if (0 == strcasecmp (service_name, "arm"))
951 "arm"))
952 op->is_arm_stop = GNUNET_YES; 882 op->is_arm_stop = GNUNET_YES;
953 return op; 883 return op;
954} 884}
@@ -971,8 +901,7 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
971 struct GNUNET_MQ_Envelope *env; 901 struct GNUNET_MQ_Envelope *env;
972 struct GNUNET_ARM_Message *msg; 902 struct GNUNET_ARM_Message *msg;
973 903
974 LOG (GNUNET_ERROR_TYPE_DEBUG, 904 LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting LIST from ARM service\n");
975 "Requesting LIST from ARM service\n");
976 if (0 == h->request_id_counter) 905 if (0 == h->request_id_counter)
977 h->request_id_counter++; 906 h->request_id_counter++;
978 op = GNUNET_new (struct GNUNET_ARM_Operation); 907 op = GNUNET_new (struct GNUNET_ARM_Operation);
@@ -983,12 +912,10 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
983 GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, 912 GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head,
984 h->operation_pending_tail, 913 h->operation_pending_tail,
985 op); 914 op);
986 env = GNUNET_MQ_msg (msg, 915 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_LIST);
987 GNUNET_MESSAGE_TYPE_ARM_LIST);
988 msg->reserved = htonl (0); 916 msg->reserved = htonl (0);
989 msg->request_id = GNUNET_htonll (op->id); 917 msg->request_id = GNUNET_htonll (op->id);
990 GNUNET_MQ_send (h->mq, 918 GNUNET_MQ_send (h->mq, env);
991 env);
992 return op; 919 return op;
993} 920}
994 921
diff --git a/src/arm/arm_monitor_api.c b/src/arm/arm_monitor_api.c
index 15f91c036..55b12240f 100644
--- a/src/arm/arm_monitor_api.c
+++ b/src/arm/arm_monitor_api.c
@@ -32,7 +32,7 @@
32 32
33#define INIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 33#define INIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
34 34
35#define LOG(kind,...) GNUNET_log_from (kind, "arm-monitor-api",__VA_ARGS__) 35#define LOG(kind, ...) GNUNET_log_from (kind, "arm-monitor-api", __VA_ARGS__)
36 36
37/** 37/**
38 * Handle for interacting with ARM. 38 * Handle for interacting with ARM.
@@ -69,7 +69,6 @@ struct GNUNET_ARM_MonitorHandle
69 * Closure for @e service_status. 69 * Closure for @e service_status.
70 */ 70 */
71 void *service_status_cls; 71 void *service_status_cls;
72
73}; 72};
74 73
75 74
@@ -115,9 +114,9 @@ reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h)
115 h->mq = NULL; 114 h->mq = NULL;
116 } 115 }
117 GNUNET_assert (NULL == h->reconnect_task); 116 GNUNET_assert (NULL == h->reconnect_task);
118 h->reconnect_task 117 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
119 = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, 118 &reconnect_arm_monitor_task,
120 &reconnect_arm_monitor_task, h); 119 h);
121 h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); 120 h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff);
122} 121}
123 122
@@ -130,14 +129,14 @@ reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h)
130 * @return #GNUNET_OK if the message is well-formed 129 * @return #GNUNET_OK if the message is well-formed
131 */ 130 */
132static int 131static int
133check_monitor_notify (void *cls, 132check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg)
134 const struct GNUNET_ARM_StatusMessage *msg)
135{ 133{
136 size_t sl = ntohs (msg->header.size) - sizeof (struct GNUNET_ARM_StatusMessage); 134 size_t sl =
135 ntohs (msg->header.size) - sizeof (struct GNUNET_ARM_StatusMessage);
137 const char *name = (const char *) &msg[1]; 136 const char *name = (const char *) &msg[1];
138 137
139 if ( (0 == sl) || 138 (void) cls;
140 ('\0' != name[sl-1]) ) 139 if ((0 == sl) || ('\0' != name[sl - 1]))
141 { 140 {
142 GNUNET_break (0); 141 GNUNET_break (0);
143 return GNUNET_SYSERR; 142 return GNUNET_SYSERR;
@@ -153,8 +152,7 @@ check_monitor_notify (void *cls,
153 * @param res the message received from the arm service 152 * @param res the message received from the arm service
154 */ 153 */
155static void 154static void
156handle_monitor_notify (void *cls, 155handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res)
157 const struct GNUNET_ARM_StatusMessage *res)
158{ 156{
159 struct GNUNET_ARM_MonitorHandle *h = cls; 157 struct GNUNET_ARM_MonitorHandle *h = cls;
160 enum GNUNET_ARM_ServiceStatus status; 158 enum GNUNET_ARM_ServiceStatus status;
@@ -165,9 +163,7 @@ handle_monitor_notify (void *cls,
165 (const char *) &res[1], 163 (const char *) &res[1],
166 (int) status); 164 (int) status);
167 if (NULL != h->service_status) 165 if (NULL != h->service_status)
168 h->service_status (h->service_status_cls, 166 h->service_status (h->service_status_cls, (const char *) &res[1], status);
169 (const char *) &res[1],
170 status);
171} 167}
172 168
173 169
@@ -180,11 +176,11 @@ handle_monitor_notify (void *cls,
180 * @param error error code 176 * @param error error code
181 */ 177 */
182static void 178static void
183mq_error_handler (void *cls, 179mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
184 enum GNUNET_MQ_Error error)
185{ 180{
186 struct GNUNET_ARM_MonitorHandle *h = cls; 181 struct GNUNET_ARM_MonitorHandle *h = cls;
187 182
183 (void) error;
188 reconnect_arm_monitor_later (h); 184 reconnect_arm_monitor_later (h);
189} 185}
190 186
@@ -198,22 +194,17 @@ mq_error_handler (void *cls,
198static int 194static int
199reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) 195reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h)
200{ 196{
201 struct GNUNET_MQ_MessageHandler handlers[] = { 197 struct GNUNET_MQ_MessageHandler handlers[] =
202 GNUNET_MQ_hd_var_size (monitor_notify, 198 {GNUNET_MQ_hd_var_size (monitor_notify,
203 GNUNET_MESSAGE_TYPE_ARM_STATUS, 199 GNUNET_MESSAGE_TYPE_ARM_STATUS,
204 struct GNUNET_ARM_StatusMessage, 200 struct GNUNET_ARM_StatusMessage,
205 h), 201 h),
206 GNUNET_MQ_handler_end () 202 GNUNET_MQ_handler_end ()};
207 };
208 struct GNUNET_MessageHeader *msg; 203 struct GNUNET_MessageHeader *msg;
209 struct GNUNET_MQ_Envelope *env; 204 struct GNUNET_MQ_Envelope *env;
210 205
211 GNUNET_assert (NULL == h->mq); 206 GNUNET_assert (NULL == h->mq);
212 h->mq = GNUNET_CLIENT_connect (h->cfg, 207 h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h);
213 "arm",
214 handlers,
215 &mq_error_handler,
216 h);
217 if (NULL == h->mq) 208 if (NULL == h->mq)
218 { 209 {
219 if (NULL != h->service_status) 210 if (NULL != h->service_status)
@@ -222,10 +213,8 @@ reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h)
222 GNUNET_ARM_SERVICE_STOPPED); 213 GNUNET_ARM_SERVICE_STOPPED);
223 return GNUNET_SYSERR; 214 return GNUNET_SYSERR;
224 } 215 }
225 env = GNUNET_MQ_msg (msg, 216 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR);
226 GNUNET_MESSAGE_TYPE_ARM_MONITOR); 217 GNUNET_MQ_send (h->mq, env);
227 GNUNET_MQ_send (h->mq,
228 env);
229 return GNUNET_OK; 218 return GNUNET_OK;
230} 219}
231 220
diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c
index c9f00b5dd..667556314 100644
--- a/src/arm/mockup-service.c
+++ b/src/arm/mockup-service.c
@@ -33,13 +33,13 @@ static int special_ret = 0;
33 * @param message the actual message 33 * @param message the actual message
34 */ 34 */
35static void 35static void
36handle_stop (void *cls, 36handle_stop (void *cls, const struct GNUNET_MessageHeader *message)
37 const struct GNUNET_MessageHeader *message)
38{ 37{
39 struct GNUNET_SERVICE_Client *client = cls; 38 struct GNUNET_SERVICE_Client *client = cls;
40 39
40 (void) message;
41 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 41 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
42 _("Initiating shutdown as requested by client.\n")); 42 _ ("Initiating shutdown as requested by client.\n"));
43 GNUNET_SERVICE_client_persist (client); 43 GNUNET_SERVICE_client_persist (client);
44 GNUNET_SCHEDULER_shutdown (); 44 GNUNET_SCHEDULER_shutdown ();
45 /* ARM won't exponentially increase restart delay if we 45 /* ARM won't exponentially increase restart delay if we
@@ -59,9 +59,11 @@ handle_stop (void *cls,
59 */ 59 */
60static void * 60static void *
61client_connect_cb (void *cls, 61client_connect_cb (void *cls,
62 struct GNUNET_SERVICE_Client *c, 62 struct GNUNET_SERVICE_Client *c,
63 struct GNUNET_MQ_Handle *mq) 63 struct GNUNET_MQ_Handle *mq)
64{ 64{
65 (void) cls;
66 (void) mq;
65 return c; 67 return c;
66} 68}
67 69
@@ -75,9 +77,10 @@ client_connect_cb (void *cls,
75 */ 77 */
76static void 78static void
77client_disconnect_cb (void *cls, 79client_disconnect_cb (void *cls,
78 struct GNUNET_SERVICE_Client *c, 80 struct GNUNET_SERVICE_Client *c,
79 void *internal_cls) 81 void *internal_cls)
80{ 82{
83 (void) cls;
81 GNUNET_assert (c == internal_cls); 84 GNUNET_assert (c == internal_cls);
82} 85}
83 86
@@ -87,6 +90,9 @@ run (void *cls,
87 const struct GNUNET_CONFIGURATION_Handle *cfg, 90 const struct GNUNET_CONFIGURATION_Handle *cfg,
88 struct GNUNET_SERVICE_Handle *service) 91 struct GNUNET_SERVICE_Handle *service)
89{ 92{
93 (void) cls;
94 (void) cfg;
95 (void) service;
90 /* nothing to do */ 96 /* nothing to do */
91} 97}
92 98
@@ -94,25 +100,20 @@ run (void *cls,
94/** 100/**
95 * Define "main" method using service macro. 101 * Define "main" method using service macro.
96 */ 102 */
97GNUNET_SERVICE_MAIN 103GNUNET_SERVICE_MAIN ("do-nothing",
98("do-nothing", 104 GNUNET_SERVICE_OPTION_NONE,
99 GNUNET_SERVICE_OPTION_NONE, 105 &run,
100 &run, 106 &client_connect_cb,
101 &client_connect_cb, 107 &client_disconnect_cb,
102 &client_disconnect_cb, 108 NULL,
103 NULL, 109 GNUNET_MQ_hd_fixed_size (stop,
104 GNUNET_MQ_hd_fixed_size (stop, 110 GNUNET_MESSAGE_TYPE_ARM_STOP,
105 GNUNET_MESSAGE_TYPE_ARM_STOP, 111 struct GNUNET_MessageHeader,
106 struct GNUNET_MessageHeader, 112 NULL),
107 NULL), 113 GNUNET_MQ_handler_end ());
108 GNUNET_MQ_handler_end ());
109 114
110 115
111/** 116/**
112 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 117 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
113 */ 118 */
114void __attribute__ ((destructor)) 119void __attribute__ ((destructor)) GNUNET_mockup_done () { _exit (special_ret); }
115GNUNET_mockup_done ()
116{
117 _exit (special_ret);
118}