From 2a7c0cbbc0e81baef36446683c7e220eca1760c6 Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Fri, 14 Jun 2019 14:16:47 +0200 Subject: fix intendation --- src/reclaim/reclaim_api.c | 1009 ++++++++++++++++++++++++--------------------- 1 file changed, 530 insertions(+), 479 deletions(-) (limited to 'src/reclaim/reclaim_api.c') diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c index 21c870a37..725b2b876 100644 --- a/src/reclaim/reclaim_api.c +++ b/src/reclaim/reclaim_api.c @@ -292,514 +292,549 @@ struct GNUNET_RECLAIM_Handle */ struct GNUNET_SCHEDULER_Task *reconnect_task; - /** - * Time for next connect retry. - */ - struct GNUNET_TIME_Relative reconnect_backoff; - - /** - * Connection to service (if available). - */ - struct GNUNET_MQ_Handle *mq; - - /** - * Request Id generator. Incremented by one for each request. - */ - uint32_t r_id_gen; - - /** - * Are we polling for incoming messages right now? - */ - int in_receive; - }; - + /** + * Time for next connect retry. + */ + struct GNUNET_TIME_Relative reconnect_backoff; /** - * Try again to connect to the service. - * - * @param h handle to the reclaim service. + * Connection to service (if available). */ - static void - reconnect (struct GNUNET_RECLAIM_Handle *h); + struct GNUNET_MQ_Handle *mq; + /** + * Request Id generator. Incremented by one for each request. + */ + uint32_t r_id_gen; /** - * Reconnect - * - * @param cls the handle + * Are we polling for incoming messages right now? */ - static void - reconnect_task (void *cls) - { - struct GNUNET_RECLAIM_Handle *handle = cls; + int in_receive; +}; - handle->reconnect_task = NULL; - reconnect (handle); - } +/** + * Try again to connect to the service. + * + * @param h handle to the reclaim service. + */ +static void +reconnect (struct GNUNET_RECLAIM_Handle *h); - /** - * Disconnect from service and then reconnect. - * - * @param handle our service - */ - static void - force_reconnect (struct GNUNET_RECLAIM_Handle *handle) - { - GNUNET_MQ_destroy (handle->mq); - handle->mq = NULL; - handle->reconnect_backoff = - GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); - handle->reconnect_task = GNUNET_SCHEDULER_add_delayed ( - handle->reconnect_backoff, &reconnect_task, handle); - } +/** + * Reconnect + * + * @param cls the handle + */ +static void +reconnect_task (void *cls) +{ + struct GNUNET_RECLAIM_Handle *handle = cls; - /** - * Free @a it. - * - * @param it entry to free - */ - static void - free_it (struct GNUNET_RECLAIM_AttributeIterator *it) - { - struct GNUNET_RECLAIM_Handle *h = it->h; + handle->reconnect_task = NULL; + reconnect (handle); +} - GNUNET_CONTAINER_DLL_remove (h->it_head, h->it_tail, it); - if (NULL != it->env) - GNUNET_MQ_discard (it->env); - GNUNET_free (it); - } - /** - * Free @a op - * - * @param op the operation to free - */ - static void - free_op (struct GNUNET_RECLAIM_Operation *op) - { - if (NULL == op) - return; - if (NULL != op->env) - GNUNET_MQ_discard (op->env); - GNUNET_free (op); - } +/** + * Disconnect from service and then reconnect. + * + * @param handle our service + */ +static void +force_reconnect (struct GNUNET_RECLAIM_Handle *handle) +{ + GNUNET_MQ_destroy (handle->mq); + handle->mq = NULL; + handle->reconnect_backoff = + GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); + handle->reconnect_task = + GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff, + &reconnect_task, + handle); +} - /** - * Generic error handler, called with the appropriate error code and - * the same closure specified at the creation of the message queue. - * Not every message queue implementation supports an error handler. - * - * @param cls closure with the `struct GNUNET_GNS_Handle *` - * @param error error code - */ - static void - mq_error_handler (void *cls, enum GNUNET_MQ_Error error) +/** + * Free @a it. + * + * @param it entry to free + */ +static void +free_it (struct GNUNET_RECLAIM_AttributeIterator *it) +{ + struct GNUNET_RECLAIM_Handle *h = it->h; + + GNUNET_CONTAINER_DLL_remove (h->it_head, h->it_tail, it); + if (NULL != it->env) + GNUNET_MQ_discard (it->env); + GNUNET_free (it); +} + +/** + * Free @a op + * + * @param op the operation to free + */ +static void +free_op (struct GNUNET_RECLAIM_Operation *op) +{ + if (NULL == op) + return; + if (NULL != op->env) + GNUNET_MQ_discard (op->env); + GNUNET_free (op); +} + + +/** + * Generic error handler, called with the appropriate error code and + * the same closure specified at the creation of the message queue. + * Not every message queue implementation supports an error handler. + * + * @param cls closure with the `struct GNUNET_GNS_Handle *` + * @param error error code + */ +static void +mq_error_handler (void *cls, enum GNUNET_MQ_Error error) +{ + struct GNUNET_RECLAIM_Handle *handle = cls; + force_reconnect (handle); +} + + +/** + * Handle an incoming message of type + * #GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE + * + * @param cls + * @param msg the message we received + */ +static void +handle_success_response (void *cls, const struct SuccessResultMessage *msg) +{ + struct GNUNET_RECLAIM_Handle *h = cls; + struct GNUNET_RECLAIM_Operation *op; + uint32_t r_id = ntohl (msg->id); + int res; + const char *emsg; + + for (op = h->op_head; NULL != op; op = op->next) + if (op->r_id == r_id) + break; + if (NULL == op) + return; + + res = ntohl (msg->op_result); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received SUCCESS_RESPONSE with result %d\n", + res); + + /* TODO: add actual error message to response... */ + if (GNUNET_SYSERR == res) + emsg = _ ("failed to store record\n"); + else + emsg = NULL; + if (NULL != op->as_cb) + op->as_cb (op->cls, res, emsg); + GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); + free_op (op); +} + + +/** + * Handle an incoming message of type + * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT + * + * @param cls + * @param msg the message we received + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error + */ +static int +check_consume_ticket_result (void *cls, + const struct ConsumeTicketResultMessage *msg) +{ + size_t msg_len; + size_t attrs_len; + + msg_len = ntohs (msg->header.size); + attrs_len = ntohs (msg->attrs_len); + if (msg_len != sizeof (struct ConsumeTicketResultMessage) + attrs_len) { - struct GNUNET_RECLAIM_Handle *handle = cls; - force_reconnect (handle); + GNUNET_break (0); + return GNUNET_SYSERR; } + return GNUNET_OK; +} - /** - * Handle an incoming message of type - * #GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE - * - * @param cls - * @param msg the message we received - */ - static void - handle_success_response (void *cls, const struct SuccessResultMessage *msg) - { - struct GNUNET_RECLAIM_Handle *h = cls; - struct GNUNET_RECLAIM_Operation *op; - uint32_t r_id = ntohl (msg->id); - int res; - const char *emsg; - - for (op = h->op_head; NULL != op; op = op->next) - if (op->r_id == r_id) - break; - if (NULL == op) - return; +/** + * Handle an incoming message of type + * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT + * + * @param cls + * @param msg the message we received + */ +static void +handle_consume_ticket_result (void *cls, + const struct ConsumeTicketResultMessage *msg) +{ + struct GNUNET_RECLAIM_Handle *h = cls; + struct GNUNET_RECLAIM_Operation *op; + size_t attrs_len; + uint32_t r_id = ntohl (msg->id); - res = ntohl (msg->op_result); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Received SUCCESS_RESPONSE with result %d\n", - res); + attrs_len = ntohs (msg->attrs_len); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); - /* TODO: add actual error message to response... */ - if (GNUNET_SYSERR == res) - emsg = _ ("failed to store record\n"); - else - emsg = NULL; - if (NULL != op->as_cb) - op->as_cb (op->cls, res, emsg); + + for (op = h->op_head; NULL != op; op = op->next) + if (op->r_id == r_id) + break; + if (NULL == op) + return; + + { + struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; + struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; + attrs = + GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *) &msg[1], attrs_len); + if (NULL != op->ar_cb) + { + if (NULL == attrs) + { + op->ar_cb (op->cls, &msg->identity, NULL); + } + else + { + for (le = attrs->list_head; NULL != le; le = le->next) + op->ar_cb (op->cls, &msg->identity, le->claim); + GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); + attrs = NULL; + } + op->ar_cb (op->cls, NULL, NULL); + } GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); free_op (op); + GNUNET_free_non_null (attrs); + return; } + GNUNET_assert (0); +} - /** - * Handle an incoming message of type - * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT - * - * @param cls - * @param msg the message we received - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ - static int - check_consume_ticket_result (void *cls, - const struct ConsumeTicketResultMessage *msg) - { - size_t msg_len; - size_t attrs_len; +/** + * Handle an incoming message of type + * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT + * + * @param cls + * @param msg the message we received + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error + */ +static int +check_attribute_result (void *cls, const struct AttributeResultMessage *msg) +{ + size_t msg_len; + size_t attr_len; - msg_len = ntohs (msg->header.size); - attrs_len = ntohs (msg->attrs_len); - if (msg_len != sizeof (struct ConsumeTicketResultMessage) + attrs_len) { - GNUNET_break (0); - return GNUNET_SYSERR; - } - return GNUNET_OK; + msg_len = ntohs (msg->header.size); + attr_len = ntohs (msg->attr_len); + if (msg_len != sizeof (struct AttributeResultMessage) + attr_len) + { + GNUNET_break (0); + return GNUNET_SYSERR; } + return GNUNET_OK; +} - /** - * Handle an incoming message of type - * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT - * - * @param cls - * @param msg the message we received - */ - static void - handle_consume_ticket_result (void *cls, - const struct ConsumeTicketResultMessage *msg) - { - struct GNUNET_RECLAIM_Handle *h = cls; - struct GNUNET_RECLAIM_Operation *op; - size_t attrs_len; - uint32_t r_id = ntohl (msg->id); +/** + * Handle an incoming message of type + * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT + * + * @param cls + * @param msg the message we received + */ +static void +handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) +{ + static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; + struct GNUNET_RECLAIM_Handle *h = cls; + struct GNUNET_RECLAIM_AttributeIterator *it; + struct GNUNET_RECLAIM_Operation *op; + size_t attr_len; + uint32_t r_id = ntohl (msg->id); - attrs_len = ntohs (msg->attrs_len); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); + attr_len = ntohs (msg->attr_len); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); - for (op = h->op_head; NULL != op; op = op->next) - if (op->r_id == r_id) - break; - if (NULL == op) - return; + for (it = h->it_head; NULL != it; it = it->next) + if (it->r_id == r_id) + break; + for (op = h->op_head; NULL != op; op = op->next) + if (op->r_id == r_id) + break; + if ((NULL == it) && (NULL == op)) + return; + if ((0 == + (memcmp (&msg->identity, &identity_dummy, sizeof (identity_dummy))))) + { + if ((NULL == it) && (NULL == op)) + { + GNUNET_break (0); + force_reconnect (h); + return; + } + if (NULL != it) + { + if (NULL != it->finish_cb) + it->finish_cb (it->finish_cb_cls); + free_it (it); + } + if (NULL != op) { - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; - struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; - attrs = - GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *)&msg[1], attrs_len); - if (NULL != op->ar_cb) { - if (NULL == attrs) { - op->ar_cb (op->cls, &msg->identity, NULL); - } else { - for (le = attrs->list_head; NULL != le; le = le->next) - op->ar_cb (op->cls, &msg->identity, le->claim); - GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); - attrs = NULL; - } + if (NULL != op->ar_cb) op->ar_cb (op->cls, NULL, NULL); - } GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); free_op (op); - GNUNET_free_non_null (attrs); - return; } - GNUNET_assert (0); + return; } - - /** - * Handle an incoming message of type - * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT - * - * @param cls - * @param msg the message we received - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ - static int - check_attribute_result (void *cls, const struct AttributeResultMessage *msg) { - size_t msg_len; - size_t attr_len; - - msg_len = ntohs (msg->header.size); - attr_len = ntohs (msg->attr_len); - if (msg_len != sizeof (struct AttributeResultMessage) + attr_len) { - GNUNET_break (0); - return GNUNET_SYSERR; + struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; + attr = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *) &msg[1], attr_len); + if (NULL != it) + { + if (NULL != it->proc) + it->proc (it->proc_cls, &msg->identity, attr); } - return GNUNET_OK; + else if (NULL != op) + { + if (NULL != op->ar_cb) + op->ar_cb (op->cls, &msg->identity, attr); + } + GNUNET_free (attr); + return; } + GNUNET_assert (0); +} - /** - * Handle an incoming message of type - * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT - * - * @param cls - * @param msg the message we received - */ - static void - handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) +/** + * Handle an incoming message of type + * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT + * + * @param cls + * @param msg the message we received + */ +static void +handle_ticket_result (void *cls, const struct TicketResultMessage *msg) +{ + struct GNUNET_RECLAIM_Handle *handle = cls; + struct GNUNET_RECLAIM_Operation *op; + struct GNUNET_RECLAIM_TicketIterator *it; + uint32_t r_id = ntohl (msg->id); + static const struct GNUNET_RECLAIM_Ticket ticket; + for (op = handle->op_head; NULL != op; op = op->next) + if (op->r_id == r_id) + break; + for (it = handle->ticket_it_head; NULL != it; it = it->next) + if (it->r_id == r_id) + break; + if ((NULL == op) && (NULL == it)) + return; + if (NULL != op) { - static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; - struct GNUNET_RECLAIM_Handle *h = cls; - struct GNUNET_RECLAIM_AttributeIterator *it; - struct GNUNET_RECLAIM_Operation *op; - size_t attr_len; - uint32_t r_id = ntohl (msg->id); - - attr_len = ntohs (msg->attr_len); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); - - - for (it = h->it_head; NULL != it; it = it->next) - if (it->r_id == r_id) - break; - for (op = h->op_head; NULL != op; op = op->next) - if (op->r_id == r_id) - break; - if ((NULL == it) && (NULL == op)) - return; - - if ((0 == - (memcmp (&msg->identity, &identity_dummy, sizeof (identity_dummy))))) { - if ((NULL == it) && (NULL == op)) { - GNUNET_break (0); - force_reconnect (h); - return; - } - if (NULL != it) { - if (NULL != it->finish_cb) - it->finish_cb (it->finish_cb_cls); - free_it (it); - } - if (NULL != op) { - if (NULL != op->ar_cb) - op->ar_cb (op->cls, NULL, NULL); - GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); - free_op (op); - } - return; + GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op); + if (0 == + memcmp (&msg->ticket, &ticket, sizeof (struct GNUNET_RECLAIM_Ticket))) + { + if (NULL != op->tr_cb) + op->tr_cb (op->cls, NULL); } - + else { - struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; - attr = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *)&msg[1], attr_len); - if (NULL != it) { - if (NULL != it->proc) - it->proc (it->proc_cls, &msg->identity, attr); - } else if (NULL != op) { - if (NULL != op->ar_cb) - op->ar_cb (op->cls, &msg->identity, attr); - } - GNUNET_free (attr); - return; + if (NULL != op->tr_cb) + op->tr_cb (op->cls, &msg->ticket); } - GNUNET_assert (0); + free_op (op); + return; } - - - /** - * Handle an incoming message of type - * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT - * - * @param cls - * @param msg the message we received - */ - static void - handle_ticket_result (void *cls, const struct TicketResultMessage *msg) + else if (NULL != it) { - struct GNUNET_RECLAIM_Handle *handle = cls; - struct GNUNET_RECLAIM_Operation *op; - struct GNUNET_RECLAIM_TicketIterator *it; - uint32_t r_id = ntohl (msg->id); - static const struct GNUNET_RECLAIM_Ticket ticket; - for (op = handle->op_head; NULL != op; op = op->next) - if (op->r_id == r_id) - break; - for (it = handle->ticket_it_head; NULL != it; it = it->next) - if (it->r_id == r_id) - break; - if ((NULL == op) && (NULL == it)) - return; - if (NULL != op) { - GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op); - if (0 == memcmp (&msg->ticket, &ticket, sizeof (struct GNUNET_RECLAIM_Ticket))) - { - if (NULL != op->tr_cb) - op->tr_cb (op->cls, NULL); - } else { - if (NULL != op->tr_cb) - op->tr_cb (op->cls, &msg->ticket); - } - free_op (op); - return; - } else if (NULL != it) { - if (0 == memcmp (&msg->ticket, &ticket, sizeof (struct GNUNET_RECLAIM_Ticket))) - { - GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head, - handle->ticket_it_tail, it); - it->finish_cb (it->finish_cb_cls); - GNUNET_free (it); - } else { - if (NULL != it->tr_cb) - it->tr_cb (it->cls, &msg->ticket); - } - return; + if (0 == + memcmp (&msg->ticket, &ticket, sizeof (struct GNUNET_RECLAIM_Ticket))) + { + GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head, + handle->ticket_it_tail, + it); + it->finish_cb (it->finish_cb_cls); + GNUNET_free (it); } - GNUNET_break (0); + else + { + if (NULL != it->tr_cb) + it->tr_cb (it->cls, &msg->ticket); + } + return; } + GNUNET_break (0); +} - /** - * Handle an incoming message of type - * #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT - * - * @param cls - * @param msg the message we received - */ - static void - handle_revoke_ticket_result (void *cls, - const struct RevokeTicketResultMessage *msg) - { - struct GNUNET_RECLAIM_Handle *h = cls; - struct GNUNET_RECLAIM_Operation *op; - uint32_t r_id = ntohl (msg->id); - int32_t success; +/** + * Handle an incoming message of type + * #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT + * + * @param cls + * @param msg the message we received + */ +static void +handle_revoke_ticket_result (void *cls, + const struct RevokeTicketResultMessage *msg) +{ + struct GNUNET_RECLAIM_Handle *h = cls; + struct GNUNET_RECLAIM_Operation *op; + uint32_t r_id = ntohl (msg->id); + int32_t success; - LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing revocation result.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing revocation result.\n"); - for (op = h->op_head; NULL != op; op = op->next) - if (op->r_id == r_id) - break; - if (NULL == op) - return; - success = ntohl (msg->success); + for (op = h->op_head; NULL != op; op = op->next) + if (op->r_id == r_id) + break; + if (NULL == op) + return; + success = ntohl (msg->success); + { + if (NULL != op->rvk_cb) { - if (NULL != op->rvk_cb) { - op->rvk_cb (op->cls, success, NULL); - } - GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); - free_op (op); - return; + op->rvk_cb (op->cls, success, NULL); } - GNUNET_assert (0); + GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); + free_op (op); + return; } + GNUNET_assert (0); +} - /** - * Try again to connect to the service. - * - * @param h handle to the reclaim service. - */ - static void - reconnect (struct GNUNET_RECLAIM_Handle *h) - { - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size (success_response, - GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE, - struct SuccessResultMessage, h), - GNUNET_MQ_hd_var_size (attribute_result, - GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT, - struct AttributeResultMessage, h), - GNUNET_MQ_hd_fixed_size (ticket_result, - GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT, - struct TicketResultMessage, h), - GNUNET_MQ_hd_var_size (consume_ticket_result, - GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT, - struct ConsumeTicketResultMessage, h), - GNUNET_MQ_hd_fixed_size (revoke_ticket_result, - GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT, - struct RevokeTicketResultMessage, h), - GNUNET_MQ_handler_end ()}; - struct GNUNET_RECLAIM_Operation *op; - - GNUNET_assert (NULL == h->mq); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to reclaim service.\n"); - - h->mq = - GNUNET_CLIENT_connect (h->cfg, "reclaim", handlers, &mq_error_handler, h); - if (NULL == h->mq) - return; - for (op = h->op_head; NULL != op; op = op->next) - GNUNET_MQ_send_copy (h->mq, op->env); - } +/** + * Try again to connect to the service. + * + * @param h handle to the reclaim service. + */ +static void +reconnect (struct GNUNET_RECLAIM_Handle *h) +{ + struct GNUNET_MQ_MessageHandler handlers[] = + {GNUNET_MQ_hd_fixed_size (success_response, + GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE, + struct SuccessResultMessage, + h), + GNUNET_MQ_hd_var_size (attribute_result, + GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT, + struct AttributeResultMessage, + h), + GNUNET_MQ_hd_fixed_size (ticket_result, + GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT, + struct TicketResultMessage, + h), + GNUNET_MQ_hd_var_size (consume_ticket_result, + GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT, + struct ConsumeTicketResultMessage, + h), + GNUNET_MQ_hd_fixed_size (revoke_ticket_result, + GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT, + struct RevokeTicketResultMessage, + h), + GNUNET_MQ_handler_end ()}; + struct GNUNET_RECLAIM_Operation *op; + GNUNET_assert (NULL == h->mq); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to reclaim service.\n"); - /** - * Connect to the reclaim service. - * - * @param cfg the configuration to use - * @return handle to use - */ - struct GNUNET_RECLAIM_Handle * - GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) + h->mq = + GNUNET_CLIENT_connect (h->cfg, "reclaim", handlers, &mq_error_handler, h); + if (NULL == h->mq) + return; + for (op = h->op_head; NULL != op; op = op->next) + GNUNET_MQ_send_copy (h->mq, op->env); +} + + +/** + * Connect to the reclaim service. + * + * @param cfg the configuration to use + * @return handle to use + */ +struct GNUNET_RECLAIM_Handle * +GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + struct GNUNET_RECLAIM_Handle *h; + + h = GNUNET_new (struct GNUNET_RECLAIM_Handle); + h->cfg = cfg; + reconnect (h); + if (NULL == h->mq) { - struct GNUNET_RECLAIM_Handle *h; - - h = GNUNET_new (struct GNUNET_RECLAIM_Handle); - h->cfg = cfg; - reconnect (h); - if (NULL == h->mq) { - GNUNET_free (h); - return NULL; - } - return h; + GNUNET_free (h); + return NULL; } + return h; +} - /** - * Cancel an operation. Note that the operation MAY still - * be executed; this merely cancels the continuation; if the request - * was already transmitted, the service may still choose to complete - * the operation. - * - * @param op operation to cancel - */ - void - GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op) - { - struct GNUNET_RECLAIM_Handle *h = op->h; +/** + * Cancel an operation. Note that the operation MAY still + * be executed; this merely cancels the continuation; if the request + * was already transmitted, the service may still choose to complete + * the operation. + * + * @param op operation to cancel + */ +void +GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op) +{ + struct GNUNET_RECLAIM_Handle *h = op->h; - GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); - free_op (op); - } + GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); + free_op (op); +} - /** - * Disconnect from service - * - * @param h handle to destroy - */ - void - GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h) +/** + * Disconnect from service + * + * @param h handle to destroy + */ +void +GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h) +{ + GNUNET_assert (NULL != h); + if (NULL != h->mq) { - GNUNET_assert (NULL != h); - if (NULL != h->mq) { - GNUNET_MQ_destroy (h->mq); - h->mq = NULL; - } - if (NULL != h->reconnect_task) { - GNUNET_SCHEDULER_cancel (h->reconnect_task); - h->reconnect_task = NULL; - } - GNUNET_assert (NULL == h->op_head); - GNUNET_free (h); + GNUNET_MQ_destroy (h->mq); + h->mq = NULL; + } + if (NULL != h->reconnect_task) + { + GNUNET_SCHEDULER_cancel (h->reconnect_task); + h->reconnect_task = NULL; } + GNUNET_assert (NULL == h->op_head); + GNUNET_free (h); +} - /** - * Store an attribute. If the attribute is already present, +/** + * Store an attribute. If the attribute is already present, * it is replaced with the new attribute. * * @param h handle to the re:claimID service @@ -812,11 +847,12 @@ struct GNUNET_RECLAIM_Handle */ struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_attribute_store ( - struct GNUNET_RECLAIM_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - const struct GNUNET_TIME_Relative *exp_interval, - GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls) + struct GNUNET_RECLAIM_Handle *h, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, + const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, + const struct GNUNET_TIME_Relative *exp_interval, + GNUNET_RECLAIM_ContinuationWithStatus cont, + void *cont_cls) { struct GNUNET_RECLAIM_Operation *op; struct AttributeStoreMessage *sam; @@ -829,13 +865,14 @@ GNUNET_RECLAIM_attribute_store ( op->r_id = h->r_id_gen++; GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr); - op->env = GNUNET_MQ_msg_extra (sam, attr_len, + op->env = GNUNET_MQ_msg_extra (sam, + attr_len, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE); sam->identity = *pkey; sam->id = htonl (op->r_id); sam->exp = GNUNET_htonll (exp_interval->rel_value_us); - GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *)&sam[1]); + GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *) &sam[1]); sam->attr_len = htons (attr_len); if (NULL != h->mq) @@ -857,10 +894,11 @@ GNUNET_RECLAIM_attribute_store ( */ struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_attribute_delete ( - struct GNUNET_RECLAIM_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, - const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, - GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls) + struct GNUNET_RECLAIM_Handle *h, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, + const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, + GNUNET_RECLAIM_ContinuationWithStatus cont, + void *cont_cls) { struct GNUNET_RECLAIM_Operation *op; struct AttributeDeleteMessage *dam; @@ -873,11 +911,12 @@ GNUNET_RECLAIM_attribute_delete ( op->r_id = h->r_id_gen++; GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr); - op->env = GNUNET_MQ_msg_extra (dam, attr_len, + op->env = GNUNET_MQ_msg_extra (dam, + attr_len, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE); dam->identity = *pkey; dam->id = htonl (op->r_id); - GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *)&dam[1]); + GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *) &dam[1]); dam->attr_len = htons (attr_len); if (NULL != h->mq) @@ -912,11 +951,14 @@ GNUNET_RECLAIM_attribute_delete ( */ struct GNUNET_RECLAIM_AttributeIterator * GNUNET_RECLAIM_get_attributes_start ( - struct GNUNET_RECLAIM_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, - GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, - GNUNET_RECLAIM_AttributeResult proc, void *proc_cls, - GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls) + struct GNUNET_RECLAIM_Handle *h, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, + GNUNET_SCHEDULER_TaskCallback error_cb, + void *error_cb_cls, + GNUNET_RECLAIM_AttributeResult proc, + void *proc_cls, + GNUNET_SCHEDULER_TaskCallback finish_cb, + void *finish_cb_cls) { struct GNUNET_RECLAIM_AttributeIterator *it; struct GNUNET_MQ_Envelope *env; @@ -935,8 +977,8 @@ GNUNET_RECLAIM_get_attributes_start ( it->r_id = rid; it->identity = *identity; GNUNET_CONTAINER_DLL_insert_tail (h->it_head, h->it_tail, it); - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START); + env = + GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START); msg->id = htonl (rid); msg->identity = *identity; if (NULL == h->mq) @@ -981,9 +1023,10 @@ GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it) struct GNUNET_MQ_Envelope *env; struct AttributeIterationStopMessage *msg; - if (NULL != h->mq) { - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP); + if (NULL != h->mq) + { + env = + GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP); msg->id = htonl (it->r_id); GNUNET_MQ_send (h->mq, env); } @@ -1006,16 +1049,17 @@ GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it) */ struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_ticket_issue ( - struct GNUNET_RECLAIM_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, - const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, - const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, - GNUNET_RECLAIM_TicketCallback cb, void *cb_cls) + struct GNUNET_RECLAIM_Handle *h, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, + const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, + const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, + GNUNET_RECLAIM_TicketCallback cb, + void *cb_cls) { struct GNUNET_RECLAIM_Operation *op; struct IssueTicketMessage *tim; size_t attr_len; - fprintf(stderr, "Issuing ticket\n"); + fprintf (stderr, "Issuing ticket\n"); op = GNUNET_new (struct GNUNET_RECLAIM_Operation); op->h = h; op->tr_cb = cb; @@ -1023,13 +1067,14 @@ GNUNET_RECLAIM_ticket_issue ( op->r_id = h->r_id_gen++; GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); attr_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); - op->env = GNUNET_MQ_msg_extra (tim, attr_len, + op->env = GNUNET_MQ_msg_extra (tim, + attr_len, GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET); tim->identity = *iss; tim->rp = *rp; tim->id = htonl (op->r_id); - GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, (char *)&tim[1]); + GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, (char *) &tim[1]); tim->attr_len = htons (attr_len); if (NULL != h->mq) @@ -1052,10 +1097,11 @@ GNUNET_RECLAIM_ticket_issue ( */ struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_ticket_consume ( - struct GNUNET_RECLAIM_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, - const struct GNUNET_RECLAIM_Ticket *ticket, - GNUNET_RECLAIM_AttributeResult cb, void *cb_cls) + struct GNUNET_RECLAIM_Handle *h, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, + const struct GNUNET_RECLAIM_Ticket *ticket, + GNUNET_RECLAIM_AttributeResult cb, + void *cb_cls) { struct GNUNET_RECLAIM_Operation *op; struct ConsumeTicketMessage *ctm; @@ -1066,8 +1112,7 @@ GNUNET_RECLAIM_ticket_consume ( op->cls = cb_cls; op->r_id = h->r_id_gen++; GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); - op->env = - GNUNET_MQ_msg (ctm, GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET); + op->env = GNUNET_MQ_msg (ctm, GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET); ctm->identity = *identity; ctm->id = htonl (op->r_id); ctm->ticket = *ticket; @@ -1096,11 +1141,14 @@ GNUNET_RECLAIM_ticket_consume ( */ struct GNUNET_RECLAIM_TicketIterator * GNUNET_RECLAIM_ticket_iteration_start ( - struct GNUNET_RECLAIM_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, - GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, - GNUNET_RECLAIM_TicketCallback proc, void *proc_cls, - GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls) + struct GNUNET_RECLAIM_Handle *h, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, + GNUNET_SCHEDULER_TaskCallback error_cb, + void *error_cb_cls, + GNUNET_RECLAIM_TicketCallback proc, + void *proc_cls, + GNUNET_SCHEDULER_TaskCallback finish_cb, + void *finish_cb_cls) { struct GNUNET_RECLAIM_TicketIterator *it; struct GNUNET_MQ_Envelope *env; @@ -1162,7 +1210,8 @@ GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it) struct GNUNET_MQ_Envelope *env; struct TicketIterationStopMessage *msg; - if (NULL != h->mq) { + if (NULL != h->mq) + { env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP); msg->id = htonl (it->r_id); @@ -1187,10 +1236,11 @@ GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it) */ struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_ticket_revoke ( - struct GNUNET_RECLAIM_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, - const struct GNUNET_RECLAIM_Ticket *ticket, - GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls) + struct GNUNET_RECLAIM_Handle *h, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, + const struct GNUNET_RECLAIM_Ticket *ticket, + GNUNET_RECLAIM_ContinuationWithStatus cb, + void *cb_cls) { struct GNUNET_RECLAIM_Operation *op; struct RevokeTicketMessage *msg; @@ -1207,7 +1257,8 @@ GNUNET_RECLAIM_ticket_revoke ( msg->id = htonl (rid); msg->identity = *identity; msg->ticket = *ticket; - if (NULL != h->mq) { + if (NULL != h->mq) + { GNUNET_MQ_send (h->mq, op->env); op->env = NULL; } -- cgit v1.2.3