gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r31423 - in gnunet/src: include set util


From: gnunet
Subject: [GNUnet-SVN] r31423 - in gnunet/src: include set util
Date: Mon, 16 Dec 2013 17:14:09 +0100

Author: cfuchs
Date: 2013-12-16 17:14:09 +0100 (Mon, 16 Dec 2013)
New Revision: 31423

Modified:
   gnunet/src/include/gnunet_container_lib.h
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/set/gnunet-service-set_intersection.c
   gnunet/src/set/set_protocol.h
   gnunet/src/util/container_bloomfilter.c
Log:
- 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

Modified: gnunet/src/include/gnunet_container_lib.h
===================================================================
--- gnunet/src/include/gnunet_container_lib.h   2013-12-16 16:11:30 UTC (rev 
31422)
+++ gnunet/src/include/gnunet_container_lib.h   2013-12-16 16:14:09 UTC (rev 
31423)
@@ -186,6 +186,15 @@
 
 
 /**
+ * Get the number of the addresses set per element in the bloom filter.
+ *
+ * @param bf the filter
+ * @return addresses set per element in the bf
+ */
+size_t
+GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct 
GNUNET_CONTAINER_BloomFilter *bf);
+
+/**
  * @ingroup bloomfilter
  * Get size of the bloom filter.
  *

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2013-12-16 16:11:30 UTC (rev 
31422)
+++ gnunet/src/include/gnunet_protocols.h       2013-12-16 16:14:09 UTC (rev 
31423)
@@ -1839,6 +1839,11 @@
  */
 #define GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF 592
 
+/**
+ * Bloom filter message for intersection exchange started by Bob.
+ */
+#define GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF_PART 593
+
 
/*******************************************************************************
  * TESTBED LOGGER message types
  
******************************************************************************/

Modified: gnunet/src/set/gnunet-service-set_intersection.c
===================================================================
--- gnunet/src/set/gnunet-service-set_intersection.c    2013-12-16 16:11:30 UTC 
(rev 31422)
+++ gnunet/src/set/gnunet-service-set_intersection.c    2013-12-16 16:14:09 UTC 
(rev 31423)
@@ -90,10 +90,10 @@
   char * local_bf_data;
 
   /**
-   * for multipart msgs we have to store the bloomfilter-data until we fully 
sent it.
+   * size of the bloomfilter
    */
   uint32_t local_bf_data_size;
-
+  
   /**
    * Current state of the operation.
    */
@@ -360,31 +360,26 @@
 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));
+  struct BFPart *msg;
+  uint32_t chunk_size = (GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct 
BFPart));
   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);
+  ev = GNUNET_MQ_msg_extra (msg, chunk_size, 
GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF_PART);
 
-  msg->reserved = 0;
-  msg->bloomfilter_total_length = htonl (op->state->local_bf_data_size);
   msg->bloomfilter_length = htonl (chunk_size);
   msg->bloomfilter_offset = htonl (offset);
-  memcpy(&msg[1], op->state->local_bf, chunk_size);
+  memcpy(&msg[1], &op->state->local_bf_data[offset], chunk_size);
 
   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_data = NULL;
-    op->state->local_bf = NULL;
     return;
   }
 
@@ -405,37 +400,61 @@
   struct GNUNET_MQ_Envelope *ev;
   struct BFMessage *msg;
   uint32_t bf_size;
+  uint32_t bf_elementbits;
+  uint32_t chunk_size;
+  struct GNUNET_CONTAINER_BloomFilter * local_bf;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending bf of size %u\n");
+  
+  CALCULATE_BF_SIZE(op->state->my_element_count,
+                    op->spec->remote_element_count,
+                    bf_size,
+                    bf_elementbits);
 
+  local_bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
+                                                bf_size,
+                                                bf_elementbits);
+
+  op->spec->salt++;
+  GNUNET_CONTAINER_multihashmap_iterate (op->spec->set->elements,
+                                         &iterator_bf_create,
+                                         op);
+
   // send our bloomfilter
-  bf_size = GNUNET_CONTAINER_bloomfilter_get_size (op->state->local_bf);
-  if ( GNUNET_SERVER_MAX_MESSAGE_SIZE <= bf_size + sizeof(struct BFMessage))
-  {
+  if (GNUNET_SERVER_MAX_MESSAGE_SIZE <= bf_size + sizeof (struct BFMessage)) {
     // singlepart
-    ev = GNUNET_MQ_msg_extra (msg, bf_size, 
GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF);
-
-    GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf);
-    op->state->local_bf = NULL;
-
-    msg->reserved = 0;
-    msg->sender_element_count = htonl (op->state->my_element_count);
-    msg->bloomfilter_length = htonl (bf_size);
-    msg->bloomfilter_offset = htonl (0);
-    msg->sender_mutator = htonl (op->spec->salt);
-
-    GNUNET_MQ_send (op->mq, ev);
+    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 (local_bf,
+                                                              &msg[1],
+                                                              bf_size));
   }
   else {
     //multipart
-    op->state->local_bf_data = (char *)GNUNET_malloc(bf_size);
+    chunk_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct 
BFMessage);
+    ev = GNUNET_MQ_msg_extra (msg, chunk_size, 
GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF);
+    op->state->local_bf_data = (char *) GNUNET_malloc (bf_size);
     GNUNET_assert (GNUNET_SYSERR !=
-                 GNUNET_CONTAINER_bloomfilter_get_raw_data 
(op->state->local_bf,
-                                                            
op->state->local_bf_data,
-                                                            bf_size));
+                   GNUNET_CONTAINER_bloomfilter_get_raw_data (local_bf,
+                                                              
op->state->local_bf_data,
+                                                              bf_size));
+    memcpy (&msg[1], op->state->local_bf_data, chunk_size);
     op->state->local_bf_data_size = bf_size;
-    send_bloomfilter_multipart (op, 0);
   }
+  GNUNET_CONTAINER_bloomfilter_free (local_bf);
+
+  msg->sender_element_count = htonl (op->state->my_element_count);
+  msg->bloomfilter_total_length = htonl (bf_size);
+  msg->bloomfilter_length = htonl (chunk_size);
+  msg->bits_per_element = htonl (bf_elementbits);
+  msg->sender_mutator = htonl (op->spec->salt);
+
+  GNUNET_MQ_send (op->mq, ev);
+
+  if (op->state->local_bf_data) {
+    send_bloomfilter_multipart (op, chunk_size);
+  }
 }
 
 
@@ -601,8 +620,6 @@
 {
   struct Operation *op = cls;
   struct BFMessage *msg = (struct BFMessage *) mh;
-  uint32_t bf_size;
-  uint32_t bits_per_element;
 
   op->spec->remote_element_count = ntohl(msg->sender_element_count);
   if ((op->state->phase != PHASE_INITIAL)
@@ -617,15 +634,6 @@
   GNUNET_CONTAINER_multihashmap_iterate (op->spec->set->elements,
                                          &iterator_initialization,
                                          op);
-  
-  CALCULATE_BF_SIZE(op->state->my_element_count,
-                    op->spec->remote_element_count,
-                    bf_size,
-                    bits_per_element);
-  
-  op->state->local_bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
-                                                           bf_size,
-                                                           bits_per_element);
 
   GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf);
   op->state->remote_bf = NULL;
@@ -652,7 +660,6 @@
 
   // just send our element count, as the other peer must start
   ev = GNUNET_MQ_msg (msg, 
GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO);
-  msg->reserved = 0;
   msg->sender_element_count = htonl (op->state->my_element_count);
   msg->bloomfilter_length = htonl (0);
   msg->sender_mutator = htonl (0);

Modified: gnunet/src/set/set_protocol.h
===================================================================
--- gnunet/src/set/set_protocol.h       2013-12-16 16:11:30 UTC (rev 31422)
+++ gnunet/src/set/set_protocol.h       2013-12-16 16:14:09 UTC (rev 31423)
@@ -101,11 +101,6 @@
   struct GNUNET_MessageHeader header;
 
   /**
-   * Padding, must be 0.
-   */
-  uint8_t reserved;
-
-  /**
    * mutator used with this bloomfilter.
    */
   uint32_t sender_element_count GNUNET_PACKED;
@@ -126,6 +121,28 @@
   uint32_t bloomfilter_length GNUNET_PACKED;
   
   /**
+   * Length of the bloomfilter data
+   */
+  uint32_t bits_per_element GNUNET_PACKED;
+  
+  /**
+   * rest: the sender's bloomfilter
+   */
+};
+
+struct BFPart
+{
+  /**
+   * Type: GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Length of the appended bloomfilter data block
+   */
+  uint32_t bloomfilter_length GNUNET_PACKED;
+  
+  /**
    * offset in the bloolfilter data block, if multipart message
    */
   uint32_t bloomfilter_offset GNUNET_PACKED;

Modified: gnunet/src/util/container_bloomfilter.c
===================================================================
--- gnunet/src/util/container_bloomfilter.c     2013-12-16 16:11:30 UTC (rev 
31422)
+++ gnunet/src/util/container_bloomfilter.c     2013-12-16 16:14:09 UTC (rev 
31423)
@@ -79,7 +79,22 @@
 };
 
 
+/**
+ * Get the number of the addresses set per element in the bloom filter.
+ *
+ * @param bf the filter
+ * @return addresses set per element in the bf
+ */
+size_t
+GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct 
GNUNET_CONTAINER_BloomFilter
+                                       *bf)
+{
+  if (bf == NULL)
+    return 0;
+  return bf->addressesPerElement;
+}
 
+
 /**
  * Get size of the bloom filter.
  *




reply via email to

[Prev in Thread] Current Thread [Next in Thread]