aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2013-11-20 10:55:44 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2013-11-20 10:55:44 +0000
commitcaa980cad091220c6c52108182fe52337a247cdb (patch)
tree5f33b49ba18af47f1f769c9030406342848e1534 /src/set
parent622a6de8fa308d19e3c82941233447963660f2c0 (diff)
downloadgnunet-caa980cad091220c6c52108182fe52337a247cdb.tar.gz
gnunet-caa980cad091220c6c52108182fe52337a247cdb.zip
fixed bug from set-union
more work on set intersection, should now be logically complete except for the adaptive bloomfilter size
Diffstat (limited to 'src/set')
-rw-r--r--src/set/gnunet-service-set_intersection.c105
-rw-r--r--src/set/gnunet-service-set_union.c1
2 files changed, 19 insertions, 87 deletions
diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c
index 3fa2a5289..8631dd4a7 100644
--- a/src/set/gnunet-service-set_intersection.c
+++ b/src/set/gnunet-service-set_intersection.c
@@ -270,49 +270,6 @@ iterator_bf_round (void *cls,
270} 270}
271 271
272/** 272/**
273 * Destroy a intersection operation, and free all resources
274 * associated with it.
275 *
276 * @param eo the intersection operation to destroy
277 */
278static void
279intersection_operation_destroy (struct OperationState *eo)
280{
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying intersection op\n");
282 GNUNET_CONTAINER_DLL_remove (eo->set->state->ops_head,
283 eo->set->state->ops_tail,
284 eo);
285 if (NULL != eo->mq)
286 {
287 GNUNET_MQ_destroy (eo->mq);
288 eo->mq = NULL;
289 }
290 if (NULL != eo->tunnel)
291 {
292 struct GNUNET_MESH_Tunnel *t = eo->tunnel;
293 eo->tunnel = NULL;
294 GNUNET_MESH_tunnel_destroy (t);
295 }
296 // TODO: destroy set elements?
297 if (NULL != eo->spec)
298 {
299 if (NULL != eo->spec->context_msg)
300 {
301 GNUNET_free (eo->spec->context_msg);
302 eo->spec->context_msg = NULL;
303 }
304 GNUNET_free (eo->spec);
305 eo->spec = NULL;
306 }
307 GNUNET_free (eo);
308
309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying intersection op done\n");
310
311 /* FIXME: do a garbage collection of the set generations */
312}
313
314
315/**
316 * Inform the client that the union operation has failed, 273 * Inform the client that the union operation has failed,
317 * and proceed to destroy the evaluate operation. 274 * and proceed to destroy the evaluate operation.
318 * 275 *
@@ -642,33 +599,26 @@ intersection_evaluate (struct Operation *op)
642static void 599static void
643intersection_accept (struct Operation *op) 600intersection_accept (struct Operation *op)
644{ 601{
645 struct OperationRequestMessage * context = 1;
646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "accepting set union operation\n"); 602 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "accepting set union operation\n");
647
648 op->state = GNUNET_new (struct OperationState); 603 op->state = GNUNET_new (struct OperationState);
649 op->state->my_elements = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_YES); 604 op->state->my_elements = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_YES);
650
651 GNUNET_CONTAINER_multihashmap_iterate(op->spec->set->elements, 605 GNUNET_CONTAINER_multihashmap_iterate(op->spec->set->elements,
652 &iterator_element_count, 606 &iterator_element_count,
653 op); 607 op);
654
655 // if Alice (the peer) has more elements than Bob (us), she should start 608 // if Alice (the peer) has more elements than Bob (us), she should start
656 if (op->spec->element_count < op->state->my_elements_count){ 609 if (op->spec->element_count < op->state->my_elements_count){
657 op->state->phase = PHASE_INITIAL; 610 op->state->phase = PHASE_INITIAL;
658 send_element_count(op); 611 send_element_count(op);
659 return; 612 return;
660 } 613 }
661
662 // create a new bloomfilter in case we have fewer elements 614 // create a new bloomfilter in case we have fewer elements
663 op->state->phase = PHASE_BF_EXCHANGE; 615 op->state->phase = PHASE_BF_EXCHANGE;
664 op->state->local_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 616 op->state->local_bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
665 BLOOMFILTER_SIZE, 617 BLOOMFILTER_SIZE,
666 GNUNET_CONSTANTS_BLOOMFILTER_K); 618 GNUNET_CONSTANTS_BLOOMFILTER_K);
667
668 GNUNET_CONTAINER_multihashmap_iterate (op->spec->set->elements, 619 GNUNET_CONTAINER_multihashmap_iterate (op->spec->set->elements,
669 &iterator_initialization, 620 &iterator_initialization,
670 op); 621 op);
671
672 send_bloomfilter (op); 622 send_bloomfilter (op);
673} 623}
674 624
@@ -783,7 +733,6 @@ send_client_done_and_destroy (void *cls)
783 GNUNET_MQ_send (op->spec->set->client_mq, ev); 733 GNUNET_MQ_send (op->spec->set->client_mq, ev);
784 _GSS_operation_destroy (op); 734 _GSS_operation_destroy (op);
785} 735}
786
787/** 736/**
788 * Send all elements in the full result iterator. 737 * Send all elements in the full result iterator.
789 * 738 *
@@ -793,49 +742,33 @@ static void
793send_remaining_elements (void *cls) 742send_remaining_elements (void *cls)
794{ 743{
795 struct Operation *op = cls; 744 struct Operation *op = cls;
796 struct KeyEntry *remaining; //TODO rework this, key entry does not exist here 745 struct ElementEntry *remaining; //TODO rework this, key entry does not exist here
746 struct GNUNET_MQ_Envelope *ev;
747 struct GNUNET_SET_ResultMessage *rm;
748 struct GNUNET_SET_Element *element;
797 int res; 749 int res;
798 750
799 res = GNUNET_CONTAINER_multihashmap32_iterator_next (op->state->full_result_iter, NULL, (const void **) &remaining); 751 res = GNUNET_CONTAINER_multihashmap32_iterator_next (op->state->full_result_iter, NULL, (const void **) &remaining);
800 res = GNUNET_NO; 752 if (GNUNET_NO == res) {
801 if (GNUNET_NO == res)
802 {
803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending done and destroy because iterator ran out\n"); 753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending done and destroy because iterator ran out\n");
804 send_client_done_and_destroy (op); 754 send_client_done_and_destroy (op);
805 return; 755 return;
806 } 756 }
757
758 element = &remaining->element;
759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending element (size %u) to client (full set)\n", element->size);
760 GNUNET_assert (0 != op->spec->client_request_id);
761
762 ev = GNUNET_MQ_msg_extra (rm, element->size, GNUNET_MESSAGE_TYPE_SET_RESULT);
763 GNUNET_assert (NULL != ev);
764
765 rm->result_status = htons (GNUNET_SET_STATUS_OK);
766 rm->request_id = htonl (op->spec->client_request_id);
767 rm->element_type = element->type;
768 memcpy (&rm[1], element->data, element->size);
807 769
808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending elements from key entry\n"); 770 GNUNET_MQ_notify_sent (ev, send_remaining_elements, op);
809 771 GNUNET_MQ_send (op->spec->set->client_mq, ev);
810 while (1)
811 {
812 struct GNUNET_MQ_Envelope *ev;
813 struct GNUNET_SET_ResultMessage *rm;
814 struct GNUNET_SET_Element *element;
815 element = &remaining->element->element;
816
817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending element (size %u) to client (full set)\n", element->size);
818 GNUNET_assert (0 != op->spec->client_request_id);
819 ev = GNUNET_MQ_msg_extra (rm, element->size, GNUNET_MESSAGE_TYPE_SET_RESULT);
820 if (NULL == ev)
821 {
822 GNUNET_MQ_discard (ev);
823 GNUNET_break (0);
824 continue;
825 }
826 rm->result_status = htons (GNUNET_SET_STATUS_OK);
827 rm->request_id = htonl (op->spec->client_request_id);
828 rm->element_type = element->type;
829 memcpy (&rm[1], element->data, element->size);
830 if (remaining->next_colliding == NULL)
831 {
832 GNUNET_MQ_notify_sent (ev, send_remaining_elements, op);
833 GNUNET_MQ_send (op->spec->set->client_mq, ev);
834 break;
835 }
836 GNUNET_MQ_send (op->spec->set->client_mq, ev);
837 remaining = remaining->next_colliding;
838 }
839} 772}
840 773
841/** 774/**
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c
index 826071af8..9dc688aee 100644
--- a/src/set/gnunet-service-set_union.c
+++ b/src/set/gnunet-service-set_union.c
@@ -1003,7 +1003,6 @@ send_remaining_elements (void *cls)
1003 int res; 1003 int res;
1004 1004
1005 res = GNUNET_CONTAINER_multihashmap32_iterator_next (op->state->full_result_iter, NULL, (const void **) &ke); 1005 res = GNUNET_CONTAINER_multihashmap32_iterator_next (op->state->full_result_iter, NULL, (const void **) &ke);
1006 res = GNUNET_NO;
1007 if (GNUNET_NO == res) 1006 if (GNUNET_NO == res)
1008 { 1007 {
1009 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending done and destroy because iterator ran out\n"); 1008 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending done and destroy because iterator ran out\n");