GNUnet  0.10.x
Data Structures | Macros | Functions
arm_monitor_api.c File Reference

API for monitoring the ARM service. More...

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

Go to the source code of this file.

Data Structures

struct  GNUNET_ARM_MonitorHandle
 Handle for interacting with ARM. More...
 

Macros

#define INIT_TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 
#define LOG(kind, ...)   GNUNET_log_from (kind, "arm-monitor-api", __VA_ARGS__)
 

Functions

static int reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h)
 Connect to the ARM service for monitoring. More...
 
static void reconnect_arm_monitor_task (void *cls)
 Task scheduled to try to re-connect to arm. More...
 
static void reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h)
 Close down any existing connection to the ARM service and try re-establishing it later. More...
 
static int check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg)
 Check notification messages received from ARM is well-formed. More...
 
static void handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res)
 Handler for notification messages received from ARM. 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_MonitorHandleGNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_ARM_ServiceStatusCallback 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 (if connected) and destroy the context. More...
 

Detailed Description

API for monitoring the ARM service.

Author
Christian Grothoff
LRN

Definition in file arm_monitor_api.c.

Macro Definition Documentation

◆ INIT_TIMEOUT

Definition at line 33 of file arm_monitor_api.c.

◆ LOG

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

Definition at line 35 of file arm_monitor_api.c.

Referenced by handle_monitor_notify(), and reconnect_arm_monitor_task().

Function Documentation

◆ reconnect_arm_monitor()

static int reconnect_arm_monitor ( struct GNUNET_ARM_MonitorHandle h)
static

Connect to the ARM service for monitoring.

Parameters
hhandle to connect
Returns
GNUNET_OK on success

Definition at line 195 of file arm_monitor_api.c.

References GNUNET_ARM_MonitorHandle::cfg, env, GNUNET_ARM_SERVICE_STOPPED, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_ARM_MONITOR, GNUNET_MESSAGE_TYPE_ARM_STATUS, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_OK, GNUNET_SYSERR, GNUNET_ARM_MonitorHandle::mq, mq_error_handler(), msg, GNUNET_ARM_MonitorHandle::service_status, and GNUNET_ARM_MonitorHandle::service_status_cls.

Referenced by GNUNET_ARM_monitor_start(), and reconnect_arm_monitor_task().

196 {
198  {GNUNET_MQ_hd_var_size (monitor_notify,
201  h),
203  struct GNUNET_MessageHeader *msg;
204  struct GNUNET_MQ_Envelope *env;
205 
206  GNUNET_assert (NULL == h->mq);
207  h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h);
208  if (NULL == h->mq)
209  {
210  if (NULL != h->service_status)
212  NULL,
214  return GNUNET_SYSERR;
215  }
217  GNUNET_MQ_send (h->mq, env);
218  return GNUNET_OK;
219 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_MESSAGE_TYPE_ARM_STATUS
Status update from ARM.
void * service_status_cls
Closure for service_status.
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:901
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Status update from ARM to client.
Definition: arm.h:41
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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...
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
Service was stopped.
Message handler for a specific message type.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
GNUNET_ARM_ServiceStatusCallback service_status
Callback to invoke on status updates.
#define GNUNET_MESSAGE_TYPE_ARM_MONITOR
Request to ARM to notify client of service status changes.
struct GNUNET_MQ_Handle * mq
Our control connection to the ARM service.
Header for all communications.
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
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reconnect_arm_monitor_task()

static void reconnect_arm_monitor_task ( void *  cls)
static

Task scheduled to try to re-connect to arm.

Parameters
clsthe struct GNUNET_ARM_MonitorHandle

Definition at line 91 of file arm_monitor_api.c.

References GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_OK, h, LOG, reconnect_arm_monitor(), and GNUNET_ARM_MonitorHandle::reconnect_task.

Referenced by reconnect_arm_monitor_later().

92 {
93  struct GNUNET_ARM_MonitorHandle *h = cls;
94 
95  h->reconnect_task = NULL;
97  "Connecting to ARM service for monitoring after delay\n");
99 }
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Handle for interacting with ARM.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
#define LOG(kind,...)
static int reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h)
Connect to the ARM service for monitoring.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reconnect_arm_monitor_later()

static void reconnect_arm_monitor_later ( struct GNUNET_ARM_MonitorHandle h)
static

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

Parameters
hour handle

Definition at line 109 of file arm_monitor_api.c.

References GNUNET_assert, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, GNUNET_ARM_MonitorHandle::mq, reconnect_arm_monitor_task(), GNUNET_ARM_MonitorHandle::reconnect_task, and GNUNET_ARM_MonitorHandle::retry_backoff.

Referenced by mq_error_handler().

110 {
111  if (NULL != h->mq)
112  {
113  GNUNET_MQ_destroy (h->mq);
114  h->mq = NULL;
115  }
116  GNUNET_assert (NULL == h->reconnect_task);
119  h);
121 }
struct GNUNET_TIME_Relative retry_backoff
Current delay we use for re-trying to connect to core.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
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:1246
#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_MQ_Handle * mq
Our control connection to the ARM service.
static void reconnect_arm_monitor_task(void *cls)
Task scheduled to try to re-connect to arm.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_monitor_notify()

static int check_monitor_notify ( void *  cls,
const struct GNUNET_ARM_StatusMessage msg 
)
static

Check notification messages received from ARM is well-formed.

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

Definition at line 132 of file arm_monitor_api.c.

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_ARM_StatusMessage::header, name, and GNUNET_MessageHeader::size.

133 {
134  size_t sl =
135  ntohs (msg->header.size) - sizeof (struct GNUNET_ARM_StatusMessage);
136  const char *name = (const char *) &msg[1];
137 
138  (void) cls;
139  if ((0 == sl) || ('\0' != name[sl - 1]))
140  {
141  GNUNET_break (0);
142  return GNUNET_SYSERR;
143  }
144  return GNUNET_OK;
145 }
Status update from ARM to client.
Definition: arm.h:41
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_MessageHeader header
Reply to client, of type is GNUNET_MESSAGE_TYPE_ARM_STATUS.
Definition: arm.h:47
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
const char * name

◆ handle_monitor_notify()

static void handle_monitor_notify ( void *  cls,
const struct GNUNET_ARM_StatusMessage res 
)
static

Handler for notification messages received from ARM.

Parameters
clsour struct GNUNET_ARM_MonitorHandle
resthe message received from the arm service

Definition at line 155 of file arm_monitor_api.c.

References GNUNET_ERROR_TYPE_DEBUG, h, LOG, GNUNET_ARM_MonitorHandle::service_status, GNUNET_ARM_MonitorHandle::service_status_cls, GNUNET_ARM_StatusMessage::status, and status.

156 {
157  struct GNUNET_ARM_MonitorHandle *h = cls;
159 
160  status = (enum GNUNET_ARM_ServiceStatus) ntohl (res->status);
162  "Received notification from ARM for service `%s' with status %d\n",
163  (const char *) &res[1],
164  (int) status);
165  if (NULL != h->service_status)
166  h->service_status (h->service_status_cls, (const char *) &res[1], status);
167 }
void * service_status_cls
Closure for service_status.
Handle for interacting with ARM.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
uint16_t status
See PRISM_STATUS_*-constants.
#define LOG(kind,...)
GNUNET_ARM_ServiceStatusCallback service_status
Callback to invoke on status updates.
uint32_t status
Status from the 'enum GNUNET_ARM_ServiceStatus'.
Definition: arm.h:52
GNUNET_ARM_ServiceStatus
Statuses of services.

◆ 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_MonitorHandle *
errorerror code

Definition at line 179 of file arm_monitor_api.c.

References h, and reconnect_arm_monitor_later().

Referenced by reconnect_arm_monitor().

180 {
181  struct GNUNET_ARM_MonitorHandle *h = cls;
182 
183  (void) error;
185 }
static void reconnect_arm_monitor_later(struct GNUNET_ARM_MonitorHandle *h)
Close down any existing connection to the ARM service and try re-establishing it later.
Handle for interacting with ARM.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
Here is the call graph for this function:
Here is the caller graph for this function: