From d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb Mon Sep 17 00:00:00 2001 From: ng0 Date: Sun, 8 Sep 2019 12:33:09 +0000 Subject: uncrustify as demanded. --- src/set/gnunet-service-set.c | 1843 ++++++++-------- src/set/gnunet-service-set.h | 54 +- src/set/gnunet-service-set_intersection.c | 1241 +++++------ src/set/gnunet-service-set_intersection.h | 20 +- src/set/gnunet-service-set_protocol.h | 26 +- src/set/gnunet-service-set_union.c | 2299 ++++++++++---------- src/set/gnunet-service-set_union.h | 76 +- .../gnunet-service-set_union_strata_estimator.c | 210 +- .../gnunet-service-set_union_strata_estimator.h | 41 +- src/set/gnunet-set-ibf-profiler.c | 362 +-- src/set/gnunet-set-profiler.c | 505 ++--- src/set/ibf.c | 282 +-- src/set/ibf.h | 60 +- src/set/ibf_sim.c | 119 +- src/set/plugin_block_set_test.c | 48 +- src/set/set.h | 45 +- src/set/set_api.c | 923 ++++---- src/set/test_set_api.c | 411 ++-- src/set/test_set_intersection_result_full.c | 388 ++-- src/set/test_set_union_copy.c | 285 ++- src/set/test_set_union_result_symmetric.c | 394 ++-- 21 files changed, 4814 insertions(+), 4818 deletions(-) (limited to 'src/set') diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index 5becd7bd9..2dad49e6d 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/gnunet-service-set.c * @brief two-peer set operations @@ -39,8 +39,7 @@ /** * Lazy copy requests made by a client. */ -struct LazyCopyRequest -{ +struct LazyCopyRequest { /** * Kept in a DLL. */ @@ -67,8 +66,7 @@ struct LazyCopyRequest * A listener is inhabited by a client, and waits for evaluation * requests from remote peers. */ -struct Listener -{ +struct Listener { /** * Listeners are held in a doubly linked list. */ @@ -182,15 +180,15 @@ static uint32_t suggest_id; * or NULL if there is none */ static struct Operation * -get_incoming (uint32_t id) +get_incoming(uint32_t id) { for (struct Listener *listener = listener_head; NULL != listener; listener = listener->next) - { - for (struct Operation *op = listener->op_head; NULL != op; op = op->next) - if (op->suggest_id == id) - return op; - } + { + for (struct Operation *op = listener->op_head; NULL != op; op = op->next) + if (op->suggest_id == id) + return op; + } return NULL; } @@ -201,33 +199,31 @@ get_incoming (uint32_t id) * @param op remote request to destroy */ static void -incoming_destroy (struct Operation *op) +incoming_destroy(struct Operation *op) { struct Listener *listener; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Destroying incoming operation %p\n", - op); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Destroying incoming operation %p\n", + op); if (NULL != (listener = op->listener)) - { - GNUNET_CONTAINER_DLL_remove (listener->op_head, listener->op_tail, op); - op->listener = NULL; - } + { + GNUNET_CONTAINER_DLL_remove(listener->op_head, listener->op_tail, op); + op->listener = NULL; + } if (NULL != op->timeout_task) - { - GNUNET_SCHEDULER_cancel (op->timeout_task); - op->timeout_task = NULL; - } - _GSS_operation_destroy2 (op); + { + GNUNET_SCHEDULER_cancel(op->timeout_task); + op->timeout_task = NULL; + } + _GSS_operation_destroy2(op); } /** * Context for the #garbage_collect_cb(). */ -struct GarbageContext -{ - +struct GarbageContext { /** * Map for which we are garbage collecting removed elements. */ @@ -255,7 +251,7 @@ struct GarbageContext * @return #GNUNET_OK (continue to iterate) */ static int -garbage_collect_cb (void *cls, const struct GNUNET_HashCode *key, void *value) +garbage_collect_cb(void *cls, const struct GNUNET_HashCode *key, void *value) { //struct GarbageContext *gc = cls; //struct ElementEntry *ee = value; @@ -283,23 +279,23 @@ garbage_collect_cb (void *cls, const struct GNUNET_HashCode *key, void *value) * @param set set to garbage collect */ static void -collect_generation_garbage (struct Set *set) +collect_generation_garbage(struct Set *set) { struct GarbageContext gc; gc.min_op_generation = UINT_MAX; gc.max_op_generation = 0; for (struct Operation *op = set->ops_head; NULL != op; op = op->next) - { - gc.min_op_generation = - GNUNET_MIN (gc.min_op_generation, op->generation_created); - gc.max_op_generation = - GNUNET_MAX (gc.max_op_generation, op->generation_created); - } + { + gc.min_op_generation = + GNUNET_MIN(gc.min_op_generation, op->generation_created); + gc.max_op_generation = + GNUNET_MAX(gc.max_op_generation, op->generation_created); + } gc.map = set->content->elements; - GNUNET_CONTAINER_multihashmap_iterate (set->content->elements, - &garbage_collect_cb, - &gc); + GNUNET_CONTAINER_multihashmap_iterate(set->content->elements, + &garbage_collect_cb, + &gc); } @@ -312,9 +308,9 @@ collect_generation_garbage (struct Set *set) * @return #GNUNET_YES if @a generation is in any of the ranges */ static int -is_excluded_generation (unsigned int generation, - struct GenerationRange *excluded, - unsigned int excluded_size) +is_excluded_generation(unsigned int generation, + struct GenerationRange *excluded, + unsigned int excluded_size) { for (unsigned int i = 0; i < excluded_size; i++) if ((generation >= excluded[i].start) && (generation < excluded[i].end)) @@ -333,57 +329,57 @@ is_excluded_generation (unsigned int generation, * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not */ static int -is_element_of_generation (struct ElementEntry *ee, - unsigned int query_generation, - struct GenerationRange *excluded, - unsigned int excluded_size) +is_element_of_generation(struct ElementEntry *ee, + unsigned int query_generation, + struct GenerationRange *excluded, + unsigned int excluded_size) { struct MutationEvent *mut; int is_present; - GNUNET_assert (NULL != ee->mutations); + GNUNET_assert(NULL != ee->mutations); if (GNUNET_YES == - is_excluded_generation (query_generation, excluded, excluded_size)) - { - GNUNET_break (0); - return GNUNET_NO; - } + is_excluded_generation(query_generation, excluded, excluded_size)) + { + GNUNET_break(0); + return GNUNET_NO; + } is_present = GNUNET_NO; /* Could be made faster with binary search, but lists are small, so why bother. */ for (unsigned int i = 0; i < ee->mutations_size; i++) - { - mut = &ee->mutations[i]; - - if (mut->generation > query_generation) - { - /* The mutation doesn't apply to our generation - anymore. We can'b break here, since mutations aren't - sorted by generation. */ - continue; - } - - if (GNUNET_YES == - is_excluded_generation (mut->generation, excluded, excluded_size)) { - /* The generation is excluded (because it belongs to another - fork via a lazy copy) and thus mutations aren't considered - for membership testing. */ - continue; + mut = &ee->mutations[i]; + + if (mut->generation > query_generation) + { + /* The mutation doesn't apply to our generation + anymore. We can'b break here, since mutations aren't + sorted by generation. */ + continue; + } + + if (GNUNET_YES == + is_excluded_generation(mut->generation, excluded, excluded_size)) + { + /* The generation is excluded (because it belongs to another + fork via a lazy copy) and thus mutations aren't considered + for membership testing. */ + continue; + } + + /* This would be an inconsistency in how we manage mutations. */ + if ((GNUNET_YES == is_present) && (GNUNET_YES == mut->added)) + GNUNET_assert(0); + /* Likewise. */ + if ((GNUNET_NO == is_present) && (GNUNET_NO == mut->added)) + GNUNET_assert(0); + + is_present = mut->added; } - /* This would be an inconsistency in how we manage mutations. */ - if ((GNUNET_YES == is_present) && (GNUNET_YES == mut->added)) - GNUNET_assert (0); - /* Likewise. */ - if ((GNUNET_NO == is_present) && (GNUNET_NO == mut->added)) - GNUNET_assert (0); - - is_present = mut->added; - } - return is_present; } @@ -396,12 +392,12 @@ is_element_of_generation (struct ElementEntry *ee, * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not */ int -_GSS_is_element_of_operation (struct ElementEntry *ee, struct Operation *op) +_GSS_is_element_of_operation(struct ElementEntry *ee, struct Operation *op) { - return is_element_of_generation (ee, - op->generation_created, - op->set->excluded_generations, - op->set->excluded_generations_size); + return is_element_of_generation(ee, + op->generation_created, + op->set->excluded_generations, + op->set->excluded_generations_size); } @@ -419,37 +415,37 @@ _GSS_is_element_of_operation (struct ElementEntry *ee, struct Operation *op) * @param gc #GNUNET_YES to perform garbage collection on the set */ void -_GSS_operation_destroy (struct Operation *op, int gc) +_GSS_operation_destroy(struct Operation *op, int gc) { struct Set *set = op->set; struct GNUNET_CADET_Channel *channel; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying operation %p\n", op); - GNUNET_assert (NULL == op->listener); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying operation %p\n", op); + GNUNET_assert(NULL == op->listener); if (NULL != op->state) - { - set->vt->cancel (op); - op->state = NULL; - } + { + set->vt->cancel(op); + op->state = NULL; + } if (NULL != set) - { - GNUNET_CONTAINER_DLL_remove (set->ops_head, set->ops_tail, op); - op->set = NULL; - } + { + GNUNET_CONTAINER_DLL_remove(set->ops_head, set->ops_tail, op); + op->set = NULL; + } if (NULL != op->context_msg) - { - GNUNET_free (op->context_msg); - op->context_msg = NULL; - } + { + GNUNET_free(op->context_msg); + op->context_msg = NULL; + } if (NULL != (channel = op->channel)) - { - /* This will free op; called conditionally as this helper function - is also called from within the channel disconnect handler. */ - op->channel = NULL; - GNUNET_CADET_channel_destroy (channel); - } + { + /* This will free op; called conditionally as this helper function + is also called from within the channel disconnect handler. */ + op->channel = NULL; + GNUNET_CADET_channel_destroy(channel); + } if ((NULL != set) && (GNUNET_YES == gc)) - collect_generation_garbage (set); + collect_generation_garbage(set); /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL, * there was a channel end handler that will free 'op' on the call stack. */ } @@ -464,14 +460,14 @@ _GSS_operation_destroy (struct Operation *op, int gc) * @return @a `struct ClientState` */ static void * -client_connect_cb (void *cls, - struct GNUNET_SERVICE_Client *c, - struct GNUNET_MQ_Handle *mq) +client_connect_cb(void *cls, + struct GNUNET_SERVICE_Client *c, + struct GNUNET_MQ_Handle *mq) { struct ClientState *cs; num_clients++; - cs = GNUNET_new (struct ClientState); + cs = GNUNET_new(struct ClientState); cs->client = c; cs->mq = mq; return cs; @@ -487,14 +483,14 @@ client_connect_cb (void *cls, * @return #GNUNET_YES (continue to iterate) */ static int -destroy_elements_iterator (void *cls, - const struct GNUNET_HashCode *key, - void *value) +destroy_elements_iterator(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct ElementEntry *ee = value; - GNUNET_free_non_null (ee->mutations); - GNUNET_free (ee); + GNUNET_free_non_null(ee->mutations); + GNUNET_free(ee); return GNUNET_YES; } @@ -507,117 +503,117 @@ destroy_elements_iterator (void *cls, * @param internal_cls the `struct ClientState` */ static void -client_disconnect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - void *internal_cls) +client_disconnect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + void *internal_cls) { struct ClientState *cs = internal_cls; struct Operation *op; struct Listener *listener; struct Set *set; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, cleaning up\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, cleaning up\n"); if (NULL != (set = cs->set)) - { - struct SetContent *content = set->content; - struct PendingMutation *pm; - struct PendingMutation *pm_current; - struct LazyCopyRequest *lcr; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying client's set\n"); - /* Destroy pending set operations */ - while (NULL != set->ops_head) - _GSS_operation_destroy (set->ops_head, GNUNET_NO); - - /* Destroy operation-specific state */ - GNUNET_assert (NULL != set->state); - set->vt->destroy_set (set->state); - set->state = NULL; - - /* Clean up ongoing iterations */ - if (NULL != set->iter) { - GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter); - set->iter = NULL; - set->iteration_id++; + struct SetContent *content = set->content; + struct PendingMutation *pm; + struct PendingMutation *pm_current; + struct LazyCopyRequest *lcr; + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying client's set\n"); + /* Destroy pending set operations */ + while (NULL != set->ops_head) + _GSS_operation_destroy(set->ops_head, GNUNET_NO); + + /* Destroy operation-specific state */ + GNUNET_assert(NULL != set->state); + set->vt->destroy_set(set->state); + set->state = NULL; + + /* Clean up ongoing iterations */ + if (NULL != set->iter) + { + GNUNET_CONTAINER_multihashmap_iterator_destroy(set->iter); + set->iter = NULL; + set->iteration_id++; + } + + /* discard any pending mutations that reference this set */ + pm = content->pending_mutations_head; + while (NULL != pm) + { + pm_current = pm; + pm = pm->next; + if (pm_current->set == set) + { + GNUNET_CONTAINER_DLL_remove(content->pending_mutations_head, + content->pending_mutations_tail, + pm_current); + GNUNET_free(pm_current); + } + } + + /* free set content (or at least decrement RC) */ + set->content = NULL; + GNUNET_assert(0 != content->refcount); + content->refcount--; + if (0 == content->refcount) + { + GNUNET_assert(NULL != content->elements); + GNUNET_CONTAINER_multihashmap_iterate(content->elements, + &destroy_elements_iterator, + NULL); + GNUNET_CONTAINER_multihashmap_destroy(content->elements); + content->elements = NULL; + GNUNET_free(content); + } + GNUNET_free_non_null(set->excluded_generations); + set->excluded_generations = NULL; + + /* remove set from pending copy requests */ + lcr = lazy_copy_head; + while (NULL != lcr) + { + struct LazyCopyRequest *lcr_current = lcr; + + lcr = lcr->next; + if (lcr_current->source_set == set) + { + GNUNET_CONTAINER_DLL_remove(lazy_copy_head, + lazy_copy_tail, + lcr_current); + GNUNET_free(lcr_current); + } + } + GNUNET_free(set); } - /* discard any pending mutations that reference this set */ - pm = content->pending_mutations_head; - while (NULL != pm) - { - pm_current = pm; - pm = pm->next; - if (pm_current->set == set) - { - GNUNET_CONTAINER_DLL_remove (content->pending_mutations_head, - content->pending_mutations_tail, - pm_current); - GNUNET_free (pm_current); - } - } - - /* free set content (or at least decrement RC) */ - set->content = NULL; - GNUNET_assert (0 != content->refcount); - content->refcount--; - if (0 == content->refcount) - { - GNUNET_assert (NULL != content->elements); - GNUNET_CONTAINER_multihashmap_iterate (content->elements, - &destroy_elements_iterator, - NULL); - GNUNET_CONTAINER_multihashmap_destroy (content->elements); - content->elements = NULL; - GNUNET_free (content); - } - GNUNET_free_non_null (set->excluded_generations); - set->excluded_generations = NULL; - - /* remove set from pending copy requests */ - lcr = lazy_copy_head; - while (NULL != lcr) - { - struct LazyCopyRequest *lcr_current = lcr; - - lcr = lcr->next; - if (lcr_current->source_set == set) - { - GNUNET_CONTAINER_DLL_remove (lazy_copy_head, - lazy_copy_tail, - lcr_current); - GNUNET_free (lcr_current); - } - } - GNUNET_free (set); - } - if (NULL != (listener = cs->listener)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying client's listener\n"); - GNUNET_CADET_close_port (listener->open_port); - listener->open_port = NULL; - while (NULL != (op = listener->op_head)) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Destroying incoming operation `%u' from peer `%s'\n", - (unsigned int) op->client_request_id, - GNUNET_i2s (&op->peer)); - incoming_destroy (op); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying client's listener\n"); + GNUNET_CADET_close_port(listener->open_port); + listener->open_port = NULL; + while (NULL != (op = listener->op_head)) + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Destroying incoming operation `%u' from peer `%s'\n", + (unsigned int)op->client_request_id, + GNUNET_i2s(&op->peer)); + incoming_destroy(op); + } + GNUNET_CONTAINER_DLL_remove(listener_head, listener_tail, listener); + GNUNET_free(listener); } - GNUNET_CONTAINER_DLL_remove (listener_head, listener_tail, listener); - GNUNET_free (listener); - } - GNUNET_free (cs); + GNUNET_free(cs); num_clients--; if ((GNUNET_YES == in_shutdown) && (0 == num_clients)) - { - if (NULL != cadet) { - GNUNET_CADET_disconnect (cadet); - cadet = NULL; + if (NULL != cadet) + { + GNUNET_CADET_disconnect(cadet); + cadet = NULL; + } } - } } @@ -630,7 +626,7 @@ client_disconnect_cb (void *cls, * #GNUNET_SYSERR to destroy the channel */ static int -check_incoming_msg (void *cls, const struct OperationRequestMessage *msg) +check_incoming_msg(void *cls, const struct OperationRequestMessage *msg) { struct Operation *op = cls; struct Listener *listener = op->listener; @@ -638,29 +634,29 @@ check_incoming_msg (void *cls, const struct OperationRequestMessage *msg) /* double operation request */ if (0 != op->suggest_id) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } /* This should be equivalent to the previous condition, but can't hurt to check twice */ if (NULL == op->listener) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } if (listener->operation != - (enum GNUNET_SET_OperationType) ntohl (msg->operation)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - nested_context = GNUNET_MQ_extract_nested_mh (msg); + (enum GNUNET_SET_OperationType)ntohl(msg->operation)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + nested_context = GNUNET_MQ_extract_nested_mh(msg); if ((NULL != nested_context) && - (ntohs (nested_context->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + (ntohs(nested_context->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -683,7 +679,7 @@ check_incoming_msg (void *cls, const struct OperationRequestMessage *msg) * #GNUNET_SYSERR to destroy the channel */ static void -handle_incoming_msg (void *cls, const struct OperationRequestMessage *msg) +handle_incoming_msg(void *cls, const struct OperationRequestMessage *msg) { struct Operation *op = cls; struct Listener *listener = op->listener; @@ -691,39 +687,39 @@ handle_incoming_msg (void *cls, const struct OperationRequestMessage *msg) struct GNUNET_MQ_Envelope *env; struct GNUNET_SET_RequestMessage *cmsg; - nested_context = GNUNET_MQ_extract_nested_mh (msg); + nested_context = GNUNET_MQ_extract_nested_mh(msg); /* Make a copy of the nested_context (application-specific context information that is opaque to set) so we can pass it to the listener later on */ if (NULL != nested_context) - op->context_msg = GNUNET_copy_message (nested_context); - op->remote_element_count = ntohl (msg->element_count); - GNUNET_log ( + op->context_msg = GNUNET_copy_message(nested_context); + op->remote_element_count = ntohl(msg->element_count); + GNUNET_log( GNUNET_ERROR_TYPE_DEBUG, "Received P2P operation request (op %u, port %s) for active listener\n", - (uint32_t) ntohl (msg->operation), - GNUNET_h2s (&op->listener->app_id)); - GNUNET_assert (0 == op->suggest_id); + (uint32_t)ntohl(msg->operation), + GNUNET_h2s(&op->listener->app_id)); + GNUNET_assert(0 == op->suggest_id); if (0 == suggest_id) suggest_id++; op->suggest_id = suggest_id++; - GNUNET_assert (NULL != op->timeout_task); - GNUNET_SCHEDULER_cancel (op->timeout_task); + GNUNET_assert(NULL != op->timeout_task); + GNUNET_SCHEDULER_cancel(op->timeout_task); op->timeout_task = NULL; - env = GNUNET_MQ_msg_nested_mh (cmsg, - GNUNET_MESSAGE_TYPE_SET_REQUEST, - op->context_msg); - GNUNET_log ( + env = GNUNET_MQ_msg_nested_mh(cmsg, + GNUNET_MESSAGE_TYPE_SET_REQUEST, + op->context_msg); + GNUNET_log( GNUNET_ERROR_TYPE_DEBUG, "Suggesting incoming request with accept id %u to listener %p of client %p\n", op->suggest_id, listener, listener->cs); - cmsg->accept_id = htonl (op->suggest_id); + cmsg->accept_id = htonl(op->suggest_id); cmsg->peer_id = op->peer; - GNUNET_MQ_send (listener->cs->mq, env); + GNUNET_MQ_send(listener->cs->mq, env); /* NOTE: GNUNET_CADET_receive_done() will be called in - #handle_client_accept() */ + #handle_client_accept() */ } @@ -734,61 +730,61 @@ handle_incoming_msg (void *cls, const struct OperationRequestMessage *msg) * @param msg message specifying the change */ static void -execute_add (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) +execute_add(struct Set *set, const struct GNUNET_SET_ElementMessage *msg) { struct GNUNET_SET_Element el; struct ElementEntry *ee; struct GNUNET_HashCode hash; - GNUNET_assert (GNUNET_MESSAGE_TYPE_SET_ADD == ntohs (msg->header.type)); - el.size = ntohs (msg->header.size) - sizeof (*msg); + GNUNET_assert(GNUNET_MESSAGE_TYPE_SET_ADD == ntohs(msg->header.type)); + el.size = ntohs(msg->header.size) - sizeof(*msg); el.data = &msg[1]; - el.element_type = ntohs (msg->element_type); - GNUNET_SET_element_hash (&el, &hash); - ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, &hash); + el.element_type = ntohs(msg->element_type); + GNUNET_SET_element_hash(&el, &hash); + ee = GNUNET_CONTAINER_multihashmap_get(set->content->elements, &hash); if (NULL == ee) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client inserts element %s of size %u\n", - GNUNET_h2s (&hash), - el.size); - ee = GNUNET_malloc (el.size + sizeof (*ee)); - ee->element.size = el.size; - GNUNET_memcpy (&ee[1], el.data, el.size); - ee->element.data = &ee[1]; - ee->element.element_type = el.element_type; - ee->remote = GNUNET_NO; - ee->mutations = NULL; - ee->mutations_size = 0; - ee->element_hash = hash; - GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_put ( - set->content->elements, - &ee->element_hash, - ee, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Client inserts element %s of size %u\n", + GNUNET_h2s(&hash), + el.size); + ee = GNUNET_malloc(el.size + sizeof(*ee)); + ee->element.size = el.size; + GNUNET_memcpy(&ee[1], el.data, el.size); + ee->element.data = &ee[1]; + ee->element.element_type = el.element_type; + ee->remote = GNUNET_NO; + ee->mutations = NULL; + ee->mutations_size = 0; + ee->element_hash = hash; + GNUNET_break(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_put( + set->content->elements, + &ee->element_hash, + ee, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + } else if (GNUNET_YES == - is_element_of_generation (ee, - set->current_generation, - set->excluded_generations, - set->excluded_generations_size)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client inserted element %s of size %u twice (ignored)\n", - GNUNET_h2s (&hash), - el.size); + is_element_of_generation(ee, + set->current_generation, + set->excluded_generations, + set->excluded_generations_size)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Client inserted element %s of size %u twice (ignored)\n", + GNUNET_h2s(&hash), + el.size); - /* same element inserted twice */ - return; - } + /* same element inserted twice */ + return; + } { - struct MutationEvent mut = {.generation = set->current_generation, - .added = GNUNET_YES}; - GNUNET_array_append (ee->mutations, ee->mutations_size, mut); + struct MutationEvent mut = { .generation = set->current_generation, + .added = GNUNET_YES }; + GNUNET_array_append(ee->mutations, ee->mutations_size, mut); } - set->vt->add (set->state, ee); + set->vt->add(set->state, ee); } @@ -799,49 +795,49 @@ execute_add (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) * @param msg message specifying the change */ static void -execute_remove (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) +execute_remove(struct Set *set, const struct GNUNET_SET_ElementMessage *msg) { struct GNUNET_SET_Element el; struct ElementEntry *ee; struct GNUNET_HashCode hash; - GNUNET_assert (GNUNET_MESSAGE_TYPE_SET_REMOVE == ntohs (msg->header.type)); - el.size = ntohs (msg->header.size) - sizeof (*msg); + GNUNET_assert(GNUNET_MESSAGE_TYPE_SET_REMOVE == ntohs(msg->header.type)); + el.size = ntohs(msg->header.size) - sizeof(*msg); el.data = &msg[1]; - el.element_type = ntohs (msg->element_type); - GNUNET_SET_element_hash (&el, &hash); - ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, &hash); + el.element_type = ntohs(msg->element_type); + GNUNET_SET_element_hash(&el, &hash); + ee = GNUNET_CONTAINER_multihashmap_get(set->content->elements, &hash); if (NULL == ee) - { - /* Client tried to remove non-existing element. */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client removes non-existing element of size %u\n", - el.size); - return; - } - if (GNUNET_NO == is_element_of_generation (ee, - set->current_generation, - set->excluded_generations, - set->excluded_generations_size)) - { - /* Client tried to remove element twice */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client removed element of size %u twice (ignored)\n", - el.size); - return; - } + { + /* Client tried to remove non-existing element. */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Client removes non-existing element of size %u\n", + el.size); + return; + } + if (GNUNET_NO == is_element_of_generation(ee, + set->current_generation, + set->excluded_generations, + set->excluded_generations_size)) + { + /* Client tried to remove element twice */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Client removed element of size %u twice (ignored)\n", + el.size); + return; + } else - { - struct MutationEvent mut = {.generation = set->current_generation, - .added = GNUNET_NO}; + { + struct MutationEvent mut = { .generation = set->current_generation, + .added = GNUNET_NO }; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client removes element of size %u\n", - el.size); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Client removes element of size %u\n", + el.size); - GNUNET_array_append (ee->mutations, ee->mutations_size, mut); - } - set->vt->remove (set->state, ee); + GNUNET_array_append(ee->mutations, ee->mutations_size, mut); + } + set->vt->remove(set->state, ee); } @@ -852,19 +848,21 @@ execute_remove (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) * @param msg specification of what to change */ static void -execute_mutation (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) +execute_mutation(struct Set *set, const struct GNUNET_SET_ElementMessage *msg) { - switch (ntohs (msg->header.type)) - { - case GNUNET_MESSAGE_TYPE_SET_ADD: - execute_add (set, msg); - break; - case GNUNET_MESSAGE_TYPE_SET_REMOVE: - execute_remove (set, msg); - break; - default: - GNUNET_break (0); - } + switch (ntohs(msg->header.type)) + { + case GNUNET_MESSAGE_TYPE_SET_ADD: + execute_add(set, msg); + break; + + case GNUNET_MESSAGE_TYPE_SET_REMOVE: + execute_remove(set, msg); + break; + + default: + GNUNET_break(0); + } } @@ -875,24 +873,24 @@ execute_mutation (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) * @param set the set to execute mutations on */ static void -execute_delayed_mutations (struct Set *set) +execute_delayed_mutations(struct Set *set) { struct PendingMutation *pm; if (0 != set->content->iterator_count) return; /* still cannot do this */ while (NULL != (pm = set->content->pending_mutations_head)) - { - GNUNET_CONTAINER_DLL_remove (set->content->pending_mutations_head, - set->content->pending_mutations_tail, - pm); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Executing pending mutation on %p.\n", - pm->set); - execute_mutation (pm->set, pm->msg); - GNUNET_free (pm->msg); - GNUNET_free (pm); - } + { + GNUNET_CONTAINER_DLL_remove(set->content->pending_mutations_head, + set->content->pending_mutations_tail, + pm); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Executing pending mutation on %p.\n", + pm->set); + execute_mutation(pm->set, pm->msg); + GNUNET_free(pm->msg); + GNUNET_free(pm); + } } @@ -910,48 +908,49 @@ execute_delayed_mutations (struct Set *set) * @param set set that should send its next element to its client */ static void -send_client_element (struct Set *set) +send_client_element(struct Set *set) { int ret; struct ElementEntry *ee; struct GNUNET_MQ_Envelope *ev; struct GNUNET_SET_IterResponseMessage *msg; - GNUNET_assert (NULL != set->iter); + GNUNET_assert(NULL != set->iter); do - { - ret = GNUNET_CONTAINER_multihashmap_iterator_next (set->iter, - NULL, - (const void **) &ee); - if (GNUNET_NO == ret) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration on %p done.\n", set); - ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_DONE); - GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter); - set->iter = NULL; - set->iteration_id++; - GNUNET_assert (set->content->iterator_count > 0); - set->content->iterator_count--; - execute_delayed_mutations (set); - GNUNET_MQ_send (set->cs->mq, ev); - return; + ret = GNUNET_CONTAINER_multihashmap_iterator_next(set->iter, + NULL, + (const void **)&ee); + if (GNUNET_NO == ret) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Iteration on %p done.\n", set); + ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_ITER_DONE); + GNUNET_CONTAINER_multihashmap_iterator_destroy(set->iter); + set->iter = NULL; + set->iteration_id++; + GNUNET_assert(set->content->iterator_count > 0); + set->content->iterator_count--; + execute_delayed_mutations(set); + GNUNET_MQ_send(set->cs->mq, ev); + return; + } + GNUNET_assert(NULL != ee); } - GNUNET_assert (NULL != ee); - } while (GNUNET_NO == - is_element_of_generation (ee, - set->iter_generation, - set->excluded_generations, - set->excluded_generations_size)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending iteration element on %p.\n", - set); - ev = GNUNET_MQ_msg_extra (msg, - ee->element.size, - GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT); - GNUNET_memcpy (&msg[1], ee->element.data, ee->element.size); - msg->element_type = htons (ee->element.element_type); - msg->iteration_id = htons (set->iteration_id); - GNUNET_MQ_send (set->cs->mq, ev); + while (GNUNET_NO == + is_element_of_generation(ee, + set->iter_generation, + set->excluded_generations, + set->excluded_generations_size)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending iteration element on %p.\n", + set); + ev = GNUNET_MQ_msg_extra(msg, + ee->element.size, + GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT); + GNUNET_memcpy(&msg[1], ee->element.data, ee->element.size); + msg->element_type = htons(ee->element.element_type); + msg->iteration_id = htons(set->iteration_id); + GNUNET_MQ_send(set->cs->mq, ev); } @@ -965,36 +964,36 @@ send_client_element (struct Set *set) * @param m message sent by the client */ static void -handle_client_iterate (void *cls, const struct GNUNET_MessageHeader *m) +handle_client_iterate(void *cls, const struct GNUNET_MessageHeader *m) { struct ClientState *cs = cls; struct Set *set; if (NULL == (set = cs->set)) - { - /* attempt to iterate over a non existing set */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } + { + /* attempt to iterate over a non existing set */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } if (NULL != set->iter) - { - /* Only one concurrent iterate-action allowed per set */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Iterating set %p in gen %u with %u content elements\n", - (void *) set, - set->current_generation, - GNUNET_CONTAINER_multihashmap_size (set->content->elements)); - GNUNET_SERVICE_client_continue (cs->client); + { + /* Only one concurrent iterate-action allowed per set */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Iterating set %p in gen %u with %u content elements\n", + (void *)set, + set->current_generation, + GNUNET_CONTAINER_multihashmap_size(set->content->elements)); + GNUNET_SERVICE_client_continue(cs->client); set->content->iterator_count++; set->iter = - GNUNET_CONTAINER_multihashmap_iterator_create (set->content->elements); + GNUNET_CONTAINER_multihashmap_iterator_create(set->content->elements); set->iter_generation = set->current_generation; - send_client_element (set); + send_client_element(set); } @@ -1007,51 +1006,53 @@ handle_client_iterate (void *cls, const struct GNUNET_MessageHeader *m) * @param m message sent by the client */ static void -handle_client_create_set (void *cls, const struct GNUNET_SET_CreateMessage *msg) +handle_client_create_set(void *cls, const struct GNUNET_SET_CreateMessage *msg) { struct ClientState *cs = cls; struct Set *set; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client created new set (operation %u)\n", - (uint32_t) ntohl (msg->operation)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Client created new set (operation %u)\n", + (uint32_t)ntohl(msg->operation)); if (NULL != cs->set) - { - /* There can only be one set per client */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } - set = GNUNET_new (struct Set); - switch (ntohl (msg->operation)) - { - case GNUNET_SET_OPERATION_INTERSECTION: - set->vt = _GSS_intersection_vt (); - break; - case GNUNET_SET_OPERATION_UNION: - set->vt = _GSS_union_vt (); - break; - default: - GNUNET_free (set); - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } - set->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation); - set->state = set->vt->create (); + { + /* There can only be one set per client */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } + set = GNUNET_new(struct Set); + switch (ntohl(msg->operation)) + { + case GNUNET_SET_OPERATION_INTERSECTION: + set->vt = _GSS_intersection_vt(); + break; + + case GNUNET_SET_OPERATION_UNION: + set->vt = _GSS_union_vt(); + break; + + default: + GNUNET_free(set); + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } + set->operation = (enum GNUNET_SET_OperationType)ntohl(msg->operation); + set->state = set->vt->create(); if (NULL == set->state) - { - /* initialization failed (i.e. out of memory) */ - GNUNET_free (set); - GNUNET_SERVICE_client_drop (cs->client); - return; - } - set->content = GNUNET_new (struct SetContent); + { + /* initialization failed (i.e. out of memory) */ + GNUNET_free(set); + GNUNET_SERVICE_client_drop(cs->client); + return; + } + set->content = GNUNET_new(struct SetContent); set->content->refcount = 1; - set->content->elements = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); + set->content->elements = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_YES); set->cs = cs; cs->set = set; - GNUNET_SERVICE_client_continue (cs->client); + GNUNET_SERVICE_client_continue(cs->client); } @@ -1065,14 +1066,14 @@ handle_client_create_set (void *cls, const struct GNUNET_SET_CreateMessage *msg) * @param tc context information (why was this task triggered now) */ static void -incoming_timeout_cb (void *cls) +incoming_timeout_cb(void *cls) { struct Operation *op = cls; op->timeout_task = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Remote peer's incoming request timed out\n"); - incoming_destroy (op); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Remote peer's incoming request timed out\n"); + incoming_destroy(op); } @@ -1093,24 +1094,24 @@ incoming_timeout_cb (void *cls) * returns NULL on error */ static void * -channel_new_cb (void *cls, - struct GNUNET_CADET_Channel *channel, - const struct GNUNET_PeerIdentity *source) +channel_new_cb(void *cls, + struct GNUNET_CADET_Channel *channel, + const struct GNUNET_PeerIdentity *source) { struct Listener *listener = cls; struct Operation *op; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New incoming channel\n"); - op = GNUNET_new (struct Operation); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New incoming channel\n"); + op = GNUNET_new(struct Operation); op->listener = listener; op->peer = *source; op->channel = channel; - op->mq = GNUNET_CADET_get_mq (op->channel); - op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); - op->timeout_task = GNUNET_SCHEDULER_add_delayed (INCOMING_CHANNEL_TIMEOUT, - &incoming_timeout_cb, - op); - GNUNET_CONTAINER_DLL_insert (listener->op_head, listener->op_tail, op); + op->mq = GNUNET_CADET_get_mq(op->channel); + op->salt = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); + op->timeout_task = GNUNET_SCHEDULER_add_delayed(INCOMING_CHANNEL_TIMEOUT, + &incoming_timeout_cb, + op); + GNUNET_CONTAINER_DLL_insert(listener->op_head, listener->op_tail, op); return op; } @@ -1132,12 +1133,12 @@ channel_new_cb (void *cls, * @param channel connection to the other end (henceforth invalid) */ static void -channel_end_cb (void *channel_ctx, const struct GNUNET_CADET_Channel *channel) +channel_end_cb(void *channel_ctx, const struct GNUNET_CADET_Channel *channel) { struct Operation *op = channel_ctx; op->channel = NULL; - _GSS_operation_destroy2 (op); + _GSS_operation_destroy2(op); } @@ -1147,28 +1148,28 @@ channel_end_cb (void *channel_ctx, const struct GNUNET_CADET_Channel *channel) * logic in the various places where it is called. */ void -_GSS_operation_destroy2 (struct Operation *op) +_GSS_operation_destroy2(struct Operation *op) { struct GNUNET_CADET_Channel *channel; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "channel_end_cb called\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "channel_end_cb called\n"); if (NULL != (channel = op->channel)) - { - /* This will free op; called conditionally as this helper function - is also called from within the channel disconnect handler. */ - op->channel = NULL; - GNUNET_CADET_channel_destroy (channel); - } + { + /* This will free op; called conditionally as this helper function + is also called from within the channel disconnect handler. */ + op->channel = NULL; + GNUNET_CADET_channel_destroy(channel); + } if (NULL != op->listener) - { - incoming_destroy (op); - return; - } + { + incoming_destroy(op); + return; + } if (NULL != op->set) - op->set->vt->channel_death (op); + op->set->vt->channel_death(op); else - _GSS_operation_destroy (op, GNUNET_YES); - GNUNET_free (op); + _GSS_operation_destroy(op, GNUNET_YES); + GNUNET_free(op); } @@ -1187,9 +1188,9 @@ _GSS_operation_destroy2 (struct Operation *op) * this value will be negative.. */ static void -channel_window_cb (void *cls, - const struct GNUNET_CADET_Channel *channel, - int window_size) +channel_window_cb(void *cls, + const struct GNUNET_CADET_Channel *channel, + int window_size) { /* FIXME: not implemented, we could do flow control here... */ } @@ -1202,102 +1203,102 @@ channel_window_cb (void *cls, * @param msg message sent by the client */ static void -handle_client_listen (void *cls, const struct GNUNET_SET_ListenMessage *msg) +handle_client_listen(void *cls, const struct GNUNET_SET_ListenMessage *msg) { struct ClientState *cs = cls; struct GNUNET_MQ_MessageHandler cadet_handlers[] = - {GNUNET_MQ_hd_var_size (incoming_msg, - GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, - struct OperationRequestMessage, - NULL), - GNUNET_MQ_hd_var_size (union_p2p_ibf, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, - struct IBFMessage, - NULL), - GNUNET_MQ_hd_var_size (union_p2p_elements, - GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, - struct GNUNET_SET_ElementMessage, - NULL), - GNUNET_MQ_hd_var_size (union_p2p_offer, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, + { GNUNET_MQ_hd_var_size(incoming_msg, + GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, + struct OperationRequestMessage, + NULL), + GNUNET_MQ_hd_var_size(union_p2p_ibf, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, + struct IBFMessage, + NULL), + GNUNET_MQ_hd_var_size(union_p2p_elements, + GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, + struct GNUNET_SET_ElementMessage, + NULL), + GNUNET_MQ_hd_var_size(union_p2p_offer, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_var_size(union_p2p_inquiry, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, + struct InquiryMessage, + NULL), + GNUNET_MQ_hd_var_size(union_p2p_demand, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_fixed_size(union_p2p_done, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, struct GNUNET_MessageHeader, NULL), - GNUNET_MQ_hd_var_size (union_p2p_inquiry, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, - struct InquiryMessage, - NULL), - GNUNET_MQ_hd_var_size (union_p2p_demand, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, + GNUNET_MQ_hd_fixed_size(union_p2p_over, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, struct GNUNET_MessageHeader, NULL), - GNUNET_MQ_hd_fixed_size (union_p2p_done, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size (union_p2p_over, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size (union_p2p_full_done, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size (union_p2p_request_full, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, - struct StrataEstimatorMessage, + GNUNET_MQ_hd_fixed_size(union_p2p_full_done, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, + struct GNUNET_MessageHeader, NULL), - GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, - struct StrataEstimatorMessage, + GNUNET_MQ_hd_fixed_size(union_p2p_request_full, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, + struct GNUNET_MessageHeader, NULL), - GNUNET_MQ_hd_var_size (union_p2p_full_element, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, - struct GNUNET_SET_ElementMessage, + GNUNET_MQ_hd_var_size(union_p2p_strata_estimator, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, + struct StrataEstimatorMessage, + NULL), + GNUNET_MQ_hd_var_size(union_p2p_strata_estimator, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, + struct StrataEstimatorMessage, + NULL), + GNUNET_MQ_hd_var_size(union_p2p_full_element, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, + struct GNUNET_SET_ElementMessage, + NULL), + GNUNET_MQ_hd_fixed_size(intersection_p2p_element_info, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, + struct IntersectionElementInfoMessage, NULL), - GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, - struct IntersectionElementInfoMessage, - NULL), - GNUNET_MQ_hd_var_size (intersection_p2p_bf, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, - struct BFMessage, + GNUNET_MQ_hd_var_size(intersection_p2p_bf, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, + struct BFMessage, + NULL), + GNUNET_MQ_hd_fixed_size(intersection_p2p_done, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, + struct IntersectionDoneMessage, NULL), - GNUNET_MQ_hd_fixed_size (intersection_p2p_done, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, - struct IntersectionDoneMessage, - NULL), - GNUNET_MQ_handler_end ()}; + GNUNET_MQ_handler_end() }; struct Listener *listener; if (NULL != cs->listener) - { - /* max. one active listener per client! */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } - listener = GNUNET_new (struct Listener); + { + /* max. one active listener per client! */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } + listener = GNUNET_new(struct Listener); listener->cs = cs; cs->listener = listener; listener->app_id = msg->app_id; - listener->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation); - GNUNET_CONTAINER_DLL_insert (listener_head, listener_tail, listener); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "New listener created (op %u, port %s)\n", - listener->operation, - GNUNET_h2s (&listener->app_id)); - listener->open_port = GNUNET_CADET_open_port (cadet, - &msg->app_id, - &channel_new_cb, - listener, - &channel_window_cb, - &channel_end_cb, - cadet_handlers); - GNUNET_SERVICE_client_continue (cs->client); + listener->operation = (enum GNUNET_SET_OperationType)ntohl(msg->operation); + GNUNET_CONTAINER_DLL_insert(listener_head, listener_tail, listener); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "New listener created (op %u, port %s)\n", + listener->operation, + GNUNET_h2s(&listener->app_id)); + listener->open_port = GNUNET_CADET_open_port(cadet, + &msg->app_id, + &channel_new_cb, + listener, + &channel_window_cb, + &channel_end_cb, + cadet_handlers); + GNUNET_SERVICE_client_continue(cs->client); } @@ -1309,28 +1310,28 @@ handle_client_listen (void *cls, const struct GNUNET_SET_ListenMessage *msg) * @param msg message sent by the client */ static void -handle_client_reject (void *cls, const struct GNUNET_SET_RejectMessage *msg) +handle_client_reject(void *cls, const struct GNUNET_SET_RejectMessage *msg) { struct ClientState *cs = cls; struct Operation *op; - op = get_incoming (ntohl (msg->accept_reject_id)); + op = get_incoming(ntohl(msg->accept_reject_id)); if (NULL == op) - { - /* no matching incoming operation for this reject; - could be that the other peer already disconnected... */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Client rejected unknown operation %u\n", - (unsigned int) ntohl (msg->accept_reject_id)); - GNUNET_SERVICE_client_continue (cs->client); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer request (op %u, app %s) rejected by client\n", - op->listener->operation, - GNUNET_h2s (&cs->listener->app_id)); - _GSS_operation_destroy2 (op); - GNUNET_SERVICE_client_continue (cs->client); + { + /* no matching incoming operation for this reject; + could be that the other peer already disconnected... */ + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Client rejected unknown operation %u\n", + (unsigned int)ntohl(msg->accept_reject_id)); + GNUNET_SERVICE_client_continue(cs->client); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Peer request (op %u, app %s) rejected by client\n", + op->listener->operation, + GNUNET_h2s(&cs->listener->app_id)); + _GSS_operation_destroy2(op); + GNUNET_SERVICE_client_continue(cs->client); } @@ -1341,7 +1342,7 @@ handle_client_reject (void *cls, const struct GNUNET_SET_RejectMessage *msg) * @param msg message sent by the client */ static int -check_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg) +check_client_mutation(void *cls, const struct GNUNET_SET_ElementMessage *msg) { /* NOTE: Technically, we should probably check with the block library whether the element we are given is well-formed */ @@ -1356,36 +1357,36 @@ check_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg) * @param msg message sent by the client */ static void -handle_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg) +handle_client_mutation(void *cls, const struct GNUNET_SET_ElementMessage *msg) { struct ClientState *cs = cls; struct Set *set; if (NULL == (set = cs->set)) - { - /* client without a set requested an operation */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } - GNUNET_SERVICE_client_continue (cs->client); + { + /* client without a set requested an operation */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } + GNUNET_SERVICE_client_continue(cs->client); if (0 != set->content->iterator_count) - { - struct PendingMutation *pm; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduling mutation on set\n"); - pm = GNUNET_new (struct PendingMutation); - pm->msg = - (struct GNUNET_SET_ElementMessage *) GNUNET_copy_message (&msg->header); - pm->set = set; - GNUNET_CONTAINER_DLL_insert_tail (set->content->pending_mutations_head, - set->content->pending_mutations_tail, - pm); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing mutation on set\n"); - execute_mutation (set, msg); + { + struct PendingMutation *pm; + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling mutation on set\n"); + pm = GNUNET_new(struct PendingMutation); + pm->msg = + (struct GNUNET_SET_ElementMessage *)GNUNET_copy_message(&msg->header); + pm->set = set; + GNUNET_CONTAINER_DLL_insert_tail(set->content->pending_mutations_head, + set->content->pending_mutations_tail, + pm); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing mutation on set\n"); + execute_mutation(set, msg); } @@ -1396,26 +1397,26 @@ handle_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg) * @param set the set where we want to advance the generation */ static void -advance_generation (struct Set *set) +advance_generation(struct Set *set) { struct GenerationRange r; if (set->current_generation == set->content->latest_generation) - { - set->content->latest_generation++; - set->current_generation++; - return; - } + { + set->content->latest_generation++; + set->current_generation++; + return; + } - GNUNET_assert (set->current_generation < set->content->latest_generation); + GNUNET_assert(set->current_generation < set->content->latest_generation); r.start = set->current_generation + 1; r.end = set->content->latest_generation + 1; set->content->latest_generation = r.end; set->current_generation = r.end; - GNUNET_array_append (set->excluded_generations, - set->excluded_generations_size, - r); + GNUNET_array_append(set->excluded_generations, + set->excluded_generations_size, + r); } @@ -1429,7 +1430,7 @@ advance_generation (struct Set *set) * @return #GNUNET_OK if the message is well-formed */ static int -check_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg) +check_client_evaluate(void *cls, const struct GNUNET_SET_EvaluateMessage *msg) { /* FIXME: suboptimal, even if the context below could be NULL, there are malformed messages this does not check for... */ @@ -1446,122 +1447,122 @@ check_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg) * @param msg message sent by the client */ static void -handle_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg) +handle_client_evaluate(void *cls, const struct GNUNET_SET_EvaluateMessage *msg) { struct ClientState *cs = cls; - struct Operation *op = GNUNET_new (struct Operation); + struct Operation *op = GNUNET_new(struct Operation); const struct GNUNET_MQ_MessageHandler cadet_handlers[] = - {GNUNET_MQ_hd_var_size (incoming_msg, - GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, - struct OperationRequestMessage, - op), - GNUNET_MQ_hd_var_size (union_p2p_ibf, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, - struct IBFMessage, - op), - GNUNET_MQ_hd_var_size (union_p2p_elements, - GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, - struct GNUNET_SET_ElementMessage, - op), - GNUNET_MQ_hd_var_size (union_p2p_offer, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, + { GNUNET_MQ_hd_var_size(incoming_msg, + GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, + struct OperationRequestMessage, + op), + GNUNET_MQ_hd_var_size(union_p2p_ibf, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, + struct IBFMessage, + op), + GNUNET_MQ_hd_var_size(union_p2p_elements, + GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, + struct GNUNET_SET_ElementMessage, + op), + GNUNET_MQ_hd_var_size(union_p2p_offer, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, + struct GNUNET_MessageHeader, + op), + GNUNET_MQ_hd_var_size(union_p2p_inquiry, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, + struct InquiryMessage, + op), + GNUNET_MQ_hd_var_size(union_p2p_demand, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, + struct GNUNET_MessageHeader, + op), + GNUNET_MQ_hd_fixed_size(union_p2p_done, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, struct GNUNET_MessageHeader, op), - GNUNET_MQ_hd_var_size (union_p2p_inquiry, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, - struct InquiryMessage, - op), - GNUNET_MQ_hd_var_size (union_p2p_demand, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, + GNUNET_MQ_hd_fixed_size(union_p2p_over, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, struct GNUNET_MessageHeader, op), - GNUNET_MQ_hd_fixed_size (union_p2p_done, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, - struct GNUNET_MessageHeader, - op), - GNUNET_MQ_hd_fixed_size (union_p2p_over, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, - struct GNUNET_MessageHeader, - op), - GNUNET_MQ_hd_fixed_size (union_p2p_full_done, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, - struct GNUNET_MessageHeader, - op), - GNUNET_MQ_hd_fixed_size (union_p2p_request_full, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, - struct GNUNET_MessageHeader, - op), - GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, - struct StrataEstimatorMessage, + GNUNET_MQ_hd_fixed_size(union_p2p_full_done, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, + struct GNUNET_MessageHeader, op), - GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, - struct StrataEstimatorMessage, + GNUNET_MQ_hd_fixed_size(union_p2p_request_full, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, + struct GNUNET_MessageHeader, op), - GNUNET_MQ_hd_var_size (union_p2p_full_element, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, - struct GNUNET_SET_ElementMessage, + GNUNET_MQ_hd_var_size(union_p2p_strata_estimator, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, + struct StrataEstimatorMessage, + op), + GNUNET_MQ_hd_var_size(union_p2p_strata_estimator, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, + struct StrataEstimatorMessage, + op), + GNUNET_MQ_hd_var_size(union_p2p_full_element, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, + struct GNUNET_SET_ElementMessage, + op), + GNUNET_MQ_hd_fixed_size(intersection_p2p_element_info, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, + struct IntersectionElementInfoMessage, op), - GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, - struct IntersectionElementInfoMessage, - op), - GNUNET_MQ_hd_var_size (intersection_p2p_bf, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, - struct BFMessage, + GNUNET_MQ_hd_var_size(intersection_p2p_bf, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, + struct BFMessage, + op), + GNUNET_MQ_hd_fixed_size(intersection_p2p_done, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, + struct IntersectionDoneMessage, op), - GNUNET_MQ_hd_fixed_size (intersection_p2p_done, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, - struct IntersectionDoneMessage, - op), - GNUNET_MQ_handler_end ()}; + GNUNET_MQ_handler_end() }; struct Set *set; const struct GNUNET_MessageHeader *context; if (NULL == (set = cs->set)) - { - GNUNET_break (0); - GNUNET_free (op); - GNUNET_SERVICE_client_drop (cs->client); - return; - } - op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); + { + GNUNET_break(0); + GNUNET_free(op); + GNUNET_SERVICE_client_drop(cs->client); + return; + } + op->salt = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); op->peer = msg->target_peer; - op->result_mode = ntohl (msg->result_mode); - op->client_request_id = ntohl (msg->request_id); + op->result_mode = ntohl(msg->result_mode); + op->client_request_id = ntohl(msg->request_id); op->byzantine = msg->byzantine; op->byzantine_lower_bound = msg->byzantine_lower_bound; op->force_full = msg->force_full; op->force_delta = msg->force_delta; - context = GNUNET_MQ_extract_nested_mh (msg); + context = GNUNET_MQ_extract_nested_mh(msg); /* Advance generation values, so that mutations won't interfer with the running operation. */ op->set = set; op->generation_created = set->current_generation; - advance_generation (set); - GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating new CADET channel to port %s for set operation type %u\n", - GNUNET_h2s (&msg->app_id), - set->operation); - op->channel = GNUNET_CADET_channel_create (cadet, - op, - &msg->target_peer, - &msg->app_id, - &channel_window_cb, - &channel_end_cb, - cadet_handlers); - op->mq = GNUNET_CADET_get_mq (op->channel); - op->state = set->vt->evaluate (op, context); + advance_generation(set); + GNUNET_CONTAINER_DLL_insert(set->ops_head, set->ops_tail, op); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Creating new CADET channel to port %s for set operation type %u\n", + GNUNET_h2s(&msg->app_id), + set->operation); + op->channel = GNUNET_CADET_channel_create(cadet, + op, + &msg->target_peer, + &msg->app_id, + &channel_window_cb, + &channel_end_cb, + cadet_handlers); + op->mq = GNUNET_CADET_get_mq(op->channel); + op->state = set->vt->evaluate(op, context); if (NULL == op->state) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } - GNUNET_SERVICE_client_continue (cs->client); + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } + GNUNET_SERVICE_client_continue(cs->client); } @@ -1574,37 +1575,37 @@ handle_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg) * @param ack the message */ static void -handle_client_iter_ack (void *cls, const struct GNUNET_SET_IterAckMessage *ack) +handle_client_iter_ack(void *cls, const struct GNUNET_SET_IterAckMessage *ack) { struct ClientState *cs = cls; struct Set *set; if (NULL == (set = cs->set)) - { - /* client without a set acknowledged receiving a value */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } + { + /* client without a set acknowledged receiving a value */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } if (NULL == set->iter) - { - /* client sent an ack, but we were not expecting one (as - set iteration has finished) */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } - GNUNET_SERVICE_client_continue (cs->client); - if (ntohl (ack->send_more)) - { - send_client_element (set); - } + { + /* client sent an ack, but we were not expecting one (as + set iteration has finished) */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } + GNUNET_SERVICE_client_continue(cs->client); + if (ntohl(ack->send_more)) + { + send_client_element(set); + } else - { - GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter); - set->iter = NULL; - set->iteration_id++; - } + { + GNUNET_CONTAINER_multihashmap_iterator_destroy(set->iter); + set->iter = NULL; + set->iteration_id++; + } } @@ -1615,8 +1616,8 @@ handle_client_iter_ack (void *cls, const struct GNUNET_SET_IterAckMessage *ack) * @param mh the message */ static void -handle_client_copy_lazy_prepare (void *cls, - const struct GNUNET_MessageHeader *mh) +handle_client_copy_lazy_prepare(void *cls, + const struct GNUNET_MessageHeader *mh) { struct ClientState *cs = cls; struct Set *set; @@ -1625,22 +1626,22 @@ handle_client_copy_lazy_prepare (void *cls, struct GNUNET_SET_CopyLazyResponseMessage *resp_msg; if (NULL == (set = cs->set)) - { - /* client without a set requested an operation */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client requested creation of lazy copy\n"); - cr = GNUNET_new (struct LazyCopyRequest); + { + /* client without a set requested an operation */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Client requested creation of lazy copy\n"); + cr = GNUNET_new(struct LazyCopyRequest); cr->cookie = ++lazy_copy_cookie; cr->source_set = set; - GNUNET_CONTAINER_DLL_insert (lazy_copy_head, lazy_copy_tail, cr); - ev = GNUNET_MQ_msg (resp_msg, GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE); + GNUNET_CONTAINER_DLL_insert(lazy_copy_head, lazy_copy_tail, cr); + ev = GNUNET_MQ_msg(resp_msg, GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE); resp_msg->cookie = cr->cookie; - GNUNET_MQ_send (set->cs->mq, ev); - GNUNET_SERVICE_client_continue (cs->client); + GNUNET_MQ_send(set->cs->mq, ev); + GNUNET_SERVICE_client_continue(cs->client); } @@ -1651,7 +1652,7 @@ handle_client_copy_lazy_prepare (void *cls, * @param msg the message */ static void -handle_client_copy_lazy_connect ( +handle_client_copy_lazy_connect( void *cls, const struct GNUNET_SET_CopyLazyConnectMessage *msg) { @@ -1661,75 +1662,77 @@ handle_client_copy_lazy_connect ( int found; if (NULL != cs->set) - { - /* There can only be one set per client */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } + { + /* There can only be one set per client */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } found = GNUNET_NO; for (cr = lazy_copy_head; NULL != cr; cr = cr->next) - { - if (cr->cookie == msg->cookie) { - found = GNUNET_YES; - break; + if (cr->cookie == msg->cookie) + { + found = GNUNET_YES; + break; + } } - } if (GNUNET_NO == found) - { - /* client asked for copy with cookie we don't know */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } - GNUNET_CONTAINER_DLL_remove (lazy_copy_head, lazy_copy_tail, cr); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client %p requested use of lazy copy\n", - cs); - set = GNUNET_new (struct Set); + { + /* client asked for copy with cookie we don't know */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } + GNUNET_CONTAINER_DLL_remove(lazy_copy_head, lazy_copy_tail, cr); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Client %p requested use of lazy copy\n", + cs); + set = GNUNET_new(struct Set); switch (cr->source_set->operation) - { - case GNUNET_SET_OPERATION_INTERSECTION: - set->vt = _GSS_intersection_vt (); - break; - case GNUNET_SET_OPERATION_UNION: - set->vt = _GSS_union_vt (); - break; - default: - GNUNET_assert (0); - return; - } + { + case GNUNET_SET_OPERATION_INTERSECTION: + set->vt = _GSS_intersection_vt(); + break; + + case GNUNET_SET_OPERATION_UNION: + set->vt = _GSS_union_vt(); + break; + + default: + GNUNET_assert(0); + return; + } if (NULL == set->vt->copy_state) - { - /* Lazy copy not supported for this set operation */ - GNUNET_break (0); - GNUNET_free (set); - GNUNET_free (cr); - GNUNET_SERVICE_client_drop (cs->client); - return; - } + { + /* Lazy copy not supported for this set operation */ + GNUNET_break(0); + GNUNET_free(set); + GNUNET_free(cr); + GNUNET_SERVICE_client_drop(cs->client); + return; + } set->operation = cr->source_set->operation; - set->state = set->vt->copy_state (cr->source_set->state); + set->state = set->vt->copy_state(cr->source_set->state); set->content = cr->source_set->content; set->content->refcount++; set->current_generation = cr->source_set->current_generation; set->excluded_generations_size = cr->source_set->excluded_generations_size; set->excluded_generations = - GNUNET_memdup (cr->source_set->excluded_generations, - set->excluded_generations_size * - sizeof (struct GenerationRange)); + GNUNET_memdup(cr->source_set->excluded_generations, + set->excluded_generations_size * + sizeof(struct GenerationRange)); /* Advance the generation of the new set, so that mutations to the of the cloned set and the source set are independent. */ - advance_generation (set); + advance_generation(set); set->cs = cs; cs->set = set; - GNUNET_free (cr); - GNUNET_SERVICE_client_continue (cs->client); + GNUNET_free(cr); + GNUNET_SERVICE_client_continue(cs->client); } @@ -1740,7 +1743,7 @@ handle_client_copy_lazy_connect ( * @param msg the message */ static void -handle_client_cancel (void *cls, const struct GNUNET_SET_CancelMessage *msg) +handle_client_cancel(void *cls, const struct GNUNET_SET_CancelMessage *msg) { struct ClientState *cs = cls; struct Set *set; @@ -1748,40 +1751,40 @@ handle_client_cancel (void *cls, const struct GNUNET_SET_CancelMessage *msg) int found; if (NULL == (set = cs->set)) - { - /* client without a set requested an operation */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } + { + /* client without a set requested an operation */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } found = GNUNET_NO; for (op = set->ops_head; NULL != op; op = op->next) - { - if (op->client_request_id == ntohl (msg->request_id)) { - found = GNUNET_YES; - break; + if (op->client_request_id == ntohl(msg->request_id)) + { + found = GNUNET_YES; + break; + } } - } if (GNUNET_NO == found) - { - /* It may happen that the operation was already destroyed due to - * the other peer disconnecting. The client may not know about this - * yet and try to cancel the (just barely non-existent) operation. - * So this is not a hard error. - */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Client canceled non-existent op %u\n", - (uint32_t) ntohl (msg->request_id)); - } + { + /* It may happen that the operation was already destroyed due to + * the other peer disconnecting. The client may not know about this + * yet and try to cancel the (just barely non-existent) operation. + * So this is not a hard error. + */ + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Client canceled non-existent op %u\n", + (uint32_t)ntohl(msg->request_id)); + } else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client requested cancel for op %u\n", - (uint32_t) ntohl (msg->request_id)); - _GSS_operation_destroy (op, GNUNET_YES); - } - GNUNET_SERVICE_client_continue (cs->client); + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Client requested cancel for op %u\n", + (uint32_t)ntohl(msg->request_id)); + _GSS_operation_destroy(op, GNUNET_YES); + } + GNUNET_SERVICE_client_continue(cs->client); } @@ -1794,7 +1797,7 @@ handle_client_cancel (void *cls, const struct GNUNET_SET_CancelMessage *msg) * @param msg the message */ static void -handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg) +handle_client_accept(void *cls, const struct GNUNET_SET_AcceptMessage *msg) { struct ClientState *cs = cls; struct Set *set; @@ -1804,40 +1807,40 @@ handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg) struct Listener *listener; if (NULL == (set = cs->set)) - { - /* client without a set requested to accept */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } - op = get_incoming (ntohl (msg->accept_reject_id)); + { + /* client without a set requested to accept */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } + op = get_incoming(ntohl(msg->accept_reject_id)); if (NULL == op) - { - /* It is not an error if the set op does not exist -- it may - * have been destroyed when the partner peer disconnected. */ - GNUNET_log ( - GNUNET_ERROR_TYPE_INFO, - "Client %p accepted request %u of listener %p that is no longer active\n", - cs, - ntohl (msg->accept_reject_id), - cs->listener); - ev = GNUNET_MQ_msg (result_message, GNUNET_MESSAGE_TYPE_SET_RESULT); - result_message->request_id = msg->request_id; - result_message->result_status = htons (GNUNET_SET_STATUS_FAILURE); - GNUNET_MQ_send (set->cs->mq, ev); - GNUNET_SERVICE_client_continue (cs->client); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client accepting request %u\n", - (uint32_t) ntohl (msg->accept_reject_id)); + { + /* It is not an error if the set op does not exist -- it may + * have been destroyed when the partner peer disconnected. */ + GNUNET_log( + GNUNET_ERROR_TYPE_INFO, + "Client %p accepted request %u of listener %p that is no longer active\n", + cs, + ntohl(msg->accept_reject_id), + cs->listener); + ev = GNUNET_MQ_msg(result_message, GNUNET_MESSAGE_TYPE_SET_RESULT); + result_message->request_id = msg->request_id; + result_message->result_status = htons(GNUNET_SET_STATUS_FAILURE); + GNUNET_MQ_send(set->cs->mq, ev); + GNUNET_SERVICE_client_continue(cs->client); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Client accepting request %u\n", + (uint32_t)ntohl(msg->accept_reject_id)); listener = op->listener; op->listener = NULL; - GNUNET_CONTAINER_DLL_remove (listener->op_head, listener->op_tail, op); + GNUNET_CONTAINER_DLL_remove(listener->op_head, listener->op_tail, op); op->set = set; - GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op); - op->client_request_id = ntohl (msg->request_id); - op->result_mode = ntohl (msg->result_mode); + GNUNET_CONTAINER_DLL_insert(set->ops_head, set->ops_tail, op); + op->client_request_id = ntohl(msg->request_id); + op->result_mode = ntohl(msg->result_mode); op->byzantine = msg->byzantine; op->byzantine_lower_bound = msg->byzantine_lower_bound; op->force_full = msg->force_full; @@ -1846,20 +1849,20 @@ handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg) /* Advance generation values, so that future mutations do not interfer with the running operation. */ op->generation_created = set->current_generation; - advance_generation (set); - GNUNET_assert (NULL == op->state); - op->state = set->vt->accept (op); + advance_generation(set); + GNUNET_assert(NULL == op->state); + op->state = set->vt->accept(op); if (NULL == op->state) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cs->client); - return; - } + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cs->client); + return; + } /* Now allow CADET to continue, as we did not do this in - #handle_incoming_msg (as we wanted to first see if the + #handle_incoming_msg (as we wanted to first see if the local client would accept the request). */ - GNUNET_CADET_receive_done (op->channel); - GNUNET_SERVICE_client_continue (cs->client); + GNUNET_CADET_receive_done(op->channel); + GNUNET_SERVICE_client_continue(cs->client); } @@ -1869,20 +1872,20 @@ handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg) * @param cls closure, NULL */ static void -shutdown_task (void *cls) +shutdown_task(void *cls) { /* Delay actual shutdown to allow service to disconnect clients */ in_shutdown = GNUNET_YES; if (0 == num_clients) - { - if (NULL != cadet) { - GNUNET_CADET_disconnect (cadet); - cadet = NULL; + if (NULL != cadet) + { + GNUNET_CADET_disconnect(cadet); + cadet = NULL; + } } - } - GNUNET_STATISTICS_destroy (_GSS_statistics, GNUNET_YES); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handled shutdown request\n"); + GNUNET_STATISTICS_destroy(_GSS_statistics, GNUNET_YES); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "handled shutdown request\n"); } @@ -1895,85 +1898,85 @@ shutdown_task (void *cls) * @param service the initialized service */ static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_SERVICE_Handle *service) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_SERVICE_Handle *service) { /* FIXME: need to modify SERVICE (!) API to allow us to run a shutdown task *after* clients were forcefully disconnected! */ - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); - _GSS_statistics = GNUNET_STATISTICS_create ("set", cfg); - cadet = GNUNET_CADET_connect (cfg); + GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); + _GSS_statistics = GNUNET_STATISTICS_create("set", cfg); + cadet = GNUNET_CADET_connect(cfg); if (NULL == cadet) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Could not connect to CADET service\n")); - GNUNET_SCHEDULER_shutdown (); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Could not connect to CADET service\n")); + GNUNET_SCHEDULER_shutdown(); + return; + } } /** * Define "main" method using service macro. */ -GNUNET_SERVICE_MAIN ( +GNUNET_SERVICE_MAIN( "set", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, - GNUNET_MQ_hd_fixed_size (client_accept, - GNUNET_MESSAGE_TYPE_SET_ACCEPT, - struct GNUNET_SET_AcceptMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_iter_ack, - GNUNET_MESSAGE_TYPE_SET_ITER_ACK, - struct GNUNET_SET_IterAckMessage, - NULL), - GNUNET_MQ_hd_var_size (client_mutation, - GNUNET_MESSAGE_TYPE_SET_ADD, - struct GNUNET_SET_ElementMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_create_set, - GNUNET_MESSAGE_TYPE_SET_CREATE, - struct GNUNET_SET_CreateMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_iterate, - GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_var_size (client_evaluate, - GNUNET_MESSAGE_TYPE_SET_EVALUATE, - struct GNUNET_SET_EvaluateMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_listen, - GNUNET_MESSAGE_TYPE_SET_LISTEN, - struct GNUNET_SET_ListenMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_reject, - GNUNET_MESSAGE_TYPE_SET_REJECT, - struct GNUNET_SET_RejectMessage, - NULL), - GNUNET_MQ_hd_var_size (client_mutation, - GNUNET_MESSAGE_TYPE_SET_REMOVE, - struct GNUNET_SET_ElementMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_cancel, - GNUNET_MESSAGE_TYPE_SET_CANCEL, - struct GNUNET_SET_CancelMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_copy_lazy_prepare, - GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size (client_copy_lazy_connect, - GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT, - struct GNUNET_SET_CopyLazyConnectMessage, - NULL), - GNUNET_MQ_handler_end ()); + GNUNET_MQ_hd_fixed_size(client_accept, + GNUNET_MESSAGE_TYPE_SET_ACCEPT, + struct GNUNET_SET_AcceptMessage, + NULL), + GNUNET_MQ_hd_fixed_size(client_iter_ack, + GNUNET_MESSAGE_TYPE_SET_ITER_ACK, + struct GNUNET_SET_IterAckMessage, + NULL), + GNUNET_MQ_hd_var_size(client_mutation, + GNUNET_MESSAGE_TYPE_SET_ADD, + struct GNUNET_SET_ElementMessage, + NULL), + GNUNET_MQ_hd_fixed_size(client_create_set, + GNUNET_MESSAGE_TYPE_SET_CREATE, + struct GNUNET_SET_CreateMessage, + NULL), + GNUNET_MQ_hd_fixed_size(client_iterate, + GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_var_size(client_evaluate, + GNUNET_MESSAGE_TYPE_SET_EVALUATE, + struct GNUNET_SET_EvaluateMessage, + NULL), + GNUNET_MQ_hd_fixed_size(client_listen, + GNUNET_MESSAGE_TYPE_SET_LISTEN, + struct GNUNET_SET_ListenMessage, + NULL), + GNUNET_MQ_hd_fixed_size(client_reject, + GNUNET_MESSAGE_TYPE_SET_REJECT, + struct GNUNET_SET_RejectMessage, + NULL), + GNUNET_MQ_hd_var_size(client_mutation, + GNUNET_MESSAGE_TYPE_SET_REMOVE, + struct GNUNET_SET_ElementMessage, + NULL), + GNUNET_MQ_hd_fixed_size(client_cancel, + GNUNET_MESSAGE_TYPE_SET_CANCEL, + struct GNUNET_SET_CancelMessage, + NULL), + GNUNET_MQ_hd_fixed_size(client_copy_lazy_prepare, + GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_fixed_size(client_copy_lazy_connect, + GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT, + struct GNUNET_SET_CopyLazyConnectMessage, + NULL), + GNUNET_MQ_handler_end()); /* end of gnunet-service-set.c */ diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h index c39c68d21..2234a5c72 100644 --- a/src/set/gnunet-service-set.h +++ b/src/set/gnunet-service-set.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/gnunet-service-set.h * @brief common components for the implementation the different set operations @@ -86,7 +86,7 @@ typedef struct SetState * */ typedef void (*SetAddRemoveImpl) (struct SetState *state, - struct ElementEntry *ee); + struct ElementEntry *ee); /** @@ -159,8 +159,7 @@ typedef void * Dispatch table for a specific set operation. Every set operation * has to implement the callback in this struct. */ -struct SetVT -{ +struct SetVT { /** * Callback for the set creation. */ @@ -205,7 +204,6 @@ struct SetVT * Callback called in case the CADET channel died. */ OpChannelDeathImpl channel_death; - }; @@ -213,8 +211,7 @@ struct SetVT * MutationEvent gives information about changes * to an element (removal / addition) in a set content. */ -struct MutationEvent -{ +struct MutationEvent { /** * First generation affected by this mutation event. * @@ -237,8 +234,7 @@ struct MutationEvent * Element`, so that the remove and add operations are reasonably * fast. */ -struct ElementEntry -{ +struct ElementEntry { /** * The actual element. The data for the element * should be allocated at the end of this struct. @@ -285,8 +281,7 @@ struct Listener; /** * State we keep per client. */ -struct ClientState -{ +struct ClientState { /** * Set, if associated with the client, otherwise NULL. */ @@ -306,16 +301,13 @@ struct ClientState * Message queue. */ struct GNUNET_MQ_Handle *mq; - }; /** * Operation context used to execute a set operation. */ -struct Operation -{ - +struct Operation { /** * Kept in a DLL of the listener, if @e listener is non-NULL. */ @@ -427,7 +419,6 @@ struct Operation * was created. */ unsigned int generation_created; - }; @@ -435,9 +426,7 @@ struct Operation * SetContent stores the actual set elements, which may be shared by * multiple generations derived from one set. */ -struct SetContent -{ - +struct SetContent { /** * Maps `struct GNUNET_HashCode *` to `struct ElementEntry *`. */ @@ -474,8 +463,7 @@ struct SetContent }; -struct GenerationRange -{ +struct GenerationRange { /** * First generation that is excluded. */ @@ -491,8 +479,7 @@ struct GenerationRange /** * Information about a mutation to apply to a set. */ -struct PendingMutation -{ +struct PendingMutation { /** * Mutations are kept in a DLL. */ @@ -520,9 +507,7 @@ struct PendingMutation /** * A set that supports a specific operation with other peers. */ -struct Set -{ - +struct Set { /** * Sets are held in a doubly linked list (in `sets_head` and `sets_tail`). */ @@ -606,7 +591,6 @@ struct Set * can distinguish iterations. */ uint16_t iteration_id; - }; @@ -627,8 +611,8 @@ extern struct GNUNET_STATISTICS_Handle *_GSS_statistics; * @param gc #GNUNET_YES to perform garbage collection on the set */ void -_GSS_operation_destroy (struct Operation *op, - int gc); +_GSS_operation_destroy(struct Operation *op, + int gc); /** @@ -637,7 +621,7 @@ _GSS_operation_destroy (struct Operation *op, * logic in the various places where it is called. */ void -_GSS_operation_destroy2 (struct Operation *op); +_GSS_operation_destroy2(struct Operation *op); /** @@ -646,7 +630,7 @@ _GSS_operation_destroy2 (struct Operation *op); * @return the operation specific VTable */ const struct SetVT * -_GSS_union_vt (void); +_GSS_union_vt(void); /** @@ -655,7 +639,7 @@ _GSS_union_vt (void); * @return the operation specific VTable */ const struct SetVT * -_GSS_intersection_vt (void); +_GSS_intersection_vt(void); /** @@ -666,8 +650,8 @@ _GSS_intersection_vt (void); * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not */ int -_GSS_is_element_of_operation (struct ElementEntry *ee, - struct Operation *op); +_GSS_is_element_of_operation(struct ElementEntry *ee, + struct Operation *op); #endif diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c index e1bbcc152..964a26b91 100644 --- a/src/set/gnunet-service-set_intersection.c +++ b/src/set/gnunet-service-set_intersection.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/gnunet-service-set_intersection.c * @brief two-peer set intersection @@ -36,8 +36,7 @@ /** * Current phase we are in for a intersection operation. */ -enum IntersectionOperationPhase -{ +enum IntersectionOperationPhase { /** * We are just starting. */ @@ -73,15 +72,13 @@ enum IntersectionOperationPhase * client. */ PHASE_FINISHED - }; /** * State of an evaluate operation with another peer. */ -struct OperationState -{ +struct OperationState { /** * The bf we currently receive */ @@ -189,8 +186,7 @@ struct OperationState * Extra state required for efficient set intersection. * Merely tracks the total number of elements. */ -struct SetState -{ +struct SetState { /** * Number of currently valid elements in the set which have not been * removed. @@ -207,38 +203,38 @@ struct SetState * @param element element to send */ static void -send_client_removed_element (struct Operation *op, - struct GNUNET_SET_Element *element) +send_client_removed_element(struct Operation *op, + struct GNUNET_SET_Element *element) { struct GNUNET_MQ_Envelope *ev; struct GNUNET_SET_ResultMessage *rm; if (GNUNET_SET_RESULT_REMOVED != op->result_mode) return; /* Wrong mode for transmitting removed elements */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending removed element (size %u) to client\n", - element->size); - GNUNET_STATISTICS_update (_GSS_statistics, - "# Element removed messages sent", - 1, - GNUNET_NO); - GNUNET_assert (0 != op->client_request_id); - ev = GNUNET_MQ_msg_extra (rm, - element->size, - GNUNET_MESSAGE_TYPE_SET_RESULT); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending removed element (size %u) to client\n", + element->size); + GNUNET_STATISTICS_update(_GSS_statistics, + "# Element removed messages sent", + 1, + GNUNET_NO); + GNUNET_assert(0 != op->client_request_id); + ev = GNUNET_MQ_msg_extra(rm, + element->size, + GNUNET_MESSAGE_TYPE_SET_RESULT); if (NULL == ev) - { - GNUNET_break (0); - return; - } - rm->result_status = htons (GNUNET_SET_STATUS_OK); - rm->request_id = htonl (op->client_request_id); + { + GNUNET_break(0); + return; + } + rm->result_status = htons(GNUNET_SET_STATUS_OK); + rm->request_id = htonl(op->client_request_id); rm->element_type = element->element_type; - GNUNET_memcpy (&rm[1], - element->data, - element->size); - GNUNET_MQ_send (op->set->cs->mq, - ev); + GNUNET_memcpy(&rm[1], + element->data, + element->size); + GNUNET_MQ_send(op->set->cs->mq, + ev); } @@ -251,63 +247,63 @@ send_client_removed_element (struct Operation *op, * @return #GNUNET_YES (we should continue to iterate) */ static int -filtered_map_initialization (void *cls, - const struct GNUNET_HashCode *key, - void *value) +filtered_map_initialization(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct Operation *op = cls; struct ElementEntry *ee = value; struct GNUNET_HashCode mutated_hash; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "FIMA called for %s:%u\n", - GNUNET_h2s (&ee->element_hash), - ee->element.size); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "FIMA called for %s:%u\n", + GNUNET_h2s(&ee->element_hash), + ee->element.size); - if (GNUNET_NO == _GSS_is_element_of_operation (ee, op)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Reduced initialization, not starting with %s:%u (wrong generation)\n", - GNUNET_h2s (&ee->element_hash), - ee->element.size); - return GNUNET_YES; /* element not valid in our operation's generation */ - } + if (GNUNET_NO == _GSS_is_element_of_operation(ee, op)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Reduced initialization, not starting with %s:%u (wrong generation)\n", + GNUNET_h2s(&ee->element_hash), + ee->element.size); + return GNUNET_YES; /* element not valid in our operation's generation */ + } /* Test if element is in other peer's bloomfilter */ - GNUNET_BLOCK_mingle_hash (&ee->element_hash, - op->state->salt, - &mutated_hash); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Testing mingled hash %s with salt %u\n", - GNUNET_h2s (&mutated_hash), - op->state->salt); + GNUNET_BLOCK_mingle_hash(&ee->element_hash, + op->state->salt, + &mutated_hash); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Testing mingled hash %s with salt %u\n", + GNUNET_h2s(&mutated_hash), + op->state->salt); if (GNUNET_NO == - GNUNET_CONTAINER_bloomfilter_test (op->state->remote_bf, - &mutated_hash)) - { - /* remove this element */ - send_client_removed_element (op, - &ee->element); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Reduced initialization, not starting with %s:%u\n", - GNUNET_h2s (&ee->element_hash), - ee->element.size); - return GNUNET_YES; - } + GNUNET_CONTAINER_bloomfilter_test(op->state->remote_bf, + &mutated_hash)) + { + /* remove this element */ + send_client_removed_element(op, + &ee->element); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Reduced initialization, not starting with %s:%u\n", + GNUNET_h2s(&ee->element_hash), + ee->element.size); + return GNUNET_YES; + } op->state->my_element_count++; - GNUNET_CRYPTO_hash_xor (&op->state->my_xor, - &ee->element_hash, - &op->state->my_xor); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Filtered initialization of my_elements, adding %s:%u\n", - GNUNET_h2s (&ee->element_hash), - ee->element.size); - GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_put (op->state->my_elements, - &ee->element_hash, - ee, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CRYPTO_hash_xor(&op->state->my_xor, + &ee->element_hash, + &op->state->my_xor); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Filtered initialization of my_elements, adding %s:%u\n", + GNUNET_h2s(&ee->element_hash), + ee->element.size); + GNUNET_break(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_put(op->state->my_elements, + &ee->element_hash, + ee, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); return GNUNET_YES; } @@ -323,7 +319,7 @@ filtered_map_initialization (void *cls, * @return #GNUNET_YES (we should continue to iterate) */ static int -iterator_bf_reduce (void *cls, +iterator_bf_reduce(void *cls, const struct GNUNET_HashCode *key, void *value) { @@ -331,40 +327,40 @@ iterator_bf_reduce (void *cls, struct ElementEntry *ee = value; struct GNUNET_HashCode mutated_hash; - GNUNET_BLOCK_mingle_hash (&ee->element_hash, - op->state->salt, - &mutated_hash); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Testing mingled hash %s with salt %u\n", - GNUNET_h2s (&mutated_hash), - op->state->salt); + GNUNET_BLOCK_mingle_hash(&ee->element_hash, + op->state->salt, + &mutated_hash); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Testing mingled hash %s with salt %u\n", + GNUNET_h2s(&mutated_hash), + op->state->salt); if (GNUNET_NO == - GNUNET_CONTAINER_bloomfilter_test (op->state->remote_bf, - &mutated_hash)) - { - GNUNET_break (0 < op->state->my_element_count); - op->state->my_element_count--; - GNUNET_CRYPTO_hash_xor (&op->state->my_xor, - &ee->element_hash, - &op->state->my_xor); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Bloom filter reduction of my_elements, removing %s:%u\n", - GNUNET_h2s (&ee->element_hash), - ee->element.size); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (op->state->my_elements, + GNUNET_CONTAINER_bloomfilter_test(op->state->remote_bf, + &mutated_hash)) + { + GNUNET_break(0 < op->state->my_element_count); + op->state->my_element_count--; + GNUNET_CRYPTO_hash_xor(&op->state->my_xor, + &ee->element_hash, + &op->state->my_xor); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Bloom filter reduction of my_elements, removing %s:%u\n", + GNUNET_h2s(&ee->element_hash), + ee->element.size); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(op->state->my_elements, &ee->element_hash, ee)); - send_client_removed_element (op, - &ee->element); - } + send_client_removed_element(op, + &ee->element); + } else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Bloom filter reduction of my_elements, keeping %s:%u\n", - GNUNET_h2s (&ee->element_hash), - ee->element.size); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Bloom filter reduction of my_elements, keeping %s:%u\n", + GNUNET_h2s(&ee->element_hash), + ee->element.size); + } return GNUNET_YES; } @@ -378,23 +374,23 @@ iterator_bf_reduce (void *cls, * @return #GNUNET_YES (we should continue to iterate) */ static int -iterator_bf_create (void *cls, - const struct GNUNET_HashCode *key, - void *value) +iterator_bf_create(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct Operation *op = cls; struct ElementEntry *ee = value; struct GNUNET_HashCode mutated_hash; - GNUNET_BLOCK_mingle_hash (&ee->element_hash, - op->state->salt, - &mutated_hash); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Initializing BF with hash %s with salt %u\n", - GNUNET_h2s (&mutated_hash), - op->state->salt); - GNUNET_CONTAINER_bloomfilter_add (op->state->local_bf, - &mutated_hash); + GNUNET_BLOCK_mingle_hash(&ee->element_hash, + op->state->salt, + &mutated_hash); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Initializing BF with hash %s with salt %u\n", + GNUNET_h2s(&mutated_hash), + op->state->salt); + GNUNET_CONTAINER_bloomfilter_add(op->state->local_bf, + &mutated_hash); return GNUNET_YES; } @@ -406,31 +402,31 @@ iterator_bf_create (void *cls, * @param op the intersection operation to fail */ static void -fail_intersection_operation (struct Operation *op) +fail_intersection_operation(struct Operation *op) { struct GNUNET_MQ_Envelope *ev; struct GNUNET_SET_ResultMessage *msg; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Intersection operation failed\n"); - GNUNET_STATISTICS_update (_GSS_statistics, - "# Intersection operations failed", - 1, - GNUNET_NO); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + "Intersection operation failed\n"); + GNUNET_STATISTICS_update(_GSS_statistics, + "# Intersection operations failed", + 1, + GNUNET_NO); if (NULL != op->state->my_elements) - { - GNUNET_CONTAINER_multihashmap_destroy (op->state->my_elements); - op->state->my_elements = NULL; - } - ev = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_SET_RESULT); - msg->result_status = htons (GNUNET_SET_STATUS_FAILURE); - msg->request_id = htonl (op->client_request_id); - msg->element_type = htons (0); - GNUNET_MQ_send (op->set->cs->mq, - ev); - _GSS_operation_destroy (op, - GNUNET_YES); + { + GNUNET_CONTAINER_multihashmap_destroy(op->state->my_elements); + op->state->my_elements = NULL; + } + ev = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_SET_RESULT); + msg->result_status = htons(GNUNET_SET_STATUS_FAILURE); + msg->request_id = htonl(op->client_request_id); + msg->element_type = htons(0); + GNUNET_MQ_send(op->set->cs->mq, + ev); + _GSS_operation_destroy(op, + GNUNET_YES); } @@ -441,7 +437,7 @@ fail_intersection_operation (struct Operation *op) * @param op intersection operation */ static void -send_bloomfilter (struct Operation *op) +send_bloomfilter(struct Operation *op) { struct GNUNET_MQ_Envelope *ev; struct BFMessage *msg; @@ -455,81 +451,81 @@ send_bloomfilter (struct Operation *op) the number of bits per element, as the smaller set should use more bits to maximize its set reduction potential and minimize overall bandwidth consumption. */ - bf_elementbits = 2 + ceil (log2((double) - (op->remote_element_count / - (double) op->state->my_element_count))); + bf_elementbits = 2 + ceil(log2((double) + (op->remote_element_count / + (double)op->state->my_element_count))); if (bf_elementbits < 1) bf_elementbits = 1; /* make sure k is not 0 */ /* optimize BF-size to ~50% of bits set */ - bf_size = ceil ((double) (op->state->my_element_count - * bf_elementbits / log(2))); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending Bloom filter (%u) of size %u bytes\n", - (unsigned int) bf_elementbits, - (unsigned int) bf_size); - op->state->local_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, - bf_size, - bf_elementbits); - op->state->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, - UINT32_MAX); - GNUNET_CONTAINER_multihashmap_iterate (op->state->my_elements, - &iterator_bf_create, - op); + bf_size = ceil((double)(op->state->my_element_count + * bf_elementbits / log(2))); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending Bloom filter (%u) of size %u bytes\n", + (unsigned int)bf_elementbits, + (unsigned int)bf_size); + op->state->local_bf = GNUNET_CONTAINER_bloomfilter_init(NULL, + bf_size, + bf_elementbits); + op->state->salt = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, + UINT32_MAX); + GNUNET_CONTAINER_multihashmap_iterate(op->state->my_elements, + &iterator_bf_create, + op); /* send our Bloom filter */ - GNUNET_STATISTICS_update (_GSS_statistics, - "# Intersection Bloom filters sent", - 1, - GNUNET_NO); - chunk_size = 60 * 1024 - sizeof (struct BFMessage); + GNUNET_STATISTICS_update(_GSS_statistics, + "# Intersection Bloom filters sent", + 1, + GNUNET_NO); + chunk_size = 60 * 1024 - sizeof(struct BFMessage); if (bf_size <= chunk_size) - { - /* singlepart */ - chunk_size = bf_size; - ev = GNUNET_MQ_msg_extra (msg, - chunk_size, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); - GNUNET_assert (GNUNET_SYSERR != - GNUNET_CONTAINER_bloomfilter_get_raw_data (op->state->local_bf, - (char*) &msg[1], + { + /* singlepart */ + chunk_size = bf_size; + ev = GNUNET_MQ_msg_extra(msg, + chunk_size, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); + GNUNET_assert(GNUNET_SYSERR != + GNUNET_CONTAINER_bloomfilter_get_raw_data(op->state->local_bf, + (char*)&msg[1], bf_size)); - msg->sender_element_count = htonl (op->state->my_element_count); - msg->bloomfilter_total_length = htonl (bf_size); - msg->bits_per_element = htonl (bf_elementbits); - msg->sender_mutator = htonl (op->state->salt); - msg->element_xor_hash = op->state->my_xor; - GNUNET_MQ_send (op->mq, ev); - } + msg->sender_element_count = htonl(op->state->my_element_count); + msg->bloomfilter_total_length = htonl(bf_size); + msg->bits_per_element = htonl(bf_elementbits); + msg->sender_mutator = htonl(op->state->salt); + msg->element_xor_hash = op->state->my_xor; + GNUNET_MQ_send(op->mq, ev); + } else - { - /* multipart */ - bf_data = GNUNET_malloc (bf_size); - GNUNET_assert (GNUNET_SYSERR != - GNUNET_CONTAINER_bloomfilter_get_raw_data (op->state->local_bf, + { + /* multipart */ + bf_data = GNUNET_malloc(bf_size); + GNUNET_assert(GNUNET_SYSERR != + GNUNET_CONTAINER_bloomfilter_get_raw_data(op->state->local_bf, bf_data, bf_size)); - offset = 0; - while (offset < bf_size) - { - if (bf_size - chunk_size < offset) - chunk_size = bf_size - offset; - ev = GNUNET_MQ_msg_extra (msg, - chunk_size, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); - GNUNET_memcpy (&msg[1], - &bf_data[offset], - chunk_size); - offset += chunk_size; - msg->sender_element_count = htonl (op->state->my_element_count); - msg->bloomfilter_total_length = htonl (bf_size); - msg->bits_per_element = htonl (bf_elementbits); - msg->sender_mutator = htonl (op->state->salt); - msg->element_xor_hash = op->state->my_xor; - GNUNET_MQ_send (op->mq, ev); + offset = 0; + while (offset < bf_size) + { + if (bf_size - chunk_size < offset) + chunk_size = bf_size - offset; + ev = GNUNET_MQ_msg_extra(msg, + chunk_size, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); + GNUNET_memcpy(&msg[1], + &bf_data[offset], + chunk_size); + offset += chunk_size; + msg->sender_element_count = htonl(op->state->my_element_count); + msg->bloomfilter_total_length = htonl(bf_size); + msg->bits_per_element = htonl(bf_elementbits); + msg->sender_mutator = htonl(op->state->salt); + msg->element_xor_hash = op->state->my_xor; + GNUNET_MQ_send(op->mq, ev); + } + GNUNET_free(bf_data); } - GNUNET_free (bf_data); - } - GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf); + GNUNET_CONTAINER_bloomfilter_free(op->state->local_bf); op->state->local_bf = NULL; } @@ -541,27 +537,27 @@ send_bloomfilter (struct Operation *op) * @param cls operation to destroy */ static void -send_client_done_and_destroy (void *cls) +send_client_done_and_destroy(void *cls) { struct Operation *op = cls; struct GNUNET_MQ_Envelope *ev; struct GNUNET_SET_ResultMessage *rm; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Intersection succeeded, sending DONE to local client\n"); - GNUNET_STATISTICS_update (_GSS_statistics, - "# Intersection operations succeeded", - 1, - GNUNET_NO); - ev = GNUNET_MQ_msg (rm, - GNUNET_MESSAGE_TYPE_SET_RESULT); - rm->request_id = htonl (op->client_request_id); - rm->result_status = htons (GNUNET_SET_STATUS_DONE); - rm->element_type = htons (0); - GNUNET_MQ_send (op->set->cs->mq, - ev); - _GSS_operation_destroy (op, - GNUNET_YES); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Intersection succeeded, sending DONE to local client\n"); + GNUNET_STATISTICS_update(_GSS_statistics, + "# Intersection operations succeeded", + 1, + GNUNET_NO); + ev = GNUNET_MQ_msg(rm, + GNUNET_MESSAGE_TYPE_SET_RESULT); + rm->request_id = htonl(op->client_request_id); + rm->result_status = htons(GNUNET_SET_STATUS_DONE); + rm->element_type = htons(0); + GNUNET_MQ_send(op->set->cs->mq, + ev); + _GSS_operation_destroy(op, + GNUNET_YES); } @@ -574,12 +570,12 @@ send_client_done_and_destroy (void *cls) * @param cls the `struct Operation`. */ static void -finished_local_operations (void *cls) +finished_local_operations(void *cls) { struct Operation *op = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "DONE sent to other peer, now waiting for other end to close the channel\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "DONE sent to other peer, now waiting for other end to close the channel\n"); op->state->phase = PHASE_FINISHED; op->state->channel_death_expected = GNUNET_YES; } @@ -593,22 +589,22 @@ finished_local_operations (void *cls) * @param op operation to notify for. */ static void -send_p2p_done (struct Operation *op) +send_p2p_done(struct Operation *op) { struct GNUNET_MQ_Envelope *ev; struct IntersectionDoneMessage *idm; - GNUNET_assert (PHASE_MUST_SEND_DONE == op->state->phase); - GNUNET_assert (GNUNET_NO == op->state->channel_death_expected); - ev = GNUNET_MQ_msg (idm, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE); - idm->final_element_count = htonl (op->state->my_element_count); + GNUNET_assert(PHASE_MUST_SEND_DONE == op->state->phase); + GNUNET_assert(GNUNET_NO == op->state->channel_death_expected); + ev = GNUNET_MQ_msg(idm, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE); + idm->final_element_count = htonl(op->state->my_element_count); idm->element_xor_hash = op->state->my_xor; - GNUNET_MQ_notify_sent (ev, - &finished_local_operations, - op); - GNUNET_MQ_send (op->mq, - ev); + GNUNET_MQ_notify_sent(ev, + &finished_local_operations, + op); + GNUNET_MQ_send(op->mq, + ev); } @@ -618,7 +614,7 @@ send_p2p_done (struct Operation *op) * @param cls the `struct Operation *` */ static void -send_remaining_elements (void *cls) +send_remaining_elements(void *cls) { struct Operation *op = cls; const void *nxt; @@ -628,52 +624,52 @@ send_remaining_elements (void *cls) const struct GNUNET_SET_Element *element; int res; - res = GNUNET_CONTAINER_multihashmap_iterator_next (op->state->full_result_iter, - NULL, - &nxt); + res = GNUNET_CONTAINER_multihashmap_iterator_next(op->state->full_result_iter, + NULL, + &nxt); if (GNUNET_NO == res) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending done and destroy because iterator ran out\n"); - GNUNET_CONTAINER_multihashmap_iterator_destroy (op->state->full_result_iter); - op->state->full_result_iter = NULL; - if (PHASE_DONE_RECEIVED == op->state->phase) - { - op->state->phase = PHASE_FINISHED; - send_client_done_and_destroy (op); - } - else if (PHASE_MUST_SEND_DONE == op->state->phase) - { - send_p2p_done (op); - } - else { - GNUNET_assert (0); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending done and destroy because iterator ran out\n"); + GNUNET_CONTAINER_multihashmap_iterator_destroy(op->state->full_result_iter); + op->state->full_result_iter = NULL; + if (PHASE_DONE_RECEIVED == op->state->phase) + { + op->state->phase = PHASE_FINISHED; + send_client_done_and_destroy(op); + } + else if (PHASE_MUST_SEND_DONE == op->state->phase) + { + send_p2p_done(op); + } + else + { + GNUNET_assert(0); + } + return; } - return; - } ee = nxt; element = &ee->element; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending element %s:%u to client (full set)\n", - GNUNET_h2s (&ee->element_hash), - element->size); - GNUNET_assert (0 != op->client_request_id); - ev = GNUNET_MQ_msg_extra (rm, - element->size, - GNUNET_MESSAGE_TYPE_SET_RESULT); - GNUNET_assert (NULL != ev); - rm->result_status = htons (GNUNET_SET_STATUS_OK); - rm->request_id = htonl (op->client_request_id); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending element %s:%u to client (full set)\n", + GNUNET_h2s(&ee->element_hash), + element->size); + GNUNET_assert(0 != op->client_request_id); + ev = GNUNET_MQ_msg_extra(rm, + element->size, + GNUNET_MESSAGE_TYPE_SET_RESULT); + GNUNET_assert(NULL != ev); + rm->result_status = htons(GNUNET_SET_STATUS_OK); + rm->request_id = htonl(op->client_request_id); rm->element_type = element->element_type; - GNUNET_memcpy (&rm[1], - element->data, - element->size); - GNUNET_MQ_notify_sent (ev, - &send_remaining_elements, - op); - GNUNET_MQ_send (op->set->cs->mq, - ev); + GNUNET_memcpy(&rm[1], + element->data, + element->size); + GNUNET_MQ_notify_sent(ev, + &send_remaining_elements, + op); + GNUNET_MQ_send(op->set->cs->mq, + ev); } @@ -687,27 +683,27 @@ send_remaining_elements (void *cls) * @return #GNUNET_YES (we should continue to iterate) */ static int -initialize_map_unfiltered (void *cls, - const struct GNUNET_HashCode *key, - void *value) +initialize_map_unfiltered(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct ElementEntry *ee = value; struct Operation *op = cls; - if (GNUNET_NO == _GSS_is_element_of_operation (ee, op)) + if (GNUNET_NO == _GSS_is_element_of_operation(ee, op)) return GNUNET_YES; /* element not live in operation's generation */ - GNUNET_CRYPTO_hash_xor (&op->state->my_xor, - &ee->element_hash, - &op->state->my_xor); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Initial full initialization of my_elements, adding %s:%u\n", - GNUNET_h2s (&ee->element_hash), - ee->element.size); - GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_put (op->state->my_elements, - &ee->element_hash, - ee, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CRYPTO_hash_xor(&op->state->my_xor, + &ee->element_hash, + &op->state->my_xor); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Initial full initialization of my_elements, adding %s:%u\n", + GNUNET_h2s(&ee->element_hash), + ee->element.size); + GNUNET_break(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_put(op->state->my_elements, + &ee->element_hash, + ee, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); return GNUNET_YES; } @@ -719,18 +715,18 @@ initialize_map_unfiltered (void *cls, * @param op intersection operation */ static void -send_element_count (struct Operation *op) +send_element_count(struct Operation *op) { struct GNUNET_MQ_Envelope *ev; struct IntersectionElementInfoMessage *msg; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending our element count (%u)\n", - op->state->my_element_count); - ev = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO); - msg->sender_element_count = htonl (op->state->my_element_count); - GNUNET_MQ_send (op->mq, ev); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending our element count (%u)\n", + op->state->my_element_count); + ev = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO); + msg->sender_element_count = htonl(op->state->my_element_count); + GNUNET_MQ_send(op->mq, ev); } @@ -741,13 +737,13 @@ send_element_count (struct Operation *op) * @param op operation to start exchange for */ static void -begin_bf_exchange (struct Operation *op) +begin_bf_exchange(struct Operation *op) { op->state->phase = PHASE_BF_EXCHANGE; - GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements, - &initialize_map_unfiltered, - op); - send_bloomfilter (op); + GNUNET_CONTAINER_multihashmap_iterate(op->set->content->elements, + &initialize_map_unfiltered, + op); + send_bloomfilter(op); } @@ -759,35 +755,35 @@ begin_bf_exchange (struct Operation *op) * @param mh the header of the message */ void -handle_intersection_p2p_element_info (void *cls, - const struct IntersectionElementInfoMessage *msg) +handle_intersection_p2p_element_info(void *cls, + const struct IntersectionElementInfoMessage *msg) { struct Operation *op = cls; if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation) - { - GNUNET_break_op (0); - fail_intersection_operation(op); - return; - } - op->remote_element_count = ntohl (msg->sender_element_count); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received remote element count (%u), I have %u\n", - op->remote_element_count, - op->state->my_element_count); - if ( ( (PHASE_INITIAL != op->state->phase) && - (PHASE_COUNT_SENT != op->state->phase) ) || - (op->state->my_element_count > op->remote_element_count) || - (0 == op->state->my_element_count) || - (0 == op->remote_element_count) ) - { - GNUNET_break_op (0); - fail_intersection_operation(op); - return; - } - GNUNET_break (NULL == op->state->remote_bf); - begin_bf_exchange (op); - GNUNET_CADET_receive_done (op->channel); + { + GNUNET_break_op(0); + fail_intersection_operation(op); + return; + } + op->remote_element_count = ntohl(msg->sender_element_count); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received remote element count (%u), I have %u\n", + op->remote_element_count, + op->state->my_element_count); + if (((PHASE_INITIAL != op->state->phase) && + (PHASE_COUNT_SENT != op->state->phase)) || + (op->state->my_element_count > op->remote_element_count) || + (0 == op->state->my_element_count) || + (0 == op->remote_element_count)) + { + GNUNET_break_op(0); + fail_intersection_operation(op); + return; + } + GNUNET_break(NULL == op->state->remote_bf); + begin_bf_exchange(op); + GNUNET_CADET_receive_done(op->channel); } @@ -797,76 +793,81 @@ handle_intersection_p2p_element_info (void *cls, * @param op the intersection operation */ static void -process_bf (struct Operation *op) +process_bf(struct Operation *op) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received BF in phase %u, foreign count is %u, my element count is %u/%u\n", - op->state->phase, - op->remote_element_count, - op->state->my_element_count, - GNUNET_CONTAINER_multihashmap_size (op->set->content->elements)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received BF in phase %u, foreign count is %u, my element count is %u/%u\n", + op->state->phase, + op->remote_element_count, + op->state->my_element_count, + GNUNET_CONTAINER_multihashmap_size(op->set->content->elements)); switch (op->state->phase) - { - case PHASE_INITIAL: - GNUNET_break_op (0); - fail_intersection_operation(op); - return; - case PHASE_COUNT_SENT: - /* This is the first BF being sent, build our initial map with - filtering in place */ - op->state->my_element_count = 0; - GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements, - &filtered_map_initialization, - op); - break; - case PHASE_BF_EXCHANGE: - /* Update our set by reduction */ - GNUNET_CONTAINER_multihashmap_iterate (op->state->my_elements, - &iterator_bf_reduce, - op); - break; - case PHASE_MUST_SEND_DONE: - GNUNET_break_op (0); - fail_intersection_operation(op); - return; - case PHASE_DONE_RECEIVED: - GNUNET_break_op (0); - fail_intersection_operation(op); - return; - case PHASE_FINISHED: - GNUNET_break_op (0); - fail_intersection_operation(op); - return; - } - GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf); + { + case PHASE_INITIAL: + GNUNET_break_op(0); + fail_intersection_operation(op); + return; + + case PHASE_COUNT_SENT: + /* This is the first BF being sent, build our initial map with + filtering in place */ + op->state->my_element_count = 0; + GNUNET_CONTAINER_multihashmap_iterate(op->set->content->elements, + &filtered_map_initialization, + op); + break; + + case PHASE_BF_EXCHANGE: + /* Update our set by reduction */ + GNUNET_CONTAINER_multihashmap_iterate(op->state->my_elements, + &iterator_bf_reduce, + op); + break; + + case PHASE_MUST_SEND_DONE: + GNUNET_break_op(0); + fail_intersection_operation(op); + return; + + case PHASE_DONE_RECEIVED: + GNUNET_break_op(0); + fail_intersection_operation(op); + return; + + case PHASE_FINISHED: + GNUNET_break_op(0); + fail_intersection_operation(op); + return; + } + GNUNET_CONTAINER_bloomfilter_free(op->state->remote_bf); op->state->remote_bf = NULL; - if ( (0 == op->state->my_element_count) || /* fully disjoint */ - ( (op->state->my_element_count == op->remote_element_count) && - (0 == GNUNET_memcmp (&op->state->my_xor, - &op->state->other_xor)) ) ) - { - /* we are done */ - op->state->phase = PHASE_MUST_SEND_DONE; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Intersection succeeded, sending DONE to other peer\n"); - GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf); - op->state->local_bf = NULL; - if (GNUNET_SET_RESULT_FULL == op->result_mode) + if ((0 == op->state->my_element_count) || /* fully disjoint */ + ((op->state->my_element_count == op->remote_element_count) && + (0 == GNUNET_memcmp(&op->state->my_xor, + &op->state->other_xor)))) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending full result set (%u elements)\n", - GNUNET_CONTAINER_multihashmap_size (op->state->my_elements)); - op->state->full_result_iter - = GNUNET_CONTAINER_multihashmap_iterator_create (op->state->my_elements); - send_remaining_elements (op); + /* we are done */ + op->state->phase = PHASE_MUST_SEND_DONE; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Intersection succeeded, sending DONE to other peer\n"); + GNUNET_CONTAINER_bloomfilter_free(op->state->local_bf); + op->state->local_bf = NULL; + if (GNUNET_SET_RESULT_FULL == op->result_mode) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending full result set (%u elements)\n", + GNUNET_CONTAINER_multihashmap_size(op->state->my_elements)); + op->state->full_result_iter + = GNUNET_CONTAINER_multihashmap_iterator_create(op->state->my_elements); + send_remaining_elements(op); + return; + } + send_p2p_done(op); return; } - send_p2p_done (op); - return; - } op->state->phase = PHASE_BF_EXCHANGE; - send_bloomfilter (op); + send_bloomfilter(op); } @@ -878,16 +879,16 @@ process_bf (struct Operation *op) * @return #GNUNET_OK if @a msg is well-formed */ int -check_intersection_p2p_bf (void *cls, - const struct BFMessage *msg) +check_intersection_p2p_bf(void *cls, + const struct BFMessage *msg) { struct Operation *op = cls; if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -899,8 +900,8 @@ check_intersection_p2p_bf (void *cls, * @param msg the header of the message */ void -handle_intersection_p2p_bf (void *cls, - const struct BFMessage *msg) +handle_intersection_p2p_bf(void *cls, + const struct BFMessage *msg) { struct Operation *op = cls; uint32_t bf_size; @@ -908,83 +909,85 @@ handle_intersection_p2p_bf (void *cls, uint32_t bf_bits_per_element; switch (op->state->phase) - { - case PHASE_INITIAL: - GNUNET_break_op (0); - fail_intersection_operation (op); - return; - case PHASE_COUNT_SENT: - case PHASE_BF_EXCHANGE: - bf_size = ntohl (msg->bloomfilter_total_length); - bf_bits_per_element = ntohl (msg->bits_per_element); - chunk_size = htons (msg->header.size) - sizeof (struct BFMessage); - op->state->other_xor = msg->element_xor_hash; - if (bf_size == chunk_size) { - if (NULL != op->state->bf_data) - { - GNUNET_break_op (0); - fail_intersection_operation (op); - return; - } - /* single part, done here immediately */ - op->state->remote_bf - = GNUNET_CONTAINER_bloomfilter_init ((const char*) &msg[1], - bf_size, - bf_bits_per_element); - op->state->salt = ntohl (msg->sender_mutator); - op->remote_element_count = ntohl (msg->sender_element_count); - process_bf (op); + case PHASE_INITIAL: + GNUNET_break_op(0); + fail_intersection_operation(op); + return; + + case PHASE_COUNT_SENT: + case PHASE_BF_EXCHANGE: + bf_size = ntohl(msg->bloomfilter_total_length); + bf_bits_per_element = ntohl(msg->bits_per_element); + chunk_size = htons(msg->header.size) - sizeof(struct BFMessage); + op->state->other_xor = msg->element_xor_hash; + if (bf_size == chunk_size) + { + if (NULL != op->state->bf_data) + { + GNUNET_break_op(0); + fail_intersection_operation(op); + return; + } + /* single part, done here immediately */ + op->state->remote_bf + = GNUNET_CONTAINER_bloomfilter_init((const char*)&msg[1], + bf_size, + bf_bits_per_element); + op->state->salt = ntohl(msg->sender_mutator); + op->remote_element_count = ntohl(msg->sender_element_count); + process_bf(op); + break; + } + /* multipart chunk */ + if (NULL == op->state->bf_data) + { + /* first chunk, initialize */ + op->state->bf_data = GNUNET_malloc(bf_size); + op->state->bf_data_size = bf_size; + op->state->bf_bits_per_element = bf_bits_per_element; + op->state->bf_data_offset = 0; + op->state->salt = ntohl(msg->sender_mutator); + op->remote_element_count = ntohl(msg->sender_element_count); + } + else + { + /* increment */ + if ((op->state->bf_data_size != bf_size) || + (op->state->bf_bits_per_element != bf_bits_per_element) || + (op->state->bf_data_offset + chunk_size > bf_size) || + (op->state->salt != ntohl(msg->sender_mutator)) || + (op->remote_element_count != ntohl(msg->sender_element_count))) + { + GNUNET_break_op(0); + fail_intersection_operation(op); + return; + } + } + GNUNET_memcpy(&op->state->bf_data[op->state->bf_data_offset], + (const char*)&msg[1], + chunk_size); + op->state->bf_data_offset += chunk_size; + if (op->state->bf_data_offset == bf_size) + { + /* last chunk, run! */ + op->state->remote_bf + = GNUNET_CONTAINER_bloomfilter_init(op->state->bf_data, + bf_size, + bf_bits_per_element); + GNUNET_free(op->state->bf_data); + op->state->bf_data = NULL; + op->state->bf_data_size = 0; + process_bf(op); + } break; + + default: + GNUNET_break_op(0); + fail_intersection_operation(op); + return; } - /* multipart chunk */ - if (NULL == op->state->bf_data) - { - /* first chunk, initialize */ - op->state->bf_data = GNUNET_malloc (bf_size); - op->state->bf_data_size = bf_size; - op->state->bf_bits_per_element = bf_bits_per_element; - op->state->bf_data_offset = 0; - op->state->salt = ntohl (msg->sender_mutator); - op->remote_element_count = ntohl (msg->sender_element_count); - } - else - { - /* increment */ - if ( (op->state->bf_data_size != bf_size) || - (op->state->bf_bits_per_element != bf_bits_per_element) || - (op->state->bf_data_offset + chunk_size > bf_size) || - (op->state->salt != ntohl (msg->sender_mutator)) || - (op->remote_element_count != ntohl (msg->sender_element_count)) ) - { - GNUNET_break_op (0); - fail_intersection_operation (op); - return; - } - } - GNUNET_memcpy (&op->state->bf_data[op->state->bf_data_offset], - (const char*) &msg[1], - chunk_size); - op->state->bf_data_offset += chunk_size; - if (op->state->bf_data_offset == bf_size) - { - /* last chunk, run! */ - op->state->remote_bf - = GNUNET_CONTAINER_bloomfilter_init (op->state->bf_data, - bf_size, - bf_bits_per_element); - GNUNET_free (op->state->bf_data); - op->state->bf_data = NULL; - op->state->bf_data_size = 0; - process_bf (op); - } - break; - default: - GNUNET_break_op (0); - fail_intersection_operation (op); - return; - } - GNUNET_CADET_receive_done (op->channel); + GNUNET_CADET_receive_done(op->channel); } @@ -997,28 +1000,28 @@ handle_intersection_p2p_bf (void *cls, * @return #GNUNET_YES (we should continue to iterate) */ static int -filter_all (void *cls, - const struct GNUNET_HashCode *key, - void *value) +filter_all(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct Operation *op = cls; struct ElementEntry *ee = value; - GNUNET_break (0 < op->state->my_element_count); + GNUNET_break(0 < op->state->my_element_count); op->state->my_element_count--; - GNUNET_CRYPTO_hash_xor (&op->state->my_xor, - &ee->element_hash, - &op->state->my_xor); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Final reduction of my_elements, removing %s:%u\n", - GNUNET_h2s (&ee->element_hash), - ee->element.size); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (op->state->my_elements, - &ee->element_hash, - ee)); - send_client_removed_element (op, - &ee->element); + GNUNET_CRYPTO_hash_xor(&op->state->my_xor, + &ee->element_hash, + &op->state->my_xor); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Final reduction of my_elements, removing %s:%u\n", + GNUNET_h2s(&ee->element_hash), + ee->element.size); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(op->state->my_elements, + &ee->element_hash, + ee)); + send_client_removed_element(op, + &ee->element); return GNUNET_YES; } @@ -1030,61 +1033,61 @@ filter_all (void *cls, * @param mh the message */ void -handle_intersection_p2p_done (void *cls, - const struct IntersectionDoneMessage *idm) +handle_intersection_p2p_done(void *cls, + const struct IntersectionDoneMessage *idm) { struct Operation *op = cls; if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation) - { - GNUNET_break_op (0); - fail_intersection_operation (op); - return; - } + { + GNUNET_break_op(0); + fail_intersection_operation(op); + return; + } if (PHASE_BF_EXCHANGE != op->state->phase) - { - /* wrong phase to conclude? FIXME: Or should we allow this - if the other peer has _initially_ already an empty set? */ - GNUNET_break_op (0); - fail_intersection_operation (op); - return; - } - if (0 == ntohl (idm->final_element_count)) - { - /* other peer determined empty set is the intersection, - remove all elements */ - GNUNET_CONTAINER_multihashmap_iterate (op->state->my_elements, - &filter_all, - op); - } - if ( (op->state->my_element_count != ntohl (idm->final_element_count)) || - (0 != GNUNET_memcmp (&op->state->my_xor, - &idm->element_xor_hash)) ) - { - /* Other peer thinks we are done, but we disagree on the result! */ - GNUNET_break_op (0); - fail_intersection_operation (op); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Got IntersectionDoneMessage, have %u elements in intersection\n", - op->state->my_element_count); + { + /* wrong phase to conclude? FIXME: Or should we allow this + if the other peer has _initially_ already an empty set? */ + GNUNET_break_op(0); + fail_intersection_operation(op); + return; + } + if (0 == ntohl(idm->final_element_count)) + { + /* other peer determined empty set is the intersection, + remove all elements */ + GNUNET_CONTAINER_multihashmap_iterate(op->state->my_elements, + &filter_all, + op); + } + if ((op->state->my_element_count != ntohl(idm->final_element_count)) || + (0 != GNUNET_memcmp(&op->state->my_xor, + &idm->element_xor_hash))) + { + /* Other peer thinks we are done, but we disagree on the result! */ + GNUNET_break_op(0); + fail_intersection_operation(op); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Got IntersectionDoneMessage, have %u elements in intersection\n", + op->state->my_element_count); op->state->phase = PHASE_DONE_RECEIVED; - GNUNET_CADET_receive_done (op->channel); + GNUNET_CADET_receive_done(op->channel); - GNUNET_assert (GNUNET_NO == op->state->client_done_sent); + GNUNET_assert(GNUNET_NO == op->state->client_done_sent); if (GNUNET_SET_RESULT_FULL == op->result_mode) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending full result set to client (%u elements)\n", - GNUNET_CONTAINER_multihashmap_size (op->state->my_elements)); - op->state->full_result_iter - = GNUNET_CONTAINER_multihashmap_iterator_create (op->state->my_elements); - send_remaining_elements (op); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending full result set to client (%u elements)\n", + GNUNET_CONTAINER_multihashmap_size(op->state->my_elements)); + op->state->full_result_iter + = GNUNET_CONTAINER_multihashmap_iterator_create(op->state->my_elements); + send_remaining_elements(op); + return; + } op->state->phase = PHASE_FINISHED; - send_client_done_and_destroy (op); + send_client_done_and_destroy(op); } @@ -1098,43 +1101,43 @@ handle_intersection_p2p_done (void *cls, * @return operation-specific state to keep in @a op */ static struct OperationState * -intersection_evaluate (struct Operation *op, - const struct GNUNET_MessageHeader *opaque_context) +intersection_evaluate(struct Operation *op, + const struct GNUNET_MessageHeader *opaque_context) { struct OperationState *state; struct GNUNET_MQ_Envelope *ev; struct OperationRequestMessage *msg; - ev = GNUNET_MQ_msg_nested_mh (msg, - GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, - opaque_context); + ev = GNUNET_MQ_msg_nested_mh(msg, + GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, + opaque_context); if (NULL == ev) - { - /* the context message is too large!? */ - GNUNET_break (0); - return NULL; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Initiating intersection operation evaluation\n"); - state = GNUNET_new (struct OperationState); + { + /* the context message is too large!? */ + GNUNET_break(0); + return NULL; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Initiating intersection operation evaluation\n"); + state = GNUNET_new(struct OperationState); /* we started the operation, thus we have to send the operation request */ state->phase = PHASE_INITIAL; state->my_element_count = op->set->state->current_set_element_count; state->my_elements - = GNUNET_CONTAINER_multihashmap_create (state->my_element_count, - GNUNET_YES); + = GNUNET_CONTAINER_multihashmap_create(state->my_element_count, + GNUNET_YES); - msg->operation = htonl (GNUNET_SET_OPERATION_INTERSECTION); - msg->element_count = htonl (state->my_element_count); - GNUNET_MQ_send (op->mq, - ev); + msg->operation = htonl(GNUNET_SET_OPERATION_INTERSECTION); + msg->element_count = htonl(state->my_element_count); + GNUNET_MQ_send(op->mq, + ev); state->phase = PHASE_COUNT_SENT; if (NULL != opaque_context) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sent op request with context message\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sent op request with context message\n"); else - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sent op request without context message\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sent op request without context message\n"); return state; } @@ -1146,31 +1149,31 @@ intersection_evaluate (struct Operation *op, * @param op operation that will be accepted as an intersection operation */ static struct OperationState * -intersection_accept (struct Operation *op) +intersection_accept(struct Operation *op) { struct OperationState *state; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Accepting set intersection operation\n"); - state = GNUNET_new (struct OperationState); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Accepting set intersection operation\n"); + state = GNUNET_new(struct OperationState); state->phase = PHASE_INITIAL; state->my_element_count = op->set->state->current_set_element_count; state->my_elements - = GNUNET_CONTAINER_multihashmap_create (GNUNET_MIN (state->my_element_count, - op->remote_element_count), - GNUNET_YES); + = GNUNET_CONTAINER_multihashmap_create(GNUNET_MIN(state->my_element_count, + op->remote_element_count), + GNUNET_YES); op->state = state; if (op->remote_element_count < state->my_element_count) - { - /* If the other peer (Alice) has fewer elements than us (Bob), - we just send the count as Alice should send the first BF */ - send_element_count (op); - state->phase = PHASE_COUNT_SENT; - return state; - } + { + /* If the other peer (Alice) has fewer elements than us (Bob), + we just send the count as Alice should send the first BF */ + send_element_count(op); + state->phase = PHASE_COUNT_SENT; + return state; + } /* We have fewer elements, so we start with the BF */ - begin_bf_exchange (op); + begin_bf_exchange(op); return state; } @@ -1182,34 +1185,34 @@ intersection_accept (struct Operation *op) * @param op intersection operation to destroy */ static void -intersection_op_cancel (struct Operation *op) +intersection_op_cancel(struct Operation *op) { /* check if the op was canceled twice */ - GNUNET_assert (NULL != op->state); + GNUNET_assert(NULL != op->state); if (NULL != op->state->remote_bf) - { - GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf); - op->state->remote_bf = NULL; - } + { + GNUNET_CONTAINER_bloomfilter_free(op->state->remote_bf); + op->state->remote_bf = NULL; + } if (NULL != op->state->local_bf) - { - GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf); - op->state->local_bf = NULL; - } + { + GNUNET_CONTAINER_bloomfilter_free(op->state->local_bf); + op->state->local_bf = NULL; + } if (NULL != op->state->my_elements) - { - GNUNET_CONTAINER_multihashmap_destroy (op->state->my_elements); - op->state->my_elements = NULL; - } + { + GNUNET_CONTAINER_multihashmap_destroy(op->state->my_elements); + op->state->my_elements = NULL; + } if (NULL != op->state->full_result_iter) - { - GNUNET_CONTAINER_multihashmap_iterator_destroy (op->state->full_result_iter); - op->state->full_result_iter = NULL; - } - GNUNET_free (op->state); + { + GNUNET_CONTAINER_multihashmap_iterator_destroy(op->state->full_result_iter); + op->state->full_result_iter = NULL; + } + GNUNET_free(op->state); op->state = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Destroying intersection op state done\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Destroying intersection op state done\n"); } @@ -1219,13 +1222,13 @@ intersection_op_cancel (struct Operation *op) * @return the newly created set */ static struct SetState * -intersection_set_create () +intersection_set_create() { struct SetState *set_state; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Intersection set created\n"); - set_state = GNUNET_new (struct SetState); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Intersection set created\n"); + set_state = GNUNET_new(struct SetState); set_state->current_set_element_count = 0; return set_state; @@ -1239,8 +1242,8 @@ intersection_set_create () * @param ee the element to add to the set */ static void -intersection_add (struct SetState *set_state, - struct ElementEntry *ee) +intersection_add(struct SetState *set_state, + struct ElementEntry *ee) { set_state->current_set_element_count++; } @@ -1252,9 +1255,9 @@ intersection_add (struct SetState *set_state, * @param set_state the set to destroy */ static void -intersection_set_destroy (struct SetState *set_state) +intersection_set_destroy(struct SetState *set_state) { - GNUNET_free (set_state); + GNUNET_free(set_state); } @@ -1265,10 +1268,10 @@ intersection_set_destroy (struct SetState *set_state) * @param element set element to remove */ static void -intersection_remove (struct SetState *set_state, - struct ElementEntry *element) +intersection_remove(struct SetState *set_state, + struct ElementEntry *element) { - GNUNET_assert (0 < set_state->current_set_element_count); + GNUNET_assert(0 < set_state->current_set_element_count); set_state->current_set_element_count--; } @@ -1279,19 +1282,19 @@ intersection_remove (struct SetState *set_state, * @param op operation that lost the channel */ static void -intersection_channel_death (struct Operation *op) +intersection_channel_death(struct Operation *op) { if (GNUNET_YES == op->state->channel_death_expected) - { - /* oh goodie, we are done! */ - send_client_done_and_destroy (op); - } + { + /* oh goodie, we are done! */ + send_client_done_and_destroy(op); + } else - { - /* sorry, channel went down early, too bad. */ - _GSS_operation_destroy (op, - GNUNET_YES); - } + { + /* sorry, channel went down early, too bad. */ + _GSS_operation_destroy(op, + GNUNET_YES); + } } @@ -1301,7 +1304,7 @@ intersection_channel_death (struct Operation *op) * @return the operation specific VTable */ const struct SetVT * -_GSS_intersection_vt () +_GSS_intersection_vt() { static const struct SetVT intersection_vt = { .create = &intersection_set_create, diff --git a/src/set/gnunet-service-set_intersection.h b/src/set/gnunet-service-set_intersection.h index 0e8e644cc..1035cca3b 100644 --- a/src/set/gnunet-service-set_intersection.h +++ b/src/set/gnunet-service-set_intersection.h @@ -12,12 +12,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/gnunet-service-set_intersection.h * @brief two-peer set operations @@ -38,8 +38,8 @@ * @return #GNUNET_OK if @a msg is well-formed */ int -check_intersection_p2p_bf (void *cls, - const struct BFMessage *msg); +check_intersection_p2p_bf(void *cls, + const struct BFMessage *msg); /** @@ -49,8 +49,8 @@ check_intersection_p2p_bf (void *cls, * @param msg the header of the message */ void -handle_intersection_p2p_bf (void *cls, - const struct BFMessage *msg); +handle_intersection_p2p_bf(void *cls, + const struct BFMessage *msg); /** @@ -61,8 +61,8 @@ handle_intersection_p2p_bf (void *cls, * @param mh the header of the message */ void -handle_intersection_p2p_element_info (void *cls, - const struct IntersectionElementInfoMessage *msg); +handle_intersection_p2p_element_info(void *cls, + const struct IntersectionElementInfoMessage *msg); /** @@ -72,8 +72,8 @@ handle_intersection_p2p_element_info (void *cls, * @param mh the message */ void -handle_intersection_p2p_done (void *cls, - const struct IntersectionDoneMessage *idm); +handle_intersection_p2p_done(void *cls, + const struct IntersectionDoneMessage *idm); #endif diff --git a/src/set/gnunet-service-set_protocol.h b/src/set/gnunet-service-set_protocol.h index 13f90a6df..529fed64c 100644 --- a/src/set/gnunet-service-set_protocol.h +++ b/src/set/gnunet-service-set_protocol.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @author Florian Dold * @author Christian Grothoff @@ -32,8 +32,7 @@ GNUNET_NETWORK_STRUCT_BEGIN -struct OperationRequestMessage -{ +struct OperationRequestMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST */ @@ -64,8 +63,7 @@ struct OperationRequestMessage * If an IBF has too many buckets for an IBF message, * it is split into multiple messages. */ -struct IBFMessage -{ +struct IBFMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF */ @@ -101,8 +99,7 @@ struct IBFMessage }; -struct InquiryMessage -{ +struct InquiryMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF */ @@ -127,8 +124,7 @@ struct InquiryMessage * send it the number of elements in the set, to allow the peers * to decide who should start with the Bloom filter. */ -struct IntersectionElementInfoMessage -{ +struct IntersectionElementInfoMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO */ @@ -138,15 +134,13 @@ struct IntersectionElementInfoMessage * mutator used with this bloomfilter. */ uint32_t sender_element_count GNUNET_PACKED; - }; /** * Bloom filter messages exchanged for set intersection calculation. */ -struct BFMessage -{ +struct BFMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF */ @@ -190,8 +184,7 @@ struct BFMessage * by getting the empty set, which in that case also needs to be * communicated. */ -struct IntersectionDoneMessage -{ +struct IntersectionDoneMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE */ @@ -212,8 +205,7 @@ struct IntersectionDoneMessage /** * Strata estimator together with the peer's overall set size. */ -struct StrataEstimatorMessage -{ +struct StrataEstimatorMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE(C) */ diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index 8786807dc..fd7bc24d4 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/gnunet-service-set_union.c * @brief two-peer set operations @@ -34,7 +34,7 @@ #include -#define LOG(kind,...) GNUNET_log_from (kind, "set-union",__VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from(kind, "set-union", __VA_ARGS__) /** @@ -55,7 +55,7 @@ /** * Number of buckets that can be transmitted in one message. */ -#define MAX_BUCKETS_PER_MESSAGE ((1<<15) / IBF_BUCKET_SIZE) +#define MAX_BUCKETS_PER_MESSAGE ((1 << 15) / IBF_BUCKET_SIZE) /** * The maximum size of an ibf we use is 2^(MAX_IBF_ORDER). @@ -74,8 +74,7 @@ /** * Current phase we are in for a union operation. */ -enum UnionOperationPhase -{ +enum UnionOperationPhase { /** * We sent the request message, and expect a strata estimator. */ @@ -139,8 +138,7 @@ enum UnionOperationPhase /** * State of an evaluate operation with another peer. */ -struct OperationState -{ +struct OperationState { /** * Copy of the set's strata estimator at the time of * creation of this operation. @@ -216,8 +214,7 @@ struct OperationState /** * The key entry is used to associate an ibf key with an element. */ -struct KeyEntry -{ +struct KeyEntry { /** * IBF key for the entry, derived from the current salt. */ @@ -245,8 +242,7 @@ struct KeyEntry * Used as a closure for sending elements * with a specific IBF key. */ -struct SendElementClosure -{ +struct SendElementClosure { /** * The IBF key whose matching elements should be * sent. @@ -264,8 +260,7 @@ struct SendElementClosure /** * Extra state required for efficient set union. */ -struct SetState -{ +struct SetState { /** * The strata estimator is only generated once for * each set. @@ -287,19 +282,19 @@ struct SetState * #GNUNET_NO if not. */ static int -destroy_key_to_element_iter (void *cls, - uint32_t key, - void *value) +destroy_key_to_element_iter(void *cls, + uint32_t key, + void *value) { struct KeyEntry *k = value; - GNUNET_assert (NULL != k); + GNUNET_assert(NULL != k); if (GNUNET_YES == k->element->remote) - { - GNUNET_free (k->element); - k->element = NULL; - } - GNUNET_free (k); + { + GNUNET_free(k->element); + k->element = NULL; + } + GNUNET_free(k); return GNUNET_YES; } @@ -311,44 +306,44 @@ destroy_key_to_element_iter (void *cls, * @param op union operation to destroy */ static void -union_op_cancel (struct Operation *op) +union_op_cancel(struct Operation *op) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "destroying union op\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "destroying union op\n"); /* check if the op was canceled twice */ - GNUNET_assert (NULL != op->state); + GNUNET_assert(NULL != op->state); if (NULL != op->state->remote_ibf) - { - ibf_destroy (op->state->remote_ibf); - op->state->remote_ibf = NULL; - } + { + ibf_destroy(op->state->remote_ibf); + op->state->remote_ibf = NULL; + } if (NULL != op->state->demanded_hashes) - { - GNUNET_CONTAINER_multihashmap_destroy (op->state->demanded_hashes); - op->state->demanded_hashes = NULL; - } + { + GNUNET_CONTAINER_multihashmap_destroy(op->state->demanded_hashes); + op->state->demanded_hashes = NULL; + } if (NULL != op->state->local_ibf) - { - ibf_destroy (op->state->local_ibf); - op->state->local_ibf = NULL; - } + { + ibf_destroy(op->state->local_ibf); + op->state->local_ibf = NULL; + } if (NULL != op->state->se) - { - strata_estimator_destroy (op->state->se); - op->state->se = NULL; - } + { + strata_estimator_destroy(op->state->se); + op->state->se = NULL; + } if (NULL != op->state->key_to_element) - { - GNUNET_CONTAINER_multihashmap32_iterate (op->state->key_to_element, - &destroy_key_to_element_iter, - NULL); - GNUNET_CONTAINER_multihashmap32_destroy (op->state->key_to_element); - op->state->key_to_element = NULL; - } - GNUNET_free (op->state); + { + GNUNET_CONTAINER_multihashmap32_iterate(op->state->key_to_element, + &destroy_key_to_element_iter, + NULL); + GNUNET_CONTAINER_multihashmap32_destroy(op->state->key_to_element); + op->state->key_to_element = NULL; + } + GNUNET_free(op->state); op->state = NULL; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "destroying union op done\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "destroying union op done\n"); } @@ -359,20 +354,20 @@ union_op_cancel (struct Operation *op) * @param op the union operation to fail */ static void -fail_union_operation (struct Operation *op) +fail_union_operation(struct Operation *op) { struct GNUNET_MQ_Envelope *ev; struct GNUNET_SET_ResultMessage *msg; - LOG (GNUNET_ERROR_TYPE_WARNING, - "union operation failed\n"); - ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_RESULT); - msg->result_status = htons (GNUNET_SET_STATUS_FAILURE); - msg->request_id = htonl (op->client_request_id); - msg->element_type = htons (0); - GNUNET_MQ_send (op->set->cs->mq, - ev); - _GSS_operation_destroy (op, GNUNET_YES); + LOG(GNUNET_ERROR_TYPE_WARNING, + "union operation failed\n"); + ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_SET_RESULT); + msg->result_status = htons(GNUNET_SET_STATUS_FAILURE); + msg->request_id = htonl(op->client_request_id); + msg->element_type = htons(0); + GNUNET_MQ_send(op->set->cs->mq, + ev); + _GSS_operation_destroy(op, GNUNET_YES); } @@ -384,16 +379,16 @@ fail_union_operation (struct Operation *op) * @return the derived IBF key */ static struct IBF_Key -get_ibf_key (const struct GNUNET_HashCode *src) +get_ibf_key(const struct GNUNET_HashCode *src) { struct IBF_Key key; uint16_t salt = 0; - GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_kdf (&key, sizeof (key), - src, sizeof *src, - &salt, sizeof (salt), - NULL, 0)); + GNUNET_assert(GNUNET_OK == + GNUNET_CRYPTO_kdf(&key, sizeof(key), + src, sizeof *src, + &salt, sizeof(salt), + NULL, 0)); return key; } @@ -401,8 +396,7 @@ get_ibf_key (const struct GNUNET_HashCode *src) /** * Context for #op_get_element_iterator */ -struct GetElementContext -{ +struct GetElementContext { /** * FIXME. */ @@ -426,20 +420,20 @@ struct GetElementContext * #GNUNET_NO if we've found the element. */ static int -op_get_element_iterator (void *cls, - uint32_t key, - void *value) +op_get_element_iterator(void *cls, + uint32_t key, + void *value) { struct GetElementContext *ctx = cls; struct KeyEntry *k = value; - GNUNET_assert (NULL != k); - if (0 == GNUNET_CRYPTO_hash_cmp (&k->element->element_hash, - &ctx->hash)) - { - ctx->k = k; - return GNUNET_NO; - } + GNUNET_assert(NULL != k); + if (0 == GNUNET_CRYPTO_hash_cmp(&k->element->element_hash, + &ctx->hash)) + { + ctx->k = k; + return GNUNET_NO; + } return GNUNET_YES; } @@ -453,27 +447,27 @@ op_get_element_iterator (void *cls, * @return #GNUNET_YES if the element has been found, #GNUNET_NO otherwise */ static struct KeyEntry * -op_get_element (struct Operation *op, - const struct GNUNET_HashCode *element_hash) +op_get_element(struct Operation *op, + const struct GNUNET_HashCode *element_hash) { int ret; struct IBF_Key ibf_key; - struct GetElementContext ctx = {{{ 0 }} , 0}; + struct GetElementContext ctx = { { { 0 } }, 0 }; ctx.hash = *element_hash; - ibf_key = get_ibf_key (element_hash); - ret = GNUNET_CONTAINER_multihashmap32_get_multiple (op->state->key_to_element, - (uint32_t) ibf_key.key_val, - op_get_element_iterator, - &ctx); + ibf_key = get_ibf_key(element_hash); + ret = GNUNET_CONTAINER_multihashmap32_get_multiple(op->state->key_to_element, + (uint32_t)ibf_key.key_val, + op_get_element_iterator, + &ctx); /* was the iteration aborted because we found the element? */ if (GNUNET_SYSERR == ret) - { - GNUNET_assert (NULL != ctx.k); - return ctx.k; - } + { + GNUNET_assert(NULL != ctx.k); + return ctx.k; + } return NULL; } @@ -493,23 +487,23 @@ op_get_element (struct Operation *op, * @parem received was this element received from the remote peer? */ static void -op_register_element (struct Operation *op, - struct ElementEntry *ee, - int received) +op_register_element(struct Operation *op, + struct ElementEntry *ee, + int received) { struct IBF_Key ibf_key; struct KeyEntry *k; - ibf_key = get_ibf_key (&ee->element_hash); - k = GNUNET_new (struct KeyEntry); + ibf_key = get_ibf_key(&ee->element_hash); + k = GNUNET_new(struct KeyEntry); k->element = ee; k->ibf_key = ibf_key; k->received = received; - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap32_put (op->state->key_to_element, - (uint32_t) ibf_key.key_val, - k, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap32_put(op->state->key_to_element, + (uint32_t)ibf_key.key_val, + k, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); } @@ -517,12 +511,13 @@ op_register_element (struct Operation *op, * FIXME. */ static void -salt_key (const struct IBF_Key *k_in, - uint32_t salt, - struct IBF_Key *k_out) +salt_key(const struct IBF_Key *k_in, + uint32_t salt, + struct IBF_Key *k_out) { int s = salt % 64; uint64_t x = k_in->key_val; + /* rotate ibf key */ x = (x >> s) | (x << (64 - s)); k_out->key_val = x; @@ -533,12 +528,13 @@ salt_key (const struct IBF_Key *k_in, * FIXME. */ static void -unsalt_key (const struct IBF_Key *k_in, - uint32_t salt, - struct IBF_Key *k_out) +unsalt_key(const struct IBF_Key *k_in, + uint32_t salt, + struct IBF_Key *k_out) { int s = salt % 64; uint64_t x = k_in->key_val; + x = (x << s) | (x >> (64 - s)); k_out->key_val = x; } @@ -552,23 +548,23 @@ unsalt_key (const struct IBF_Key *k_in, * @param value the key entry to get the key from */ static int -prepare_ibf_iterator (void *cls, - uint32_t key, - void *value) +prepare_ibf_iterator(void *cls, + uint32_t key, + void *value) { struct Operation *op = cls; struct KeyEntry *ke = value; struct IBF_Key salted_key; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "[OP %x] inserting %lx (hash %s) into ibf\n", - (void *) op, - (unsigned long) ke->ibf_key.key_val, - GNUNET_h2s (&ke->element->element_hash)); - salt_key (&ke->ibf_key, - op->state->salt_send, - &salted_key); - ibf_insert (op->state->local_ibf, salted_key); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "[OP %x] inserting %lx (hash %s) into ibf\n", + (void *)op, + (unsigned long)ke->ibf_key.key_val, + GNUNET_h2s(&ke->element->element_hash)); + salt_key(&ke->ibf_key, + op->state->salt_send, + &salted_key); + ibf_insert(op->state->local_ibf, salted_key); return GNUNET_YES; } @@ -584,9 +580,9 @@ prepare_ibf_iterator (void *cls, * @return #GNUNET_YES (to continue iterating) */ static int -init_key_to_element_iterator (void *cls, - const struct GNUNET_HashCode *key, - void *value) +init_key_to_element_iterator(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct Operation *op = cls; struct ElementEntry *ee = value; @@ -594,13 +590,13 @@ init_key_to_element_iterator (void *cls, /* make sure that the element belongs to the set at the time * of creating the operation */ if (GNUNET_NO == - _GSS_is_element_of_operation (ee, - op)) + _GSS_is_element_of_operation(ee, + op)) return GNUNET_YES; - GNUNET_assert (GNUNET_NO == ee->remote); - op_register_element (op, - ee, - GNUNET_NO); + GNUNET_assert(GNUNET_NO == ee->remote); + op_register_element(op, + ee, + GNUNET_NO); return GNUNET_YES; } @@ -612,16 +608,16 @@ init_key_to_element_iterator (void *cls, * @param op the set union operation */ static void -initialize_key_to_element (struct Operation *op) +initialize_key_to_element(struct Operation *op) { unsigned int len; - GNUNET_assert (NULL == op->state->key_to_element); - len = GNUNET_CONTAINER_multihashmap_size (op->set->content->elements); - op->state->key_to_element = GNUNET_CONTAINER_multihashmap32_create (len + 1); - GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements, - &init_key_to_element_iterator, - op); + GNUNET_assert(NULL == op->state->key_to_element); + len = GNUNET_CONTAINER_multihashmap_size(op->set->content->elements); + op->state->key_to_element = GNUNET_CONTAINER_multihashmap32_create(len + 1); + GNUNET_CONTAINER_multihashmap_iterate(op->set->content->elements, + &init_key_to_element_iterator, + op); } @@ -634,23 +630,23 @@ initialize_key_to_element (struct Operation *op) * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -prepare_ibf (struct Operation *op, - uint32_t size) +prepare_ibf(struct Operation *op, + uint32_t size) { - GNUNET_assert (NULL != op->state->key_to_element); + GNUNET_assert(NULL != op->state->key_to_element); if (NULL != op->state->local_ibf) - ibf_destroy (op->state->local_ibf); - op->state->local_ibf = ibf_create (size, SE_IBF_HASH_NUM); + ibf_destroy(op->state->local_ibf); + op->state->local_ibf = ibf_create(size, SE_IBF_HASH_NUM); if (NULL == op->state->local_ibf) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to allocate local IBF\n"); - return GNUNET_SYSERR; - } - GNUNET_CONTAINER_multihashmap32_iterate (op->state->key_to_element, - &prepare_ibf_iterator, - op); + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to allocate local IBF\n"); + return GNUNET_SYSERR; + } + GNUNET_CONTAINER_multihashmap32_iterate(op->state->key_to_element, + &prepare_ibf_iterator, + op); return GNUNET_OK; } @@ -665,60 +661,60 @@ prepare_ibf (struct Operation *op, * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -send_ibf (struct Operation *op, - uint16_t ibf_order) +send_ibf(struct Operation *op, + uint16_t ibf_order) { unsigned int buckets_sent = 0; struct InvertibleBloomFilter *ibf; if (GNUNET_OK != - prepare_ibf (op, 1<state->local_ibf; while (buckets_sent < (1 << ibf_order)) - { - unsigned int buckets_in_message; - struct GNUNET_MQ_Envelope *ev; - struct IBFMessage *msg; - - buckets_in_message = (1 << ibf_order) - buckets_sent; - /* limit to maximum */ - if (buckets_in_message > MAX_BUCKETS_PER_MESSAGE) - buckets_in_message = MAX_BUCKETS_PER_MESSAGE; - - ev = GNUNET_MQ_msg_extra (msg, - buckets_in_message * IBF_BUCKET_SIZE, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF); - msg->reserved1 = 0; - msg->reserved2 = 0; - msg->order = ibf_order; - msg->offset = htonl (buckets_sent); - msg->salt = htonl (op->state->salt_send); - ibf_write_slice (ibf, buckets_sent, - buckets_in_message, &msg[1]); - buckets_sent += buckets_in_message; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "ibf chunk size %u, %u/%u sent\n", - buckets_in_message, - buckets_sent, - 1<mq, ev); - } + { + unsigned int buckets_in_message; + struct GNUNET_MQ_Envelope *ev; + struct IBFMessage *msg; + + buckets_in_message = (1 << ibf_order) - buckets_sent; + /* limit to maximum */ + if (buckets_in_message > MAX_BUCKETS_PER_MESSAGE) + buckets_in_message = MAX_BUCKETS_PER_MESSAGE; + + ev = GNUNET_MQ_msg_extra(msg, + buckets_in_message * IBF_BUCKET_SIZE, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF); + msg->reserved1 = 0; + msg->reserved2 = 0; + msg->order = ibf_order; + msg->offset = htonl(buckets_sent); + msg->salt = htonl(op->state->salt_send); + ibf_write_slice(ibf, buckets_sent, + buckets_in_message, &msg[1]); + buckets_sent += buckets_in_message; + LOG(GNUNET_ERROR_TYPE_DEBUG, + "ibf chunk size %u, %u/%u sent\n", + buckets_in_message, + buckets_sent, + 1 << ibf_order); + GNUNET_MQ_send(op->mq, ev); + } /* The other peer must decode the IBF, so * we're passive. */ @@ -735,14 +731,14 @@ send_ibf (struct Operation *op, * @return the required size of the ibf */ static unsigned int -get_order_from_difference (unsigned int diff) +get_order_from_difference(unsigned int diff) { unsigned int ibf_order; ibf_order = 2; - while ( ( (1<element; struct GNUNET_MQ_Envelope *ev; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Sending element %s\n", - GNUNET_h2s (key)); - ev = GNUNET_MQ_msg_extra (emsg, - el->size, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT); - emsg->element_type = htons (el->element_type); - GNUNET_memcpy (&emsg[1], - el->data, - el->size); - GNUNET_MQ_send (op->mq, - ev); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Sending element %s\n", + GNUNET_h2s(key)); + ev = GNUNET_MQ_msg_extra(emsg, + el->size, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT); + emsg->element_type = htons(el->element_type); + GNUNET_memcpy(&emsg[1], + el->data, + el->size); + GNUNET_MQ_send(op->mq, + ev); return GNUNET_YES; } @@ -791,21 +787,21 @@ send_full_element_iterator (void *cls, * @param op operation to switch to full set transmission. */ static void -send_full_set (struct Operation *op) +send_full_set(struct Operation *op) { struct GNUNET_MQ_Envelope *ev; op->state->phase = PHASE_FULL_SENDING; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Dedicing to transmit the full set\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Dedicing to transmit the full set\n"); /* FIXME: use a more memory-friendly way of doing this with an iterator, just as we do in the non-full case! */ - (void) GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements, - &send_full_element_iterator, - op); - ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE); - GNUNET_MQ_send (op->mq, - ev); + (void)GNUNET_CONTAINER_multihashmap_iterate(op->set->content->elements, + &send_full_element_iterator, + op); + ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE); + GNUNET_MQ_send(op->mq, + ev); } @@ -816,26 +812,26 @@ send_full_set (struct Operation *op) * @param msg the message */ int -check_union_p2p_strata_estimator (void *cls, - const struct StrataEstimatorMessage *msg) +check_union_p2p_strata_estimator(void *cls, + const struct StrataEstimatorMessage *msg) { struct Operation *op = cls; int is_compressed; size_t len; if (op->state->phase != PHASE_EXPECT_SE) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - is_compressed = (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC == htons (msg->header.type)); - len = ntohs (msg->header.size) - sizeof (struct StrataEstimatorMessage); - if ( (GNUNET_NO == is_compressed) && - (len != SE_STRATA_COUNT * SE_IBF_SIZE * IBF_BUCKET_SIZE) ) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + is_compressed = (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC == htons(msg->header.type)); + len = ntohs(msg->header.size) - sizeof(struct StrataEstimatorMessage); + if ((GNUNET_NO == is_compressed) && + (len != SE_STRATA_COUNT * SE_IBF_SIZE * IBF_BUCKET_SIZE)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -847,8 +843,8 @@ check_union_p2p_strata_estimator (void *cls, * @param msg the message */ void -handle_union_p2p_strata_estimator (void *cls, - const struct StrataEstimatorMessage *msg) +handle_union_p2p_strata_estimator(void *cls, + const struct StrataEstimatorMessage *msg) { struct Operation *op = cls; struct StrataEstimator *remote_se; @@ -857,116 +853,116 @@ handle_union_p2p_strata_estimator (void *cls, size_t len; int is_compressed; - is_compressed = (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC == htons (msg->header.type)); - GNUNET_STATISTICS_update (_GSS_statistics, - "# bytes of SE received", - ntohs (msg->header.size), - GNUNET_NO); - len = ntohs (msg->header.size) - sizeof (struct StrataEstimatorMessage); - other_size = GNUNET_ntohll (msg->set_size); - remote_se = strata_estimator_create (SE_STRATA_COUNT, - SE_IBF_SIZE, - SE_IBF_HASH_NUM); + is_compressed = (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC == htons(msg->header.type)); + GNUNET_STATISTICS_update(_GSS_statistics, + "# bytes of SE received", + ntohs(msg->header.size), + GNUNET_NO); + len = ntohs(msg->header.size) - sizeof(struct StrataEstimatorMessage); + other_size = GNUNET_ntohll(msg->set_size); + remote_se = strata_estimator_create(SE_STRATA_COUNT, + SE_IBF_SIZE, + SE_IBF_HASH_NUM); if (NULL == remote_se) - { - /* insufficient resources, fail */ - fail_union_operation (op); - return; - } + { + /* insufficient resources, fail */ + fail_union_operation(op); + return; + } if (GNUNET_OK != - strata_estimator_read (&msg[1], - len, - is_compressed, - remote_se)) - { - /* decompression failed */ - strata_estimator_destroy (remote_se); - fail_union_operation (op); - return; - } - GNUNET_assert (NULL != op->state->se); - diff = strata_estimator_difference (remote_se, - op->state->se); + strata_estimator_read(&msg[1], + len, + is_compressed, + remote_se)) + { + /* decompression failed */ + strata_estimator_destroy(remote_se); + fail_union_operation(op); + return; + } + GNUNET_assert(NULL != op->state->se); + diff = strata_estimator_difference(remote_se, + op->state->se); if (diff > 200) diff = diff * 3 / 2; - strata_estimator_destroy (remote_se); - strata_estimator_destroy (op->state->se); + strata_estimator_destroy(remote_se); + strata_estimator_destroy(op->state->se); op->state->se = NULL; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "got se diff=%d, using ibf size %d\n", - diff, - 1U << get_order_from_difference (diff)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "got se diff=%d, using ibf size %d\n", + diff, + 1U << get_order_from_difference(diff)); { char *set_debug; - set_debug = getenv ("GNUNET_SET_BENCHMARK"); - if ( (NULL != set_debug) && - (0 == strcmp (set_debug, "1")) ) - { - FILE *f = fopen ("set.log", "a"); - fprintf (f, "%llu\n", (unsigned long long) diff); - fclose (f); - } - } - - if ( (GNUNET_YES == op->byzantine) && - (other_size < op->byzantine_lower_bound) ) - { - GNUNET_break (0); - fail_union_operation (op); - return; + set_debug = getenv("GNUNET_SET_BENCHMARK"); + if ((NULL != set_debug) && + (0 == strcmp(set_debug, "1"))) + { + FILE *f = fopen("set.log", "a"); + fprintf(f, "%llu\n", (unsigned long long)diff); + fclose(f); + } } - if ( (GNUNET_YES == op->force_full) || - (diff > op->state->initial_size / 4) || - (0 == other_size) ) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Deciding to go for full set transmission (diff=%d, own set=%u)\n", - diff, - op->state->initial_size); - GNUNET_STATISTICS_update (_GSS_statistics, - "# of full sends", - 1, - GNUNET_NO); - if ( (op->state->initial_size <= other_size) || - (0 == other_size) ) + if ((GNUNET_YES == op->byzantine) && + (other_size < op->byzantine_lower_bound)) { - send_full_set (op); + GNUNET_break(0); + fail_union_operation(op); + return; } - else - { - struct GNUNET_MQ_Envelope *ev; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Telling other peer that we expect its full set\n"); - op->state->phase = PHASE_EXPECT_IBF; - ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL); - GNUNET_MQ_send (op->mq, - ev); + if ((GNUNET_YES == op->force_full) || + (diff > op->state->initial_size / 4) || + (0 == other_size)) + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Deciding to go for full set transmission (diff=%d, own set=%u)\n", + diff, + op->state->initial_size); + GNUNET_STATISTICS_update(_GSS_statistics, + "# of full sends", + 1, + GNUNET_NO); + if ((op->state->initial_size <= other_size) || + (0 == other_size)) + { + send_full_set(op); + } + else + { + struct GNUNET_MQ_Envelope *ev; + + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Telling other peer that we expect its full set\n"); + op->state->phase = PHASE_EXPECT_IBF; + ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL); + GNUNET_MQ_send(op->mq, + ev); + } } - } else - { - GNUNET_STATISTICS_update (_GSS_statistics, - "# of ibf sends", - 1, - GNUNET_NO); - if (GNUNET_OK != - send_ibf (op, - get_order_from_difference (diff))) - { - /* Internal error, best we can do is shut the connection */ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to send IBF, closing connection\n"); - fail_union_operation (op); - return; + { + GNUNET_STATISTICS_update(_GSS_statistics, + "# of ibf sends", + 1, + GNUNET_NO); + if (GNUNET_OK != + send_ibf(op, + get_order_from_difference(diff))) + { + /* Internal error, best we can do is shut the connection */ + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to send IBF, closing connection\n"); + fail_union_operation(op); + return; + } } - } - GNUNET_CADET_receive_done (op->channel); + GNUNET_CADET_receive_done(op->channel); } @@ -978,9 +974,9 @@ handle_union_p2p_strata_estimator (void *cls, * @param value the key entry */ static int -send_offers_iterator (void *cls, - uint32_t key, - void *value) +send_offers_iterator(void *cls, + uint32_t key, + void *value) { struct SendElementClosure *sec = cls; struct Operation *op = sec->op; @@ -992,17 +988,17 @@ send_offers_iterator (void *cls, if (ke->ibf_key.key_val != sec->ibf_key.key_val) return GNUNET_YES; - ev = GNUNET_MQ_msg_header_extra (mh, - sizeof (struct GNUNET_HashCode), - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER); - - GNUNET_assert (NULL != ev); - *(struct GNUNET_HashCode *) &mh[1] = ke->element->element_hash; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "[OP %x] sending element offer (%s) to peer\n", - (void *) op, - GNUNET_h2s (&ke->element->element_hash)); - GNUNET_MQ_send (op->mq, ev); + ev = GNUNET_MQ_msg_header_extra(mh, + sizeof(struct GNUNET_HashCode), + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER); + + GNUNET_assert(NULL != ev); + *(struct GNUNET_HashCode *)&mh[1] = ke->element->element_hash; + LOG(GNUNET_ERROR_TYPE_DEBUG, + "[OP %x] sending element offer (%s) to peer\n", + (void *)op, + GNUNET_h2s(&ke->element->element_hash)); + GNUNET_MQ_send(op->mq, ev); return GNUNET_YES; } @@ -1014,17 +1010,17 @@ send_offers_iterator (void *cls, * @param ibf_key IBF key of interest */ static void -send_offers_for_key (struct Operation *op, - struct IBF_Key ibf_key) +send_offers_for_key(struct Operation *op, + struct IBF_Key ibf_key) { struct SendElementClosure send_cls; send_cls.ibf_key = ibf_key; send_cls.op = op; - (void) GNUNET_CONTAINER_multihashmap32_get_multiple (op->state->key_to_element, - (uint32_t) ibf_key.key_val, - &send_offers_iterator, - &send_cls); + (void)GNUNET_CONTAINER_multihashmap32_get_multiple(op->state->key_to_element, + (uint32_t)ibf_key.key_val, + &send_offers_iterator, + &send_cls); } @@ -1036,7 +1032,7 @@ send_offers_for_key (struct Operation *op, * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -decode_and_send (struct Operation *op) +decode_and_send(struct Operation *op) { struct IBF_Key key; struct IBF_Key last_key; @@ -1044,147 +1040,147 @@ decode_and_send (struct Operation *op) unsigned int num_decoded; struct InvertibleBloomFilter *diff_ibf; - GNUNET_assert (PHASE_INVENTORY_ACTIVE == op->state->phase); + GNUNET_assert(PHASE_INVENTORY_ACTIVE == op->state->phase); if (GNUNET_OK != - prepare_ibf (op, - op->state->remote_ibf->size)) - { - GNUNET_break (0); - /* allocation failed */ - return GNUNET_SYSERR; - } - diff_ibf = ibf_dup (op->state->local_ibf); - ibf_subtract (diff_ibf, - op->state->remote_ibf); + prepare_ibf(op, + op->state->remote_ibf->size)) + { + GNUNET_break(0); + /* allocation failed */ + return GNUNET_SYSERR; + } + diff_ibf = ibf_dup(op->state->local_ibf); + ibf_subtract(diff_ibf, + op->state->remote_ibf); - ibf_destroy (op->state->remote_ibf); + ibf_destroy(op->state->remote_ibf); op->state->remote_ibf = NULL; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "decoding IBF (size=%u)\n", - diff_ibf->size); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "decoding IBF (size=%u)\n", + diff_ibf->size); num_decoded = 0; key.key_val = 0; /* just to avoid compiler thinking we use undef'ed variable */ while (1) - { - int res; - int cycle_detected = GNUNET_NO; + { + int res; + int cycle_detected = GNUNET_NO; - last_key = key; + last_key = key; - res = ibf_decode (diff_ibf, &side, &key); - if (res == GNUNET_OK) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "decoded ibf key %lx\n", - (unsigned long) key.key_val); - num_decoded += 1; - if ( (num_decoded > diff_ibf->size) || - ( (num_decoded > 1) && - (last_key.key_val == key.key_val) ) ) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "detected cyclic ibf (decoded %u/%u)\n", - num_decoded, - diff_ibf->size); - cycle_detected = GNUNET_YES; - } - } - if ( (GNUNET_SYSERR == res) || - (GNUNET_YES == cycle_detected) ) - { - int next_order; - next_order = 0; - while (1<size) - next_order++; - next_order++; - if (next_order <= MAX_IBF_ORDER) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "decoding failed, sending larger ibf (size %u)\n", - 1<state->salt_send++; - if (GNUNET_OK != - send_ibf (op, next_order)) + res = ibf_decode(diff_ibf, &side, &key); + if (res == GNUNET_OK) { - /* Internal error, best we can do is shut the connection */ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to send IBF, closing connection\n"); - fail_union_operation (op); - ibf_destroy (diff_ibf); - return GNUNET_SYSERR; + LOG(GNUNET_ERROR_TYPE_DEBUG, + "decoded ibf key %lx\n", + (unsigned long)key.key_val); + num_decoded += 1; + if ((num_decoded > diff_ibf->size) || + ((num_decoded > 1) && + (last_key.key_val == key.key_val))) + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "detected cyclic ibf (decoded %u/%u)\n", + num_decoded, + diff_ibf->size); + cycle_detected = GNUNET_YES; + } } - } - else - { - GNUNET_STATISTICS_update (_GSS_statistics, - "# of failed union operations (too large)", - 1, - GNUNET_NO); - // XXX: Send the whole set, element-by-element - LOG (GNUNET_ERROR_TYPE_ERROR, - "set union failed: reached ibf limit\n"); - fail_union_operation (op); - ibf_destroy (diff_ibf); - return GNUNET_SYSERR; - } - break; - } - if (GNUNET_NO == res) - { - struct GNUNET_MQ_Envelope *ev; - - LOG (GNUNET_ERROR_TYPE_DEBUG, - "transmitted all values, sending DONE\n"); - ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE); - GNUNET_MQ_send (op->mq, ev); - /* We now wait until we get a DONE message back - * and then wait for our MQ to be flushed and all our - * demands be delivered. */ - break; - } - if (1 == side) - { - struct IBF_Key unsalted_key; + if ((GNUNET_SYSERR == res) || + (GNUNET_YES == cycle_detected)) + { + int next_order; + next_order = 0; + while (1 << next_order < diff_ibf->size) + next_order++; + next_order++; + if (next_order <= MAX_IBF_ORDER) + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "decoding failed, sending larger ibf (size %u)\n", + 1 << next_order); + GNUNET_STATISTICS_update(_GSS_statistics, + "# of IBF retries", + 1, + GNUNET_NO); + op->state->salt_send++; + if (GNUNET_OK != + send_ibf(op, next_order)) + { + /* Internal error, best we can do is shut the connection */ + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to send IBF, closing connection\n"); + fail_union_operation(op); + ibf_destroy(diff_ibf); + return GNUNET_SYSERR; + } + } + else + { + GNUNET_STATISTICS_update(_GSS_statistics, + "# of failed union operations (too large)", + 1, + GNUNET_NO); + // XXX: Send the whole set, element-by-element + LOG(GNUNET_ERROR_TYPE_ERROR, + "set union failed: reached ibf limit\n"); + fail_union_operation(op); + ibf_destroy(diff_ibf); + return GNUNET_SYSERR; + } + break; + } + if (GNUNET_NO == res) + { + struct GNUNET_MQ_Envelope *ev; + + LOG(GNUNET_ERROR_TYPE_DEBUG, + "transmitted all values, sending DONE\n"); + ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE); + GNUNET_MQ_send(op->mq, ev); + /* We now wait until we get a DONE message back + * and then wait for our MQ to be flushed and all our + * demands be delivered. */ + break; + } + if (1 == side) + { + struct IBF_Key unsalted_key; - unsalt_key (&key, - op->state->salt_receive, - &unsalted_key); - send_offers_for_key (op, - unsalted_key); - } - else if (-1 == side) - { - struct GNUNET_MQ_Envelope *ev; - struct InquiryMessage *msg; - - /* It may be nice to merge multiple requests, but with CADET's corking it is not worth - * the effort additional complexity. */ - ev = GNUNET_MQ_msg_extra (msg, - sizeof (struct IBF_Key), - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY); - msg->salt = htonl (op->state->salt_receive); - GNUNET_memcpy (&msg[1], - &key, - sizeof (struct IBF_Key)); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "sending element inquiry for IBF key %lx\n", - (unsigned long) key.key_val); - GNUNET_MQ_send (op->mq, ev); - } - else - { - GNUNET_assert (0); + unsalt_key(&key, + op->state->salt_receive, + &unsalted_key); + send_offers_for_key(op, + unsalted_key); + } + else if (-1 == side) + { + struct GNUNET_MQ_Envelope *ev; + struct InquiryMessage *msg; + + /* It may be nice to merge multiple requests, but with CADET's corking it is not worth + * the effort additional complexity. */ + ev = GNUNET_MQ_msg_extra(msg, + sizeof(struct IBF_Key), + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY); + msg->salt = htonl(op->state->salt_receive); + GNUNET_memcpy(&msg[1], + &key, + sizeof(struct IBF_Key)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "sending element inquiry for IBF key %lx\n", + (unsigned long)key.key_val); + GNUNET_MQ_send(op->mq, ev); + } + else + { + GNUNET_assert(0); + } } - } - ibf_destroy (diff_ibf); + ibf_destroy(diff_ibf); return GNUNET_OK; } @@ -1200,52 +1196,52 @@ decode_and_send (struct Operation *op) * @return #GNUNET_OK if @a msg is well-formed */ int -check_union_p2p_ibf (void *cls, - const struct IBFMessage *msg) +check_union_p2p_ibf(void *cls, + const struct IBFMessage *msg) { struct Operation *op = cls; unsigned int buckets_in_message; if (GNUNET_SET_OPERATION_UNION != op->set->operation) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - buckets_in_message = (ntohs (msg->header.size) - sizeof *msg) / IBF_BUCKET_SIZE; + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + buckets_in_message = (ntohs(msg->header.size) - sizeof *msg) / IBF_BUCKET_SIZE; if (0 == buckets_in_message) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if ((ntohs (msg->header.size) - sizeof *msg) != buckets_in_message * IBF_BUCKET_SIZE) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (op->state->phase == PHASE_EXPECT_IBF_CONT) - { - if (ntohl (msg->offset) != op->state->ibf_buckets_received) { - GNUNET_break_op (0); + GNUNET_break_op(0); return GNUNET_SYSERR; } - if (1<order != op->state->remote_ibf->size) + if ((ntohs(msg->header.size) - sizeof *msg) != buckets_in_message * IBF_BUCKET_SIZE) { - GNUNET_break_op (0); + GNUNET_break_op(0); return GNUNET_SYSERR; } - if (ntohl (msg->salt) != op->state->salt_receive) + if (op->state->phase == PHASE_EXPECT_IBF_CONT) { - GNUNET_break_op (0); + if (ntohl(msg->offset) != op->state->ibf_buckets_received) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + if (1 << msg->order != op->state->remote_ibf->size) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + if (ntohl(msg->salt) != op->state->salt_receive) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + } + else if ((op->state->phase != PHASE_INVENTORY_PASSIVE) && + (op->state->phase != PHASE_EXPECT_IBF)) + { + GNUNET_break_op(0); return GNUNET_SYSERR; } - } - else if ( (op->state->phase != PHASE_INVENTORY_PASSIVE) && - (op->state->phase != PHASE_EXPECT_IBF) ) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } return GNUNET_OK; } @@ -1261,71 +1257,71 @@ check_union_p2p_ibf (void *cls, * @param msg the header of the message */ void -handle_union_p2p_ibf (void *cls, - const struct IBFMessage *msg) +handle_union_p2p_ibf(void *cls, + const struct IBFMessage *msg) { struct Operation *op = cls; unsigned int buckets_in_message; - buckets_in_message = (ntohs (msg->header.size) - sizeof *msg) / IBF_BUCKET_SIZE; - if ( (op->state->phase == PHASE_INVENTORY_PASSIVE) || - (op->state->phase == PHASE_EXPECT_IBF) ) - { - op->state->phase = PHASE_EXPECT_IBF_CONT; - GNUNET_assert (NULL == op->state->remote_ibf); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Creating new ibf of size %u\n", - 1 << msg->order); - op->state->remote_ibf = ibf_create (1<order, SE_IBF_HASH_NUM); - op->state->salt_receive = ntohl (msg->salt); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Receiving new IBF with salt %u\n", - op->state->salt_receive); - if (NULL == op->state->remote_ibf) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to parse remote IBF, closing connection\n"); - fail_union_operation (op); - return; - } - op->state->ibf_buckets_received = 0; - if (0 != ntohl (msg->offset)) + buckets_in_message = (ntohs(msg->header.size) - sizeof *msg) / IBF_BUCKET_SIZE; + if ((op->state->phase == PHASE_INVENTORY_PASSIVE) || + (op->state->phase == PHASE_EXPECT_IBF)) { - GNUNET_break_op (0); - fail_union_operation (op); - return; + op->state->phase = PHASE_EXPECT_IBF_CONT; + GNUNET_assert(NULL == op->state->remote_ibf); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Creating new ibf of size %u\n", + 1 << msg->order); + op->state->remote_ibf = ibf_create(1 << msg->order, SE_IBF_HASH_NUM); + op->state->salt_receive = ntohl(msg->salt); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Receiving new IBF with salt %u\n", + op->state->salt_receive); + if (NULL == op->state->remote_ibf) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to parse remote IBF, closing connection\n"); + fail_union_operation(op); + return; + } + op->state->ibf_buckets_received = 0; + if (0 != ntohl(msg->offset)) + { + GNUNET_break_op(0); + fail_union_operation(op); + return; + } } - } else - { - GNUNET_assert (op->state->phase == PHASE_EXPECT_IBF_CONT); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received more of IBF\n"); - } - GNUNET_assert (NULL != op->state->remote_ibf); + { + GNUNET_assert(op->state->phase == PHASE_EXPECT_IBF_CONT); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Received more of IBF\n"); + } + GNUNET_assert(NULL != op->state->remote_ibf); - ibf_read_slice (&msg[1], - op->state->ibf_buckets_received, - buckets_in_message, - op->state->remote_ibf); + ibf_read_slice(&msg[1], + op->state->ibf_buckets_received, + buckets_in_message, + op->state->remote_ibf); op->state->ibf_buckets_received += buckets_in_message; if (op->state->ibf_buckets_received == op->state->remote_ibf->size) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "received full ibf\n"); - op->state->phase = PHASE_INVENTORY_ACTIVE; - if (GNUNET_OK != - decode_and_send (op)) - { - /* Internal error, best we can do is shut down */ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to decode IBF, closing connection\n"); - fail_union_operation (op); - return; + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "received full ibf\n"); + op->state->phase = PHASE_INVENTORY_ACTIVE; + if (GNUNET_OK != + decode_and_send(op)) + { + /* Internal error, best we can do is shut down */ + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to decode IBF, closing connection\n"); + fail_union_operation(op); + return; + } } - } - GNUNET_CADET_receive_done (op->channel); + GNUNET_CADET_receive_done(op->channel); } @@ -1338,33 +1334,33 @@ handle_union_p2p_ibf (void *cls, * @param status status to send with the new element */ static void -send_client_element (struct Operation *op, - struct GNUNET_SET_Element *element, - int status) +send_client_element(struct Operation *op, + struct GNUNET_SET_Element *element, + int status) { struct GNUNET_MQ_Envelope *ev; struct GNUNET_SET_ResultMessage *rm; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "sending element (size %u) to client\n", - element->size); - GNUNET_assert (0 != op->client_request_id); - ev = GNUNET_MQ_msg_extra (rm, element->size, GNUNET_MESSAGE_TYPE_SET_RESULT); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "sending element (size %u) to client\n", + element->size); + GNUNET_assert(0 != op->client_request_id); + ev = GNUNET_MQ_msg_extra(rm, element->size, GNUNET_MESSAGE_TYPE_SET_RESULT); if (NULL == ev) - { - GNUNET_MQ_discard (ev); - GNUNET_break (0); - return; - } - rm->result_status = htons (status); - rm->request_id = htonl (op->client_request_id); - rm->element_type = htons (element->element_type); - rm->current_size = GNUNET_htonll (GNUNET_CONTAINER_multihashmap32_size (op->state->key_to_element)); - GNUNET_memcpy (&rm[1], - element->data, - element->size); - GNUNET_MQ_send (op->set->cs->mq, - ev); + { + GNUNET_MQ_discard(ev); + GNUNET_break(0); + return; + } + rm->result_status = htons(status); + rm->request_id = htonl(op->client_request_id); + rm->element_type = htons(element->element_type); + rm->current_size = GNUNET_htonll(GNUNET_CONTAINER_multihashmap32_size(op->state->key_to_element)); + GNUNET_memcpy(&rm[1], + element->data, + element->size); + GNUNET_MQ_send(op->set->cs->mq, + ev); } @@ -1375,49 +1371,50 @@ send_client_element (struct Operation *op, * @param cls operation to destroy */ static void -send_client_done (void *cls) +send_client_done(void *cls) { struct Operation *op = cls; struct GNUNET_MQ_Envelope *ev; struct GNUNET_SET_ResultMessage *rm; if (GNUNET_YES == op->state->client_done_sent) - { - return; - } + { + return; + } - if (PHASE_DONE != op->state->phase) { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Union operation failed\n"); - GNUNET_STATISTICS_update (_GSS_statistics, - "# Union operations failed", - 1, - GNUNET_NO); - ev = GNUNET_MQ_msg (rm, GNUNET_MESSAGE_TYPE_SET_RESULT); - rm->result_status = htons (GNUNET_SET_STATUS_FAILURE); - rm->request_id = htonl (op->client_request_id); - rm->element_type = htons (0); - GNUNET_MQ_send (op->set->cs->mq, - ev); - return; - } + if (PHASE_DONE != op->state->phase) + { + LOG(GNUNET_ERROR_TYPE_WARNING, + "Union operation failed\n"); + GNUNET_STATISTICS_update(_GSS_statistics, + "# Union operations failed", + 1, + GNUNET_NO); + ev = GNUNET_MQ_msg(rm, GNUNET_MESSAGE_TYPE_SET_RESULT); + rm->result_status = htons(GNUNET_SET_STATUS_FAILURE); + rm->request_id = htonl(op->client_request_id); + rm->element_type = htons(0); + GNUNET_MQ_send(op->set->cs->mq, + ev); + return; + } op->state->client_done_sent = GNUNET_YES; - GNUNET_STATISTICS_update (_GSS_statistics, - "# Union operations succeeded", - 1, - GNUNET_NO); - LOG (GNUNET_ERROR_TYPE_INFO, - "Signalling client that union operation is done\n"); - ev = GNUNET_MQ_msg (rm, - GNUNET_MESSAGE_TYPE_SET_RESULT); - rm->request_id = htonl (op->client_request_id); - rm->result_status = htons (GNUNET_SET_STATUS_DONE); - rm->element_type = htons (0); - rm->current_size = GNUNET_htonll (GNUNET_CONTAINER_multihashmap32_size (op->state->key_to_element)); - GNUNET_MQ_send (op->set->cs->mq, - ev); + GNUNET_STATISTICS_update(_GSS_statistics, + "# Union operations succeeded", + 1, + GNUNET_NO); + LOG(GNUNET_ERROR_TYPE_INFO, + "Signalling client that union operation is done\n"); + ev = GNUNET_MQ_msg(rm, + GNUNET_MESSAGE_TYPE_SET_RESULT); + rm->request_id = htonl(op->client_request_id); + rm->result_status = htons(GNUNET_SET_STATUS_DONE); + rm->element_type = htons(0); + rm->current_size = GNUNET_htonll(GNUNET_CONTAINER_multihashmap32_size(op->state->key_to_element)); + GNUNET_MQ_send(op->set->cs->mq, + ev); } @@ -1427,41 +1424,41 @@ send_client_done (void *cls) * @param op operation to check */ static void -maybe_finish (struct Operation *op) +maybe_finish(struct Operation *op) { unsigned int num_demanded; - num_demanded = GNUNET_CONTAINER_multihashmap_size (op->state->demanded_hashes); + num_demanded = GNUNET_CONTAINER_multihashmap_size(op->state->demanded_hashes); if (PHASE_FINISH_WAITING == op->state->phase) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "In PHASE_FINISH_WAITING, pending %u demands\n", - num_demanded); - if (0 == num_demanded) { - struct GNUNET_MQ_Envelope *ev; - - op->state->phase = PHASE_DONE; - ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE); - GNUNET_MQ_send (op->mq, - ev); - /* We now wait until the other peer sends P2P_OVER - * after it got all elements from us. */ + LOG(GNUNET_ERROR_TYPE_DEBUG, + "In PHASE_FINISH_WAITING, pending %u demands\n", + num_demanded); + if (0 == num_demanded) + { + struct GNUNET_MQ_Envelope *ev; + + op->state->phase = PHASE_DONE; + ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE); + GNUNET_MQ_send(op->mq, + ev); + /* We now wait until the other peer sends P2P_OVER + * after it got all elements from us. */ + } } - } if (PHASE_FINISH_CLOSING == op->state->phase) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "In PHASE_FINISH_CLOSING, pending %u demands\n", - num_demanded); - if (0 == num_demanded) { - op->state->phase = PHASE_DONE; - send_client_done (op); - _GSS_operation_destroy2 (op); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "In PHASE_FINISH_CLOSING, pending %u demands\n", + num_demanded); + if (0 == num_demanded) + { + op->state->phase = PHASE_DONE; + send_client_done(op); + _GSS_operation_destroy2(op); + } } - } } @@ -1472,21 +1469,21 @@ maybe_finish (struct Operation *op) * @param emsg the message */ int -check_union_p2p_elements (void *cls, - const struct GNUNET_SET_ElementMessage *emsg) +check_union_p2p_elements(void *cls, + const struct GNUNET_SET_ElementMessage *emsg) { struct Operation *op = cls; if (GNUNET_SET_OPERATION_UNION != op->set->operation) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (0 == GNUNET_CONTAINER_multihashmap_size (op->state->demanded_hashes)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + if (0 == GNUNET_CONTAINER_multihashmap_size(op->state->demanded_hashes)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -1500,96 +1497,98 @@ check_union_p2p_elements (void *cls, * @param emsg the message */ void -handle_union_p2p_elements (void *cls, - const struct GNUNET_SET_ElementMessage *emsg) +handle_union_p2p_elements(void *cls, + const struct GNUNET_SET_ElementMessage *emsg) { struct Operation *op = cls; struct ElementEntry *ee; struct KeyEntry *ke; uint16_t element_size; - element_size = ntohs (emsg->header.size) - sizeof (struct GNUNET_SET_ElementMessage); - ee = GNUNET_malloc (sizeof (struct ElementEntry) + element_size); - GNUNET_memcpy (&ee[1], - &emsg[1], - element_size); + element_size = ntohs(emsg->header.size) - sizeof(struct GNUNET_SET_ElementMessage); + ee = GNUNET_malloc(sizeof(struct ElementEntry) + element_size); + GNUNET_memcpy(&ee[1], + &emsg[1], + element_size); ee->element.size = element_size; ee->element.data = &ee[1]; - ee->element.element_type = ntohs (emsg->element_type); + ee->element.element_type = ntohs(emsg->element_type); ee->remote = GNUNET_YES; - GNUNET_SET_element_hash (&ee->element, - &ee->element_hash); + GNUNET_SET_element_hash(&ee->element, + &ee->element_hash); if (GNUNET_NO == - GNUNET_CONTAINER_multihashmap_remove (op->state->demanded_hashes, - &ee->element_hash, - NULL)) - { - /* We got something we didn't demand, since it's not in our map. */ - GNUNET_break_op (0); - fail_union_operation (op); - return; - } + GNUNET_CONTAINER_multihashmap_remove(op->state->demanded_hashes, + &ee->element_hash, + NULL)) + { + /* We got something we didn't demand, since it's not in our map. */ + GNUNET_break_op(0); + fail_union_operation(op); + return; + } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Got element (size %u, hash %s) from peer\n", - (unsigned int) element_size, - GNUNET_h2s (&ee->element_hash)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Got element (size %u, hash %s) from peer\n", + (unsigned int)element_size, + GNUNET_h2s(&ee->element_hash)); - GNUNET_STATISTICS_update (_GSS_statistics, - "# received elements", - 1, - GNUNET_NO); - GNUNET_STATISTICS_update (_GSS_statistics, - "# exchanged elements", - 1, - GNUNET_NO); + GNUNET_STATISTICS_update(_GSS_statistics, + "# received elements", + 1, + GNUNET_NO); + GNUNET_STATISTICS_update(_GSS_statistics, + "# exchanged elements", + 1, + GNUNET_NO); op->state->received_total++; - ke = op_get_element (op, &ee->element_hash); + ke = op_get_element(op, &ee->element_hash); if (NULL != ke) - { - /* Got repeated element. Should not happen since - * we track demands. */ - GNUNET_STATISTICS_update (_GSS_statistics, - "# repeated elements", - 1, - GNUNET_NO); - ke->received = GNUNET_YES; - GNUNET_free (ee); - } + { + /* Got repeated element. Should not happen since + * we track demands. */ + GNUNET_STATISTICS_update(_GSS_statistics, + "# repeated elements", + 1, + GNUNET_NO); + ke->received = GNUNET_YES; + GNUNET_free(ee); + } else - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Registering new element from remote peer\n"); - op->state->received_fresh++; - op_register_element (op, ee, GNUNET_YES); - /* only send results immediately if the client wants it */ - switch (op->result_mode) - { - case GNUNET_SET_RESULT_ADDED: - send_client_element (op, &ee->element, GNUNET_SET_STATUS_OK); - break; - case GNUNET_SET_RESULT_SYMMETRIC: - send_client_element (op, &ee->element, GNUNET_SET_STATUS_ADD_LOCAL); - break; - default: - /* Result mode not supported, should have been caught earlier. */ - GNUNET_break (0); - break; + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Registering new element from remote peer\n"); + op->state->received_fresh++; + op_register_element(op, ee, GNUNET_YES); + /* only send results immediately if the client wants it */ + switch (op->result_mode) + { + case GNUNET_SET_RESULT_ADDED: + send_client_element(op, &ee->element, GNUNET_SET_STATUS_OK); + break; + + case GNUNET_SET_RESULT_SYMMETRIC: + send_client_element(op, &ee->element, GNUNET_SET_STATUS_ADD_LOCAL); + break; + + default: + /* Result mode not supported, should have been caught earlier. */ + GNUNET_break(0); + break; + } } - } - if ( (op->state->received_total > 8) && - (op->state->received_fresh < op->state->received_total / 3) ) - { - /* The other peer gave us lots of old elements, there's something wrong. */ - GNUNET_break_op (0); - fail_union_operation (op); - return; - } - GNUNET_CADET_receive_done (op->channel); - maybe_finish (op); + if ((op->state->received_total > 8) && + (op->state->received_fresh < op->state->received_total / 3)) + { + /* The other peer gave us lots of old elements, there's something wrong. */ + GNUNET_break_op(0); + fail_union_operation(op); + return; + } + GNUNET_CADET_receive_done(op->channel); + maybe_finish(op); } @@ -1600,16 +1599,16 @@ handle_union_p2p_elements (void *cls, * @param emsg the message */ int -check_union_p2p_full_element (void *cls, - const struct GNUNET_SET_ElementMessage *emsg) +check_union_p2p_full_element(void *cls, + const struct GNUNET_SET_ElementMessage *emsg) { struct Operation *op = cls; if (GNUNET_SET_OPERATION_UNION != op->set->operation) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } // FIXME: check that we expect full elements here? return GNUNET_OK; } @@ -1622,87 +1621,89 @@ check_union_p2p_full_element (void *cls, * @param emsg the message */ void -handle_union_p2p_full_element (void *cls, - const struct GNUNET_SET_ElementMessage *emsg) +handle_union_p2p_full_element(void *cls, + const struct GNUNET_SET_ElementMessage *emsg) { struct Operation *op = cls; struct ElementEntry *ee; struct KeyEntry *ke; uint16_t element_size; - element_size = ntohs (emsg->header.size) - sizeof (struct GNUNET_SET_ElementMessage); - ee = GNUNET_malloc (sizeof (struct ElementEntry) + element_size); - GNUNET_memcpy (&ee[1], &emsg[1], element_size); + element_size = ntohs(emsg->header.size) - sizeof(struct GNUNET_SET_ElementMessage); + ee = GNUNET_malloc(sizeof(struct ElementEntry) + element_size); + GNUNET_memcpy(&ee[1], &emsg[1], element_size); ee->element.size = element_size; ee->element.data = &ee[1]; - ee->element.element_type = ntohs (emsg->element_type); + ee->element.element_type = ntohs(emsg->element_type); ee->remote = GNUNET_YES; - GNUNET_SET_element_hash (&ee->element, &ee->element_hash); - - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Got element (full diff, size %u, hash %s) from peer\n", - (unsigned int) element_size, - GNUNET_h2s (&ee->element_hash)); - - GNUNET_STATISTICS_update (_GSS_statistics, - "# received elements", - 1, - GNUNET_NO); - GNUNET_STATISTICS_update (_GSS_statistics, - "# exchanged elements", - 1, - GNUNET_NO); + GNUNET_SET_element_hash(&ee->element, &ee->element_hash); + + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Got element (full diff, size %u, hash %s) from peer\n", + (unsigned int)element_size, + GNUNET_h2s(&ee->element_hash)); + + GNUNET_STATISTICS_update(_GSS_statistics, + "# received elements", + 1, + GNUNET_NO); + GNUNET_STATISTICS_update(_GSS_statistics, + "# exchanged elements", + 1, + GNUNET_NO); op->state->received_total++; - ke = op_get_element (op, &ee->element_hash); + ke = op_get_element(op, &ee->element_hash); if (NULL != ke) - { - /* Got repeated element. Should not happen since - * we track demands. */ - GNUNET_STATISTICS_update (_GSS_statistics, - "# repeated elements", - 1, - GNUNET_NO); - ke->received = GNUNET_YES; - GNUNET_free (ee); - } + { + /* Got repeated element. Should not happen since + * we track demands. */ + GNUNET_STATISTICS_update(_GSS_statistics, + "# repeated elements", + 1, + GNUNET_NO); + ke->received = GNUNET_YES; + GNUNET_free(ee); + } else - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Registering new element from remote peer\n"); - op->state->received_fresh++; - op_register_element (op, ee, GNUNET_YES); - /* only send results immediately if the client wants it */ - switch (op->result_mode) - { - case GNUNET_SET_RESULT_ADDED: - send_client_element (op, &ee->element, GNUNET_SET_STATUS_OK); - break; - case GNUNET_SET_RESULT_SYMMETRIC: - send_client_element (op, &ee->element, GNUNET_SET_STATUS_ADD_LOCAL); - break; - default: - /* Result mode not supported, should have been caught earlier. */ - GNUNET_break (0); - break; + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Registering new element from remote peer\n"); + op->state->received_fresh++; + op_register_element(op, ee, GNUNET_YES); + /* only send results immediately if the client wants it */ + switch (op->result_mode) + { + case GNUNET_SET_RESULT_ADDED: + send_client_element(op, &ee->element, GNUNET_SET_STATUS_OK); + break; + + case GNUNET_SET_RESULT_SYMMETRIC: + send_client_element(op, &ee->element, GNUNET_SET_STATUS_ADD_LOCAL); + break; + + default: + /* Result mode not supported, should have been caught earlier. */ + GNUNET_break(0); + break; + } } - } - if ( (GNUNET_YES == op->byzantine) && - (op->state->received_total > 384 + op->state->received_fresh * 4) && - (op->state->received_fresh < op->state->received_total / 6) ) - { - /* The other peer gave us lots of old elements, there's something wrong. */ - LOG (GNUNET_ERROR_TYPE_ERROR, - "Other peer sent only %llu/%llu fresh elements, failing operation\n", - (unsigned long long) op->state->received_fresh, - (unsigned long long) op->state->received_total); - GNUNET_break_op (0); - fail_union_operation (op); - return; - } - GNUNET_CADET_receive_done (op->channel); + if ((GNUNET_YES == op->byzantine) && + (op->state->received_total > 384 + op->state->received_fresh * 4) && + (op->state->received_fresh < op->state->received_total / 6)) + { + /* The other peer gave us lots of old elements, there's something wrong. */ + LOG(GNUNET_ERROR_TYPE_ERROR, + "Other peer sent only %llu/%llu fresh elements, failing operation\n", + (unsigned long long)op->state->received_fresh, + (unsigned long long)op->state->received_total); + GNUNET_break_op(0); + fail_union_operation(op); + return; + } + GNUNET_CADET_receive_done(op->channel); } @@ -1714,30 +1715,30 @@ handle_union_p2p_full_element (void *cls, * @param msg the message */ int -check_union_p2p_inquiry (void *cls, - const struct InquiryMessage *msg) +check_union_p2p_inquiry(void *cls, + const struct InquiryMessage *msg) { struct Operation *op = cls; unsigned int num_keys; if (GNUNET_SET_OPERATION_UNION != op->set->operation) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } if (op->state->phase != PHASE_INVENTORY_PASSIVE) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - num_keys = (ntohs (msg->header.size) - sizeof (struct InquiryMessage)) - / sizeof (struct IBF_Key); - if ((ntohs (msg->header.size) - sizeof (struct InquiryMessage)) - != num_keys * sizeof (struct IBF_Key)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + num_keys = (ntohs(msg->header.size) - sizeof(struct InquiryMessage)) + / sizeof(struct IBF_Key); + if ((ntohs(msg->header.size) - sizeof(struct InquiryMessage)) + != num_keys * sizeof(struct IBF_Key)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -1750,30 +1751,30 @@ check_union_p2p_inquiry (void *cls, * @param msg the message */ void -handle_union_p2p_inquiry (void *cls, - const struct InquiryMessage *msg) +handle_union_p2p_inquiry(void *cls, + const struct InquiryMessage *msg) { struct Operation *op = cls; const struct IBF_Key *ibf_key; unsigned int num_keys; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received union inquiry\n"); - num_keys = (ntohs (msg->header.size) - sizeof (struct InquiryMessage)) - / sizeof (struct IBF_Key); - ibf_key = (const struct IBF_Key *) &msg[1]; + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Received union inquiry\n"); + num_keys = (ntohs(msg->header.size) - sizeof(struct InquiryMessage)) + / sizeof(struct IBF_Key); + ibf_key = (const struct IBF_Key *)&msg[1]; while (0 != num_keys--) - { - struct IBF_Key unsalted_key; - - unsalt_key (ibf_key, - ntohl (msg->salt), - &unsalted_key); - send_offers_for_key (op, - unsalted_key); - ibf_key++; - } - GNUNET_CADET_receive_done (op->channel); + { + struct IBF_Key unsalted_key; + + unsalt_key(ibf_key, + ntohl(msg->salt), + &unsalted_key); + send_offers_for_key(op, + unsalted_key); + ibf_key++; + } + GNUNET_CADET_receive_done(op->channel); } @@ -1788,9 +1789,9 @@ handle_union_p2p_inquiry (void *cls, * #GNUNET_NO if not. */ static int -send_missing_full_elements_iter (void *cls, - uint32_t key, - void *value) +send_missing_full_elements_iter(void *cls, + uint32_t key, + void *value) { struct Operation *op = cls; struct KeyEntry *ke = value; @@ -1800,15 +1801,15 @@ send_missing_full_elements_iter (void *cls, if (GNUNET_YES == ke->received) return GNUNET_YES; - ev = GNUNET_MQ_msg_extra (emsg, - ee->element.size, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT); - GNUNET_memcpy (&emsg[1], - ee->element.data, - ee->element.size); - emsg->element_type = htons (ee->element.element_type); - GNUNET_MQ_send (op->mq, - ev); + ev = GNUNET_MQ_msg_extra(emsg, + ee->element.size, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT); + GNUNET_memcpy(&emsg[1], + ee->element.data, + ee->element.size); + emsg->element_type = htons(ee->element.element_type); + GNUNET_MQ_send(op->mq, + ev); return GNUNET_YES; } @@ -1820,30 +1821,30 @@ send_missing_full_elements_iter (void *cls, * @param mh the demand message */ void -handle_union_p2p_request_full (void *cls, - const struct GNUNET_MessageHeader *mh) +handle_union_p2p_request_full(void *cls, + const struct GNUNET_MessageHeader *mh) { struct Operation *op = cls; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received request for full set transmission\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Received request for full set transmission\n"); if (GNUNET_SET_OPERATION_UNION != op->set->operation) - { - GNUNET_break_op (0); - fail_union_operation (op); - return; - } + { + GNUNET_break_op(0); + fail_union_operation(op); + return; + } if (PHASE_EXPECT_IBF != op->state->phase) - { - GNUNET_break_op (0); - fail_union_operation (op); - return; - } + { + GNUNET_break_op(0); + fail_union_operation(op); + return; + } // FIXME: we need to check that our set is larger than the // byzantine_lower_bound by some threshold - send_full_set (op); - GNUNET_CADET_receive_done (op->channel); + send_full_set(op); + GNUNET_CADET_receive_done(op->channel); } @@ -1854,53 +1855,55 @@ handle_union_p2p_request_full (void *cls, * @param mh the demand message */ void -handle_union_p2p_full_done (void *cls, - const struct GNUNET_MessageHeader *mh) +handle_union_p2p_full_done(void *cls, + const struct GNUNET_MessageHeader *mh) { struct Operation *op = cls; switch (op->state->phase) - { - case PHASE_EXPECT_IBF: + { + case PHASE_EXPECT_IBF: { struct GNUNET_MQ_Envelope *ev; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "got FULL DONE, sending elements that other peer is missing\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "got FULL DONE, sending elements that other peer is missing\n"); /* send all the elements that did not come from the remote peer */ - GNUNET_CONTAINER_multihashmap32_iterate (op->state->key_to_element, - &send_missing_full_elements_iter, - op); + GNUNET_CONTAINER_multihashmap32_iterate(op->state->key_to_element, + &send_missing_full_elements_iter, + op); - ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE); - GNUNET_MQ_send (op->mq, - ev); + ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE); + GNUNET_MQ_send(op->mq, + ev); op->state->phase = PHASE_DONE; /* we now wait until the other peer sends us the OVER message*/ } break; - case PHASE_FULL_SENDING: + + case PHASE_FULL_SENDING: { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "got FULL DONE, finishing\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "got FULL DONE, finishing\n"); /* We sent the full set, and got the response for that. We're done. */ op->state->phase = PHASE_DONE; - GNUNET_CADET_receive_done (op->channel); - send_client_done (op); - _GSS_operation_destroy2 (op); + GNUNET_CADET_receive_done(op->channel); + send_client_done(op); + _GSS_operation_destroy2(op); return; } break; - default: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Handle full done phase is %u\n", - (unsigned) op->state->phase); - GNUNET_break_op (0); - fail_union_operation (op); - return; - } - GNUNET_CADET_receive_done (op->channel); + + default: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Handle full done phase is %u\n", + (unsigned)op->state->phase); + GNUNET_break_op(0); + fail_union_operation(op); + return; + } + GNUNET_CADET_receive_done(op->channel); } @@ -1913,25 +1916,25 @@ handle_union_p2p_full_done (void *cls, * @return #GNUNET_OK if @a mh is well-formed */ int -check_union_p2p_demand (void *cls, - const struct GNUNET_MessageHeader *mh) +check_union_p2p_demand(void *cls, + const struct GNUNET_MessageHeader *mh) { struct Operation *op = cls; unsigned int num_hashes; if (GNUNET_SET_OPERATION_UNION != op->set->operation) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - num_hashes = (ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader)) - / sizeof (struct GNUNET_HashCode); - if ((ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader)) - != num_hashes * sizeof (struct GNUNET_HashCode)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + num_hashes = (ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) + / sizeof(struct GNUNET_HashCode); + if ((ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) + != num_hashes * sizeof(struct GNUNET_HashCode)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -1944,8 +1947,8 @@ check_union_p2p_demand (void *cls, * @param mh the demand message */ void -handle_union_p2p_demand (void *cls, - const struct GNUNET_MessageHeader *mh) +handle_union_p2p_demand(void *cls, + const struct GNUNET_MessageHeader *mh) { struct Operation *op = cls; struct ElementEntry *ee; @@ -1954,58 +1957,60 @@ handle_union_p2p_demand (void *cls, unsigned int num_hashes; struct GNUNET_MQ_Envelope *ev; - num_hashes = (ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader)) - / sizeof (struct GNUNET_HashCode); - for (hash = (const struct GNUNET_HashCode *) &mh[1]; + num_hashes = (ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) + / sizeof(struct GNUNET_HashCode); + for (hash = (const struct GNUNET_HashCode *)&mh[1]; num_hashes > 0; hash++, num_hashes--) - { - ee = GNUNET_CONTAINER_multihashmap_get (op->set->content->elements, - hash); - if (NULL == ee) { - /* Demand for non-existing element. */ - GNUNET_break_op (0); - fail_union_operation (op); - return; - } - if (GNUNET_NO == _GSS_is_element_of_operation (ee, op)) - { - /* Probably confused lazily copied sets. */ - GNUNET_break_op (0); - fail_union_operation (op); - return; - } - ev = GNUNET_MQ_msg_extra (emsg, ee->element.size, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS); - GNUNET_memcpy (&emsg[1], ee->element.data, ee->element.size); - emsg->reserved = htons (0); - emsg->element_type = htons (ee->element.element_type); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "[OP %x] Sending demanded element (size %u, hash %s) to peer\n", - (void *) op, - (unsigned int) ee->element.size, - GNUNET_h2s (&ee->element_hash)); - GNUNET_MQ_send (op->mq, ev); - GNUNET_STATISTICS_update (_GSS_statistics, - "# exchanged elements", - 1, - GNUNET_NO); - - switch (op->result_mode) - { - case GNUNET_SET_RESULT_ADDED: - /* Nothing to do. */ - break; - case GNUNET_SET_RESULT_SYMMETRIC: - send_client_element (op, &ee->element, GNUNET_SET_STATUS_ADD_REMOTE); - break; - default: - /* Result mode not supported, should have been caught earlier. */ - GNUNET_break (0); - break; + ee = GNUNET_CONTAINER_multihashmap_get(op->set->content->elements, + hash); + if (NULL == ee) + { + /* Demand for non-existing element. */ + GNUNET_break_op(0); + fail_union_operation(op); + return; + } + if (GNUNET_NO == _GSS_is_element_of_operation(ee, op)) + { + /* Probably confused lazily copied sets. */ + GNUNET_break_op(0); + fail_union_operation(op); + return; + } + ev = GNUNET_MQ_msg_extra(emsg, ee->element.size, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS); + GNUNET_memcpy(&emsg[1], ee->element.data, ee->element.size); + emsg->reserved = htons(0); + emsg->element_type = htons(ee->element.element_type); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "[OP %x] Sending demanded element (size %u, hash %s) to peer\n", + (void *)op, + (unsigned int)ee->element.size, + GNUNET_h2s(&ee->element_hash)); + GNUNET_MQ_send(op->mq, ev); + GNUNET_STATISTICS_update(_GSS_statistics, + "# exchanged elements", + 1, + GNUNET_NO); + + switch (op->result_mode) + { + case GNUNET_SET_RESULT_ADDED: + /* Nothing to do. */ + break; + + case GNUNET_SET_RESULT_SYMMETRIC: + send_client_element(op, &ee->element, GNUNET_SET_STATUS_ADD_REMOTE); + break; + + default: + /* Result mode not supported, should have been caught earlier. */ + GNUNET_break(0); + break; + } } - } - GNUNET_CADET_receive_done (op->channel); + GNUNET_CADET_receive_done(op->channel); } @@ -2017,32 +2022,32 @@ handle_union_p2p_demand (void *cls, * @return #GNUNET_OK if @a mh is well-formed */ int -check_union_p2p_offer (void *cls, - const struct GNUNET_MessageHeader *mh) +check_union_p2p_offer(void *cls, + const struct GNUNET_MessageHeader *mh) { struct Operation *op = cls; unsigned int num_hashes; if (GNUNET_SET_OPERATION_UNION != op->set->operation) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } /* look up elements and send them */ - if ( (op->state->phase != PHASE_INVENTORY_PASSIVE) && - (op->state->phase != PHASE_INVENTORY_ACTIVE)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - num_hashes = (ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader)) - / sizeof (struct GNUNET_HashCode); - if ((ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader)) != - num_hashes * sizeof (struct GNUNET_HashCode)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + if ((op->state->phase != PHASE_INVENTORY_PASSIVE) && + (op->state->phase != PHASE_INVENTORY_ACTIVE)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + num_hashes = (ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) + / sizeof(struct GNUNET_HashCode); + if ((ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) != + num_hashes * sizeof(struct GNUNET_HashCode)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -2055,56 +2060,56 @@ check_union_p2p_offer (void *cls, * @param mh the message */ void -handle_union_p2p_offer (void *cls, - const struct GNUNET_MessageHeader *mh) +handle_union_p2p_offer(void *cls, + const struct GNUNET_MessageHeader *mh) { struct Operation *op = cls; const struct GNUNET_HashCode *hash; unsigned int num_hashes; - num_hashes = (ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader)) - / sizeof (struct GNUNET_HashCode); - for (hash = (const struct GNUNET_HashCode *) &mh[1]; + num_hashes = (ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) + / sizeof(struct GNUNET_HashCode); + for (hash = (const struct GNUNET_HashCode *)&mh[1]; num_hashes > 0; hash++, num_hashes--) - { - struct ElementEntry *ee; - struct GNUNET_MessageHeader *demands; - struct GNUNET_MQ_Envelope *ev; + { + struct ElementEntry *ee; + struct GNUNET_MessageHeader *demands; + struct GNUNET_MQ_Envelope *ev; - ee = GNUNET_CONTAINER_multihashmap_get (op->set->content->elements, - hash); - if (NULL != ee) - if (GNUNET_YES == _GSS_is_element_of_operation (ee, op)) - continue; + ee = GNUNET_CONTAINER_multihashmap_get(op->set->content->elements, + hash); + if (NULL != ee) + if (GNUNET_YES == _GSS_is_element_of_operation(ee, op)) + continue; - if (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_contains (op->state->demanded_hashes, - hash)) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Skipped sending duplicate demand\n"); - continue; - } + if (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_contains(op->state->demanded_hashes, + hash)) + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Skipped sending duplicate demand\n"); + continue; + } - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (op->state->demanded_hashes, + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put(op->state->demanded_hashes, hash, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "[OP %x] Requesting element (hash %s)\n", - (void *) op, GNUNET_h2s (hash)); - ev = GNUNET_MQ_msg_header_extra (demands, - sizeof (struct GNUNET_HashCode), - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND); - GNUNET_memcpy (&demands[1], - hash, - sizeof (struct GNUNET_HashCode)); - GNUNET_MQ_send (op->mq, ev); - } - GNUNET_CADET_receive_done (op->channel); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "[OP %x] Requesting element (hash %s)\n", + (void *)op, GNUNET_h2s(hash)); + ev = GNUNET_MQ_msg_header_extra(demands, + sizeof(struct GNUNET_HashCode), + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND); + GNUNET_memcpy(&demands[1], + hash, + sizeof(struct GNUNET_HashCode)); + GNUNET_MQ_send(op->mq, ev); + } + GNUNET_CADET_receive_done(op->channel); } @@ -2115,56 +2120,58 @@ handle_union_p2p_offer (void *cls, * @param mh the message */ void -handle_union_p2p_done (void *cls, - const struct GNUNET_MessageHeader *mh) +handle_union_p2p_done(void *cls, + const struct GNUNET_MessageHeader *mh) { struct Operation *op = cls; if (GNUNET_SET_OPERATION_UNION != op->set->operation) - { - GNUNET_break_op (0); - fail_union_operation (op); - return; - } + { + GNUNET_break_op(0); + fail_union_operation(op); + return; + } switch (op->state->phase) - { - case PHASE_INVENTORY_PASSIVE: - /* We got all requests, but still have to send our elements in response. */ - op->state->phase = PHASE_FINISH_WAITING; - - LOG (GNUNET_ERROR_TYPE_DEBUG, - "got DONE (as passive partner), waiting for our demands to be satisfied\n"); - /* The active peer is done sending offers - * and inquiries. This means that all - * our responses to that (demands and offers) - * must be in flight (queued or in mesh). - * - * We should notify the active peer once - * all our demands are satisfied, so that the active - * peer can quit if we gave it everything. - */ - GNUNET_CADET_receive_done (op->channel); - maybe_finish (op); - return; - case PHASE_INVENTORY_ACTIVE: - LOG (GNUNET_ERROR_TYPE_DEBUG, - "got DONE (as active partner), waiting to finish\n"); - /* All demands of the other peer are satisfied, - * and we processed all offers, thus we know - * exactly what our demands must be. - * - * We'll close the channel - * to the other peer once our demands are met. - */ - op->state->phase = PHASE_FINISH_CLOSING; - GNUNET_CADET_receive_done (op->channel); - maybe_finish (op); - return; - default: - GNUNET_break_op (0); - fail_union_operation (op); - return; - } + { + case PHASE_INVENTORY_PASSIVE: + /* We got all requests, but still have to send our elements in response. */ + op->state->phase = PHASE_FINISH_WAITING; + + LOG(GNUNET_ERROR_TYPE_DEBUG, + "got DONE (as passive partner), waiting for our demands to be satisfied\n"); + /* The active peer is done sending offers + * and inquiries. This means that all + * our responses to that (demands and offers) + * must be in flight (queued or in mesh). + * + * We should notify the active peer once + * all our demands are satisfied, so that the active + * peer can quit if we gave it everything. + */ + GNUNET_CADET_receive_done(op->channel); + maybe_finish(op); + return; + + case PHASE_INVENTORY_ACTIVE: + LOG(GNUNET_ERROR_TYPE_DEBUG, + "got DONE (as active partner), waiting to finish\n"); + /* All demands of the other peer are satisfied, + * and we processed all offers, thus we know + * exactly what our demands must be. + * + * We'll close the channel + * to the other peer once our demands are met. + */ + op->state->phase = PHASE_FINISH_CLOSING; + GNUNET_CADET_receive_done(op->channel); + maybe_finish(op); + return; + + default: + GNUNET_break_op(0); + fail_union_operation(op); + return; + } } /** @@ -2174,10 +2181,10 @@ handle_union_p2p_done (void *cls, * @param mh the message */ void -handle_union_p2p_over (void *cls, - const struct GNUNET_MessageHeader *mh) +handle_union_p2p_over(void *cls, + const struct GNUNET_MessageHeader *mh) { - send_client_done (cls); + send_client_done(cls); } @@ -2189,54 +2196,54 @@ handle_union_p2p_over (void *cls, * to convince it to accept, may be NULL */ static struct OperationState * -union_evaluate (struct Operation *op, - const struct GNUNET_MessageHeader *opaque_context) +union_evaluate(struct Operation *op, + const struct GNUNET_MessageHeader *opaque_context) { struct OperationState *state; struct GNUNET_MQ_Envelope *ev; struct OperationRequestMessage *msg; - ev = GNUNET_MQ_msg_nested_mh (msg, - GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, - opaque_context); + ev = GNUNET_MQ_msg_nested_mh(msg, + GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, + opaque_context); if (NULL == ev) - { - /* the context message is too large */ - GNUNET_break (0); - return NULL; - } - state = GNUNET_new (struct OperationState); - state->demanded_hashes = GNUNET_CONTAINER_multihashmap_create (32, - GNUNET_NO); + { + /* the context message is too large */ + GNUNET_break(0); + return NULL; + } + state = GNUNET_new(struct OperationState); + state->demanded_hashes = GNUNET_CONTAINER_multihashmap_create(32, + GNUNET_NO); /* copy the current generation's strata estimator for this operation */ - state->se = strata_estimator_dup (op->set->state->se); + state->se = strata_estimator_dup(op->set->state->se); /* we started the operation, thus we have to send the operation request */ state->phase = PHASE_EXPECT_SE; state->salt_receive = state->salt_send = 42; // FIXME????? - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Initiating union operation evaluation\n"); - GNUNET_STATISTICS_update (_GSS_statistics, - "# of total union operations", - 1, - GNUNET_NO); - GNUNET_STATISTICS_update (_GSS_statistics, - "# of initiated union operations", - 1, - GNUNET_NO); - msg->operation = htonl (GNUNET_SET_OPERATION_UNION); - GNUNET_MQ_send (op->mq, - ev); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Initiating union operation evaluation\n"); + GNUNET_STATISTICS_update(_GSS_statistics, + "# of total union operations", + 1, + GNUNET_NO); + GNUNET_STATISTICS_update(_GSS_statistics, + "# of initiated union operations", + 1, + GNUNET_NO); + msg->operation = htonl(GNUNET_SET_OPERATION_UNION); + GNUNET_MQ_send(op->mq, + ev); if (NULL != opaque_context) - LOG (GNUNET_ERROR_TYPE_DEBUG, - "sent op request with context message\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "sent op request with context message\n"); else - LOG (GNUNET_ERROR_TYPE_DEBUG, - "sent op request without context message\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "sent op request without context message\n"); op->state = state; - initialize_key_to_element (op); - state->initial_size = GNUNET_CONTAINER_multihashmap32_size (state->key_to_element); + initialize_key_to_element(op); + state->initial_size = GNUNET_CONTAINER_multihashmap32_size(state->key_to_element); return state; } @@ -2248,7 +2255,7 @@ union_evaluate (struct Operation *op, * @param op operation that will be accepted as a union operation */ static struct OperationState * -union_accept (struct Operation *op) +union_accept(struct Operation *op) { struct OperationState *state; const struct StrataEstimator *se; @@ -2258,46 +2265,46 @@ union_accept (struct Operation *op) size_t len; uint16_t type; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "accepting set union operation\n"); - GNUNET_STATISTICS_update (_GSS_statistics, - "# of accepted union operations", - 1, - GNUNET_NO); - GNUNET_STATISTICS_update (_GSS_statistics, - "# of total union operations", - 1, - GNUNET_NO); - - state = GNUNET_new (struct OperationState); - state->se = strata_estimator_dup (op->set->state->se); - state->demanded_hashes = GNUNET_CONTAINER_multihashmap_create (32, - GNUNET_NO); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "accepting set union operation\n"); + GNUNET_STATISTICS_update(_GSS_statistics, + "# of accepted union operations", + 1, + GNUNET_NO); + GNUNET_STATISTICS_update(_GSS_statistics, + "# of total union operations", + 1, + GNUNET_NO); + + state = GNUNET_new(struct OperationState); + state->se = strata_estimator_dup(op->set->state->se); + state->demanded_hashes = GNUNET_CONTAINER_multihashmap_create(32, + GNUNET_NO); state->salt_receive = state->salt_send = 42; // FIXME????? op->state = state; - initialize_key_to_element (op); - state->initial_size = GNUNET_CONTAINER_multihashmap32_size (state->key_to_element); + initialize_key_to_element(op); + state->initial_size = GNUNET_CONTAINER_multihashmap32_size(state->key_to_element); /* kick off the operation */ se = state->se; - buf = GNUNET_malloc (se->strata_count * IBF_BUCKET_SIZE * se->ibf_size); - len = strata_estimator_write (se, - buf); + buf = GNUNET_malloc(se->strata_count * IBF_BUCKET_SIZE * se->ibf_size); + len = strata_estimator_write(se, + buf); if (len < se->strata_count * IBF_BUCKET_SIZE * se->ibf_size) type = GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC; else type = GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE; - ev = GNUNET_MQ_msg_extra (strata_msg, - len, - type); - GNUNET_memcpy (&strata_msg[1], - buf, - len); - GNUNET_free (buf); + ev = GNUNET_MQ_msg_extra(strata_msg, + len, + type); + GNUNET_memcpy(&strata_msg[1], + buf, + len); + GNUNET_free(buf); strata_msg->set_size - = GNUNET_htonll (GNUNET_CONTAINER_multihashmap_size (op->set->content->elements)); - GNUNET_MQ_send (op->mq, - ev); + = GNUNET_htonll(GNUNET_CONTAINER_multihashmap_size(op->set->content->elements)); + GNUNET_MQ_send(op->mq, + ev); state->phase = PHASE_EXPECT_IBF; return state; } @@ -2312,22 +2319,22 @@ union_accept (struct Operation *op) * @return the newly created set, NULL on error */ static struct SetState * -union_set_create (void) +union_set_create(void) { struct SetState *set_state; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "union set created\n"); - set_state = GNUNET_new (struct SetState); - set_state->se = strata_estimator_create (SE_STRATA_COUNT, - SE_IBF_SIZE, SE_IBF_HASH_NUM); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "union set created\n"); + set_state = GNUNET_new(struct SetState); + set_state->se = strata_estimator_create(SE_STRATA_COUNT, + SE_IBF_SIZE, SE_IBF_HASH_NUM); if (NULL == set_state->se) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to allocate strata estimator\n"); - GNUNET_free (set_state); - return NULL; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to allocate strata estimator\n"); + GNUNET_free(set_state); + return NULL; + } return set_state; } @@ -2339,11 +2346,11 @@ union_set_create (void) * @param ee the element to add to the set */ static void -union_add (struct SetState *set_state, - struct ElementEntry *ee) +union_add(struct SetState *set_state, + struct ElementEntry *ee) { - strata_estimator_insert (set_state->se, - get_ibf_key (&ee->element_hash)); + strata_estimator_insert(set_state->se, + get_ibf_key(&ee->element_hash)); } @@ -2355,11 +2362,11 @@ union_add (struct SetState *set_state, * @param ee set element to remove */ static void -union_remove (struct SetState *set_state, - struct ElementEntry *ee) +union_remove(struct SetState *set_state, + struct ElementEntry *ee) { - strata_estimator_remove (set_state->se, - get_ibf_key (&ee->element_hash)); + strata_estimator_remove(set_state->se, + get_ibf_key(&ee->element_hash)); } @@ -2369,14 +2376,14 @@ union_remove (struct SetState *set_state, * @param set_state the set to destroy */ static void -union_set_destroy (struct SetState *set_state) +union_set_destroy(struct SetState *set_state) { if (NULL != set_state->se) - { - strata_estimator_destroy (set_state->se); - set_state->se = NULL; - } - GNUNET_free (set_state); + { + strata_estimator_destroy(set_state->se); + set_state->se = NULL; + } + GNUNET_free(set_state); } @@ -2387,14 +2394,14 @@ union_set_destroy (struct SetState *set_state) * @return a copy of the union-specific set state */ static struct SetState * -union_copy_state (struct SetState *state) +union_copy_state(struct SetState *state) { struct SetState *new_state; - GNUNET_assert ( (NULL != state) && - (NULL != state->se) ); - new_state = GNUNET_new (struct SetState); - new_state->se = strata_estimator_dup (state->se); + GNUNET_assert((NULL != state) && + (NULL != state->se)); + new_state = GNUNET_new(struct SetState); + new_state->se = strata_estimator_dup(state->se); return new_state; } @@ -2406,11 +2413,11 @@ union_copy_state (struct SetState *state) * @param op operation that lost the channel */ static void -union_channel_death (struct Operation *op) +union_channel_death(struct Operation *op) { - send_client_done (op); - _GSS_operation_destroy (op, - GNUNET_YES); + send_client_done(op); + _GSS_operation_destroy(op, + GNUNET_YES); } @@ -2421,7 +2428,7 @@ union_channel_death (struct Operation *op) * @return the operation specific VTable */ const struct SetVT * -_GSS_union_vt () +_GSS_union_vt() { static const struct SetVT union_vt = { .create = &union_set_create, diff --git a/src/set/gnunet-service-set_union.h b/src/set/gnunet-service-set_union.h index 5d9b8965a..b56d59ef9 100644 --- a/src/set/gnunet-service-set_union.h +++ b/src/set/gnunet-service-set_union.h @@ -12,12 +12,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/gnunet-service-set_union.h * @brief two-peer set operations @@ -38,8 +38,8 @@ * @param msg the message */ int -check_union_p2p_strata_estimator (void *cls, - const struct StrataEstimatorMessage *msg); +check_union_p2p_strata_estimator(void *cls, + const struct StrataEstimatorMessage *msg); /** @@ -49,8 +49,8 @@ check_union_p2p_strata_estimator (void *cls, * @param msg the message */ void -handle_union_p2p_strata_estimator (void *cls, - const struct StrataEstimatorMessage *msg); +handle_union_p2p_strata_estimator(void *cls, + const struct StrataEstimatorMessage *msg); /** @@ -64,8 +64,8 @@ handle_union_p2p_strata_estimator (void *cls, * @return #GNUNET_OK if @a msg is well-formed */ int -check_union_p2p_ibf (void *cls, - const struct IBFMessage *msg); +check_union_p2p_ibf(void *cls, + const struct IBFMessage *msg); /** @@ -78,8 +78,8 @@ check_union_p2p_ibf (void *cls, * @param msg the header of the message */ void -handle_union_p2p_ibf (void *cls, - const struct IBFMessage *msg); +handle_union_p2p_ibf(void *cls, + const struct IBFMessage *msg); /** @@ -89,8 +89,8 @@ handle_union_p2p_ibf (void *cls, * @param emsg the message */ int -check_union_p2p_elements (void *cls, - const struct GNUNET_SET_ElementMessage *emsg); +check_union_p2p_elements(void *cls, + const struct GNUNET_SET_ElementMessage *emsg); /** @@ -102,8 +102,8 @@ check_union_p2p_elements (void *cls, * @param emsg the message */ void -handle_union_p2p_elements (void *cls, - const struct GNUNET_SET_ElementMessage *emsg); +handle_union_p2p_elements(void *cls, + const struct GNUNET_SET_ElementMessage *emsg); /** @@ -113,8 +113,8 @@ handle_union_p2p_elements (void *cls, * @param emsg the message */ int -check_union_p2p_full_element (void *cls, - const struct GNUNET_SET_ElementMessage *emsg); +check_union_p2p_full_element(void *cls, + const struct GNUNET_SET_ElementMessage *emsg); /** @@ -124,8 +124,8 @@ check_union_p2p_full_element (void *cls, * @param emsg the message */ void -handle_union_p2p_full_element (void *cls, - const struct GNUNET_SET_ElementMessage *emsg); +handle_union_p2p_full_element(void *cls, + const struct GNUNET_SET_ElementMessage *emsg); /** @@ -136,8 +136,8 @@ handle_union_p2p_full_element (void *cls, * @param msg the message */ int -check_union_p2p_inquiry (void *cls, - const struct InquiryMessage *msg); +check_union_p2p_inquiry(void *cls, + const struct InquiryMessage *msg); /** @@ -148,8 +148,8 @@ check_union_p2p_inquiry (void *cls, * @param msg the message */ void -handle_union_p2p_inquiry (void *cls, - const struct InquiryMessage *msg); +handle_union_p2p_inquiry(void *cls, + const struct InquiryMessage *msg); @@ -160,8 +160,8 @@ handle_union_p2p_inquiry (void *cls, * @param mh the demand message */ void -handle_union_p2p_request_full (void *cls, - const struct GNUNET_MessageHeader *mh); +handle_union_p2p_request_full(void *cls, + const struct GNUNET_MessageHeader *mh); @@ -172,8 +172,8 @@ handle_union_p2p_request_full (void *cls, * @param mh the demand message */ void -handle_union_p2p_full_done (void *cls, - const struct GNUNET_MessageHeader *mh); +handle_union_p2p_full_done(void *cls, + const struct GNUNET_MessageHeader *mh); /** @@ -185,8 +185,8 @@ handle_union_p2p_full_done (void *cls, * @return #GNUNET_OK if @a mh is well-formed */ int -check_union_p2p_demand (void *cls, - const struct GNUNET_MessageHeader *mh); +check_union_p2p_demand(void *cls, + const struct GNUNET_MessageHeader *mh); /** @@ -197,8 +197,8 @@ check_union_p2p_demand (void *cls, * @param mh the demand message */ void -handle_union_p2p_demand (void *cls, - const struct GNUNET_MessageHeader *mh); +handle_union_p2p_demand(void *cls, + const struct GNUNET_MessageHeader *mh); /** @@ -209,8 +209,8 @@ handle_union_p2p_demand (void *cls, * @return #GNUNET_OK if @a mh is well-formed */ int -check_union_p2p_offer (void *cls, - const struct GNUNET_MessageHeader *mh); +check_union_p2p_offer(void *cls, + const struct GNUNET_MessageHeader *mh); /** @@ -221,8 +221,8 @@ check_union_p2p_offer (void *cls, * @param mh the message */ void -handle_union_p2p_offer (void *cls, - const struct GNUNET_MessageHeader *mh); +handle_union_p2p_offer(void *cls, + const struct GNUNET_MessageHeader *mh); /** @@ -232,8 +232,8 @@ handle_union_p2p_offer (void *cls, * @param mh the message */ void -handle_union_p2p_done (void *cls, - const struct GNUNET_MessageHeader *mh); +handle_union_p2p_done(void *cls, + const struct GNUNET_MessageHeader *mh); /** * Handle an over message from a remote peer @@ -242,8 +242,8 @@ handle_union_p2p_done (void *cls, * @param mh the message */ void -handle_union_p2p_over (void *cls, - const struct GNUNET_MessageHeader *mh); +handle_union_p2p_over(void *cls, + const struct GNUNET_MessageHeader *mh); #endif diff --git a/src/set/gnunet-service-set_union_strata_estimator.c b/src/set/gnunet-service-set_union_strata_estimator.c index 688c32306..dcc00a680 100644 --- a/src/set/gnunet-service-set_union_strata_estimator.c +++ b/src/set/gnunet-service-set_union_strata_estimator.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/gnunet-service-set_union_strata_estimator.c * @brief invertible bloom filter @@ -44,21 +44,21 @@ * @return number of bytes written to @a buf */ size_t -strata_estimator_write (const struct StrataEstimator *se, - void *buf) +strata_estimator_write(const struct StrataEstimator *se, + void *buf) { char *sbuf = buf; unsigned int i; size_t osize; - GNUNET_assert (NULL != se); + GNUNET_assert(NULL != se); for (i = 0; i < se->strata_count; i++) - { - ibf_write_slice (se->strata[i], - 0, - se->ibf_size, - &sbuf[se->ibf_size * IBF_BUCKET_SIZE * i]); - } + { + ibf_write_slice(se->strata[i], + 0, + se->ibf_size, + &sbuf[se->ibf_size * IBF_BUCKET_SIZE * i]); + } osize = se->ibf_size * IBF_BUCKET_SIZE * se->strata_count; #if FAIL_10_1_COMPATIBILTIY { @@ -66,15 +66,15 @@ strata_estimator_write (const struct StrataEstimator *se, size_t nsize; if (GNUNET_YES == - GNUNET_try_compression (buf, - osize, - &cbuf, - &nsize)) - { - GNUNET_memcpy (buf, cbuf, nsize); - osize = nsize; - GNUNET_free (cbuf); - } + GNUNET_try_compression(buf, + osize, + &cbuf, + &nsize)) + { + GNUNET_memcpy(buf, cbuf, nsize); + osize = nsize; + GNUNET_free(cbuf); + } } #endif return osize; @@ -92,10 +92,10 @@ strata_estimator_write (const struct StrataEstimator *se, * @return #GNUNET_OK on success */ int -strata_estimator_read (const void *buf, - size_t buf_len, - int is_compressed, - struct StrataEstimator *se) +strata_estimator_read(const void *buf, + size_t buf_len, + int is_compressed, + struct StrataEstimator *se) { unsigned int i; size_t osize; @@ -103,33 +103,33 @@ strata_estimator_read (const void *buf, dbuf = NULL; if (GNUNET_YES == is_compressed) - { - osize = se->ibf_size * IBF_BUCKET_SIZE * se->strata_count; - dbuf = GNUNET_decompress (buf, - buf_len, - osize); - if (NULL == dbuf) { - GNUNET_break_op (0); /* bad compressed input data */ - return GNUNET_SYSERR; + osize = se->ibf_size * IBF_BUCKET_SIZE * se->strata_count; + dbuf = GNUNET_decompress(buf, + buf_len, + osize); + if (NULL == dbuf) + { + GNUNET_break_op(0); /* bad compressed input data */ + return GNUNET_SYSERR; + } + buf = dbuf; + buf_len = osize; } - buf = dbuf; - buf_len = osize; - } if (buf_len != se->strata_count * se->ibf_size * IBF_BUCKET_SIZE) - { - GNUNET_break (0); /* very odd error */ - GNUNET_free_non_null (dbuf); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); /* very odd error */ + GNUNET_free_non_null(dbuf); + return GNUNET_SYSERR; + } for (i = 0; i < se->strata_count; i++) - { - ibf_read_slice (buf, 0, se->ibf_size, se->strata[i]); - buf += se->ibf_size * IBF_BUCKET_SIZE; - } - GNUNET_free_non_null (dbuf); + { + ibf_read_slice(buf, 0, se->ibf_size, se->strata[i]); + buf += se->ibf_size * IBF_BUCKET_SIZE; + } + GNUNET_free_non_null(dbuf); return GNUNET_OK; } @@ -141,17 +141,17 @@ strata_estimator_read (const void *buf, * @param key key to add */ void -strata_estimator_insert (struct StrataEstimator *se, - struct IBF_Key key) +strata_estimator_insert(struct StrataEstimator *se, + struct IBF_Key key) { uint64_t v; unsigned int i; v = key.key_val; /* count trailing '1'-bits of v */ - for (i = 0; v & 1; v>>=1, i++) + for (i = 0; v & 1; v >>= 1, i++) /* empty */; - ibf_insert (se->strata[i], key); + ibf_insert(se->strata[i], key); } @@ -162,17 +162,17 @@ strata_estimator_insert (struct StrataEstimator *se, * @param key key to remove */ void -strata_estimator_remove (struct StrataEstimator *se, - struct IBF_Key key) +strata_estimator_remove(struct StrataEstimator *se, + struct IBF_Key key) { uint64_t v; unsigned int i; v = key.key_val; /* count trailing '1'-bits of v */ - for (i = 0; v & 1; v>>=1, i++) + for (i = 0; v & 1; v >>= 1, i++) /* empty */; - ibf_remove (se->strata[i], key); + ibf_remove(se->strata[i], key); } @@ -185,32 +185,32 @@ strata_estimator_remove (struct StrataEstimator *se, * @return a freshly allocated, empty strata estimator, NULL on error */ struct StrataEstimator * -strata_estimator_create (unsigned int strata_count, - uint32_t ibf_size, - uint8_t ibf_hashnum) +strata_estimator_create(unsigned int strata_count, + uint32_t ibf_size, + uint8_t ibf_hashnum) { struct StrataEstimator *se; unsigned int i; unsigned int j; - se = GNUNET_new (struct StrataEstimator); + se = GNUNET_new(struct StrataEstimator); se->strata_count = strata_count; se->ibf_size = ibf_size; - se->strata = GNUNET_new_array (strata_count, - struct InvertibleBloomFilter *); + se->strata = GNUNET_new_array(strata_count, + struct InvertibleBloomFilter *); for (i = 0; i < strata_count; i++) - { - se->strata[i] = ibf_create (ibf_size, ibf_hashnum); - if (NULL == se->strata[i]) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to allocate memory for strata estimator\n"); - for (j = 0; j < i; j++) - ibf_destroy (se->strata[i]); - GNUNET_free (se); - return NULL; + se->strata[i] = ibf_create(ibf_size, ibf_hashnum); + if (NULL == se->strata[i]) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to allocate memory for strata estimator\n"); + for (j = 0; j < i; j++) + ibf_destroy(se->strata[i]); + GNUNET_free(se); + return NULL; + } } - } return se; } @@ -225,40 +225,40 @@ strata_estimator_create (unsigned int strata_count, * @return the estimated difference */ unsigned int -strata_estimator_difference (const struct StrataEstimator *se1, - const struct StrataEstimator *se2) +strata_estimator_difference(const struct StrataEstimator *se1, + const struct StrataEstimator *se2) { unsigned int count; - GNUNET_assert (se1->strata_count == se2->strata_count); + GNUNET_assert(se1->strata_count == se2->strata_count); count = 0; for (int i = se1->strata_count - 1; i >= 0; i--) - { - struct InvertibleBloomFilter *diff; - /* number of keys decoded from the ibf */ - - /* FIXME: implement this without always allocating new IBFs */ - diff = ibf_dup (se1->strata[i]); - ibf_subtract (diff, se2->strata[i]); - for (int ibf_count = 0; GNUNET_YES; ibf_count++) { - int more; - - more = ibf_decode (diff, NULL, NULL); - if (GNUNET_NO == more) - { - count += ibf_count; - break; - } - /* Estimate if decoding fails or would not terminate */ - if ((GNUNET_SYSERR == more) || (ibf_count > diff->size)) - { - ibf_destroy (diff); - return count * (1 << (i + 1)); - } + struct InvertibleBloomFilter *diff; + /* number of keys decoded from the ibf */ + + /* FIXME: implement this without always allocating new IBFs */ + diff = ibf_dup(se1->strata[i]); + ibf_subtract(diff, se2->strata[i]); + for (int ibf_count = 0; GNUNET_YES; ibf_count++) + { + int more; + + more = ibf_decode(diff, NULL, NULL); + if (GNUNET_NO == more) + { + count += ibf_count; + break; + } + /* Estimate if decoding fails or would not terminate */ + if ((GNUNET_SYSERR == more) || (ibf_count > diff->size)) + { + ibf_destroy(diff); + return count * (1 << (i + 1)); + } + } + ibf_destroy(diff); } - ibf_destroy (diff); - } return count; } @@ -270,18 +270,18 @@ strata_estimator_difference (const struct StrataEstimator *se1, * @return the copy */ struct StrataEstimator * -strata_estimator_dup (struct StrataEstimator *se) +strata_estimator_dup(struct StrataEstimator *se) { struct StrataEstimator *c; unsigned int i; - c = GNUNET_new (struct StrataEstimator); + c = GNUNET_new(struct StrataEstimator); c->strata_count = se->strata_count; c->ibf_size = se->ibf_size; - c->strata = GNUNET_new_array (se->strata_count, - struct InvertibleBloomFilter *); + c->strata = GNUNET_new_array(se->strata_count, + struct InvertibleBloomFilter *); for (i = 0; i < se->strata_count; i++) - c->strata[i] = ibf_dup (se->strata[i]); + c->strata[i] = ibf_dup(se->strata[i]); return c; } @@ -292,12 +292,12 @@ strata_estimator_dup (struct StrataEstimator *se) * @param se strata estimator to destroy. */ void -strata_estimator_destroy (struct StrataEstimator *se) +strata_estimator_destroy(struct StrataEstimator *se) { unsigned int i; for (i = 0; i < se->strata_count; i++) - ibf_destroy (se->strata[i]); - GNUNET_free (se->strata); - GNUNET_free (se); + ibf_destroy(se->strata[i]); + GNUNET_free(se->strata); + GNUNET_free(se); } diff --git a/src/set/gnunet-service-set_union_strata_estimator.h b/src/set/gnunet-service-set_union_strata_estimator.h index 99f16f20a..2c09e1089 100644 --- a/src/set/gnunet-service-set_union_strata_estimator.h +++ b/src/set/gnunet-service-set_union_strata_estimator.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/gnunet-service-set_union_strata_estimator.h @@ -43,8 +43,7 @@ extern "C" /** * A handle to a strata estimator. */ -struct StrataEstimator -{ +struct StrataEstimator { /** * The IBFs of this strata estimator. */ @@ -70,8 +69,8 @@ struct StrataEstimator * @return number of bytes written to @a buf */ size_t -strata_estimator_write (const struct StrataEstimator *se, - void *buf); +strata_estimator_write(const struct StrataEstimator *se, + void *buf); /** @@ -85,10 +84,10 @@ strata_estimator_write (const struct StrataEstimator *se, * @return #GNUNET_OK on success */ int -strata_estimator_read (const void *buf, - size_t buf_len, - int is_compressed, - struct StrataEstimator *se); +strata_estimator_read(const void *buf, + size_t buf_len, + int is_compressed, + struct StrataEstimator *se); /** @@ -100,9 +99,9 @@ strata_estimator_read (const void *buf, * @return a freshly allocated, empty strata estimator, NULL on error */ struct StrataEstimator * -strata_estimator_create (unsigned int strata_count, - uint32_t ibf_size, - uint8_t ibf_hashnum); +strata_estimator_create(unsigned int strata_count, + uint32_t ibf_size, + uint8_t ibf_hashnum); /** @@ -114,8 +113,8 @@ strata_estimator_create (unsigned int strata_count, * @return abs(|se1| - |se2|) */ unsigned int -strata_estimator_difference (const struct StrataEstimator *se1, - const struct StrataEstimator *se2); +strata_estimator_difference(const struct StrataEstimator *se1, + const struct StrataEstimator *se2); /** @@ -125,8 +124,8 @@ strata_estimator_difference (const struct StrataEstimator *se1, * @param key key to add */ void -strata_estimator_insert (struct StrataEstimator *se, - struct IBF_Key key); +strata_estimator_insert(struct StrataEstimator *se, + struct IBF_Key key); /** @@ -136,8 +135,8 @@ strata_estimator_insert (struct StrataEstimator *se, * @param key key to remove */ void -strata_estimator_remove (struct StrataEstimator *se, - struct IBF_Key key); +strata_estimator_remove(struct StrataEstimator *se, + struct IBF_Key key); /** @@ -146,7 +145,7 @@ strata_estimator_remove (struct StrataEstimator *se, * @param se strata estimator to destroy. */ void -strata_estimator_destroy (struct StrataEstimator *se); +strata_estimator_destroy(struct StrataEstimator *se); /** @@ -156,7 +155,7 @@ strata_estimator_destroy (struct StrataEstimator *se); * @return the copy */ struct StrataEstimator * -strata_estimator_dup (struct StrataEstimator *se); +strata_estimator_dup(struct StrataEstimator *se); #if 0 /* keep Emacsens' auto-indent happy */ diff --git a/src/set/gnunet-set-ibf-profiler.c b/src/set/gnunet-set-ibf-profiler.c index 1e3f78595..c54557fb0 100644 --- a/src/set/gnunet-set-ibf-profiler.c +++ b/src/set/gnunet-set-ibf-profiler.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/gnunet-set-ibf-profiler.c @@ -50,60 +50,62 @@ static struct InvertibleBloomFilter *ibf_b; static void -register_hashcode (struct GNUNET_HashCode *hash) +register_hashcode(struct GNUNET_HashCode *hash) { struct GNUNET_HashCode replicated; struct IBF_Key key; - key = ibf_key_from_hashcode (hash); - ibf_hashcode_from_key (key, &replicated); - (void) GNUNET_CONTAINER_multihashmap_put ( + + key = ibf_key_from_hashcode(hash); + ibf_hashcode_from_key(key, &replicated); + (void)GNUNET_CONTAINER_multihashmap_put( key_to_hashcode, &replicated, - GNUNET_memdup (hash, sizeof *hash), + GNUNET_memdup(hash, sizeof *hash), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); } static void -iter_hashcodes (struct IBF_Key key, - GNUNET_CONTAINER_MulitHashMapIteratorCallback iter, - void *cls) +iter_hashcodes(struct IBF_Key key, + GNUNET_CONTAINER_MulitHashMapIteratorCallback iter, + void *cls) { struct GNUNET_HashCode replicated; - ibf_hashcode_from_key (key, &replicated); - GNUNET_CONTAINER_multihashmap_get_multiple (key_to_hashcode, - &replicated, - iter, - cls); + ibf_hashcode_from_key(key, &replicated); + GNUNET_CONTAINER_multihashmap_get_multiple(key_to_hashcode, + &replicated, + iter, + cls); } static int -insert_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) +insert_iterator(void *cls, const struct GNUNET_HashCode *key, void *value) { struct InvertibleBloomFilter *ibf = cls; - ibf_insert (ibf, ibf_key_from_hashcode (key)); + ibf_insert(ibf, ibf_key_from_hashcode(key)); return GNUNET_YES; } static int -remove_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) +remove_iterator(void *cls, const struct GNUNET_HashCode *key, void *value) { struct GNUNET_CONTAINER_MultiHashMap *hashmap = cls; + /* if remove fails, there just was a collision with another key */ - (void) GNUNET_CONTAINER_multihashmap_remove (hashmap, value, NULL); + (void)GNUNET_CONTAINER_multihashmap_remove(hashmap, value, NULL); return GNUNET_YES; } static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_HashCode id; struct IBF_Key ibf_key; @@ -114,193 +116,193 @@ run (void *cls, struct GNUNET_TIME_Relative delta_time; set_a = - GNUNET_CONTAINER_multihashmap_create (((asize == 0) ? 1 : (asize + csize)), - GNUNET_NO); + GNUNET_CONTAINER_multihashmap_create(((asize == 0) ? 1 : (asize + csize)), + GNUNET_NO); set_b = - GNUNET_CONTAINER_multihashmap_create (((bsize == 0) ? 1 : (bsize + csize)), - GNUNET_NO); - set_c = GNUNET_CONTAINER_multihashmap_create (((csize == 0) ? 1 : csize), - GNUNET_NO); + GNUNET_CONTAINER_multihashmap_create(((bsize == 0) ? 1 : (bsize + csize)), + GNUNET_NO); + set_c = GNUNET_CONTAINER_multihashmap_create(((csize == 0) ? 1 : csize), + GNUNET_NO); key_to_hashcode = - GNUNET_CONTAINER_multihashmap_create (((asize + bsize + csize == 0) - ? 1 - : (asize + bsize + csize)), - GNUNET_NO); - - printf ("hash-num=%u, size=%u, #(A-B)=%u, #(B-A)=%u, #(A&B)=%u\n", - hash_num, - ibf_size, - asize, - bsize, - csize); + GNUNET_CONTAINER_multihashmap_create(((asize + bsize + csize == 0) + ? 1 + : (asize + bsize + csize)), + GNUNET_NO); + + printf("hash-num=%u, size=%u, #(A-B)=%u, #(B-A)=%u, #(A&B)=%u\n", + hash_num, + ibf_size, + asize, + bsize, + csize); i = 0; while (i < asize) - { - GNUNET_CRYPTO_hash_create_random (random_quality, &id); - if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id)) - continue; - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put ( - set_a, - &id, - NULL, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - register_hashcode (&id); - i++; - } + { + GNUNET_CRYPTO_hash_create_random(random_quality, &id); + if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_a, &id)) + continue; + GNUNET_break(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put( + set_a, + &id, + NULL, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + register_hashcode(&id); + i++; + } i = 0; while (i < bsize) - { - GNUNET_CRYPTO_hash_create_random (random_quality, &id); - if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id)) - continue; - if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_b, &id)) - continue; - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put ( - set_b, - &id, - NULL, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - register_hashcode (&id); - i++; - } + { + GNUNET_CRYPTO_hash_create_random(random_quality, &id); + if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_a, &id)) + continue; + if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_b, &id)) + continue; + GNUNET_break(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put( + set_b, + &id, + NULL, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + register_hashcode(&id); + i++; + } i = 0; while (i < csize) - { - GNUNET_CRYPTO_hash_create_random (random_quality, &id); - if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id)) - continue; - if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_b, &id)) - continue; - if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_c, &id)) - continue; - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put ( - set_c, - &id, - NULL, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - register_hashcode (&id); - i++; - } - - ibf_a = ibf_create (ibf_size, hash_num); - ibf_b = ibf_create (ibf_size, hash_num); + { + GNUNET_CRYPTO_hash_create_random(random_quality, &id); + if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_a, &id)) + continue; + if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_b, &id)) + continue; + if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_c, &id)) + continue; + GNUNET_break(GNUNET_OK == + GNUNET_CONTAINER_multihashmap_put( + set_c, + &id, + NULL, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + register_hashcode(&id); + i++; + } + + ibf_a = ibf_create(ibf_size, hash_num); + ibf_b = ibf_create(ibf_size, hash_num); if ((NULL == ibf_a) || (NULL == ibf_b)) - { - /* insufficient memory */ - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } + { + /* insufficient memory */ + GNUNET_break(0); + GNUNET_SCHEDULER_shutdown(); + return; + } - printf ("generated sets\n"); + printf("generated sets\n"); - start_time = GNUNET_TIME_absolute_get (); + start_time = GNUNET_TIME_absolute_get(); - GNUNET_CONTAINER_multihashmap_iterate (set_a, &insert_iterator, ibf_a); - GNUNET_CONTAINER_multihashmap_iterate (set_b, &insert_iterator, ibf_b); - GNUNET_CONTAINER_multihashmap_iterate (set_c, &insert_iterator, ibf_a); - GNUNET_CONTAINER_multihashmap_iterate (set_c, &insert_iterator, ibf_b); + GNUNET_CONTAINER_multihashmap_iterate(set_a, &insert_iterator, ibf_a); + GNUNET_CONTAINER_multihashmap_iterate(set_b, &insert_iterator, ibf_b); + GNUNET_CONTAINER_multihashmap_iterate(set_c, &insert_iterator, ibf_a); + GNUNET_CONTAINER_multihashmap_iterate(set_c, &insert_iterator, ibf_b); - delta_time = GNUNET_TIME_absolute_get_duration (start_time); + delta_time = GNUNET_TIME_absolute_get_duration(start_time); - printf ("encoded in: %s\n", - GNUNET_STRINGS_relative_time_to_string (delta_time, GNUNET_NO)); + printf("encoded in: %s\n", + GNUNET_STRINGS_relative_time_to_string(delta_time, GNUNET_NO)); - ibf_subtract (ibf_a, ibf_b); + ibf_subtract(ibf_a, ibf_b); - start_time = GNUNET_TIME_absolute_get (); + start_time = GNUNET_TIME_absolute_get(); for (i = 0; i <= asize + bsize; i++) - { - res = ibf_decode (ibf_a, &side, &ibf_key); - if (GNUNET_SYSERR == res) { - printf ("decode failed, %u/%u elements left\n", - GNUNET_CONTAINER_multihashmap_size (set_a) + - GNUNET_CONTAINER_multihashmap_size (set_b), - asize + bsize); - return; + res = ibf_decode(ibf_a, &side, &ibf_key); + if (GNUNET_SYSERR == res) + { + printf("decode failed, %u/%u elements left\n", + GNUNET_CONTAINER_multihashmap_size(set_a) + + GNUNET_CONTAINER_multihashmap_size(set_b), + asize + bsize); + return; + } + if (GNUNET_NO == res) + { + if ((0 == GNUNET_CONTAINER_multihashmap_size(set_b)) && + (0 == GNUNET_CONTAINER_multihashmap_size(set_a))) + { + delta_time = GNUNET_TIME_absolute_get_duration(start_time); + printf("decoded successfully in: %s\n", + GNUNET_STRINGS_relative_time_to_string(delta_time, GNUNET_NO)); + } + else + { + printf("decode missed elements (should never happen)\n"); + } + return; + } + + if (side == 1) + iter_hashcodes(ibf_key, remove_iterator, set_a); + if (side == -1) + iter_hashcodes(ibf_key, remove_iterator, set_b); } - if (GNUNET_NO == res) - { - if ((0 == GNUNET_CONTAINER_multihashmap_size (set_b)) && - (0 == GNUNET_CONTAINER_multihashmap_size (set_a))) - { - delta_time = GNUNET_TIME_absolute_get_duration (start_time); - printf ("decoded successfully in: %s\n", - GNUNET_STRINGS_relative_time_to_string (delta_time, GNUNET_NO)); - } - else - { - printf ("decode missed elements (should never happen)\n"); - } - return; - } - - if (side == 1) - iter_hashcodes (ibf_key, remove_iterator, set_a); - if (side == -1) - iter_hashcodes (ibf_key, remove_iterator, set_b); - } - printf ("cyclic IBF, %u/%u elements left\n", - GNUNET_CONTAINER_multihashmap_size (set_a) + - GNUNET_CONTAINER_multihashmap_size (set_b), - asize + bsize); + printf("cyclic IBF, %u/%u elements left\n", + GNUNET_CONTAINER_multihashmap_size(set_a) + + GNUNET_CONTAINER_multihashmap_size(set_b), + asize + bsize); } int -main (int argc, char **argv) +main(int argc, char **argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { - - GNUNET_GETOPT_option_uint ('A', - "asize", - NULL, - gettext_noop ("number of element in set A-B"), - &asize), - - GNUNET_GETOPT_option_uint ('B', - "bsize", - NULL, - gettext_noop ("number of element in set B-A"), - &bsize), - - GNUNET_GETOPT_option_uint ('C', - "csize", - NULL, - gettext_noop ( - "number of common elements in A and B"), - &csize), - - GNUNET_GETOPT_option_uint ('k', - "hash-num", - NULL, - gettext_noop ("hash num"), - &hash_num), - - GNUNET_GETOPT_option_uint ('s', - "ibf-size", - NULL, - gettext_noop ("ibf size"), - &ibf_size), - - GNUNET_GETOPT_OPTION_END}; - - GNUNET_PROGRAM_run2 (argc, - argv, - "gnunet-consensus-ibf", - "help", - options, - &run, - NULL, - GNUNET_YES); + GNUNET_GETOPT_option_uint('A', + "asize", + NULL, + gettext_noop("number of element in set A-B"), + &asize), + + GNUNET_GETOPT_option_uint('B', + "bsize", + NULL, + gettext_noop("number of element in set B-A"), + &bsize), + + GNUNET_GETOPT_option_uint('C', + "csize", + NULL, + gettext_noop( + "number of common elements in A and B"), + &csize), + + GNUNET_GETOPT_option_uint('k', + "hash-num", + NULL, + gettext_noop("hash num"), + &hash_num), + + GNUNET_GETOPT_option_uint('s', + "ibf-size", + NULL, + gettext_noop("ibf size"), + &ibf_size), + + GNUNET_GETOPT_OPTION_END + }; + + GNUNET_PROGRAM_run2(argc, + argv, + "gnunet-consensus-ibf", + "help", + options, + &run, + NULL, + GNUNET_YES); return 0; } diff --git a/src/set/gnunet-set-profiler.c b/src/set/gnunet-set-profiler.c index 9b30d47fd..4fabc8388 100644 --- a/src/set/gnunet-set-profiler.c +++ b/src/set/gnunet-set-profiler.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/gnunet-set-profiler.c @@ -40,8 +40,7 @@ static char *op_str = "union"; const static struct GNUNET_CONFIGURATION_Handle *config; -struct SetInfo -{ +struct SetInfo { char *id; struct GNUNET_SET_Handle *set; struct GNUNET_SET_OperationHandle *oh; @@ -82,20 +81,19 @@ static FILE *statistics_file; static int -map_remove_iterator (void *cls, - const struct GNUNET_HashCode *key, - void *value) +map_remove_iterator(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_CONTAINER_MultiHashMap *m = cls; int ret; - GNUNET_assert (NULL != key); + GNUNET_assert(NULL != key); - ret = GNUNET_CONTAINER_multihashmap_remove_all (m, key); + ret = GNUNET_CONTAINER_multihashmap_remove_all(m, key); if (GNUNET_OK != ret) - printf ("spurious element\n"); + printf("spurious element\n"); return GNUNET_YES; - } @@ -110,158 +108,162 @@ map_remove_iterator (void *cls, * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration */ static int -statistics_result (void *cls, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent) +statistics_result(void *cls, + const char *subsystem, + const char *name, + uint64_t value, + int is_persistent) { if (NULL != statistics_file) - { - fprintf (statistics_file, "%s\t%s\t%lu\n", subsystem, name, (unsigned long) value); - } + { + fprintf(statistics_file, "%s\t%s\t%lu\n", subsystem, name, (unsigned long)value); + } return GNUNET_OK; } static void -statistics_done (void *cls, - int success) +statistics_done(void *cls, + int success) { - GNUNET_assert (GNUNET_YES == success); + GNUNET_assert(GNUNET_YES == success); if (NULL != statistics_file) - fclose (statistics_file); - GNUNET_SCHEDULER_shutdown (); + fclose(statistics_file); + GNUNET_SCHEDULER_shutdown(); } static void -check_all_done (void) +check_all_done(void) { if (info1.done == GNUNET_NO || info2.done == GNUNET_NO) return; - GNUNET_CONTAINER_multihashmap_iterate (info1.received, map_remove_iterator, info2.sent); - GNUNET_CONTAINER_multihashmap_iterate (info2.received, map_remove_iterator, info1.sent); + GNUNET_CONTAINER_multihashmap_iterate(info1.received, map_remove_iterator, info2.sent); + GNUNET_CONTAINER_multihashmap_iterate(info2.received, map_remove_iterator, info1.sent); - printf ("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (info1.sent)); - printf ("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (info2.sent)); + printf("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size(info1.sent)); + printf("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size(info2.sent)); if (NULL == statistics_filename) - { - GNUNET_SCHEDULER_shutdown (); - return; - } + { + GNUNET_SCHEDULER_shutdown(); + return; + } - statistics_file = fopen (statistics_filename, "w"); - GNUNET_STATISTICS_get (statistics, NULL, NULL, - &statistics_done, - &statistics_result, NULL); + statistics_file = fopen(statistics_filename, "w"); + GNUNET_STATISTICS_get(statistics, NULL, NULL, + &statistics_done, + &statistics_result, NULL); } static void -set_result_cb (void *cls, - const struct GNUNET_SET_Element *element, - uint64_t current_size, - enum GNUNET_SET_Status status) +set_result_cb(void *cls, + const struct GNUNET_SET_Element *element, + uint64_t current_size, + enum GNUNET_SET_Status status) { struct SetInfo *info = cls; struct GNUNET_HashCode hash; - GNUNET_assert (GNUNET_NO == info->done); + GNUNET_assert(GNUNET_NO == info->done); switch (status) - { + { case GNUNET_SET_STATUS_DONE: case GNUNET_SET_STATUS_HALF_DONE: info->done = GNUNET_YES; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s done\n", info->id); - check_all_done (); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s done\n", info->id); + check_all_done(); info->oh = NULL; return; + case GNUNET_SET_STATUS_FAILURE: info->oh = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failure\n"); - GNUNET_SCHEDULER_shutdown (); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "failure\n"); + GNUNET_SCHEDULER_shutdown(); return; + case GNUNET_SET_STATUS_ADD_LOCAL: - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: local element\n", info->id); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s: local element\n", info->id); break; + case GNUNET_SET_STATUS_ADD_REMOTE: - GNUNET_CRYPTO_hash (element->data, element->size, &hash); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: remote element %s\n", info->id, - GNUNET_h2s (&hash)); + GNUNET_CRYPTO_hash(element->data, element->size, &hash); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s: remote element %s\n", info->id, + GNUNET_h2s(&hash)); // XXX: record and check return; + default: - GNUNET_assert (0); - } + GNUNET_assert(0); + } if (element->size != element_size) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "wrong element size: %u, expected %u\n", - element->size, - (unsigned int) sizeof (struct GNUNET_HashCode)); - GNUNET_assert (0); - } - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: got element (%s)\n", - info->id, GNUNET_h2s (element->data)); - GNUNET_assert (NULL != element->data); + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "wrong element size: %u, expected %u\n", + element->size, + (unsigned int)sizeof(struct GNUNET_HashCode)); + GNUNET_assert(0); + } + + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s: got element (%s)\n", + info->id, GNUNET_h2s(element->data)); + GNUNET_assert(NULL != element->data); struct GNUNET_HashCode data_hash; - GNUNET_CRYPTO_hash (element->data, element_size, &data_hash); - GNUNET_CONTAINER_multihashmap_put (info->received, - &data_hash, NULL, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); + GNUNET_CRYPTO_hash(element->data, element_size, &data_hash); + GNUNET_CONTAINER_multihashmap_put(info->received, + &data_hash, NULL, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); } static void -set_listen_cb (void *cls, - const struct GNUNET_PeerIdentity *other_peer, - const struct GNUNET_MessageHeader *context_msg, - struct GNUNET_SET_Request *request) +set_listen_cb(void *cls, + const struct GNUNET_PeerIdentity *other_peer, + const struct GNUNET_MessageHeader *context_msg, + struct GNUNET_SET_Request *request) { /* max. 2 options plus terminator */ - struct GNUNET_SET_Option opts[3] = {{0}}; + struct GNUNET_SET_Option opts[3] = { { 0 } }; unsigned int n_opts = 0; if (NULL == request) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "listener failed\n"); - return; - } - GNUNET_assert (NULL == info2.oh); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "set listen cb called\n"); + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "listener failed\n"); + return; + } + GNUNET_assert(NULL == info2.oh); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "set listen cb called\n"); if (byzantine) - { - opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_BYZANTINE }; - } - GNUNET_assert (!(force_full && force_delta)); + { + opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_BYZANTINE }; + } + GNUNET_assert(!(force_full && force_delta)); if (force_full) - { - opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_FULL }; - } + { + opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_FULL }; + } if (force_delta) - { - opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_DELTA }; - } + { + opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_DELTA }; + } opts[n_opts].type = 0; - info2.oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_SYMMETRIC, - opts, - set_result_cb, &info2); - GNUNET_SET_commit (info2.oh, info2.set); + info2.oh = GNUNET_SET_accept(request, GNUNET_SET_RESULT_SYMMETRIC, + opts, + set_result_cb, &info2); + GNUNET_SET_commit(info2.oh, info2.set); } static int -set_insert_iterator (void *cls, - const struct GNUNET_HashCode *key, - void *value) +set_insert_iterator(void *cls, + const struct GNUNET_HashCode *key, + void *value) { struct GNUNET_SET_Handle *set = cls; struct GNUNET_SET_Element el; @@ -269,221 +271,222 @@ set_insert_iterator (void *cls, el.element_type = 0; el.data = value; el.size = element_size; - GNUNET_SET_add_element (set, &el, NULL, NULL); + GNUNET_SET_add_element(set, &el, NULL, NULL); return GNUNET_YES; } static void -handle_shutdown (void *cls) +handle_shutdown(void *cls) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Shutting down set profiler\n"); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Shutting down set profiler\n"); if (NULL != set_listener) - { - GNUNET_SET_listen_cancel (set_listener); - set_listener = NULL; - } + { + GNUNET_SET_listen_cancel(set_listener); + set_listener = NULL; + } if (NULL != info1.oh) - { - GNUNET_SET_operation_cancel (info1.oh); - info1.oh = NULL; - } + { + GNUNET_SET_operation_cancel(info1.oh); + info1.oh = NULL; + } if (NULL != info2.oh) - { - GNUNET_SET_operation_cancel (info2.oh); - info2.oh = NULL; - } + { + GNUNET_SET_operation_cancel(info2.oh); + info2.oh = NULL; + } if (NULL != info1.set) - { - GNUNET_SET_destroy (info1.set); - info1.set = NULL; - } + { + GNUNET_SET_destroy(info1.set); + info1.set = NULL; + } if (NULL != info2.set) - { - GNUNET_SET_destroy (info2.set); - info2.set = NULL; - } - GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); + { + GNUNET_SET_destroy(info2.set); + info2.set = NULL; + } + GNUNET_STATISTICS_destroy(statistics, GNUNET_NO); } static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { unsigned int i; struct GNUNET_HashCode hash; /* max. 2 options plus terminator */ - struct GNUNET_SET_Option opts[3] = {{0}}; + struct GNUNET_SET_Option opts[3] = { { 0 } }; unsigned int n_opts = 0; config = cfg; - GNUNET_assert (element_size > 0); + GNUNET_assert(element_size > 0); - if (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity (cfg, &local_peer)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not retrieve host identity\n"); - ret = 0; - return; - } + if (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity(cfg, &local_peer)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "could not retrieve host identity\n"); + ret = 0; + return; + } - statistics = GNUNET_STATISTICS_create ("set-profiler", cfg); + statistics = GNUNET_STATISTICS_create("set-profiler", cfg); - GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL); + GNUNET_SCHEDULER_add_shutdown(&handle_shutdown, NULL); info1.id = "a"; info2.id = "b"; - info1.sent = GNUNET_CONTAINER_multihashmap_create (num_a+1, GNUNET_NO); - info2.sent = GNUNET_CONTAINER_multihashmap_create (num_b+1, GNUNET_NO); - common_sent = GNUNET_CONTAINER_multihashmap_create (num_c+1, GNUNET_NO); + info1.sent = GNUNET_CONTAINER_multihashmap_create(num_a + 1, GNUNET_NO); + info2.sent = GNUNET_CONTAINER_multihashmap_create(num_b + 1, GNUNET_NO); + common_sent = GNUNET_CONTAINER_multihashmap_create(num_c + 1, GNUNET_NO); - info1.received = GNUNET_CONTAINER_multihashmap_create (num_a+1, GNUNET_NO); - info2.received = GNUNET_CONTAINER_multihashmap_create (num_b+1, GNUNET_NO); + info1.received = GNUNET_CONTAINER_multihashmap_create(num_a + 1, GNUNET_NO); + info2.received = GNUNET_CONTAINER_multihashmap_create(num_b + 1, GNUNET_NO); for (i = 0; i < num_a; i++) - { - char *data = GNUNET_malloc (element_size); - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); - GNUNET_CRYPTO_hash (data, element_size, &hash); - GNUNET_CONTAINER_multihashmap_put (info1.sent, &hash, data, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); - } + { + char *data = GNUNET_malloc(element_size); + GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); + GNUNET_CRYPTO_hash(data, element_size, &hash); + GNUNET_CONTAINER_multihashmap_put(info1.sent, &hash, data, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); + } for (i = 0; i < num_b; i++) - { - char *data = GNUNET_malloc (element_size); - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); - GNUNET_CRYPTO_hash (data, element_size, &hash); - GNUNET_CONTAINER_multihashmap_put (info2.sent, &hash, data, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); - } + { + char *data = GNUNET_malloc(element_size); + GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); + GNUNET_CRYPTO_hash(data, element_size, &hash); + GNUNET_CONTAINER_multihashmap_put(info2.sent, &hash, data, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); + } for (i = 0; i < num_c; i++) - { - char *data = GNUNET_malloc (element_size); - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); - GNUNET_CRYPTO_hash (data, element_size, &hash); - GNUNET_CONTAINER_multihashmap_put (common_sent, &hash, data, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); - } + { + char *data = GNUNET_malloc(element_size); + GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); + GNUNET_CRYPTO_hash(data, element_size, &hash); + GNUNET_CONTAINER_multihashmap_put(common_sent, &hash, data, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); + } - GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &app_id); + GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_STRONG, &app_id); /* FIXME: also implement intersection etc. */ - info1.set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); - info2.set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); + info1.set = GNUNET_SET_create(config, GNUNET_SET_OPERATION_UNION); + info2.set = GNUNET_SET_create(config, GNUNET_SET_OPERATION_UNION); - GNUNET_CONTAINER_multihashmap_iterate (info1.sent, set_insert_iterator, info1.set); - GNUNET_CONTAINER_multihashmap_iterate (info2.sent, set_insert_iterator, info2.set); - GNUNET_CONTAINER_multihashmap_iterate (common_sent, set_insert_iterator, info1.set); - GNUNET_CONTAINER_multihashmap_iterate (common_sent, set_insert_iterator, info2.set); + GNUNET_CONTAINER_multihashmap_iterate(info1.sent, set_insert_iterator, info1.set); + GNUNET_CONTAINER_multihashmap_iterate(info2.sent, set_insert_iterator, info2.set); + GNUNET_CONTAINER_multihashmap_iterate(common_sent, set_insert_iterator, info1.set); + GNUNET_CONTAINER_multihashmap_iterate(common_sent, set_insert_iterator, info2.set); - set_listener = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION, - &app_id, set_listen_cb, NULL); + set_listener = GNUNET_SET_listen(config, GNUNET_SET_OPERATION_UNION, + &app_id, set_listen_cb, NULL); if (byzantine) - { - opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_BYZANTINE }; - } - GNUNET_assert (!(force_full && force_delta)); + { + opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_BYZANTINE }; + } + GNUNET_assert(!(force_full && force_delta)); if (force_full) - { - opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_FULL }; - } + { + opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_FULL }; + } if (force_delta) - { - opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_DELTA }; - } + { + opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_DELTA }; + } opts[n_opts].type = 0; - info1.oh = GNUNET_SET_prepare (&local_peer, &app_id, NULL, - GNUNET_SET_RESULT_SYMMETRIC, - opts, - set_result_cb, &info1); - GNUNET_SET_commit (info1.oh, info1.set); - GNUNET_SET_destroy (info1.set); + info1.oh = GNUNET_SET_prepare(&local_peer, &app_id, NULL, + GNUNET_SET_RESULT_SYMMETRIC, + opts, + set_result_cb, &info1); + GNUNET_SET_commit(info1.oh, info1.set); + GNUNET_SET_destroy(info1.set); info1.set = NULL; } static void -pre_run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +pre_run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { - if (0 != GNUNET_TESTING_peer_run ("set-profiler", - cfgfile, - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("set-profiler", + cfgfile, + &run, NULL)) ret = 2; } int -main (int argc, char **argv) +main(int argc, char **argv) { - struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_uint ('A', - "num-first", - NULL, - gettext_noop ("number of values"), - &num_a), - - GNUNET_GETOPT_option_uint ('B', - "num-second", - NULL, - gettext_noop ("number of values"), - &num_b), - - GNUNET_GETOPT_option_flag ('b', - "byzantine", - gettext_noop ("use byzantine mode"), - &byzantine), - - GNUNET_GETOPT_option_uint ('f', - "force-full", - NULL, - gettext_noop ("force sending full set"), - &force_full), - - GNUNET_GETOPT_option_uint ('d', - "force-delta", - NULL, - gettext_noop ("number delta operation"), - &force_delta), - - GNUNET_GETOPT_option_uint ('C', - "num-common", - NULL, - gettext_noop ("number of values"), - &num_c), - - GNUNET_GETOPT_option_string ('x', - "operation", - NULL, - gettext_noop ("operation to execute"), - &op_str), - - GNUNET_GETOPT_option_uint ('w', - "element-size", - NULL, - gettext_noop ("element size"), - &element_size), - - GNUNET_GETOPT_option_filename ('s', - "statistics", - "FILENAME", - gettext_noop ("write statistics to file"), - &statistics_filename), - - GNUNET_GETOPT_OPTION_END + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_option_uint('A', + "num-first", + NULL, + gettext_noop("number of values"), + &num_a), + + GNUNET_GETOPT_option_uint('B', + "num-second", + NULL, + gettext_noop("number of values"), + &num_b), + + GNUNET_GETOPT_option_flag('b', + "byzantine", + gettext_noop("use byzantine mode"), + &byzantine), + + GNUNET_GETOPT_option_uint('f', + "force-full", + NULL, + gettext_noop("force sending full set"), + &force_full), + + GNUNET_GETOPT_option_uint('d', + "force-delta", + NULL, + gettext_noop("number delta operation"), + &force_delta), + + GNUNET_GETOPT_option_uint('C', + "num-common", + NULL, + gettext_noop("number of values"), + &num_c), + + GNUNET_GETOPT_option_string('x', + "operation", + NULL, + gettext_noop("operation to execute"), + &op_str), + + GNUNET_GETOPT_option_uint('w', + "element-size", + NULL, + gettext_noop("element size"), + &element_size), + + GNUNET_GETOPT_option_filename('s', + "statistics", + "FILENAME", + gettext_noop("write statistics to file"), + &statistics_filename), + + GNUNET_GETOPT_OPTION_END }; - GNUNET_PROGRAM_run2 (argc, argv, "gnunet-set-profiler", - "help", - options, &pre_run, NULL, GNUNET_YES); + + GNUNET_PROGRAM_run2(argc, argv, "gnunet-set-profiler", + "help", + options, &pre_run, NULL, GNUNET_YES); return ret; } diff --git a/src/set/ibf.c b/src/set/ibf.c index 43d2e7bce..a573ef6b4 100644 --- a/src/set/ibf.c +++ b/src/set/ibf.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/ibf.c @@ -30,7 +30,7 @@ * Compute the key's hash from the key. * Redefine to use a different hash function. */ -#define IBF_KEY_HASH_VAL(k) (GNUNET_CRYPTO_crc32_n (&(k), sizeof (struct IBF_KeyHash))) +#define IBF_KEY_HASH_VAL(k) (GNUNET_CRYPTO_crc32_n(&(k), sizeof(struct IBF_KeyHash))) /** * Create a key from a hashcode. @@ -39,9 +39,9 @@ * @return a key */ struct IBF_Key -ibf_key_from_hashcode (const struct GNUNET_HashCode *hash) +ibf_key_from_hashcode(const struct GNUNET_HashCode *hash) { - return *(struct IBF_Key *) hash; + return *(struct IBF_Key *)hash; } /** @@ -52,14 +52,14 @@ ibf_key_from_hashcode (const struct GNUNET_HashCode *hash) * @param dst hashcode to store the result in */ void -ibf_hashcode_from_key (struct IBF_Key key, - struct GNUNET_HashCode *dst) +ibf_hashcode_from_key(struct IBF_Key key, + struct GNUNET_HashCode *dst) { struct IBF_Key *p; unsigned int i; - const unsigned int keys_per_hashcode = sizeof (struct GNUNET_HashCode) / sizeof (struct IBF_Key); + const unsigned int keys_per_hashcode = sizeof(struct GNUNET_HashCode) / sizeof(struct IBF_Key); - p = (struct IBF_Key *) dst; + p = (struct IBF_Key *)dst; for (i = 0; i < keys_per_hashcode; i++) *p++ = key; } @@ -73,34 +73,34 @@ ibf_hashcode_from_key (struct IBF_Key key, * @return the newly created invertible bloom filter, NULL on error */ struct InvertibleBloomFilter * -ibf_create (uint32_t size, uint8_t hash_num) +ibf_create(uint32_t size, uint8_t hash_num) { struct InvertibleBloomFilter *ibf; - GNUNET_assert (0 != size); + GNUNET_assert(0 != size); - ibf = GNUNET_new (struct InvertibleBloomFilter); - ibf->count = GNUNET_malloc_large (size * sizeof (uint8_t)); + ibf = GNUNET_new(struct InvertibleBloomFilter); + ibf->count = GNUNET_malloc_large(size * sizeof(uint8_t)); if (NULL == ibf->count) - { - GNUNET_free (ibf); - return NULL; - } - ibf->key_sum = GNUNET_malloc_large (size * sizeof (struct IBF_Key)); + { + GNUNET_free(ibf); + return NULL; + } + ibf->key_sum = GNUNET_malloc_large(size * sizeof(struct IBF_Key)); if (NULL == ibf->key_sum) - { - GNUNET_free (ibf->count); - GNUNET_free (ibf); - return NULL; - } - ibf->key_hash_sum = GNUNET_malloc_large (size * sizeof (struct IBF_KeyHash)); + { + GNUNET_free(ibf->count); + GNUNET_free(ibf); + return NULL; + } + ibf->key_hash_sum = GNUNET_malloc_large(size * sizeof(struct IBF_KeyHash)); if (NULL == ibf->key_hash_sum) - { - GNUNET_free (ibf->key_sum); - GNUNET_free (ibf->count); - GNUNET_free (ibf); - return NULL; - } + { + GNUNET_free(ibf->key_sum); + GNUNET_free(ibf->count); + GNUNET_free(ibf); + return NULL; + } ibf->size = size; ibf->hash_num = hash_num; @@ -112,45 +112,45 @@ ibf_create (uint32_t size, uint8_t hash_num) * Store unique bucket indices for the specified key in dst. */ static void -ibf_get_indices (const struct InvertibleBloomFilter *ibf, - struct IBF_Key key, - int *dst) +ibf_get_indices(const struct InvertibleBloomFilter *ibf, + struct IBF_Key key, + int *dst) { uint32_t filled; uint32_t i; uint32_t bucket; - bucket = GNUNET_CRYPTO_crc32_n (&key, sizeof key); - for (i = 0, filled=0; filled < ibf->hash_num; i++) - { - unsigned int j; - uint64_t x; - for (j = 0; j < filled; j++) - if (dst[j] == bucket) - goto try_next; - dst[filled++] = bucket % ibf->size; - try_next: ; - x = ((uint64_t) bucket << 32) | i; - bucket = GNUNET_CRYPTO_crc32_n (&x, sizeof x); - } + bucket = GNUNET_CRYPTO_crc32_n(&key, sizeof key); + for (i = 0, filled = 0; filled < ibf->hash_num; i++) + { + unsigned int j; + uint64_t x; + for (j = 0; j < filled; j++) + if (dst[j] == bucket) + goto try_next; + dst[filled++] = bucket % ibf->size; +try_next:; + x = ((uint64_t)bucket << 32) | i; + bucket = GNUNET_CRYPTO_crc32_n(&x, sizeof x); + } } static void -ibf_insert_into (struct InvertibleBloomFilter *ibf, - struct IBF_Key key, - const int *buckets, int side) +ibf_insert_into(struct InvertibleBloomFilter *ibf, + struct IBF_Key key, + const int *buckets, int side) { int i; for (i = 0; i < ibf->hash_num; i++) - { - const int bucket = buckets[i]; - ibf->count[bucket].count_val += side; - ibf->key_sum[bucket].key_val ^= key.key_val; - ibf->key_hash_sum[bucket].key_hash_val - ^= IBF_KEY_HASH_VAL (key); - } + { + const int bucket = buckets[i]; + ibf->count[bucket].count_val += side; + ibf->key_sum[bucket].key_val ^= key.key_val; + ibf->key_hash_sum[bucket].key_hash_val + ^= IBF_KEY_HASH_VAL(key); + } } @@ -161,12 +161,13 @@ ibf_insert_into (struct InvertibleBloomFilter *ibf, * @param key the element's hash code */ void -ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key) +ibf_insert(struct InvertibleBloomFilter *ibf, struct IBF_Key key) { int buckets[ibf->hash_num]; - GNUNET_assert (ibf->hash_num <= ibf->size); - ibf_get_indices (ibf, key, buckets); - ibf_insert_into (ibf, key, buckets, 1); + + GNUNET_assert(ibf->hash_num <= ibf->size); + ibf_get_indices(ibf, key, buckets); + ibf_insert_into(ibf, key, buckets, 1); } @@ -177,12 +178,13 @@ ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key) * @param key the element's hash code */ void -ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key) +ibf_remove(struct InvertibleBloomFilter *ibf, struct IBF_Key key) { int buckets[ibf->hash_num]; - GNUNET_assert (ibf->hash_num <= ibf->size); - ibf_get_indices (ibf, key, buckets); - ibf_insert_into (ibf, key, buckets, -1); + + GNUNET_assert(ibf->hash_num <= ibf->size); + ibf_get_indices(ibf, key, buckets); + ibf_insert_into(ibf, key, buckets, -1); } @@ -190,18 +192,19 @@ ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key) * Test is the IBF is empty, i.e. all counts, keys and key hashes are zero. */ static int -ibf_is_empty (struct InvertibleBloomFilter *ibf) +ibf_is_empty(struct InvertibleBloomFilter *ibf) { int i; + for (i = 0; i < ibf->size; i++) - { - if (0 != ibf->count[i].count_val) - return GNUNET_NO; - if (0 != ibf->key_hash_sum[i].key_hash_val) - return GNUNET_NO; - if (0 != ibf->key_sum[i].key_val) - return GNUNET_NO; - } + { + if (0 != ibf->count[i].count_val) + return GNUNET_NO; + if (0 != ibf->key_hash_sum[i].key_hash_val) + return GNUNET_NO; + if (0 != ibf->key_sum[i].key_val) + return GNUNET_NO; + } return GNUNET_YES; } @@ -219,53 +222,53 @@ ibf_is_empty (struct InvertibleBloomFilter *ibf) * GNUNET_SYSERR if the decoding has failed */ int -ibf_decode (struct InvertibleBloomFilter *ibf, - int *ret_side, struct IBF_Key *ret_id) +ibf_decode(struct InvertibleBloomFilter *ibf, + int *ret_side, struct IBF_Key *ret_id) { struct IBF_KeyHash hash; int i; int buckets[ibf->hash_num]; - GNUNET_assert (NULL != ibf); + GNUNET_assert(NULL != ibf); for (i = 0; i < ibf->size; i++) - { - int j; - int hit; + { + int j; + int hit; - /* we can only decode from pure buckets */ - if ((1 != ibf->count[i].count_val) && (-1 != ibf->count[i].count_val)) - continue; + /* we can only decode from pure buckets */ + if ((1 != ibf->count[i].count_val) && (-1 != ibf->count[i].count_val)) + continue; - hash.key_hash_val = IBF_KEY_HASH_VAL (ibf->key_sum[i]); + hash.key_hash_val = IBF_KEY_HASH_VAL(ibf->key_sum[i]); - /* test if the hash matches the key */ - if (hash.key_hash_val != ibf->key_hash_sum[i].key_hash_val) - continue; + /* test if the hash matches the key */ + if (hash.key_hash_val != ibf->key_hash_sum[i].key_hash_val) + continue; - /* test if key in bucket hits its own location, - * if not, the key hash was subject to collision */ - hit = GNUNET_NO; - ibf_get_indices (ibf, ibf->key_sum[i], buckets); - for (j = 0; j < ibf->hash_num; j++) - if (buckets[j] == i) - hit = GNUNET_YES; + /* test if key in bucket hits its own location, + * if not, the key hash was subject to collision */ + hit = GNUNET_NO; + ibf_get_indices(ibf, ibf->key_sum[i], buckets); + for (j = 0; j < ibf->hash_num; j++) + if (buckets[j] == i) + hit = GNUNET_YES; - if (GNUNET_NO == hit) - continue; + if (GNUNET_NO == hit) + continue; - if (NULL != ret_side) - *ret_side = ibf->count[i].count_val; - if (NULL != ret_id) - *ret_id = ibf->key_sum[i]; + if (NULL != ret_side) + *ret_side = ibf->count[i].count_val; + if (NULL != ret_id) + *ret_id = ibf->key_sum[i]; - /* insert on the opposite side, effectively removing the element */ - ibf_insert_into (ibf, ibf->key_sum[i], buckets, -ibf->count[i].count_val); + /* insert on the opposite side, effectively removing the element */ + ibf_insert_into(ibf, ibf->key_sum[i], buckets, -ibf->count[i].count_val); - return GNUNET_YES; - } + return GNUNET_YES; + } - if (GNUNET_YES == ibf_is_empty (ibf)) + if (GNUNET_YES == ibf_is_empty(ibf)) return GNUNET_NO; return GNUNET_SYSERR; } @@ -281,25 +284,25 @@ ibf_decode (struct InvertibleBloomFilter *ibf, * @param buf buffer to write the data to */ void -ibf_write_slice (const struct InvertibleBloomFilter *ibf, uint32_t start, uint32_t count, void *buf) +ibf_write_slice(const struct InvertibleBloomFilter *ibf, uint32_t start, uint32_t count, void *buf) { struct IBF_Key *key_dst; struct IBF_KeyHash *key_hash_dst; struct IBF_Count *count_dst; - GNUNET_assert (start + count <= ibf->size); + GNUNET_assert(start + count <= ibf->size); /* copy keys */ - key_dst = (struct IBF_Key *) buf; - GNUNET_memcpy (key_dst, ibf->key_sum + start, count * sizeof *key_dst); + key_dst = (struct IBF_Key *)buf; + GNUNET_memcpy(key_dst, ibf->key_sum + start, count * sizeof *key_dst); key_dst += count; /* copy key hashes */ - key_hash_dst = (struct IBF_KeyHash *) key_dst; - GNUNET_memcpy (key_hash_dst, ibf->key_hash_sum + start, count * sizeof *key_hash_dst); + key_hash_dst = (struct IBF_KeyHash *)key_dst; + GNUNET_memcpy(key_hash_dst, ibf->key_hash_sum + start, count * sizeof *key_hash_dst); key_hash_dst += count; /* copy counts */ - count_dst = (struct IBF_Count *) key_hash_dst; - GNUNET_memcpy (count_dst, ibf->count + start, count * sizeof *count_dst); + count_dst = (struct IBF_Count *)key_hash_dst; + GNUNET_memcpy(count_dst, ibf->count + start, count * sizeof *count_dst); } @@ -312,26 +315,26 @@ ibf_write_slice (const struct InvertibleBloomFilter *ibf, uint32_t start, uint32 * @param ibf the ibf to read from */ void -ibf_read_slice (const void *buf, uint32_t start, uint32_t count, struct InvertibleBloomFilter *ibf) +ibf_read_slice(const void *buf, uint32_t start, uint32_t count, struct InvertibleBloomFilter *ibf) { struct IBF_Key *key_src; struct IBF_KeyHash *key_hash_src; struct IBF_Count *count_src; - GNUNET_assert (count > 0); - GNUNET_assert (start + count <= ibf->size); + GNUNET_assert(count > 0); + GNUNET_assert(start + count <= ibf->size); /* copy keys */ - key_src = (struct IBF_Key *) buf; - GNUNET_memcpy (ibf->key_sum + start, key_src, count * sizeof *key_src); + key_src = (struct IBF_Key *)buf; + GNUNET_memcpy(ibf->key_sum + start, key_src, count * sizeof *key_src); key_src += count; /* copy key hashes */ - key_hash_src = (struct IBF_KeyHash *) key_src; - GNUNET_memcpy (ibf->key_hash_sum + start, key_hash_src, count * sizeof *key_hash_src); + key_hash_src = (struct IBF_KeyHash *)key_src; + GNUNET_memcpy(ibf->key_hash_sum + start, key_hash_src, count * sizeof *key_hash_src); key_hash_src += count; /* copy counts */ - count_src = (struct IBF_Count *) key_hash_src; - GNUNET_memcpy (ibf->count + start, count_src, count * sizeof *count_src); + count_src = (struct IBF_Count *)key_hash_src; + GNUNET_memcpy(ibf->count + start, count_src, count * sizeof *count_src); } @@ -343,19 +346,19 @@ ibf_read_slice (const void *buf, uint32_t start, uint32_t count, struct Invertib * @param ibf2 IBF that will be subtracted from ibf1 */ void -ibf_subtract (struct InvertibleBloomFilter *ibf1, const struct InvertibleBloomFilter *ibf2) +ibf_subtract(struct InvertibleBloomFilter *ibf1, const struct InvertibleBloomFilter *ibf2) { int i; - GNUNET_assert (ibf1->size == ibf2->size); - GNUNET_assert (ibf1->hash_num == ibf2->hash_num); + GNUNET_assert(ibf1->size == ibf2->size); + GNUNET_assert(ibf1->hash_num == ibf2->hash_num); for (i = 0; i < ibf1->size; i++) - { - ibf1->count[i].count_val -= ibf2->count[i].count_val; - ibf1->key_hash_sum[i].key_hash_val ^= ibf2->key_hash_sum[i].key_hash_val; - ibf1->key_sum[i].key_val ^= ibf2->key_sum[i].key_val; - } + { + ibf1->count[i].count_val -= ibf2->count[i].count_val; + ibf1->key_hash_sum[i].key_hash_val ^= ibf2->key_hash_sum[i].key_hash_val; + ibf1->key_sum[i].key_val ^= ibf2->key_sum[i].key_val; + } } @@ -365,15 +368,16 @@ ibf_subtract (struct InvertibleBloomFilter *ibf1, const struct InvertibleBloomFi * @param ibf the IBF to copy */ struct InvertibleBloomFilter * -ibf_dup (const struct InvertibleBloomFilter *ibf) +ibf_dup(const struct InvertibleBloomFilter *ibf) { struct InvertibleBloomFilter *copy; - copy = GNUNET_malloc (sizeof *copy); + + copy = GNUNET_malloc(sizeof *copy); copy->hash_num = ibf->hash_num; copy->size = ibf->size; - copy->key_hash_sum = GNUNET_memdup (ibf->key_hash_sum, ibf->size * sizeof (struct IBF_KeyHash)); - copy->key_sum = GNUNET_memdup (ibf->key_sum, ibf->size * sizeof (struct IBF_Key)); - copy->count = GNUNET_memdup (ibf->count, ibf->size * sizeof (struct IBF_Count)); + copy->key_hash_sum = GNUNET_memdup(ibf->key_hash_sum, ibf->size * sizeof(struct IBF_KeyHash)); + copy->key_sum = GNUNET_memdup(ibf->key_sum, ibf->size * sizeof(struct IBF_Key)); + copy->count = GNUNET_memdup(ibf->count, ibf->size * sizeof(struct IBF_Count)); return copy; } @@ -385,10 +389,10 @@ ibf_dup (const struct InvertibleBloomFilter *ibf) * @param ibf the intertible bloom filter to destroy */ void -ibf_destroy (struct InvertibleBloomFilter *ibf) +ibf_destroy(struct InvertibleBloomFilter *ibf) { - GNUNET_free (ibf->key_sum); - GNUNET_free (ibf->key_hash_sum); - GNUNET_free (ibf->count); - GNUNET_free (ibf); + GNUNET_free(ibf->key_sum); + GNUNET_free(ibf->key_hash_sum); + GNUNET_free(ibf->count); + GNUNET_free(ibf); } diff --git a/src/set/ibf.h b/src/set/ibf.h index dd0edc053..94079a39f 100644 --- a/src/set/ibf.h +++ b/src/set/ibf.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/ibf.h @@ -42,8 +42,7 @@ extern "C" /** * Keys that can be inserted into and removed from an IBF. */ -struct IBF_Key -{ +struct IBF_Key { uint64_t key_val; }; @@ -51,8 +50,7 @@ struct IBF_Key /** * Hash of an IBF key. */ -struct IBF_KeyHash -{ +struct IBF_KeyHash { uint32_t key_hash_val; }; @@ -60,8 +58,7 @@ struct IBF_KeyHash /** * Type of the count field of IBF buckets. */ -struct IBF_Count -{ +struct IBF_Count { int8_t count_val; }; @@ -69,8 +66,8 @@ struct IBF_Count /** * Size of one ibf bucket in bytes */ -#define IBF_BUCKET_SIZE (sizeof (struct IBF_Count) + sizeof (struct IBF_Key) + \ - sizeof (struct IBF_KeyHash)) +#define IBF_BUCKET_SIZE (sizeof(struct IBF_Count) + sizeof(struct IBF_Key) + \ + sizeof(struct IBF_KeyHash)) /** @@ -79,8 +76,7 @@ struct IBF_Count * An IBF is a counting bloom filter that has the ability to restore * the hashes of its stored elements with high probability. */ -struct InvertibleBloomFilter -{ +struct InvertibleBloomFilter { /** * How many cells does this IBF have? */ @@ -123,10 +119,10 @@ struct InvertibleBloomFilter * @param buf buffer to write the data to */ void -ibf_write_slice (const struct InvertibleBloomFilter *ibf, - uint32_t start, - uint32_t count, - void *buf); +ibf_write_slice(const struct InvertibleBloomFilter *ibf, + uint32_t start, + uint32_t count, + void *buf); /** @@ -138,10 +134,10 @@ ibf_write_slice (const struct InvertibleBloomFilter *ibf, * @param ibf the ibf to write to */ void -ibf_read_slice (const void *buf, - uint32_t start, - uint32_t count, - struct InvertibleBloomFilter *ibf); +ibf_read_slice(const void *buf, + uint32_t start, + uint32_t count, + struct InvertibleBloomFilter *ibf); /** @@ -151,7 +147,7 @@ ibf_read_slice (const void *buf, * @return a key */ struct IBF_Key -ibf_key_from_hashcode (const struct GNUNET_HashCode *hash); +ibf_key_from_hashcode(const struct GNUNET_HashCode *hash); /** @@ -162,7 +158,7 @@ ibf_key_from_hashcode (const struct GNUNET_HashCode *hash); * @param dst hashcode to store the result in */ void -ibf_hashcode_from_key (struct IBF_Key key, struct GNUNET_HashCode *dst); +ibf_hashcode_from_key(struct IBF_Key key, struct GNUNET_HashCode *dst); /** @@ -173,7 +169,7 @@ ibf_hashcode_from_key (struct IBF_Key key, struct GNUNET_HashCode *dst); * @return the newly created invertible bloom filter, NULL on error */ struct InvertibleBloomFilter * -ibf_create (uint32_t size, uint8_t hash_num); +ibf_create(uint32_t size, uint8_t hash_num); /** @@ -183,7 +179,7 @@ ibf_create (uint32_t size, uint8_t hash_num); * @param key the element's hash code */ void -ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key); +ibf_insert(struct InvertibleBloomFilter *ibf, struct IBF_Key key); /** @@ -193,7 +189,7 @@ ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key); * @param key the element's hash code */ void -ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key); +ibf_remove(struct InvertibleBloomFilter *ibf, struct IBF_Key key); /** @@ -204,8 +200,8 @@ ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key); * @param ibf2 IBF that will be subtracted from ibf1 */ void -ibf_subtract (struct InvertibleBloomFilter *ibf1, - const struct InvertibleBloomFilter *ibf2); +ibf_subtract(struct InvertibleBloomFilter *ibf1, + const struct InvertibleBloomFilter *ibf2); /** @@ -221,9 +217,9 @@ ibf_subtract (struct InvertibleBloomFilter *ibf1, * #GNUNET_SYSERR if the decoding has failed */ int -ibf_decode (struct InvertibleBloomFilter *ibf, - int *ret_side, - struct IBF_Key *ret_id); +ibf_decode(struct InvertibleBloomFilter *ibf, + int *ret_side, + struct IBF_Key *ret_id); /** @@ -232,7 +228,7 @@ ibf_decode (struct InvertibleBloomFilter *ibf, * @param ibf the IBF to copy */ struct InvertibleBloomFilter * -ibf_dup (const struct InvertibleBloomFilter *ibf); +ibf_dup(const struct InvertibleBloomFilter *ibf); /** @@ -242,7 +238,7 @@ ibf_dup (const struct InvertibleBloomFilter *ibf); * @param ibf the intertible bloom filter to destroy */ void -ibf_destroy (struct InvertibleBloomFilter *ibf); +ibf_destroy(struct InvertibleBloomFilter *ibf); #if 0 /* keep Emacsens' auto-indent happy */ diff --git a/src/set/ibf_sim.c b/src/set/ibf_sim.c index d05e06188..02b675f4a 100644 --- a/src/set/ibf_sim.c +++ b/src/set/ibf_sim.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/ibf_sim.c @@ -62,76 +62,77 @@ main(int argc, char **argv) unsigned int want; double predict; - srandom (time (NULL)); + srandom(time(NULL)); total = 0; - want = atoi (argv[1]); - for (round=0;round= 0; j--) - { + buckets[j]++; + } + ret = 0; + predict = 0.0; + for (j = 31; j >= 0; j--) + { #if FIX1 - /* improved algorithm, for 1000 elements with IBF-DECODE 8, I - get 990/1000 elements on average over 1 million runs; key - idea being to stop short of the 'last' possible IBF as - otherwise a "lowball" per-chance would unduely influence the - result */ - if ( (j > 0) && - (buckets[j - 1] > MAX_IBF_DECODE) ) - { - ret *= (1 << (j + 1)); - break; - } + /* improved algorithm, for 1000 elements with IBF-DECODE 8, I + get 990/1000 elements on average over 1 million runs; key + idea being to stop short of the 'last' possible IBF as + otherwise a "lowball" per-chance would unduely influence the + result */ + if ((j > 0) && + (buckets[j - 1] > MAX_IBF_DECODE)) + { + ret *= (1 << (j + 1)); + break; + } #endif #if FIX2 - /* another improvement: don't just always cut off the last one, - but rather try to predict based on all previous values where - that "last" one is; additional prediction can only really - work if MAX_IBF_DECODE is sufficiently high */ - if ( (j > 0) && - ( (buckets[j - 1] > MAX_IBF_DECODE) || - (predict > MAX_IBF_DECODE) ) ) - { - ret *= (1 << (j + 1)); - break; - } + /* another improvement: don't just always cut off the last one, + but rather try to predict based on all previous values where + that "last" one is; additional prediction can only really + work if MAX_IBF_DECODE is sufficiently high */ + if ((j > 0) && + ((buckets[j - 1] > MAX_IBF_DECODE) || + (predict > MAX_IBF_DECODE))) + { + ret *= (1 << (j + 1)); + break; + } #endif #if STRATA - /* original algorithm, for 1000 elements with IBF-DECODE 8, - I get 920/1000 elements on average over 1 million runs */ - if (buckets[j] > MAX_IBF_DECODE) - { - ret *= (1 << (j+1)); - break; - } + /* original algorithm, for 1000 elements with IBF-DECODE 8, + I get 920/1000 elements on average over 1 million runs */ + if (buckets[j] > MAX_IBF_DECODE) + { + ret *= (1 << (j + 1)); + break; + } #endif - ret += buckets[j]; - predict = (buckets[j] + 2.0 * predict) / 2.0; - } + ret += buckets[j]; + predict = (buckets[j] + 2.0 * predict) / 2.0; + } #if VERBOSE - fprintf (stderr, "%u ", ret); + fprintf(stderr, "%u ", ret); #endif - total += ret; - } - fprintf (stderr, "\n"); - fprintf (stdout, "average %llu\n", total / ROUNDS); + total += ret; + } + fprintf(stderr, "\n"); + fprintf(stdout, "average %llu\n", total / ROUNDS); return 0; } diff --git a/src/set/plugin_block_set_test.c b/src/set/plugin_block_set_test.c index f7bdb8920..e7322aea0 100644 --- a/src/set/plugin_block_set_test.c +++ b/src/set/plugin_block_set_test.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/plugin_block_set_test.c @@ -46,20 +46,20 @@ * @return characterization of result */ static enum GNUNET_BLOCK_EvaluationResult -block_plugin_set_test_evaluate (void *cls, - struct GNUNET_BLOCK_Context *ctx, - enum GNUNET_BLOCK_Type type, - struct GNUNET_BLOCK_Group *group, - enum GNUNET_BLOCK_EvaluationOptions eo, - const struct GNUNET_HashCode *query, - const void *xquery, - size_t xquery_size, - const void *reply_block, - size_t reply_block_size) +block_plugin_set_test_evaluate(void *cls, + struct GNUNET_BLOCK_Context *ctx, + enum GNUNET_BLOCK_Type type, + struct GNUNET_BLOCK_Group *group, + enum GNUNET_BLOCK_EvaluationOptions eo, + const struct GNUNET_HashCode *query, + const void *xquery, + size_t xquery_size, + const void *reply_block, + size_t reply_block_size) { - if ( (NULL == reply_block) || - (reply_block_size == 0) || - (0 != ((char *) reply_block)[0]) ) + if ((NULL == reply_block) || + (reply_block_size == 0) || + (0 != ((char *)reply_block)[0])) return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; return GNUNET_BLOCK_EVALUATION_OK_MORE; } @@ -77,11 +77,11 @@ block_plugin_set_test_evaluate (void *cls, * (or if extracting a key from a block of this type does not work) */ static int -block_plugin_set_test_get_key (void *cls, - enum GNUNET_BLOCK_Type type, - const void *block, - size_t block_size, - struct GNUNET_HashCode *key) +block_plugin_set_test_get_key(void *cls, + enum GNUNET_BLOCK_Type type, + const void *block, + size_t block_size, + struct GNUNET_HashCode *key) { return GNUNET_SYSERR; } @@ -91,7 +91,7 @@ block_plugin_set_test_get_key (void *cls, * Entry point for the plugin. */ void * -libgnunet_plugin_block_set_test_init (void *cls) +libgnunet_plugin_block_set_test_init(void *cls) { static enum GNUNET_BLOCK_Type types[] = { @@ -100,7 +100,7 @@ libgnunet_plugin_block_set_test_init (void *cls) }; struct GNUNET_BLOCK_PluginFunctions *api; - api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); + api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); api->evaluate = &block_plugin_set_test_evaluate; api->get_key = &block_plugin_set_test_get_key; api->types = types; @@ -112,11 +112,11 @@ libgnunet_plugin_block_set_test_init (void *cls) * Exit point from the plugin. */ void * -libgnunet_plugin_block_set_test_done (void *cls) +libgnunet_plugin_block_set_test_done(void *cls) { struct GNUNET_BLOCK_PluginFunctions *api = cls; - GNUNET_free (api); + GNUNET_free(api); return NULL; } diff --git a/src/set/set.h b/src/set/set.h index 34b97736c..74c7ddda8 100644 --- a/src/set/set.h +++ b/src/set/set.h @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/set.h * @brief messages used for the set api @@ -37,8 +37,7 @@ GNUNET_NETWORK_STRUCT_BEGIN * a new set to perform operations with. Includes the desired * set operation type. */ -struct GNUNET_SET_CreateMessage -{ +struct GNUNET_SET_CreateMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_CREATE */ @@ -56,8 +55,7 @@ struct GNUNET_SET_CreateMessage * incoming requests to perform a certain type of set operation for a * certain type of application. */ -struct GNUNET_SET_ListenMessage -{ +struct GNUNET_SET_ListenMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_LISTEN */ @@ -72,7 +70,6 @@ struct GNUNET_SET_ListenMessage * application id */ struct GNUNET_HashCode app_id; - }; @@ -80,8 +77,7 @@ struct GNUNET_SET_ListenMessage * Message sent by a listening client to the service to accept * performing the operation with the other peer. */ -struct GNUNET_SET_AcceptMessage -{ +struct GNUNET_SET_AcceptMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_ACCEPT */ @@ -133,8 +129,7 @@ struct GNUNET_SET_AcceptMessage * Message sent by a listening client to the service to reject * performing the operation with the other peer. */ -struct GNUNET_SET_RejectMessage -{ +struct GNUNET_SET_RejectMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_REJECT */ @@ -144,15 +139,13 @@ struct GNUNET_SET_RejectMessage * ID of the incoming request we want to reject. */ uint32_t accept_reject_id GNUNET_PACKED; - }; /** * A request for an operation with another client. */ -struct GNUNET_SET_RequestMessage -{ +struct GNUNET_SET_RequestMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_REQUEST. */ @@ -179,8 +172,7 @@ struct GNUNET_SET_RequestMessage * client (not as listener). A set (which determines the operation * type) must already exist in association with this client. */ -struct GNUNET_SET_EvaluateMessage -{ +struct GNUNET_SET_EvaluateMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_EVALUATE */ @@ -243,8 +235,7 @@ struct GNUNET_SET_EvaluateMessage * (set union) or part of the final result, depending on * options specified for the operation. */ -struct GNUNET_SET_ResultMessage -{ +struct GNUNET_SET_ResultMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_RESULT */ @@ -279,8 +270,7 @@ struct GNUNET_SET_ResultMessage * Message sent by client to the service to add or remove * an element to/from the set. */ -struct GNUNET_SET_ElementMessage -{ +struct GNUNET_SET_ElementMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_ADD or * #GNUNET_MESSAGE_TYPE_SET_REMOVE @@ -305,8 +295,7 @@ struct GNUNET_SET_ElementMessage * Sent to the service by the client * in order to cancel a set operation. */ -struct GNUNET_SET_CancelMessage -{ +struct GNUNET_SET_CancelMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_CANCEL */ @@ -323,8 +312,7 @@ struct GNUNET_SET_CancelMessage * Set element transmitted by service to client in response to a set * iteration request. */ -struct GNUNET_SET_IterResponseMessage -{ +struct GNUNET_SET_IterResponseMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT */ @@ -349,8 +337,7 @@ struct GNUNET_SET_IterResponseMessage /** * Client acknowledges receiving element in iteration. */ -struct GNUNET_SET_IterAckMessage -{ +struct GNUNET_SET_IterAckMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_ITER_ACK */ @@ -366,8 +353,7 @@ struct GNUNET_SET_IterAckMessage /** * Server responds to a lazy copy request. */ -struct GNUNET_SET_CopyLazyResponseMessage -{ +struct GNUNET_SET_CopyLazyResponseMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE */ @@ -383,8 +369,7 @@ struct GNUNET_SET_CopyLazyResponseMessage /** * Client connects to a lazily copied set. */ -struct GNUNET_SET_CopyLazyConnectMessage -{ +struct GNUNET_SET_CopyLazyConnectMessage { /** * Type: #GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT */ diff --git a/src/set/set_api.c b/src/set/set_api.c index 3b92cd26c..7db5abcbd 100644 --- a/src/set/set_api.c +++ b/src/set/set_api.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/set_api.c * @brief api for the set service @@ -30,10 +30,9 @@ #include "set.h" -#define LOG(kind,...) GNUNET_log_from (kind, "set-api",__VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from(kind, "set-api", __VA_ARGS__) -struct SetCopyRequest -{ +struct SetCopyRequest { struct SetCopyRequest *next; struct SetCopyRequest *prev; @@ -46,8 +45,7 @@ struct SetCopyRequest /** * Opaque handle to a set. */ -struct GNUNET_SET_Handle -{ +struct GNUNET_SET_Handle { /** * Message queue for @e client. */ @@ -112,8 +110,7 @@ struct GNUNET_SET_Handle /** * Handle for a set operation request from another peer. */ -struct GNUNET_SET_Request -{ +struct GNUNET_SET_Request { /** * Id of the request, used to identify the request when * accepting/rejecting it. @@ -132,8 +129,7 @@ struct GNUNET_SET_Request * Handle to an operation. Only known to the service after committing * the handle with a set. */ -struct GNUNET_SET_OperationHandle -{ +struct GNUNET_SET_OperationHandle { /** * Function to be called when we have a result, * or an error. @@ -183,9 +179,7 @@ struct GNUNET_SET_OperationHandle /** * Opaque handle to a listen operation. */ -struct GNUNET_SET_ListenHandle -{ - +struct GNUNET_SET_ListenHandle { /** * Message queue for the client. */ @@ -233,9 +227,9 @@ struct GNUNET_SET_ListenHandle /* mutual recursion with handle_copy_lazy */ static struct GNUNET_SET_Handle * -create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, - enum GNUNET_SET_OperationType op, - const uint32_t *cookie); +create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg, + enum GNUNET_SET_OperationType op, + const uint32_t *cookie); /** @@ -246,8 +240,8 @@ create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, * @param msg the message */ static void -handle_copy_lazy (void *cls, - const struct GNUNET_SET_CopyLazyResponseMessage *msg) +handle_copy_lazy(void *cls, + const struct GNUNET_SET_CopyLazyResponseMessage *msg) { struct GNUNET_SET_Handle *set = cls; struct SetCopyRequest *req; @@ -255,24 +249,24 @@ handle_copy_lazy (void *cls, req = set->copy_req_head; if (NULL == req) - { - /* Service sent us unsolicited lazy copy response */ - GNUNET_break (0); - return; - } + { + /* Service sent us unsolicited lazy copy response */ + GNUNET_break(0); + return; + } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Handling response to lazy copy\n"); - GNUNET_CONTAINER_DLL_remove (set->copy_req_head, - set->copy_req_tail, - req); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Handling response to lazy copy\n"); + GNUNET_CONTAINER_DLL_remove(set->copy_req_head, + set->copy_req_tail, + req); // We pass none as operation here, since it doesn't matter when // cloning. - new_set = create_internal (set->cfg, - GNUNET_SET_OPERATION_NONE, - &msg->cookie); - req->cb (req->cls, new_set); - GNUNET_free (req); + new_set = create_internal(set->cfg, + GNUNET_SET_OPERATION_NONE, + &msg->cookie); + req->cb(req->cls, new_set); + GNUNET_free(req); } @@ -284,8 +278,8 @@ handle_copy_lazy (void *cls, * @return #GNUNET_OK if message is well-formed */ static int -check_iter_element (void *cls, - const struct GNUNET_SET_IterResponseMessage *msg) +check_iter_element(void *cls, + const struct GNUNET_SET_IterResponseMessage *msg) { /* minimum size was already checked, everything else is OK! */ return GNUNET_OK; @@ -300,8 +294,8 @@ check_iter_element (void *cls, * @param mh the message */ static void -handle_iter_element (void *cls, - const struct GNUNET_SET_IterResponseMessage *msg) +handle_iter_element(void *cls, + const struct GNUNET_SET_IterResponseMessage *msg) { struct GNUNET_SET_Handle *set = cls; GNUNET_SET_ElementIterator iter = set->iterator; @@ -310,26 +304,26 @@ handle_iter_element (void *cls, struct GNUNET_MQ_Envelope *ev; uint16_t msize; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received element in set iteration\n"); - msize = ntohs (msg->header.size); - if (set->iteration_id != ntohs (msg->iteration_id)) - { - /* element from a previous iteration, skip! */ - iter = NULL; - } + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Received element in set iteration\n"); + msize = ntohs(msg->header.size); + if (set->iteration_id != ntohs(msg->iteration_id)) + { + /* element from a previous iteration, skip! */ + iter = NULL; + } if (NULL != iter) - { - element.size = msize - sizeof (struct GNUNET_SET_IterResponseMessage); - element.element_type = ntohs (msg->element_type); - element.data = &msg[1]; - iter (set->iterator_cls, - &element); - } - ev = GNUNET_MQ_msg (ack_msg, - GNUNET_MESSAGE_TYPE_SET_ITER_ACK); - ack_msg->send_more = htonl ((NULL != iter)); - GNUNET_MQ_send (set->mq, ev); + { + element.size = msize - sizeof(struct GNUNET_SET_IterResponseMessage); + element.element_type = ntohs(msg->element_type); + element.data = &msg[1]; + iter(set->iterator_cls, + &element); + } + ev = GNUNET_MQ_msg(ack_msg, + GNUNET_MESSAGE_TYPE_SET_ITER_ACK); + ack_msg->send_more = htonl((NULL != iter)); + GNUNET_MQ_send(set->mq, ev); } @@ -341,31 +335,31 @@ handle_iter_element (void *cls, * @param mh the message */ static void -handle_iter_done (void *cls, - const struct GNUNET_MessageHeader *mh) +handle_iter_done(void *cls, + const struct GNUNET_MessageHeader *mh) { struct GNUNET_SET_Handle *set = cls; GNUNET_SET_ElementIterator iter = set->iterator; if (NULL == iter) - { - /* FIXME: if this is true, could cancel+start a fresh one - cause elements to go to the wrong iteration? */ - LOG (GNUNET_ERROR_TYPE_INFO, - "Service completed set iteration that was already cancelled\n"); - return; - } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Set iteration completed\n"); + { + /* FIXME: if this is true, could cancel+start a fresh one + cause elements to go to the wrong iteration? */ + LOG(GNUNET_ERROR_TYPE_INFO, + "Service completed set iteration that was already cancelled\n"); + return; + } + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Set iteration completed\n"); set->destroy_requested = GNUNET_SYSERR; set->iterator = NULL; set->iteration_id++; - iter (set->iterator_cls, - NULL); + iter(set->iterator_cls, + NULL); if (GNUNET_SYSERR == set->destroy_requested) set->destroy_requested = GNUNET_NO; if (GNUNET_YES == set->destroy_requested) - GNUNET_SET_destroy (set); + GNUNET_SET_destroy(set); } @@ -377,8 +371,8 @@ handle_iter_done (void *cls, * @return #GNUNET_OK if message is well-formed */ static int -check_result (void *cls, - const struct GNUNET_SET_ResultMessage *msg) +check_result(void *cls, + const struct GNUNET_SET_ResultMessage *msg) { /* minimum size was already checked, everything else is OK! */ return GNUNET_OK; @@ -392,8 +386,8 @@ check_result (void *cls, * @param mh the message */ static void -handle_result (void *cls, - const struct GNUNET_SET_ResultMessage *msg) +handle_result(void *cls, + const struct GNUNET_SET_ResultMessage *msg) { struct GNUNET_SET_Handle *set = cls; struct GNUNET_SET_OperationHandle *oh; @@ -401,78 +395,80 @@ handle_result (void *cls, enum GNUNET_SET_Status result_status; int destroy_set; - GNUNET_assert (NULL != set->mq); - result_status = (enum GNUNET_SET_Status) ntohs (msg->result_status); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Got result message with status %d\n", - result_status); + GNUNET_assert(NULL != set->mq); + result_status = (enum GNUNET_SET_Status)ntohs(msg->result_status); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Got result message with status %d\n", + result_status); - oh = GNUNET_MQ_assoc_get (set->mq, - ntohl (msg->request_id)); + oh = GNUNET_MQ_assoc_get(set->mq, + ntohl(msg->request_id)); if (NULL == oh) - { - /* 'oh' can be NULL if we canceled the operation, but the service - did not get the cancel message yet. */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Ignoring result from canceled operation\n"); - return; - } + { + /* 'oh' can be NULL if we canceled the operation, but the service + did not get the cancel message yet. */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Ignoring result from canceled operation\n"); + return; + } switch (result_status) - { + { case GNUNET_SET_STATUS_OK: case GNUNET_SET_STATUS_ADD_LOCAL: case GNUNET_SET_STATUS_ADD_REMOTE: goto do_element; + case GNUNET_SET_STATUS_FAILURE: case GNUNET_SET_STATUS_DONE: goto do_final; + case GNUNET_SET_STATUS_HALF_DONE: /* not used anymore */ - GNUNET_assert (0); - } + GNUNET_assert(0); + } do_final: - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Treating result as final status\n"); - GNUNET_MQ_assoc_remove (set->mq, - ntohl (msg->request_id)); - GNUNET_CONTAINER_DLL_remove (set->ops_head, - set->ops_tail, - oh); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Treating result as final status\n"); + GNUNET_MQ_assoc_remove(set->mq, + ntohl(msg->request_id)); + GNUNET_CONTAINER_DLL_remove(set->ops_head, + set->ops_tail, + oh); /* Need to do this calculation _before_ the result callback, as IF the application still has a valid set handle, it may trigger destruction of the set during the callback. */ destroy_set = (GNUNET_YES == set->destroy_requested) && (NULL == set->ops_head); if (NULL != oh->result_cb) - { - oh->result_cb (oh->result_cls, - NULL, - GNUNET_ntohll (msg->current_size), - result_status); - } + { + oh->result_cb(oh->result_cls, + NULL, + GNUNET_ntohll(msg->current_size), + result_status); + } else - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "No callback for final status\n"); - } + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "No callback for final status\n"); + } if (destroy_set) - GNUNET_SET_destroy (set); - GNUNET_free (oh); + GNUNET_SET_destroy(set); + GNUNET_free(oh); return; do_element: - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Treating result as element\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Treating result as element\n"); e.data = &msg[1]; - e.size = ntohs (msg->header.size) - sizeof (struct GNUNET_SET_ResultMessage); - e.element_type = ntohs (msg->element_type); + e.size = ntohs(msg->header.size) - sizeof(struct GNUNET_SET_ResultMessage); + e.element_type = ntohs(msg->element_type); if (NULL != oh->result_cb) - oh->result_cb (oh->result_cls, - &e, - GNUNET_ntohll (msg->current_size), - result_status); + oh->result_cb(oh->result_cls, + &e, + GNUNET_ntohll(msg->current_size), + result_status); } @@ -482,25 +478,25 @@ do_element: * @param oh set operation to destroy */ static void -set_operation_destroy (struct GNUNET_SET_OperationHandle *oh) +set_operation_destroy(struct GNUNET_SET_OperationHandle *oh) { struct GNUNET_SET_Handle *set = oh->set; struct GNUNET_SET_OperationHandle *h_assoc; if (NULL != oh->conclude_mqm) - GNUNET_MQ_discard (oh->conclude_mqm); + GNUNET_MQ_discard(oh->conclude_mqm); /* is the operation already commited? */ if (NULL != set) - { - GNUNET_CONTAINER_DLL_remove (set->ops_head, - set->ops_tail, - oh); - h_assoc = GNUNET_MQ_assoc_remove (set->mq, - oh->request_id); - GNUNET_assert ( (NULL == h_assoc) || - (h_assoc == oh) ); - } - GNUNET_free (oh); + { + GNUNET_CONTAINER_DLL_remove(set->ops_head, + set->ops_tail, + oh); + h_assoc = GNUNET_MQ_assoc_remove(set->mq, + oh->request_id); + GNUNET_assert((NULL == h_assoc) || + (h_assoc == oh)); + } + GNUNET_free(oh); } @@ -512,29 +508,29 @@ set_operation_destroy (struct GNUNET_SET_OperationHandle *oh) * @param oh set operation to cancel */ void -GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh) +GNUNET_SET_operation_cancel(struct GNUNET_SET_OperationHandle *oh) { struct GNUNET_SET_Handle *set = oh->set; struct GNUNET_SET_CancelMessage *m; struct GNUNET_MQ_Envelope *mqm; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Cancelling SET operation\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Cancelling SET operation\n"); if (NULL != set) - { - mqm = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_SET_CANCEL); - m->request_id = htonl (oh->request_id); - GNUNET_MQ_send (set->mq, mqm); - } - set_operation_destroy (oh); - if ( (NULL != set) && - (GNUNET_YES == set->destroy_requested) && - (NULL == set->ops_head) ) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Destroying set after operation cancel\n"); - GNUNET_SET_destroy (set); - } + { + mqm = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_SET_CANCEL); + m->request_id = htonl(oh->request_id); + GNUNET_MQ_send(set->mq, mqm); + } + set_operation_destroy(oh); + if ((NULL != set) && + (GNUNET_YES == set->destroy_requested) && + (NULL == set->ops_head)) + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Destroying set after operation cancel\n"); + GNUNET_SET_destroy(set); + } } @@ -546,31 +542,31 @@ GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh) * @param error error code */ static void -handle_client_set_error (void *cls, - enum GNUNET_MQ_Error error) +handle_client_set_error(void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_SET_Handle *set = cls; GNUNET_SET_ElementIterator iter = set->iterator; - LOG (GNUNET_ERROR_TYPE_ERROR, - "Handling client set error %d\n", - error); + LOG(GNUNET_ERROR_TYPE_ERROR, + "Handling client set error %d\n", + error); while (NULL != set->ops_head) - { - if ( (NULL != set->ops_head->result_cb) && - (GNUNET_NO == set->destroy_requested) ) - set->ops_head->result_cb (set->ops_head->result_cls, - NULL, - 0, - GNUNET_SET_STATUS_FAILURE); - set_operation_destroy (set->ops_head); - } + { + if ((NULL != set->ops_head->result_cb) && + (GNUNET_NO == set->destroy_requested)) + set->ops_head->result_cb(set->ops_head->result_cls, + NULL, + 0, + GNUNET_SET_STATUS_FAILURE); + set_operation_destroy(set->ops_head); + } set->iterator = NULL; set->iteration_id++; set->invalid = GNUNET_YES; if (NULL != iter) - iter (set->iterator_cls, - NULL); + iter(set->iterator_cls, + NULL); } @@ -578,65 +574,65 @@ handle_client_set_error (void *cls, * FIXME. */ static struct GNUNET_SET_Handle * -create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, - enum GNUNET_SET_OperationType op, - const uint32_t *cookie) +create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg, + enum GNUNET_SET_OperationType op, + const uint32_t *cookie) { - struct GNUNET_SET_Handle *set = GNUNET_new (struct GNUNET_SET_Handle); + struct GNUNET_SET_Handle *set = GNUNET_new(struct GNUNET_SET_Handle); struct GNUNET_MQ_MessageHandler mq_handlers[] = { - GNUNET_MQ_hd_var_size (result, - GNUNET_MESSAGE_TYPE_SET_RESULT, - struct GNUNET_SET_ResultMessage, - set), - GNUNET_MQ_hd_var_size (iter_element, - GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT, - struct GNUNET_SET_IterResponseMessage, - set), - GNUNET_MQ_hd_fixed_size (iter_done, - GNUNET_MESSAGE_TYPE_SET_ITER_DONE, - struct GNUNET_MessageHeader, - set), - GNUNET_MQ_hd_fixed_size (copy_lazy, - GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE, - struct GNUNET_SET_CopyLazyResponseMessage, - set), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_var_size(result, + GNUNET_MESSAGE_TYPE_SET_RESULT, + struct GNUNET_SET_ResultMessage, + set), + GNUNET_MQ_hd_var_size(iter_element, + GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT, + struct GNUNET_SET_IterResponseMessage, + set), + GNUNET_MQ_hd_fixed_size(iter_done, + GNUNET_MESSAGE_TYPE_SET_ITER_DONE, + struct GNUNET_MessageHeader, + set), + GNUNET_MQ_hd_fixed_size(copy_lazy, + GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE, + struct GNUNET_SET_CopyLazyResponseMessage, + set), + GNUNET_MQ_handler_end() }; struct GNUNET_MQ_Envelope *mqm; struct GNUNET_SET_CreateMessage *create_msg; struct GNUNET_SET_CopyLazyConnectMessage *copy_msg; set->cfg = cfg; - set->mq = GNUNET_CLIENT_connect (cfg, - "set", - mq_handlers, - &handle_client_set_error, - set); + set->mq = GNUNET_CLIENT_connect(cfg, + "set", + mq_handlers, + &handle_client_set_error, + set); if (NULL == set->mq) - { - GNUNET_free (set); - return NULL; - } + { + GNUNET_free(set); + return NULL; + } if (NULL == cookie) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Creating new set (operation %u)\n", - op); - mqm = GNUNET_MQ_msg (create_msg, - GNUNET_MESSAGE_TYPE_SET_CREATE); - create_msg->operation = htonl (op); - } + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Creating new set (operation %u)\n", + op); + mqm = GNUNET_MQ_msg(create_msg, + GNUNET_MESSAGE_TYPE_SET_CREATE); + create_msg->operation = htonl(op); + } else - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Creating new set (lazy copy)\n", - op); - mqm = GNUNET_MQ_msg (copy_msg, - GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT); - copy_msg->cookie = *cookie; - } - GNUNET_MQ_send (set->mq, - mqm); + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Creating new set (lazy copy)\n", + op); + mqm = GNUNET_MQ_msg(copy_msg, + GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT); + copy_msg->cookie = *cookie; + } + GNUNET_MQ_send(set->mq, + mqm); return set; } @@ -653,18 +649,18 @@ create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, * @return a handle to the set */ struct GNUNET_SET_Handle * -GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg, - enum GNUNET_SET_OperationType op) +GNUNET_SET_create(const struct GNUNET_CONFIGURATION_Handle *cfg, + enum GNUNET_SET_OperationType op) { struct GNUNET_SET_Handle *set; - set = create_internal (cfg, - op, - NULL); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Creating set %p for operation %d\n", - set, - op); + set = create_internal(cfg, + op, + NULL); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Creating set %p for operation %d\n", + set, + op); return set; } @@ -683,35 +679,35 @@ GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg, * set is invalid (e.g. the set service crashed) */ int -GNUNET_SET_add_element (struct GNUNET_SET_Handle *set, - const struct GNUNET_SET_Element *element, - GNUNET_SET_Continuation cont, - void *cont_cls) +GNUNET_SET_add_element(struct GNUNET_SET_Handle *set, + const struct GNUNET_SET_Element *element, + GNUNET_SET_Continuation cont, + void *cont_cls) { struct GNUNET_MQ_Envelope *mqm; struct GNUNET_SET_ElementMessage *msg; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "adding element of type %u to set %p\n", - (unsigned int) element->element_type, - set); - GNUNET_assert (NULL != set); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "adding element of type %u to set %p\n", + (unsigned int)element->element_type, + set); + GNUNET_assert(NULL != set); if (GNUNET_YES == set->invalid) - { - if (NULL != cont) - cont (cont_cls); - return GNUNET_SYSERR; - } - mqm = GNUNET_MQ_msg_extra (msg, - element->size, - GNUNET_MESSAGE_TYPE_SET_ADD); - msg->element_type = htons (element->element_type); - GNUNET_memcpy (&msg[1], - element->data, - element->size); - GNUNET_MQ_notify_sent (mqm, - cont, cont_cls); - GNUNET_MQ_send (set->mq, mqm); + { + if (NULL != cont) + cont(cont_cls); + return GNUNET_SYSERR; + } + mqm = GNUNET_MQ_msg_extra(msg, + element->size, + GNUNET_MESSAGE_TYPE_SET_ADD); + msg->element_type = htons(element->element_type); + GNUNET_memcpy(&msg[1], + element->data, + element->size); + GNUNET_MQ_notify_sent(mqm, + cont, cont_cls); + GNUNET_MQ_send(set->mq, mqm); return GNUNET_OK; } @@ -730,33 +726,33 @@ GNUNET_SET_add_element (struct GNUNET_SET_Handle *set, * set is invalid (e.g. the set service crashed) */ int -GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set, - const struct GNUNET_SET_Element *element, - GNUNET_SET_Continuation cont, - void *cont_cls) +GNUNET_SET_remove_element(struct GNUNET_SET_Handle *set, + const struct GNUNET_SET_Element *element, + GNUNET_SET_Continuation cont, + void *cont_cls) { struct GNUNET_MQ_Envelope *mqm; struct GNUNET_SET_ElementMessage *msg; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Removing element from set %p\n", - set); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Removing element from set %p\n", + set); if (GNUNET_YES == set->invalid) - { - if (NULL != cont) - cont (cont_cls); - return GNUNET_SYSERR; - } - mqm = GNUNET_MQ_msg_extra (msg, - element->size, - GNUNET_MESSAGE_TYPE_SET_REMOVE); - msg->element_type = htons (element->element_type); - GNUNET_memcpy (&msg[1], - element->data, - element->size); - GNUNET_MQ_notify_sent (mqm, - cont, cont_cls); - GNUNET_MQ_send (set->mq, mqm); + { + if (NULL != cont) + cont(cont_cls); + return GNUNET_SYSERR; + } + mqm = GNUNET_MQ_msg_extra(msg, + element->size, + GNUNET_MESSAGE_TYPE_SET_REMOVE); + msg->element_type = htons(element->element_type); + GNUNET_memcpy(&msg[1], + element->data, + element->size); + GNUNET_MQ_notify_sent(mqm, + cont, cont_cls); + GNUNET_MQ_send(set->mq, mqm); return GNUNET_OK; } @@ -768,29 +764,29 @@ GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set, * @param set set handle to destroy */ void -GNUNET_SET_destroy (struct GNUNET_SET_Handle *set) +GNUNET_SET_destroy(struct GNUNET_SET_Handle *set) { /* destroying set while iterator is active is currently not supported; we should expand the API to allow clients to explicitly cancel the iteration! */ - GNUNET_assert (NULL != set); - if ( (NULL != set->ops_head) || - (NULL != set->iterator) || - (GNUNET_SYSERR == set->destroy_requested) ) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Set operations are pending, delaying set destruction\n"); - set->destroy_requested = GNUNET_YES; - return; - } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Really destroying set\n"); + GNUNET_assert(NULL != set); + if ((NULL != set->ops_head) || + (NULL != set->iterator) || + (GNUNET_SYSERR == set->destroy_requested)) + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Set operations are pending, delaying set destruction\n"); + set->destroy_requested = GNUNET_YES; + return; + } + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Really destroying set\n"); if (NULL != set->mq) - { - GNUNET_MQ_destroy (set->mq); - set->mq = NULL; - } - GNUNET_free (set); + { + GNUNET_MQ_destroy(set->mq); + set->mq = NULL; + } + GNUNET_free(set); } @@ -809,50 +805,53 @@ GNUNET_SET_destroy (struct GNUNET_SET_Handle *set) * @return a handle to cancel the operation */ struct GNUNET_SET_OperationHandle * -GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer, - const struct GNUNET_HashCode *app_id, - const struct GNUNET_MessageHeader *context_msg, - enum GNUNET_SET_ResultMode result_mode, - struct GNUNET_SET_Option options[], - GNUNET_SET_ResultIterator result_cb, - void *result_cls) +GNUNET_SET_prepare(const struct GNUNET_PeerIdentity *other_peer, + const struct GNUNET_HashCode *app_id, + const struct GNUNET_MessageHeader *context_msg, + enum GNUNET_SET_ResultMode result_mode, + struct GNUNET_SET_Option options[], + GNUNET_SET_ResultIterator result_cb, + void *result_cls) { struct GNUNET_MQ_Envelope *mqm; struct GNUNET_SET_OperationHandle *oh; struct GNUNET_SET_EvaluateMessage *msg; struct GNUNET_SET_Option *opt; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Client prepares set operation (%d)\n", - result_mode); - oh = GNUNET_new (struct GNUNET_SET_OperationHandle); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Client prepares set operation (%d)\n", + result_mode); + oh = GNUNET_new(struct GNUNET_SET_OperationHandle); oh->result_cb = result_cb; oh->result_cls = result_cls; - mqm = GNUNET_MQ_msg_nested_mh (msg, - GNUNET_MESSAGE_TYPE_SET_EVALUATE, - context_msg); + mqm = GNUNET_MQ_msg_nested_mh(msg, + GNUNET_MESSAGE_TYPE_SET_EVALUATE, + context_msg); msg->app_id = *app_id; - msg->result_mode = htonl (result_mode); + msg->result_mode = htonl(result_mode); msg->target_peer = *other_peer; for (opt = options; opt->type != 0; opt++) - { - switch (opt->type) { - case GNUNET_SET_OPTION_BYZANTINE: - msg->byzantine = GNUNET_YES; - msg->byzantine_lower_bound = opt->v.num; - break; - case GNUNET_SET_OPTION_FORCE_FULL: - msg->force_full = GNUNET_YES; - break; - case GNUNET_SET_OPTION_FORCE_DELTA: - msg->force_delta = GNUNET_YES; - break; - default: - LOG (GNUNET_ERROR_TYPE_ERROR, - "Option with type %d not recognized\n", (int) opt->type); + switch (opt->type) + { + case GNUNET_SET_OPTION_BYZANTINE: + msg->byzantine = GNUNET_YES; + msg->byzantine_lower_bound = opt->v.num; + break; + + case GNUNET_SET_OPTION_FORCE_FULL: + msg->force_full = GNUNET_YES; + break; + + case GNUNET_SET_OPTION_FORCE_DELTA: + msg->force_delta = GNUNET_YES; + break; + + default: + LOG(GNUNET_ERROR_TYPE_ERROR, + "Option with type %d not recognized\n", (int)opt->type); + } } - } oh->conclude_mqm = mqm; oh->request_id_addr = &msg->request_id; @@ -866,7 +865,7 @@ GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer, * @param cls the `struct GNUNET_SET_ListenHandle *` to connect */ static void -listen_connect (void *cls); +listen_connect(void *cls); /** @@ -877,20 +876,20 @@ listen_connect (void *cls); * @return #GNUNET_OK if the message is well-formed */ static int -check_request (void *cls, - const struct GNUNET_SET_RequestMessage *msg) +check_request(void *cls, + const struct GNUNET_SET_RequestMessage *msg) { const struct GNUNET_MessageHeader *context_msg; - if (ntohs (msg->header.size) == sizeof (*msg)) + if (ntohs(msg->header.size) == sizeof(*msg)) return GNUNET_OK; /* no context message is OK */ - context_msg = GNUNET_MQ_extract_nested_mh (msg); + context_msg = GNUNET_MQ_extract_nested_mh(msg); if (NULL == context_msg) - { - /* malformed context message is NOT ok */ - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + /* malformed context message is NOT ok */ + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -902,8 +901,8 @@ check_request (void *cls, * @param msg the message */ static void -handle_request (void *cls, - const struct GNUNET_SET_RequestMessage *msg) +handle_request(void *cls, + const struct GNUNET_SET_RequestMessage *msg) { struct GNUNET_SET_ListenHandle *lh = cls; struct GNUNET_SET_Request req; @@ -911,28 +910,28 @@ handle_request (void *cls, struct GNUNET_MQ_Envelope *mqm; struct GNUNET_SET_RejectMessage *rmsg; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Processing incoming operation request with id %u\n", - ntohl (msg->accept_id)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Processing incoming operation request with id %u\n", + ntohl(msg->accept_id)); /* we got another valid request => reset the backoff */ lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; - req.accept_id = ntohl (msg->accept_id); + req.accept_id = ntohl(msg->accept_id); req.accepted = GNUNET_NO; - context_msg = GNUNET_MQ_extract_nested_mh (msg); + context_msg = GNUNET_MQ_extract_nested_mh(msg); /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */ - lh->listen_cb (lh->listen_cls, - &msg->peer_id, - context_msg, - &req); + lh->listen_cb(lh->listen_cls, + &msg->peer_id, + context_msg, + &req); if (GNUNET_YES == req.accepted) return; /* the accept-case is handled in #GNUNET_SET_accept() */ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Rejected request %u\n", - ntohl (msg->accept_id)); - mqm = GNUNET_MQ_msg (rmsg, - GNUNET_MESSAGE_TYPE_SET_REJECT); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Rejected request %u\n", + ntohl(msg->accept_id)); + mqm = GNUNET_MQ_msg(rmsg, + GNUNET_MESSAGE_TYPE_SET_REJECT); rmsg->accept_reject_id = msg->accept_id; - GNUNET_MQ_send (lh->mq, mqm); + GNUNET_MQ_send(lh->mq, mqm); } @@ -944,20 +943,20 @@ handle_request (void *cls, * @param error reason for the disconnect */ static void -handle_client_listener_error (void *cls, - enum GNUNET_MQ_Error error) +handle_client_listener_error(void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_SET_ListenHandle *lh = cls; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Listener broke down (%d), re-connecting\n", - (int) error); - GNUNET_MQ_destroy (lh->mq); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Listener broke down (%d), re-connecting\n", + (int)error); + GNUNET_MQ_destroy(lh->mq); lh->mq = NULL; - lh->reconnect_task = GNUNET_SCHEDULER_add_delayed (lh->reconnect_backoff, - &listen_connect, - lh); - lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (lh->reconnect_backoff); + lh->reconnect_task = GNUNET_SCHEDULER_add_delayed(lh->reconnect_backoff, + &listen_connect, + lh); + lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF(lh->reconnect_backoff); } @@ -967,33 +966,33 @@ handle_client_listener_error (void *cls, * @param cls the `struct GNUNET_SET_ListenHandle *` to connect */ static void -listen_connect (void *cls) +listen_connect(void *cls) { struct GNUNET_SET_ListenHandle *lh = cls; struct GNUNET_MQ_MessageHandler mq_handlers[] = { - GNUNET_MQ_hd_var_size (request, - GNUNET_MESSAGE_TYPE_SET_REQUEST, - struct GNUNET_SET_RequestMessage, - lh), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_var_size(request, + GNUNET_MESSAGE_TYPE_SET_REQUEST, + struct GNUNET_SET_RequestMessage, + lh), + GNUNET_MQ_handler_end() }; struct GNUNET_MQ_Envelope *mqm; struct GNUNET_SET_ListenMessage *msg; lh->reconnect_task = NULL; - GNUNET_assert (NULL == lh->mq); - lh->mq = GNUNET_CLIENT_connect (lh->cfg, - "set", - mq_handlers, - &handle_client_listener_error, - lh); + GNUNET_assert(NULL == lh->mq); + lh->mq = GNUNET_CLIENT_connect(lh->cfg, + "set", + mq_handlers, + &handle_client_listener_error, + lh); if (NULL == lh->mq) return; - mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_LISTEN); - msg->operation = htonl (lh->operation); + mqm = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_SET_LISTEN); + msg->operation = htonl(lh->operation); msg->app_id = lh->app_id; - GNUNET_MQ_send (lh->mq, - mqm); + GNUNET_MQ_send(lh->mq, + mqm); } @@ -1010,30 +1009,30 @@ listen_connect (void *cls) * @return a handle that can be used to cancel the listen operation */ struct GNUNET_SET_ListenHandle * -GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, - enum GNUNET_SET_OperationType operation, - const struct GNUNET_HashCode *app_id, - GNUNET_SET_ListenCallback listen_cb, - void *listen_cls) +GNUNET_SET_listen(const struct GNUNET_CONFIGURATION_Handle *cfg, + enum GNUNET_SET_OperationType operation, + const struct GNUNET_HashCode *app_id, + GNUNET_SET_ListenCallback listen_cb, + void *listen_cls) { struct GNUNET_SET_ListenHandle *lh; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Starting listener for app %s\n", - GNUNET_h2s (app_id)); - lh = GNUNET_new (struct GNUNET_SET_ListenHandle); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Starting listener for app %s\n", + GNUNET_h2s(app_id)); + lh = GNUNET_new(struct GNUNET_SET_ListenHandle); lh->listen_cb = listen_cb; lh->listen_cls = listen_cls; lh->cfg = cfg; lh->operation = operation; lh->app_id = *app_id; lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; - listen_connect (lh); + listen_connect(lh); if (NULL == lh->mq) - { - GNUNET_free (lh); - return NULL; - } + { + GNUNET_free(lh); + return NULL; + } return lh; } @@ -1044,22 +1043,22 @@ GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, * @param lh handle for the listen operation */ void -GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh) +GNUNET_SET_listen_cancel(struct GNUNET_SET_ListenHandle *lh) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Canceling listener %s\n", - GNUNET_h2s (&lh->app_id)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Canceling listener %s\n", + GNUNET_h2s(&lh->app_id)); if (NULL != lh->mq) - { - GNUNET_MQ_destroy (lh->mq); - lh->mq = NULL; - } + { + GNUNET_MQ_destroy(lh->mq); + lh->mq = NULL; + } if (NULL != lh->reconnect_task) - { - GNUNET_SCHEDULER_cancel (lh->reconnect_task); - lh->reconnect_task = NULL; - } - GNUNET_free (lh); + { + GNUNET_SCHEDULER_cancel(lh->reconnect_task); + lh->reconnect_task = NULL; + } + GNUNET_free(lh); } @@ -1078,27 +1077,27 @@ GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh) * @return a handle to cancel the operation */ struct GNUNET_SET_OperationHandle * -GNUNET_SET_accept (struct GNUNET_SET_Request *request, - enum GNUNET_SET_ResultMode result_mode, - struct GNUNET_SET_Option options[], - GNUNET_SET_ResultIterator result_cb, - void *result_cls) +GNUNET_SET_accept(struct GNUNET_SET_Request *request, + enum GNUNET_SET_ResultMode result_mode, + struct GNUNET_SET_Option options[], + GNUNET_SET_ResultIterator result_cb, + void *result_cls) { struct GNUNET_MQ_Envelope *mqm; struct GNUNET_SET_OperationHandle *oh; struct GNUNET_SET_AcceptMessage *msg; - GNUNET_assert (GNUNET_NO == request->accepted); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Client accepts set operation (%d) with id %u\n", - result_mode, - request->accept_id); + GNUNET_assert(GNUNET_NO == request->accepted); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Client accepts set operation (%d) with id %u\n", + result_mode, + request->accept_id); request->accepted = GNUNET_YES; - mqm = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_SET_ACCEPT); - msg->accept_reject_id = htonl (request->accept_id); - msg->result_mode = htonl (result_mode); - oh = GNUNET_new (struct GNUNET_SET_OperationHandle); + mqm = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_SET_ACCEPT); + msg->accept_reject_id = htonl(request->accept_id); + msg->result_mode = htonl(result_mode); + oh = GNUNET_new(struct GNUNET_SET_OperationHandle); oh->result_cb = result_cb; oh->result_cls = result_cls; oh->conclude_mqm = mqm; @@ -1121,31 +1120,31 @@ GNUNET_SET_accept (struct GNUNET_SET_Request *request, * set is invalid (e.g. the set service crashed) */ int -GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh, - struct GNUNET_SET_Handle *set) +GNUNET_SET_commit(struct GNUNET_SET_OperationHandle *oh, + struct GNUNET_SET_Handle *set) { if (NULL != oh->set) - { - /* Some other set was already committed for this - * operation, there is a logic bug in the client of this API */ - GNUNET_break (0); - return GNUNET_OK; - } - GNUNET_assert (NULL != set); + { + /* Some other set was already committed for this + * operation, there is a logic bug in the client of this API */ + GNUNET_break(0); + return GNUNET_OK; + } + GNUNET_assert(NULL != set); if (GNUNET_YES == set->invalid) return GNUNET_SYSERR; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Client commits to SET\n"); - GNUNET_assert (NULL != oh->conclude_mqm); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Client commits to SET\n"); + GNUNET_assert(NULL != oh->conclude_mqm); oh->set = set; - GNUNET_CONTAINER_DLL_insert (set->ops_head, - set->ops_tail, - oh); - oh->request_id = GNUNET_MQ_assoc_add (set->mq, - oh); - *oh->request_id_addr = htonl (oh->request_id); - GNUNET_MQ_send (set->mq, - oh->conclude_mqm); + GNUNET_CONTAINER_DLL_insert(set->ops_head, + set->ops_tail, + oh); + oh->request_id = GNUNET_MQ_assoc_add(set->mq, + oh); + *oh->request_id_addr = htonl(oh->request_id); + GNUNET_MQ_send(set->mq, + oh->conclude_mqm); oh->conclude_mqm = NULL; oh->request_id_addr = NULL; return GNUNET_OK; @@ -1165,46 +1164,46 @@ GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh, * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected) */ int -GNUNET_SET_iterate (struct GNUNET_SET_Handle *set, - GNUNET_SET_ElementIterator iter, - void *iter_cls) +GNUNET_SET_iterate(struct GNUNET_SET_Handle *set, + GNUNET_SET_ElementIterator iter, + void *iter_cls) { struct GNUNET_MQ_Envelope *ev; - GNUNET_assert (NULL != iter); + GNUNET_assert(NULL != iter); if (GNUNET_YES == set->invalid) return GNUNET_SYSERR; if (NULL != set->iterator) return GNUNET_NO; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Iterating over set\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Iterating over set\n"); set->iterator = iter; set->iterator_cls = iter_cls; - ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST); - GNUNET_MQ_send (set->mq, ev); + ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST); + GNUNET_MQ_send(set->mq, ev); return GNUNET_YES; } void -GNUNET_SET_copy_lazy (struct GNUNET_SET_Handle *set, - GNUNET_SET_CopyReadyCallback cb, - void *cls) +GNUNET_SET_copy_lazy(struct GNUNET_SET_Handle *set, + GNUNET_SET_CopyReadyCallback cb, + void *cls) { struct GNUNET_MQ_Envelope *ev; struct SetCopyRequest *req; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Creating lazy copy of set\n"); - ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE); - GNUNET_MQ_send (set->mq, ev); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Creating lazy copy of set\n"); + ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE); + GNUNET_MQ_send(set->mq, ev); - req = GNUNET_new (struct SetCopyRequest); + req = GNUNET_new(struct SetCopyRequest); req->cb = cb; req->cls = cls; - GNUNET_CONTAINER_DLL_insert (set->copy_req_head, - set->copy_req_tail, - req); + GNUNET_CONTAINER_DLL_insert(set->copy_req_head, + set->copy_req_tail, + req); } @@ -1216,17 +1215,17 @@ GNUNET_SET_copy_lazy (struct GNUNET_SET_Handle *set, * @return the copied element */ struct GNUNET_SET_Element * -GNUNET_SET_element_dup (const struct GNUNET_SET_Element *element) +GNUNET_SET_element_dup(const struct GNUNET_SET_Element *element) { struct GNUNET_SET_Element *copy; - copy = GNUNET_malloc (element->size + sizeof (struct GNUNET_SET_Element)); + copy = GNUNET_malloc(element->size + sizeof(struct GNUNET_SET_Element)); copy->size = element->size; copy->element_type = element->element_type; copy->data = ©[1]; - GNUNET_memcpy (©[1], - element->data, - copy->size); + GNUNET_memcpy(©[1], + element->data, + copy->size); return copy; } @@ -1239,17 +1238,17 @@ GNUNET_SET_element_dup (const struct GNUNET_SET_Element *element) * should be stored */ void -GNUNET_SET_element_hash (const struct GNUNET_SET_Element *element, - struct GNUNET_HashCode *ret_hash) +GNUNET_SET_element_hash(const struct GNUNET_SET_Element *element, + struct GNUNET_HashCode *ret_hash) { - struct GNUNET_HashContext *ctx = GNUNET_CRYPTO_hash_context_start (); + struct GNUNET_HashContext *ctx = GNUNET_CRYPTO_hash_context_start(); /* It's not guaranteed that the element data is always after the element header, so we need to hash the chunks separately. */ - GNUNET_CRYPTO_hash_context_read (ctx, &element->size, sizeof (uint16_t)); - GNUNET_CRYPTO_hash_context_read (ctx, &element->element_type, sizeof (uint16_t)); - GNUNET_CRYPTO_hash_context_read (ctx, element->data, element->size); - GNUNET_CRYPTO_hash_context_finish (ctx, ret_hash); + GNUNET_CRYPTO_hash_context_read(ctx, &element->size, sizeof(uint16_t)); + GNUNET_CRYPTO_hash_context_read(ctx, &element->element_type, sizeof(uint16_t)); + GNUNET_CRYPTO_hash_context_read(ctx, element->data, element->size); + GNUNET_CRYPTO_hash_context_finish(ctx, ret_hash); } /* end of set_api.c */ diff --git a/src/set/test_set_api.c b/src/set/test_set_api.c index 0f2b20a01..7cfa222b1 100644 --- a/src/set/test_set_api.c +++ b/src/set/test_set_api.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/test_set_api.c @@ -53,100 +53,106 @@ static struct GNUNET_SCHEDULER_Task *tt; static void -result_cb_set1 (void *cls, - const struct GNUNET_SET_Element *element, - uint64_t size, - enum GNUNET_SET_Status status) +result_cb_set1(void *cls, + const struct GNUNET_SET_Element *element, + uint64_t size, + enum GNUNET_SET_Status status) { switch (status) - { - case GNUNET_SET_STATUS_OK: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 1: got element\n"); - break; - case GNUNET_SET_STATUS_FAILURE: - GNUNET_break (0); - oh1 = NULL; - fprintf (stderr, "set 1: received failure status!\n"); - ret = 1; - if (NULL != tt) - { - GNUNET_SCHEDULER_cancel (tt); - tt = NULL; - } - GNUNET_SCHEDULER_shutdown (); - break; - case GNUNET_SET_STATUS_DONE: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 1: done\n"); - oh1 = NULL; - if (NULL != set1) { - GNUNET_SET_destroy (set1); - set1 = NULL; - } - if (NULL == set2) - { - GNUNET_SCHEDULER_cancel (tt); - tt = NULL; - GNUNET_SCHEDULER_shutdown (); + case GNUNET_SET_STATUS_OK: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "set 1: got element\n"); + break; + + case GNUNET_SET_STATUS_FAILURE: + GNUNET_break(0); + oh1 = NULL; + fprintf(stderr, "set 1: received failure status!\n"); + ret = 1; + if (NULL != tt) + { + GNUNET_SCHEDULER_cancel(tt); + tt = NULL; + } + GNUNET_SCHEDULER_shutdown(); + break; + + case GNUNET_SET_STATUS_DONE: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "set 1: done\n"); + oh1 = NULL; + if (NULL != set1) + { + GNUNET_SET_destroy(set1); + set1 = NULL; + } + if (NULL == set2) + { + GNUNET_SCHEDULER_cancel(tt); + tt = NULL; + GNUNET_SCHEDULER_shutdown(); + } + break; + + default: + GNUNET_assert(0); } - break; - default: - GNUNET_assert (0); - } } static void -result_cb_set2 (void *cls, - const struct GNUNET_SET_Element *element, - uint64_t size, - enum GNUNET_SET_Status status) +result_cb_set2(void *cls, + const struct GNUNET_SET_Element *element, + uint64_t size, + enum GNUNET_SET_Status status) { switch (status) - { - case GNUNET_SET_STATUS_OK: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 2: got element\n"); - break; - case GNUNET_SET_STATUS_FAILURE: - GNUNET_break (0); - oh2 = NULL; - fprintf (stderr, "set 2: received failure status\n"); - GNUNET_SCHEDULER_shutdown (); - ret = 1; - break; - case GNUNET_SET_STATUS_DONE: - oh2 = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 2: done\n"); - GNUNET_SET_destroy (set2); - set2 = NULL; - if (NULL == set1) { - GNUNET_SCHEDULER_cancel (tt); - tt = NULL; - GNUNET_SCHEDULER_shutdown (); + case GNUNET_SET_STATUS_OK: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "set 2: got element\n"); + break; + + case GNUNET_SET_STATUS_FAILURE: + GNUNET_break(0); + oh2 = NULL; + fprintf(stderr, "set 2: received failure status\n"); + GNUNET_SCHEDULER_shutdown(); + ret = 1; + break; + + case GNUNET_SET_STATUS_DONE: + oh2 = NULL; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "set 2: done\n"); + GNUNET_SET_destroy(set2); + set2 = NULL; + if (NULL == set1) + { + GNUNET_SCHEDULER_cancel(tt); + tt = NULL; + GNUNET_SCHEDULER_shutdown(); + } + break; + + default: + GNUNET_assert(0); } - break; - default: - GNUNET_assert (0); - } } static void -listen_cb (void *cls, - const struct GNUNET_PeerIdentity *other_peer, - const struct GNUNET_MessageHeader *context_msg, - struct GNUNET_SET_Request *request) +listen_cb(void *cls, + const struct GNUNET_PeerIdentity *other_peer, + const struct GNUNET_MessageHeader *context_msg, + struct GNUNET_SET_Request *request) { - GNUNET_assert (NULL != context_msg); - GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "listen cb called\n"); - oh2 = GNUNET_SET_accept (request, - GNUNET_SET_RESULT_ADDED, - (struct GNUNET_SET_Option[]){0}, - &result_cb_set2, - NULL); - GNUNET_SET_commit (oh2, set2); + GNUNET_assert(NULL != context_msg); + GNUNET_assert(ntohs(context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "listen cb called\n"); + oh2 = GNUNET_SET_accept(request, + GNUNET_SET_RESULT_ADDED, + (struct GNUNET_SET_Option[]){ 0 }, + &result_cb_set2, + NULL); + GNUNET_SET_commit(oh2, set2); } @@ -156,26 +162,26 @@ listen_cb (void *cls, * @param cls closure, unused */ static void -start (void *cls) +start(void *cls) { struct GNUNET_MessageHeader context_msg; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting reconciliation\n"); - context_msg.size = htons (sizeof context_msg); - context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY); - listen_handle = GNUNET_SET_listen (config, - GNUNET_SET_OPERATION_UNION, - &app_id, - &listen_cb, - NULL); - oh1 = GNUNET_SET_prepare (&local_id, - &app_id, - &context_msg, - GNUNET_SET_RESULT_ADDED, - (struct GNUNET_SET_Option[]){0}, - &result_cb_set1, - NULL); - GNUNET_SET_commit (oh1, set1); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting reconciliation\n"); + context_msg.size = htons(sizeof context_msg); + context_msg.type = htons(GNUNET_MESSAGE_TYPE_DUMMY); + listen_handle = GNUNET_SET_listen(config, + GNUNET_SET_OPERATION_UNION, + &app_id, + &listen_cb, + NULL); + oh1 = GNUNET_SET_prepare(&local_id, + &app_id, + &context_msg, + GNUNET_SET_RESULT_ADDED, + (struct GNUNET_SET_Option[]){ 0 }, + &result_cb_set1, + NULL); + GNUNET_SET_commit(oh1, set1); } @@ -185,22 +191,22 @@ start (void *cls) * @param cls closure, unused */ static void -init_set2 (void *cls) +init_set2(void *cls) { struct GNUNET_SET_Element element; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initializing set 2\n"); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "initializing set 2\n"); element.element_type = 0; element.data = "hello"; - element.size = strlen (element.data); - GNUNET_SET_add_element (set2, &element, NULL, NULL); + element.size = strlen(element.data); + GNUNET_SET_add_element(set2, &element, NULL, NULL); element.data = "quux"; - element.size = strlen (element.data); - GNUNET_SET_add_element (set2, &element, NULL, NULL); + element.size = strlen(element.data); + GNUNET_SET_add_element(set2, &element, NULL, NULL); element.data = "baz"; - element.size = strlen (element.data); - GNUNET_SET_add_element (set2, &element, &start, NULL); + element.size = strlen(element.data); + GNUNET_SET_add_element(set2, &element, &start, NULL); } @@ -208,63 +214,63 @@ init_set2 (void *cls) * Initialize the first set, continue. */ static void -init_set1 (void) +init_set1(void) { struct GNUNET_SET_Element element; element.element_type = 0; element.data = "hello"; - element.size = strlen (element.data); - GNUNET_SET_add_element (set1, &element, NULL, NULL); + element.size = strlen(element.data); + GNUNET_SET_add_element(set1, &element, NULL, NULL); element.data = "bar"; - element.size = strlen (element.data); - GNUNET_SET_add_element (set1, &element, &init_set2, NULL); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized set 1\n"); + element.size = strlen(element.data); + GNUNET_SET_add_element(set1, &element, &init_set2, NULL); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "initialized set 1\n"); } static int -iter_cb (void *cls, const struct GNUNET_SET_Element *element) +iter_cb(void *cls, const struct GNUNET_SET_Element *element) { struct GNUNET_SET_Handle *set = cls; if (NULL == element) - { - GNUNET_assert (3 == iter_count); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Iteration finished, destroying set %p\n", - set); - GNUNET_SET_destroy (set); - return GNUNET_YES; - } + { + GNUNET_assert(3 == iter_count); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Iteration finished, destroying set %p\n", + set); + GNUNET_SET_destroy(set); + return GNUNET_YES; + } iter_count++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "iter: got element %u\n", iter_count); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "iter: got element %u\n", iter_count); return GNUNET_YES; } static void -test_iter () +test_iter() { struct GNUNET_SET_Element element; struct GNUNET_SET_Handle *iter_set; - iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Testing iteration over 3 elements on set %p\n", - iter_set); + iter_set = GNUNET_SET_create(config, GNUNET_SET_OPERATION_UNION); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Testing iteration over 3 elements on set %p\n", + iter_set); element.element_type = 0; element.data = "hello"; - element.size = strlen (element.data); - GNUNET_SET_add_element (iter_set, &element, NULL, NULL); + element.size = strlen(element.data); + GNUNET_SET_add_element(iter_set, &element, NULL, NULL); element.data = "bar"; - element.size = strlen (element.data); - GNUNET_SET_add_element (iter_set, &element, NULL, NULL); + element.size = strlen(element.data); + GNUNET_SET_add_element(iter_set, &element, NULL, NULL); element.data = "quux"; - element.size = strlen (element.data); - GNUNET_SET_add_element (iter_set, &element, NULL, NULL); - GNUNET_SET_iterate (iter_set, &iter_cb, iter_set); + element.size = strlen(element.data); + GNUNET_SET_add_element(iter_set, &element, NULL, NULL); + GNUNET_SET_iterate(iter_set, &iter_cb, iter_set); } @@ -274,11 +280,11 @@ test_iter () * @param cls closure */ static void -timeout_fail (void *cls) +timeout_fail(void *cls) { tt = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Testcase failed with timeout\n"); - GNUNET_SCHEDULER_shutdown (); + GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, "Testcase failed with timeout\n"); + GNUNET_SCHEDULER_shutdown(); ret = 1; } @@ -289,38 +295,38 @@ timeout_fail (void *cls) * @param cls closure */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { if (NULL != tt) - { - GNUNET_SCHEDULER_cancel (tt); - tt = NULL; - } + { + GNUNET_SCHEDULER_cancel(tt); + tt = NULL; + } if (NULL != oh1) - { - GNUNET_SET_operation_cancel (oh1); - oh1 = NULL; - } + { + GNUNET_SET_operation_cancel(oh1); + oh1 = NULL; + } if (NULL != oh2) - { - GNUNET_SET_operation_cancel (oh2); - oh2 = NULL; - } + { + GNUNET_SET_operation_cancel(oh2); + oh2 = NULL; + } if (NULL != set1) - { - GNUNET_SET_destroy (set1); - set1 = NULL; - } + { + GNUNET_SET_destroy(set1); + set1 = NULL; + } if (NULL != set2) - { - GNUNET_SET_destroy (set2); - set2 = NULL; - } + { + GNUNET_SET_destroy(set2); + set2 = NULL; + } if (NULL != listen_handle) - { - GNUNET_SET_listen_cancel (listen_handle); - listen_handle = NULL; - } + { + GNUNET_SET_listen_cancel(listen_handle); + listen_handle = NULL; + } } @@ -333,66 +339,65 @@ do_shutdown (void *cls) * @param peer identity of the peer that was created */ static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { - struct GNUNET_SET_OperationHandle *my_oh; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running preparatory tests\n"); - tt = GNUNET_SCHEDULER_add_delayed ( - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running preparatory tests\n"); + tt = GNUNET_SCHEDULER_add_delayed( + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), &timeout_fail, NULL); - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); config = cfg; - GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_get_peer_identity (cfg, &local_id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "my id (from CRYPTO): %s\n", - GNUNET_i2s (&local_id)); - GNUNET_TESTING_peer_get_identity (peer, &local_id); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "my id (from TESTING): %s\n", - GNUNET_i2s (&local_id)); - test_iter (); - - set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); - set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created sets %p and %p for union operation\n", - set1, - set2); - GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &app_id); + GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_get_peer_identity(cfg, &local_id)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "my id (from CRYPTO): %s\n", + GNUNET_i2s(&local_id)); + GNUNET_TESTING_peer_get_identity(peer, &local_id); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "my id (from TESTING): %s\n", + GNUNET_i2s(&local_id)); + test_iter(); + + set1 = GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_UNION); + set2 = GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_UNION); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Created sets %p and %p for union operation\n", + set1, + set2); + GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &app_id); /* test if canceling an uncommited request works! */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Launching and instantly stopping set operation\n"); - my_oh = GNUNET_SET_prepare (&local_id, - &app_id, - NULL, - GNUNET_SET_RESULT_ADDED, - (struct GNUNET_SET_Option[]){0}, - NULL, - NULL); - GNUNET_SET_operation_cancel (my_oh); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Launching and instantly stopping set operation\n"); + my_oh = GNUNET_SET_prepare(&local_id, + &app_id, + NULL, + GNUNET_SET_RESULT_ADDED, + (struct GNUNET_SET_Option[]){ 0 }, + NULL, + NULL); + GNUNET_SET_operation_cancel(my_oh); /* test the real set reconciliation */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running real set-reconciliation\n"); - init_set1 (); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running real set-reconciliation\n"); + init_set1(); } int -main (int argc, char **argv) +main(int argc, char **argv) { - GNUNET_log_setup ("test_set_api", "WARNING", NULL); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching peer\n"); + GNUNET_log_setup("test_set_api", "WARNING", NULL); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Launching peer\n"); if (0 != - GNUNET_TESTING_peer_run ("test_set_api", "test_set.conf", &run, NULL)) - { - return 1; - } + GNUNET_TESTING_peer_run("test_set_api", "test_set.conf", &run, NULL)) + { + return 1; + } return ret; } diff --git a/src/set/test_set_intersection_result_full.c b/src/set/test_set_intersection_result_full.c index 3f209668d..12ebcb64f 100644 --- a/src/set/test_set_intersection_result_full.c +++ b/src/set/test_set_intersection_result_full.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/test_set_intersection_result_full.c @@ -54,90 +54,96 @@ static struct GNUNET_SET_OperationHandle *oh2; static void -result_cb_set1 (void *cls, - const struct GNUNET_SET_Element *element, - uint64_t current_size, - enum GNUNET_SET_Status status) +result_cb_set1(void *cls, + const struct GNUNET_SET_Element *element, + uint64_t current_size, + enum GNUNET_SET_Status status) { static int count; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Processing result set 1 (%d)\n", - status); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Processing result set 1 (%d)\n", + status); switch (status) - { - case GNUNET_SET_STATUS_OK: - count++; - break; - case GNUNET_SET_STATUS_FAILURE: - oh1 = NULL; - ret = 1; - break; - case GNUNET_SET_STATUS_DONE: - oh1 = NULL; - GNUNET_assert (1 == count); - GNUNET_SET_destroy (set1); - set1 = NULL; - if (NULL == set2) - GNUNET_SCHEDULER_shutdown (); - break; - default: - GNUNET_assert (0); - } + { + case GNUNET_SET_STATUS_OK: + count++; + break; + + case GNUNET_SET_STATUS_FAILURE: + oh1 = NULL; + ret = 1; + break; + + case GNUNET_SET_STATUS_DONE: + oh1 = NULL; + GNUNET_assert(1 == count); + GNUNET_SET_destroy(set1); + set1 = NULL; + if (NULL == set2) + GNUNET_SCHEDULER_shutdown(); + break; + + default: + GNUNET_assert(0); + } } static void -result_cb_set2 (void *cls, - const struct GNUNET_SET_Element *element, - uint64_t current_size, - enum GNUNET_SET_Status status) +result_cb_set2(void *cls, + const struct GNUNET_SET_Element *element, + uint64_t current_size, + enum GNUNET_SET_Status status) { static int count; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Processing result set 2 (%d)\n", - status); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Processing result set 2 (%d)\n", + status); switch (status) - { - case GNUNET_SET_STATUS_OK: - count++; - break; - case GNUNET_SET_STATUS_FAILURE: - oh2 = NULL; - ret = 1; - break; - case GNUNET_SET_STATUS_DONE: - oh2 = NULL; - GNUNET_assert (1 == count); - GNUNET_SET_destroy (set2); - set2 = NULL; - if (NULL == set1) - GNUNET_SCHEDULER_shutdown (); - break; - default: - GNUNET_assert (0); - } + { + case GNUNET_SET_STATUS_OK: + count++; + break; + + case GNUNET_SET_STATUS_FAILURE: + oh2 = NULL; + ret = 1; + break; + + case GNUNET_SET_STATUS_DONE: + oh2 = NULL; + GNUNET_assert(1 == count); + GNUNET_SET_destroy(set2); + set2 = NULL; + if (NULL == set1) + GNUNET_SCHEDULER_shutdown(); + break; + + default: + GNUNET_assert(0); + } } static void -listen_cb (void *cls, - const struct GNUNET_PeerIdentity *other_peer, - const struct GNUNET_MessageHeader *context_msg, - struct GNUNET_SET_Request *request) +listen_cb(void *cls, + const struct GNUNET_PeerIdentity *other_peer, + const struct GNUNET_MessageHeader *context_msg, + struct GNUNET_SET_Request *request) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "starting intersection by accepting and committing\n"); - GNUNET_assert (NULL != context_msg); - GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); - oh2 = GNUNET_SET_accept (request, - GNUNET_SET_RESULT_FULL, - (struct GNUNET_SET_Option[]) { 0 }, - &result_cb_set2, - NULL); - GNUNET_SET_commit (oh2, - set2); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "starting intersection by accepting and committing\n"); + GNUNET_assert(NULL != context_msg); + GNUNET_assert(ntohs(context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); + oh2 = GNUNET_SET_accept(request, + GNUNET_SET_RESULT_FULL, + (struct GNUNET_SET_Option[]) { 0 }, + &result_cb_set2, + NULL); + GNUNET_SET_commit(oh2, + set2); } @@ -147,28 +153,28 @@ listen_cb (void *cls, * @param cls closure, unused */ static void -start (void *cls) +start(void *cls) { struct GNUNET_MessageHeader context_msg; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "starting listener\n"); - context_msg.size = htons (sizeof context_msg); - context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY); - listen_handle = GNUNET_SET_listen (config, - GNUNET_SET_OPERATION_INTERSECTION, - &app_id, - &listen_cb, - NULL); - oh1 = GNUNET_SET_prepare (&local_id, - &app_id, - &context_msg, - GNUNET_SET_RESULT_FULL, - (struct GNUNET_SET_Option[]) { 0 }, - &result_cb_set1, - NULL); - GNUNET_SET_commit (oh1, - set1); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "starting listener\n"); + context_msg.size = htons(sizeof context_msg); + context_msg.type = htons(GNUNET_MESSAGE_TYPE_DUMMY); + listen_handle = GNUNET_SET_listen(config, + GNUNET_SET_OPERATION_INTERSECTION, + &app_id, + &listen_cb, + NULL); + oh1 = GNUNET_SET_prepare(&local_id, + &app_id, + &context_msg, + GNUNET_SET_RESULT_FULL, + (struct GNUNET_SET_Option[]) { 0 }, + &result_cb_set1, + NULL); + GNUNET_SET_commit(oh1, + set1); } @@ -178,31 +184,31 @@ start (void *cls) * @param cls closure, unused */ static void -init_set2 (void *cls) +init_set2(void *cls) { struct GNUNET_SET_Element element; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "initializing set 2\n"); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "initializing set 2\n"); element.element_type = 0; element.data = "hello"; element.size = strlen(element.data); - GNUNET_SET_add_element (set2, - &element, - NULL, - NULL); + GNUNET_SET_add_element(set2, + &element, + NULL, + NULL); element.data = "quux"; element.size = strlen(element.data); - GNUNET_SET_add_element (set2, - &element, - NULL, - NULL); + GNUNET_SET_add_element(set2, + &element, + NULL, + NULL); element.data = "baz"; element.size = strlen(element.data); - GNUNET_SET_add_element (set2, - &element, - &start, - NULL); + GNUNET_SET_add_element(set2, + &element, + &start, + NULL); } @@ -210,73 +216,73 @@ init_set2 (void *cls) * Initialize the first set, continue. */ static void -init_set1 (void) +init_set1(void) { struct GNUNET_SET_Element element; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "initializing set 1\n"); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "initializing set 1\n"); element.element_type = 0; element.data = "hello"; element.size = strlen(element.data); - GNUNET_SET_add_element (set1, - &element, - NULL, - NULL); + GNUNET_SET_add_element(set1, + &element, + NULL, + NULL); element.data = "bar"; element.size = strlen(element.data); - GNUNET_SET_add_element (set1, - &element, - &init_set2, - NULL); + GNUNET_SET_add_element(set1, + &element, + &init_set2, + NULL); } static int -iter_cb (void *cls, - const struct GNUNET_SET_Element *element) +iter_cb(void *cls, + const struct GNUNET_SET_Element *element) { if (NULL == element) - { - GNUNET_assert (iter_count == 3); - GNUNET_SET_destroy (cls); - return GNUNET_YES; - } + { + GNUNET_assert(iter_count == 3); + GNUNET_SET_destroy(cls); + return GNUNET_YES; + } iter_count++; return GNUNET_YES; } static void -test_iter () +test_iter() { struct GNUNET_SET_Element element; struct GNUNET_SET_Handle *iter_set; - iter_set = GNUNET_SET_create (config, - GNUNET_SET_OPERATION_INTERSECTION); + iter_set = GNUNET_SET_create(config, + GNUNET_SET_OPERATION_INTERSECTION); element.element_type = 0; element.data = "hello"; element.size = strlen(element.data); - GNUNET_SET_add_element (iter_set, - &element, - NULL, - NULL); + GNUNET_SET_add_element(iter_set, + &element, + NULL, + NULL); element.data = "bar"; element.size = strlen(element.data); - GNUNET_SET_add_element (iter_set, - &element, - NULL, - NULL); + GNUNET_SET_add_element(iter_set, + &element, + NULL, + NULL); element.data = "quux"; element.size = strlen(element.data); - GNUNET_SET_add_element (iter_set, - &element, - NULL, - NULL); - GNUNET_SET_iterate (iter_set, - &iter_cb, - iter_set); + GNUNET_SET_add_element(iter_set, + &element, + NULL, + NULL); + GNUNET_SET_iterate(iter_set, + &iter_cb, + iter_set); } @@ -286,38 +292,38 @@ test_iter () * @param cls closure */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { if (NULL != tt) - { - GNUNET_SCHEDULER_cancel (tt); - tt = NULL; - } + { + GNUNET_SCHEDULER_cancel(tt); + tt = NULL; + } if (NULL != oh1) - { - GNUNET_SET_operation_cancel (oh1); - oh1 = NULL; - } + { + GNUNET_SET_operation_cancel(oh1); + oh1 = NULL; + } if (NULL != oh2) - { - GNUNET_SET_operation_cancel (oh2); - oh2 = NULL; - } + { + GNUNET_SET_operation_cancel(oh2); + oh2 = NULL; + } if (NULL != set1) - { - GNUNET_SET_destroy (set1); - set1 = NULL; - } + { + GNUNET_SET_destroy(set1); + set1 = NULL; + } if (NULL != set2) - { - GNUNET_SET_destroy (set2); - set2 = NULL; - } + { + GNUNET_SET_destroy(set2); + set2 = NULL; + } if (NULL != listen_handle) - { - GNUNET_SET_listen_cancel (listen_handle); - listen_handle = NULL; - } + { + GNUNET_SET_listen_cancel(listen_handle); + listen_handle = NULL; + } } @@ -327,12 +333,12 @@ do_shutdown (void *cls) * @param cls closure */ static void -timeout_fail (void *cls) +timeout_fail(void *cls) { tt = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, - "Testcase failed with timeout\n"); - GNUNET_SCHEDULER_shutdown (); + GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, + "Testcase failed with timeout\n"); + GNUNET_SCHEDULER_shutdown(); ret = 1; } @@ -346,41 +352,41 @@ timeout_fail (void *cls) * @param peer identity of the peer that was created */ static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { config = cfg; - GNUNET_TESTING_peer_get_identity (peer, - &local_id); + GNUNET_TESTING_peer_get_identity(peer, + &local_id); if (0) - test_iter (); + test_iter(); - tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), - &timeout_fail, - NULL); - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, - NULL); + tt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), + &timeout_fail, + NULL); + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, + NULL); - set1 = GNUNET_SET_create (cfg, - GNUNET_SET_OPERATION_INTERSECTION); - set2 = GNUNET_SET_create (cfg, - GNUNET_SET_OPERATION_INTERSECTION); - GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, - &app_id); + set1 = GNUNET_SET_create(cfg, + GNUNET_SET_OPERATION_INTERSECTION); + set2 = GNUNET_SET_create(cfg, + GNUNET_SET_OPERATION_INTERSECTION); + GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, + &app_id); /* test the real set reconciliation */ - init_set1 (); + init_set1(); } int -main (int argc, - char **argv) +main(int argc, + char **argv) { - if (0 != GNUNET_TESTING_peer_run ("test_set_intersection_result_full", - "test_set.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run("test_set_intersection_result_full", + "test_set.conf", + &run, NULL)) return 1; return ret; } diff --git a/src/set/test_set_union_copy.c b/src/set/test_set_union_copy.c index d129753e8..ab76668cc 100644 --- a/src/set/test_set_union_copy.c +++ b/src/set/test_set_union_copy.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/test_set_union_copy.c @@ -47,34 +47,34 @@ static struct GNUNET_SCHEDULER_Task *tt; static void -add_element_str (struct GNUNET_SET_Handle *set, - char *str) +add_element_str(struct GNUNET_SET_Handle *set, + char *str) { struct GNUNET_SET_Element element; element.element_type = 0; element.data = str; - element.size = strlen (str); - GNUNET_SET_add_element (set, - &element, - NULL, - NULL); + element.size = strlen(str); + GNUNET_SET_add_element(set, + &element, + NULL, + NULL); } static void -remove_element_str (struct GNUNET_SET_Handle *set, - char *str) +remove_element_str(struct GNUNET_SET_Handle *set, + char *str) { struct GNUNET_SET_Element element; element.element_type = 0; element.data = str; - element.size = strlen (str); - GNUNET_SET_remove_element (set, - &element, - NULL, - NULL); + element.size = strlen(str); + GNUNET_SET_remove_element(set, + &element, + NULL, + NULL); } @@ -84,16 +84,15 @@ remove_element_str (struct GNUNET_SET_Handle *set, * @param cls closure */ static void -timeout_fail (void *cls) +timeout_fail(void *cls) { tt = NULL; - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); ret = 1; } -struct CountIterClosure -{ +struct CountIterClosure { unsigned int expected_count; unsigned int ongoing_count; GNUNET_SCHEDULER_TaskCallback cont; @@ -103,33 +102,33 @@ struct CountIterClosure static int -check_count_iter (void *cls, - const struct GNUNET_SET_Element *element) +check_count_iter(void *cls, + const struct GNUNET_SET_Element *element) { struct CountIterClosure *ci_cls = cls; if (NULL == element) - { - if (ci_cls->expected_count != ci_cls->ongoing_count) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Expected count (what: %s) to be %u, but it's actually %u\n", - ci_cls->what, - ci_cls->expected_count, - ci_cls->ongoing_count); - ret = 1; - GNUNET_SCHEDULER_shutdown (); + if (ci_cls->expected_count != ci_cls->ongoing_count) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Expected count (what: %s) to be %u, but it's actually %u\n", + ci_cls->what, + ci_cls->expected_count, + ci_cls->ongoing_count); + ret = 1; + GNUNET_SCHEDULER_shutdown(); + return GNUNET_NO; + } + ci_cls->cont(ci_cls->cont_cls); + GNUNET_free(ci_cls); return GNUNET_NO; } - ci_cls->cont (ci_cls->cont_cls); - GNUNET_free (ci_cls); - return GNUNET_NO; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Set `%s' has element %.*s\n", - ci_cls->what, - (int) element->size, - (const char *) element->data); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Set `%s' has element %.*s\n", + ci_cls->what, + (int)element->size, + (const char *)element->data); ci_cls->ongoing_count++; return GNUNET_YES; @@ -137,17 +136,17 @@ check_count_iter (void *cls, static void -check_count (struct GNUNET_SET_Handle *set, - char *what, - unsigned int expected_count, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) +check_count(struct GNUNET_SET_Handle *set, + char *what, + unsigned int expected_count, + GNUNET_SCHEDULER_TaskCallback cont, + void *cont_cls) { - struct CountIterClosure *ci_cls = GNUNET_new (struct CountIterClosure); + struct CountIterClosure *ci_cls = GNUNET_new(struct CountIterClosure); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Checking count of %s\n", - what); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Checking count of %s\n", + what); ci_cls->expected_count = expected_count; ci_cls->ongoing_count = 0; @@ -155,65 +154,65 @@ check_count (struct GNUNET_SET_Handle *set, ci_cls->cont_cls = cont_cls; ci_cls->what = what; - GNUNET_assert (GNUNET_YES == - GNUNET_SET_iterate (set, - &check_count_iter, - ci_cls)); + GNUNET_assert(GNUNET_YES == + GNUNET_SET_iterate(set, + &check_count_iter, + ci_cls)); } static void -test_done (void *cls) +test_done(void *cls) { - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); } static void -check_new_set_count (void *cls) +check_new_set_count(void *cls) { - check_count (set2, - "new set", - 3, - &test_done, - NULL); + check_count(set2, + "new set", + 3, + &test_done, + NULL); } static void -copy_done (void *cls, - struct GNUNET_SET_Handle *new_set) +copy_done(void *cls, + struct GNUNET_SET_Handle *new_set) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "copy done\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "copy done\n"); set2 = new_set; - remove_element_str (set2, - "k5555"); - add_element_str (set2, - "n66666"); - add_element_str (set2, - "new2butremoved"); - remove_element_str (set2, - "new2butremoved"); - remove_element_str (set2, - "new3justremoved"); + remove_element_str(set2, + "k5555"); + add_element_str(set2, + "n66666"); + add_element_str(set2, + "new2butremoved"); + remove_element_str(set2, + "new2butremoved"); + remove_element_str(set2, + "new3justremoved"); // Check that set1 didn't change. - check_count (set1, - "old set", - 3, - &check_new_set_count, - NULL); + check_count(set1, + "old set", + 3, + &check_new_set_count, + NULL); } static void -test_copy (void *cls) +test_copy(void *cls) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "about to copy\n"); - GNUNET_SET_copy_lazy (set1, - ©_done, - NULL); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "about to copy\n"); + GNUNET_SET_copy_lazy(set1, + ©_done, + NULL); } @@ -223,23 +222,23 @@ test_copy (void *cls) * @param cls closure */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { if (NULL != tt) - { - GNUNET_SCHEDULER_cancel (tt); - tt = NULL; - } + { + GNUNET_SCHEDULER_cancel(tt); + tt = NULL; + } if (NULL != set1) - { - GNUNET_SET_destroy (set1); - set1 = NULL; - } + { + GNUNET_SET_destroy(set1); + set1 = NULL; + } if (NULL != set2) - { - GNUNET_SET_destroy (set2); - set2 = NULL; - } + { + GNUNET_SET_destroy(set2); + set2 = NULL; + } } @@ -252,59 +251,59 @@ do_shutdown (void *cls) * @param peer identity of the peer that was created */ static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { - tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), - &timeout_fail, - NULL); - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, - NULL); + tt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), + &timeout_fail, + NULL); + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, + NULL); config = cfg; - GNUNET_TESTING_peer_get_identity (peer, - &local_id); - - set1 = GNUNET_SET_create (cfg, - GNUNET_SET_OPERATION_UNION); - add_element_str (set1, - "333"); - add_element_str (set1, - "k444"); + GNUNET_TESTING_peer_get_identity(peer, + &local_id); + + set1 = GNUNET_SET_create(cfg, + GNUNET_SET_OPERATION_UNION); + add_element_str(set1, + "333"); + add_element_str(set1, + "k444"); /* duplicate -- ignored */ - add_element_str (set1, - "k444"); - remove_element_str (set1, - "333"); + add_element_str(set1, + "k444"); + remove_element_str(set1, + "333"); /* non-existent -- ignored */ - remove_element_str (set1, - "999999999"); - add_element_str (set1, - "k5555"); + remove_element_str(set1, + "999999999"); + add_element_str(set1, + "k5555"); /* duplicate -- ignored */ - remove_element_str (set1, - "333"); - add_element_str (set1, - "k2"); - - check_count (set1, - "initial test", - 3, - &test_copy, - NULL); + remove_element_str(set1, + "333"); + add_element_str(set1, + "k2"); + + check_count(set1, + "initial test", + 3, + &test_copy, + NULL); } int -main (int argc, char **argv) +main(int argc, char **argv) { - if (0 != GNUNET_TESTING_peer_run ("test_set_union_copy", - "test_set.conf", - &run, NULL)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "failed to start testing peer\n"); - return 1; - } + if (0 != GNUNET_TESTING_peer_run("test_set_union_copy", + "test_set.conf", + &run, NULL)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "failed to start testing peer\n"); + return 1; + } return ret; } diff --git a/src/set/test_set_union_result_symmetric.c b/src/set/test_set_union_result_symmetric.c index 3fe7e4995..5238aa596 100644 --- a/src/set/test_set_union_result_symmetric.c +++ b/src/set/test_set_union_result_symmetric.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file set/test_set_union_result_smmetric @@ -75,120 +75,128 @@ static struct GNUNET_SCHEDULER_Task *timeout_task; static void -result_cb_set1 (void *cls, - const struct GNUNET_SET_Element *element, - uint64_t current_size, - enum GNUNET_SET_Status status) +result_cb_set1(void *cls, + const struct GNUNET_SET_Element *element, + uint64_t current_size, + enum GNUNET_SET_Status status) { switch (status) - { + { case GNUNET_SET_STATUS_ADD_LOCAL: count_set1++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "set 1: got element\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "set 1: got element\n"); break; + case GNUNET_SET_STATUS_FAILURE: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "set 1: failure\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "set 1: failure\n"); oh1 = NULL; ret = 1; if (NULL != timeout_task) - { - GNUNET_SCHEDULER_cancel (timeout_task); - timeout_task = NULL; - } - GNUNET_SCHEDULER_shutdown (); + { + GNUNET_SCHEDULER_cancel(timeout_task); + timeout_task = NULL; + } + GNUNET_SCHEDULER_shutdown(); break; + case GNUNET_SET_STATUS_DONE: oh1 = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "set 1: done\n"); - GNUNET_SET_destroy (set1); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "set 1: done\n"); + GNUNET_SET_destroy(set1); set1 = NULL; if (NULL == set2) - { - if (NULL != timeout_task) { - GNUNET_SCHEDULER_cancel (timeout_task); - timeout_task = NULL; + if (NULL != timeout_task) + { + GNUNET_SCHEDULER_cancel(timeout_task); + timeout_task = NULL; + } + GNUNET_SCHEDULER_shutdown(); } - GNUNET_SCHEDULER_shutdown (); - } break; + case GNUNET_SET_STATUS_ADD_REMOTE: break; + default: - GNUNET_assert (0); - } + GNUNET_assert(0); + } } static void -result_cb_set2 (void *cls, - const struct GNUNET_SET_Element *element, - uint64_t current_size, - enum GNUNET_SET_Status status) +result_cb_set2(void *cls, + const struct GNUNET_SET_Element *element, + uint64_t current_size, + enum GNUNET_SET_Status status) { switch (status) - { + { case GNUNET_SET_STATUS_ADD_LOCAL: count_set2++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "set 2: got element\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "set 2: got element\n"); break; + case GNUNET_SET_STATUS_FAILURE: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "set 2: failure\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "set 2: failure\n"); oh2 = NULL; ret = 1; if (NULL != timeout_task) - { - GNUNET_SCHEDULER_cancel (timeout_task); - timeout_task = NULL; - } - GNUNET_SCHEDULER_shutdown (); + { + GNUNET_SCHEDULER_cancel(timeout_task); + timeout_task = NULL; + } + GNUNET_SCHEDULER_shutdown(); break; + case GNUNET_SET_STATUS_DONE: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "set 2: done\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "set 2: done\n"); oh2 = NULL; - GNUNET_SET_destroy (set2); + GNUNET_SET_destroy(set2); set2 = NULL; if (NULL == set1) - { - if (NULL != timeout_task) { - GNUNET_SCHEDULER_cancel (timeout_task); - timeout_task = NULL; + if (NULL != timeout_task) + { + GNUNET_SCHEDULER_cancel(timeout_task); + timeout_task = NULL; + } + GNUNET_SCHEDULER_shutdown(); } - GNUNET_SCHEDULER_shutdown (); - } break; + case GNUNET_SET_STATUS_ADD_REMOTE: break; + default: - GNUNET_assert (0); - } + GNUNET_assert(0); + } } static void -listen_cb (void *cls, - const struct GNUNET_PeerIdentity *other_peer, - const struct GNUNET_MessageHeader *context_msg, - struct GNUNET_SET_Request *request) +listen_cb(void *cls, + const struct GNUNET_PeerIdentity *other_peer, + const struct GNUNET_MessageHeader *context_msg, + struct GNUNET_SET_Request *request) { - GNUNET_assert (NULL != context_msg); - GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "listen cb called\n"); - oh2 = GNUNET_SET_accept (request, - GNUNET_SET_RESULT_SYMMETRIC, - (struct GNUNET_SET_Option[]) { 0 }, - &result_cb_set2, - NULL); - GNUNET_SET_commit (oh2, - set2); + GNUNET_assert(NULL != context_msg); + GNUNET_assert(ntohs(context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "listen cb called\n"); + oh2 = GNUNET_SET_accept(request, + GNUNET_SET_RESULT_SYMMETRIC, + (struct GNUNET_SET_Option[]) { 0 }, + &result_cb_set2, + NULL); + GNUNET_SET_commit(oh2, + set2); } @@ -198,24 +206,24 @@ listen_cb (void *cls, * @param cls closure, unused */ static void -start (void *cls) +start(void *cls) { struct GNUNET_MessageHeader context_msg; - context_msg.size = htons (sizeof context_msg); - context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY); - - listen_handle = GNUNET_SET_listen (config, - GNUNET_SET_OPERATION_UNION, - &app_id, - &listen_cb, NULL); - oh1 = GNUNET_SET_prepare (&local_id, - &app_id, - &context_msg, - GNUNET_SET_RESULT_SYMMETRIC, - (struct GNUNET_SET_Option[]) { 0 }, - &result_cb_set1, NULL); - GNUNET_SET_commit (oh1, set1); + context_msg.size = htons(sizeof context_msg); + context_msg.type = htons(GNUNET_MESSAGE_TYPE_DUMMY); + + listen_handle = GNUNET_SET_listen(config, + GNUNET_SET_OPERATION_UNION, + &app_id, + &listen_cb, NULL); + oh1 = GNUNET_SET_prepare(&local_id, + &app_id, + &context_msg, + GNUNET_SET_RESULT_SYMMETRIC, + (struct GNUNET_SET_Option[]) { 0 }, + &result_cb_set1, NULL); + GNUNET_SET_commit(oh1, set1); } @@ -225,35 +233,35 @@ start (void *cls) * @param cls closure, unused */ static void -init_set2 (void *cls) +init_set2(void *cls) { struct GNUNET_SET_Element element; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "initializing set 2\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "initializing set 2\n"); if (empty) - { - start (NULL); - return; - } + { + start(NULL); + return; + } element.element_type = 0; element.data = "hello"; element.size = strlen(element.data); - GNUNET_SET_add_element (set2, - &element, - NULL, - NULL); + GNUNET_SET_add_element(set2, + &element, + NULL, + NULL); element.data = "quux"; element.size = strlen(element.data); - GNUNET_SET_add_element (set2, - &element, - NULL, - NULL); + GNUNET_SET_add_element(set2, + &element, + NULL, + NULL); element.data = "baz"; element.size = strlen(element.data); - GNUNET_SET_add_element (set2, - &element, - &start, NULL); + GNUNET_SET_add_element(set2, + &element, + &start, NULL); } @@ -261,72 +269,72 @@ init_set2 (void *cls) * Initialize the first set, continue. */ static void -init_set1 (void) +init_set1(void) { struct GNUNET_SET_Element element; if (empty) - { - init_set2 (NULL); - return; - } + { + init_set2(NULL); + return; + } element.element_type = 0; element.data = "hello"; element.size = strlen(element.data); - GNUNET_SET_add_element (set1, - &element, - NULL, - NULL); + GNUNET_SET_add_element(set1, + &element, + NULL, + NULL); element.data = "bar"; element.size = strlen(element.data); - GNUNET_SET_add_element (set1, - &element, - &init_set2, - NULL); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "initialized set 1\n"); + GNUNET_SET_add_element(set1, + &element, + &init_set2, + NULL); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "initialized set 1\n"); } static int -iter_cb (void *cls, - const struct GNUNET_SET_Element *element) +iter_cb(void *cls, + const struct GNUNET_SET_Element *element) { if (NULL == element) - { - GNUNET_assert (iter_count == 3); - GNUNET_SET_destroy (cls); - return GNUNET_YES; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "iter: got element\n"); + { + GNUNET_assert(iter_count == 3); + GNUNET_SET_destroy(cls); + return GNUNET_YES; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "iter: got element\n"); iter_count++; return GNUNET_YES; } static void -test_iter () +test_iter() { struct GNUNET_SET_Element element; struct GNUNET_SET_Handle *iter_set; iter_count = 0; - iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); + iter_set = GNUNET_SET_create(config, GNUNET_SET_OPERATION_UNION); element.element_type = 0; element.data = "hello"; element.size = strlen(element.data); - GNUNET_SET_add_element (iter_set, &element, NULL, NULL); + GNUNET_SET_add_element(iter_set, &element, NULL, NULL); element.data = "bar"; element.size = strlen(element.data); - GNUNET_SET_add_element (iter_set, &element, NULL, NULL); + GNUNET_SET_add_element(iter_set, &element, NULL, NULL); element.data = "quux"; element.size = strlen(element.data); - GNUNET_SET_add_element (iter_set, &element, NULL, NULL); + GNUNET_SET_add_element(iter_set, &element, NULL, NULL); - GNUNET_SET_iterate (iter_set, - &iter_cb, - iter_set); + GNUNET_SET_iterate(iter_set, + &iter_cb, + iter_set); } @@ -336,12 +344,12 @@ test_iter () * @param cls closure */ static void -timeout_fail (void *cls) +timeout_fail(void *cls) { timeout_task = NULL; - GNUNET_SCHEDULER_shutdown (); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "test timed out\n"); + GNUNET_SCHEDULER_shutdown(); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "test timed out\n"); ret = 1; } @@ -352,38 +360,38 @@ timeout_fail (void *cls) * @param cls closure */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { if (NULL != timeout_task) - { - GNUNET_SCHEDULER_cancel (timeout_task); - timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(timeout_task); + timeout_task = NULL; + } if (NULL != oh1) - { - GNUNET_SET_operation_cancel (oh1); - oh1 = NULL; - } + { + GNUNET_SET_operation_cancel(oh1); + oh1 = NULL; + } if (NULL != oh2) - { - GNUNET_SET_operation_cancel (oh2); - oh2 = NULL; - } + { + GNUNET_SET_operation_cancel(oh2); + oh2 = NULL; + } if (NULL != set1) - { - GNUNET_SET_destroy (set1); - set1 = NULL; - } + { + GNUNET_SET_destroy(set1); + set1 = NULL; + } if (NULL != set2) - { - GNUNET_SET_destroy (set2); - set2 = NULL; - } + { + GNUNET_SET_destroy(set2); + set2 = NULL; + } if (NULL != listen_handle) - { - GNUNET_SET_listen_cancel (listen_handle); - listen_handle = NULL; - } + { + GNUNET_SET_listen_cancel(listen_handle); + listen_handle = NULL; + } } @@ -396,51 +404,51 @@ do_shutdown (void *cls) * @param peer identity of the peer that was created */ static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { - timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), - &timeout_fail, - NULL); - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, - NULL); + timeout_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), + &timeout_fail, + NULL); + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, + NULL); config = cfg; - GNUNET_TESTING_peer_get_identity (peer, - &local_id); + GNUNET_TESTING_peer_get_identity(peer, + &local_id); if (0) - test_iter (); + test_iter(); - set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); - set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); - GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &app_id); + set1 = GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_UNION); + set2 = GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_UNION); + GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &app_id); /* test the real set reconciliation */ - init_set1 (); + init_set1(); } int -main (int argc, char **argv) +main(int argc, char **argv) { empty = 1; - if (0 != GNUNET_TESTING_peer_run ("test_set_api", - "test_set.conf", - &run, NULL)) - { - return 1; - } - GNUNET_assert (0 == count_set1); - GNUNET_assert (0 == count_set2); + if (0 != GNUNET_TESTING_peer_run("test_set_api", + "test_set.conf", + &run, NULL)) + { + return 1; + } + GNUNET_assert(0 == count_set1); + GNUNET_assert(0 == count_set2); empty = 0; - if (0 != GNUNET_TESTING_peer_run ("test_set_api", - "test_set.conf", - &run, NULL)) - { - return 1; - } - GNUNET_break (2 == count_set1); - GNUNET_break (1 == count_set2); + if (0 != GNUNET_TESTING_peer_run("test_set_api", + "test_set.conf", + &run, NULL)) + { + return 1; + } + GNUNET_break(2 == count_set1); + GNUNET_break(1 == count_set2); return ret; } -- cgit v1.2.3