summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexia Pagkopoulou <a.pagkopoulou@tum.de>2019-06-14 11:09:34 +0200
committerAlexia Pagkopoulou <a.pagkopoulou@tum.de>2019-06-14 11:09:34 +0200
commit670f014bd8384cadad7963812f2934387572d2bd (patch)
treef1717dafc20cad1892959168fcd2ae1bcc39f317
parent5541e2e3f2b321164f3c33dfc551a8f237380393 (diff)
NULL pointer fix
-rw-r--r--src/reclaim/reclaim_api.c875
1 files changed, 438 insertions, 437 deletions
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c
index 8c97ba9a2..21c870a37 100644
--- a/src/reclaim/reclaim_api.c
+++ b/src/reclaim/reclaim_api.c
@@ -292,513 +292,514 @@ 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.
+ * Try again to connect to the service.
+ *
+ * @param h handle to the reclaim service.
*/
- struct GNUNET_TIME_Relative reconnect_backoff;
+ static void
+ reconnect (struct GNUNET_RECLAIM_Handle *h);
+
/**
- * Connection to service (if available).
+ * Reconnect
+ *
+ * @param cls the handle
*/
- struct GNUNET_MQ_Handle *mq;
+ static void
+ reconnect_task (void *cls)
+ {
+ struct GNUNET_RECLAIM_Handle *handle = cls;
+
+ handle->reconnect_task = NULL;
+ reconnect (handle);
+ }
+
/**
- * Request Id generator. Incremented by one for each request.
+ * Disconnect from service and then reconnect.
+ *
+ * @param handle our service
*/
- uint32_t r_id_gen;
+ 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);
+ }
+
/**
- * Are we polling for incoming messages right now?
+ * Free @a it.
+ *
+ * @param it entry to free
*/
- int in_receive;
-};
+ 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);
+ }
-/**
- * Try again to connect to the service.
- *
- * @param h handle to the reclaim service.
- */
-static void
-reconnect (struct GNUNET_RECLAIM_Handle *h);
+ /**
+ * 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);
+ }
-/**
- * Reconnect
- *
- * @param cls the handle
- */
-static void
-reconnect_task (void *cls)
-{
- struct GNUNET_RECLAIM_Handle *handle = cls;
+ /**
+ * 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->reconnect_task = NULL;
- 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;
-/**
- * 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);
-}
+ 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);
+ }
-/**
- * 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 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;
- GNUNET_CONTAINER_DLL_remove (h->it_head, h->it_tail, it);
- if (NULL != it->env)
- GNUNET_MQ_discard (it->env);
- GNUNET_free (it);
-}
+ 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;
+ }
-/**
- * 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);
-}
+ /**
+ * 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);
-/**
- * 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);
-}
+ attrs_len = ntohs (msg->attrs_len);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n");
-/**
- * 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);
-}
+ 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;
- 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;
+ /**
+ * 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;
+ }
+ return GNUNET_OK;
}
- 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);
+
+ 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;
- attrs_len = ntohs (msg->attrs_len);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n");
+ 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;
+ }
+ {
+ 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;
+ }
+ GNUNET_assert (0);
+ }
- 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_TICKET_RESULT
+ *
+ * @param cls
+ * @param msg the message we received
+ */
+ static void
+ handle_ticket_result (void *cls, const struct TicketResultMessage *msg)
{
- 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);
+ 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 {
- 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);
+ if (NULL != it->tr_cb)
+ it->tr_cb (it->cls, &msg->ticket);
}
- op->ar_cb (op->cls, NULL, NULL);
+ return;
}
- 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_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;
}
- return GNUNET_OK;
-}
-/**
- * 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);
-
- attr_len = ntohs (msg->attr_len);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n");
+ /**
+ * 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");
- 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);
+ for (op = h->op_head; NULL != op; op = op->next)
+ if (op->r_id == r_id)
+ break;
+ if (NULL == op)
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);
+ success = ntohl (msg->success);
+ {
+ 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;
}
- 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_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;
+ 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);
}
- GNUNET_assert (0);
-}
-/**
- * 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) {
- 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);
+ /**
+ * 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) {
+ GNUNET_free (h);
+ return NULL;
}
- return;
+ return h;
}
- 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;
- 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);
+ /**
+ * 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)
{
- if (NULL != op->rvk_cb) {
- op->rvk_cb (op->cls, success, NULL);
- }
+ struct GNUNET_RECLAIM_Handle *h = op->h;
+
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);
-}
-
-
-/**
- * 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) {
+ /**
+ * 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_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);
- 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;
-
- 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)
-{
- 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);
-}
-/**
- * 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