gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r34439 - in gnunet/src: include set
Date: Thu, 27 Nov 2014 14:55:23 +0100

Author: grothoff
Date: 2014-11-27 14:55:23 +0100 (Thu, 27 Nov 2014)
New Revision: 34439

Modified:
   gnunet/src/include/gnunet_set_service.h
   gnunet/src/set/gnunet-service-set.c
   gnunet/src/set/gnunet-service-set.h
   gnunet/src/set/set.h
   gnunet/src/set/set_api.c
Log:
adding logic to allow GNUNET_SET_iterate_cancel

Modified: gnunet/src/include/gnunet_set_service.h
===================================================================
--- gnunet/src/include/gnunet_set_service.h     2014-11-27 13:31:52 UTC (rev 
34438)
+++ gnunet/src/include/gnunet_set_service.h     2014-11-27 13:55:23 UTC (rev 
34439)
@@ -283,6 +283,11 @@
 
 /**
  * Destroy the set handle, and free all associated resources.
+ * Iterations must have completed (or be explicitly canceled)
+ * before destroying the corresponding set.  Operations may
+ * still be pending when a set is destroyed.
+ *
+ * @param set set to destroy
  */
 void
 GNUNET_SET_destroy (struct GNUNET_SET_Handle *set);
@@ -334,9 +339,8 @@
 
 
 /**
- * Cancel the given listen operation.
- * After calling cancel, the listen callback for this listen handle
- * will not be called again.
+ * Cancel the given listen operation.  After calling cancel, the
+ * listen callback for this listen handle will not be called again.
  *
  * @param lh handle for the listen operation
  */
@@ -404,14 +408,25 @@
  * @param iter the iterator to call for each element
  * @param iter_cls closure for @a iter
  * @return #GNUNET_YES if the iteration started successfuly,
- *         #GNUNET_SYSERR if the set  is invalid (e.g. the server crashed, 
disconnected)
+ *         #GNUNET_NO if another iteration was still active,
+ *         #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, 
disconnected)
  */
 int
 GNUNET_SET_iterate (struct GNUNET_SET_Handle *set,
                     GNUNET_SET_ElementIterator iter,
                     void *iter_cls);
 
+/**
+ * Stop iteration over all elements in the given set.  Can only
+ * be called before the iteration has "naturally" completed its
+ * turn.
+ *
+ * @param set the set to stop iterating over
+ */
+void
+GNUNET_SET_iterate_cancel (struct GNUNET_SET_Handle *set);
 
+
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif

Modified: gnunet/src/set/gnunet-service-set.c
===================================================================
--- gnunet/src/set/gnunet-service-set.c 2014-11-27 13:31:52 UTC (rev 34438)
+++ gnunet/src/set/gnunet-service-set.c 2014-11-27 13:55:23 UTC (rev 34439)
@@ -410,6 +410,7 @@
   {
     GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter);
     set->iter = NULL;
+    set->iteration_id++;
   }
   if (NULL != set->elements)
   {
@@ -667,6 +668,7 @@
     ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_DONE);
     GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter);
     set->iter = NULL;
+    set->iteration_id++;
   }
   else
   {
@@ -678,6 +680,7 @@
             ee->element.data,
             ee->element.size);
     msg->element_type = ee->element.element_type;
+    msg->iteration_id = htons (set->iteration_id);
   }
   GNUNET_MQ_send (set->client_mq, ev);
 }
@@ -1097,6 +1100,7 @@
   {
     GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter);
     set->iter = NULL;
+    set->iteration_id++;
   }
 }
 

Modified: gnunet/src/set/gnunet-service-set.h
===================================================================
--- gnunet/src/set/gnunet-service-set.h 2014-11-27 13:31:52 UTC (rev 34438)
+++ gnunet/src/set/gnunet-service-set.h 2014-11-27 13:55:23 UTC (rev 34439)
@@ -468,6 +468,12 @@
    */
   enum GNUNET_SET_OperationType operation;
 
+  /**
+   * Each @e iter is assigned a unique number, so that the client
+   * can distinguish iterations.
+   */
+  uint16_t iteration_id;
+
 };
 
 

Modified: gnunet/src/set/set.h
===================================================================
--- gnunet/src/set/set.h        2014-11-27 13:31:52 UTC (rev 34438)
+++ gnunet/src/set/set.h        2014-11-27 13:55:23 UTC (rev 34439)
@@ -29,12 +29,6 @@
 #include "platform.h"
 #include "gnunet_common.h"
 
-/**
- * FIXME
- */
-#define GNUNET_SET_ACK_WINDOW 10
-
-
 GNUNET_NETWORK_STRUCT_BEGIN
 
 /**
@@ -266,6 +260,10 @@
 };
 
 
+/**
+ * Set element transmitted by service to client in response to a set
+ * iteration request.
+ */
 struct GNUNET_SET_IterResponseMessage
 {
   /**
@@ -274,6 +272,12 @@
   struct GNUNET_MessageHeader header;
 
   /**
+   * To which set iteration does this reponse belong to?  First
+   * iteration (per client) has counter zero. Wraps around.
+   */
+  uint16_t iteration_id GNUNET_PACKED;
+
+  /**
    * Type of the element attachted to the message,
    * if any.
    */
@@ -282,6 +286,10 @@
   /* rest: element */
 };
 
+
+/**
+ * Client acknowledges receiving element in iteration.
+ */
 struct GNUNET_SET_IterAckMessage
 {
   /**

Modified: gnunet/src/set/set_api.c
===================================================================
--- gnunet/src/set/set_api.c    2014-11-27 13:31:52 UTC (rev 34438)
+++ gnunet/src/set/set_api.c    2014-11-27 13:55:23 UTC (rev 34439)
@@ -77,6 +77,12 @@
    * Has the set become invalid (e.g. service died)?
    */
   int invalid;
+
+  /**
+   * Both client and service count the number of iterators
+   * created so far to match replies with iterators.
+   */
+  uint16_t iteration_id;
 };
 
 
@@ -210,7 +216,7 @@
  * Handle element for iteration over the set.  Notifies the
  * iterator and sends an acknowledgement to the service.
  *
- * @param cls the set
+ * @param cls the `struct GNUNET_SET_Handle *`
  * @param mh the message
  */
 static void
@@ -231,13 +237,19 @@
     /* message malformed */
     GNUNET_break (0);
     set->iterator = NULL;
+    set->iteration_id++;
     iter (set->iterator_cls,
           NULL);
     iter = NULL;
   }
+  msg = (const struct GNUNET_SET_IterResponseMessage *) mh;
+  if (set->iteration_id != ntohs (msg->iteration_id))
+  {
+    /* element from a previous iteration, skip! */
+    iter = NULL;
+  }
   if (NULL != iter)
   {
-    msg = (const struct GNUNET_SET_IterResponseMessage *) mh;
     element.size = msize - sizeof (struct GNUNET_SET_IterResponseMessage);
     element.element_type = htons (msg->element_type);
     element.data = &msg[1];
@@ -268,6 +280,7 @@
   if (NULL == iter)
     return;
   set->iterator = NULL;
+  set->iteration_id++;
   iter (set->iterator_cls,
         NULL);
 }
@@ -304,7 +317,7 @@
   }
   if (GNUNET_SET_STATUS_OK != result_status)
   {
-    /* status is not STATUS_OK => there's no attached element,
+    /* status is not #GNUNET_SET_STATUS_OK => there's no attached element,
      * and this is the last result message we get */
     GNUNET_MQ_assoc_remove (set->mq, ntohl (msg->request_id));
     GNUNET_CONTAINER_DLL_remove (set->ops_head,
@@ -608,6 +621,10 @@
 void
 GNUNET_SET_destroy (struct GNUNET_SET_Handle *set)
 {
+  /* destroying set while iterator is active is currently
+     not supported; we should expand the API to allow
+     clients to explicitly cancel the iteration! */
+  GNUNET_assert (NULL == set->iterator);
   if (NULL != set->ops_head)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -923,4 +940,21 @@
   return GNUNET_YES;
 }
 
+
+/**
+ * Stop iteration over all elements in the given set.  Can only
+ * be called before the iteration has "naturally" completed its
+ * turn.
+ *
+ * @param set the set to stop iterating over
+ */
+void
+GNUNET_SET_iterate_cancel (struct GNUNET_SET_Handle *set)
+{
+  GNUNET_assert (NULL != set->iterator);
+  set->iterator = NULL;
+  set->iteration_id++;
+}
+
+
 /* end of set_api.c */




reply via email to

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