gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r30463 - gnunet/src/set


From: gnunet
Subject: [GNUnet-SVN] r30463 - gnunet/src/set
Date: Tue, 29 Oct 2013 18:41:50 +0100

Author: dold
Date: 2013-10-29 18:41:49 +0100 (Tue, 29 Oct 2013)
New Revision: 30463

Modified:
   gnunet/src/set/gnunet-service-set.c
   gnunet/src/set/gnunet-service-set.h
   gnunet/src/set/gnunet-service-set_union.c
   gnunet/src/set/ibf.c
   gnunet/src/set/ibf.h
   gnunet/src/set/set.h
   gnunet/src/set/set_api.c
   gnunet/src/set/strata_estimator.c
   gnunet/src/set/strata_estimator.h
Log:
- some of the missing set union functionality implemented


Modified: gnunet/src/set/gnunet-service-set.c
===================================================================
--- gnunet/src/set/gnunet-service-set.c 2013-10-29 16:56:19 UTC (rev 30462)
+++ gnunet/src/set/gnunet-service-set.c 2013-10-29 17:41:49 UTC (rev 30463)
@@ -805,6 +805,7 @@
   spec->salt = ntohl (msg->salt);
   spec->peer = msg->target_peer;
   spec->set = set;
+  spec->result_mode = ntohs (msg->result_mode);
   spec->client_request_id = ntohl (msg->request_id);
   spec->context_msg = GNUNET_MQ_extract_nested_mh (msg);
   if (NULL != spec->context_msg)
@@ -923,6 +924,7 @@
 
   incoming->spec->set = set;
   incoming->spec->client_request_id = ntohl (msg->request_id);
+  incoming->spec->result_mode = ntohs (msg->result_mode);
   set->vt->accept (incoming->spec, incoming->tunnel, incoming->tc);
   /* tunnel ownership goes to operation */
   incoming->tunnel = NULL;
@@ -1124,7 +1126,7 @@
     {handle_client_reject, NULL, GNUNET_MESSAGE_TYPE_SET_REJECT,
         sizeof (struct GNUNET_SET_AcceptRejectMessage)},
     {handle_client_add_remove, NULL, GNUNET_MESSAGE_TYPE_SET_REMOVE, 0},
-    {handle_client_cancel, NULL, GNUNET_MESSAGE_TYPE_SET_REMOVE,
+    {handle_client_cancel, NULL, GNUNET_MESSAGE_TYPE_SET_CANCEL,
         sizeof (struct GNUNET_SET_CancelMessage)},
     {NULL, NULL, 0, 0}
   };

Modified: gnunet/src/set/gnunet-service-set.h
===================================================================
--- gnunet/src/set/gnunet-service-set.h 2013-10-29 16:56:19 UTC (rev 30462)
+++ gnunet/src/set/gnunet-service-set.h 2013-10-29 17:41:49 UTC (rev 30463)
@@ -100,6 +100,11 @@
    * with a set.
    */
   struct Set *set;
+
+  /**
+   * When are elements sent to the client, and which elements are sent?
+   */
+  enum GNUNET_SET_ResultMode result_mode;
 };
 
 

Modified: gnunet/src/set/gnunet-service-set_union.c
===================================================================
--- gnunet/src/set/gnunet-service-set_union.c   2013-10-29 16:56:19 UTC (rev 
30462)
+++ gnunet/src/set/gnunet-service-set_union.c   2013-10-29 17:41:49 UTC (rev 
30463)
@@ -273,7 +273,7 @@
                              void *value)
 {
   struct KeyEntry *k = value;
-
+  /* destroy the linked list of colliding ibf key entries */
   while (NULL != k)
   {
     struct KeyEntry *k_tmp = k;
@@ -1035,7 +1035,9 @@
   /* FIXME: see if the element has already been inserted! */
 
   op_register_element (eo, ee);
-  send_client_element (eo, &ee->element);
+  /* only send results immediately if the client wants it */
+  if (GNUNET_SET_RESULT_ADDED == eo->spec->result_mode)
+    send_client_element (eo, &ee->element);
 }
 
 
@@ -1137,6 +1139,7 @@
   eo->set = spec->set;
   eo->spec = spec;
   eo->tunnel = tunnel;
+  eo->tunnel = tunnel;
   eo->mq = GNUNET_MESH_mq_create (tunnel);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1223,6 +1226,20 @@
 
 
 /**
+ * Remove the element given in the element message from the set.
+ * Only marks the element as removed, so that older set operations can still 
exchange it.
+ *
+ * @param set_state state of the set to remove from
+ * @param ee set element to remove
+ */
+static void
+union_remove (struct SetState *set_state, struct ElementEntry *ee)
+{
+  strata_estimator_remove (set_state->se, get_ibf_key (&ee->element_hash, 0));
+}
+
+
+/**
  * Destroy a set that supports the union operation
  *
  * @param set_state the set to destroy
@@ -1244,20 +1261,6 @@
 
 
 /**
- * Remove the element given in the element message from the set.
- * Only marks the element as removed, so that older set operations can still 
exchange it.
- *
- * @param set_state state of the set to remove from
- * @param element set element to remove
- */
-static void
-union_remove (struct SetState *set_state, struct ElementEntry *element)
-{
-  /* FIXME: remove from strata estimator */
-}
-
-
-/**
  * Dispatch messages for a union operation.
  *
  * @param eo the state of the union evaluate operation
@@ -1331,7 +1334,22 @@
 static void
 union_op_cancel (struct SetState *set_state, uint32_t op_id)
 {
-  /* FIXME: implement */
+  struct OperationState *op_state; 
+  int found = GNUNET_NO;
+  for (op_state = set_state->ops_head; NULL != op_state; op_state = 
op_state->next)
+  {
+    if (op_state->spec->client_request_id == op_id)
+    {
+      found = GNUNET_YES;
+      break;
+    }
+  }
+  if (GNUNET_NO == found)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "canceling non-existing 
operation\n");
+    return;
+  }
+  union_operation_destroy (op_state);
 }
 
 

Modified: gnunet/src/set/ibf.c
===================================================================
--- gnunet/src/set/ibf.c        2013-10-29 16:56:19 UTC (rev 30462)
+++ gnunet/src/set/ibf.c        2013-10-29 17:41:49 UTC (rev 30463)
@@ -134,7 +134,7 @@
 
 
 /**
- * Insert an element into an IBF.
+ * Insert a key into an IBF.
  *
  * @param ibf the IBF
  * @param key the element's hash code
@@ -148,7 +148,24 @@
   ibf_insert_into (ibf, key, buckets, 1);
 }
 
+
 /**
+ * Remove a key from an IBF.
+ *
+ * @param ibf the IBF
+ * @param key the element's hash code
+ */
+void
+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);
+}
+
+
+/**
  * Test is the IBF is empty, i.e. all counts, keys and key hashes are zero.
  */
 static int

Modified: gnunet/src/set/ibf.h
===================================================================
--- gnunet/src/set/ibf.h        2013-10-29 16:56:19 UTC (rev 30462)
+++ gnunet/src/set/ibf.h        2013-10-29 17:41:49 UTC (rev 30463)
@@ -158,7 +158,7 @@
 
 
 /**
- * Insert an element into an IBF.
+ * Insert a key into an IBF.
  *
  * @param ibf the IBF
  * @param key the element's hash code
@@ -168,6 +168,16 @@
 
 
 /**
+ * Remove a key from an IBF.
+ *
+ * @param ibf the IBF
+ * @param key the element's hash code
+ */
+void
+ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key);
+
+
+/**
  * Subtract ibf2 from ibf1, storing the result in ibf1.
  * The two IBF's must have the same parameters size and hash_num.
  *

Modified: gnunet/src/set/set.h
===================================================================
--- gnunet/src/set/set.h        2013-10-29 16:56:19 UTC (rev 30462)
+++ gnunet/src/set/set.h        2013-10-29 17:41:49 UTC (rev 30463)
@@ -87,6 +87,12 @@
    * must be 0 if we don't accept the request.
    */
   uint32_t request_id GNUNET_PACKED;
+
+  /**
+   * How should results be sent to us?
+   * See enum GNUNET_SET_ResultMode.
+   */
+  uint16_t result_mode GNUNET_PACKED;
 };
 
 
@@ -143,9 +149,10 @@
   uint16_t salt GNUNET_PACKED;
 
   /**
-   * Padding
+   * How should results be sent to us?
+   * See enum GNUNET_SET_ResultMode.
    */
-  uint16_t reserved GNUNET_PACKED;
+  uint16_t result_mode GNUNET_PACKED;
 
   /* rest: inner message */
 };

Modified: gnunet/src/set/set_api.c
===================================================================
--- gnunet/src/set/set_api.c    2013-10-29 16:56:19 UTC (rev 30462)
+++ gnunet/src/set/set_api.c    2013-10-29 17:41:49 UTC (rev 30463)
@@ -550,9 +550,9 @@
   mqm = GNUNET_MQ_msg_nested_mh (msg, GNUNET_MESSAGE_TYPE_SET_EVALUATE, 
context_msg);
 
   msg->app_id = *app_id;
+  msg->result_mode = htons (result_mode);
   msg->target_peer = *other_peer;
   msg->salt = salt;
-  msg->reserved = 0;
   oh->conclude_mqm = mqm;
   oh->request_id_addr = &msg->request_id;
 
@@ -679,6 +679,7 @@
 
   mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_ACCEPT);
   msg->accept_reject_id = htonl (request->accept_id);
+  msg->result_mode = htons (result_mode);
 
   oh->conclude_mqm = mqm;
   oh->request_id_addr = &msg->request_id;
@@ -688,10 +689,8 @@
 
 
 /**
- * Cancel the given set operation.
- * We need to send an explicit cancel message, as
- * all operations communicate with the set's client
- * handle.
+ * Cancel the given set operation.  We need to send an explicit cancel message,
+ * as all operations one one set communicate using one handle.
  *
  * @param oh set operation to cancel
  */

Modified: gnunet/src/set/strata_estimator.c
===================================================================
--- gnunet/src/set/strata_estimator.c   2013-10-29 16:56:19 UTC (rev 30462)
+++ gnunet/src/set/strata_estimator.c   2013-10-29 17:41:49 UTC (rev 30463)
@@ -67,7 +67,20 @@
 }
 
 
+void
+strata_estimator_remove (struct StrataEstimator *se, struct IBF_Key key)
+{
+  uint64_t v;
+  int i;
+  v = key.key_val;
+  /* count trailing '1'-bits of v */
+  for (i = 0; v & 1; v>>=1, i++)
+    /* empty */;
+  ibf_remove (se->strata[i], key);
+}
 
+
+
 struct StrataEstimator *
 strata_estimator_create (unsigned int strata_count, uint32_t ibf_size, uint8_t 
ibf_hashnum)
 {

Modified: gnunet/src/set/strata_estimator.h
===================================================================
--- gnunet/src/set/strata_estimator.h   2013-10-29 16:56:19 UTC (rev 30462)
+++ gnunet/src/set/strata_estimator.h   2013-10-29 17:41:49 UTC (rev 30463)
@@ -70,6 +70,10 @@
 
 
 void
+strata_estimator_remove (struct StrataEstimator *se, struct IBF_Key key);
+
+
+void
 strata_estimator_destroy (struct StrataEstimator *se);
 
 




reply via email to

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