aboutsummaryrefslogtreecommitdiff
path: root/src/set/set_api.c
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2015-10-05 21:26:56 +0000
committerFlorian Dold <florian.dold@gmail.com>2015-10-05 21:26:56 +0000
commita11e17158609766f29c40de6daecf5ce02b38e6c (patch)
tree1fbce1a057d5e74415781074a429d53751b43111 /src/set/set_api.c
parent4dcb414e2faabc800577c25dec3b63e3ceaaa84b (diff)
work on consensus and set
- evil peers for consensus - various fixes for consensus and set
Diffstat (limited to 'src/set/set_api.c')
-rw-r--r--src/set/set_api.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/set/set_api.c b/src/set/set_api.c
index 16aa87cd04..6cbee9a572 100644
--- a/src/set/set_api.c
+++ b/src/set/set_api.c
@@ -1112,4 +1112,40 @@ GNUNET_SET_copy_lazy (struct GNUNET_SET_Handle *set,
}
+/**
+ * Create a copy of an element. The copy
+ * must be GNUNET_free-d by the caller.
+ *
+ * @param element the element to copy
+ * @return the copied element
+ */
+struct GNUNET_SET_Element *
+GNUNET_SET_element_dup (const struct GNUNET_SET_Element *element)
+{
+ struct GNUNET_SET_Element *copy;
+
+ copy = GNUNET_malloc (element->size + sizeof (struct GNUNET_SET_Element));
+ copy->size = element->size;
+ copy->element_type = element->element_type;
+ copy->data = &copy[1];
+ memcpy ((void *) copy->data, element->data, copy->size);
+
+ return copy;
+}
+
+
+/**
+ * Hash a set element.
+ *
+ * @param element the element that should be hashed
+ * @param ret_hash a pointer to where the hash of @a element
+ * should be stored
+ */
+void
+GNUNET_SET_element_hash (const struct GNUNET_SET_Element *element, struct GNUNET_HashCode *ret_hash)
+{
+ /* FIXME: The element type should also be hashed. */
+ GNUNET_CRYPTO_hash (element->data, element->size, ret_hash);
+}
+
/* end of set_api.c */