GNUnet 0.26.2-114-g7c6b613e3
 
Loading...
Searching...
No Matches
arm_api.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2012, 2013, 2016, 2019 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_arm_service.h"
30#include "gnunet_protocols.h"
31#include "arm.h"
32
33#define LOG(kind, ...) GNUNET_log_from (kind, "arm-api", __VA_ARGS__)
34
35
97
98
165
166
175
176
182static void
184{
185 struct GNUNET_ARM_Handle *h = cls;
186
187 h->reconnect_task = NULL;
189}
190
191
198static void
200{
201 struct GNUNET_ARM_Operation *op;
202
203 if (NULL != h->mq)
204 {
206 h->mq = NULL;
207 }
209 GNUNET_assert (NULL == h->reconnect_task);
213 h);
214 while (NULL != (op = h->operation_pending_head))
215 {
216 if (NULL != op->result_cont)
219 0);
220 if (NULL != op->list_cont)
223 0,
224 NULL);
226 }
229 if (NULL != h->conn_status)
231 GNUNET_NO);
232}
233
234
242static struct GNUNET_ARM_Operation *
244 uint64_t id)
245{
247 NULL != result;
248 result = result->next)
249 if (id == result->id)
250 return result;
251 return NULL;
252}
253
254
261static void
263 const struct GNUNET_ARM_ResultMessage *res)
264{
265 struct GNUNET_ARM_Handle *h = cls;
266 struct GNUNET_ARM_Operation *op;
267 uint64_t id;
270 void *result_cont_cls;
271
272 id = GNUNET_ntohll (res->arm_msg.request_id);
273 op = find_op_by_id (h,
274 id);
275 if (NULL == op)
276 {
278 "Message with unknown id %llu\n",
279 (unsigned long long) id);
280 return;
281 }
282
283 result = ntohl (res->result);
284 if ( (GNUNET_YES == op->is_arm_stop) &&
286 {
287 /* special case: if we are stopping 'gnunet-service-arm', we do not just
288 wait for the result message, but also wait for the service to close
289 the connection (and then we have to close our client handle as well);
290 this is done by installing a different receive handler, waiting for
291 the connection to go down */if (NULL != h->thm)
292 {
293 GNUNET_break (0);
297 GNUNET_free (h->thm);
298 }
301 op);
302 h->thm = op;
303 return;
304 }
306 result_cont_cls = op->cont_cls;
308 if (NULL != result_cont)
309 result_cont (result_cont_cls,
311 result);
312}
313
314
324static const char *
325pool_get (const char *pool_start,
326 size_t pool_size,
327 size_t str_index)
328{
329 const char *str_start;
330 const char *end;
331
332 if (str_index >= pool_size)
333 return NULL;
334 str_start = pool_start + str_index;
335 end = memchr (str_start, 0, pool_size - str_index);
336 if (NULL == end)
337 return NULL;
338 return str_start;
339}
340
341
351 const struct GNUNET_ARM_ListResultMessage *lres)
352{
353 uint16_t rcount = ntohs (lres->count);
354 uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof(*lres);
356 size_t pool_size;
357 char *pool_start;
358
359 (void) cls;
360 if ((rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage) > msize))
361 {
362 GNUNET_break_op (0);
363 return GNUNET_NO;
364 }
365 ssm = (struct GNUNET_ARM_ServiceInfoMessage *) &lres[1];
366 pool_start = (char *) (ssm + rcount);
367 pool_size = msize - (rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage));
368 for (unsigned int i = 0; i < rcount; i++)
369 {
370 uint16_t name_index = ntohs (ssm->name_index);
371 uint16_t binary_index = ntohs (ssm->binary_index);
372 if (NULL == pool_get (pool_start,
373 pool_size,
374 name_index))
375 {
376 GNUNET_break_op (0);
377 return GNUNET_NO;
378 }
379 if (NULL == pool_get (pool_start,
380 pool_size,
382 {
383 GNUNET_break_op (0);
384 return GNUNET_NO;
385 }
386 ssm++;
387 }
388 return GNUNET_OK;
389}
390
391
398static void
400 const struct GNUNET_ARM_ListResultMessage *lres)
401{
402 struct GNUNET_ARM_Handle *h = cls;
403 uint16_t rcount = ntohs (lres->count);
404 uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof(*lres);
405 struct GNUNET_ARM_ServiceInfo list[rcount];
407 struct GNUNET_ARM_Operation *op;
408 uint64_t id;
409 size_t pool_size;
410 char *pool_start;
411
412 id = GNUNET_ntohll (lres->arm_msg.request_id);
413 op = find_op_by_id (h, id);
414 if (NULL == op)
415 {
417 "Message with unknown id %llu\n",
418 (unsigned long long) id);
419 return;
420 }
421
422 GNUNET_assert ((rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage) <=
423 msize));
424
425 ssm = (struct GNUNET_ARM_ServiceInfoMessage *) &lres[1];
426 pool_start = (char *) (ssm + rcount);
427 pool_size = msize - (rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage));
428
429 for (unsigned int i = 0; i < rcount; i++)
430 {
431 uint16_t name_index = ntohs (ssm->name_index);
432 uint16_t binary_index = ntohs (ssm->binary_index);
433 const char *name;
434 const char *binary;
435
436 name = pool_get (pool_start, pool_size, name_index);
437 binary = pool_get (pool_start, pool_size, binary_index);
438 GNUNET_assert (NULL != name);
439 GNUNET_assert (NULL != binary);
440 list[i] = (struct GNUNET_ARM_ServiceInfo) {
441 .name = name,
442 .binary = binary,
443 .status = ntohl (ssm->status),
444 .last_started_at = GNUNET_TIME_absolute_ntoh (ssm->last_started_at),
445 .restart_at = GNUNET_TIME_absolute_ntoh (ssm->restart_at),
446 .last_exit_status = ntohs (ssm->last_exit_status),
447 };
448 ssm++;
449 }
450 if (NULL != op->list_cont)
453 rcount,
454 list);
456}
457
458
465static void
466handle_confirm (void *cls,
467 const struct GNUNET_MessageHeader *msg)
468{
469 struct GNUNET_ARM_Handle *h = cls;
470
471 (void) msg;
473 "Got confirmation from ARM that we are up!\n");
474 if (GNUNET_NO == h->currently_up)
475 {
477 if (NULL != h->conn_status)
479 }
480}
481
482
491static void
493 enum GNUNET_MQ_Error error)
494{
495 struct GNUNET_ARM_Handle *h = cls;
496 struct GNUNET_ARM_Operation *op;
497
498 (void) error;
500 if (NULL != (op = h->thm))
501 {
502 h->thm = NULL;
506 GNUNET_free (op);
507 }
509}
510
511
520{
522 GNUNET_MQ_hd_fixed_size (arm_result,
525 h),
526 GNUNET_MQ_hd_var_size (arm_list_result,
529 h),
533 h),
535 };
536 struct GNUNET_MessageHeader *test;
537 struct GNUNET_MQ_Envelope *env;
538
539 if (NULL != h->mq)
540 return GNUNET_OK;
543 "arm",
544 handlers,
546 h);
547 if (NULL == h->mq)
548 {
550 "GNUNET_CLIENT_connect returned NULL\n");
551 if (NULL != h->conn_status)
554 return GNUNET_SYSERR;
555 }
557 "Sending TEST message to ARM\n");
558 env = GNUNET_MQ_msg (test,
561 return GNUNET_OK;
562}
563
564
576struct GNUNET_ARM_Handle *
578 const struct GNUNET_CONFIGURATION_Handle *cfg,
580 void *conn_status_cls)
581{
582 struct GNUNET_ARM_Handle *h;
583
584 h = GNUNET_new (struct GNUNET_ARM_Handle);
585 h->cfg = cfg;
588 if (GNUNET_OK != reconnect_arm (h))
589 {
590 GNUNET_free (h);
591 return NULL;
592 }
593 return h;
594}
595
596
602void
604{
605 struct GNUNET_ARM_Operation *op;
606
608 "Disconnecting from ARM service\n");
609 while (NULL != (op = h->operation_pending_head))
610 {
613 op);
614 if (NULL != op->result_cont)
617 0);
618 if (NULL != op->list_cont)
621 0,
622 NULL);
623 if (NULL != op->async)
624 {
626 op->async = NULL;
627 }
628 GNUNET_free (op);
629 }
630 if (NULL != h->mq)
631 {
633 h->mq = NULL;
634 }
635 if (NULL != h->reconnect_task)
636 {
638 h->reconnect_task = NULL;
639 }
640 GNUNET_free (h);
641}
642
643
653static enum GNUNET_ARM_Result
655 enum GNUNET_OS_InheritStdioFlags std_inheritance,
656 struct GNUNET_DISK_FileHandle *sigfd)
657{
658 struct GNUNET_Process *proc;
659 char *cbinary;
660 char *binary;
661 char *quotedbinary;
662 char *config;
663 char *loprefix;
664 char *lopostfix;
666 bool daemonize;
667
668 if (GNUNET_OK !=
670 "arm",
671 "BINARY",
672 &cbinary))
673 {
675 "arm",
676 "BINARY");
678 }
679
681 if (NULL != sigfd)
682 {
684 "Passing listen socket %d\n",
685 sigfd->fd);
687 GNUNET_OK ==
689 proc,
691 }
692 if (GNUNET_OK !=
694 "arm",
695 "PREFIX",
696 &loprefix))
697 loprefix = NULL;
698 else
700 loprefix);
701 if (GNUNET_OK !=
703 "arm",
704 "OPTIONS",
705 &lopostfix))
706 lopostfix = NULL;
707 else
709 lopostfix);
710 if (GNUNET_OK !=
712 "arm",
713 "CONFIG",
714 &config))
715 config = NULL;
718 cbinary);
719 GNUNET_asprintf (&quotedbinary,
720 "\"%s\"",
721 binary);
722 GNUNET_free (cbinary);
723 daemonize = ! ( (GNUNET_YES ==
725 "TESTING",
726 "WEAKRANDOM")) &&
727 (GNUNET_YES ==
729 "TESTING",
730 "WEAKRANDOM")) &&
731 (GNUNET_NO ==
733 "TESTING",
734 "HOSTFILE")) );
735 {
736 char *command;
737
738 GNUNET_asprintf (&command,
739 "%s%s%s%s%s%s%s%s",
740 NULL == loprefix ? "" : loprefix,
741 NULL == loprefix ? "" : " ",
742 NULL == loprefix ? binary : quotedbinary,
743 NULL == config ? "" : " -c ",
744 NULL == config ? "" : config,
745 daemonize ? " -d" : "",
746 NULL == lopostfix ? "" : " ",
747 NULL == lopostfix ? "" : lopostfix);
749 "Trying to run ARM command: `%s'\n",
750 command);
752 command);
753 GNUNET_free (command);
754 }
755 GNUNET_free (binary);
756 GNUNET_free (quotedbinary);
758 GNUNET_free (loprefix);
759 GNUNET_free (lopostfix);
761 if (GNUNET_OK != ret)
762 {
764 "Failed to start ARM service: could not set command\n");
766 }
768}
769
770
777void
779{
780 struct GNUNET_ARM_Handle *h = op->h;
781
782 if (NULL != op->async)
783 {
785 op->async = NULL;
786 }
787 if (NULL != op->rfd)
788 {
790 op->rfd = NULL;
791 }
792 if (h->thm == op)
793 {
794 op->result_cont = NULL;
795 return;
796 }
799 op);
800 GNUNET_free (op);
801}
802
803
814static struct GNUNET_ARM_Operation *
816 const char *service_name,
818 void *cb_cls,
819 uint16_t type)
820{
821 struct GNUNET_ARM_Operation *op;
822 size_t slen;
823 struct GNUNET_MQ_Envelope *env;
824 struct GNUNET_ARM_Message *msg;
825
826 slen = strlen (service_name) + 1;
827 if (slen + sizeof(struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE)
828 {
829 GNUNET_break (0);
830 return NULL;
831 }
832 if (0 == h->request_id_counter)
835 op->h = h;
836 op->result_cont = cb;
837 op->cont_cls = cb_cls;
841 op);
843 slen,
844 type);
845 msg->reserved = htonl (0);
846 msg->request_id = GNUNET_htonll (op->id);
847 GNUNET_memcpy (&msg[1],
849 slen);
851 return op;
852}
853
854
860static void
861notify_running (void *cls)
862{
863 struct GNUNET_ARM_Operation *op = cls;
864 struct GNUNET_ARM_Handle *h = op->h;
865
866 op->async = NULL;
869 op);
870 if (NULL != op->result_cont)
874 if ( (GNUNET_YES == h->currently_up) &&
875 (NULL != h->conn_status) )
877 GNUNET_YES);
878 GNUNET_free (op);
879}
880
881
887static void
889{
890 struct GNUNET_ARM_Operation *op = cls;
891 struct GNUNET_ARM_Handle *h = op->h;
892
893 op->async = NULL;
895 "Notifying client that we started the ARM service\n");
898 op);
899 if (NULL != op->result_cont)
904 GNUNET_free (op);
905}
906
907
920 struct GNUNET_ARM_Handle *h,
921 const char *service_name,
922 enum GNUNET_OS_InheritStdioFlags std_inheritance,
924 void *cont_cls)
925{
926 struct GNUNET_ARM_Operation *op;
928 struct GNUNET_DISK_PipeHandle *sig;
929
931 "Starting service `%s'\n",
933 if (0 != strcasecmp ("arm",
935 return change_service (h,
937 cont,
938 cont_cls,
940
941 /* Possible cases:
942 * 1) We're connected to ARM already. Invoke the callback immediately.
943 * 2) We're not connected to ARM.
944 * Cancel any reconnection attempts temporarily, then perform
945 * a service test.
946 */
947 if (GNUNET_YES == h->currently_up)
948 {
950 "ARM is already running\n");
952 op->h = h;
953 op->result_cont = cont;
954 op->cont_cls = cont_cls;
957 op);
959 op);
960 return op;
961 }
962 /* This is an inherently uncertain choice, as it is of course
963 theoretically possible that ARM is up and we just did not
964 yet complete the MQ handshake. However, given that users
965 are unlikely to hammer 'gnunet-arm -s' on a busy system,
966 the above check should catch 99.99% of the cases where ARM
967 is already running. */
969 "Starting ARM service\n");
970 if (NULL == (sig = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE)))
971 {
973 "pipe");
975 }
976 else
977 {
978 struct GNUNET_DISK_FileHandle *wsig;
979
980 wsig = GNUNET_DISK_pipe_detach_end (sig,
983 std_inheritance,
984 wsig);
988 }
990 op->h = h;
991 op->result_cont = cont;
992 op->cont_cls = cont_cls;
995 op);
997 if (NULL != sig)
998 {
1001 /* Wait at most a minute for gnunet-service-arm to be up, as beyond
1002 that something clearly just went wrong */
1004 op->rfd,
1006 op);
1008 }
1009 else
1010 {
1012 op);
1013 }
1014 return op;
1015}
1016
1017
1032struct GNUNET_ARM_Operation *
1034 struct GNUNET_ARM_Handle *h,
1035 const char *service_name,
1037 void *cont_cls)
1038{
1039 struct GNUNET_ARM_Operation *op;
1040
1042 "Stopping service `%s'\n",
1043 service_name);
1044 op = change_service (h,
1046 cont,
1047 cont_cls,
1049 if (NULL == op)
1050 return NULL;
1051 /* If the service is ARM, set a flag as we will use MQ errors
1052 to detect that the process is really gone. */
1053 if (0 == strcasecmp (service_name,
1054 "arm"))
1056 return op;
1057}
1058
1059
1068struct GNUNET_ARM_Operation *
1070 struct GNUNET_ARM_Handle *h,
1072 void *cont_cls)
1073{
1074 struct GNUNET_ARM_Operation *op;
1075 struct GNUNET_MQ_Envelope *env;
1076 struct GNUNET_ARM_Message *msg;
1077
1079 "Requesting LIST from ARM service\n");
1080 if (0 == h->request_id_counter)
1083 op->h = h;
1084 op->list_cont = cont;
1085 op->cont_cls = cont_cls;
1086 op->id = h->request_id_counter++;
1089 op);
1092 msg->reserved = htonl (0);
1093 msg->request_id = GNUNET_htonll (op->id);
1094 GNUNET_MQ_send (h->mq, env);
1095 return op;
1096}
1097
1098
1099/* end of arm_api.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition 003.c:1
struct GNUNET_MessageHeader * msg
Definition 005.c:2
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static void handle_arm_list_result(void *cls, const struct GNUNET_ARM_ListResultMessage *lres)
Handler for ARM list replies.
Definition arm_api.c:399
static enum GNUNET_GenericReturnValue check_arm_list_result(void *cls, const struct GNUNET_ARM_ListResultMessage *lres)
Check that list result message is well-formed.
Definition arm_api.c:350
static void reconnect_arm_later(struct GNUNET_ARM_Handle *h)
Close down any existing connection to the ARM service and try re-establishing it later.
Definition arm_api.c:199
static void reconnect_arm_task(void *cls)
Task scheduled to try to re-connect to arm.
Definition arm_api.c:183
static void handle_confirm(void *cls, const struct GNUNET_MessageHeader *msg)
Receive confirmation from test, ARM service is up.
Definition arm_api.c:466
static struct GNUNET_ARM_Operation * change_service(struct GNUNET_ARM_Handle *h, const char *service_name, GNUNET_ARM_ResultCallback cb, void *cb_cls, uint16_t type)
Start or stop a service.
Definition arm_api.c:815
static void handle_arm_result(void *cls, const struct GNUNET_ARM_ResultMessage *res)
Handler for ARM replies.
Definition arm_api.c:262
static struct GNUNET_ARM_Operation * find_op_by_id(struct GNUNET_ARM_Handle *h, uint64_t id)
Find a control message by its unique ID.
Definition arm_api.c:243
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
Definition arm_api.c:492
static enum GNUNET_ARM_Result start_arm_service(struct GNUNET_ARM_Handle *h, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_FileHandle *sigfd)
A client specifically requested starting of ARM itself.
Definition arm_api.c:654
static const char * pool_get(const char *pool_start, size_t pool_size, size_t str_index)
Read from a string pool.
Definition arm_api.c:325
static void notify_running(void *cls)
Task run to notify application that ARM is already up.
Definition arm_api.c:861
#define LOG(kind,...)
Definition arm_api.c:33
static enum GNUNET_GenericReturnValue reconnect_arm(struct GNUNET_ARM_Handle *h)
Connect to arm.
Definition arm_api.c:519
static void notify_starting(void *cls)
Task run to notify application that ARM is being started.
Definition arm_api.c:888
static struct GNUNET_ARM_Operation * op
Current operation.
Definition gnunet-arm.c:143
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition gnunet-arm.c:98
static int list
Set if we should print a list of currently running services.
Definition gnunet-arm.c:68
static int ret
Final status code.
Definition gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static void conn_status(void *cls, int connected)
Function called whenever we connect to or disconnect from ARM.
Definition gnunet-arm.c:301
static int end
Set if we are to shutdown all services (including ARM).
Definition gnunet-arm.c:33
const struct GNUNET_CONFIGURATION_Handle * config
static char * name
Name (label) of the records to list.
static char * res
Currently read line or NULL on EOF.
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
static uint32_t type
Type string converted to DNS type value.
static int result
Global testing status.
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition gnunet-vpn.c:50
Constants for network protocols.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
void(* GNUNET_ARM_ServiceListCallback)(void *cls, enum GNUNET_ARM_RequestStatus rs, unsigned int count, const struct GNUNET_ARM_ServiceInfo *list)
Callback function invoked when list operation is complete.
struct GNUNET_ARM_Handle * GNUNET_ARM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_ARM_ConnectionStatusCallback conn_status, void *conn_status_cls)
Set up a context for communicating with ARM, then start connecting to the ARM service using that cont...
Definition arm_api.c:577
struct GNUNET_ARM_Operation * GNUNET_ARM_request_service_start(struct GNUNET_ARM_Handle *h, const char *service_name, enum GNUNET_OS_InheritStdioFlags std_inheritance, GNUNET_ARM_ResultCallback cont, void *cont_cls)
Request for a service to be started.
Definition arm_api.c:919
struct GNUNET_ARM_Operation * GNUNET_ARM_request_service_list(struct GNUNET_ARM_Handle *h, GNUNET_ARM_ServiceListCallback cont, void *cont_cls)
Request a list of running services.
Definition arm_api.c:1069
void(* GNUNET_ARM_ResultCallback)(void *cls, enum GNUNET_ARM_RequestStatus rs, enum GNUNET_ARM_Result result)
Function called in response to a start/stop request.
struct GNUNET_ARM_Operation * GNUNET_ARM_request_service_stop(struct GNUNET_ARM_Handle *h, const char *service_name, GNUNET_ARM_ResultCallback cont, void *cont_cls)
Request a service to be stopped.
Definition arm_api.c:1033
void(* GNUNET_ARM_ConnectionStatusCallback)(void *cls, enum GNUNET_GenericReturnValue connected)
Function called whenever we connect to or disconnect from ARM.
void GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h)
Disconnect from the ARM service (if connected) and destroy the context.
Definition arm_api.c:603
GNUNET_ARM_Result
Replies to ARM requests.
void GNUNET_ARM_operation_cancel(struct GNUNET_ARM_Operation *op)
Abort an operation.
Definition arm_api.c:778
@ GNUNET_ARM_RESULT_IS_NOT_KNOWN
Asked to start or stop a service, but it's not known.
@ GNUNET_ARM_RESULT_STARTING
Service starting was initiated.
@ GNUNET_ARM_RESULT_IS_STARTED_ALREADY
Asked to start it, but it's already started.
@ GNUNET_ARM_RESULT_STOPPING
ARM stopping was initiated (there's no "stopped" for ARM itself).
@ GNUNET_ARM_RESULT_STOPPED
Service was stopped (never sent for ARM itself).
@ GNUNET_ARM_RESULT_START_FAILED
Tried to start a service, but that failed for some reason.
@ GNUNET_ARM_REQUEST_DISCONNECTED
We disconnected from ARM, and request was not sent.
@ GNUNET_ARM_REQUEST_SENT_OK
Message was sent successfully.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition client.c:1060
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
char * GNUNET_CONFIGURATION_expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig)
Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_detach_end(struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end)
Detaches one of the ends from the pipe.
Definition disk.c:1644
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition disk.c:1524
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition disk.c:1671
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition disk.c:1386
@ GNUNET_DISK_PF_NONE
No special options, use non-blocking read/write operations.
@ GNUNET_DISK_PIPE_END_WRITE
The writing-end of a pipe.
@ GNUNET_DISK_PIPE_END_READ
The reading-end of a pipe.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition mq.c:700
GNUNET_OS_InheritStdioFlags
Flags that determine which of the standard streams should be inherited by the child process.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
#define GNUNET_process_option_inherit_lsock(lsock)
Pass listen socket to child systemd-style.
enum GNUNET_GenericReturnValue GNUNET_process_run_command(struct GNUNET_Process *p, const char *command)
Set the command and start a process.
Definition os_process.c:921
void GNUNET_process_destroy(struct GNUNET_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition os_process.c:363
#define GNUNET_process_set_options(proc,...)
Set the requested options for the process.
struct GNUNET_Process * GNUNET_process_create(enum GNUNET_OS_InheritStdioFlags std_inheritance)
Create a process handle.
Definition os_process.c:462
char * GNUNET_OS_get_libexec_binary_path(const struct GNUNET_OS_ProjectData *pd, const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
#define GNUNET_MESSAGE_TYPE_ARM_STOP
Request to ARM to stop a service.
#define GNUNET_MESSAGE_TYPE_ARM_RESULT
Response from ARM.
#define GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT
Response from ARM for listing currently running services.
#define GNUNET_MESSAGE_TYPE_ARM_TEST
Test if ARM service is online.
#define GNUNET_MESSAGE_TYPE_ARM_START
Request to ARM to start a service.
#define GNUNET_MESSAGE_TYPE_ARM_LIST
Request to ARM to list all currently running services.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition scheduler.c:1667
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1310
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1283
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition time.c:737
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
Handle for interacting with ARM.
Definition arm_api.c:103
uint64_t request_id_counter
Counter for request identifiers.
Definition arm_api.c:158
void * conn_status_cls
Closure for conn_status.
Definition arm_api.c:132
struct GNUNET_ARM_Operation * operation_pending_head
Head of doubly-linked list of pending operations.
Definition arm_api.c:117
int currently_up
Have we detected that ARM is up?
Definition arm_api.c:163
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition arm_api.c:107
struct GNUNET_ARM_Operation * operation_pending_tail
Tail of doubly-linked list of pending operations.
Definition arm_api.c:122
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition arm_api.c:112
struct GNUNET_ARM_Operation * thm
ARM operation where the goal is to wait for ARM shutdown to complete.
Definition arm_api.c:142
struct GNUNET_TIME_Relative retry_backoff
Current delay we use for re-trying to connect to core.
Definition arm_api.c:152
GNUNET_ARM_ConnectionStatusCallback conn_status
Callback to invoke on connection/disconnection.
Definition arm_api.c:127
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Definition arm_api.c:147
Reply from ARM to client for the GNUNET_MESSAGE_TYPE_ARM_LIST request followed by count '\0' terminat...
Definition arm.h:145
uint16_t count
Number of 'struct GNUNET_ARM_ServiceInfoMessage' that are at the end of this message.
Definition arm.h:156
struct GNUNET_ARM_Message arm_msg
Reply to client, of type is GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, with an ID.
Definition arm.h:150
uint64_t request_id
ID of a request that is being replied to.
Definition arm.h:77
struct GNUNET_MessageHeader header
Reply to client, type is GNUNET_MESSAGE_TYPE_ARM_RESULT or GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT.
Definition arm.h:65
Entry in a doubly-linked list of operations awaiting for replies (in-order) from the ARM service.
Definition arm_api.c:41
int is_arm_stop
Is this an operation to stop the ARM service?
Definition arm_api.c:95
void * cont_cls
Closure for result_cont or list_cont.
Definition arm_api.c:70
struct GNUNET_ARM_Operation * prev
This is a doubly-linked list.
Definition arm_api.c:50
struct GNUNET_DISK_FileHandle * rfd
File descriptor to close on operation stop, if not NULL.
Definition arm_api.c:90
struct GNUNET_SCHEDULER_Task * async
Task for async completion.
Definition arm_api.c:75
uint64_t id
Unique ID for the request.
Definition arm_api.c:80
GNUNET_ARM_ServiceListCallback list_cont
Callback for service list requests.
Definition arm_api.c:65
enum GNUNET_ARM_Result starting_ret
Result of this operation for notify_starting().
Definition arm_api.c:85
GNUNET_ARM_ResultCallback result_cont
Callback for service state change requests.
Definition arm_api.c:60
struct GNUNET_ARM_Operation * next
This is a doubly-linked list.
Definition arm_api.c:45
struct GNUNET_ARM_Handle * h
ARM handle.
Definition arm_api.c:55
Reply from ARM to client.
Definition arm.h:87
struct GNUNET_TIME_AbsoluteNBO last_started_at
Time when the service was first started, if applicable.
Definition arm.h:135
uint16_t binary_index
String pool index for the service's binary.
Definition arm.h:109
struct GNUNET_TIME_AbsoluteNBO restart_at
Time when the service will be restarted, if applicable to the current status.
Definition arm.h:130
uint32_t status
Status from the 'enum GNUNET_ARM_ServiceStatus'.
Definition arm.h:124
int16_t last_exit_status
Last process exit status.
Definition arm.h:114
uint16_t name_index
String pool index for the service's name.
Definition arm.h:104
Information about a service managed by ARM.
const char * name
The name of the service.
const char * binary
The binary used to execute the service.
Handle used to access files (and pipes).
int fd
File handle on Unix-like systems.
Handle used to manage a pipe.
Definition disk.c:69
Handle to a message queue.
Definition mq.c:87
Message handler for a specific message type.
Header for all communications.
enum GNUNET_OS_InheritStdioFlags std_inheritance
What to do with stdin/stdout/stderr unless already specified in the file map.
Definition os_process.c:106
Entry in list of pending tasks.
Definition scheduler.c:141
Time for relative time used by GNUnet, in microseconds.