diff options
Diffstat (limited to 'src/arm/arm_api.c')
-rw-r--r-- | src/arm/arm_api.c | 710 |
1 files changed, 354 insertions, 356 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index bf0acbcb9..b42c95dc0 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file arm/arm_api.c | 22 | * @file arm/arm_api.c |
@@ -30,15 +30,14 @@ | |||
30 | #include "gnunet_protocols.h" | 30 | #include "gnunet_protocols.h" |
31 | #include "arm.h" | 31 | #include "arm.h" |
32 | 32 | ||
33 | #define LOG(kind, ...) GNUNET_log_from (kind, "arm-api", __VA_ARGS__) | 33 | #define LOG(kind, ...) GNUNET_log_from(kind, "arm-api", __VA_ARGS__) |
34 | 34 | ||
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Entry in a doubly-linked list of operations awaiting for replies | 37 | * Entry in a doubly-linked list of operations awaiting for replies |
38 | * (in-order) from the ARM service. | 38 | * (in-order) from the ARM service. |
39 | */ | 39 | */ |
40 | struct GNUNET_ARM_Operation | 40 | struct GNUNET_ARM_Operation { |
41 | { | ||
42 | /** | 41 | /** |
43 | * This is a doubly-linked list. | 42 | * This is a doubly-linked list. |
44 | */ | 43 | */ |
@@ -94,8 +93,7 @@ struct GNUNET_ARM_Operation | |||
94 | /** | 93 | /** |
95 | * Handle for interacting with ARM. | 94 | * Handle for interacting with ARM. |
96 | */ | 95 | */ |
97 | struct GNUNET_ARM_Handle | 96 | struct GNUNET_ARM_Handle { |
98 | { | ||
99 | /** | 97 | /** |
100 | * Our connection to the ARM service. | 98 | * Our connection to the ARM service. |
101 | */ | 99 | */ |
@@ -166,7 +164,7 @@ struct GNUNET_ARM_Handle | |||
166 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 164 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
167 | */ | 165 | */ |
168 | static int | 166 | static int |
169 | reconnect_arm (struct GNUNET_ARM_Handle *h); | 167 | reconnect_arm(struct GNUNET_ARM_Handle *h); |
170 | 168 | ||
171 | 169 | ||
172 | /** | 170 | /** |
@@ -175,12 +173,12 @@ reconnect_arm (struct GNUNET_ARM_Handle *h); | |||
175 | * @param cls the `struct GNUNET_ARM_Handle` | 173 | * @param cls the `struct GNUNET_ARM_Handle` |
176 | */ | 174 | */ |
177 | static void | 175 | static void |
178 | reconnect_arm_task (void *cls) | 176 | reconnect_arm_task(void *cls) |
179 | { | 177 | { |
180 | struct GNUNET_ARM_Handle *h = cls; | 178 | struct GNUNET_ARM_Handle *h = cls; |
181 | 179 | ||
182 | h->reconnect_task = NULL; | 180 | h->reconnect_task = NULL; |
183 | reconnect_arm (h); | 181 | reconnect_arm(h); |
184 | } | 182 | } |
185 | 183 | ||
186 | 184 | ||
@@ -191,31 +189,31 @@ reconnect_arm_task (void *cls) | |||
191 | * @param h our handle | 189 | * @param h our handle |
192 | */ | 190 | */ |
193 | static void | 191 | static void |
194 | reconnect_arm_later (struct GNUNET_ARM_Handle *h) | 192 | reconnect_arm_later(struct GNUNET_ARM_Handle *h) |
195 | { | 193 | { |
196 | struct GNUNET_ARM_Operation *op; | 194 | struct GNUNET_ARM_Operation *op; |
197 | 195 | ||
198 | if (NULL != h->mq) | 196 | if (NULL != h->mq) |
199 | { | 197 | { |
200 | GNUNET_MQ_destroy (h->mq); | 198 | GNUNET_MQ_destroy(h->mq); |
201 | h->mq = NULL; | 199 | h->mq = NULL; |
202 | } | 200 | } |
203 | h->currently_up = GNUNET_NO; | 201 | h->currently_up = GNUNET_NO; |
204 | GNUNET_assert (NULL == h->reconnect_task); | 202 | GNUNET_assert(NULL == h->reconnect_task); |
205 | h->reconnect_task = | 203 | h->reconnect_task = |
206 | GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_task, h); | 204 | GNUNET_SCHEDULER_add_delayed(h->retry_backoff, &reconnect_arm_task, h); |
207 | while (NULL != (op = h->operation_pending_head)) | 205 | while (NULL != (op = h->operation_pending_head)) |
208 | { | 206 | { |
209 | if (NULL != op->result_cont) | 207 | if (NULL != op->result_cont) |
210 | op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); | 208 | op->result_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); |
211 | if (NULL != op->list_cont) | 209 | if (NULL != op->list_cont) |
212 | op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); | 210 | op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); |
213 | GNUNET_ARM_operation_cancel (op); | 211 | GNUNET_ARM_operation_cancel(op); |
214 | } | 212 | } |
215 | GNUNET_assert (NULL == h->operation_pending_head); | 213 | GNUNET_assert(NULL == h->operation_pending_head); |
216 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); | 214 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF(h->retry_backoff); |
217 | if (NULL != h->conn_status) | 215 | if (NULL != h->conn_status) |
218 | h->conn_status (h->conn_status_cls, GNUNET_NO); | 216 | h->conn_status(h->conn_status_cls, GNUNET_NO); |
219 | } | 217 | } |
220 | 218 | ||
221 | 219 | ||
@@ -227,7 +225,7 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h) | |||
227 | * @return NULL if not found | 225 | * @return NULL if not found |
228 | */ | 226 | */ |
229 | static struct GNUNET_ARM_Operation * | 227 | static struct GNUNET_ARM_Operation * |
230 | find_op_by_id (struct GNUNET_ARM_Handle *h, uint64_t id) | 228 | find_op_by_id(struct GNUNET_ARM_Handle *h, uint64_t id) |
231 | { | 229 | { |
232 | struct GNUNET_ARM_Operation *result; | 230 | struct GNUNET_ARM_Operation *result; |
233 | 231 | ||
@@ -246,7 +244,7 @@ find_op_by_id (struct GNUNET_ARM_Handle *h, uint64_t id) | |||
246 | * @param res the message received from the arm service | 244 | * @param res the message received from the arm service |
247 | */ | 245 | */ |
248 | static void | 246 | static void |
249 | handle_arm_result (void *cls, const struct GNUNET_ARM_ResultMessage *res) | 247 | handle_arm_result(void *cls, const struct GNUNET_ARM_ResultMessage *res) |
250 | { | 248 | { |
251 | struct GNUNET_ARM_Handle *h = cls; | 249 | struct GNUNET_ARM_Handle *h = cls; |
252 | struct GNUNET_ARM_Operation *op; | 250 | struct GNUNET_ARM_Operation *op; |
@@ -255,43 +253,43 @@ handle_arm_result (void *cls, const struct GNUNET_ARM_ResultMessage *res) | |||
255 | GNUNET_ARM_ResultCallback result_cont; | 253 | GNUNET_ARM_ResultCallback result_cont; |
256 | void *result_cont_cls; | 254 | void *result_cont_cls; |
257 | 255 | ||
258 | id = GNUNET_ntohll (res->arm_msg.request_id); | 256 | id = GNUNET_ntohll(res->arm_msg.request_id); |
259 | op = find_op_by_id (h, id); | 257 | op = find_op_by_id(h, id); |
260 | if (NULL == op) | 258 | if (NULL == op) |
261 | { | 259 | { |
262 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 260 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
263 | "Message with unknown id %llu\n", | 261 | "Message with unknown id %llu\n", |
264 | (unsigned long long) id); | 262 | (unsigned long long)id); |
265 | return; | 263 | return; |
266 | } | 264 | } |
267 | 265 | ||
268 | result = (enum GNUNET_ARM_Result) ntohl (res->result); | 266 | result = (enum GNUNET_ARM_Result)ntohl(res->result); |
269 | if ((GNUNET_YES == op->is_arm_stop) && (GNUNET_ARM_RESULT_STOPPING == result)) | 267 | if ((GNUNET_YES == op->is_arm_stop) && (GNUNET_ARM_RESULT_STOPPING == result)) |
270 | { | ||
271 | /* special case: if we are stopping 'gnunet-service-arm', we do not just | ||
272 | wait for the result message, but also wait for the service to close | ||
273 | the connection (and then we have to close our client handle as well); | ||
274 | this is done by installing a different receive handler, waiting for | ||
275 | the connection to go down */ | ||
276 | if (NULL != h->thm) | ||
277 | { | 268 | { |
278 | GNUNET_break (0); | 269 | /* special case: if we are stopping 'gnunet-service-arm', we do not just |
279 | op->result_cont (h->thm->cont_cls, | 270 | wait for the result message, but also wait for the service to close |
280 | GNUNET_ARM_REQUEST_SENT_OK, | 271 | the connection (and then we have to close our client handle as well); |
281 | GNUNET_ARM_RESULT_IS_NOT_KNOWN); | 272 | this is done by installing a different receive handler, waiting for |
282 | GNUNET_free (h->thm); | 273 | the connection to go down */ |
274 | if (NULL != h->thm) | ||
275 | { | ||
276 | GNUNET_break(0); | ||
277 | op->result_cont(h->thm->cont_cls, | ||
278 | GNUNET_ARM_REQUEST_SENT_OK, | ||
279 | GNUNET_ARM_RESULT_IS_NOT_KNOWN); | ||
280 | GNUNET_free(h->thm); | ||
281 | } | ||
282 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, | ||
283 | h->operation_pending_tail, | ||
284 | op); | ||
285 | h->thm = op; | ||
286 | return; | ||
283 | } | 287 | } |
284 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, | ||
285 | h->operation_pending_tail, | ||
286 | op); | ||
287 | h->thm = op; | ||
288 | return; | ||
289 | } | ||
290 | result_cont = op->result_cont; | 288 | result_cont = op->result_cont; |
291 | result_cont_cls = op->cont_cls; | 289 | result_cont_cls = op->cont_cls; |
292 | GNUNET_ARM_operation_cancel (op); | 290 | GNUNET_ARM_operation_cancel(op); |
293 | if (NULL != result_cont) | 291 | if (NULL != result_cont) |
294 | result_cont (result_cont_cls, GNUNET_ARM_REQUEST_SENT_OK, result); | 292 | result_cont(result_cont_cls, GNUNET_ARM_REQUEST_SENT_OK, result); |
295 | } | 293 | } |
296 | 294 | ||
297 | 295 | ||
@@ -303,27 +301,27 @@ handle_arm_result (void *cls, const struct GNUNET_ARM_ResultMessage *res) | |||
303 | * @return #GNUNET_OK if message is well-formed | 301 | * @return #GNUNET_OK if message is well-formed |
304 | */ | 302 | */ |
305 | static int | 303 | static int |
306 | check_arm_list_result (void *cls, | 304 | check_arm_list_result(void *cls, |
307 | const struct GNUNET_ARM_ListResultMessage *lres) | 305 | const struct GNUNET_ARM_ListResultMessage *lres) |
308 | { | 306 | { |
309 | const char *pos = (const char *) &lres[1]; | 307 | const char *pos = (const char *)&lres[1]; |
310 | uint16_t rcount = ntohs (lres->count); | 308 | uint16_t rcount = ntohs(lres->count); |
311 | uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof (*lres); | 309 | uint16_t msize = ntohs(lres->arm_msg.header.size) - sizeof(*lres); |
312 | uint16_t size_check; | 310 | uint16_t size_check; |
313 | 311 | ||
314 | (void) cls; | 312 | (void)cls; |
315 | size_check = 0; | 313 | size_check = 0; |
316 | for (unsigned int i = 0; i < rcount; i++) | 314 | for (unsigned int i = 0; i < rcount; i++) |
317 | { | ||
318 | const char *end = memchr (pos, 0, msize - size_check); | ||
319 | if (NULL == end) | ||
320 | { | 315 | { |
321 | GNUNET_break (0); | 316 | const char *end = memchr(pos, 0, msize - size_check); |
322 | return GNUNET_SYSERR; | 317 | if (NULL == end) |
318 | { | ||
319 | GNUNET_break(0); | ||
320 | return GNUNET_SYSERR; | ||
321 | } | ||
322 | size_check += (end - pos) + 1; | ||
323 | pos = end + 1; | ||
323 | } | 324 | } |
324 | size_check += (end - pos) + 1; | ||
325 | pos = end + 1; | ||
326 | } | ||
327 | return GNUNET_OK; | 325 | return GNUNET_OK; |
328 | } | 326 | } |
329 | 327 | ||
@@ -335,41 +333,41 @@ check_arm_list_result (void *cls, | |||
335 | * @param lres the message received from the arm service | 333 | * @param lres the message received from the arm service |
336 | */ | 334 | */ |
337 | static void | 335 | static void |
338 | handle_arm_list_result (void *cls, | 336 | handle_arm_list_result(void *cls, |
339 | const struct GNUNET_ARM_ListResultMessage *lres) | 337 | const struct GNUNET_ARM_ListResultMessage *lres) |
340 | { | 338 | { |
341 | struct GNUNET_ARM_Handle *h = cls; | 339 | struct GNUNET_ARM_Handle *h = cls; |
342 | uint16_t rcount = ntohs (lres->count); | 340 | uint16_t rcount = ntohs(lres->count); |
343 | const char *list[rcount]; | 341 | const char *list[rcount]; |
344 | const char *pos = (const char *) &lres[1]; | 342 | const char *pos = (const char *)&lres[1]; |
345 | uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof (*lres); | 343 | uint16_t msize = ntohs(lres->arm_msg.header.size) - sizeof(*lres); |
346 | struct GNUNET_ARM_Operation *op; | 344 | struct GNUNET_ARM_Operation *op; |
347 | uint16_t size_check; | 345 | uint16_t size_check; |
348 | uint64_t id; | 346 | uint64_t id; |
349 | 347 | ||
350 | id = GNUNET_ntohll (lres->arm_msg.request_id); | 348 | id = GNUNET_ntohll(lres->arm_msg.request_id); |
351 | op = find_op_by_id (h, id); | 349 | op = find_op_by_id(h, id); |
352 | if (NULL == op) | 350 | if (NULL == op) |
353 | { | 351 | { |
354 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 352 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
355 | "Message with unknown id %llu\n", | 353 | "Message with unknown id %llu\n", |
356 | (unsigned long long) id); | 354 | (unsigned long long)id); |
357 | return; | 355 | return; |
358 | } | 356 | } |
359 | size_check = 0; | 357 | size_check = 0; |
360 | for (unsigned int i = 0; i < rcount; i++) | 358 | for (unsigned int i = 0; i < rcount; i++) |
361 | { | 359 | { |
362 | const char *end = memchr (pos, 0, msize - size_check); | 360 | const char *end = memchr(pos, 0, msize - size_check); |
363 | 361 | ||
364 | /* Assert, as this was already checked in #check_arm_list_result() */ | 362 | /* Assert, as this was already checked in #check_arm_list_result() */ |
365 | GNUNET_assert (NULL != end); | 363 | GNUNET_assert(NULL != end); |
366 | list[i] = pos; | 364 | list[i] = pos; |
367 | size_check += (end - pos) + 1; | 365 | size_check += (end - pos) + 1; |
368 | pos = end + 1; | 366 | pos = end + 1; |
369 | } | 367 | } |
370 | if (NULL != op->list_cont) | 368 | if (NULL != op->list_cont) |
371 | op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, rcount, list); | 369 | op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, rcount, list); |
372 | GNUNET_ARM_operation_cancel (op); | 370 | GNUNET_ARM_operation_cancel(op); |
373 | } | 371 | } |
374 | 372 | ||
375 | 373 | ||
@@ -380,18 +378,18 @@ handle_arm_list_result (void *cls, | |||
380 | * @param msg message received | 378 | * @param msg message received |
381 | */ | 379 | */ |
382 | static void | 380 | static void |
383 | handle_confirm (void *cls, const struct GNUNET_MessageHeader *msg) | 381 | handle_confirm(void *cls, const struct GNUNET_MessageHeader *msg) |
384 | { | 382 | { |
385 | struct GNUNET_ARM_Handle *h = cls; | 383 | struct GNUNET_ARM_Handle *h = cls; |
386 | 384 | ||
387 | (void) msg; | 385 | (void)msg; |
388 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Got confirmation from ARM that we are up!\n"); | 386 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Got confirmation from ARM that we are up!\n"); |
389 | if (GNUNET_NO == h->currently_up) | 387 | if (GNUNET_NO == h->currently_up) |
390 | { | 388 | { |
391 | h->currently_up = GNUNET_YES; | 389 | h->currently_up = GNUNET_YES; |
392 | if (NULL != h->conn_status) | 390 | if (NULL != h->conn_status) |
393 | h->conn_status (h->conn_status_cls, GNUNET_YES); | 391 | h->conn_status(h->conn_status_cls, GNUNET_YES); |
394 | } | 392 | } |
395 | } | 393 | } |
396 | 394 | ||
397 | 395 | ||
@@ -404,22 +402,22 @@ handle_confirm (void *cls, const struct GNUNET_MessageHeader *msg) | |||
404 | * @param error error code | 402 | * @param error error code |
405 | */ | 403 | */ |
406 | static void | 404 | static void |
407 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 405 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
408 | { | 406 | { |
409 | struct GNUNET_ARM_Handle *h = cls; | 407 | struct GNUNET_ARM_Handle *h = cls; |
410 | struct GNUNET_ARM_Operation *op; | 408 | struct GNUNET_ARM_Operation *op; |
411 | 409 | ||
412 | (void) error; | 410 | (void)error; |
413 | h->currently_up = GNUNET_NO; | 411 | h->currently_up = GNUNET_NO; |
414 | if (NULL != (op = h->thm)) | 412 | if (NULL != (op = h->thm)) |
415 | { | 413 | { |
416 | h->thm = NULL; | 414 | h->thm = NULL; |
417 | op->result_cont (op->cont_cls, | 415 | op->result_cont(op->cont_cls, |
418 | GNUNET_ARM_REQUEST_SENT_OK, | 416 | GNUNET_ARM_REQUEST_SENT_OK, |
419 | GNUNET_ARM_RESULT_STOPPED); | 417 | GNUNET_ARM_RESULT_STOPPED); |
420 | GNUNET_free (op); | 418 | GNUNET_free(op); |
421 | } | 419 | } |
422 | reconnect_arm_later (h); | 420 | reconnect_arm_later(h); |
423 | } | 421 | } |
424 | 422 | ||
425 | 423 | ||
@@ -430,39 +428,39 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
430 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 428 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
431 | */ | 429 | */ |
432 | static int | 430 | static int |
433 | reconnect_arm (struct GNUNET_ARM_Handle *h) | 431 | reconnect_arm(struct GNUNET_ARM_Handle *h) |
434 | { | 432 | { |
435 | struct GNUNET_MQ_MessageHandler handlers[] = | 433 | struct GNUNET_MQ_MessageHandler handlers[] = |
436 | {GNUNET_MQ_hd_fixed_size (arm_result, | 434 | { GNUNET_MQ_hd_fixed_size(arm_result, |
437 | GNUNET_MESSAGE_TYPE_ARM_RESULT, | 435 | GNUNET_MESSAGE_TYPE_ARM_RESULT, |
438 | struct GNUNET_ARM_ResultMessage, | 436 | struct GNUNET_ARM_ResultMessage, |
439 | h), | 437 | h), |
440 | GNUNET_MQ_hd_var_size (arm_list_result, | 438 | GNUNET_MQ_hd_var_size(arm_list_result, |
441 | GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, | 439 | GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, |
442 | struct GNUNET_ARM_ListResultMessage, | 440 | struct GNUNET_ARM_ListResultMessage, |
441 | h), | ||
442 | GNUNET_MQ_hd_fixed_size(confirm, | ||
443 | GNUNET_MESSAGE_TYPE_ARM_TEST, | ||
444 | struct GNUNET_MessageHeader, | ||
443 | h), | 445 | h), |
444 | GNUNET_MQ_hd_fixed_size (confirm, | 446 | GNUNET_MQ_handler_end() }; |
445 | GNUNET_MESSAGE_TYPE_ARM_TEST, | ||
446 | struct GNUNET_MessageHeader, | ||
447 | h), | ||
448 | GNUNET_MQ_handler_end ()}; | ||
449 | struct GNUNET_MessageHeader *test; | 447 | struct GNUNET_MessageHeader *test; |
450 | struct GNUNET_MQ_Envelope *env; | 448 | struct GNUNET_MQ_Envelope *env; |
451 | 449 | ||
452 | if (NULL != h->mq) | 450 | if (NULL != h->mq) |
453 | return GNUNET_OK; | 451 | return GNUNET_OK; |
454 | GNUNET_assert (GNUNET_NO == h->currently_up); | 452 | GNUNET_assert(GNUNET_NO == h->currently_up); |
455 | h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h); | 453 | h->mq = GNUNET_CLIENT_connect(h->cfg, "arm", handlers, &mq_error_handler, h); |
456 | if (NULL == h->mq) | 454 | if (NULL == h->mq) |
457 | { | 455 | { |
458 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CLIENT_connect returned NULL\n"); | 456 | LOG(GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CLIENT_connect returned NULL\n"); |
459 | if (NULL != h->conn_status) | 457 | if (NULL != h->conn_status) |
460 | h->conn_status (h->conn_status_cls, GNUNET_SYSERR); | 458 | h->conn_status(h->conn_status_cls, GNUNET_SYSERR); |
461 | return GNUNET_SYSERR; | 459 | return GNUNET_SYSERR; |
462 | } | 460 | } |
463 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending TEST message to ARM\n"); | 461 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending TEST message to ARM\n"); |
464 | env = GNUNET_MQ_msg (test, GNUNET_MESSAGE_TYPE_ARM_TEST); | 462 | env = GNUNET_MQ_msg(test, GNUNET_MESSAGE_TYPE_ARM_TEST); |
465 | GNUNET_MQ_send (h->mq, env); | 463 | GNUNET_MQ_send(h->mq, env); |
466 | return GNUNET_OK; | 464 | return GNUNET_OK; |
467 | } | 465 | } |
468 | 466 | ||
@@ -479,21 +477,21 @@ reconnect_arm (struct GNUNET_ARM_Handle *h) | |||
479 | * @return context to use for further ARM operations, NULL on error. | 477 | * @return context to use for further ARM operations, NULL on error. |
480 | */ | 478 | */ |
481 | struct GNUNET_ARM_Handle * | 479 | struct GNUNET_ARM_Handle * |
482 | GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 480 | GNUNET_ARM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, |
483 | GNUNET_ARM_ConnectionStatusCallback conn_status, | 481 | GNUNET_ARM_ConnectionStatusCallback conn_status, |
484 | void *conn_status_cls) | 482 | void *conn_status_cls) |
485 | { | 483 | { |
486 | struct GNUNET_ARM_Handle *h; | 484 | struct GNUNET_ARM_Handle *h; |
487 | 485 | ||
488 | h = GNUNET_new (struct GNUNET_ARM_Handle); | 486 | h = GNUNET_new(struct GNUNET_ARM_Handle); |
489 | h->cfg = cfg; | 487 | h->cfg = cfg; |
490 | h->conn_status = conn_status; | 488 | h->conn_status = conn_status; |
491 | h->conn_status_cls = conn_status_cls; | 489 | h->conn_status_cls = conn_status_cls; |
492 | if (GNUNET_OK != reconnect_arm (h)) | 490 | if (GNUNET_OK != reconnect_arm(h)) |
493 | { | 491 | { |
494 | GNUNET_free (h); | 492 | GNUNET_free(h); |
495 | return NULL; | 493 | return NULL; |
496 | } | 494 | } |
497 | return h; | 495 | return h; |
498 | } | 496 | } |
499 | 497 | ||
@@ -504,38 +502,38 @@ GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
504 | * @param h the handle that was being used | 502 | * @param h the handle that was being used |
505 | */ | 503 | */ |
506 | void | 504 | void |
507 | GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h) | 505 | GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h) |
508 | { | 506 | { |
509 | struct GNUNET_ARM_Operation *op; | 507 | struct GNUNET_ARM_Operation *op; |
510 | 508 | ||
511 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); | 509 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); |
512 | while (NULL != (op = h->operation_pending_head)) | 510 | while (NULL != (op = h->operation_pending_head)) |
513 | { | ||
514 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, | ||
515 | h->operation_pending_tail, | ||
516 | op); | ||
517 | if (NULL != op->result_cont) | ||
518 | op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); | ||
519 | if (NULL != op->list_cont) | ||
520 | op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); | ||
521 | if (NULL != op->async) | ||
522 | { | 511 | { |
523 | GNUNET_SCHEDULER_cancel (op->async); | 512 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, |
524 | op->async = NULL; | 513 | h->operation_pending_tail, |
514 | op); | ||
515 | if (NULL != op->result_cont) | ||
516 | op->result_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); | ||
517 | if (NULL != op->list_cont) | ||
518 | op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); | ||
519 | if (NULL != op->async) | ||
520 | { | ||
521 | GNUNET_SCHEDULER_cancel(op->async); | ||
522 | op->async = NULL; | ||
523 | } | ||
524 | GNUNET_free(op); | ||
525 | } | 525 | } |
526 | GNUNET_free (op); | ||
527 | } | ||
528 | if (NULL != h->mq) | 526 | if (NULL != h->mq) |
529 | { | 527 | { |
530 | GNUNET_MQ_destroy (h->mq); | 528 | GNUNET_MQ_destroy(h->mq); |
531 | h->mq = NULL; | 529 | h->mq = NULL; |
532 | } | 530 | } |
533 | if (NULL != h->reconnect_task) | 531 | if (NULL != h->reconnect_task) |
534 | { | 532 | { |
535 | GNUNET_SCHEDULER_cancel (h->reconnect_task); | 533 | GNUNET_SCHEDULER_cancel(h->reconnect_task); |
536 | h->reconnect_task = NULL; | 534 | h->reconnect_task = NULL; |
537 | } | 535 | } |
538 | GNUNET_free (h); | 536 | GNUNET_free(h); |
539 | } | 537 | } |
540 | 538 | ||
541 | 539 | ||
@@ -548,8 +546,8 @@ GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h) | |||
548 | * @return operation status code | 546 | * @return operation status code |
549 | */ | 547 | */ |
550 | static enum GNUNET_ARM_Result | 548 | static enum GNUNET_ARM_Result |
551 | start_arm_service (struct GNUNET_ARM_Handle *h, | 549 | start_arm_service(struct GNUNET_ARM_Handle *h, |
552 | enum GNUNET_OS_InheritStdioFlags std_inheritance) | 550 | enum GNUNET_OS_InheritStdioFlags std_inheritance) |
553 | { | 551 | { |
554 | struct GNUNET_OS_Process *proc; | 552 | struct GNUNET_OS_Process *proc; |
555 | char *cbinary; | 553 | char *cbinary; |
@@ -559,98 +557,98 @@ start_arm_service (struct GNUNET_ARM_Handle *h, | |||
559 | char *loprefix; | 557 | char *loprefix; |
560 | char *lopostfix; | 558 | char *lopostfix; |
561 | 559 | ||
562 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, | 560 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(h->cfg, |
563 | "arm", | 561 | "arm", |
564 | "PREFIX", | 562 | "PREFIX", |
565 | &loprefix)) | 563 | &loprefix)) |
566 | loprefix = GNUNET_strdup (""); | 564 | loprefix = GNUNET_strdup(""); |
567 | else | 565 | else |
568 | loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, loprefix); | 566 | loprefix = GNUNET_CONFIGURATION_expand_dollar(h->cfg, loprefix); |
569 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, | 567 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(h->cfg, |
570 | "arm", | 568 | "arm", |
571 | "OPTIONS", | 569 | "OPTIONS", |
572 | &lopostfix)) | 570 | &lopostfix)) |
573 | lopostfix = GNUNET_strdup (""); | 571 | lopostfix = GNUNET_strdup(""); |
574 | else | 572 | else |
575 | lopostfix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, lopostfix); | 573 | lopostfix = GNUNET_CONFIGURATION_expand_dollar(h->cfg, lopostfix); |
576 | if (GNUNET_OK != | 574 | if (GNUNET_OK != |
577 | GNUNET_CONFIGURATION_get_value_string (h->cfg, "arm", "BINARY", &cbinary)) | 575 | GNUNET_CONFIGURATION_get_value_string(h->cfg, "arm", "BINARY", &cbinary)) |
578 | { | 576 | { |
579 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, "arm", "BINARY"); | 577 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, "arm", "BINARY"); |
580 | GNUNET_free (loprefix); | 578 | GNUNET_free(loprefix); |
581 | GNUNET_free (lopostfix); | 579 | GNUNET_free(lopostfix); |
582 | return GNUNET_ARM_RESULT_IS_NOT_KNOWN; | 580 | return GNUNET_ARM_RESULT_IS_NOT_KNOWN; |
583 | } | 581 | } |
584 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, | 582 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(h->cfg, |
585 | "arm", | 583 | "arm", |
586 | "CONFIG", | 584 | "CONFIG", |
587 | &config)) | 585 | &config)) |
588 | config = NULL; | 586 | config = NULL; |
589 | binary = GNUNET_OS_get_libexec_binary_path (cbinary); | 587 | binary = GNUNET_OS_get_libexec_binary_path(cbinary); |
590 | GNUNET_asprintf ("edbinary, "\"%s\"", binary); | 588 | GNUNET_asprintf("edbinary, "\"%s\"", binary); |
591 | GNUNET_free (cbinary); | 589 | GNUNET_free(cbinary); |
592 | if ((GNUNET_YES == | 590 | if ((GNUNET_YES == |
593 | GNUNET_CONFIGURATION_have_value (h->cfg, "TESTING", "WEAKRANDOM")) && | 591 | GNUNET_CONFIGURATION_have_value(h->cfg, "TESTING", "WEAKRANDOM")) && |
594 | (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (h->cfg, | 592 | (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(h->cfg, |
595 | "TESTING", | 593 | "TESTING", |
596 | "WEAKRANDOM")) && | 594 | "WEAKRANDOM")) && |
597 | (GNUNET_NO == | 595 | (GNUNET_NO == |
598 | GNUNET_CONFIGURATION_have_value (h->cfg, "TESTING", "HOSTFILE"))) | 596 | GNUNET_CONFIGURATION_have_value(h->cfg, "TESTING", "HOSTFILE"))) |
599 | { | 597 | { |
600 | /* Means we are ONLY running locally */ | 598 | /* Means we are ONLY running locally */ |
601 | /* we're clearly running a test, don't daemonize */ | 599 | /* we're clearly running a test, don't daemonize */ |
602 | if (NULL == config) | 600 | if (NULL == config) |
603 | proc = GNUNET_OS_start_process_s (GNUNET_NO, | 601 | proc = GNUNET_OS_start_process_s(GNUNET_NO, |
604 | std_inheritance, | 602 | std_inheritance, |
605 | NULL, | 603 | NULL, |
606 | loprefix, | 604 | loprefix, |
607 | quotedbinary, | 605 | quotedbinary, |
608 | /* no daemonization! */ | 606 | /* no daemonization! */ |
609 | lopostfix, | 607 | lopostfix, |
610 | NULL); | 608 | NULL); |
611 | else | 609 | else |
612 | proc = GNUNET_OS_start_process_s (GNUNET_NO, | 610 | proc = GNUNET_OS_start_process_s(GNUNET_NO, |
613 | std_inheritance, | 611 | std_inheritance, |
614 | NULL, | 612 | NULL, |
615 | loprefix, | 613 | loprefix, |
616 | quotedbinary, | 614 | quotedbinary, |
617 | "-c", | 615 | "-c", |
618 | config, | 616 | config, |
619 | /* no daemonization! */ | 617 | /* no daemonization! */ |
620 | lopostfix, | 618 | lopostfix, |
621 | NULL); | 619 | NULL); |
622 | } | 620 | } |
623 | else | 621 | else |
624 | { | 622 | { |
625 | if (NULL == config) | 623 | if (NULL == config) |
626 | proc = GNUNET_OS_start_process_s (GNUNET_NO, | 624 | proc = GNUNET_OS_start_process_s(GNUNET_NO, |
627 | std_inheritance, | 625 | std_inheritance, |
628 | NULL, | 626 | NULL, |
629 | loprefix, | 627 | loprefix, |
630 | quotedbinary, | 628 | quotedbinary, |
631 | "-d", /* do daemonize */ | 629 | "-d", /* do daemonize */ |
632 | lopostfix, | 630 | lopostfix, |
633 | NULL); | 631 | NULL); |
634 | else | 632 | else |
635 | proc = GNUNET_OS_start_process_s (GNUNET_NO, | 633 | proc = GNUNET_OS_start_process_s(GNUNET_NO, |
636 | std_inheritance, | 634 | std_inheritance, |
637 | NULL, | 635 | NULL, |
638 | loprefix, | 636 | loprefix, |
639 | quotedbinary, | 637 | quotedbinary, |
640 | "-c", | 638 | "-c", |
641 | config, | 639 | config, |
642 | "-d", /* do daemonize */ | 640 | "-d", /* do daemonize */ |
643 | lopostfix, | 641 | lopostfix, |
644 | NULL); | 642 | NULL); |
645 | } | 643 | } |
646 | GNUNET_free (binary); | 644 | GNUNET_free(binary); |
647 | GNUNET_free (quotedbinary); | 645 | GNUNET_free(quotedbinary); |
648 | GNUNET_free_non_null (config); | 646 | GNUNET_free_non_null(config); |
649 | GNUNET_free (loprefix); | 647 | GNUNET_free(loprefix); |
650 | GNUNET_free (lopostfix); | 648 | GNUNET_free(lopostfix); |
651 | if (NULL == proc) | 649 | if (NULL == proc) |
652 | return GNUNET_ARM_RESULT_START_FAILED; | 650 | return GNUNET_ARM_RESULT_START_FAILED; |
653 | GNUNET_OS_process_destroy (proc); | 651 | GNUNET_OS_process_destroy(proc); |
654 | return GNUNET_ARM_RESULT_STARTING; | 652 | return GNUNET_ARM_RESULT_STARTING; |
655 | } | 653 | } |
656 | 654 | ||
@@ -662,19 +660,19 @@ start_arm_service (struct GNUNET_ARM_Handle *h, | |||
662 | * @param op operation to cancel | 660 | * @param op operation to cancel |
663 | */ | 661 | */ |
664 | void | 662 | void |
665 | GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op) | 663 | GNUNET_ARM_operation_cancel(struct GNUNET_ARM_Operation *op) |
666 | { | 664 | { |
667 | struct GNUNET_ARM_Handle *h = op->h; | 665 | struct GNUNET_ARM_Handle *h = op->h; |
668 | 666 | ||
669 | if (h->thm == op) | 667 | if (h->thm == op) |
670 | { | 668 | { |
671 | op->result_cont = NULL; | 669 | op->result_cont = NULL; |
672 | return; | 670 | return; |
673 | } | 671 | } |
674 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, | 672 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, |
675 | h->operation_pending_tail, | 673 | h->operation_pending_tail, |
676 | op); | 674 | op); |
677 | GNUNET_free (op); | 675 | GNUNET_free(op); |
678 | } | 676 | } |
679 | 677 | ||
680 | 678 | ||
@@ -689,38 +687,38 @@ GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op) | |||
689 | * @return handle to queue, NULL on error | 687 | * @return handle to queue, NULL on error |
690 | */ | 688 | */ |
691 | static struct GNUNET_ARM_Operation * | 689 | static struct GNUNET_ARM_Operation * |
692 | change_service (struct GNUNET_ARM_Handle *h, | 690 | change_service(struct GNUNET_ARM_Handle *h, |
693 | const char *service_name, | 691 | const char *service_name, |
694 | GNUNET_ARM_ResultCallback cb, | 692 | GNUNET_ARM_ResultCallback cb, |
695 | void *cb_cls, | 693 | void *cb_cls, |
696 | uint16_t type) | 694 | uint16_t type) |
697 | { | 695 | { |
698 | struct GNUNET_ARM_Operation *op; | 696 | struct GNUNET_ARM_Operation *op; |
699 | size_t slen; | 697 | size_t slen; |
700 | struct GNUNET_MQ_Envelope *env; | 698 | struct GNUNET_MQ_Envelope *env; |
701 | struct GNUNET_ARM_Message *msg; | 699 | struct GNUNET_ARM_Message *msg; |
702 | 700 | ||
703 | slen = strlen (service_name) + 1; | 701 | slen = strlen(service_name) + 1; |
704 | if (slen + sizeof (struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE) | 702 | if (slen + sizeof(struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE) |
705 | { | 703 | { |
706 | GNUNET_break (0); | 704 | GNUNET_break(0); |
707 | return NULL; | 705 | return NULL; |
708 | } | 706 | } |
709 | if (0 == h->request_id_counter) | 707 | if (0 == h->request_id_counter) |
710 | h->request_id_counter++; | 708 | h->request_id_counter++; |
711 | op = GNUNET_new (struct GNUNET_ARM_Operation); | 709 | op = GNUNET_new(struct GNUNET_ARM_Operation); |
712 | op->h = h; | 710 | op->h = h; |
713 | op->result_cont = cb; | 711 | op->result_cont = cb; |
714 | op->cont_cls = cb_cls; | 712 | op->cont_cls = cb_cls; |
715 | op->id = h->request_id_counter++; | 713 | op->id = h->request_id_counter++; |
716 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, | 714 | GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, |
717 | h->operation_pending_tail, | 715 | h->operation_pending_tail, |
718 | op); | 716 | op); |
719 | env = GNUNET_MQ_msg_extra (msg, slen, type); | 717 | env = GNUNET_MQ_msg_extra(msg, slen, type); |
720 | msg->reserved = htonl (0); | 718 | msg->reserved = htonl(0); |
721 | msg->request_id = GNUNET_htonll (op->id); | 719 | msg->request_id = GNUNET_htonll(op->id); |
722 | GNUNET_memcpy (&msg[1], service_name, slen); | 720 | GNUNET_memcpy(&msg[1], service_name, slen); |
723 | GNUNET_MQ_send (h->mq, env); | 721 | GNUNET_MQ_send(h->mq, env); |
724 | return op; | 722 | return op; |
725 | } | 723 | } |
726 | 724 | ||
@@ -731,22 +729,22 @@ change_service (struct GNUNET_ARM_Handle *h, | |||
731 | * @param cls the operation that asked ARM to be started | 729 | * @param cls the operation that asked ARM to be started |
732 | */ | 730 | */ |
733 | static void | 731 | static void |
734 | notify_running (void *cls) | 732 | notify_running(void *cls) |
735 | { | 733 | { |
736 | struct GNUNET_ARM_Operation *op = cls; | 734 | struct GNUNET_ARM_Operation *op = cls; |
737 | struct GNUNET_ARM_Handle *h = op->h; | 735 | struct GNUNET_ARM_Handle *h = op->h; |
738 | 736 | ||
739 | op->async = NULL; | 737 | op->async = NULL; |
740 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, | 738 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, |
741 | h->operation_pending_tail, | 739 | h->operation_pending_tail, |
742 | op); | 740 | op); |
743 | if (NULL != op->result_cont) | 741 | if (NULL != op->result_cont) |
744 | op->result_cont (op->cont_cls, | 742 | op->result_cont(op->cont_cls, |
745 | GNUNET_ARM_REQUEST_SENT_OK, | 743 | GNUNET_ARM_REQUEST_SENT_OK, |
746 | GNUNET_ARM_RESULT_IS_STARTED_ALREADY); | 744 | GNUNET_ARM_RESULT_IS_STARTED_ALREADY); |
747 | if ((GNUNET_YES == h->currently_up) && (NULL != h->conn_status)) | 745 | if ((GNUNET_YES == h->currently_up) && (NULL != h->conn_status)) |
748 | h->conn_status (h->conn_status_cls, GNUNET_YES); | 746 | h->conn_status(h->conn_status_cls, GNUNET_YES); |
749 | GNUNET_free (op); | 747 | GNUNET_free(op); |
750 | } | 748 | } |
751 | 749 | ||
752 | 750 | ||
@@ -756,22 +754,22 @@ notify_running (void *cls) | |||
756 | * @param cls the operation that asked ARM to be started | 754 | * @param cls the operation that asked ARM to be started |
757 | */ | 755 | */ |
758 | static void | 756 | static void |
759 | notify_starting (void *cls) | 757 | notify_starting(void *cls) |
760 | { | 758 | { |
761 | struct GNUNET_ARM_Operation *op = cls; | 759 | struct GNUNET_ARM_Operation *op = cls; |
762 | struct GNUNET_ARM_Handle *h = op->h; | 760 | struct GNUNET_ARM_Handle *h = op->h; |
763 | 761 | ||
764 | op->async = NULL; | 762 | op->async = NULL; |
765 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 763 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
766 | "Notifying client that we started the ARM service\n"); | 764 | "Notifying client that we started the ARM service\n"); |
767 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, | 765 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, |
768 | h->operation_pending_tail, | 766 | h->operation_pending_tail, |
769 | op); | 767 | op); |
770 | if (NULL != op->result_cont) | 768 | if (NULL != op->result_cont) |
771 | op->result_cont (op->cont_cls, | 769 | op->result_cont(op->cont_cls, |
772 | GNUNET_ARM_REQUEST_SENT_OK, | 770 | GNUNET_ARM_REQUEST_SENT_OK, |
773 | op->starting_ret); | 771 | op->starting_ret); |
774 | GNUNET_free (op); | 772 | GNUNET_free(op); |
775 | } | 773 | } |
776 | 774 | ||
777 | 775 | ||
@@ -786,7 +784,7 @@ notify_starting (void *cls) | |||
786 | * @return handle for the operation, NULL on error | 784 | * @return handle for the operation, NULL on error |
787 | */ | 785 | */ |
788 | struct GNUNET_ARM_Operation * | 786 | struct GNUNET_ARM_Operation * |
789 | GNUNET_ARM_request_service_start ( | 787 | GNUNET_ARM_request_service_start( |
790 | struct GNUNET_ARM_Handle *h, | 788 | struct GNUNET_ARM_Handle *h, |
791 | const char *service_name, | 789 | const char *service_name, |
792 | enum GNUNET_OS_InheritStdioFlags std_inheritance, | 790 | enum GNUNET_OS_InheritStdioFlags std_inheritance, |
@@ -796,13 +794,13 @@ GNUNET_ARM_request_service_start ( | |||
796 | struct GNUNET_ARM_Operation *op; | 794 | struct GNUNET_ARM_Operation *op; |
797 | enum GNUNET_ARM_Result ret; | 795 | enum GNUNET_ARM_Result ret; |
798 | 796 | ||
799 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting service `%s'\n", service_name); | 797 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Starting service `%s'\n", service_name); |
800 | if (0 != strcasecmp ("arm", service_name)) | 798 | if (0 != strcasecmp("arm", service_name)) |
801 | return change_service (h, | 799 | return change_service(h, |
802 | service_name, | 800 | service_name, |
803 | cont, | 801 | cont, |
804 | cont_cls, | 802 | cont_cls, |
805 | GNUNET_MESSAGE_TYPE_ARM_START); | 803 | GNUNET_MESSAGE_TYPE_ARM_START); |
806 | 804 | ||
807 | /* Possible cases: | 805 | /* Possible cases: |
808 | * 1) We're connected to ARM already. Invoke the callback immediately. | 806 | * 1) We're connected to ARM already. Invoke the callback immediately. |
@@ -811,37 +809,37 @@ GNUNET_ARM_request_service_start ( | |||
811 | * a service test. | 809 | * a service test. |
812 | */ | 810 | */ |
813 | if (GNUNET_YES == h->currently_up) | 811 | if (GNUNET_YES == h->currently_up) |
814 | { | 812 | { |
815 | LOG (GNUNET_ERROR_TYPE_DEBUG, "ARM is already running\n"); | 813 | LOG(GNUNET_ERROR_TYPE_DEBUG, "ARM is already running\n"); |
816 | op = GNUNET_new (struct GNUNET_ARM_Operation); | 814 | op = GNUNET_new(struct GNUNET_ARM_Operation); |
817 | op->h = h; | 815 | op->h = h; |
818 | op->result_cont = cont; | 816 | op->result_cont = cont; |
819 | op->cont_cls = cont_cls; | 817 | op->cont_cls = cont_cls; |
820 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, | 818 | GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, |
821 | h->operation_pending_tail, | 819 | h->operation_pending_tail, |
822 | op); | 820 | op); |
823 | op->async = GNUNET_SCHEDULER_add_now (¬ify_running, op); | 821 | op->async = GNUNET_SCHEDULER_add_now(¬ify_running, op); |
824 | return op; | 822 | return op; |
825 | } | 823 | } |
826 | /* This is an inherently uncertain choice, as it is of course | 824 | /* This is an inherently uncertain choice, as it is of course |
827 | theoretically possible that ARM is up and we just did not | 825 | theoretically possible that ARM is up and we just did not |
828 | yet complete the MQ handshake. However, given that users | 826 | yet complete the MQ handshake. However, given that users |
829 | are unlikely to hammer 'gnunet-arm -s' on a busy system, | 827 | are unlikely to hammer 'gnunet-arm -s' on a busy system, |
830 | the above check should catch 99.99% of the cases where ARM | 828 | the above check should catch 99.99% of the cases where ARM |
831 | is already running. */ | 829 | is already running. */ |
832 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting ARM service\n"); | 830 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Starting ARM service\n"); |
833 | ret = start_arm_service (h, std_inheritance); | 831 | ret = start_arm_service(h, std_inheritance); |
834 | if (GNUNET_ARM_RESULT_STARTING == ret) | 832 | if (GNUNET_ARM_RESULT_STARTING == ret) |
835 | reconnect_arm (h); | 833 | reconnect_arm(h); |
836 | op = GNUNET_new (struct GNUNET_ARM_Operation); | 834 | op = GNUNET_new(struct GNUNET_ARM_Operation); |
837 | op->h = h; | 835 | op->h = h; |
838 | op->result_cont = cont; | 836 | op->result_cont = cont; |
839 | op->cont_cls = cont_cls; | 837 | op->cont_cls = cont_cls; |
840 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, | 838 | GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, |
841 | h->operation_pending_tail, | 839 | h->operation_pending_tail, |
842 | op); | 840 | op); |
843 | op->starting_ret = ret; | 841 | op->starting_ret = ret; |
844 | op->async = GNUNET_SCHEDULER_add_now (¬ify_starting, op); | 842 | op->async = GNUNET_SCHEDULER_add_now(¬ify_starting, op); |
845 | return op; | 843 | return op; |
846 | } | 844 | } |
847 | 845 | ||
@@ -861,24 +859,24 @@ GNUNET_ARM_request_service_start ( | |||
861 | * @return handle for the operation, NULL on error | 859 | * @return handle for the operation, NULL on error |
862 | */ | 860 | */ |
863 | struct GNUNET_ARM_Operation * | 861 | struct GNUNET_ARM_Operation * |
864 | GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, | 862 | GNUNET_ARM_request_service_stop(struct GNUNET_ARM_Handle *h, |
865 | const char *service_name, | 863 | const char *service_name, |
866 | GNUNET_ARM_ResultCallback cont, | 864 | GNUNET_ARM_ResultCallback cont, |
867 | void *cont_cls) | 865 | void *cont_cls) |
868 | { | 866 | { |
869 | struct GNUNET_ARM_Operation *op; | 867 | struct GNUNET_ARM_Operation *op; |
870 | 868 | ||
871 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping service `%s'\n", service_name); | 869 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Stopping service `%s'\n", service_name); |
872 | op = change_service (h, | 870 | op = change_service(h, |
873 | service_name, | 871 | service_name, |
874 | cont, | 872 | cont, |
875 | cont_cls, | 873 | cont_cls, |
876 | GNUNET_MESSAGE_TYPE_ARM_STOP); | 874 | GNUNET_MESSAGE_TYPE_ARM_STOP); |
877 | if (NULL == op) | 875 | if (NULL == op) |
878 | return NULL; | 876 | return NULL; |
879 | /* If the service is ARM, set a flag as we will use MQ errors | 877 | /* If the service is ARM, set a flag as we will use MQ errors |
880 | to detect that the process is really gone. */ | 878 | to detect that the process is really gone. */ |
881 | if (0 == strcasecmp (service_name, "arm")) | 879 | if (0 == strcasecmp(service_name, "arm")) |
882 | op->is_arm_stop = GNUNET_YES; | 880 | op->is_arm_stop = GNUNET_YES; |
883 | return op; | 881 | return op; |
884 | } | 882 | } |
@@ -893,29 +891,29 @@ GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, | |||
893 | * @return handle for the operation, NULL on error | 891 | * @return handle for the operation, NULL on error |
894 | */ | 892 | */ |
895 | struct GNUNET_ARM_Operation * | 893 | struct GNUNET_ARM_Operation * |
896 | GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h, | 894 | GNUNET_ARM_request_service_list(struct GNUNET_ARM_Handle *h, |
897 | GNUNET_ARM_ServiceListCallback cont, | 895 | GNUNET_ARM_ServiceListCallback cont, |
898 | void *cont_cls) | 896 | void *cont_cls) |
899 | { | 897 | { |
900 | struct GNUNET_ARM_Operation *op; | 898 | struct GNUNET_ARM_Operation *op; |
901 | struct GNUNET_MQ_Envelope *env; | 899 | struct GNUNET_MQ_Envelope *env; |
902 | struct GNUNET_ARM_Message *msg; | 900 | struct GNUNET_ARM_Message *msg; |
903 | 901 | ||
904 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting LIST from ARM service\n"); | 902 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Requesting LIST from ARM service\n"); |
905 | if (0 == h->request_id_counter) | 903 | if (0 == h->request_id_counter) |
906 | h->request_id_counter++; | 904 | h->request_id_counter++; |
907 | op = GNUNET_new (struct GNUNET_ARM_Operation); | 905 | op = GNUNET_new(struct GNUNET_ARM_Operation); |
908 | op->h = h; | 906 | op->h = h; |
909 | op->list_cont = cont; | 907 | op->list_cont = cont; |
910 | op->cont_cls = cont_cls; | 908 | op->cont_cls = cont_cls; |
911 | op->id = h->request_id_counter++; | 909 | op->id = h->request_id_counter++; |
912 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, | 910 | GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, |
913 | h->operation_pending_tail, | 911 | h->operation_pending_tail, |
914 | op); | 912 | op); |
915 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_LIST); | 913 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_ARM_LIST); |
916 | msg->reserved = htonl (0); | 914 | msg->reserved = htonl(0); |
917 | msg->request_id = GNUNET_htonll (op->id); | 915 | msg->request_id = GNUNET_htonll(op->id); |
918 | GNUNET_MQ_send (h->mq, env); | 916 | GNUNET_MQ_send(h->mq, env); |
919 | return op; | 917 | return op; |
920 | } | 918 | } |
921 | 919 | ||