aboutsummaryrefslogtreecommitdiff
path: root/src/arm/arm_api.c
diff options
context:
space:
mode:
authorLRN <lrn1986@gmail.com>2013-03-20 18:50:18 +0000
committerLRN <lrn1986@gmail.com>2013-03-20 18:50:18 +0000
commit346748a3a55e197fe206e87b0520cef85ab9fda3 (patch)
tree37bc351cba1af84ee12e8d5dcd6d596f0456da3f /src/arm/arm_api.c
parent41646c7ce6e3d1711beb4b95da08afbd5b79d097 (diff)
downloadgnunet-346748a3a55e197fe206e87b0520cef85ab9fda3.tar.gz
gnunet-346748a3a55e197fe206e87b0520cef85ab9fda3.zip
Simplify ARM alloc/connect
Diffstat (limited to 'src/arm/arm_api.c')
-rw-r--r--src/arm/arm_api.c55
1 files changed, 24 insertions, 31 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index 18b4d220c..49cc55315 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -176,7 +176,7 @@ struct ARMControlMessage
176static void 176static void
177client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg); 177client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg);
178 178
179static void 179static int
180reconnect_arm (struct GNUNET_ARM_Handle *h); 180reconnect_arm (struct GNUNET_ARM_Handle *h);
181 181
182static void 182static void
@@ -246,7 +246,7 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h)
246 } 246 }
247 247
248 if (NULL != h->conn_status) 248 if (NULL != h->conn_status)
249 h->conn_status (h->conn_status_cls, h, GNUNET_NO, GNUNET_NO); 249 h->conn_status (h->conn_status_cls, h, GNUNET_NO);
250 250
251 h->currently_down = GNUNET_YES; 251 h->currently_down = GNUNET_YES;
252 252
@@ -286,7 +286,7 @@ transmit_arm_message (void *cls, size_t size, void *buf)
286 { 286 {
287 h->currently_down = GNUNET_NO; 287 h->currently_down = GNUNET_NO;
288 if (NULL != h->conn_status) 288 if (NULL != h->conn_status)
289 h->conn_status (h->conn_status_cls, h, GNUNET_YES, GNUNET_NO); 289 h->conn_status (h->conn_status_cls, h, GNUNET_YES);
290 h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS; 290 h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
291 GNUNET_CLIENT_receive (h->client, &client_notify_handler, h, 291 GNUNET_CLIENT_receive (h->client, &client_notify_handler, h,
292 GNUNET_TIME_UNIT_FOREVER_REL); 292 GNUNET_TIME_UNIT_FOREVER_REL);
@@ -384,7 +384,7 @@ trigger_next_request (struct GNUNET_ARM_Handle *h, int ignore_currently_down)
384 * 384 *
385 * @param h arm handle 385 * @param h arm handle
386 */ 386 */
387static void 387static int
388reconnect_arm (struct GNUNET_ARM_Handle *h) 388reconnect_arm (struct GNUNET_ARM_Handle *h)
389{ 389{
390 GNUNET_assert (NULL == h->client); 390 GNUNET_assert (NULL == h->client);
@@ -395,52 +395,45 @@ reconnect_arm (struct GNUNET_ARM_Handle *h)
395 LOG (GNUNET_ERROR_TYPE_DEBUG, 395 LOG (GNUNET_ERROR_TYPE_DEBUG,
396 "arm_api, GNUNET_CLIENT_connect returned NULL\n"); 396 "arm_api, GNUNET_CLIENT_connect returned NULL\n");
397 if (NULL != h->conn_status) 397 if (NULL != h->conn_status)
398 h->conn_status (h->conn_status_cls, h, GNUNET_NO, GNUNET_YES); 398 h->conn_status (h->conn_status_cls, h, GNUNET_SYSERR);
399 return; 399 return GNUNET_SYSERR;
400 } 400 }
401 LOG (GNUNET_ERROR_TYPE_DEBUG, 401 LOG (GNUNET_ERROR_TYPE_DEBUG,
402 "arm_api, GNUNET_CLIENT_connect returned non-NULL\n"); 402 "arm_api, GNUNET_CLIENT_connect returned non-NULL\n");
403 trigger_next_request (h, GNUNET_YES); 403 trigger_next_request (h, GNUNET_YES);
404 return GNUNET_OK;
404} 405}
405 406
406 407
407/** 408/**
408 * Set up a context for communicating with ARM. Note that this 409 * Set up a context for communicating with ARM, then
409 * can be done even if the ARM service is not yet running. 410 * start connecting to the ARM service using that context.
410 * Never fails.
411 * 411 *
412 * @param cfg configuration to use (needed to contact ARM; 412 * @param cfg configuration to use (needed to contact ARM;
413 * the ARM service may internally use a different 413 * the ARM service may internally use a different
414 * configuration to determine how to start the service). 414 * configuration to determine how to start the service).
415 * @return context to use for further ARM operations
416 */
417struct GNUNET_ARM_Handle *
418GNUNET_ARM_alloc (const struct GNUNET_CONFIGURATION_Handle *cfg)
419{
420 struct GNUNET_ARM_Handle *ret;
421
422 ret = GNUNET_malloc (sizeof (struct GNUNET_ARM_Handle));
423 ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
424 ret->currently_down = GNUNET_YES;
425 ret->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
426 return ret;
427}
428
429
430/**
431 * Start connecting to the ARM service using the context.
432 *
433 * @param h ARM handle
434 * @param conn_status will be called when connecting/disconnecting 415 * @param conn_status will be called when connecting/disconnecting
435 * @param cls closure for conn_status 416 * @param cls closure for conn_status
417 * @return context to use for further ARM operations, NULL on error.
436 */ 418 */
437void 419struct GNUNET_ARM_Handle *
438GNUNET_ARM_connect (struct GNUNET_ARM_Handle *h, 420GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
439 GNUNET_ARM_ConnectionStatusCallback conn_status, void *cls) 421 GNUNET_ARM_ConnectionStatusCallback conn_status, void *cls)
440{ 422{
423 struct GNUNET_ARM_Handle *h;
424
425 h = GNUNET_malloc (sizeof (struct GNUNET_ARM_Handle));
426 h->cfg = GNUNET_CONFIGURATION_dup (cfg);
427 h->currently_down = GNUNET_YES;
428 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
441 h->conn_status = conn_status; 429 h->conn_status = conn_status;
442 h->conn_status_cls = cls; 430 h->conn_status_cls = cls;
443 reconnect_arm (h); 431 if (GNUNET_OK != reconnect_arm (h))
432 {
433 GNUNET_free (h);
434 return NULL;
435 }
436 return h;
444} 437}
445 438
446 439