GNUnet 0.22.2
arm_api.c File Reference

API for accessing the ARM service. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_arm_service.h"
#include "gnunet_protocols.h"
#include "arm.h"
Include dependency graph for arm_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_ARM_Operation
 Entry in a doubly-linked list of operations awaiting for replies (in-order) from the ARM service. More...
 
struct  GNUNET_ARM_Handle
 Handle for interacting with ARM. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "arm-api", __VA_ARGS__)
 

Functions

static enum GNUNET_GenericReturnValue reconnect_arm (struct GNUNET_ARM_Handle *h)
 Connect to arm. More...
 
static void reconnect_arm_task (void *cls)
 Task scheduled to try to re-connect to arm. More...
 
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. More...
 
static struct GNUNET_ARM_Operationfind_op_by_id (struct GNUNET_ARM_Handle *h, uint64_t id)
 Find a control message by its unique ID. More...
 
static void handle_arm_result (void *cls, const struct GNUNET_ARM_ResultMessage *res)
 Handler for ARM replies. More...
 
static const char * pool_get (const char *pool_start, size_t pool_size, size_t str_index)
 Read from a string pool. More...
 
static enum GNUNET_GenericReturnValue check_arm_list_result (void *cls, const struct GNUNET_ARM_ListResultMessage *lres)
 Check that list result message is well-formed. More...
 
static void handle_arm_list_result (void *cls, const struct GNUNET_ARM_ListResultMessage *lres)
 Handler for ARM list replies. More...
 
static void handle_confirm (void *cls, const struct GNUNET_MessageHeader *msg)
 Receive confirmation from test, ARM service is up. More...
 
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 creation of the message queue. More...
 
struct GNUNET_ARM_HandleGNUNET_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 context. More...
 
void GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h)
 Disconnect from the ARM service (if connected) and destroy the context. More...
 
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. More...
 
void GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op)
 Abort an operation. More...
 
static struct GNUNET_ARM_Operationchange_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. More...
 
static void notify_running (void *cls)
 Task run to notify application that ARM is already up. More...
 
static void notify_starting (void *cls)
 Task run to notify application that ARM is being started. More...
 
struct GNUNET_ARM_OperationGNUNET_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. More...
 
struct GNUNET_ARM_OperationGNUNET_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. More...
 
struct GNUNET_ARM_OperationGNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h, GNUNET_ARM_ServiceListCallback cont, void *cont_cls)
 Request a list of running services. More...
 

Detailed Description

API for accessing the ARM service.

Author
Christian Grothoff
LRN

Definition in file arm_api.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "arm-api", __VA_ARGS__)

Definition at line 33 of file arm_api.c.

Function Documentation

◆ reconnect_arm()

static enum GNUNET_GenericReturnValue reconnect_arm ( struct GNUNET_ARM_Handle h)
static

Connect to arm.

Parameters
harm handle
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 519 of file arm_api.c.

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}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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
#define LOG(kind,...)
Definition: arm_api.c:33
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
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
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
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(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:76
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#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.
void * conn_status_cls
Closure for conn_status.
Definition: arm_api.c:132
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
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
GNUNET_ARM_ConnectionStatusCallback conn_status
Callback to invoke on connection/disconnection.
Definition: arm_api.c:127
Reply from ARM to client for the GNUNET_MESSAGE_TYPE_ARM_LIST request followed by count '\0' terminat...
Definition: arm.h:145
Reply from ARM to client.
Definition: arm.h:87
Message handler for a specific message type.
Header for all communications.

References GNUNET_ARM_Handle::cfg, GNUNET_ARM_Handle::conn_status, GNUNET_ARM_Handle::conn_status_cls, GNUNET_ARM_Handle::currently_up, env, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, GNUNET_MESSAGE_TYPE_ARM_RESULT, GNUNET_MESSAGE_TYPE_ARM_TEST, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, h, handlers, LOG, GNUNET_ARM_Handle::mq, and mq_error_handler().

Referenced by GNUNET_ARM_connect(), GNUNET_ARM_request_service_start(), and reconnect_arm_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reconnect_arm_task()

static void reconnect_arm_task ( void *  cls)
static

Task scheduled to try to re-connect to arm.

Parameters
clsthe struct GNUNET_ARM_Handle

Definition at line 183 of file arm_api.c.

184{
185 struct GNUNET_ARM_Handle *h = cls;
186
187 h->reconnect_task = NULL;
189}
static enum GNUNET_GenericReturnValue reconnect_arm(struct GNUNET_ARM_Handle *h)
Connect to arm.
Definition: arm_api.c:519
Handle for interacting with ARM.
Definition: arm_api.c:103
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Definition: arm_api.c:147

References h, reconnect_arm(), and GNUNET_ARM_Handle::reconnect_task.

Referenced by reconnect_arm_later().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reconnect_arm_later()

static void reconnect_arm_later ( struct GNUNET_ARM_Handle h)
static

Close down any existing connection to the ARM service and try re-establishing it later.

Parameters
hour handle

Definition at line 199 of file arm_api.c.

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}
static void reconnect_arm_task(void *cls)
Task scheduled to try to re-connect to arm.
Definition: arm_api.c:183
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:143
void GNUNET_ARM_operation_cancel(struct GNUNET_ARM_Operation *op)
Abort an operation.
Definition: arm_api.c:795
@ GNUNET_ARM_REQUEST_DISCONNECTED
We disconnected from ARM, and request was not sent.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
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:1277
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
struct GNUNET_ARM_Operation * operation_pending_head
Head of doubly-linked list of pending operations.
Definition: arm_api.c:117
struct GNUNET_TIME_Relative retry_backoff
Current delay we use for re-trying to connect to core.
Definition: arm_api.c:152
Entry in a doubly-linked list of operations awaiting for replies (in-order) from the ARM service.
Definition: arm_api.c:41
void * cont_cls
Closure for result_cont or list_cont.
Definition: arm_api.c:70
GNUNET_ARM_ServiceListCallback list_cont
Callback for service list requests.
Definition: arm_api.c:65
GNUNET_ARM_ResultCallback result_cont
Callback for service state change requests.
Definition: arm_api.c:60

References GNUNET_ARM_Handle::conn_status, GNUNET_ARM_Handle::conn_status_cls, GNUNET_ARM_Operation::cont_cls, GNUNET_ARM_Handle::currently_up, GNUNET_ARM_operation_cancel(), GNUNET_ARM_REQUEST_DISCONNECTED, GNUNET_assert, GNUNET_MQ_destroy(), GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, h, GNUNET_ARM_Operation::list_cont, GNUNET_ARM_Handle::mq, op, GNUNET_ARM_Handle::operation_pending_head, reconnect_arm_task(), GNUNET_ARM_Handle::reconnect_task, GNUNET_ARM_Operation::result_cont, and GNUNET_ARM_Handle::retry_backoff.

Referenced by mq_error_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_op_by_id()

static struct GNUNET_ARM_Operation * find_op_by_id ( struct GNUNET_ARM_Handle h,
uint64_t  id 
)
static

Find a control message by its unique ID.

Parameters
hARM handle
idunique message ID to use for the lookup
Returns
NULL if not found

Definition at line 243 of file arm_api.c.

245{
247 NULL != result;
248 result = result->next)
249 if (id == result->id)
250 return result;
251 return NULL;
252}
static int result
Global testing status.

References h, GNUNET_ARM_Handle::operation_pending_head, and result.

Referenced by handle_arm_list_result(), and handle_arm_result().

Here is the caller graph for this function:

◆ handle_arm_result()

static void handle_arm_result ( void *  cls,
const struct GNUNET_ARM_ResultMessage res 
)
static

Handler for ARM replies.

Parameters
clsour struct GNUNET_ARM_Handle
resthe message received from the arm service

Definition at line 262 of file arm_api.c.

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}
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 char * res
Currently read line or NULL on EOF.
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
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.
GNUNET_ARM_Result
Replies to ARM requests.
@ GNUNET_ARM_RESULT_IS_NOT_KNOWN
Asked to start or stop a service, but it's not known.
@ GNUNET_ARM_RESULT_STOPPING
ARM stopping was initiated (there's no "stopped" for ARM itself).
@ GNUNET_ARM_REQUEST_SENT_OK
Message was sent successfully.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54
@ GNUNET_YES
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_ARM_Operation * operation_pending_tail
Tail of doubly-linked list of pending operations.
Definition: arm_api.c:122
struct GNUNET_ARM_Operation * thm
ARM operation where the goal is to wait for ARM shutdown to complete.
Definition: arm_api.c:142
int is_arm_stop
Is this an operation to stop the ARM service?
Definition: arm_api.c:95

References GNUNET_ARM_Operation::cont_cls, find_op_by_id(), GNUNET_ARM_operation_cancel(), GNUNET_ARM_REQUEST_SENT_OK, GNUNET_ARM_RESULT_IS_NOT_KNOWN, GNUNET_ARM_RESULT_STOPPING, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_ntohll(), GNUNET_YES, h, id, GNUNET_ARM_Operation::is_arm_stop, LOG, op, GNUNET_ARM_Handle::operation_pending_head, GNUNET_ARM_Handle::operation_pending_tail, res, result, GNUNET_ARM_Operation::result_cont, and GNUNET_ARM_Handle::thm.

Here is the call graph for this function:

◆ pool_get()

static const char * pool_get ( const char *  pool_start,
size_t  pool_size,
size_t  str_index 
)
static

Read from a string pool.

Parameters
pool_startstart of the string pool
pool_sizesize of the string pool
str_indexindex into the string pool
Returns
an index into the string pool, or NULL if the index is out of bounds

Definition at line 325 of file arm_api.c.

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}
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:33

References end.

Referenced by check_arm_list_result(), and handle_arm_list_result().

Here is the caller graph for this function:

◆ check_arm_list_result()

static enum GNUNET_GenericReturnValue check_arm_list_result ( void *  cls,
const struct GNUNET_ARM_ListResultMessage lres 
)
static

Check that list result message is well-formed.

Parameters
clsour struct GNUNET_ARM_Handle
lresthe message received from the arm service
Returns
GNUNET_OK if message is well-formed

Definition at line 350 of file arm_api.c.

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}
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
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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
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
uint16_t binary_index
String pool index for the service's binary.
Definition: arm.h:109
uint16_t name_index
String pool index for the service's name.
Definition: arm.h:104

References GNUNET_ARM_ListResultMessage::arm_msg, GNUNET_ARM_ServiceInfoMessage::binary_index, GNUNET_ARM_ListResultMessage::count, GNUNET_break_op, GNUNET_NO, GNUNET_OK, GNUNET_ARM_Message::header, GNUNET_ARM_ServiceInfoMessage::name_index, pool_get(), and GNUNET_MessageHeader::size.

Here is the call graph for this function:

◆ handle_arm_list_result()

static void handle_arm_list_result ( void *  cls,
const struct GNUNET_ARM_ListResultMessage lres 
)
static

Handler for ARM list replies.

Parameters
clsour struct GNUNET_ARM_Handle
lresthe message received from the arm service

Definition at line 399 of file arm_api.c.

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}
static int list
Set if we should print a list of currently running services.
Definition: gnunet-arm.c:68
static char * name
Name (label) of the records to list.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:741
uint64_t request_id
ID of a request that is being replied to.
Definition: arm.h:77
struct GNUNET_TIME_AbsoluteNBO last_started_at
Time when the service was first started, if applicable.
Definition: arm.h:135
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
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.

References GNUNET_ARM_ListResultMessage::arm_msg, GNUNET_ARM_ServiceInfo::binary, GNUNET_ARM_ServiceInfoMessage::binary_index, GNUNET_ARM_Operation::cont_cls, GNUNET_ARM_ListResultMessage::count, find_op_by_id(), GNUNET_ARM_operation_cancel(), GNUNET_ARM_REQUEST_SENT_OK, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ntohll(), GNUNET_TIME_absolute_ntoh(), h, GNUNET_ARM_Message::header, id, GNUNET_ARM_ServiceInfoMessage::last_exit_status, GNUNET_ARM_ServiceInfoMessage::last_started_at, list, GNUNET_ARM_Operation::list_cont, LOG, name, GNUNET_ARM_ServiceInfo::name, GNUNET_ARM_ServiceInfoMessage::name_index, op, pool_get(), GNUNET_ARM_Message::request_id, GNUNET_ARM_ServiceInfoMessage::restart_at, GNUNET_MessageHeader::size, and GNUNET_ARM_ServiceInfoMessage::status.

Here is the call graph for this function:

◆ handle_confirm()

static void handle_confirm ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Receive confirmation from test, ARM service is up.

Parameters
clsclosure with the struct GNUNET_ARM_Handle
msgmessage received

Definition at line 466 of file arm_api.c.

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}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2

References GNUNET_ARM_Handle::conn_status, GNUNET_ARM_Handle::conn_status_cls, GNUNET_ARM_Handle::currently_up, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_YES, h, LOG, and msg.

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_ARM_Handle *
errorerror code

Definition at line 492 of file arm_api.c.

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}
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
@ GNUNET_ARM_RESULT_STOPPED
Service was stopped (never sent for ARM itself).

References GNUNET_ARM_Operation::cont_cls, GNUNET_ARM_Handle::currently_up, GNUNET_ARM_REQUEST_SENT_OK, GNUNET_ARM_RESULT_STOPPED, GNUNET_free, GNUNET_NO, h, op, reconnect_arm_later(), GNUNET_ARM_Operation::result_cont, and GNUNET_ARM_Handle::thm.

Referenced by reconnect_arm().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_arm_service()

static enum GNUNET_ARM_Result start_arm_service ( struct GNUNET_ARM_Handle h,
enum GNUNET_OS_InheritStdioFlags  std_inheritance,
struct GNUNET_DISK_FileHandle sigfd 
)
static

A client specifically requested starting of ARM itself.

Starts the ARM service.

Parameters
hthe handle with configuration details
std_inheritanceinheritance of std streams
sigfdsocket to pass to ARM for signalling
Returns
operation status code

Definition at line 654 of file arm_api.c.

657{
658 struct GNUNET_OS_Process *proc;
659 char *cbinary;
660 char *binary;
661 char *quotedbinary;
662 char *config;
663 char *loprefix;
664 char *lopostfix;
665 int ld[2];
666 int *lsocks;
667
668 if (NULL == sigfd)
669 {
670 lsocks = NULL;
671 }
672 else
673 {
674 ld[0] = sigfd->fd;
675 ld[1] = -1;
676 lsocks = ld;
677 }
678 if (GNUNET_OK !=
680 "arm",
681 "PREFIX",
682 &loprefix))
683 loprefix = GNUNET_strdup ("");
684 else
685 loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, loprefix);
686 if (GNUNET_OK !=
688 "arm",
689 "OPTIONS",
690 &lopostfix))
691 lopostfix = GNUNET_strdup ("");
692 else
694 lopostfix);
695 if (GNUNET_OK !=
697 "arm",
698 "BINARY",
699 &cbinary))
700 {
702 "arm",
703 "BINARY");
704 GNUNET_free (loprefix);
705 GNUNET_free (lopostfix);
707 }
708 if (GNUNET_OK !=
710 "arm",
711 "CONFIG",
712 &config))
713 config = NULL;
715 cbinary);
716 GNUNET_asprintf (&quotedbinary,
717 "\"%s\"",
718 binary);
719 GNUNET_free (cbinary);
720 if ( (GNUNET_YES ==
722 "TESTING",
723 "WEAKRANDOM")) &&
724 (GNUNET_YES ==
726 "TESTING",
727 "WEAKRANDOM")) &&
728 (GNUNET_NO ==
730 "TESTING",
731 "HOSTFILE")) )
732 {
733 /* Means we are ONLY running locally */
734 /* we're clearly running a test, don't daemonize */
735 if (NULL == config)
736 proc = GNUNET_OS_start_process_s (std_inheritance,
737 lsocks,
738 loprefix,
739 quotedbinary,
740 /* no daemonization! */
741 lopostfix,
742 NULL);
743 else
744 proc = GNUNET_OS_start_process_s (std_inheritance,
745 lsocks,
746 loprefix,
747 quotedbinary,
748 "-c",
749 config,
750 /* no daemonization! */
751 lopostfix,
752 NULL);
753 }
754 else
755 {
756 if (NULL == config)
757 proc = GNUNET_OS_start_process_s (std_inheritance,
758 lsocks,
759 loprefix,
760 quotedbinary,
761 "-d", /* do daemonize */
762 lopostfix,
763 NULL);
764 else
765 proc = GNUNET_OS_start_process_s (std_inheritance,
766 lsocks,
767 loprefix,
768 quotedbinary,
769 "-c",
770 config,
771 "-d", /* do daemonize */
772 lopostfix,
773 NULL);
774 }
775 GNUNET_free (binary);
776 GNUNET_free (quotedbinary);
777 if (NULL != config)
779 GNUNET_free (loprefix);
780 GNUNET_free (lopostfix);
781 if (NULL == proc)
785}
const struct GNUNET_CONFIGURATION_Handle * config
@ GNUNET_ARM_RESULT_STARTING
Service starting was initiated.
@ GNUNET_ARM_RESULT_START_FAILED
Tried to start a service, but that failed for some reason.
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.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
@ GNUNET_ERROR_TYPE_WARNING
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
struct GNUNET_OS_Process * GNUNET_OS_start_process_s(enum GNUNET_OS_InheritStdioFlags std_inheritance, const int *lsocks, const char *filename,...)
Start a process.
Definition: os_priority.c:659
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:260
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 ...
int fd
File handle on Unix-like systems.

References GNUNET_ARM_Handle::cfg, config, GNUNET_DISK_FileHandle::fd, GNUNET_ARM_RESULT_IS_NOT_KNOWN, GNUNET_ARM_RESULT_START_FAILED, GNUNET_ARM_RESULT_STARTING, GNUNET_asprintf(), GNUNET_CONFIGURATION_expand_dollar(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONFIGURATION_have_value(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_config_missing(), GNUNET_NO, GNUNET_OK, GNUNET_OS_get_libexec_binary_path(), GNUNET_OS_process_destroy(), GNUNET_OS_project_data_gnunet(), GNUNET_OS_start_process_s(), GNUNET_strdup, GNUNET_YES, and h.

Referenced by GNUNET_ARM_request_service_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ change_service()

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 
)
static

Start or stop a service.

Parameters
hhandle to ARM
service_namename of the service
cbcallback to invoke when service is ready
cb_clsclosure for cb
typetype of the request
Returns
handle to queue, NULL on error

Definition at line 832 of file arm_api.c.

837{
838 struct GNUNET_ARM_Operation *op;
839 size_t slen;
840 struct GNUNET_MQ_Envelope *env;
841 struct GNUNET_ARM_Message *msg;
842
843 slen = strlen (service_name) + 1;
844 if (slen + sizeof(struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE)
845 {
846 GNUNET_break (0);
847 return NULL;
848 }
849 if (0 == h->request_id_counter)
852 op->h = h;
853 op->result_cont = cb;
854 op->cont_cls = cb_cls;
858 op);
860 slen,
861 type);
862 msg->reserved = htonl (0);
863 msg->request_id = GNUNET_htonll (op->id);
864 GNUNET_memcpy (&msg[1],
866 slen);
868 return op;
869}
static uint32_t type
Type string converted to DNS type value.
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:50
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:61
uint64_t request_id_counter
Counter for request identifiers.
Definition: arm_api.c:158
uint64_t id
Unique ID for the request.
Definition: arm_api.c:80
struct GNUNET_ARM_Handle * h
ARM handle.
Definition: arm_api.c:55

References GNUNET_ARM_Operation::cont_cls, env, GNUNET_break, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_htonll(), GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_new, h, GNUNET_ARM_Operation::h, GNUNET_ARM_Operation::id, GNUNET_ARM_Handle::mq, msg, op, GNUNET_ARM_Handle::operation_pending_head, GNUNET_ARM_Handle::operation_pending_tail, GNUNET_ARM_Handle::request_id_counter, GNUNET_ARM_Operation::result_cont, service_name, and type.

Referenced by GNUNET_ARM_request_service_start(), and GNUNET_ARM_request_service_stop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_running()

static void notify_running ( void *  cls)
static

Task run to notify application that ARM is already up.

Parameters
clsthe operation that asked ARM to be started

Definition at line 878 of file arm_api.c.

879{
880 struct GNUNET_ARM_Operation *op = cls;
881 struct GNUNET_ARM_Handle *h = op->h;
882
883 op->async = NULL;
886 op);
887 if (NULL != op->result_cont)
891 if ( (GNUNET_YES == h->currently_up) &&
892 (NULL != h->conn_status) )
894 GNUNET_YES);
895 GNUNET_free (op);
896}
@ GNUNET_ARM_RESULT_IS_STARTED_ALREADY
Asked to start it, but it's already started.
struct GNUNET_SCHEDULER_Task * async
Task for async completion.
Definition: arm_api.c:75

References GNUNET_ARM_Operation::async, GNUNET_ARM_Handle::conn_status, GNUNET_ARM_Handle::conn_status_cls, GNUNET_ARM_Operation::cont_cls, GNUNET_ARM_Handle::currently_up, GNUNET_ARM_REQUEST_SENT_OK, GNUNET_ARM_RESULT_IS_STARTED_ALREADY, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_YES, h, GNUNET_ARM_Operation::h, op, GNUNET_ARM_Handle::operation_pending_head, GNUNET_ARM_Handle::operation_pending_tail, and GNUNET_ARM_Operation::result_cont.

Referenced by GNUNET_ARM_request_service_start().

Here is the caller graph for this function:

◆ notify_starting()

static void notify_starting ( void *  cls)
static

Task run to notify application that ARM is being started.

Parameters
clsthe operation that asked ARM to be started

Definition at line 905 of file arm_api.c.

906{
907 struct GNUNET_ARM_Operation *op = cls;
908 struct GNUNET_ARM_Handle *h = op->h;
909
910 op->async = NULL;
912 "Notifying client that we started the ARM service\n");
915 op);
916 if (NULL != op->result_cont)
921 GNUNET_free (op);
922}
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1289
struct GNUNET_DISK_FileHandle * rfd
File descriptor to close on operation stop, if not NULL.
Definition: arm_api.c:90
enum GNUNET_ARM_Result starting_ret
Result of this operation for notify_starting().
Definition: arm_api.c:85

References GNUNET_ARM_Operation::async, GNUNET_ARM_Operation::cont_cls, GNUNET_ARM_REQUEST_SENT_OK, GNUNET_CONTAINER_DLL_remove, GNUNET_DISK_file_close(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, h, GNUNET_ARM_Operation::h, LOG, op, GNUNET_ARM_Handle::operation_pending_head, GNUNET_ARM_Handle::operation_pending_tail, GNUNET_ARM_Operation::result_cont, GNUNET_ARM_Operation::rfd, and GNUNET_ARM_Operation::starting_ret.

Referenced by GNUNET_ARM_request_service_start().

Here is the call graph for this function:
Here is the caller graph for this function: