gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r35672 - gnunet/src/dht


From: gnunet
Subject: [GNUnet-SVN] r35672 - gnunet/src/dht
Date: Wed, 29 Apr 2015 10:35:53 +0200

Author: grothoff
Date: 2015-04-29 10:35:52 +0200 (Wed, 29 Apr 2015)
New Revision: 35672

Modified:
   gnunet/src/dht/gnunet-service-wdht_datacache.c
   gnunet/src/dht/gnunet-service-wdht_datacache.h
Log:
adding API to get random key from datacache

Modified: gnunet/src/dht/gnunet-service-wdht_datacache.c
===================================================================
--- gnunet/src/dht/gnunet-service-wdht_datacache.c      2015-04-29 08:29:16 UTC 
(rev 35671)
+++ gnunet/src/dht/gnunet-service-wdht_datacache.c      2015-04-29 08:35:52 UTC 
(rev 35672)
@@ -368,6 +368,62 @@
 
 
 /**
+ * Function called with a random element from the datacache.
+ * Stores the key in the closure.
+ *
+ * @param cls a `struct GNUNET_HashCode *`, where to store the @a key
+ * @param key key for the content
+ * @param data_size number of bytes in @a data
+ * @param data content stored
+ * @param type type of the content
+ * @param exp when will the content expire?
+ * @param path_info_len number of entries in @a path_info
+ * @param path_info a path through the network
+ * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort
+ */
+static int
+datacache_random_iterator (void *cls,
+                           const struct GNUNET_HashCode *key,
+                           size_t data_size,
+                           const char *data,
+                           enum GNUNET_BLOCK_Type type,
+                           struct GNUNET_TIME_Absolute exp,
+                           unsigned int path_info_len,
+                           const struct GNUNET_PeerIdentity *path_info)
+{
+  struct GNUNET_HashCode *dest = cls;
+
+  *dest = *key;
+  return GNUNET_OK; /* should actually not matter which we return */
+}
+
+
+/**
+ * Obtain a random key from the datacache.
+ * Used by Whanau for load-balancing.
+ *
+ * @param[out] key where to store the key of a random element,
+ *             randomized by PRNG if datacache is empty
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if the datacache is empty
+ */
+int
+GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key)
+{
+  if (0 ==
+      GNUNET_DATACACHE_get_random (datacache,
+                                   &datacache_random_iterator,
+                                   key))
+  {
+    /* randomize key in this case */
+    GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE,
+                                      key);
+    return GNUNET_SYSERR;
+  }
+  return GNUNET_OK;
+}
+
+
+/**
  * Initialize datacache subsystem.
  */
 void

Modified: gnunet/src/dht/gnunet-service-wdht_datacache.h
===================================================================
--- gnunet/src/dht/gnunet-service-wdht_datacache.h      2015-04-29 08:29:16 UTC 
(rev 35671)
+++ gnunet/src/dht/gnunet-service-wdht_datacache.h      2015-04-29 08:35:52 UTC 
(rev 35672)
@@ -36,15 +36,15 @@
  *
  * @param expiration when will the reply expire
  * @param key the query this reply is for
- * @param put_path_length number of peers in 'put_path'
+ * @param put_path_length number of peers in @a put_path
  * @param put_path path the reply took on put
  * @param type type of the reply
- * @param data_size number of bytes in 'data'
+ * @param data_size number of bytes in @a data
  * @param data application payload data
  */
 void
 GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
-                          const struct GNUNET_HashCode * key,
+                          const struct GNUNET_HashCode *key,
                           unsigned int put_path_length,
                           const struct GNUNET_PeerIdentity *put_path,
                           enum GNUNET_BLOCK_Type type, size_t data_size,
@@ -57,14 +57,15 @@
  * @param key the query
  * @param type requested data type
  * @param xquery extended query
- * @param xquery_size number of bytes in xquery
+ * @param xquery_size number of bytes in @a xquery
  * @param reply_bf where the reply bf is (to be) stored, possibly updated!, 
can be NULL
- * @param reply_bf_mutator mutation value for reply_bf
+ * @param reply_bf_mutator mutation value for @a reply_bf
  * @return evaluation result for the local replies
  */
 enum GNUNET_BLOCK_EvaluationResult
-GDS_DATACACHE_handle_get (const struct GNUNET_HashCode * key,
-                          enum GNUNET_BLOCK_Type type, const void *xquery,
+GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key,
+                          enum GNUNET_BLOCK_Type type,
+                          const void *xquery,
                           size_t xquery_size,
                           struct GNUNET_CONTAINER_BloomFilter **reply_bf,
                           uint32_t reply_bf_mutator,
@@ -75,6 +76,18 @@
 
 
 /**
+ * Obtain a random key from the datacache.
+ * Used by Whanau for load-balancing.
+ *
+ * @param[out] key where to store the key of a random element,
+ *             randomized by PRNG if datacache is empty
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if the datacache is empty
+ */
+int
+GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key);
+
+
+/**
  * Initialize datacache subsystem.
  */
 void




reply via email to

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