GNUnet  0.11.x
Data Structures | Macros | Typedefs | Enumerations | Functions
ARM service

Automatic Restart Manager. More...

Data Structures

struct  GNUNET_ARM_ServiceInfo
 Information about a service managed by ARM. More...
 

Macros

#define GNUNET_ARM_VERSION   0x00000003
 Version of the arm API. More...
 

Typedefs

typedef void(* GNUNET_ARM_ConnectionStatusCallback) (void *cls, int connected)
 Function called whenever we connect to or disconnect from ARM. More...
 
typedef 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. More...
 
typedef 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. More...
 
typedef void(* GNUNET_ARM_ServiceMonitorCallback) (void *cls, const char *service, enum GNUNET_ARM_ServiceMonitorStatus status)
 Function called in when a status update arrives. More...
 

Enumerations

enum  GNUNET_ARM_RequestStatus { GNUNET_ARM_REQUEST_SENT_OK = 0, GNUNET_ARM_REQUEST_DISCONNECTED = 2 }
 Statuses of the requests that client can send to ARM. More...
 
enum  GNUNET_ARM_ServiceMonitorStatus { GNUNET_ARM_SERVICE_MONITORING_STARTED = 0, GNUNET_ARM_SERVICE_STOPPED = 1, GNUNET_ARM_SERVICE_STARTING = 2, GNUNET_ARM_SERVICE_STOPPING = 3 }
 Statuses of services. More...
 
enum  GNUNET_ARM_Result {
  GNUNET_ARM_RESULT_STOPPED = 0, GNUNET_ARM_RESULT_STOPPING = 1, GNUNET_ARM_RESULT_STARTING = 2, GNUNET_ARM_RESULT_IS_STARTING_ALREADY = 3,
  GNUNET_ARM_RESULT_IS_STOPPING_ALREADY = 4, GNUNET_ARM_RESULT_IS_STARTED_ALREADY = 5, GNUNET_ARM_RESULT_IS_STOPPED_ALREADY = 6, GNUNET_ARM_RESULT_IS_NOT_KNOWN = 7,
  GNUNET_ARM_RESULT_START_FAILED = 8, GNUNET_ARM_RESULT_IN_SHUTDOWN = 9
}
 Replies to ARM requests. More...
 
enum  GNUNET_ARM_ServiceStatus {
  GNUNET_ARM_SERVICE_STATUS_STOPPED = 0, GNUNET_ARM_SERVICE_STATUS_STARTED = 1, GNUNET_ARM_SERVICE_STATUS_FAILED = 2, GNUNET_ARM_SERVICE_STATUS_FINISHED = 3,
  GNUNET_ARM_SERVICE_STATUS_STOPPING = 4
}
 Status of a service managed by ARM. More...
 

Functions

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 and destroy the handle. More...
 
void GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op)
 Abort an operation. 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...
 
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_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_MonitorHandleGNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_ARM_ServiceMonitorCallback cont, void *cont_cls)
 Setup a context for monitoring ARM, then start connecting to the ARM service for monitoring using that context. More...
 
void GNUNET_ARM_monitor_stop (struct GNUNET_ARM_MonitorHandle *h)
 Disconnect from the ARM service and destroy the handle. More...
 

Detailed Description

Automatic Restart Manager.

See also
Documentation

Macro Definition Documentation

◆ GNUNET_ARM_VERSION

#define GNUNET_ARM_VERSION   0x00000003

Version of the arm API.

Definition at line 51 of file gnunet_arm_service.h.

Typedef Documentation

◆ GNUNET_ARM_ConnectionStatusCallback

typedef void(* GNUNET_ARM_ConnectionStatusCallback) (void *cls, int connected)

Function called whenever we connect to or disconnect from ARM.

Parameters
clsclosure
connectedGNUNET_YES if connected, GNUNET_NO if disconnected, GNUNET_SYSERR if there was an error.

Definition at line 246 of file gnunet_arm_service.h.

◆ GNUNET_ARM_ResultCallback

typedef 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.

Will be called when request was not sent successfully, or when a reply comes. If the request was not sent successfully, rs will indicate that, and result will be undefined.

Parameters
clsclosure
rsstatus of the request
resultresult of the operation

Definition at line 261 of file gnunet_arm_service.h.

◆ GNUNET_ARM_ServiceListCallback

typedef 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.

Will be called when request was not sent successfully, or when a reply comes. If the request was not sent successfully, rs will indicate that, and count and list will be undefined.

Parameters
clsclosure
rsstatus of the request
countnumber of strings in the list
listlist of services managed by arm

Definition at line 278 of file gnunet_arm_service.h.

◆ GNUNET_ARM_ServiceMonitorCallback

typedef void(* GNUNET_ARM_ServiceMonitorCallback) (void *cls, const char *service, enum GNUNET_ARM_ServiceMonitorStatus status)

Function called in when a status update arrives.

Parameters
clsclosure
serviceservice name
statusstatus of the service

Definition at line 388 of file gnunet_arm_service.h.

Enumeration Type Documentation

◆ GNUNET_ARM_RequestStatus

Statuses of the requests that client can send to ARM.

Enumerator
GNUNET_ARM_REQUEST_SENT_OK 

Message was sent successfully.

GNUNET_ARM_REQUEST_DISCONNECTED 

We disconnected from ARM, and request was not sent.

Definition at line 57 of file gnunet_arm_service.h.

58 {
63 
68 };
We disconnected from ARM, and request was not sent.
Message was sent successfully.

◆ GNUNET_ARM_ServiceMonitorStatus

Statuses of services.

Enumerator
GNUNET_ARM_SERVICE_MONITORING_STARTED 

Dummy message.

GNUNET_ARM_SERVICE_STOPPED 

Service was stopped.

GNUNET_ARM_SERVICE_STARTING 

Service starting was initiated.

GNUNET_ARM_SERVICE_STOPPING 

Service stopping was initiated.

Definition at line 74 of file gnunet_arm_service.h.

75 {
80 
85 
90 
95 };
Service stopping was initiated.
Service was stopped.
Service starting was initiated.

◆ GNUNET_ARM_Result

Replies to ARM requests.

Enumerator
GNUNET_ARM_RESULT_STOPPED 

Service was stopped (never sent for ARM itself).

GNUNET_ARM_RESULT_STOPPING 

ARM stopping was initiated (there's no "stopped" for ARM itself).

GNUNET_ARM_RESULT_STARTING 

Service starting was initiated.

GNUNET_ARM_RESULT_IS_STARTING_ALREADY 

Asked to start it, but it's already starting.

GNUNET_ARM_RESULT_IS_STOPPING_ALREADY 

Asked to stop it, but it's already stopping.

GNUNET_ARM_RESULT_IS_STARTED_ALREADY 

Asked to start it, but it's already started.

GNUNET_ARM_RESULT_IS_STOPPED_ALREADY 

Asked to stop it, but it's already stopped.

GNUNET_ARM_RESULT_IS_NOT_KNOWN 

Asked to start or stop a service, but it's not known.

GNUNET_ARM_RESULT_START_FAILED 

Tried to start a service, but that failed for some reason.

GNUNET_ARM_RESULT_IN_SHUTDOWN 

Asked to start something, but ARM is shutting down and can't comply.

Definition at line 101 of file gnunet_arm_service.h.

102 {
107 
112 
117 
122 
127 
132 
137 
142 
147 
152 };
ARM stopping was initiated (there's no "stopped" for ARM itself).
Asked to stop it, but it's already stopping.
Asked to start it, but it's already started.
Tried to start a service, but that failed for some reason.
Service starting was initiated.
Asked to start it, but it's already starting.
Asked to start something, but ARM is shutting down and can't comply.
Asked to stop it, but it's already stopped.
Asked to start or stop a service, but it's not known.
Service was stopped (never sent for ARM itself).

◆ GNUNET_ARM_ServiceStatus

Status of a service managed by ARM.

Enumerator
GNUNET_ARM_SERVICE_STATUS_STOPPED 

Service is stopped.

GNUNET_ARM_SERVICE_STATUS_STARTED 

Service has been started and is currently running.

GNUNET_ARM_SERVICE_STATUS_FAILED 

The service has previously failed, and will be restarted.

GNUNET_ARM_SERVICE_STATUS_FINISHED 

The service was started, but then exited normally.

GNUNET_ARM_SERVICE_STATUS_STOPPING 

The service was started, and we're currently waiting for it to be stopped.

Definition at line 158 of file gnunet_arm_service.h.

159 {
164 
169 
175 
180 
186 };
The service has previously failed, and will be restarted.
The service was started, but then exited normally.
The service was started, and we're currently waiting for it to be stopped.
Service has been started and is currently running.

Function Documentation

◆ GNUNET_ARM_connect()

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 context.

Parameters
cfgconfiguration to use (needed to contact ARM; the ARM service may internally use a different configuration to determine how to start the service).
conn_statuswill be called when connecting/disconnecting
conn_status_clsclosure for conn_status
Returns
context to use for further ARM operations, NULL on error.

Definition at line 579 of file arm_api.c.

References cfg, GNUNET_ARM_Handle::cfg, GNUNET_ARM_Handle::conn_status, conn_status(), GNUNET_ARM_Handle::conn_status_cls, GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_ARM_Operation::h, and reconnect_arm().

Referenced by GNUNET_TESTING_peer_stop_async(), handle_manage_peer_service(), and run().

582 {
583  struct GNUNET_ARM_Handle *h;
584 
585  h = GNUNET_new (struct GNUNET_ARM_Handle);
586  h->cfg = cfg;
589  if (GNUNET_OK != reconnect_arm (h))
590  {
591  GNUNET_free (h);
592  return NULL;
593  }
594  return h;
595 }
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
Handle for interacting with ARM.
Definition: arm_api.c:102
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
GNUNET_ARM_ConnectionStatusCallback conn_status
Callback to invoke on connection/disconnection.
Definition: arm_api.c:127
static void conn_status(void *cls, int connected)
Function called whenever we connect to or disconnect from ARM.
Definition: gnunet-arm.c:302
void * conn_status_cls
Closure for conn_status.
Definition: arm_api.c:132
static int reconnect_arm(struct GNUNET_ARM_Handle *h)
Connect to arm.
Definition: arm_api.c:521
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ARM_disconnect()

void GNUNET_ARM_disconnect ( struct GNUNET_ARM_Handle h)

Disconnect from the ARM service and destroy the handle.

Parameters
hthe handle that was being used

Disconnect from the ARM service and destroy the handle.

Parameters
hthe handle that was being used

Definition at line 604 of file arm_api.c.

References GNUNET_ARM_Operation::async, GNUNET_ARM_Operation::cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_ARM_Operation::list_cont, LOG, GNUNET_ARM_Handle::mq, op, GNUNET_ARM_Handle::operation_pending_head, GNUNET_ARM_Handle::operation_pending_tail, GNUNET_ARM_Handle::reconnect_task, and GNUNET_ARM_Operation::result_cont.

Referenced by cleanup_mctx(), disconn_status(), GNUNET_TESTING_peer_destroy(), GNUNET_TESTING_peer_stop_async_cancel(), and shutdown_task().

605 {
606  struct GNUNET_ARM_Operation *op;
607 
608  LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n");
609  while (NULL != (op = h->operation_pending_head))
610  {
613  op);
614  if (NULL != op->result_cont)
615  op->result_cont (op->cont_cls,
617  0);
618  if (NULL != op->list_cont)
619  op->list_cont (op->cont_cls,
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  {
632  GNUNET_MQ_destroy (h->mq);
633  h->mq = NULL;
634  }
635  if (NULL != h->reconnect_task)
636  {
638  h->reconnect_task = NULL;
639  }
640  GNUNET_free (h);
641 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Definition: arm_api.c:147
#define LOG(kind,...)
Definition: arm_api.c:33
Entry in a doubly-linked list of operations awaiting for replies (in-order) from the ARM service...
Definition: arm_api.c:40
We disconnected from ARM, and request was not sent.
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
void * cont_cls
Closure for result_cont or list_cont.
Definition: arm_api.c:70
struct GNUNET_SCHEDULER_Task * async
Task for async completion.
Definition: arm_api.c:75
GNUNET_ARM_ServiceListCallback list_cont
Callback for service list requests.
Definition: arm_api.c:65
struct GNUNET_ARM_Operation * operation_pending_head
Head of doubly-linked list of pending operations.
Definition: arm_api.c:117
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
struct GNUNET_ARM_Operation * operation_pending_tail
Tail of doubly-linked list of pending operations.
Definition: arm_api.c:122
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
GNUNET_ARM_ResultCallback result_cont
Callback for service state change requests.
Definition: arm_api.c:60
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ARM_operation_cancel()

void GNUNET_ARM_operation_cancel ( struct GNUNET_ARM_Operation op)

Abort an operation.

Only prevents the callback from being called, the operation may still complete.

Parameters
opoperation to cancel

Definition at line 794 of file arm_api.c.

References GNUNET_ARM_Operation::async, GNUNET_CONTAINER_DLL_remove, GNUNET_DISK_file_close(), GNUNET_free, GNUNET_SCHEDULER_cancel(), GNUNET_ARM_Operation::h, GNUNET_ARM_Handle::operation_pending_head, GNUNET_ARM_Handle::operation_pending_tail, GNUNET_ARM_Operation::result_cont, GNUNET_ARM_Operation::rfd, and GNUNET_ARM_Handle::thm.

Referenced by handle_arm_list_result(), handle_arm_result(), reconnect_arm_later(), and shutdown_task().

795 {
796  struct GNUNET_ARM_Handle *h = op->h;
797 
798  if (NULL != op->async)
799  {
801  op->async = NULL;
802  }
803  if (NULL != op->rfd)
804  {
806  op->rfd = NULL;
807  }
808  if (h->thm == op)
809  {
810  op->result_cont = NULL;
811  return;
812  }
815  op);
816  GNUNET_free (op);
817 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1345
Handle for interacting with ARM.
Definition: arm_api.c:102
struct GNUNET_DISK_FileHandle * rfd
File descriptor to close on operation stop, if not NULL.
Definition: arm_api.c:90
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_SCHEDULER_Task * async
Task for async completion.
Definition: arm_api.c:75
struct GNUNET_ARM_Operation * operation_pending_head
Head of doubly-linked list of pending operations.
Definition: arm_api.c:117
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_ARM_Handle * h
ARM handle.
Definition: arm_api.c:55
struct GNUNET_ARM_Operation * operation_pending_tail
Tail of doubly-linked list of pending operations.
Definition: arm_api.c:122
GNUNET_ARM_ResultCallback result_cont
Callback for service state change requests.
Definition: arm_api.c:60
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ARM_request_service_list()

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.

Parameters
hhandle to ARM
contcallback to invoke after request is sent or is not sent
cont_clsclosure for cont
Returns
handle for the operation, NULL on error

Definition at line 1074 of file arm_api.c.

References GNUNET_ARM_Operation::cont_cls, env, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_ERROR_TYPE_DEBUG, GNUNET_htonll(), GNUNET_MESSAGE_TYPE_ARM_LIST, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_new, GNUNET_ARM_Operation::h, GNUNET_ARM_Operation::id, GNUNET_ARM_Operation::list_cont, LOG, GNUNET_ARM_Handle::mq, msg, op, GNUNET_ARM_Handle::operation_pending_head, GNUNET_ARM_Handle::operation_pending_tail, GNUNET_ARM_Message::request_id, GNUNET_ARM_Handle::request_id_counter, and GNUNET_ARM_Message::reserved.

Referenced by action_loop().

1077 {
1078  struct GNUNET_ARM_Operation *op;
1079  struct GNUNET_MQ_Envelope *env;
1080  struct GNUNET_ARM_Message *msg;
1081 
1083  "Requesting LIST from ARM service\n");
1084  if (0 == h->request_id_counter)
1085  h->request_id_counter++;
1086  op = GNUNET_new (struct GNUNET_ARM_Operation);
1087  op->h = h;
1088  op->list_cont = cont;
1089  op->cont_cls = cont_cls;
1090  op->id = h->request_id_counter++;
1093  op);
1094  env = GNUNET_MQ_msg (msg,
1096  msg->reserved = htonl (0);
1097  msg->request_id = GNUNET_htonll (op->id);
1098  GNUNET_MQ_send (h->mq, env);
1099  return op;
1100 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
uint64_t request_id
ID of a request that is being replied to.
Definition: arm.h:77
#define LOG(kind,...)
Definition: arm_api.c:33
Entry in a doubly-linked list of operations awaiting for replies (in-order) from the ARM service...
Definition: arm_api.c:40
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void * cont_cls
Closure for result_cont or list_cont.
Definition: arm_api.c:70
uint32_t reserved
For alignment.
Definition: arm.h:70
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
GNUNET_ARM_ServiceListCallback list_cont
Callback for service list requests.
Definition: arm_api.c:65
struct GNUNET_ARM_Operation * operation_pending_head
Head of doubly-linked list of pending operations.
Definition: arm_api.c:117
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
#define GNUNET_MESSAGE_TYPE_ARM_LIST
Request to ARM to list all currently running services.
uint64_t id
Unique ID for the request.
Definition: arm_api.c:80
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
struct GNUNET_ARM_Handle * h
ARM handle.
Definition: arm_api.c:55
uint64_t request_id_counter
Counter for request identifiers.
Definition: arm_api.c:158
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:353
struct GNUNET_ARM_Operation * operation_pending_tail
Tail of doubly-linked list of pending operations.
Definition: arm_api.c:122
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ARM_request_service_stop()

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.

Stopping arm itself will not invalidate its handle, and ARM API will try to restore connection to the ARM service, even if ARM connection was lost because you asked for ARM to be stopped. Call GNUNET_ARM_disconnect() to free the handle and prevent further connection attempts.

Parameters
hhandle to ARM
service_namename of the service
contcallback to invoke after request is sent or is not sent
cont_clsclosure for cont
Returns
handle for the operation, NULL on error

Definition at line 1039 of file arm_api.c.

References change_service(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_ARM_STOP, GNUNET_YES, GNUNET_ARM_Operation::is_arm_stop, LOG, and op.

Referenced by action_loop(), and handle_manage_peer_service().

1043 {
1044  struct GNUNET_ARM_Operation *op;
1045 
1047  "Stopping service `%s'\n",
1048  service_name);
1049  op = change_service (h,
1050  service_name,
1051  cont,
1052  cont_cls,
1054  if (NULL == op)
1055  return NULL;
1056  /* If the service is ARM, set a flag as we will use MQ errors
1057  to detect that the process is really gone. */
1058  if (0 == strcasecmp (service_name,
1059  "arm"))
1060  op->is_arm_stop = GNUNET_YES;
1061  return op;
1062 }
#define LOG(kind,...)
Definition: arm_api.c:33
Entry in a doubly-linked list of operations awaiting for replies (in-order) from the ARM service...
Definition: arm_api.c:40
#define GNUNET_MESSAGE_TYPE_ARM_STOP
Request to ARM to stop a service.
void * cont_cls
Closure for result_cont or list_cont.
Definition: arm_api.c:70
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:831
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
int is_arm_stop
Is this an operation to stop the ARM service?
Definition: arm_api.c:95
#define GNUNET_YES
Definition: gnunet_common.h:77
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ARM_request_service_start()

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.

Parameters
hhandle to ARM
service_namename of the service
std_inheritanceinheritance of std streams
contcallback to invoke after request is sent or not sent
cont_clsclosure for cont
Returns
handle for the operation, NULL on error

Definition at line 930 of file arm_api.c.

References GNUNET_ARM_Operation::async, change_service(), GNUNET_ARM_Operation::cont_cls, GNUNET_ARM_Handle::currently_up, GNUNET_ARM_RESULT_STARTING, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_DISK_file_close(), GNUNET_DISK_pipe(), GNUNET_DISK_pipe_close(), GNUNET_DISK_pipe_detach_end(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_PIPE_END_WRITE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror, GNUNET_MESSAGE_TYPE_ARM_START, GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_read_file(), GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, GNUNET_ARM_Operation::h, LOG, notify_running(), notify_starting(), op, GNUNET_ARM_Handle::operation_pending_head, GNUNET_ARM_Handle::operation_pending_tail, reconnect_arm(), GNUNET_ARM_Operation::result_cont, ret, GNUNET_ARM_Operation::rfd, start_arm_service(), and GNUNET_ARM_Operation::starting_ret.

Referenced by action_loop(), and handle_manage_peer_service().

936 {
937  struct GNUNET_ARM_Operation *op;
938  enum GNUNET_ARM_Result ret;
939  struct GNUNET_DISK_PipeHandle *sig;
940  struct GNUNET_DISK_FileHandle *wsig;
941 
943  "Starting service `%s'\n",
944  service_name);
945  if (0 != strcasecmp ("arm",
946  service_name))
947  return change_service (h,
948  service_name,
949  cont,
950  cont_cls,
952 
953  /* Possible cases:
954  * 1) We're connected to ARM already. Invoke the callback immediately.
955  * 2) We're not connected to ARM.
956  * Cancel any reconnection attempts temporarily, then perform
957  * a service test.
958  */if (GNUNET_YES == h->currently_up)
959  {
961  "ARM is already running\n");
962  op = GNUNET_new (struct GNUNET_ARM_Operation);
963  op->h = h;
964  op->result_cont = cont;
965  op->cont_cls = cont_cls;
968  op);
970  return op;
971  }
972  /* This is an inherently uncertain choice, as it is of course
973  theoretically possible that ARM is up and we just did not
974  yet complete the MQ handshake. However, given that users
975  are unlikely to hammer 'gnunet-arm -s' on a busy system,
976  the above check should catch 99.99% of the cases where ARM
977  is already running. */LOG (GNUNET_ERROR_TYPE_DEBUG,
978  "Starting ARM service\n");
979  if (NULL == (sig = GNUNET_DISK_pipe (GNUNET_NO,
980  GNUNET_NO,
981  GNUNET_NO,
982  GNUNET_YES)))
983  {
985  "pipe");
986  }
987  wsig = GNUNET_DISK_pipe_detach_end (sig,
989  ret = start_arm_service (h,
990  std_inheritance,
991  wsig);
992  GNUNET_DISK_file_close (wsig);
993  if (GNUNET_ARM_RESULT_STARTING == ret)
994  reconnect_arm (h);
995  op = GNUNET_new (struct GNUNET_ARM_Operation);
996  op->h = h;
997  op->result_cont = cont;
998  op->cont_cls = cont_cls;
1001  op);
1002  op->starting_ret = ret;
1003  if (NULL != sig)
1004  {
1005  op->rfd = GNUNET_DISK_pipe_detach_end (sig,
1007  /* Wait at most a minute for gnunet-service-arm to be up, as beyond
1008  that something clearly just went wrong */
1010  op->rfd,
1011  &notify_starting,
1012  op);
1013  }
1014  else
1015  {
1017  op);
1018  }
1019  GNUNET_DISK_pipe_close (sig);
1020  return op;
1021 }
static void notify_starting(void *cls)
Task run to notify application that ARM is being started.
Definition: arm_api.c:900
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1345
#define GNUNET_TIME_UNIT_MINUTES
One minute.
#define LOG(kind,...)
Definition: arm_api.c:33
Entry in a doubly-linked list of operations awaiting for replies (in-order) from the ARM service...
Definition: arm_api.c:40
#define GNUNET_MESSAGE_TYPE_ARM_START
Request to ARM to start a service.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
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:1636
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_ARM_Result
Replies to ARM requests.
void * cont_cls
Closure for result_cont or list_cont.
Definition: arm_api.c:70
struct GNUNET_DISK_FileHandle * rfd
File descriptor to close on operation stop, if not NULL.
Definition: arm_api.c:90
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_SCHEDULER_Task * async
Task for async completion.
Definition: arm_api.c:75
static void notify_running(void *cls)
Task run to notify application that ARM is already up.
Definition: arm_api.c:873
#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...
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
Service starting was initiated.
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:1682
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:831
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:1280
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
The writing-end of a pipe.
The reading-end of a pipe.
struct GNUNET_ARM_Operation * operation_pending_head
Head of doubly-linked list of pending operations.
Definition: arm_api.c:117
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(int blocking_read, int blocking_write, int inherit_read, int inherit_write)
Creates an interprocess channel.
Definition: disk.c:1526
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
struct GNUNET_ARM_Handle * h
ARM handle.
Definition: arm_api.c:55
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1715
int currently_up
Have we detected that ARM is up?
Definition: arm_api.c:163
enum GNUNET_ARM_Result starting_ret
Result of this operation for notify_starting().
Definition: arm_api.c:85
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_ARM_Operation * operation_pending_tail
Tail of doubly-linked list of pending operations.
Definition: arm_api.c:122
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
static int reconnect_arm(struct GNUNET_ARM_Handle *h)
Connect to arm.
Definition: arm_api.c:521
GNUNET_ARM_ResultCallback result_cont
Callback for service state change requests.
Definition: arm_api.c:60
Handle used to access files (and pipes).
Handle used to manage a pipe.
Definition: disk.c:68
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ARM_monitor_start()

struct GNUNET_ARM_MonitorHandle* GNUNET_ARM_monitor_start ( const struct GNUNET_CONFIGURATION_Handle cfg,
GNUNET_ARM_ServiceMonitorCallback  cont,
void *  cont_cls 
)

Setup a context for monitoring ARM, then start connecting to the ARM service for monitoring using that context.

Parameters
cfgconfiguration to use (needed to contact ARM; the ARM service may internally use a different configuration to determine how to start the service).
contcallback to invoke on status updates
cont_clsclosure for cont
Returns
context to use for further ARM monitor operations, NULL on error.

Definition at line 233 of file arm_monitor_api.c.

References GNUNET_ARM_MonitorHandle::cfg, GNUNET_free, GNUNET_new, GNUNET_OK, h, reconnect_arm_monitor(), GNUNET_ARM_MonitorHandle::service_status, and GNUNET_ARM_MonitorHandle::service_status_cls.

Referenced by run().

236 {
237  struct GNUNET_ARM_MonitorHandle *h;
238 
240  h->cfg = cfg;
241  h->service_status = cont;
242  h->service_status_cls = cont_cls;
243  if (GNUNET_OK != reconnect_arm_monitor (h))
244  {
245  GNUNET_free (h);
246  return NULL;
247  }
248  return h;
249 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
void * service_status_cls
Closure for service_status.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Handle for interacting with ARM.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
GNUNET_ARM_ServiceMonitorCallback service_status
Callback to invoke on status updates.
static int reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h)
Connect to the ARM service for monitoring.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ARM_monitor_stop()

void GNUNET_ARM_monitor_stop ( struct GNUNET_ARM_MonitorHandle h)

Disconnect from the ARM service and destroy the handle.

Parameters
hthe handle that was being used

Disconnect from the ARM service and destroy the handle.

Parameters
hthe handle that was being used

Definition at line 258 of file arm_monitor_api.c.

References GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_ARM_MonitorHandle::mq, and GNUNET_ARM_MonitorHandle::reconnect_task.

Referenced by shutdown_task().

259 {
260  if (NULL != h->mq)
261  {
262  GNUNET_MQ_destroy (h->mq);
263  h->mq = NULL;
264  }
265  if (NULL != h->reconnect_task)
266  {
268  h->reconnect_task = NULL;
269  }
270  GNUNET_free (h);
271 }
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
struct GNUNET_MQ_Handle * mq
Our control connection to the ARM service.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function: