diff options
Diffstat (limited to 'src/arm/arm_monitor_api.c')
-rw-r--r-- | src/arm/arm_monitor_api.c | 145 |
1 files changed, 73 insertions, 72 deletions
diff --git a/src/arm/arm_monitor_api.c b/src/arm/arm_monitor_api.c index 00faaaef1..2c418d0ce 100644 --- a/src/arm/arm_monitor_api.c +++ b/src/arm/arm_monitor_api.c | |||
@@ -30,14 +30,15 @@ | |||
30 | #include "gnunet_protocols.h" | 30 | #include "gnunet_protocols.h" |
31 | #include "arm.h" | 31 | #include "arm.h" |
32 | 32 | ||
33 | #define INIT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) | 33 | #define INIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
34 | 34 | ||
35 | #define LOG(kind, ...) GNUNET_log_from(kind, "arm-monitor-api", __VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from (kind, "arm-monitor-api", __VA_ARGS__) |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Handle for interacting with ARM. | 38 | * Handle for interacting with ARM. |
39 | */ | 39 | */ |
40 | struct GNUNET_ARM_MonitorHandle { | 40 | struct GNUNET_ARM_MonitorHandle |
41 | { | ||
41 | /** | 42 | /** |
42 | * Our control connection to the ARM service. | 43 | * Our control connection to the ARM service. |
43 | */ | 44 | */ |
@@ -77,7 +78,7 @@ struct GNUNET_ARM_MonitorHandle { | |||
77 | * @return #GNUNET_OK on success | 78 | * @return #GNUNET_OK on success |
78 | */ | 79 | */ |
79 | static int | 80 | static int |
80 | reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h); | 81 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h); |
81 | 82 | ||
82 | 83 | ||
83 | /** | 84 | /** |
@@ -86,14 +87,14 @@ reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h); | |||
86 | * @param cls the `struct GNUNET_ARM_MonitorHandle` | 87 | * @param cls the `struct GNUNET_ARM_MonitorHandle` |
87 | */ | 88 | */ |
88 | static void | 89 | static void |
89 | reconnect_arm_monitor_task(void *cls) | 90 | reconnect_arm_monitor_task (void *cls) |
90 | { | 91 | { |
91 | struct GNUNET_ARM_MonitorHandle *h = cls; | 92 | struct GNUNET_ARM_MonitorHandle *h = cls; |
92 | 93 | ||
93 | h->reconnect_task = NULL; | 94 | h->reconnect_task = NULL; |
94 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 95 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
95 | "Connecting to ARM service for monitoring after delay\n"); | 96 | "Connecting to ARM service for monitoring after delay\n"); |
96 | GNUNET_break(GNUNET_OK == reconnect_arm_monitor(h)); | 97 | GNUNET_break (GNUNET_OK == reconnect_arm_monitor (h)); |
97 | } | 98 | } |
98 | 99 | ||
99 | 100 | ||
@@ -104,18 +105,18 @@ reconnect_arm_monitor_task(void *cls) | |||
104 | * @param h our handle | 105 | * @param h our handle |
105 | */ | 106 | */ |
106 | static void | 107 | static void |
107 | reconnect_arm_monitor_later(struct GNUNET_ARM_MonitorHandle *h) | 108 | reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h) |
108 | { | 109 | { |
109 | if (NULL != h->mq) | 110 | if (NULL != h->mq) |
110 | { | 111 | { |
111 | GNUNET_MQ_destroy(h->mq); | 112 | GNUNET_MQ_destroy (h->mq); |
112 | h->mq = NULL; | 113 | h->mq = NULL; |
113 | } | 114 | } |
114 | GNUNET_assert(NULL == h->reconnect_task); | 115 | GNUNET_assert (NULL == h->reconnect_task); |
115 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed(h->retry_backoff, | 116 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, |
116 | &reconnect_arm_monitor_task, | 117 | &reconnect_arm_monitor_task, |
117 | h); | 118 | h); |
118 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF(h->retry_backoff); | 119 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); |
119 | } | 120 | } |
120 | 121 | ||
121 | 122 | ||
@@ -127,18 +128,18 @@ reconnect_arm_monitor_later(struct GNUNET_ARM_MonitorHandle *h) | |||
127 | * @return #GNUNET_OK if the message is well-formed | 128 | * @return #GNUNET_OK if the message is well-formed |
128 | */ | 129 | */ |
129 | static int | 130 | static int |
130 | check_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *msg) | 131 | check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg) |
131 | { | 132 | { |
132 | size_t sl = | 133 | size_t sl = |
133 | ntohs(msg->header.size) - sizeof(struct GNUNET_ARM_StatusMessage); | 134 | ntohs (msg->header.size) - sizeof(struct GNUNET_ARM_StatusMessage); |
134 | const char *name = (const char *)&msg[1]; | 135 | const char *name = (const char *) &msg[1]; |
135 | 136 | ||
136 | (void)cls; | 137 | (void) cls; |
137 | if ((0 == sl) || ('\0' != name[sl - 1])) | 138 | if ((0 == sl) || ('\0' != name[sl - 1])) |
138 | { | 139 | { |
139 | GNUNET_break(0); | 140 | GNUNET_break (0); |
140 | return GNUNET_SYSERR; | 141 | return GNUNET_SYSERR; |
141 | } | 142 | } |
142 | return GNUNET_OK; | 143 | return GNUNET_OK; |
143 | } | 144 | } |
144 | 145 | ||
@@ -150,18 +151,18 @@ check_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *msg) | |||
150 | * @param res the message received from the arm service | 151 | * @param res the message received from the arm service |
151 | */ | 152 | */ |
152 | static void | 153 | static void |
153 | handle_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *res) | 154 | handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res) |
154 | { | 155 | { |
155 | struct GNUNET_ARM_MonitorHandle *h = cls; | 156 | struct GNUNET_ARM_MonitorHandle *h = cls; |
156 | enum GNUNET_ARM_ServiceMonitorStatus status; | 157 | enum GNUNET_ARM_ServiceMonitorStatus status; |
157 | 158 | ||
158 | status = (enum GNUNET_ARM_ServiceMonitorStatus)ntohl(res->status); | 159 | status = (enum GNUNET_ARM_ServiceMonitorStatus) ntohl (res->status); |
159 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 160 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
160 | "Received notification from ARM for service `%s' with status %d\n", | 161 | "Received notification from ARM for service `%s' with status %d\n", |
161 | (const char *)&res[1], | 162 | (const char *) &res[1], |
162 | (int)status); | 163 | (int) status); |
163 | if (NULL != h->service_status) | 164 | if (NULL != h->service_status) |
164 | h->service_status(h->service_status_cls, (const char *)&res[1], status); | 165 | h->service_status (h->service_status_cls, (const char *) &res[1], status); |
165 | } | 166 | } |
166 | 167 | ||
167 | 168 | ||
@@ -174,12 +175,12 @@ handle_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *res) | |||
174 | * @param error error code | 175 | * @param error error code |
175 | */ | 176 | */ |
176 | static void | 177 | static void |
177 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | 178 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
178 | { | 179 | { |
179 | struct GNUNET_ARM_MonitorHandle *h = cls; | 180 | struct GNUNET_ARM_MonitorHandle *h = cls; |
180 | 181 | ||
181 | (void)error; | 182 | (void) error; |
182 | reconnect_arm_monitor_later(h); | 183 | reconnect_arm_monitor_later (h); |
183 | } | 184 | } |
184 | 185 | ||
185 | 186 | ||
@@ -190,29 +191,29 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | |||
190 | * @return #GNUNET_OK on success | 191 | * @return #GNUNET_OK on success |
191 | */ | 192 | */ |
192 | static int | 193 | static int |
193 | reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h) | 194 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) |
194 | { | 195 | { |
195 | struct GNUNET_MQ_MessageHandler handlers[] = | 196 | struct GNUNET_MQ_MessageHandler handlers[] = |
196 | { GNUNET_MQ_hd_var_size(monitor_notify, | 197 | { GNUNET_MQ_hd_var_size (monitor_notify, |
197 | GNUNET_MESSAGE_TYPE_ARM_STATUS, | 198 | GNUNET_MESSAGE_TYPE_ARM_STATUS, |
198 | struct GNUNET_ARM_StatusMessage, | 199 | struct GNUNET_ARM_StatusMessage, |
199 | h), | 200 | h), |
200 | GNUNET_MQ_handler_end() }; | 201 | GNUNET_MQ_handler_end () }; |
201 | struct GNUNET_MessageHeader *msg; | 202 | struct GNUNET_MessageHeader *msg; |
202 | struct GNUNET_MQ_Envelope *env; | 203 | struct GNUNET_MQ_Envelope *env; |
203 | 204 | ||
204 | GNUNET_assert(NULL == h->mq); | 205 | GNUNET_assert (NULL == h->mq); |
205 | h->mq = GNUNET_CLIENT_connect(h->cfg, "arm", handlers, &mq_error_handler, h); | 206 | h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h); |
206 | if (NULL == h->mq) | 207 | if (NULL == h->mq) |
207 | { | 208 | { |
208 | if (NULL != h->service_status) | 209 | if (NULL != h->service_status) |
209 | h->service_status(h->service_status_cls, | 210 | h->service_status (h->service_status_cls, |
210 | NULL, | 211 | NULL, |
211 | GNUNET_ARM_SERVICE_STOPPED); | 212 | GNUNET_ARM_SERVICE_STOPPED); |
212 | return GNUNET_SYSERR; | 213 | return GNUNET_SYSERR; |
213 | } | 214 | } |
214 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR); | 215 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR); |
215 | GNUNET_MQ_send(h->mq, env); | 216 | GNUNET_MQ_send (h->mq, env); |
216 | return GNUNET_OK; | 217 | return GNUNET_OK; |
217 | } | 218 | } |
218 | 219 | ||
@@ -229,21 +230,21 @@ reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h) | |||
229 | * @return context to use for further ARM monitor operations, NULL on error. | 230 | * @return context to use for further ARM monitor operations, NULL on error. |
230 | */ | 231 | */ |
231 | struct GNUNET_ARM_MonitorHandle * | 232 | struct GNUNET_ARM_MonitorHandle * |
232 | GNUNET_ARM_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | 233 | GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
233 | GNUNET_ARM_ServiceMonitorCallback cont, | 234 | GNUNET_ARM_ServiceMonitorCallback cont, |
234 | void *cont_cls) | 235 | void *cont_cls) |
235 | { | 236 | { |
236 | struct GNUNET_ARM_MonitorHandle *h; | 237 | struct GNUNET_ARM_MonitorHandle *h; |
237 | 238 | ||
238 | h = GNUNET_new(struct GNUNET_ARM_MonitorHandle); | 239 | h = GNUNET_new (struct GNUNET_ARM_MonitorHandle); |
239 | h->cfg = cfg; | 240 | h->cfg = cfg; |
240 | h->service_status = cont; | 241 | h->service_status = cont; |
241 | h->service_status_cls = cont_cls; | 242 | h->service_status_cls = cont_cls; |
242 | if (GNUNET_OK != reconnect_arm_monitor(h)) | 243 | if (GNUNET_OK != reconnect_arm_monitor (h)) |
243 | { | 244 | { |
244 | GNUNET_free(h); | 245 | GNUNET_free (h); |
245 | return NULL; | 246 | return NULL; |
246 | } | 247 | } |
247 | return h; | 248 | return h; |
248 | } | 249 | } |
249 | 250 | ||
@@ -254,19 +255,19 @@ GNUNET_ARM_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
254 | * @param h the handle that was being used | 255 | * @param h the handle that was being used |
255 | */ | 256 | */ |
256 | void | 257 | void |
257 | GNUNET_ARM_monitor_stop(struct GNUNET_ARM_MonitorHandle *h) | 258 | GNUNET_ARM_monitor_stop (struct GNUNET_ARM_MonitorHandle *h) |
258 | { | 259 | { |
259 | if (NULL != h->mq) | 260 | if (NULL != h->mq) |
260 | { | 261 | { |
261 | GNUNET_MQ_destroy(h->mq); | 262 | GNUNET_MQ_destroy (h->mq); |
262 | h->mq = NULL; | 263 | h->mq = NULL; |
263 | } | 264 | } |
264 | if (NULL != h->reconnect_task) | 265 | if (NULL != h->reconnect_task) |
265 | { | 266 | { |
266 | GNUNET_SCHEDULER_cancel(h->reconnect_task); | 267 | GNUNET_SCHEDULER_cancel (h->reconnect_task); |
267 | h->reconnect_task = NULL; | 268 | h->reconnect_task = NULL; |
268 | } | 269 | } |
269 | GNUNET_free(h); | 270 | GNUNET_free (h); |
270 | } | 271 | } |
271 | 272 | ||
272 | 273 | ||