diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-05-11 13:06:16 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-05-11 13:06:16 +0000 |
commit | dd5612fda0a14a944ff5f0c99044449adca55605 (patch) | |
tree | f6740b863fdc886606658e068f80b1cdac886ef8 /src | |
parent | e6a918a6b4e22ba7bf61ba418923837481864a8c (diff) | |
download | gnunet-dd5612fda0a14a944ff5f0c99044449adca55605.tar.gz gnunet-dd5612fda0a14a944ff5f0c99044449adca55605.zip |
arm-specific
Diffstat (limited to 'src')
-rw-r--r-- | src/arm/gnunet-service-arm.c | 52 | ||||
-rw-r--r-- | src/arm/mockup-service.c | 4 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 17 | ||||
-rw-r--r-- | src/util/client.c | 46 | ||||
-rw-r--r-- | src/util/service.c | 86 |
5 files changed, 81 insertions, 124 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index 71a2aa446..aa4f89bdb 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c | |||
@@ -966,12 +966,64 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
966 | } | 966 | } |
967 | 967 | ||
968 | 968 | ||
969 | static size_t | ||
970 | transmit_shutdown_ack (void *cls, size_t size, void *buf) | ||
971 | { | ||
972 | struct GNUNET_SERVER_Client *client = cls; | ||
973 | struct GNUNET_MessageHeader *msg; | ||
974 | |||
975 | if (size < sizeof (struct GNUNET_MessageHeader)) | ||
976 | { | ||
977 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
978 | _("Failed to transmit shutdown ACK.\n")); | ||
979 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
980 | return 0; /* client disconnected */ | ||
981 | } | ||
982 | |||
983 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
984 | _("Transmitting shutdown ACK.\n")); | ||
985 | |||
986 | msg = (struct GNUNET_MessageHeader *) buf; | ||
987 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK); | ||
988 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
989 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
990 | GNUNET_SERVER_client_drop(client); | ||
991 | return sizeof (struct GNUNET_MessageHeader); | ||
992 | } | ||
993 | |||
994 | /** | ||
995 | * Handler for SHUTDOWN message. | ||
996 | * | ||
997 | * @param cls closure (refers to service) | ||
998 | * @param client identification of the client | ||
999 | * @param message the actual message | ||
1000 | */ | ||
1001 | static void | ||
1002 | handle_shutdown (void *cls, | ||
1003 | struct GNUNET_SERVER_Client *client, | ||
1004 | const struct GNUNET_MessageHeader *message) | ||
1005 | { | ||
1006 | GNUNET_SERVER_client_keep(client); | ||
1007 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1008 | _("Initiating shutdown as requested by client.\n")); | ||
1009 | |||
1010 | GNUNET_SERVER_notify_transmit_ready (client, | ||
1011 | sizeof(struct GNUNET_MessageHeader), | ||
1012 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1013 | &transmit_shutdown_ack, client); | ||
1014 | GNUNET_SERVER_client_persist_ (client); | ||
1015 | GNUNET_SCHEDULER_shutdown (sched); | ||
1016 | } | ||
1017 | |||
1018 | |||
969 | /** | 1019 | /** |
970 | * List of handlers for the messages understood by this service. | 1020 | * List of handlers for the messages understood by this service. |
971 | */ | 1021 | */ |
972 | static struct GNUNET_SERVER_MessageHandler handlers[] = { | 1022 | static struct GNUNET_SERVER_MessageHandler handlers[] = { |
973 | {&handle_start, NULL, GNUNET_MESSAGE_TYPE_ARM_START, 0}, | 1023 | {&handle_start, NULL, GNUNET_MESSAGE_TYPE_ARM_START, 0}, |
974 | {&handle_stop, NULL, GNUNET_MESSAGE_TYPE_ARM_STOP, 0}, | 1024 | {&handle_stop, NULL, GNUNET_MESSAGE_TYPE_ARM_STOP, 0}, |
1025 | {&handle_shutdown, NULL, GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN, | ||
1026 | sizeof (struct GNUNET_MessageHeader)}, | ||
975 | {NULL, NULL, 0, 0} | 1027 | {NULL, NULL, 0, 0} |
976 | }; | 1028 | }; |
977 | 1029 | ||
diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c index dd0f5b122..8a4940630 100644 --- a/src/arm/mockup-service.c +++ b/src/arm/mockup-service.c | |||
@@ -49,7 +49,7 @@ transmit_shutdown_ack (void *cls, size_t size, void *buf) | |||
49 | _("Transmitting shutdown ACK.\n")); | 49 | _("Transmitting shutdown ACK.\n")); |
50 | 50 | ||
51 | msg = (struct GNUNET_MessageHeader *) buf; | 51 | msg = (struct GNUNET_MessageHeader *) buf; |
52 | msg->type = htons (GNUNET_MESSAGE_TYPE_SHUTDOWN_ACK); | 52 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK); |
53 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 53 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
54 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 54 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
55 | GNUNET_SERVER_client_drop(client); | 55 | GNUNET_SERVER_client_drop(client); |
@@ -87,7 +87,7 @@ handle_shutdown (void *cls, | |||
87 | * struct. | 87 | * struct. |
88 | */ | 88 | */ |
89 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 89 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
90 | {&handle_shutdown, NULL, GNUNET_MESSAGE_TYPE_SHUTDOWN, | 90 | {&handle_shutdown, NULL, GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN, |
91 | sizeof (struct GNUNET_MessageHeader)}, | 91 | sizeof (struct GNUNET_MessageHeader)}, |
92 | {NULL, NULL, 0, 0} | 92 | {NULL, NULL, 0, 0} |
93 | }; | 93 | }; |
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 069c6d5ee..1a29069c3 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -40,11 +40,6 @@ extern "C" | |||
40 | */ | 40 | */ |
41 | #define GNUNET_MESSAGE_TYPE_TEST 0 | 41 | #define GNUNET_MESSAGE_TYPE_TEST 0 |
42 | 42 | ||
43 | /** | ||
44 | * Request service shutdown. | ||
45 | */ | ||
46 | #define GNUNET_MESSAGE_TYPE_SHUTDOWN 1 | ||
47 | |||
48 | 43 | ||
49 | /** | 44 | /** |
50 | * Request DNS resolution. | 45 | * Request DNS resolution. |
@@ -105,17 +100,15 @@ extern "C" | |||
105 | #define GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN 12 | 100 | #define GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN 12 |
106 | 101 | ||
107 | /** | 102 | /** |
108 | * Acknowledge service shutting down, disconnect | 103 | * Request ARM service shutdown. |
109 | * indicates service stopped. | ||
110 | */ | 104 | */ |
111 | #define GNUNET_MESSAGE_TYPE_SHUTDOWN_ACK 13 | 105 | #define GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN 13 |
112 | 106 | ||
113 | /** | 107 | /** |
114 | * Deny service shutdown, disconnect indicates | 108 | * Acknowledge service shutting down, disconnect |
115 | * service won't be stopped as a result of shutdown | 109 | * indicates service stopped. |
116 | * message. | ||
117 | */ | 110 | */ |
118 | #define GNUNET_MESSAGE_TYPE_SHUTDOWN_REFUSE 14 | 111 | #define GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK 14 |
119 | 112 | ||
120 | /** | 113 | /** |
121 | * HELLO message used for communicating peer addresses. | 114 | * HELLO message used for communicating peer addresses. |
diff --git a/src/util/client.c b/src/util/client.c index 55eb68d13..c87d239e6 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -624,30 +624,28 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
624 | else | 624 | else |
625 | { | 625 | { |
626 | GNUNET_assert(ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader)); | 626 | GNUNET_assert(ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader)); |
627 | |||
628 | switch (ntohs(msg->type)) | 627 | switch (ntohs(msg->type)) |
629 | { | 628 | { |
630 | case GNUNET_MESSAGE_TYPE_SHUTDOWN_ACK: | 629 | case GNUNET_MESSAGE_TYPE_SHUTDOWN_ACK: |
631 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 630 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
632 | "Received confirmation for service shutdown.\n"); | 631 | "Received confirmation for service shutdown.\n"); |
633 | shutdown_ctx->confirmed = GNUNET_YES; | 632 | shutdown_ctx->confirmed = GNUNET_YES; |
634 | GNUNET_CLIENT_receive (shutdown_ctx->sock, | 633 | GNUNET_CLIENT_receive (shutdown_ctx->sock, |
635 | &service_shutdown_handler, | 634 | &service_shutdown_handler, |
636 | shutdown_ctx, | 635 | shutdown_ctx, |
637 | GNUNET_TIME_UNIT_FOREVER_REL); | 636 | GNUNET_TIME_UNIT_FOREVER_REL); |
638 | break; | 637 | break; |
639 | case GNUNET_MESSAGE_TYPE_SHUTDOWN_REFUSE: | 638 | default: /* Fall through */ |
640 | default: /* Fall through */ | 639 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
641 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 640 | "Service shutdown refused!\n"); |
642 | "Service shutdown refused!\n"); | 641 | if (shutdown_ctx->cont != NULL) |
643 | if (shutdown_ctx->cont != NULL) | 642 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES); |
644 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES); | 643 | |
645 | 644 | GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->cancel_task); | |
646 | GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->cancel_task); | 645 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
647 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 646 | GNUNET_free(shutdown_ctx); |
648 | GNUNET_free(shutdown_ctx); | 647 | break; |
649 | break; | 648 | } |
650 | } | ||
651 | } | 649 | } |
652 | } | 650 | } |
653 | 651 | ||
@@ -701,7 +699,7 @@ write_shutdown (void *cls, size_t size, void *buf) | |||
701 | &service_shutdown_cancel, | 699 | &service_shutdown_cancel, |
702 | shutdown_ctx); | 700 | shutdown_ctx); |
703 | msg = (struct GNUNET_MessageHeader *) buf; | 701 | msg = (struct GNUNET_MessageHeader *) buf; |
704 | msg->type = htons (GNUNET_MESSAGE_TYPE_SHUTDOWN); | 702 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN); |
705 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 703 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
706 | return sizeof (struct GNUNET_MessageHeader); | 704 | return sizeof (struct GNUNET_MessageHeader); |
707 | } | 705 | } |
diff --git a/src/util/service.c b/src/util/service.c index 2214efe10..2022395f7 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -570,90 +570,6 @@ handle_test (void *cls, | |||
570 | } | 570 | } |
571 | 571 | ||
572 | 572 | ||
573 | static size_t | ||
574 | transmit_shutdown_deny (void *cls, size_t size, void *buf) | ||
575 | { | ||
576 | struct GNUNET_SERVER_Client *client = cls; | ||
577 | struct GNUNET_MessageHeader *msg; | ||
578 | |||
579 | if (size < sizeof (struct GNUNET_MessageHeader)) | ||
580 | { | ||
581 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
582 | return 0; /* client disconnected */ | ||
583 | } | ||
584 | msg = (struct GNUNET_MessageHeader *) buf; | ||
585 | msg->type = htons (GNUNET_MESSAGE_TYPE_SHUTDOWN_REFUSE); | ||
586 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
587 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
588 | GNUNET_SERVER_client_drop(client); | ||
589 | return sizeof (struct GNUNET_MessageHeader); | ||
590 | } | ||
591 | |||
592 | static size_t | ||
593 | transmit_shutdown_ack (void *cls, size_t size, void *buf) | ||
594 | { | ||
595 | struct GNUNET_SERVER_Client *client = cls; | ||
596 | struct GNUNET_MessageHeader *msg; | ||
597 | |||
598 | if (size < sizeof (struct GNUNET_MessageHeader)) | ||
599 | { | ||
600 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
601 | _("Failed to transmit shutdown ACK.\n")); | ||
602 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
603 | return 0; /* client disconnected */ | ||
604 | } | ||
605 | |||
606 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
607 | _("Transmitting shutdown ACK.\n")); | ||
608 | |||
609 | msg = (struct GNUNET_MessageHeader *) buf; | ||
610 | msg->type = htons (GNUNET_MESSAGE_TYPE_SHUTDOWN_ACK); | ||
611 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
612 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
613 | GNUNET_SERVER_client_drop(client); | ||
614 | return sizeof (struct GNUNET_MessageHeader); | ||
615 | } | ||
616 | |||
617 | /** | ||
618 | * Handler for SHUTDOWN message. | ||
619 | * | ||
620 | * @param cls closure (refers to service) | ||
621 | * @param client identification of the client | ||
622 | * @param message the actual message | ||
623 | */ | ||
624 | static void | ||
625 | handle_shutdown (void *cls, | ||
626 | struct GNUNET_SERVER_Client *client, | ||
627 | const struct GNUNET_MessageHeader *message) | ||
628 | { | ||
629 | struct GNUNET_SERVICE_Context *service = cls; | ||
630 | |||
631 | GNUNET_SERVER_client_keep(client); | ||
632 | if (!service->allow_shutdown) | ||
633 | { | ||
634 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
635 | _ | ||
636 | ("Received shutdown request, but configured to ignore!\n")); | ||
637 | GNUNET_SERVER_notify_transmit_ready (client, | ||
638 | sizeof(struct GNUNET_MessageHeader), | ||
639 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
640 | &transmit_shutdown_deny, client); | ||
641 | return; | ||
642 | } | ||
643 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
644 | _("Initiating shutdown as requested by client.\n")); | ||
645 | |||
646 | GNUNET_SERVER_notify_transmit_ready (client, | ||
647 | sizeof(struct GNUNET_MessageHeader), | ||
648 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
649 | &transmit_shutdown_ack, client); | ||
650 | |||
651 | GNUNET_assert (service->sched != NULL); | ||
652 | GNUNET_SERVER_client_persist_ (client); | ||
653 | GNUNET_SCHEDULER_shutdown (service->sched); | ||
654 | } | ||
655 | |||
656 | |||
657 | /** | 573 | /** |
658 | * Default handlers for all services. Will be copied and the | 574 | * Default handlers for all services. Will be copied and the |
659 | * "callback_cls" fields will be replaced with the specific service | 575 | * "callback_cls" fields will be replaced with the specific service |
@@ -662,8 +578,6 @@ handle_shutdown (void *cls, | |||
662 | static const struct GNUNET_SERVER_MessageHandler defhandlers[] = { | 578 | static const struct GNUNET_SERVER_MessageHandler defhandlers[] = { |
663 | {&handle_test, NULL, GNUNET_MESSAGE_TYPE_TEST, | 579 | {&handle_test, NULL, GNUNET_MESSAGE_TYPE_TEST, |
664 | sizeof (struct GNUNET_MessageHeader)}, | 580 | sizeof (struct GNUNET_MessageHeader)}, |
665 | {&handle_shutdown, NULL, GNUNET_MESSAGE_TYPE_SHUTDOWN, | ||
666 | sizeof (struct GNUNET_MessageHeader)}, | ||
667 | {NULL, NULL, 0, 0} | 581 | {NULL, NULL, 0, 0} |
668 | }; | 582 | }; |
669 | 583 | ||