-indentation, code cleanup
[oweals/gnunet.git] / src / set / gnunet-service-set.h
index 6ababe92fe2f05958927c875f1b8d83b2e68eded..f26ff3fc356bee09162e027d689e1d830ecaa57c 100644 (file)
@@ -4,7 +4,7 @@
 
       GNUnet is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
-      by the Free Software Foundation; either version 2, or (at your
+      by the Free Software Foundation; either version 3, or (at your
       option) any later version.
 
       GNUnet is distributed in the hope that it will be useful, but
 #define GNUNET_SERVICE_SET_H_PRIVATE
 
 #include "platform.h"
-#include "gnunet_common.h"
+#include "gnunet_util_lib.h"
 #include "gnunet_protocols.h"
 #include "gnunet_applications.h"
-#include "gnunet_util_lib.h"
 #include "gnunet_core_service.h"
 #include "gnunet_mesh_service.h"
 #include "gnunet_set_service.h"
@@ -57,6 +56,7 @@ struct OperationState;
 /* forward declarations */
 struct Set;
 struct TunnelContext;
+struct ElementEntry;
 
 
 /**
@@ -103,6 +103,8 @@ struct OperationSpecification
 };
 
 
+
+
 /**
  * Signature of functions that create the implementation-specific
  * state for a set supporting a specific operation.
@@ -119,7 +121,7 @@ typedef struct SetState *(*CreateImpl) (void);
  * @param set implementation-specific set state
  * @param msg element message from the client
  */
-typedef void (*AddRemoveImpl) (struct SetState *state, const struct GNUNET_SET_Element *element);
+typedef void (*AddRemoveImpl) (struct SetState *state, struct ElementEntry *ee);
 
 
 /**
@@ -169,6 +171,15 @@ typedef void (*CancelImpl) (struct SetState *set,
                             uint32_t request_id);
 
 
+/**
+ * Signature of functions that implement sending all the set's
+ * elements to the client.
+ *
+ * @param set set that should be iterated over
+ */
+typedef void (*IterateImpl) (struct Set *set);
+
+
 /**
  * Dispatch table for a specific set operation.
  * Every set operation has to implement the callback
@@ -222,6 +233,59 @@ struct SetVT
    * its ID.
    */
   CancelImpl cancel;
+
+  /**
+   * Callback for iterating over all set elements.
+   */
+  IterateImpl iterate;
+};
+
+
+/**
+ * Information about an element element in the set.
+ * All elements are stored in a hash-table
+ * from their hash-code to their 'struct Element',
+ * so that the remove and add operations are reasonably
+ * fast.
+ */
+struct ElementEntry
+{
+  /**
+   * The actual element. The data for the element
+   * should be allocated at the end of this struct.
+   */
+  struct GNUNET_SET_Element element;
+
+  /**
+   * Hash of the element.
+   * Will be used to derive the different IBF keys
+   * for different salts.
+   */
+  struct GNUNET_HashCode element_hash;
+
+  /**
+   * Generation the element was added by the client.
+   * Operations of earlier generations will not consider the element.
+   */
+  unsigned int generation_added;
+
+  /**
+   * GNUNET_YES if the element has been removed in some generation.
+   */
+  int removed;
+
+  /**
+   * Generation the element was removed by the client.
+   * Operations of later generations will not consider the element.
+   * Only valid if is_removed is GNUNET_YES.
+   */
+  unsigned int generation_removed;
+
+  /**
+   * GNUNET_YES if the element is a remote element, and does not belong
+   * to the operation's set.
+   */
+  int remote;
 };
 
 
@@ -267,6 +331,23 @@ struct Set
    * Implementation-specific state.
    */
   struct SetState *state;
+
+  /**
+   * Current state of iterating elements for the client.
+   * NULL if we are not currently iterating.
+   */
+  struct GNUNET_CONTAINER_MultiHashMapIterator *iter;
+
+  /**
+   * Maps 'struct GNUNET_HashCode' to 'struct ElementEntry'.
+   */
+  struct GNUNET_CONTAINER_MultiHashMap *elements;
+
+  /**
+   * Current generation, that is, number of
+   * previously executed operations on this set
+   */
+  unsigned int current_generation;
 };