-more datacache integration work
authorChristian Grothoff <christian@grothoff.org>
Thu, 30 Apr 2015 09:32:23 +0000 (09:32 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 30 Apr 2015 09:32:23 +0000 (09:32 +0000)
src/dht/gnunet-service-wdht_datacache.c
src/dht/gnunet-service-wdht_datacache.h
src/dht/gnunet-service-wdht_neighbours.c
src/dht/gnunet-service-wdht_neighbours.h

index 978c8f1776715acde2ec9a96cbb4f74f0851061e..577aa869995473adfdbe55acaaa7c78ca7efaa25 100644 (file)
@@ -105,28 +105,6 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
 }
 
 
-/**
- * List of peers in the get path.
- */
-struct GetPath
-{
-  /**
-   * Pointer to next item in the list
-   */
-  struct GetPath *next;
-
-  /**
-   * Pointer to previous item in the list
-   */
-  struct GetPath *prev;
-
-  /**
-   *  An element in the get path.
-   */
-  struct GNUNET_PeerIdentity peer;
-};
-
-
 /**
  * Context containing information about a GET request.
  */
@@ -147,6 +125,11 @@ struct GetRequestContext
    */
   struct GNUNET_HashCode key;
 
+  /**
+   * The trail this request was for
+   */
+  const struct GNUNET_HashCode *trail_id;
+
   /**
    * Number of bytes in @e xquery.
    */
@@ -157,37 +140,11 @@ struct GetRequestContext
    */
   uint32_t reply_bf_mutator;
 
-  /**
-   * Total number of peers in @e head.
-   */
-  unsigned int get_path_length;
-
   /**
    * Return value to give back.
    */
   enum GNUNET_BLOCK_EvaluationResult eval;
 
-  /**
-   * Peeer which has the data for the key.
-   */
-  struct GNUNET_PeerIdentity source_peer;
-
-  /**
-   * Next hop to forward the get result to.
-   */
-  struct GNUNET_PeerIdentity next_hop;
-
-  /**
-   * Head of get path.
-   */
-  struct GetPath *head;
-
-  /**
-   * Tail of get path.
-   */
-  struct GetPath *tail;
-
-  /* get_path */
 };
 
 
@@ -243,23 +200,14 @@ datacache_get_iterator (void *cls,
                               gettext_noop
                               ("# Good RESULTS found in datacache"), 1,
                               GNUNET_NO);
-    struct GNUNET_PeerIdentity *get_path;
-    get_path = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) *
-                              ctx->get_path_length);
-    struct GetPath *iterator;
-    iterator = ctx->head;
-    int i = 0;
-    while (i < ctx->get_path_length)
-    {
-      get_path[i] = iterator->peer;
-      i++;
-      iterator = iterator->next;
-    }
-    GDS_NEIGHBOURS_send_get_result (key,type, &(ctx->next_hop),&(ctx->source_peer),
-                                    put_path_length, put_path, ctx->get_path_length,
-                                    get_path, exp, data, size );
-    GNUNET_free_non_null (get_path);
-
+    GDS_NEIGHBOURS_send_get_result (ctx->trail_id,
+                                    key,
+                                    type,
+                                    put_path_length,
+                                    put_path,
+                                    exp,
+                                    data,
+                                    size);
     break;
   case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
     GNUNET_STATISTICS_update (GDS_stats,
@@ -302,64 +250,39 @@ datacache_get_iterator (void *cls,
 /**
  * Handle a GET request we've received from another peer.
  *
+ * @param trail_id trail identifying where to send the result to, NULL for us
  * @param key the query
  * @param type requested data type
  * @param xquery extended query
  * @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 @a reply_bf
- * @param get_path_length Total number of peers in @a get_path
- * @param get_path Peers query has traversed during GET
  * @return evaluation result for the local replies
  */
 enum GNUNET_BLOCK_EvaluationResult
-GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key,
+GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *trail_id,
+                          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,
-                          uint32_t get_path_length,
-                          struct GNUNET_PeerIdentity *get_path,
-                          struct GNUNET_PeerIdentity *next_hop,
-                          struct GNUNET_PeerIdentity *source_peer)
+                          uint32_t reply_bf_mutator)
 {
   struct GetRequestContext ctx;
   unsigned int r;
 
-  if (datacache == NULL)
+  if (NULL == datacache)
     return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
   GNUNET_STATISTICS_update (GDS_stats,
                             gettext_noop ("# GET requests given to datacache"),
                             1, GNUNET_NO);
   ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
+  ctx.trail_id = trail_id;
   ctx.key = *key;
   ctx.xquery = xquery;
   ctx.xquery_size = xquery_size;
   ctx.reply_bf = reply_bf;
   ctx.reply_bf_mutator = reply_bf_mutator;
-  ctx.get_path_length = get_path_length;
-
-  if (NULL != next_hop)
-    ctx.next_hop = *next_hop;
-  unsigned int i = 0;
-
-  ctx.head = NULL;
-  ctx.tail = NULL;
-  if (NULL != get_path)
-  {
-    while (i < get_path_length)
-    {
-      struct GetPath *element;
-      element = GNUNET_new (struct GetPath);
-      element->next = NULL;
-      element->prev = NULL;
-      element->peer = get_path[i];
-      GNUNET_CONTAINER_DLL_insert_tail (ctx.head, ctx.tail, element);
-      i++;
-    }
-  }
-
   r = GNUNET_DATACACHE_get (datacache,
                             key,
                             type,
@@ -428,21 +351,59 @@ GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key)
   return GNUNET_OK;
 }
 
+/**
+ * Iterator for local get request results,
+ *
+ * @param cls closure with the `struct GNUNET_HashCode *` with the trail ID
+ * @param key the key this data is stored under
+ * @param size the size of the data identified by key
+ * @param data the actual data
+ * @param type the type of the data
+ * @param exp when does this value expire?
+ * @param put_path_length number of peers in @a put_path
+ * @param put_path path the reply took on put
+ * @return #GNUNET_OK to continue iteration, anything else
+ * to stop iteration.
+ */
+static int
+datacache_get_successors_iterator (void *cls,
+                                   const struct GNUNET_HashCode *key,
+                                   size_t size,
+                                   const char *data,
+                                   enum GNUNET_BLOCK_Type type,
+                                   struct GNUNET_TIME_Absolute exp,
+                                   unsigned int put_path_length,
+                                   const struct GNUNET_PeerIdentity *put_path)
+{
+  const struct GNUNET_HashCode *trail_id = cls;
+
+  GDS_NEIGHBOURS_send_get_result (trail_id,
+                                  key,
+                                  type,
+                                  put_path_length, put_path,
+                                  exp,
+                                  data,
+                                  size);
+  return GNUNET_OK;
+}
+
 
 /**
  * Handle a request for data close to a key that we have received from
  * another peer.
  *
+ * @param trail_id trail where the reply needs to be send to
  * @param key the location at which the peer is looking for data that is close
  */
 void
-GDS_DATACACHE_get_successors (const struct GNUNET_HashCode *key)
+GDS_DATACACHE_get_successors (const struct GNUNET_HashCode *trail_id,
+                              const struct GNUNET_HashCode *key)
 {
-  GNUNET_DATACACHE_get_closest (datacache,
-                                key,
-                                NUM_CLOSEST,
-                                NULL /* FIXME */,
-                                NULL);
+  (void) GNUNET_DATACACHE_get_closest (datacache,
+                                       key,
+                                       NUM_CLOSEST,
+                                       &datacache_get_successors_iterator,
+                                       (void *) trail_id);
 }
 
 
index 818138a87a85789133f6d8faa8b8d2e0200a1327..39edbbb59ed6b840a7c782bc67faf11b82b8ad66 100644 (file)
@@ -54,6 +54,7 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
 /**
  * Handle a GET request we've received from another peer.
  *
+ * @param trail_id trail where the reply needs to be send to
  * @param key the query
  * @param type requested data type
  * @param xquery extended query
@@ -63,16 +64,13 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
  * @return evaluation result for the local replies
  */
 enum GNUNET_BLOCK_EvaluationResult
-GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key,
+GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *trail_id,
+                          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,
-                          uint32_t get_path_length,
-                          struct GNUNET_PeerIdentity *get_path,
-                          struct GNUNET_PeerIdentity *next_hop,
-                          struct GNUNET_PeerIdentity *source_peer);
+                          uint32_t reply_bf_mutator);
 
 
 /**
@@ -91,10 +89,12 @@ GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key);
  * Handle a request for data close to a key that we have received from
  * another peer.
  *
+ * @param trail_id trail where the reply needs to be send to
  * @param key the location at which the peer is looking for data that is close
  */
 void
-GDS_DATACACHE_get_successors (const struct GNUNET_HashCode *key);
+GDS_DATACACHE_get_successors (const struct GNUNET_HashCode *trail_id,
+                              const struct GNUNET_HashCode *key);
 
 
 /**
index d9cee41962215fd172351462287b021501a37bd9..fd6c625408cb4102a3285d9c41cff4c50a6329eb 100644 (file)
@@ -625,14 +625,14 @@ delete_trail (struct Trail *trail,
   struct TrailDestroyMessage *tdm;
   struct Finger *finger;
 
-  friend = current->pred;
+  friend = trail->pred;
   if (NULL != friend)
   {
     if (GNUNET_YES == inform_pred)
     {
       env = GNUNET_MQ_msg (tdm,
                            GNUNET_MESSAGE_TYPE_WDHT_TRAIL_DESTROY);
-      tdm->trail_id = current->pred_id;
+      tdm->trail_id = trail->pred_id;
       GNUNET_MQ_send (friend->mq,
                       env);
     }
@@ -641,14 +641,14 @@ delete_trail (struct Trail *trail,
                                   friend->pred_tail,
                                   trail);
   }
-  friend = current->succ;
+  friend = trail->succ;
   if (NULL != friend)
   {
     if (GNUNET_YES == inform_succ)
     {
       env = GNUNET_MQ_msg (tdm,
                            GNUNET_MESSAGE_TYPE_WDHT_TRAIL_DESTROY);
-      tdm->trail_id = current->pred_id;
+      tdm->trail_id = trail->pred_id;
       GNUNET_MQ_send (friend->mq,
                       env);
     }
@@ -672,34 +672,30 @@ delete_trail (struct Trail *trail,
 /**
  * Send the get result to requesting client.
  *
+ * @param trail_id trail identifying where to send the result to, NULL for us
  * @param key Key of the requested data.
  * @param type Block type
- * @param target_peer Next peer to forward the message to.
- * @param source_peer Peer which has the data for the key.
  * @param put_path_length Number of peers in @a put_path
  * @param put_path Path taken to put the data at its stored location.
- * @param get_path_length Number of peers in @a get_path
- * @param get_path Path taken to reach to the location of the key.
  * @param expiration When will this result expire?
  * @param data Payload to store
  * @param data_size Size of the @a data
  */
 void
-GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key,
+GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *trail_id,
+                                const struct GNUNET_HashCode *key,
                                 enum GNUNET_BLOCK_Type type,
-                                const struct GNUNET_PeerIdentity *target_peer,
-                                const struct GNUNET_PeerIdentity *source_peer,
                                 unsigned int put_path_length,
                                 const struct GNUNET_PeerIdentity *put_path,
-                                unsigned int get_path_length,
-                                const struct GNUNET_PeerIdentity *get_path,
                                 struct GNUNET_TIME_Absolute expiration,
-                                const void *data, size_t data_size)
+                                const void *data,
+                                size_t data_size)
 {
   // TRICKY: need to introduce some context to remember trail from
   // the lookup...
 }
 
+
 /**
  * Method called whenever a peer disconnects.
  *
index a46c63c48b55f6f3c802cce0300373a8cd1696b7..4dba04da285877cb8850d3434a35ace6f8fe200a 100644 (file)
@@ -71,27 +71,21 @@ GDS_NEIGHBOURS_handle_get (const struct GNUNET_HashCode *key,
 /**
  * Send the get result to requesting client.
  *
+ * @param trail_id trail identifying where to send the result to, NULL for us
  * @param key Key of the requested data.
  * @param type Block type
- * @param target_peer Next peer to forward the message to.
- * @param source_peer Peer which has the data for the key.
  * @param put_path_length Number of peers in @a put_path
  * @param put_path Path taken to put the data at its stored location.
- * @param get_path_length Number of peers in @a get_path
- * @param get_path Path taken to reach to the location of the key.
  * @param expiration When will this result expire?
  * @param data Payload to store
  * @param data_size Size of the @a data
  */
 void
-GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key,
+GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *trail_id,
+                                const struct GNUNET_HashCode *key,
                                 enum GNUNET_BLOCK_Type type,
-                                const struct GNUNET_PeerIdentity *target_peer,
-                                const struct GNUNET_PeerIdentity *source_peer,
                                 unsigned int put_path_length,
                                 const struct GNUNET_PeerIdentity *put_path,
-                                unsigned int get_path_length,
-                                const struct GNUNET_PeerIdentity *get_path,
                                 struct GNUNET_TIME_Absolute expiration,
                                 const void *data, size_t data_size);