From eadf4b7379049d32d7cfc5cffd4c88613f8a2a93 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 27 Sep 2019 22:33:50 +0200 Subject: indent --- src/arm/arm_api.c | 820 ++++++++++++++++++++++++++++------------------------ src/util/client.c | 845 +++++++++++++++++++++++++++--------------------------- 2 files changed, 862 insertions(+), 803 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 @@ /* This file is part of GNUnet. - Copyright (C) 2009, 2010, 2012, 2013, 2016 GNUnet e.V. + Copyright (C) 2009, 2010, 2012, 2013, 2016, 2019 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -30,14 +30,15 @@ #include "gnunet_protocols.h" #include "arm.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "arm-api", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "arm-api", __VA_ARGS__) /** * Entry in a doubly-linked list of operations awaiting for replies * (in-order) from the ARM service. */ -struct GNUNET_ARM_Operation { +struct GNUNET_ARM_Operation +{ /** * This is a doubly-linked list. */ @@ -93,7 +94,8 @@ struct GNUNET_ARM_Operation { /** * Handle for interacting with ARM. */ -struct GNUNET_ARM_Handle { +struct GNUNET_ARM_Handle +{ /** * Our connection to the ARM service. */ @@ -164,7 +166,7 @@ struct GNUNET_ARM_Handle { * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -reconnect_arm(struct GNUNET_ARM_Handle *h); +reconnect_arm (struct GNUNET_ARM_Handle *h); /** @@ -173,12 +175,12 @@ reconnect_arm(struct GNUNET_ARM_Handle *h); * @param cls the `struct GNUNET_ARM_Handle` */ static void -reconnect_arm_task(void *cls) +reconnect_arm_task (void *cls) { struct GNUNET_ARM_Handle *h = cls; h->reconnect_task = NULL; - reconnect_arm(h); + reconnect_arm (h); } @@ -189,31 +191,31 @@ reconnect_arm_task(void *cls) * @param h our handle */ static void -reconnect_arm_later(struct GNUNET_ARM_Handle *h) +reconnect_arm_later (struct GNUNET_ARM_Handle *h) { struct GNUNET_ARM_Operation *op; if (NULL != h->mq) - { - GNUNET_MQ_destroy(h->mq); - h->mq = NULL; - } + { + GNUNET_MQ_destroy (h->mq); + h->mq = NULL; + } h->currently_up = GNUNET_NO; - GNUNET_assert(NULL == h->reconnect_task); + GNUNET_assert (NULL == h->reconnect_task); h->reconnect_task = - GNUNET_SCHEDULER_add_delayed(h->retry_backoff, &reconnect_arm_task, h); + GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_task, h); while (NULL != (op = h->operation_pending_head)) - { - if (NULL != op->result_cont) - op->result_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); - if (NULL != op->list_cont) - op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); - GNUNET_ARM_operation_cancel(op); - } - GNUNET_assert(NULL == h->operation_pending_head); - h->retry_backoff = GNUNET_TIME_STD_BACKOFF(h->retry_backoff); + { + if (NULL != op->result_cont) + op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); + if (NULL != op->list_cont) + op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); + GNUNET_ARM_operation_cancel (op); + } + GNUNET_assert (NULL == h->operation_pending_head); + h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); if (NULL != h->conn_status) - h->conn_status(h->conn_status_cls, GNUNET_NO); + h->conn_status (h->conn_status_cls, GNUNET_NO); } @@ -225,11 +227,11 @@ reconnect_arm_later(struct GNUNET_ARM_Handle *h) * @return NULL if not found */ static struct GNUNET_ARM_Operation * -find_op_by_id(struct GNUNET_ARM_Handle *h, uint64_t id) +find_op_by_id (struct GNUNET_ARM_Handle *h, + uint64_t id) { - struct GNUNET_ARM_Operation *result; - - for (result = h->operation_pending_head; NULL != result; + for (struct GNUNET_ARM_Operation *result = h->operation_pending_head; + NULL != result; result = result->next) if (id == result->id) return result; @@ -244,7 +246,8 @@ find_op_by_id(struct GNUNET_ARM_Handle *h, uint64_t id) * @param res the message received from the arm service */ static void -handle_arm_result(void *cls, const struct GNUNET_ARM_ResultMessage *res) +handle_arm_result (void *cls, + const struct GNUNET_ARM_ResultMessage *res) { struct GNUNET_ARM_Handle *h = cls; struct GNUNET_ARM_Operation *op; @@ -253,43 +256,46 @@ handle_arm_result(void *cls, const struct GNUNET_ARM_ResultMessage *res) GNUNET_ARM_ResultCallback result_cont; void *result_cont_cls; - id = GNUNET_ntohll(res->arm_msg.request_id); - op = find_op_by_id(h, id); + id = GNUNET_ntohll (res->arm_msg.request_id); + op = find_op_by_id (h, id); if (NULL == op) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Message with unknown id %llu\n", - (unsigned long long)id); - return; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Message with unknown id %llu\n", + (unsigned long long) id); + return; + } - result = (enum GNUNET_ARM_Result)ntohl(res->result); - if ((GNUNET_YES == op->is_arm_stop) && (GNUNET_ARM_RESULT_STOPPING == result)) + result = (enum GNUNET_ARM_Result) ntohl (res->result); + if ( (GNUNET_YES == op->is_arm_stop) && + (GNUNET_ARM_RESULT_STOPPING == result) ) + { + /* special case: if we are stopping 'gnunet-service-arm', we do not just + wait for the result message, but also wait for the service to close + the connection (and then we have to close our client handle as well); + this is done by installing a different receive handler, waiting for + the connection to go down */ + if (NULL != h->thm) { - /* special case: if we are stopping 'gnunet-service-arm', we do not just - wait for the result message, but also wait for the service to close - the connection (and then we have to close our client handle as well); - this is done by installing a different receive handler, waiting for - the connection to go down */ - if (NULL != h->thm) - { - GNUNET_break(0); - op->result_cont(h->thm->cont_cls, - GNUNET_ARM_REQUEST_SENT_OK, - GNUNET_ARM_RESULT_IS_NOT_KNOWN); - GNUNET_free(h->thm); - } - GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, - h->operation_pending_tail, - op); - h->thm = op; - return; + GNUNET_break (0); + op->result_cont (h->thm->cont_cls, + GNUNET_ARM_REQUEST_SENT_OK, + GNUNET_ARM_RESULT_IS_NOT_KNOWN); + GNUNET_free (h->thm); } + GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, + h->operation_pending_tail, + op); + h->thm = op; + return; + } result_cont = op->result_cont; result_cont_cls = op->cont_cls; - GNUNET_ARM_operation_cancel(op); + GNUNET_ARM_operation_cancel (op); if (NULL != result_cont) - result_cont(result_cont_cls, GNUNET_ARM_REQUEST_SENT_OK, result); + result_cont (result_cont_cls, + GNUNET_ARM_REQUEST_SENT_OK, + result); } @@ -303,7 +309,9 @@ handle_arm_result(void *cls, const struct GNUNET_ARM_ResultMessage *res) * NULL if the index is out of bounds */ static const char * -pool_get (const char *pool_start, size_t pool_size, size_t str_index) +pool_get (const char *pool_start, + size_t pool_size, + size_t str_index) { const char *str_start; const char *end; @@ -311,7 +319,7 @@ pool_get (const char *pool_start, size_t pool_size, size_t str_index) if (str_index >= pool_size) return NULL; str_start = pool_start + str_index; - end = memchr(str_start, 0, pool_size - str_index); + end = memchr (str_start, 0, pool_size - str_index); if (NULL == end) return NULL; return str_start; @@ -326,42 +334,42 @@ pool_get (const char *pool_start, size_t pool_size, size_t str_index) * @return #GNUNET_OK if message is well-formed */ static int -check_arm_list_result(void *cls, - const struct GNUNET_ARM_ListResultMessage *lres) +check_arm_list_result (void *cls, + const struct GNUNET_ARM_ListResultMessage *lres) { - uint16_t rcount = ntohs(lres->count); - uint16_t msize = ntohs(lres->arm_msg.header.size) - sizeof(*lres); + uint16_t rcount = ntohs (lres->count); + uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof(*lres); struct GNUNET_ARM_ServiceInfoMessage *ssm; size_t pool_size; char *pool_start; + (void) cls; if ((rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage) > msize)) { GNUNET_break_op (0); return GNUNET_NO; } - ssm = (struct GNUNET_ARM_ServiceInfoMessage *) &lres[1]; pool_start = (char *) (ssm + rcount); pool_size = msize - (rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage)); - - (void)cls; for (unsigned int i = 0; i < rcount; i++) + { + uint16_t name_index = ntohs (ssm->name_index); + uint16_t binary_index = ntohs (ssm->binary_index); + if (NULL == pool_get (pool_start, pool_size, name_index)) { - uint16_t name_index = ntohs (ssm->name_index); - uint16_t binary_index = ntohs (ssm->binary_index); - if (NULL == pool_get (pool_start, pool_size, name_index)) - { - GNUNET_break_op (0); - return GNUNET_NO; - } - if (NULL == pool_get (pool_start, pool_size, binary_index)) - { - GNUNET_break_op (0); - return GNUNET_NO; - } - ssm++; + GNUNET_break_op (0); + return GNUNET_NO; } + if (NULL == pool_get (pool_start, + pool_size, + binary_index)) + { + GNUNET_break_op (0); + return GNUNET_NO; + } + ssm++; + } return GNUNET_OK; } @@ -373,12 +381,12 @@ check_arm_list_result(void *cls, * @param lres the message received from the arm service */ static void -handle_arm_list_result(void *cls, - const struct GNUNET_ARM_ListResultMessage *lres) +handle_arm_list_result (void *cls, + const struct GNUNET_ARM_ListResultMessage *lres) { struct GNUNET_ARM_Handle *h = cls; - uint16_t rcount = ntohs(lres->count); - uint16_t msize = ntohs(lres->arm_msg.header.size) - sizeof(*lres); + uint16_t rcount = ntohs (lres->count); + uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof(*lres); struct GNUNET_ARM_ServiceInfo list[rcount]; struct GNUNET_ARM_ServiceInfoMessage *ssm; struct GNUNET_ARM_Operation *op; @@ -386,44 +394,50 @@ handle_arm_list_result(void *cls, size_t pool_size; char *pool_start; - id = GNUNET_ntohll(lres->arm_msg.request_id); - op = find_op_by_id(h, id); + id = GNUNET_ntohll (lres->arm_msg.request_id); + op = find_op_by_id (h, id); if (NULL == op) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Message with unknown id %llu\n", - (unsigned long long)id); - return; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Message with unknown id %llu\n", + (unsigned long long) id); + return; + } - GNUNET_assert ((rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage) <= msize)); + GNUNET_assert ((rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage) <= + msize)); ssm = (struct GNUNET_ARM_ServiceInfoMessage *) &lres[1]; pool_start = (char *) (ssm + rcount); pool_size = msize - (rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage)); for (unsigned int i = 0; i < rcount; i++) - { - uint16_t name_index = ntohs (ssm->name_index); - uint16_t binary_index = ntohs (ssm->binary_index); - const char *name; - const char *binary; - - GNUNET_assert (NULL != (name = pool_get (pool_start, pool_size, name_index))); - GNUNET_assert (NULL != (binary = pool_get (pool_start, pool_size, binary_index))); - list[i] = (struct GNUNET_ARM_ServiceInfo) { - .name = name, - .binary = binary, - .status = ntohl (ssm->status), - .last_started_at = GNUNET_TIME_absolute_ntoh (ssm->last_started_at), - .restart_at = GNUNET_TIME_absolute_ntoh (ssm->restart_at), - .last_exit_status = ntohs (ssm->last_exit_status), - }; - ssm++; - } + { + uint16_t name_index = ntohs (ssm->name_index); + uint16_t binary_index = ntohs (ssm->binary_index); + const char *name; + const char *binary; + + GNUNET_assert (NULL != (name = pool_get (pool_start, pool_size, + name_index))); + GNUNET_assert (NULL != (binary = pool_get (pool_start, pool_size, + binary_index))); + list[i] = (struct GNUNET_ARM_ServiceInfo) { + .name = name, + .binary = binary, + .status = ntohl (ssm->status), + .last_started_at = GNUNET_TIME_absolute_ntoh (ssm->last_started_at), + .restart_at = GNUNET_TIME_absolute_ntoh (ssm->restart_at), + .last_exit_status = ntohs (ssm->last_exit_status), + }; + ssm++; + } if (NULL != op->list_cont) - op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, rcount, list); - GNUNET_ARM_operation_cancel(op); + op->list_cont (op->cont_cls, + GNUNET_ARM_REQUEST_SENT_OK, + rcount, + list); + GNUNET_ARM_operation_cancel (op); } @@ -434,18 +448,20 @@ handle_arm_list_result(void *cls, * @param msg message received */ static void -handle_confirm(void *cls, const struct GNUNET_MessageHeader *msg) +handle_confirm (void *cls, + const struct GNUNET_MessageHeader *msg) { struct GNUNET_ARM_Handle *h = cls; - (void)msg; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Got confirmation from ARM that we are up!\n"); + (void) msg; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Got confirmation from ARM that we are up!\n"); if (GNUNET_NO == h->currently_up) - { - h->currently_up = GNUNET_YES; - if (NULL != h->conn_status) - h->conn_status(h->conn_status_cls, GNUNET_YES); - } + { + h->currently_up = GNUNET_YES; + if (NULL != h->conn_status) + h->conn_status (h->conn_status_cls, GNUNET_YES); + } } @@ -458,22 +474,23 @@ handle_confirm(void *cls, const struct GNUNET_MessageHeader *msg) * @param error error code */ static void -mq_error_handler(void *cls, enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_ARM_Handle *h = cls; struct GNUNET_ARM_Operation *op; - (void)error; + (void) error; h->currently_up = GNUNET_NO; if (NULL != (op = h->thm)) - { - h->thm = NULL; - op->result_cont(op->cont_cls, - GNUNET_ARM_REQUEST_SENT_OK, - GNUNET_ARM_RESULT_STOPPED); - GNUNET_free(op); - } - reconnect_arm_later(h); + { + h->thm = NULL; + op->result_cont (op->cont_cls, + GNUNET_ARM_REQUEST_SENT_OK, + GNUNET_ARM_RESULT_STOPPED); + GNUNET_free (op); + } + reconnect_arm_later (h); } @@ -484,39 +501,48 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error) * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -reconnect_arm(struct GNUNET_ARM_Handle *h) +reconnect_arm (struct GNUNET_ARM_Handle *h) { - struct GNUNET_MQ_MessageHandler handlers[] = - { GNUNET_MQ_hd_fixed_size(arm_result, - GNUNET_MESSAGE_TYPE_ARM_RESULT, - struct GNUNET_ARM_ResultMessage, - h), - GNUNET_MQ_hd_var_size(arm_list_result, - GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, - struct GNUNET_ARM_ListResultMessage, - h), - GNUNET_MQ_hd_fixed_size(confirm, - GNUNET_MESSAGE_TYPE_ARM_TEST, - struct GNUNET_MessageHeader, - h), - GNUNET_MQ_handler_end() }; + struct GNUNET_MQ_MessageHandler handlers[] = { + GNUNET_MQ_hd_fixed_size (arm_result, + GNUNET_MESSAGE_TYPE_ARM_RESULT, + struct GNUNET_ARM_ResultMessage, + h), + GNUNET_MQ_hd_var_size (arm_list_result, + GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, + struct GNUNET_ARM_ListResultMessage, + h), + GNUNET_MQ_hd_fixed_size (confirm, + GNUNET_MESSAGE_TYPE_ARM_TEST, + struct GNUNET_MessageHeader, + h), + GNUNET_MQ_handler_end () + }; struct GNUNET_MessageHeader *test; struct GNUNET_MQ_Envelope *env; if (NULL != h->mq) return GNUNET_OK; - GNUNET_assert(GNUNET_NO == h->currently_up); - h->mq = GNUNET_CLIENT_connect(h->cfg, "arm", handlers, &mq_error_handler, h); + GNUNET_assert (GNUNET_NO == h->currently_up); + h->mq = GNUNET_CLIENT_connect (h->cfg, + "arm", + handlers, + &mq_error_handler, + h); if (NULL == h->mq) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CLIENT_connect returned NULL\n"); - if (NULL != h->conn_status) - h->conn_status(h->conn_status_cls, GNUNET_SYSERR); - return GNUNET_SYSERR; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending TEST message to ARM\n"); - env = GNUNET_MQ_msg(test, GNUNET_MESSAGE_TYPE_ARM_TEST); - GNUNET_MQ_send(h->mq, env); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "GNUNET_CLIENT_connect returned NULL\n"); + if (NULL != h->conn_status) + h->conn_status (h->conn_status_cls, + GNUNET_SYSERR); + return GNUNET_SYSERR; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sending TEST message to ARM\n"); + env = GNUNET_MQ_msg (test, + GNUNET_MESSAGE_TYPE_ARM_TEST); + GNUNET_MQ_send (h->mq, env); return GNUNET_OK; } @@ -533,21 +559,21 @@ reconnect_arm(struct GNUNET_ARM_Handle *h) * @return context to use for further ARM operations, NULL on error. */ struct GNUNET_ARM_Handle * -GNUNET_ARM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_ARM_ConnectionStatusCallback conn_status, - void *conn_status_cls) +GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_ARM_ConnectionStatusCallback conn_status, + void *conn_status_cls) { struct GNUNET_ARM_Handle *h; - h = GNUNET_new(struct GNUNET_ARM_Handle); + h = GNUNET_new (struct GNUNET_ARM_Handle); h->cfg = cfg; h->conn_status = conn_status; h->conn_status_cls = conn_status_cls; - if (GNUNET_OK != reconnect_arm(h)) - { - GNUNET_free(h); - return NULL; - } + if (GNUNET_OK != reconnect_arm (h)) + { + GNUNET_free (h); + return NULL; + } return h; } @@ -558,38 +584,43 @@ GNUNET_ARM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, * @param h the handle that was being used */ void -GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h) +GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h) { struct GNUNET_ARM_Operation *op; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); while (NULL != (op = h->operation_pending_head)) + { + GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, + h->operation_pending_tail, + op); + if (NULL != op->result_cont) + op->result_cont (op->cont_cls, + GNUNET_ARM_REQUEST_DISCONNECTED, + 0); + if (NULL != op->list_cont) + op->list_cont (op->cont_cls, + GNUNET_ARM_REQUEST_DISCONNECTED, + 0, + NULL); + if (NULL != op->async) { - GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, - h->operation_pending_tail, - op); - if (NULL != op->result_cont) - op->result_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); - if (NULL != op->list_cont) - op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); - if (NULL != op->async) - { - GNUNET_SCHEDULER_cancel(op->async); - op->async = NULL; - } - GNUNET_free(op); + GNUNET_SCHEDULER_cancel (op->async); + op->async = NULL; } + GNUNET_free (op); + } if (NULL != h->mq) - { - GNUNET_MQ_destroy(h->mq); - h->mq = NULL; - } + { + GNUNET_MQ_destroy (h->mq); + h->mq = NULL; + } if (NULL != h->reconnect_task) - { - GNUNET_SCHEDULER_cancel(h->reconnect_task); - h->reconnect_task = NULL; - } - GNUNET_free(h); + { + GNUNET_SCHEDULER_cancel (h->reconnect_task); + h->reconnect_task = NULL; + } + GNUNET_free (h); } @@ -602,8 +633,8 @@ GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h) * @return operation status code */ static enum GNUNET_ARM_Result -start_arm_service(struct GNUNET_ARM_Handle *h, - enum GNUNET_OS_InheritStdioFlags std_inheritance) +start_arm_service (struct GNUNET_ARM_Handle *h, + enum GNUNET_OS_InheritStdioFlags std_inheritance) { struct GNUNET_OS_Process *proc; char *cbinary; @@ -613,98 +644,111 @@ start_arm_service(struct GNUNET_ARM_Handle *h, char *loprefix; char *lopostfix; - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(h->cfg, - "arm", - "PREFIX", - &loprefix)) - loprefix = GNUNET_strdup(""); + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, + "arm", + "PREFIX", + &loprefix)) + loprefix = GNUNET_strdup (""); else - loprefix = GNUNET_CONFIGURATION_expand_dollar(h->cfg, loprefix); - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(h->cfg, - "arm", - "OPTIONS", - &lopostfix)) - lopostfix = GNUNET_strdup(""); + loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, loprefix); + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, + "arm", + "OPTIONS", + &lopostfix)) + lopostfix = GNUNET_strdup (""); else - lopostfix = GNUNET_CONFIGURATION_expand_dollar(h->cfg, lopostfix); + lopostfix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, + lopostfix); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string(h->cfg, "arm", "BINARY", &cbinary)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, "arm", "BINARY"); - GNUNET_free(loprefix); - GNUNET_free(lopostfix); - return GNUNET_ARM_RESULT_IS_NOT_KNOWN; - } - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(h->cfg, - "arm", - "CONFIG", - &config)) + GNUNET_CONFIGURATION_get_value_string (h->cfg, + "arm", + "BINARY", + &cbinary)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, + "arm", + "BINARY"); + GNUNET_free (loprefix); + GNUNET_free (lopostfix); + return GNUNET_ARM_RESULT_IS_NOT_KNOWN; + } + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, + "arm", + "CONFIG", + &config)) config = NULL; - binary = GNUNET_OS_get_libexec_binary_path(cbinary); - GNUNET_asprintf("edbinary, "\"%s\"", binary); - GNUNET_free(cbinary); - if ((GNUNET_YES == - GNUNET_CONFIGURATION_have_value(h->cfg, "TESTING", "WEAKRANDOM")) && - (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(h->cfg, - "TESTING", - "WEAKRANDOM")) && - (GNUNET_NO == - GNUNET_CONFIGURATION_have_value(h->cfg, "TESTING", "HOSTFILE"))) - { - /* Means we are ONLY running locally */ - /* we're clearly running a test, don't daemonize */ - if (NULL == config) - proc = GNUNET_OS_start_process_s(GNUNET_NO, - std_inheritance, - NULL, - loprefix, - quotedbinary, - /* no daemonization! */ - lopostfix, - NULL); - else - proc = GNUNET_OS_start_process_s(GNUNET_NO, - std_inheritance, - NULL, - loprefix, - quotedbinary, - "-c", - config, - /* no daemonization! */ - lopostfix, - NULL); - } + binary = GNUNET_OS_get_libexec_binary_path (cbinary); + GNUNET_asprintf ("edbinary, + "\"%s\"", + binary); + GNUNET_free (cbinary); + if ( (GNUNET_YES == + GNUNET_CONFIGURATION_have_value (h->cfg, + "TESTING", + "WEAKRANDOM")) && + (GNUNET_YES == + GNUNET_CONFIGURATION_get_value_yesno (h->cfg, + "TESTING", + "WEAKRANDOM")) && + (GNUNET_NO == + GNUNET_CONFIGURATION_have_value (h->cfg, + "TESTING", + "HOSTFILE")) ) + { + /* Means we are ONLY running locally */ + /* we're clearly running a test, don't daemonize */ + if (NULL == config) + proc = GNUNET_OS_start_process_s (GNUNET_NO, + std_inheritance, + NULL, + loprefix, + quotedbinary, + /* no daemonization! */ + lopostfix, + NULL); + else + proc = GNUNET_OS_start_process_s (GNUNET_NO, + std_inheritance, + NULL, + loprefix, + quotedbinary, + "-c", + config, + /* no daemonization! */ + lopostfix, + NULL); + } else - { - if (NULL == config) - proc = GNUNET_OS_start_process_s(GNUNET_NO, - std_inheritance, - NULL, - loprefix, - quotedbinary, - "-d", /* do daemonize */ - lopostfix, - NULL); - else - proc = GNUNET_OS_start_process_s(GNUNET_NO, - std_inheritance, - NULL, - loprefix, - quotedbinary, - "-c", - config, - "-d", /* do daemonize */ - lopostfix, - NULL); - } - GNUNET_free(binary); - GNUNET_free(quotedbinary); - GNUNET_free_non_null(config); - GNUNET_free(loprefix); - GNUNET_free(lopostfix); + { + if (NULL == config) + proc = GNUNET_OS_start_process_s (GNUNET_NO, + std_inheritance, + NULL, + loprefix, + quotedbinary, + "-d", /* do daemonize */ + lopostfix, + NULL); + else + proc = GNUNET_OS_start_process_s (GNUNET_NO, + std_inheritance, + NULL, + loprefix, + quotedbinary, + "-c", + config, + "-d", /* do daemonize */ + lopostfix, + NULL); + } + GNUNET_free (binary); + GNUNET_free (quotedbinary); + GNUNET_free_non_null (config); + GNUNET_free (loprefix); + GNUNET_free (lopostfix); if (NULL == proc) return GNUNET_ARM_RESULT_START_FAILED; - GNUNET_OS_process_destroy(proc); + GNUNET_OS_process_destroy (proc); return GNUNET_ARM_RESULT_STARTING; } @@ -716,19 +760,19 @@ start_arm_service(struct GNUNET_ARM_Handle *h, * @param op operation to cancel */ void -GNUNET_ARM_operation_cancel(struct GNUNET_ARM_Operation *op) +GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op) { struct GNUNET_ARM_Handle *h = op->h; if (h->thm == op) - { - op->result_cont = NULL; - return; - } - GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, - h->operation_pending_tail, - op); - GNUNET_free(op); + { + op->result_cont = NULL; + return; + } + GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, + h->operation_pending_tail, + op); + GNUNET_free (op); } @@ -743,38 +787,38 @@ GNUNET_ARM_operation_cancel(struct GNUNET_ARM_Operation *op) * @return handle to queue, NULL on error */ static struct GNUNET_ARM_Operation * -change_service(struct GNUNET_ARM_Handle *h, - const char *service_name, - GNUNET_ARM_ResultCallback cb, - void *cb_cls, - uint16_t type) +change_service (struct GNUNET_ARM_Handle *h, + const char *service_name, + GNUNET_ARM_ResultCallback cb, + void *cb_cls, + uint16_t type) { struct GNUNET_ARM_Operation *op; size_t slen; struct GNUNET_MQ_Envelope *env; struct GNUNET_ARM_Message *msg; - slen = strlen(service_name) + 1; + slen = strlen (service_name) + 1; if (slen + sizeof(struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE) - { - GNUNET_break(0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } if (0 == h->request_id_counter) h->request_id_counter++; - op = GNUNET_new(struct GNUNET_ARM_Operation); + op = GNUNET_new (struct GNUNET_ARM_Operation); op->h = h; op->result_cont = cb; op->cont_cls = cb_cls; op->id = h->request_id_counter++; - GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, - h->operation_pending_tail, - op); - env = GNUNET_MQ_msg_extra(msg, slen, type); - msg->reserved = htonl(0); - msg->request_id = GNUNET_htonll(op->id); - GNUNET_memcpy(&msg[1], service_name, slen); - GNUNET_MQ_send(h->mq, env); + GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, + h->operation_pending_tail, + op); + env = GNUNET_MQ_msg_extra (msg, slen, type); + msg->reserved = htonl (0); + msg->request_id = GNUNET_htonll (op->id); + GNUNET_memcpy (&msg[1], service_name, slen); + GNUNET_MQ_send (h->mq, env); return op; } @@ -785,22 +829,24 @@ change_service(struct GNUNET_ARM_Handle *h, * @param cls the operation that asked ARM to be started */ static void -notify_running(void *cls) +notify_running (void *cls) { struct GNUNET_ARM_Operation *op = cls; struct GNUNET_ARM_Handle *h = op->h; op->async = NULL; - GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, - h->operation_pending_tail, - op); + GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, + h->operation_pending_tail, + op); if (NULL != op->result_cont) - op->result_cont(op->cont_cls, - GNUNET_ARM_REQUEST_SENT_OK, - GNUNET_ARM_RESULT_IS_STARTED_ALREADY); - if ((GNUNET_YES == h->currently_up) && (NULL != h->conn_status)) - h->conn_status(h->conn_status_cls, GNUNET_YES); - GNUNET_free(op); + op->result_cont (op->cont_cls, + GNUNET_ARM_REQUEST_SENT_OK, + GNUNET_ARM_RESULT_IS_STARTED_ALREADY); + if ( (GNUNET_YES == h->currently_up) && + (NULL != h->conn_status) ) + h->conn_status (h->conn_status_cls, + GNUNET_YES); + GNUNET_free (op); } @@ -810,22 +856,22 @@ notify_running(void *cls) * @param cls the operation that asked ARM to be started */ static void -notify_starting(void *cls) +notify_starting (void *cls) { struct GNUNET_ARM_Operation *op = cls; struct GNUNET_ARM_Handle *h = op->h; op->async = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Notifying client that we started the ARM service\n"); - GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, - h->operation_pending_tail, - op); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Notifying client that we started the ARM service\n"); + GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, + h->operation_pending_tail, + op); if (NULL != op->result_cont) - op->result_cont(op->cont_cls, - GNUNET_ARM_REQUEST_SENT_OK, - op->starting_ret); - GNUNET_free(op); + op->result_cont (op->cont_cls, + GNUNET_ARM_REQUEST_SENT_OK, + op->starting_ret); + GNUNET_free (op); } @@ -840,23 +886,26 @@ notify_starting(void *cls) * @return handle for the operation, NULL on error */ struct GNUNET_ARM_Operation * -GNUNET_ARM_request_service_start( - struct GNUNET_ARM_Handle *h, - const char *service_name, - enum GNUNET_OS_InheritStdioFlags std_inheritance, - GNUNET_ARM_ResultCallback cont, - void *cont_cls) +GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, + const char *service_name, + enum GNUNET_OS_InheritStdioFlags + std_inheritance, + GNUNET_ARM_ResultCallback cont, + void *cont_cls) { struct GNUNET_ARM_Operation *op; enum GNUNET_ARM_Result ret; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Starting service `%s'\n", service_name); - if (0 != strcasecmp("arm", service_name)) - return change_service(h, - service_name, - cont, - cont_cls, - GNUNET_MESSAGE_TYPE_ARM_START); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Starting service `%s'\n", + service_name); + if (0 != strcasecmp ("arm", + service_name)) + return change_service (h, + service_name, + cont, + cont_cls, + GNUNET_MESSAGE_TYPE_ARM_START); /* Possible cases: * 1) We're connected to ARM already. Invoke the callback immediately. @@ -865,37 +914,39 @@ GNUNET_ARM_request_service_start( * a service test. */ if (GNUNET_YES == h->currently_up) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "ARM is already running\n"); - op = GNUNET_new(struct GNUNET_ARM_Operation); - op->h = h; - op->result_cont = cont; - op->cont_cls = cont_cls; - GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, - h->operation_pending_tail, - op); - op->async = GNUNET_SCHEDULER_add_now(¬ify_running, op); - return op; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "ARM is already running\n"); + op = GNUNET_new (struct GNUNET_ARM_Operation); + op->h = h; + op->result_cont = cont; + op->cont_cls = cont_cls; + GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, + h->operation_pending_tail, + op); + op->async = GNUNET_SCHEDULER_add_now (¬ify_running, op); + return op; + } /* This is an inherently uncertain choice, as it is of course theoretically possible that ARM is up and we just did not yet complete the MQ handshake. However, given that users are unlikely to hammer 'gnunet-arm -s' on a busy system, the above check should catch 99.99% of the cases where ARM is already running. */ - LOG(GNUNET_ERROR_TYPE_DEBUG, "Starting ARM service\n"); - ret = start_arm_service(h, std_inheritance); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting ARM service\n"); + ret = start_arm_service (h, std_inheritance); if (GNUNET_ARM_RESULT_STARTING == ret) - reconnect_arm(h); - op = GNUNET_new(struct GNUNET_ARM_Operation); + reconnect_arm (h); + op = GNUNET_new (struct GNUNET_ARM_Operation); op->h = h; op->result_cont = cont; op->cont_cls = cont_cls; - GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, - h->operation_pending_tail, - op); + GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, + h->operation_pending_tail, + op); op->starting_ret = ret; - op->async = GNUNET_SCHEDULER_add_now(¬ify_starting, op); + op->async = GNUNET_SCHEDULER_add_now (¬ify_starting, + op); return op; } @@ -915,24 +966,27 @@ GNUNET_ARM_request_service_start( * @return handle for the operation, NULL on error */ struct GNUNET_ARM_Operation * -GNUNET_ARM_request_service_stop(struct GNUNET_ARM_Handle *h, - const char *service_name, - GNUNET_ARM_ResultCallback cont, - void *cont_cls) +GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, + const char *service_name, + GNUNET_ARM_ResultCallback cont, + void *cont_cls) { struct GNUNET_ARM_Operation *op; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Stopping service `%s'\n", service_name); - op = change_service(h, - service_name, - cont, - cont_cls, - GNUNET_MESSAGE_TYPE_ARM_STOP); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Stopping service `%s'\n", + service_name); + op = change_service (h, + service_name, + cont, + cont_cls, + GNUNET_MESSAGE_TYPE_ARM_STOP); if (NULL == op) return NULL; /* If the service is ARM, set a flag as we will use MQ errors to detect that the process is really gone. */ - if (0 == strcasecmp(service_name, "arm")) + if (0 == strcasecmp (service_name, + "arm")) op->is_arm_stop = GNUNET_YES; return op; } @@ -947,29 +1001,31 @@ GNUNET_ARM_request_service_stop(struct GNUNET_ARM_Handle *h, * @return handle for the operation, NULL on error */ struct GNUNET_ARM_Operation * -GNUNET_ARM_request_service_list(struct GNUNET_ARM_Handle *h, - GNUNET_ARM_ServiceListCallback cont, - void *cont_cls) +GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h, + GNUNET_ARM_ServiceListCallback cont, + void *cont_cls) { struct GNUNET_ARM_Operation *op; struct GNUNET_MQ_Envelope *env; struct GNUNET_ARM_Message *msg; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Requesting LIST from ARM service\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Requesting LIST from ARM service\n"); if (0 == h->request_id_counter) h->request_id_counter++; - op = GNUNET_new(struct GNUNET_ARM_Operation); + op = GNUNET_new (struct GNUNET_ARM_Operation); op->h = h; op->list_cont = cont; op->cont_cls = cont_cls; op->id = h->request_id_counter++; - GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, - h->operation_pending_tail, - op); - env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_ARM_LIST); - msg->reserved = htonl(0); - msg->request_id = GNUNET_htonll(op->id); - GNUNET_MQ_send(h->mq, env); + GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, + h->operation_pending_tail, + op); + env = GNUNET_MQ_msg (msg, + GNUNET_MESSAGE_TYPE_ARM_LIST); + msg->reserved = htonl (0); + msg->request_id = GNUNET_htonll (op->id); + GNUNET_MQ_send (h->mq, env); return op; } diff --git a/src/util/client.c b/src/util/client.c index e3585af2e..5a77b9238 100644 --- a/src/util/client.c +++ b/src/util/client.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2001-2016 GNUnet e.V. + Copyright (C) 2001-2016, 2019 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -33,7 +33,7 @@ #include "gnunet_socks.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "util-client", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "util-client", __VA_ARGS__) /** * Timeout we use on TCP connect before trying another @@ -41,7 +41,8 @@ * is this value divided by the number of address families. * Default is 5s. */ -#define CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) +#define CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 5) @@ -55,7 +56,8 @@ struct ClientState; * During connect, we try multiple possible IP addresses * to find out which one might work. */ -struct AddressProbe { +struct AddressProbe +{ /** * This is a linked list. */ @@ -96,7 +98,8 @@ struct AddressProbe { /** * Internal state for a client connected to a GNUnet service. */ -struct ClientState { +struct ClientState +{ /** * The connection handle, NULL if not live */ @@ -205,7 +208,7 @@ struct ClientState { * @param cls the `struct ClientState` to try to connect to the service */ static void -start_connect(void *cls); +start_connect (void *cls); /** @@ -215,26 +218,26 @@ start_connect(void *cls); * @param cstate the connection we tried to establish */ static void -connect_fail_continuation(struct ClientState *cstate) +connect_fail_continuation (struct ClientState *cstate) { - GNUNET_break(NULL == cstate->ap_head); - GNUNET_break(NULL == cstate->ap_tail); - GNUNET_break(NULL == cstate->dns_active); - GNUNET_break(NULL == cstate->sock); - GNUNET_assert(NULL == cstate->send_task); - GNUNET_assert(NULL == cstate->recv_task); + GNUNET_break (NULL == cstate->ap_head); + GNUNET_break (NULL == cstate->ap_tail); + GNUNET_break (NULL == cstate->dns_active); + GNUNET_break (NULL == cstate->sock); + GNUNET_assert (NULL == cstate->send_task); + GNUNET_assert (NULL == cstate->recv_task); // GNUNET_assert (NULL == cstate->proxy_handshake); - cstate->back_off = GNUNET_TIME_STD_BACKOFF(cstate->back_off); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Failed to establish connection to `%s', no further addresses to try, will try again in %s.\n", - cstate->service_name, - GNUNET_STRINGS_relative_time_to_string(cstate->back_off, - GNUNET_YES)); + cstate->back_off = GNUNET_TIME_STD_BACKOFF (cstate->back_off); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Failed to establish connection to `%s', no further addresses to try, will try again in %s.\n", + cstate->service_name, + GNUNET_STRINGS_relative_time_to_string (cstate->back_off, + GNUNET_YES)); cstate->retry_task - = GNUNET_SCHEDULER_add_delayed(cstate->back_off, - &start_connect, - cstate); + = GNUNET_SCHEDULER_add_delayed (cstate->back_off, + &start_connect, + cstate); } @@ -244,7 +247,7 @@ connect_fail_continuation(struct ClientState *cstate) * @param cls the `struct ClientState` with the `msg` to transmit */ static void -transmit_ready(void *cls) +transmit_ready (void *cls) { struct ClientState *cstate = cls; ssize_t ret; @@ -255,56 +258,56 @@ transmit_ready(void *cls) cstate->send_task = NULL; if (GNUNET_YES == cstate->in_destroy) return; - pos = (const char *)cstate->msg; - len = ntohs(cstate->msg->size); - GNUNET_assert(cstate->msg_off < len); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "message of type %u trying to send with socket %p (MQ: %p\n", - ntohs(cstate->msg->type), - cstate->sock, - cstate->mq); + pos = (const char *) cstate->msg; + len = ntohs (cstate->msg->size); + GNUNET_assert (cstate->msg_off < len); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "message of type %u trying to send with socket %p (MQ: %p\n", + ntohs (cstate->msg->type), + cstate->sock, + cstate->mq); RETRY: - ret = GNUNET_NETWORK_socket_send(cstate->sock, - &pos[cstate->msg_off], - len - cstate->msg_off); + ret = GNUNET_NETWORK_socket_send (cstate->sock, + &pos[cstate->msg_off], + len - cstate->msg_off); if (-1 == ret) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Error during sending message of type %u\n", + ntohs (cstate->msg->type)); + if (EINTR == errno) { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Error during sending message of type %u\n", - ntohs(cstate->msg->type)); - if (EINTR == errno) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Retrying message of type %u\n", - ntohs(cstate->msg->type)); - goto RETRY; - } - GNUNET_MQ_inject_error(cstate->mq, - GNUNET_MQ_ERROR_WRITE); - return; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Retrying message of type %u\n", + ntohs (cstate->msg->type)); + goto RETRY; } + GNUNET_MQ_inject_error (cstate->mq, + GNUNET_MQ_ERROR_WRITE); + return; + } notify_in_flight = (0 == cstate->msg_off); cstate->msg_off += ret; if (cstate->msg_off < len) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "rescheduling message of type %u\n", - ntohs(cstate->msg->type)); - cstate->send_task - = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, - cstate->sock, - &transmit_ready, - cstate); - if (notify_in_flight) - GNUNET_MQ_impl_send_in_flight(cstate->mq); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "sending message of type %u successful\n", - ntohs(cstate->msg->type)); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "rescheduling message of type %u\n", + ntohs (cstate->msg->type)); + cstate->send_task + = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, + cstate->sock, + &transmit_ready, + cstate); + if (notify_in_flight) + GNUNET_MQ_impl_send_in_flight (cstate->mq); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "sending message of type %u successful\n", + ntohs (cstate->msg->type)); cstate->msg = NULL; - GNUNET_MQ_impl_send_continue(cstate->mq); + GNUNET_MQ_impl_send_continue (cstate->mq); } @@ -319,20 +322,20 @@ RETRY: * #GNUNET_SYSERR to stop further processing due to error */ static int -recv_message(void *cls, - const struct GNUNET_MessageHeader *msg) +recv_message (void *cls, + const struct GNUNET_MessageHeader *msg) { struct ClientState *cstate = cls; if (GNUNET_YES == cstate->in_destroy) return GNUNET_NO; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Received message of type %u and size %u from %s\n", - ntohs(msg->type), - ntohs(msg->size), - cstate->service_name); - GNUNET_MQ_inject_message(cstate->mq, - msg); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received message of type %u and size %u from %s\n", + ntohs (msg->type), + ntohs (msg->size), + cstate->service_name); + GNUNET_MQ_inject_message (cstate->mq, + msg); if (GNUNET_YES == cstate->in_destroy) return GNUNET_NO; return GNUNET_OK; @@ -345,20 +348,20 @@ recv_message(void *cls, * @param cstate handle of the client state to process */ static void -cancel_aps(struct ClientState *cstate) +cancel_aps (struct ClientState *cstate) { struct AddressProbe *pos; while (NULL != (pos = cstate->ap_head)) - { - GNUNET_break(GNUNET_OK == - GNUNET_NETWORK_socket_close(pos->sock)); - GNUNET_SCHEDULER_cancel(pos->task); - GNUNET_CONTAINER_DLL_remove(cstate->ap_head, - cstate->ap_tail, - pos); - GNUNET_free(pos); - } + { + GNUNET_break (GNUNET_OK == + GNUNET_NETWORK_socket_close (pos->sock)); + GNUNET_SCHEDULER_cancel (pos->task); + GNUNET_CONTAINER_DLL_remove (cstate->ap_head, + cstate->ap_tail, + pos); + GNUNET_free (pos); + } } @@ -370,51 +373,51 @@ cancel_aps(struct ClientState *cstate) * @param impl_state our `struct ClientState` */ static void -connection_client_destroy_impl(struct GNUNET_MQ_Handle *mq, - void *impl_state) +connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq, + void *impl_state) { struct ClientState *cstate = impl_state; - (void)mq; + (void) mq; if (NULL != cstate->dns_active) - { - GNUNET_RESOLVER_request_cancel(cstate->dns_active); - cstate->dns_active = NULL; - } + { + GNUNET_RESOLVER_request_cancel (cstate->dns_active); + cstate->dns_active = NULL; + } if (NULL != cstate->send_task) - { - GNUNET_SCHEDULER_cancel(cstate->send_task); - cstate->send_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (cstate->send_task); + cstate->send_task = NULL; + } if (NULL != cstate->retry_task) - { - GNUNET_SCHEDULER_cancel(cstate->retry_task); - cstate->retry_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (cstate->retry_task); + cstate->retry_task = NULL; + } if (GNUNET_SYSERR == cstate->in_destroy) - { - /* defer destruction */ - cstate->in_destroy = GNUNET_YES; - cstate->mq = NULL; - return; - } + { + /* defer destruction */ + cstate->in_destroy = GNUNET_YES; + cstate->mq = NULL; + return; + } if (NULL != cstate->recv_task) - { - GNUNET_SCHEDULER_cancel(cstate->recv_task); - cstate->recv_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (cstate->recv_task); + cstate->recv_task = NULL; + } if (NULL != cstate->sock) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "destroying socket: %p\n", - cstate->sock); - GNUNET_NETWORK_socket_close(cstate->sock); - } - cancel_aps(cstate); - GNUNET_free(cstate->service_name); - GNUNET_free_non_null(cstate->hostname); - GNUNET_MST_destroy(cstate->mst); - GNUNET_free(cstate); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "destroying socket: %p\n", + cstate->sock); + GNUNET_NETWORK_socket_close (cstate->sock); + } + cancel_aps (cstate); + GNUNET_free (cstate->service_name); + GNUNET_free_non_null (cstate->hostname); + GNUNET_MST_destroy (cstate->mst); + GNUNET_free (cstate); } @@ -424,39 +427,39 @@ connection_client_destroy_impl(struct GNUNET_MQ_Handle *mq, * @param cls `struct ClientState` with connection to read from */ static void -receive_ready(void *cls) +receive_ready (void *cls) { struct ClientState *cstate = cls; int ret; cstate->recv_task = NULL; cstate->in_destroy = GNUNET_SYSERR; - ret = GNUNET_MST_read(cstate->mst, - cstate->sock, - GNUNET_NO, - GNUNET_NO); + ret = GNUNET_MST_read (cstate->mst, + cstate->sock, + GNUNET_NO, + GNUNET_NO); if (GNUNET_SYSERR == ret) - { - if (NULL != cstate->mq) - GNUNET_MQ_inject_error(cstate->mq, - GNUNET_MQ_ERROR_READ); - if (GNUNET_YES == cstate->in_destroy) - connection_client_destroy_impl(cstate->mq, - cstate); - return; - } + { + if (NULL != cstate->mq) + GNUNET_MQ_inject_error (cstate->mq, + GNUNET_MQ_ERROR_READ); + if (GNUNET_YES == cstate->in_destroy) + connection_client_destroy_impl (cstate->mq, + cstate); + return; + } if (GNUNET_YES == cstate->in_destroy) - { - connection_client_destroy_impl(cstate->mq, - cstate); - return; - } + { + connection_client_destroy_impl (cstate->mq, + cstate); + return; + } cstate->in_destroy = GNUNET_NO; cstate->recv_task - = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, - cstate->sock, - &receive_ready, - cstate); + = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + cstate->sock, + &receive_ready, + cstate); } @@ -466,23 +469,23 @@ receive_ready(void *cls) * @param cstate the connection we tried to establish */ static void -connect_success_continuation(struct ClientState *cstate) +connect_success_continuation (struct ClientState *cstate) { - GNUNET_assert(NULL == cstate->recv_task); + GNUNET_assert (NULL == cstate->recv_task); cstate->recv_task - = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, - cstate->sock, - &receive_ready, - cstate); + = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + cstate->sock, + &receive_ready, + cstate); if (NULL != cstate->msg) - { - GNUNET_assert(NULL == cstate->send_task); - cstate->send_task - = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, - cstate->sock, - &transmit_ready, - cstate); - } + { + GNUNET_assert (NULL == cstate->send_task); + cstate->send_task + = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, + cstate->sock, + &transmit_ready, + cstate); + } } @@ -494,8 +497,8 @@ connect_success_continuation(struct ClientState *cstate) * @return NULL on error, socket connected to UNIX otherwise */ static struct GNUNET_NETWORK_Handle * -try_unixpath(const char *service_name, - const struct GNUNET_CONFIGURATION_Handle *cfg) +try_unixpath (const char *service_name, + const struct GNUNET_CONFIGURATION_Handle *cfg) { #if AF_UNIX struct GNUNET_NETWORK_Handle *sock; @@ -504,67 +507,67 @@ try_unixpath(const char *service_name, unixpath = NULL; if ((GNUNET_OK == - GNUNET_CONFIGURATION_get_value_filename(cfg, - service_name, - "UNIXPATH", - &unixpath)) && - (0 < strlen(unixpath))) + GNUNET_CONFIGURATION_get_value_filename (cfg, + service_name, + "UNIXPATH", + &unixpath)) && + (0 < strlen (unixpath))) + { + /* We have a non-NULL unixpath, need to validate it */ + if (strlen (unixpath) >= sizeof(s_un.sun_path)) { - /* We have a non-NULL unixpath, need to validate it */ - if (strlen(unixpath) >= sizeof(s_un.sun_path)) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - _("UNIXPATH `%s' too long, maximum length is %llu\n"), - unixpath, - (unsigned long long)sizeof(s_un.sun_path)); - unixpath = GNUNET_NETWORK_shorten_unixpath(unixpath); - LOG(GNUNET_ERROR_TYPE_INFO, - _("Using `%s' instead\n"), - unixpath); - if (NULL == unixpath) - return NULL; - } - memset(&s_un, - 0, - sizeof(s_un)); - s_un.sun_family = AF_UNIX; - GNUNET_strlcpy(s_un.sun_path, - unixpath, - sizeof(s_un.sun_path)); + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ("UNIXPATH `%s' too long, maximum length is %llu\n"), + unixpath, + (unsigned long long) sizeof(s_un.sun_path)); + unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("Using `%s' instead\n"), + unixpath); + if (NULL == unixpath) + return NULL; + } + memset (&s_un, + 0, + sizeof(s_un)); + s_un.sun_family = AF_UNIX; + GNUNET_strlcpy (s_un.sun_path, + unixpath, + sizeof(s_un.sun_path)); #ifdef LINUX - { - int abstract; - - abstract = GNUNET_CONFIGURATION_get_value_yesno(cfg, - "TESTING", - "USE_ABSTRACT_SOCKETS"); - if (GNUNET_YES == abstract) - s_un.sun_path[0] = '\0'; - } + { + int abstract; + + abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, + "TESTING", + "USE_ABSTRACT_SOCKETS"); + if (GNUNET_YES == abstract) + s_un.sun_path[0] = '\0'; + } #endif #if HAVE_SOCKADDR_UN_SUN_LEN - s_un.sun_len = (u_char)sizeof(struct sockaddr_un); + s_un.sun_len = (u_char) sizeof(struct sockaddr_un); #endif - sock = GNUNET_NETWORK_socket_create(AF_UNIX, - SOCK_STREAM, - 0); - if ((NULL != sock) && - ((GNUNET_OK == - GNUNET_NETWORK_socket_connect(sock, - (struct sockaddr *)&s_un, - sizeof(s_un))) || - (EINPROGRESS == errno))) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Successfully connected to unixpath `%s'!\n", - unixpath); - GNUNET_free(unixpath); - return sock; - } - if (NULL != sock) - GNUNET_NETWORK_socket_close(sock); + sock = GNUNET_NETWORK_socket_create (AF_UNIX, + SOCK_STREAM, + 0); + if ((NULL != sock) && + ((GNUNET_OK == + GNUNET_NETWORK_socket_connect (sock, + (struct sockaddr *) &s_un, + sizeof(s_un))) || + (EINPROGRESS == errno))) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Successfully connected to unixpath `%s'!\n", + unixpath); + GNUNET_free (unixpath); + return sock; } - GNUNET_free_non_null(unixpath); + if (NULL != sock) + GNUNET_NETWORK_socket_close (sock); + } + GNUNET_free_non_null (unixpath); #endif return NULL; } @@ -577,7 +580,7 @@ try_unixpath(const char *service_name, * @param cls the `struct AddressProbe *` with the address that we are probing */ static void -connect_probe_continuation(void *cls) +connect_probe_continuation (void *cls) { struct AddressProbe *ap = cls; struct ClientState *cstate = ap->cstate; @@ -586,40 +589,40 @@ connect_probe_continuation(void *cls) socklen_t len; ap->task = NULL; - GNUNET_assert(NULL != ap->sock); - GNUNET_CONTAINER_DLL_remove(cstate->ap_head, - cstate->ap_tail, - ap); + GNUNET_assert (NULL != ap->sock); + GNUNET_CONTAINER_DLL_remove (cstate->ap_head, + cstate->ap_tail, + ap); len = sizeof(error); error = 0; - tc = GNUNET_SCHEDULER_get_task_context(); + tc = GNUNET_SCHEDULER_get_task_context (); if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || (GNUNET_OK != - GNUNET_NETWORK_socket_getsockopt(ap->sock, - SOL_SOCKET, - SO_ERROR, - &error, - &len)) || + GNUNET_NETWORK_socket_getsockopt (ap->sock, + SOL_SOCKET, + SO_ERROR, + &error, + &len)) || (0 != error)) - { - GNUNET_break(GNUNET_OK == - GNUNET_NETWORK_socket_close(ap->sock)); - GNUNET_free(ap); - if ((NULL == cstate->ap_head) && - // (NULL == cstate->proxy_handshake) && - (NULL == cstate->dns_active)) - connect_fail_continuation(cstate); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Connection to `%s' succeeded!\n", - cstate->service_name); + { + GNUNET_break (GNUNET_OK == + GNUNET_NETWORK_socket_close (ap->sock)); + GNUNET_free (ap); + if ((NULL == cstate->ap_head) && + // (NULL == cstate->proxy_handshake) && + (NULL == cstate->dns_active)) + connect_fail_continuation (cstate); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Connection to `%s' succeeded!\n", + cstate->service_name); /* trigger jobs that waited for the connection */ - GNUNET_assert(NULL == cstate->sock); + GNUNET_assert (NULL == cstate->sock); cstate->sock = ap->sock; - GNUNET_free(ap); - cancel_aps(cstate); - connect_success_continuation(cstate); + GNUNET_free (ap); + cancel_aps (cstate); + connect_success_continuation (cstate); } @@ -632,82 +635,82 @@ connect_probe_continuation(void *cls) * @param addrlen length of @a addr */ static void -try_connect_using_address(void *cls, - const struct sockaddr *addr, - socklen_t addrlen) +try_connect_using_address (void *cls, + const struct sockaddr *addr, + socklen_t addrlen) { struct ClientState *cstate = cls; struct AddressProbe *ap; if (NULL == addr) - { - cstate->dns_active = NULL; - if ((NULL == cstate->ap_head) && - // (NULL == cstate->proxy_handshake) && - (NULL == cstate->sock)) - connect_fail_continuation(cstate); - return; - } + { + cstate->dns_active = NULL; + if ((NULL == cstate->ap_head) && + // (NULL == cstate->proxy_handshake) && + (NULL == cstate->sock)) + connect_fail_continuation (cstate); + return; + } if (NULL != cstate->sock) return; /* already connected */ /* try to connect */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Trying to connect using address `%s:%u'\n", - GNUNET_a2s(addr, - addrlen), - cstate->port); - ap = GNUNET_malloc(sizeof(struct AddressProbe) + addrlen); - ap->addr = (const struct sockaddr *)&ap[1]; - GNUNET_memcpy(&ap[1], - addr, - addrlen); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Trying to connect using address `%s:%u'\n", + GNUNET_a2s (addr, + addrlen), + cstate->port); + ap = GNUNET_malloc (sizeof(struct AddressProbe) + addrlen); + ap->addr = (const struct sockaddr *) &ap[1]; + GNUNET_memcpy (&ap[1], + addr, + addrlen); ap->addrlen = addrlen; ap->cstate = cstate; switch (ap->addr->sa_family) - { - case AF_INET: - ((struct sockaddr_in *)ap->addr)->sin_port = htons(cstate->port); - break; - - case AF_INET6: - ((struct sockaddr_in6 *)ap->addr)->sin6_port = htons(cstate->port); - break; - - default: - GNUNET_break(0); - GNUNET_free(ap); - return; /* not supported by us */ - } - ap->sock = GNUNET_NETWORK_socket_create(ap->addr->sa_family, - SOCK_STREAM, - 0); + { + case AF_INET: + ((struct sockaddr_in *) ap->addr)->sin_port = htons (cstate->port); + break; + + case AF_INET6: + ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (cstate->port); + break; + + default: + GNUNET_break (0); + GNUNET_free (ap); + return; /* not supported by us */ + } + ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, + SOCK_STREAM, + 0); if (NULL == ap->sock) - { - GNUNET_free(ap); - return; /* not supported by OS */ - } + { + GNUNET_free (ap); + return; /* not supported by OS */ + } if ((GNUNET_OK != - GNUNET_NETWORK_socket_connect(ap->sock, - ap->addr, - ap->addrlen)) && + GNUNET_NETWORK_socket_connect (ap->sock, + ap->addr, + ap->addrlen)) && (EINPROGRESS != errno)) - { - /* maybe refused / unsupported address, try next */ - GNUNET_log_strerror(GNUNET_ERROR_TYPE_INFO, - "connect"); - GNUNET_break(GNUNET_OK == - GNUNET_NETWORK_socket_close(ap->sock)); - GNUNET_free(ap); - return; - } - GNUNET_CONTAINER_DLL_insert(cstate->ap_head, - cstate->ap_tail, - ap); - ap->task = GNUNET_SCHEDULER_add_write_net(CONNECT_RETRY_TIMEOUT, - ap->sock, - &connect_probe_continuation, - ap); + { + /* maybe refused / unsupported address, try next */ + GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, + "connect"); + GNUNET_break (GNUNET_OK == + GNUNET_NETWORK_socket_close (ap->sock)); + GNUNET_free (ap); + return; + } + GNUNET_CONTAINER_DLL_insert (cstate->ap_head, + cstate->ap_tail, + ap); + ap->task = GNUNET_SCHEDULER_add_write_net (CONNECT_RETRY_TIMEOUT, + ap->sock, + &connect_probe_continuation, + ap); } @@ -720,8 +723,8 @@ try_connect_using_address(void *cls, * @return #GNUNET_OK if the configuration is valid, #GNUNET_SYSERR if not */ static int -test_service_configuration(const char *service_name, - const struct GNUNET_CONFIGURATION_Handle *cfg) +test_service_configuration (const char *service_name, + const struct GNUNET_CONFIGURATION_Handle *cfg) { int ret = GNUNET_SYSERR; char *hostname = NULL; @@ -731,45 +734,45 @@ test_service_configuration(const char *service_name, char *unixpath = NULL; if ((GNUNET_OK == - GNUNET_CONFIGURATION_get_value_filename(cfg, - service_name, - "UNIXPATH", - &unixpath)) && - (0 < strlen(unixpath))) + GNUNET_CONFIGURATION_get_value_filename (cfg, + service_name, + "UNIXPATH", + &unixpath)) && + (0 < strlen (unixpath))) ret = GNUNET_OK; else if ((GNUNET_OK == - GNUNET_CONFIGURATION_have_value(cfg, - service_name, - "UNIXPATH"))) - { - GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, - service_name, - "UNIXPATH", - _("not a valid filename")); - return GNUNET_SYSERR; /* UNIXPATH specified but invalid! */ - } - GNUNET_free_non_null(unixpath); + GNUNET_CONFIGURATION_have_value (cfg, + service_name, + "UNIXPATH"))) + { + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, + service_name, + "UNIXPATH", + _ ("not a valid filename")); + return GNUNET_SYSERR; /* UNIXPATH specified but invalid! */ + } + GNUNET_free_non_null (unixpath); #endif if ((GNUNET_YES == - GNUNET_CONFIGURATION_have_value(cfg, - service_name, - "PORT")) && + GNUNET_CONFIGURATION_have_value (cfg, + service_name, + "PORT")) && (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_number(cfg, - service_name, - "PORT", - &port)) && + GNUNET_CONFIGURATION_get_value_number (cfg, + service_name, + "PORT", + &port)) && (port <= 65535) && (0 != port) && (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string(cfg, - service_name, - "HOSTNAME", - &hostname)) && - (0 != strlen(hostname))) + GNUNET_CONFIGURATION_get_value_string (cfg, + service_name, + "HOSTNAME", + &hostname)) && + (0 != strlen (hostname))) ret = GNUNET_OK; - GNUNET_free_non_null(hostname); + GNUNET_free_non_null (hostname); return ret; } @@ -780,7 +783,7 @@ test_service_configuration(const char *service_name, * @param cls the `struct ClientState` to try to connect to the service */ static void -start_connect(void *cls) +start_connect (void *cls) { struct ClientState *cstate = cls; @@ -788,41 +791,41 @@ start_connect(void *cls) #if 0 /* Never use a local source if a proxy is configured */ if (GNUNET_YES == - GNUNET_SOCKS_check_service(cstate->service_name, - cstate->cfg)) - { - socks_connect(cstate); - return; - } + GNUNET_SOCKS_check_service (cstate->service_name, + cstate->cfg)) + { + socks_connect (cstate); + return; + } #endif if ((0 == (cstate->attempts++ % 2)) || (0 == cstate->port) || (NULL == cstate->hostname)) + { + /* on even rounds, try UNIX first, or always + if we do not have a DNS name and TCP port. */ + cstate->sock = try_unixpath (cstate->service_name, + cstate->cfg); + if (NULL != cstate->sock) { - /* on even rounds, try UNIX first, or always - if we do not have a DNS name and TCP port. */ - cstate->sock = try_unixpath(cstate->service_name, - cstate->cfg); - if (NULL != cstate->sock) - { - connect_success_continuation(cstate); - return; - } + connect_success_continuation (cstate); + return; } + } if ((NULL == cstate->hostname) || (0 == cstate->port)) - { - /* All options failed. Boo! */ - connect_fail_continuation(cstate); - return; - } + { + /* All options failed. Boo! */ + connect_fail_continuation (cstate); + return; + } cstate->dns_active - = GNUNET_RESOLVER_ip_get(cstate->hostname, - AF_UNSPEC, - CONNECT_RETRY_TIMEOUT, - &try_connect_using_address, - cstate); + = GNUNET_RESOLVER_ip_get (cstate->hostname, + AF_UNSPEC, + CONNECT_RETRY_TIMEOUT, + &try_connect_using_address, + cstate); } @@ -834,30 +837,30 @@ start_connect(void *cls) * @param impl_state our `struct ClientState` */ static void -connection_client_send_impl(struct GNUNET_MQ_Handle *mq, - const struct GNUNET_MessageHeader *msg, - void *impl_state) +connection_client_send_impl (struct GNUNET_MQ_Handle *mq, + const struct GNUNET_MessageHeader *msg, + void *impl_state) { struct ClientState *cstate = impl_state; - (void)mq; + (void) mq; /* only one message at a time allowed */ - GNUNET_assert(NULL == cstate->msg); - GNUNET_assert(NULL == cstate->send_task); + GNUNET_assert (NULL == cstate->msg); + GNUNET_assert (NULL == cstate->send_task); cstate->msg = msg; cstate->msg_off = 0; if (NULL == cstate->sock) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "message of type %u waiting for socket\n", - ntohs(msg->type)); - return; /* still waiting for connection */ - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "message of type %u waiting for socket\n", + ntohs (msg->type)); + return; /* still waiting for connection */ + } cstate->send_task - = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, - cstate->sock, - &transmit_ready, - cstate); + = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, + cstate->sock, + &transmit_ready, + cstate); } @@ -868,20 +871,20 @@ connection_client_send_impl(struct GNUNET_MQ_Handle *mq, * @param impl_state our `struct ClientState` */ static void -connection_client_cancel_impl(struct GNUNET_MQ_Handle *mq, - void *impl_state) +connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq, + void *impl_state) { struct ClientState *cstate = impl_state; - (void)mq; - GNUNET_assert(NULL != cstate->msg); - GNUNET_assert(0 == cstate->msg_off); + (void) mq; + GNUNET_assert (NULL != cstate->msg); + GNUNET_assert (0 == cstate->msg_off); cstate->msg = NULL; if (NULL != cstate->send_task) - { - GNUNET_SCHEDULER_cancel(cstate->send_task); - cstate->send_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (cstate->send_task); + cstate->send_task = NULL; + } } @@ -897,57 +900,57 @@ connection_client_cancel_impl(struct GNUNET_MQ_Handle *mq, * @return the message queue, NULL on error */ struct GNUNET_MQ_Handle * -GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *service_name, - const struct GNUNET_MQ_MessageHandler *handlers, - GNUNET_MQ_ErrorHandler error_handler, - void *error_handler_cls) +GNUNET_CLIENT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *service_name, + const struct GNUNET_MQ_MessageHandler *handlers, + GNUNET_MQ_ErrorHandler error_handler, + void *error_handler_cls) { struct ClientState *cstate; if (GNUNET_OK != - test_service_configuration(service_name, - cfg)) + test_service_configuration (service_name, + cfg)) return NULL; - cstate = GNUNET_new(struct ClientState); - cstate->service_name = GNUNET_strdup(service_name); + cstate = GNUNET_new (struct ClientState); + cstate->service_name = GNUNET_strdup (service_name); cstate->cfg = cfg; - cstate->retry_task = GNUNET_SCHEDULER_add_now(&start_connect, - cstate); - cstate->mst = GNUNET_MST_create(&recv_message, - cstate); + cstate->retry_task = GNUNET_SCHEDULER_add_now (&start_connect, + cstate); + cstate->mst = GNUNET_MST_create (&recv_message, + cstate); if (GNUNET_YES == - GNUNET_CONFIGURATION_have_value(cfg, - service_name, - "PORT")) - { - if (!((GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number(cfg, + GNUNET_CONFIGURATION_have_value (cfg, + service_name, + "PORT")) + { + if (! ((GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", &cstate->port)) || - (cstate->port > 65535) || - (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string(cfg, + (cstate->port > 65535) || + (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "HOSTNAME", &cstate->hostname))) && - (0 == strlen(cstate->hostname))) - { - GNUNET_free(cstate->hostname); - cstate->hostname = NULL; - LOG(GNUNET_ERROR_TYPE_WARNING, - _("Need a non-empty hostname for service `%s'.\n"), - service_name); - } + (0 == strlen (cstate->hostname))) + { + GNUNET_free (cstate->hostname); + cstate->hostname = NULL; + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ("Need a non-empty hostname for service `%s'.\n"), + service_name); } - cstate->mq = GNUNET_MQ_queue_for_callbacks(&connection_client_send_impl, - &connection_client_destroy_impl, - &connection_client_cancel_impl, - cstate, - handlers, - error_handler, - error_handler_cls); + } + cstate->mq = GNUNET_MQ_queue_for_callbacks (&connection_client_send_impl, + &connection_client_destroy_impl, + &connection_client_cancel_impl, + cstate, + handlers, + error_handler, + error_handler_cls); return cstate->mq; } -- cgit v1.2.3