From 119238db5e4b71e477a0ea2c9085eaa4251e026a Mon Sep 17 00:00:00 2001 From: Christian Fuchs Date: Mon, 9 Dec 2013 16:17:19 +0000 Subject: [PATCH] - more multipart fun - Make it so --- src/set/gnunet-service-set_intersection.c | 35 +++++++++++++++++++++++ src/set/set_protocol.h | 7 ++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c index 45d670c92..627b96fda 100644 --- a/src/set/gnunet-service-set_intersection.c +++ b/src/set/gnunet-service-set_intersection.c @@ -341,6 +341,40 @@ send_operation_request (struct Operation *op) } } +static void +send_bloomfilter_multipart (struct Operation *op, uint32_t offset) +{ + struct GNUNET_MQ_Envelope *ev; + struct BFMessage *msg; + uint32_t chunk_size = (GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct BFMessage)); + uint32_t todo_size = op->state->local_bf_data_size - offset; + + if (todo_size < chunk_size) + // we probably need many chunks, thus we assume a maximum packet size by default + chunk_size = todo_size; + + ev = GNUNET_MQ_msg_extra (msg, chunk_size, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); + + msg->reserved = 0; + msg->sender_element_count = htonl (op->state->my_element_count); + msg->bloomfilter_total_length = htonl (op->state->local_bf_data_size); + msg->bloomfilter_length = htonl (chunk_size); + msg->bloomfilter_offset = htonl (offset); + msg->sender_mutator = htonl (op->spec->salt); + + GNUNET_MQ_send (op->mq, ev); + + if (op->state->local_bf_data_size == offset + chunk_size) + { + // done + GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf); + GNUNET_free(op->state->local_bf_data); + op->state->local_bf = NULL; + return; + } + + send_bloomfilter_multipart (op, offset + chunk_size); +} /** * Send a bloomfilter to our peer. @@ -378,6 +412,7 @@ send_bloomfilter (struct Operation *op) GNUNET_MQ_send (op->mq, ev); } else { + //multipart op->state->local_bf_data = (char *)GNUNET_malloc(bf_size); GNUNET_assert (GNUNET_SYSERR != GNUNET_CONTAINER_bloomfilter_get_raw_data (op->state->local_bf, diff --git a/src/set/set_protocol.h b/src/set/set_protocol.h index 310cb202c..632e45963 100644 --- a/src/set/set_protocol.h +++ b/src/set/set_protocol.h @@ -116,7 +116,12 @@ struct BFMessage uint32_t sender_mutator GNUNET_PACKED; /** - * Length of the bloomfilter data block + * Length of the bloomfilter data + */ + uint32_t bloomfilter_total_length GNUNET_PACKED; + + /** + * Length of the appended bloomfilter data block */ uint32_t bloomfilter_length GNUNET_PACKED; -- 2.25.1