aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2013-12-16 16:14:09 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2013-12-16 16:14:09 +0000
commitaa35fc15e22f972072d9e091b01e3a3c70e598f0 (patch)
treee089fbc23eaf185400193af8d1529b22b1570429 /src/set
parent11f1a50939e73ce6fd193518f17bbc99ee430264 (diff)
downloadgnunet-aa35fc15e22f972072d9e091b01e3a3c70e598f0.tar.gz
gnunet-aa35fc15e22f972072d9e091b01e3a3c70e598f0.zip
- finished work on multipart sending in intersection
- added getter for addressesPerElement from a bloomfilter - added multipart message format for intersection - added multipart message type for intersection
Diffstat (limited to 'src/set')
-rw-r--r--src/set/gnunet-service-set_intersection.c93
-rw-r--r--src/set/set_protocol.h27
2 files changed, 72 insertions, 48 deletions
diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c
index 11527b04f..0e2ac4863 100644
--- a/src/set/gnunet-service-set_intersection.c
+++ b/src/set/gnunet-service-set_intersection.c
@@ -90,10 +90,10 @@ struct OperationState
90 char * local_bf_data; 90 char * local_bf_data;
91 91
92 /** 92 /**
93 * for multipart msgs we have to store the bloomfilter-data until we fully sent it. 93 * size of the bloomfilter
94 */ 94 */
95 uint32_t local_bf_data_size; 95 uint32_t local_bf_data_size;
96 96
97 /** 97 /**
98 * Current state of the operation. 98 * Current state of the operation.
99 */ 99 */
@@ -360,31 +360,26 @@ static void
360send_bloomfilter_multipart (struct Operation *op, uint32_t offset) 360send_bloomfilter_multipart (struct Operation *op, uint32_t offset)
361{ 361{
362 struct GNUNET_MQ_Envelope *ev; 362 struct GNUNET_MQ_Envelope *ev;
363 struct BFMessage *msg; 363 struct BFPart *msg;
364 uint32_t chunk_size = (GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct BFMessage)); 364 uint32_t chunk_size = (GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct BFPart));
365 uint32_t todo_size = op->state->local_bf_data_size - offset; 365 uint32_t todo_size = op->state->local_bf_data_size - offset;
366 366
367 if (todo_size < chunk_size) 367 if (todo_size < chunk_size)
368 // we probably need many chunks, thus we assume a maximum packet size by default
369 chunk_size = todo_size; 368 chunk_size = todo_size;
370 369
371 ev = GNUNET_MQ_msg_extra (msg, chunk_size, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); 370 ev = GNUNET_MQ_msg_extra (msg, chunk_size, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF_PART);
372 371
373 msg->reserved = 0;
374 msg->bloomfilter_total_length = htonl (op->state->local_bf_data_size);
375 msg->bloomfilter_length = htonl (chunk_size); 372 msg->bloomfilter_length = htonl (chunk_size);
376 msg->bloomfilter_offset = htonl (offset); 373 msg->bloomfilter_offset = htonl (offset);
377 memcpy(&msg[1], op->state->local_bf, chunk_size); 374 memcpy(&msg[1], &op->state->local_bf_data[offset], chunk_size);
378 375
379 GNUNET_MQ_send (op->mq, ev); 376 GNUNET_MQ_send (op->mq, ev);
380 377
381 if (op->state->local_bf_data_size == offset + chunk_size) 378 if (op->state->local_bf_data_size == offset + chunk_size)
382 { 379 {
383 // done 380 // done
384 GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf);
385 GNUNET_free(op->state->local_bf_data); 381 GNUNET_free(op->state->local_bf_data);
386 op->state->local_bf_data = NULL; 382 op->state->local_bf_data = NULL;
387 op->state->local_bf = NULL;
388 return; 383 return;
389 } 384 }
390 385
@@ -405,36 +400,60 @@ send_bloomfilter (struct Operation *op)
405 struct GNUNET_MQ_Envelope *ev; 400 struct GNUNET_MQ_Envelope *ev;
406 struct BFMessage *msg; 401 struct BFMessage *msg;
407 uint32_t bf_size; 402 uint32_t bf_size;
403 uint32_t bf_elementbits;
404 uint32_t chunk_size;
405 struct GNUNET_CONTAINER_BloomFilter * local_bf;
408 406
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending bf of size %u\n"); 407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending bf of size %u\n");
408
409 CALCULATE_BF_SIZE(op->state->my_element_count,
410 op->spec->remote_element_count,
411 bf_size,
412 bf_elementbits);
410 413
411 // send our bloomfilter 414 local_bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
412 bf_size = GNUNET_CONTAINER_bloomfilter_get_size (op->state->local_bf); 415 bf_size,
413 if ( GNUNET_SERVER_MAX_MESSAGE_SIZE <= bf_size + sizeof(struct BFMessage)) 416 bf_elementbits);
414 {
415 // singlepart
416 ev = GNUNET_MQ_msg_extra (msg, bf_size, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF);
417
418 GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf);
419 op->state->local_bf = NULL;
420 417
421 msg->reserved = 0; 418 op->spec->salt++;
422 msg->sender_element_count = htonl (op->state->my_element_count); 419 GNUNET_CONTAINER_multihashmap_iterate (op->spec->set->elements,
423 msg->bloomfilter_length = htonl (bf_size); 420 &iterator_bf_create,
424 msg->bloomfilter_offset = htonl (0); 421 op);
425 msg->sender_mutator = htonl (op->spec->salt);
426 422
427 GNUNET_MQ_send (op->mq, ev); 423 // send our bloomfilter
424 if (GNUNET_SERVER_MAX_MESSAGE_SIZE <= bf_size + sizeof (struct BFMessage)) {
425 // singlepart
426 chunk_size = bf_size;
427 ev = GNUNET_MQ_msg_extra (msg, chunk_size, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF);
428 GNUNET_assert (GNUNET_SYSERR !=
429 GNUNET_CONTAINER_bloomfilter_get_raw_data (local_bf,
430 &msg[1],
431 bf_size));
428 } 432 }
429 else { 433 else {
430 //multipart 434 //multipart
431 op->state->local_bf_data = (char *)GNUNET_malloc(bf_size); 435 chunk_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct BFMessage);
436 ev = GNUNET_MQ_msg_extra (msg, chunk_size, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF);
437 op->state->local_bf_data = (char *) GNUNET_malloc (bf_size);
432 GNUNET_assert (GNUNET_SYSERR != 438 GNUNET_assert (GNUNET_SYSERR !=
433 GNUNET_CONTAINER_bloomfilter_get_raw_data (op->state->local_bf, 439 GNUNET_CONTAINER_bloomfilter_get_raw_data (local_bf,
434 op->state->local_bf_data, 440 op->state->local_bf_data,
435 bf_size)); 441 bf_size));
442 memcpy (&msg[1], op->state->local_bf_data, chunk_size);
436 op->state->local_bf_data_size = bf_size; 443 op->state->local_bf_data_size = bf_size;
437 send_bloomfilter_multipart (op, 0); 444 }
445 GNUNET_CONTAINER_bloomfilter_free (local_bf);
446
447 msg->sender_element_count = htonl (op->state->my_element_count);
448 msg->bloomfilter_total_length = htonl (bf_size);
449 msg->bloomfilter_length = htonl (chunk_size);
450 msg->bits_per_element = htonl (bf_elementbits);
451 msg->sender_mutator = htonl (op->spec->salt);
452
453 GNUNET_MQ_send (op->mq, ev);
454
455 if (op->state->local_bf_data) {
456 send_bloomfilter_multipart (op, chunk_size);
438 } 457 }
439} 458}
440 459
@@ -601,8 +620,6 @@ handle_p2p_element_info (void *cls, const struct GNUNET_MessageHeader *mh)
601{ 620{
602 struct Operation *op = cls; 621 struct Operation *op = cls;
603 struct BFMessage *msg = (struct BFMessage *) mh; 622 struct BFMessage *msg = (struct BFMessage *) mh;
604 uint32_t bf_size;
605 uint32_t bits_per_element;
606 623
607 op->spec->remote_element_count = ntohl(msg->sender_element_count); 624 op->spec->remote_element_count = ntohl(msg->sender_element_count);
608 if ((op->state->phase != PHASE_INITIAL) 625 if ((op->state->phase != PHASE_INITIAL)
@@ -617,15 +634,6 @@ handle_p2p_element_info (void *cls, const struct GNUNET_MessageHeader *mh)
617 GNUNET_CONTAINER_multihashmap_iterate (op->spec->set->elements, 634 GNUNET_CONTAINER_multihashmap_iterate (op->spec->set->elements,
618 &iterator_initialization, 635 &iterator_initialization,
619 op); 636 op);
620
621 CALCULATE_BF_SIZE(op->state->my_element_count,
622 op->spec->remote_element_count,
623 bf_size,
624 bits_per_element);
625
626 op->state->local_bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
627 bf_size,
628 bits_per_element);
629 637
630 GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf); 638 GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf);
631 op->state->remote_bf = NULL; 639 op->state->remote_bf = NULL;
@@ -652,7 +660,6 @@ send_element_count (struct Operation *op)
652 660
653 // just send our element count, as the other peer must start 661 // just send our element count, as the other peer must start
654 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO); 662 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO);
655 msg->reserved = 0;
656 msg->sender_element_count = htonl (op->state->my_element_count); 663 msg->sender_element_count = htonl (op->state->my_element_count);
657 msg->bloomfilter_length = htonl (0); 664 msg->bloomfilter_length = htonl (0);
658 msg->sender_mutator = htonl (0); 665 msg->sender_mutator = htonl (0);
diff --git a/src/set/set_protocol.h b/src/set/set_protocol.h
index 632e45963..9d39abba8 100644
--- a/src/set/set_protocol.h
+++ b/src/set/set_protocol.h
@@ -101,11 +101,6 @@ struct BFMessage
101 struct GNUNET_MessageHeader header; 101 struct GNUNET_MessageHeader header;
102 102
103 /** 103 /**
104 * Padding, must be 0.
105 */
106 uint8_t reserved;
107
108 /**
109 * mutator used with this bloomfilter. 104 * mutator used with this bloomfilter.
110 */ 105 */
111 uint32_t sender_element_count GNUNET_PACKED; 106 uint32_t sender_element_count GNUNET_PACKED;
@@ -126,6 +121,28 @@ struct BFMessage
126 uint32_t bloomfilter_length GNUNET_PACKED; 121 uint32_t bloomfilter_length GNUNET_PACKED;
127 122
128 /** 123 /**
124 * Length of the bloomfilter data
125 */
126 uint32_t bits_per_element GNUNET_PACKED;
127
128 /**
129 * rest: the sender's bloomfilter
130 */
131};
132
133struct BFPart
134{
135 /**
136 * Type: GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF
137 */
138 struct GNUNET_MessageHeader header;
139
140 /**
141 * Length of the appended bloomfilter data block
142 */
143 uint32_t bloomfilter_length GNUNET_PACKED;
144
145 /**
129 * offset in the bloolfilter data block, if multipart message 146 * offset in the bloolfilter data block, if multipart message
130 */ 147 */
131 uint32_t bloomfilter_offset GNUNET_PACKED; 148 uint32_t bloomfilter_offset GNUNET_PACKED;