summaryrefslogtreecommitdiff
path: root/src/arm/arm_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-09-27 22:33:50 +0200
committerChristian Grothoff <christian@grothoff.org>2019-09-27 22:40:19 +0200
commiteadf4b7379049d32d7cfc5cffd4c88613f8a2a93 (patch)
tree74ae03df0080c9b72c4c827438b912436c6fba9a /src/arm/arm_api.c
parentfa0907738dcc299ed62205a11c18241acd4761eb (diff)
downloadgnunet-eadf4b7379049d32d7cfc5cffd4c88613f8a2a93.tar.gz
gnunet-eadf4b7379049d32d7cfc5cffd4c88613f8a2a93.zip
indent
Diffstat (limited to 'src/arm/arm_api.c')
-rw-r--r--src/arm/arm_api.c820
1 files changed, 438 insertions, 382 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index 4c3bb0488..dc5c9c25b 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2012, 2013, 2016 GNUnet e.V. 3 Copyright (C) 2009, 2010, 2012, 2013, 2016, 2019 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -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 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 */
40struct GNUNET_ARM_Operation { 40struct GNUNET_ARM_Operation
41{
41 /** 42 /**
42 * This is a doubly-linked list. 43 * This is a doubly-linked list.
43 */ 44 */
@@ -93,7 +94,8 @@ struct GNUNET_ARM_Operation {
93/** 94/**
94 * Handle for interacting with ARM. 95 * Handle for interacting with ARM.
95 */ 96 */
96struct GNUNET_ARM_Handle { 97struct GNUNET_ARM_Handle
98{
97 /** 99 /**
98 * Our connection to the ARM service. 100 * Our connection to the ARM service.
99 */ 101 */
@@ -164,7 +166,7 @@ struct GNUNET_ARM_Handle {
164 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 166 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
165 */ 167 */
166static int 168static int
167reconnect_arm(struct GNUNET_ARM_Handle *h); 169reconnect_arm (struct GNUNET_ARM_Handle *h);
168 170
169 171
170/** 172/**
@@ -173,12 +175,12 @@ reconnect_arm(struct GNUNET_ARM_Handle *h);
173 * @param cls the `struct GNUNET_ARM_Handle` 175 * @param cls the `struct GNUNET_ARM_Handle`
174 */ 176 */
175static void 177static void
176reconnect_arm_task(void *cls) 178reconnect_arm_task (void *cls)
177{ 179{
178 struct GNUNET_ARM_Handle *h = cls; 180 struct GNUNET_ARM_Handle *h = cls;
179 181
180 h->reconnect_task = NULL; 182 h->reconnect_task = NULL;
181 reconnect_arm(h); 183 reconnect_arm (h);
182} 184}
183 185
184 186
@@ -189,31 +191,31 @@ reconnect_arm_task(void *cls)
189 * @param h our handle 191 * @param h our handle
190 */ 192 */
191static void 193static void
192reconnect_arm_later(struct GNUNET_ARM_Handle *h) 194reconnect_arm_later (struct GNUNET_ARM_Handle *h)
193{ 195{
194 struct GNUNET_ARM_Operation *op; 196 struct GNUNET_ARM_Operation *op;
195 197
196 if (NULL != h->mq) 198 if (NULL != h->mq)
197 { 199 {
198 GNUNET_MQ_destroy(h->mq); 200 GNUNET_MQ_destroy (h->mq);
199 h->mq = NULL; 201 h->mq = NULL;
200 } 202 }
201 h->currently_up = GNUNET_NO; 203 h->currently_up = GNUNET_NO;
202 GNUNET_assert(NULL == h->reconnect_task); 204 GNUNET_assert (NULL == h->reconnect_task);
203 h->reconnect_task = 205 h->reconnect_task =
204 GNUNET_SCHEDULER_add_delayed(h->retry_backoff, &reconnect_arm_task, h); 206 GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_task, h);
205 while (NULL != (op = h->operation_pending_head)) 207 while (NULL != (op = h->operation_pending_head))
206 { 208 {
207 if (NULL != op->result_cont) 209 if (NULL != op->result_cont)
208 op->result_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); 210 op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0);
209 if (NULL != op->list_cont) 211 if (NULL != op->list_cont)
210 op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); 212 op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL);
211 GNUNET_ARM_operation_cancel(op); 213 GNUNET_ARM_operation_cancel (op);
212 } 214 }
213 GNUNET_assert(NULL == h->operation_pending_head); 215 GNUNET_assert (NULL == h->operation_pending_head);
214 h->retry_backoff = GNUNET_TIME_STD_BACKOFF(h->retry_backoff); 216 h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff);
215 if (NULL != h->conn_status) 217 if (NULL != h->conn_status)
216 h->conn_status(h->conn_status_cls, GNUNET_NO); 218 h->conn_status (h->conn_status_cls, GNUNET_NO);
217} 219}
218 220
219 221
@@ -225,11 +227,11 @@ reconnect_arm_later(struct GNUNET_ARM_Handle *h)
225 * @return NULL if not found 227 * @return NULL if not found
226 */ 228 */
227static struct GNUNET_ARM_Operation * 229static struct GNUNET_ARM_Operation *
228find_op_by_id(struct GNUNET_ARM_Handle *h, uint64_t id) 230find_op_by_id (struct GNUNET_ARM_Handle *h,
231 uint64_t id)
229{ 232{
230 struct GNUNET_ARM_Operation *result; 233 for (struct GNUNET_ARM_Operation *result = h->operation_pending_head;
231 234 NULL != result;
232 for (result = h->operation_pending_head; NULL != result;
233 result = result->next) 235 result = result->next)
234 if (id == result->id) 236 if (id == result->id)
235 return result; 237 return result;
@@ -244,7 +246,8 @@ find_op_by_id(struct GNUNET_ARM_Handle *h, uint64_t id)
244 * @param res the message received from the arm service 246 * @param res the message received from the arm service
245 */ 247 */
246static void 248static void
247handle_arm_result(void *cls, const struct GNUNET_ARM_ResultMessage *res) 249handle_arm_result (void *cls,
250 const struct GNUNET_ARM_ResultMessage *res)
248{ 251{
249 struct GNUNET_ARM_Handle *h = cls; 252 struct GNUNET_ARM_Handle *h = cls;
250 struct GNUNET_ARM_Operation *op; 253 struct GNUNET_ARM_Operation *op;
@@ -253,43 +256,46 @@ handle_arm_result(void *cls, const struct GNUNET_ARM_ResultMessage *res)
253 GNUNET_ARM_ResultCallback result_cont; 256 GNUNET_ARM_ResultCallback result_cont;
254 void *result_cont_cls; 257 void *result_cont_cls;
255 258
256 id = GNUNET_ntohll(res->arm_msg.request_id); 259 id = GNUNET_ntohll (res->arm_msg.request_id);
257 op = find_op_by_id(h, id); 260 op = find_op_by_id (h, id);
258 if (NULL == op) 261 if (NULL == op)
259 { 262 {
260 LOG(GNUNET_ERROR_TYPE_DEBUG, 263 LOG (GNUNET_ERROR_TYPE_DEBUG,
261 "Message with unknown id %llu\n", 264 "Message with unknown id %llu\n",
262 (unsigned long long)id); 265 (unsigned long long) id);
263 return; 266 return;
264 } 267 }
265 268
266 result = (enum GNUNET_ARM_Result)ntohl(res->result); 269 result = (enum GNUNET_ARM_Result) ntohl (res->result);
267 if ((GNUNET_YES == op->is_arm_stop) && (GNUNET_ARM_RESULT_STOPPING == result)) 270 if ( (GNUNET_YES == op->is_arm_stop) &&
271 (GNUNET_ARM_RESULT_STOPPING == result) )
272 {
273 /* special case: if we are stopping 'gnunet-service-arm', we do not just
274 wait for the result message, but also wait for the service to close
275 the connection (and then we have to close our client handle as well);
276 this is done by installing a different receive handler, waiting for
277 the connection to go down */
278 if (NULL != h->thm)
268 { 279 {
269 /* special case: if we are stopping 'gnunet-service-arm', we do not just 280 GNUNET_break (0);
270 wait for the result message, but also wait for the service to close 281 op->result_cont (h->thm->cont_cls,
271 the connection (and then we have to close our client handle as well); 282 GNUNET_ARM_REQUEST_SENT_OK,
272 this is done by installing a different receive handler, waiting for 283 GNUNET_ARM_RESULT_IS_NOT_KNOWN);
273 the connection to go down */ 284 GNUNET_free (h->thm);
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;
287 } 285 }
286 GNUNET_CONTAINER_DLL_remove (h->operation_pending_head,
287 h->operation_pending_tail,
288 op);
289 h->thm = op;
290 return;
291 }
288 result_cont = op->result_cont; 292 result_cont = op->result_cont;
289 result_cont_cls = op->cont_cls; 293 result_cont_cls = op->cont_cls;
290 GNUNET_ARM_operation_cancel(op); 294 GNUNET_ARM_operation_cancel (op);
291 if (NULL != result_cont) 295 if (NULL != result_cont)
292 result_cont(result_cont_cls, GNUNET_ARM_REQUEST_SENT_OK, result); 296 result_cont (result_cont_cls,
297 GNUNET_ARM_REQUEST_SENT_OK,
298 result);
293} 299}
294 300
295 301
@@ -303,7 +309,9 @@ handle_arm_result(void *cls, const struct GNUNET_ARM_ResultMessage *res)
303 * NULL if the index is out of bounds 309 * NULL if the index is out of bounds
304 */ 310 */
305static const char * 311static const char *
306pool_get (const char *pool_start, size_t pool_size, size_t str_index) 312pool_get (const char *pool_start,
313 size_t pool_size,
314 size_t str_index)
307{ 315{
308 const char *str_start; 316 const char *str_start;
309 const char *end; 317 const char *end;
@@ -311,7 +319,7 @@ pool_get (const char *pool_start, size_t pool_size, size_t str_index)
311 if (str_index >= pool_size) 319 if (str_index >= pool_size)
312 return NULL; 320 return NULL;
313 str_start = pool_start + str_index; 321 str_start = pool_start + str_index;
314 end = memchr(str_start, 0, pool_size - str_index); 322 end = memchr (str_start, 0, pool_size - str_index);
315 if (NULL == end) 323 if (NULL == end)
316 return NULL; 324 return NULL;
317 return str_start; 325 return str_start;
@@ -326,42 +334,42 @@ pool_get (const char *pool_start, size_t pool_size, size_t str_index)
326 * @return #GNUNET_OK if message is well-formed 334 * @return #GNUNET_OK if message is well-formed
327 */ 335 */
328static int 336static int
329check_arm_list_result(void *cls, 337check_arm_list_result (void *cls,
330 const struct GNUNET_ARM_ListResultMessage *lres) 338 const struct GNUNET_ARM_ListResultMessage *lres)
331{ 339{
332 uint16_t rcount = ntohs(lres->count); 340 uint16_t rcount = ntohs (lres->count);
333 uint16_t msize = ntohs(lres->arm_msg.header.size) - sizeof(*lres); 341 uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof(*lres);
334 struct GNUNET_ARM_ServiceInfoMessage *ssm; 342 struct GNUNET_ARM_ServiceInfoMessage *ssm;
335 size_t pool_size; 343 size_t pool_size;
336 char *pool_start; 344 char *pool_start;
337 345
346 (void) cls;
338 if ((rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage) > msize)) 347 if ((rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage) > msize))
339 { 348 {
340 GNUNET_break_op (0); 349 GNUNET_break_op (0);
341 return GNUNET_NO; 350 return GNUNET_NO;
342 } 351 }
343
344 ssm = (struct GNUNET_ARM_ServiceInfoMessage *) &lres[1]; 352 ssm = (struct GNUNET_ARM_ServiceInfoMessage *) &lres[1];
345 pool_start = (char *) (ssm + rcount); 353 pool_start = (char *) (ssm + rcount);
346 pool_size = msize - (rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage)); 354 pool_size = msize - (rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage));
347
348 (void)cls;
349 for (unsigned int i = 0; i < rcount; i++) 355 for (unsigned int i = 0; i < rcount; i++)
356 {
357 uint16_t name_index = ntohs (ssm->name_index);
358 uint16_t binary_index = ntohs (ssm->binary_index);
359 if (NULL == pool_get (pool_start, pool_size, name_index))
350 { 360 {
351 uint16_t name_index = ntohs (ssm->name_index); 361 GNUNET_break_op (0);
352 uint16_t binary_index = ntohs (ssm->binary_index); 362 return GNUNET_NO;
353 if (NULL == pool_get (pool_start, pool_size, name_index))
354 {
355 GNUNET_break_op (0);
356 return GNUNET_NO;
357 }
358 if (NULL == pool_get (pool_start, pool_size, binary_index))
359 {
360 GNUNET_break_op (0);
361 return GNUNET_NO;
362 }
363 ssm++;
364 } 363 }
364 if (NULL == pool_get (pool_start,
365 pool_size,
366 binary_index))
367 {
368 GNUNET_break_op (0);
369 return GNUNET_NO;
370 }
371 ssm++;
372 }
365 return GNUNET_OK; 373 return GNUNET_OK;
366} 374}
367 375
@@ -373,12 +381,12 @@ check_arm_list_result(void *cls,
373 * @param lres the message received from the arm service 381 * @param lres the message received from the arm service
374 */ 382 */
375static void 383static void
376handle_arm_list_result(void *cls, 384handle_arm_list_result (void *cls,
377 const struct GNUNET_ARM_ListResultMessage *lres) 385 const struct GNUNET_ARM_ListResultMessage *lres)
378{ 386{
379 struct GNUNET_ARM_Handle *h = cls; 387 struct GNUNET_ARM_Handle *h = cls;
380 uint16_t rcount = ntohs(lres->count); 388 uint16_t rcount = ntohs (lres->count);
381 uint16_t msize = ntohs(lres->arm_msg.header.size) - sizeof(*lres); 389 uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof(*lres);
382 struct GNUNET_ARM_ServiceInfo list[rcount]; 390 struct GNUNET_ARM_ServiceInfo list[rcount];
383 struct GNUNET_ARM_ServiceInfoMessage *ssm; 391 struct GNUNET_ARM_ServiceInfoMessage *ssm;
384 struct GNUNET_ARM_Operation *op; 392 struct GNUNET_ARM_Operation *op;
@@ -386,44 +394,50 @@ handle_arm_list_result(void *cls,
386 size_t pool_size; 394 size_t pool_size;
387 char *pool_start; 395 char *pool_start;
388 396
389 id = GNUNET_ntohll(lres->arm_msg.request_id); 397 id = GNUNET_ntohll (lres->arm_msg.request_id);
390 op = find_op_by_id(h, id); 398 op = find_op_by_id (h, id);
391 if (NULL == op) 399 if (NULL == op)
392 { 400 {
393 LOG(GNUNET_ERROR_TYPE_DEBUG, 401 LOG (GNUNET_ERROR_TYPE_DEBUG,
394 "Message with unknown id %llu\n", 402 "Message with unknown id %llu\n",
395 (unsigned long long)id); 403 (unsigned long long) id);
396 return; 404 return;
397 } 405 }
398 406
399 GNUNET_assert ((rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage) <= msize)); 407 GNUNET_assert ((rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage) <=
408 msize));
400 409
401 ssm = (struct GNUNET_ARM_ServiceInfoMessage *) &lres[1]; 410 ssm = (struct GNUNET_ARM_ServiceInfoMessage *) &lres[1];
402 pool_start = (char *) (ssm + rcount); 411 pool_start = (char *) (ssm + rcount);
403 pool_size = msize - (rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage)); 412 pool_size = msize - (rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage));
404 413
405 for (unsigned int i = 0; i < rcount; i++) 414 for (unsigned int i = 0; i < rcount; i++)
406 { 415 {
407 uint16_t name_index = ntohs (ssm->name_index); 416 uint16_t name_index = ntohs (ssm->name_index);
408 uint16_t binary_index = ntohs (ssm->binary_index); 417 uint16_t binary_index = ntohs (ssm->binary_index);
409 const char *name; 418 const char *name;
410 const char *binary; 419 const char *binary;
411 420
412 GNUNET_assert (NULL != (name = pool_get (pool_start, pool_size, name_index))); 421 GNUNET_assert (NULL != (name = pool_get (pool_start, pool_size,
413 GNUNET_assert (NULL != (binary = pool_get (pool_start, pool_size, binary_index))); 422 name_index)));
414 list[i] = (struct GNUNET_ARM_ServiceInfo) { 423 GNUNET_assert (NULL != (binary = pool_get (pool_start, pool_size,
415 .name = name, 424 binary_index)));
416 .binary = binary, 425 list[i] = (struct GNUNET_ARM_ServiceInfo) {
417 .status = ntohl (ssm->status), 426 .name = name,
418 .last_started_at = GNUNET_TIME_absolute_ntoh (ssm->last_started_at), 427 .binary = binary,
419 .restart_at = GNUNET_TIME_absolute_ntoh (ssm->restart_at), 428 .status = ntohl (ssm->status),
420 .last_exit_status = ntohs (ssm->last_exit_status), 429 .last_started_at = GNUNET_TIME_absolute_ntoh (ssm->last_started_at),
421 }; 430 .restart_at = GNUNET_TIME_absolute_ntoh (ssm->restart_at),
422 ssm++; 431 .last_exit_status = ntohs (ssm->last_exit_status),
423 } 432 };
433 ssm++;
434 }
424 if (NULL != op->list_cont) 435 if (NULL != op->list_cont)
425 op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, rcount, list); 436 op->list_cont (op->cont_cls,
426 GNUNET_ARM_operation_cancel(op); 437 GNUNET_ARM_REQUEST_SENT_OK,
438 rcount,
439 list);
440 GNUNET_ARM_operation_cancel (op);
427} 441}
428 442
429 443
@@ -434,18 +448,20 @@ handle_arm_list_result(void *cls,
434 * @param msg message received 448 * @param msg message received
435 */ 449 */
436static void 450static void
437handle_confirm(void *cls, const struct GNUNET_MessageHeader *msg) 451handle_confirm (void *cls,
452 const struct GNUNET_MessageHeader *msg)
438{ 453{
439 struct GNUNET_ARM_Handle *h = cls; 454 struct GNUNET_ARM_Handle *h = cls;
440 455
441 (void)msg; 456 (void) msg;
442 LOG(GNUNET_ERROR_TYPE_DEBUG, "Got confirmation from ARM that we are up!\n"); 457 LOG (GNUNET_ERROR_TYPE_DEBUG,
458 "Got confirmation from ARM that we are up!\n");
443 if (GNUNET_NO == h->currently_up) 459 if (GNUNET_NO == h->currently_up)
444 { 460 {
445 h->currently_up = GNUNET_YES; 461 h->currently_up = GNUNET_YES;
446 if (NULL != h->conn_status) 462 if (NULL != h->conn_status)
447 h->conn_status(h->conn_status_cls, GNUNET_YES); 463 h->conn_status (h->conn_status_cls, GNUNET_YES);
448 } 464 }
449} 465}
450 466
451 467
@@ -458,22 +474,23 @@ handle_confirm(void *cls, const struct GNUNET_MessageHeader *msg)
458 * @param error error code 474 * @param error error code
459 */ 475 */
460static void 476static void
461mq_error_handler(void *cls, enum GNUNET_MQ_Error error) 477mq_error_handler (void *cls,
478 enum GNUNET_MQ_Error error)
462{ 479{
463 struct GNUNET_ARM_Handle *h = cls; 480 struct GNUNET_ARM_Handle *h = cls;
464 struct GNUNET_ARM_Operation *op; 481 struct GNUNET_ARM_Operation *op;
465 482
466 (void)error; 483 (void) error;
467 h->currently_up = GNUNET_NO; 484 h->currently_up = GNUNET_NO;
468 if (NULL != (op = h->thm)) 485 if (NULL != (op = h->thm))
469 { 486 {
470 h->thm = NULL; 487 h->thm = NULL;
471 op->result_cont(op->cont_cls, 488 op->result_cont (op->cont_cls,
472 GNUNET_ARM_REQUEST_SENT_OK, 489 GNUNET_ARM_REQUEST_SENT_OK,
473 GNUNET_ARM_RESULT_STOPPED); 490 GNUNET_ARM_RESULT_STOPPED);
474 GNUNET_free(op); 491 GNUNET_free (op);
475 } 492 }
476 reconnect_arm_later(h); 493 reconnect_arm_later (h);
477} 494}
478 495
479 496
@@ -484,39 +501,48 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
484 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 501 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
485 */ 502 */
486static int 503static int
487reconnect_arm(struct GNUNET_ARM_Handle *h) 504reconnect_arm (struct GNUNET_ARM_Handle *h)
488{ 505{
489 struct GNUNET_MQ_MessageHandler handlers[] = 506 struct GNUNET_MQ_MessageHandler handlers[] = {
490 { GNUNET_MQ_hd_fixed_size(arm_result, 507 GNUNET_MQ_hd_fixed_size (arm_result,
491 GNUNET_MESSAGE_TYPE_ARM_RESULT, 508 GNUNET_MESSAGE_TYPE_ARM_RESULT,
492 struct GNUNET_ARM_ResultMessage, 509 struct GNUNET_ARM_ResultMessage,
493 h), 510 h),
494 GNUNET_MQ_hd_var_size(arm_list_result, 511 GNUNET_MQ_hd_var_size (arm_list_result,
495 GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, 512 GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT,
496 struct GNUNET_ARM_ListResultMessage, 513 struct GNUNET_ARM_ListResultMessage,
497 h), 514 h),
498 GNUNET_MQ_hd_fixed_size(confirm, 515 GNUNET_MQ_hd_fixed_size (confirm,
499 GNUNET_MESSAGE_TYPE_ARM_TEST, 516 GNUNET_MESSAGE_TYPE_ARM_TEST,
500 struct GNUNET_MessageHeader, 517 struct GNUNET_MessageHeader,
501 h), 518 h),
502 GNUNET_MQ_handler_end() }; 519 GNUNET_MQ_handler_end ()
520 };
503 struct GNUNET_MessageHeader *test; 521 struct GNUNET_MessageHeader *test;
504 struct GNUNET_MQ_Envelope *env; 522 struct GNUNET_MQ_Envelope *env;
505 523
506 if (NULL != h->mq) 524 if (NULL != h->mq)
507 return GNUNET_OK; 525 return GNUNET_OK;
508 GNUNET_assert(GNUNET_NO == h->currently_up); 526 GNUNET_assert (GNUNET_NO == h->currently_up);
509 h->mq = GNUNET_CLIENT_connect(h->cfg, "arm", handlers, &mq_error_handler, h); 527 h->mq = GNUNET_CLIENT_connect (h->cfg,
528 "arm",
529 handlers,
530 &mq_error_handler,
531 h);
510 if (NULL == h->mq) 532 if (NULL == h->mq)
511 { 533 {
512 LOG(GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CLIENT_connect returned NULL\n"); 534 LOG (GNUNET_ERROR_TYPE_DEBUG,
513 if (NULL != h->conn_status) 535 "GNUNET_CLIENT_connect returned NULL\n");
514 h->conn_status(h->conn_status_cls, GNUNET_SYSERR); 536 if (NULL != h->conn_status)
515 return GNUNET_SYSERR; 537 h->conn_status (h->conn_status_cls,
516 } 538 GNUNET_SYSERR);
517 LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending TEST message to ARM\n"); 539 return GNUNET_SYSERR;
518 env = GNUNET_MQ_msg(test, GNUNET_MESSAGE_TYPE_ARM_TEST); 540 }
519 GNUNET_MQ_send(h->mq, env); 541 LOG (GNUNET_ERROR_TYPE_DEBUG,
542 "Sending TEST message to ARM\n");
543 env = GNUNET_MQ_msg (test,
544 GNUNET_MESSAGE_TYPE_ARM_TEST);
545 GNUNET_MQ_send (h->mq, env);
520 return GNUNET_OK; 546 return GNUNET_OK;
521} 547}
522 548
@@ -533,21 +559,21 @@ reconnect_arm(struct GNUNET_ARM_Handle *h)
533 * @return context to use for further ARM operations, NULL on error. 559 * @return context to use for further ARM operations, NULL on error.
534 */ 560 */
535struct GNUNET_ARM_Handle * 561struct GNUNET_ARM_Handle *
536GNUNET_ARM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, 562GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
537 GNUNET_ARM_ConnectionStatusCallback conn_status, 563 GNUNET_ARM_ConnectionStatusCallback conn_status,
538 void *conn_status_cls) 564 void *conn_status_cls)
539{ 565{
540 struct GNUNET_ARM_Handle *h; 566 struct GNUNET_ARM_Handle *h;
541 567
542 h = GNUNET_new(struct GNUNET_ARM_Handle); 568 h = GNUNET_new (struct GNUNET_ARM_Handle);
543 h->cfg = cfg; 569 h->cfg = cfg;
544 h->conn_status = conn_status; 570 h->conn_status = conn_status;
545 h->conn_status_cls = conn_status_cls; 571 h->conn_status_cls = conn_status_cls;
546 if (GNUNET_OK != reconnect_arm(h)) 572 if (GNUNET_OK != reconnect_arm (h))
547 { 573 {
548 GNUNET_free(h); 574 GNUNET_free (h);
549 return NULL; 575 return NULL;
550 } 576 }
551 return h; 577 return h;
552} 578}
553 579
@@ -558,38 +584,43 @@ GNUNET_ARM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg,
558 * @param h the handle that was being used 584 * @param h the handle that was being used
559 */ 585 */
560void 586void
561GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h) 587GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h)
562{ 588{
563 struct GNUNET_ARM_Operation *op; 589 struct GNUNET_ARM_Operation *op;
564 590
565 LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); 591 LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n");
566 while (NULL != (op = h->operation_pending_head)) 592 while (NULL != (op = h->operation_pending_head))
593 {
594 GNUNET_CONTAINER_DLL_remove (h->operation_pending_head,
595 h->operation_pending_tail,
596 op);
597 if (NULL != op->result_cont)
598 op->result_cont (op->cont_cls,
599 GNUNET_ARM_REQUEST_DISCONNECTED,
600 0);
601 if (NULL != op->list_cont)
602 op->list_cont (op->cont_cls,
603 GNUNET_ARM_REQUEST_DISCONNECTED,
604 0,
605 NULL);
606 if (NULL != op->async)
567 { 607 {
568 GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, 608 GNUNET_SCHEDULER_cancel (op->async);
569 h->operation_pending_tail, 609 op->async = NULL;
570 op);
571 if (NULL != op->result_cont)
572 op->result_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0);
573 if (NULL != op->list_cont)
574 op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL);
575 if (NULL != op->async)
576 {
577 GNUNET_SCHEDULER_cancel(op->async);
578 op->async = NULL;
579 }
580 GNUNET_free(op);
581 } 610 }
611 GNUNET_free (op);
612 }
582 if (NULL != h->mq) 613 if (NULL != h->mq)
583 { 614 {
584 GNUNET_MQ_destroy(h->mq); 615 GNUNET_MQ_destroy (h->mq);
585 h->mq = NULL; 616 h->mq = NULL;
586 } 617 }
587 if (NULL != h->reconnect_task) 618 if (NULL != h->reconnect_task)
588 { 619 {
589 GNUNET_SCHEDULER_cancel(h->reconnect_task); 620 GNUNET_SCHEDULER_cancel (h->reconnect_task);
590 h->reconnect_task = NULL; 621 h->reconnect_task = NULL;
591 } 622 }
592 GNUNET_free(h); 623 GNUNET_free (h);
593} 624}
594 625
595 626
@@ -602,8 +633,8 @@ GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h)
602 * @return operation status code 633 * @return operation status code
603 */ 634 */
604static enum GNUNET_ARM_Result 635static enum GNUNET_ARM_Result
605start_arm_service(struct GNUNET_ARM_Handle *h, 636start_arm_service (struct GNUNET_ARM_Handle *h,
606 enum GNUNET_OS_InheritStdioFlags std_inheritance) 637 enum GNUNET_OS_InheritStdioFlags std_inheritance)
607{ 638{
608 struct GNUNET_OS_Process *proc; 639 struct GNUNET_OS_Process *proc;
609 char *cbinary; 640 char *cbinary;
@@ -613,98 +644,111 @@ start_arm_service(struct GNUNET_ARM_Handle *h,
613 char *loprefix; 644 char *loprefix;
614 char *lopostfix; 645 char *lopostfix;
615 646
616 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(h->cfg, 647 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg,
617 "arm", 648 "arm",
618 "PREFIX", 649 "PREFIX",
619 &loprefix)) 650 &loprefix))
620 loprefix = GNUNET_strdup(""); 651 loprefix = GNUNET_strdup ("");
621 else 652 else
622 loprefix = GNUNET_CONFIGURATION_expand_dollar(h->cfg, loprefix); 653 loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, loprefix);
623 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(h->cfg, 654 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg,
624 "arm", 655 "arm",
625 "OPTIONS", 656 "OPTIONS",
626 &lopostfix)) 657 &lopostfix))
627 lopostfix = GNUNET_strdup(""); 658 lopostfix = GNUNET_strdup ("");
628 else 659 else
629 lopostfix = GNUNET_CONFIGURATION_expand_dollar(h->cfg, lopostfix); 660 lopostfix = GNUNET_CONFIGURATION_expand_dollar (h->cfg,
661 lopostfix);
630 if (GNUNET_OK != 662 if (GNUNET_OK !=
631 GNUNET_CONFIGURATION_get_value_string(h->cfg, "arm", "BINARY", &cbinary)) 663 GNUNET_CONFIGURATION_get_value_string (h->cfg,
632 { 664 "arm",
633 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, "arm", "BINARY"); 665 "BINARY",
634 GNUNET_free(loprefix); 666 &cbinary))
635 GNUNET_free(lopostfix); 667 {
636 return GNUNET_ARM_RESULT_IS_NOT_KNOWN; 668 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
637 } 669 "arm",
638 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(h->cfg, 670 "BINARY");
639 "arm", 671 GNUNET_free (loprefix);
640 "CONFIG", 672 GNUNET_free (lopostfix);
641 &config)) 673 return GNUNET_ARM_RESULT_IS_NOT_KNOWN;
674 }
675 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg,
676 "arm",
677 "CONFIG",
678 &config))
642 config = NULL; 679 config = NULL;
643 binary = GNUNET_OS_get_libexec_binary_path(cbinary); 680 binary = GNUNET_OS_get_libexec_binary_path (cbinary);
644 GNUNET_asprintf(&quotedbinary, "\"%s\"", binary); 681 GNUNET_asprintf (&quotedbinary,
645 GNUNET_free(cbinary); 682 "\"%s\"",
646 if ((GNUNET_YES == 683 binary);
647 GNUNET_CONFIGURATION_have_value(h->cfg, "TESTING", "WEAKRANDOM")) && 684 GNUNET_free (cbinary);
648 (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(h->cfg, 685 if ( (GNUNET_YES ==
649 "TESTING", 686 GNUNET_CONFIGURATION_have_value (h->cfg,
650 "WEAKRANDOM")) && 687 "TESTING",
651 (GNUNET_NO == 688 "WEAKRANDOM")) &&
652 GNUNET_CONFIGURATION_have_value(h->cfg, "TESTING", "HOSTFILE"))) 689 (GNUNET_YES ==
653 { 690 GNUNET_CONFIGURATION_get_value_yesno (h->cfg,
654 /* Means we are ONLY running locally */ 691 "TESTING",
655 /* we're clearly running a test, don't daemonize */ 692 "WEAKRANDOM")) &&
656 if (NULL == config) 693 (GNUNET_NO ==
657 proc = GNUNET_OS_start_process_s(GNUNET_NO, 694 GNUNET_CONFIGURATION_have_value (h->cfg,
658 std_inheritance, 695 "TESTING",
659 NULL, 696 "HOSTFILE")) )
660 loprefix, 697 {
661 quotedbinary, 698 /* Means we are ONLY running locally */
662 /* no daemonization! */ 699 /* we're clearly running a test, don't daemonize */
663 lopostfix, 700 if (NULL == config)
664 NULL); 701 proc = GNUNET_OS_start_process_s (GNUNET_NO,
665 else 702 std_inheritance,
666 proc = GNUNET_OS_start_process_s(GNUNET_NO, 703 NULL,
667 std_inheritance, 704 loprefix,
668 NULL, 705 quotedbinary,
669 loprefix, 706 /* no daemonization! */
670 quotedbinary, 707 lopostfix,
671 "-c", 708 NULL);
672 config, 709 else
673 /* no daemonization! */ 710 proc = GNUNET_OS_start_process_s (GNUNET_NO,
674 lopostfix, 711 std_inheritance,
675 NULL); 712 NULL,
676 } 713 loprefix,
714 quotedbinary,
715 "-c",
716 config,
717 /* no daemonization! */
718 lopostfix,
719 NULL);
720 }
677 else 721 else
678 { 722 {
679 if (NULL == config) 723 if (NULL == config)
680 proc = GNUNET_OS_start_process_s(GNUNET_NO, 724 proc = GNUNET_OS_start_process_s (GNUNET_NO,
681 std_inheritance, 725 std_inheritance,
682 NULL, 726 NULL,
683 loprefix, 727 loprefix,
684 quotedbinary, 728 quotedbinary,
685 "-d", /* do daemonize */ 729 "-d", /* do daemonize */
686 lopostfix, 730 lopostfix,
687 NULL); 731 NULL);
688 else 732 else
689 proc = GNUNET_OS_start_process_s(GNUNET_NO, 733 proc = GNUNET_OS_start_process_s (GNUNET_NO,
690 std_inheritance, 734 std_inheritance,
691 NULL, 735 NULL,
692 loprefix, 736 loprefix,
693 quotedbinary, 737 quotedbinary,
694 "-c", 738 "-c",
695 config, 739 config,
696 "-d", /* do daemonize */ 740 "-d", /* do daemonize */
697 lopostfix, 741 lopostfix,
698 NULL); 742 NULL);
699 } 743 }
700 GNUNET_free(binary); 744 GNUNET_free (binary);
701 GNUNET_free(quotedbinary); 745 GNUNET_free (quotedbinary);
702 GNUNET_free_non_null(config); 746 GNUNET_free_non_null (config);
703 GNUNET_free(loprefix); 747 GNUNET_free (loprefix);
704 GNUNET_free(lopostfix); 748 GNUNET_free (lopostfix);
705 if (NULL == proc) 749 if (NULL == proc)
706 return GNUNET_ARM_RESULT_START_FAILED; 750 return GNUNET_ARM_RESULT_START_FAILED;
707 GNUNET_OS_process_destroy(proc); 751 GNUNET_OS_process_destroy (proc);
708 return GNUNET_ARM_RESULT_STARTING; 752 return GNUNET_ARM_RESULT_STARTING;
709} 753}
710 754
@@ -716,19 +760,19 @@ start_arm_service(struct GNUNET_ARM_Handle *h,
716 * @param op operation to cancel 760 * @param op operation to cancel
717 */ 761 */
718void 762void
719GNUNET_ARM_operation_cancel(struct GNUNET_ARM_Operation *op) 763GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op)
720{ 764{
721 struct GNUNET_ARM_Handle *h = op->h; 765 struct GNUNET_ARM_Handle *h = op->h;
722 766
723 if (h->thm == op) 767 if (h->thm == op)
724 { 768 {
725 op->result_cont = NULL; 769 op->result_cont = NULL;
726 return; 770 return;
727 } 771 }
728 GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, 772 GNUNET_CONTAINER_DLL_remove (h->operation_pending_head,
729 h->operation_pending_tail, 773 h->operation_pending_tail,
730 op); 774 op);
731 GNUNET_free(op); 775 GNUNET_free (op);
732} 776}
733 777
734 778
@@ -743,38 +787,38 @@ GNUNET_ARM_operation_cancel(struct GNUNET_ARM_Operation *op)
743 * @return handle to queue, NULL on error 787 * @return handle to queue, NULL on error
744 */ 788 */
745static struct GNUNET_ARM_Operation * 789static struct GNUNET_ARM_Operation *
746change_service(struct GNUNET_ARM_Handle *h, 790change_service (struct GNUNET_ARM_Handle *h,
747 const char *service_name, 791 const char *service_name,
748 GNUNET_ARM_ResultCallback cb, 792 GNUNET_ARM_ResultCallback cb,
749 void *cb_cls, 793 void *cb_cls,
750 uint16_t type) 794 uint16_t type)
751{ 795{
752 struct GNUNET_ARM_Operation *op; 796 struct GNUNET_ARM_Operation *op;
753 size_t slen; 797 size_t slen;
754 struct GNUNET_MQ_Envelope *env; 798 struct GNUNET_MQ_Envelope *env;
755 struct GNUNET_ARM_Message *msg; 799 struct GNUNET_ARM_Message *msg;
756 800
757 slen = strlen(service_name) + 1; 801 slen = strlen (service_name) + 1;
758 if (slen + sizeof(struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE) 802 if (slen + sizeof(struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE)
759 { 803 {
760 GNUNET_break(0); 804 GNUNET_break (0);
761 return NULL; 805 return NULL;
762 } 806 }
763 if (0 == h->request_id_counter) 807 if (0 == h->request_id_counter)
764 h->request_id_counter++; 808 h->request_id_counter++;
765 op = GNUNET_new(struct GNUNET_ARM_Operation); 809 op = GNUNET_new (struct GNUNET_ARM_Operation);
766 op->h = h; 810 op->h = h;
767 op->result_cont = cb; 811 op->result_cont = cb;
768 op->cont_cls = cb_cls; 812 op->cont_cls = cb_cls;
769 op->id = h->request_id_counter++; 813 op->id = h->request_id_counter++;
770 GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, 814 GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head,
771 h->operation_pending_tail, 815 h->operation_pending_tail,
772 op); 816 op);
773 env = GNUNET_MQ_msg_extra(msg, slen, type); 817 env = GNUNET_MQ_msg_extra (msg, slen, type);
774 msg->reserved = htonl(0); 818 msg->reserved = htonl (0);
775 msg->request_id = GNUNET_htonll(op->id); 819 msg->request_id = GNUNET_htonll (op->id);
776 GNUNET_memcpy(&msg[1], service_name, slen); 820 GNUNET_memcpy (&msg[1], service_name, slen);
777 GNUNET_MQ_send(h->mq, env); 821 GNUNET_MQ_send (h->mq, env);
778 return op; 822 return op;
779} 823}
780 824
@@ -785,22 +829,24 @@ change_service(struct GNUNET_ARM_Handle *h,
785 * @param cls the operation that asked ARM to be started 829 * @param cls the operation that asked ARM to be started
786 */ 830 */
787static void 831static void
788notify_running(void *cls) 832notify_running (void *cls)
789{ 833{
790 struct GNUNET_ARM_Operation *op = cls; 834 struct GNUNET_ARM_Operation *op = cls;
791 struct GNUNET_ARM_Handle *h = op->h; 835 struct GNUNET_ARM_Handle *h = op->h;
792 836
793 op->async = NULL; 837 op->async = NULL;
794 GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, 838 GNUNET_CONTAINER_DLL_remove (h->operation_pending_head,
795 h->operation_pending_tail, 839 h->operation_pending_tail,
796 op); 840 op);
797 if (NULL != op->result_cont) 841 if (NULL != op->result_cont)
798 op->result_cont(op->cont_cls, 842 op->result_cont (op->cont_cls,
799 GNUNET_ARM_REQUEST_SENT_OK, 843 GNUNET_ARM_REQUEST_SENT_OK,
800 GNUNET_ARM_RESULT_IS_STARTED_ALREADY); 844 GNUNET_ARM_RESULT_IS_STARTED_ALREADY);
801 if ((GNUNET_YES == h->currently_up) && (NULL != h->conn_status)) 845 if ( (GNUNET_YES == h->currently_up) &&
802 h->conn_status(h->conn_status_cls, GNUNET_YES); 846 (NULL != h->conn_status) )
803 GNUNET_free(op); 847 h->conn_status (h->conn_status_cls,
848 GNUNET_YES);
849 GNUNET_free (op);
804} 850}
805 851
806 852
@@ -810,22 +856,22 @@ notify_running(void *cls)
810 * @param cls the operation that asked ARM to be started 856 * @param cls the operation that asked ARM to be started
811 */ 857 */
812static void 858static void
813notify_starting(void *cls) 859notify_starting (void *cls)
814{ 860{
815 struct GNUNET_ARM_Operation *op = cls; 861 struct GNUNET_ARM_Operation *op = cls;
816 struct GNUNET_ARM_Handle *h = op->h; 862 struct GNUNET_ARM_Handle *h = op->h;
817 863
818 op->async = NULL; 864 op->async = NULL;
819 LOG(GNUNET_ERROR_TYPE_DEBUG, 865 LOG (GNUNET_ERROR_TYPE_DEBUG,
820 "Notifying client that we started the ARM service\n"); 866 "Notifying client that we started the ARM service\n");
821 GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, 867 GNUNET_CONTAINER_DLL_remove (h->operation_pending_head,
822 h->operation_pending_tail, 868 h->operation_pending_tail,
823 op); 869 op);
824 if (NULL != op->result_cont) 870 if (NULL != op->result_cont)
825 op->result_cont(op->cont_cls, 871 op->result_cont (op->cont_cls,
826 GNUNET_ARM_REQUEST_SENT_OK, 872 GNUNET_ARM_REQUEST_SENT_OK,
827 op->starting_ret); 873 op->starting_ret);
828 GNUNET_free(op); 874 GNUNET_free (op);
829} 875}
830 876
831 877
@@ -840,23 +886,26 @@ notify_starting(void *cls)
840 * @return handle for the operation, NULL on error 886 * @return handle for the operation, NULL on error
841 */ 887 */
842struct GNUNET_ARM_Operation * 888struct GNUNET_ARM_Operation *
843GNUNET_ARM_request_service_start( 889GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
844 struct GNUNET_ARM_Handle *h, 890 const char *service_name,
845 const char *service_name, 891 enum GNUNET_OS_InheritStdioFlags
846 enum GNUNET_OS_InheritStdioFlags std_inheritance, 892 std_inheritance,
847 GNUNET_ARM_ResultCallback cont, 893 GNUNET_ARM_ResultCallback cont,
848 void *cont_cls) 894 void *cont_cls)
849{ 895{
850 struct GNUNET_ARM_Operation *op; 896 struct GNUNET_ARM_Operation *op;
851 enum GNUNET_ARM_Result ret; 897 enum GNUNET_ARM_Result ret;
852 898
853 LOG(GNUNET_ERROR_TYPE_DEBUG, "Starting service `%s'\n", service_name); 899 LOG (GNUNET_ERROR_TYPE_DEBUG,
854 if (0 != strcasecmp("arm", service_name)) 900 "Starting service `%s'\n",
855 return change_service(h, 901 service_name);
856 service_name, 902 if (0 != strcasecmp ("arm",
857 cont, 903 service_name))
858 cont_cls, 904 return change_service (h,
859 GNUNET_MESSAGE_TYPE_ARM_START); 905 service_name,
906 cont,
907 cont_cls,
908 GNUNET_MESSAGE_TYPE_ARM_START);
860 909
861 /* Possible cases: 910 /* Possible cases:
862 * 1) We're connected to ARM already. Invoke the callback immediately. 911 * 1) We're connected to ARM already. Invoke the callback immediately.
@@ -865,37 +914,39 @@ GNUNET_ARM_request_service_start(
865 * a service test. 914 * a service test.
866 */ 915 */
867 if (GNUNET_YES == h->currently_up) 916 if (GNUNET_YES == h->currently_up)
868 { 917 {
869 LOG(GNUNET_ERROR_TYPE_DEBUG, "ARM is already running\n"); 918 LOG (GNUNET_ERROR_TYPE_DEBUG,
870 op = GNUNET_new(struct GNUNET_ARM_Operation); 919 "ARM is already running\n");
871 op->h = h; 920 op = GNUNET_new (struct GNUNET_ARM_Operation);
872 op->result_cont = cont; 921 op->h = h;
873 op->cont_cls = cont_cls; 922 op->result_cont = cont;
874 GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, 923 op->cont_cls = cont_cls;
875 h->operation_pending_tail, 924 GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head,
876 op); 925 h->operation_pending_tail,
877 op->async = GNUNET_SCHEDULER_add_now(&notify_running, op); 926 op);
878 return op; 927 op->async = GNUNET_SCHEDULER_add_now (&notify_running, op);
879 } 928 return op;
929 }
880 /* This is an inherently uncertain choice, as it is of course 930 /* This is an inherently uncertain choice, as it is of course
881 theoretically possible that ARM is up and we just did not 931 theoretically possible that ARM is up and we just did not
882 yet complete the MQ handshake. However, given that users 932 yet complete the MQ handshake. However, given that users
883 are unlikely to hammer 'gnunet-arm -s' on a busy system, 933 are unlikely to hammer 'gnunet-arm -s' on a busy system,
884 the above check should catch 99.99% of the cases where ARM 934 the above check should catch 99.99% of the cases where ARM
885 is already running. */ 935 is already running. */
886 LOG(GNUNET_ERROR_TYPE_DEBUG, "Starting ARM service\n"); 936 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting ARM service\n");
887 ret = start_arm_service(h, std_inheritance); 937 ret = start_arm_service (h, std_inheritance);
888 if (GNUNET_ARM_RESULT_STARTING == ret) 938 if (GNUNET_ARM_RESULT_STARTING == ret)
889 reconnect_arm(h); 939 reconnect_arm (h);
890 op = GNUNET_new(struct GNUNET_ARM_Operation); 940 op = GNUNET_new (struct GNUNET_ARM_Operation);
891 op->h = h; 941 op->h = h;
892 op->result_cont = cont; 942 op->result_cont = cont;
893 op->cont_cls = cont_cls; 943 op->cont_cls = cont_cls;
894 GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, 944 GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head,
895 h->operation_pending_tail, 945 h->operation_pending_tail,
896 op); 946 op);
897 op->starting_ret = ret; 947 op->starting_ret = ret;
898 op->async = GNUNET_SCHEDULER_add_now(&notify_starting, op); 948 op->async = GNUNET_SCHEDULER_add_now (&notify_starting,
949 op);
899 return op; 950 return op;
900} 951}
901 952
@@ -915,24 +966,27 @@ GNUNET_ARM_request_service_start(
915 * @return handle for the operation, NULL on error 966 * @return handle for the operation, NULL on error
916 */ 967 */
917struct GNUNET_ARM_Operation * 968struct GNUNET_ARM_Operation *
918GNUNET_ARM_request_service_stop(struct GNUNET_ARM_Handle *h, 969GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
919 const char *service_name, 970 const char *service_name,
920 GNUNET_ARM_ResultCallback cont, 971 GNUNET_ARM_ResultCallback cont,
921 void *cont_cls) 972 void *cont_cls)
922{ 973{
923 struct GNUNET_ARM_Operation *op; 974 struct GNUNET_ARM_Operation *op;
924 975
925 LOG(GNUNET_ERROR_TYPE_DEBUG, "Stopping service `%s'\n", service_name); 976 LOG (GNUNET_ERROR_TYPE_DEBUG,
926 op = change_service(h, 977 "Stopping service `%s'\n",
927 service_name, 978 service_name);
928 cont, 979 op = change_service (h,
929 cont_cls, 980 service_name,
930 GNUNET_MESSAGE_TYPE_ARM_STOP); 981 cont,
982 cont_cls,
983 GNUNET_MESSAGE_TYPE_ARM_STOP);
931 if (NULL == op) 984 if (NULL == op)
932 return NULL; 985 return NULL;
933 /* If the service is ARM, set a flag as we will use MQ errors 986 /* If the service is ARM, set a flag as we will use MQ errors
934 to detect that the process is really gone. */ 987 to detect that the process is really gone. */
935 if (0 == strcasecmp(service_name, "arm")) 988 if (0 == strcasecmp (service_name,
989 "arm"))
936 op->is_arm_stop = GNUNET_YES; 990 op->is_arm_stop = GNUNET_YES;
937 return op; 991 return op;
938} 992}
@@ -947,29 +1001,31 @@ GNUNET_ARM_request_service_stop(struct GNUNET_ARM_Handle *h,
947 * @return handle for the operation, NULL on error 1001 * @return handle for the operation, NULL on error
948 */ 1002 */
949struct GNUNET_ARM_Operation * 1003struct GNUNET_ARM_Operation *
950GNUNET_ARM_request_service_list(struct GNUNET_ARM_Handle *h, 1004GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
951 GNUNET_ARM_ServiceListCallback cont, 1005 GNUNET_ARM_ServiceListCallback cont,
952 void *cont_cls) 1006 void *cont_cls)
953{ 1007{
954 struct GNUNET_ARM_Operation *op; 1008 struct GNUNET_ARM_Operation *op;
955 struct GNUNET_MQ_Envelope *env; 1009 struct GNUNET_MQ_Envelope *env;
956 struct GNUNET_ARM_Message *msg; 1010 struct GNUNET_ARM_Message *msg;
957 1011
958 LOG(GNUNET_ERROR_TYPE_DEBUG, "Requesting LIST from ARM service\n"); 1012 LOG (GNUNET_ERROR_TYPE_DEBUG,
1013 "Requesting LIST from ARM service\n");
959 if (0 == h->request_id_counter) 1014 if (0 == h->request_id_counter)
960 h->request_id_counter++; 1015 h->request_id_counter++;
961 op = GNUNET_new(struct GNUNET_ARM_Operation); 1016 op = GNUNET_new (struct GNUNET_ARM_Operation);
962 op->h = h; 1017 op->h = h;
963 op->list_cont = cont; 1018 op->list_cont = cont;
964 op->cont_cls = cont_cls; 1019 op->cont_cls = cont_cls;
965 op->id = h->request_id_counter++; 1020 op->id = h->request_id_counter++;
966 GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, 1021 GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head,
967 h->operation_pending_tail, 1022 h->operation_pending_tail,
968 op); 1023 op);
969 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_ARM_LIST); 1024 env = GNUNET_MQ_msg (msg,
970 msg->reserved = htonl(0); 1025 GNUNET_MESSAGE_TYPE_ARM_LIST);
971 msg->request_id = GNUNET_htonll(op->id); 1026 msg->reserved = htonl (0);
972 GNUNET_MQ_send(h->mq, env); 1027 msg->request_id = GNUNET_htonll (op->id);
1028 GNUNET_MQ_send (h->mq, env);
973 return op; 1029 return op;
974} 1030}
975 1031