naming
[oweals/gnunet.git] / src / dht / gnunet-service-dht_datacache.c
index fc19834193b88e6b70bf34be304ce6054f81fb87..1ba176e6eaa13f34bb9feb57c8c5e0c104532b74 100644 (file)
@@ -99,6 +99,9 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
       return;
     }
   /* Put size is actual data size plus struct overhead plus path length (if any) */
+  GNUNET_STATISTICS_update (GDS_stats,
+                           gettext_noop ("# ITEMS stored in datacache"), 1,
+                           GNUNET_NO);
   pe = (struct DHTPutEntry *) buf;
   pe->data_size = htons (data_size);
   pe->path_length = htons ((uint16_t) put_path_length);
@@ -142,6 +145,10 @@ struct GetRequestContext
    */
   uint32_t reply_bf_mutator;
 
+  /**
+   * Return value to give back.
+   */
+  enum GNUNET_BLOCK_EvaluationResult eval;
 };
 
 
@@ -192,12 +199,16 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
                              ctx->xquery_size, 
                             rdata,
                              rdata_size);
+  ctx->eval = eval;      
   switch (eval)
   {
   case GNUNET_BLOCK_EVALUATION_OK_LAST:
   case GNUNET_BLOCK_EVALUATION_OK_MORE:
     /* forward to local clients */
-    GDS_CLIENT_handle_reply (exp,
+    GNUNET_STATISTICS_update (GDS_stats,
+                             gettext_noop ("# Good RESULTS found in datacache"), 1,
+                             GNUNET_NO);
+    GDS_CLIENTS_handle_reply (exp,
                             key,
                             0, NULL,
                             put_path_length, pp,
@@ -208,8 +219,14 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
                         0, NULL, rdata, rdata_size);
     break;
   case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
+    GNUNET_STATISTICS_update (GDS_stats,
+                             gettext_noop ("# Duplicate RESULTS found in datacache"), 1,
+                             GNUNET_NO);
     break;
   case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
+    GNUNET_STATISTICS_update (GDS_stats,
+                             gettext_noop ("# Invalid RESULTS found in datacache"), 1,
+                             GNUNET_NO);
     break;
   case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
     GNUNET_break (0);
@@ -218,12 +235,15 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
+    GNUNET_STATISTICS_update (GDS_stats,
+                             gettext_noop ("# Unsupported RESULTS found in datacache"), 1,
+                             GNUNET_NO);
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Unsupported block type (%u) in local response!\n",
                 type);
     break;
   }
-  return GNUNET_OK;
+  return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK;
 }
 
 
@@ -236,8 +256,9 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
  * @param xquery_size number of bytes in 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
+ * @return evaluation result for the local replies
  */
-void
+enum GNUNET_BLOCK_EvaluationResult
 GDS_DATACACHE_handle_get (const GNUNET_HashCode *key,
                          enum GNUNET_BLOCK_Type type,
                          const void *xquery,
@@ -248,7 +269,11 @@ GDS_DATACACHE_handle_get (const GNUNET_HashCode *key,
   struct GetRequestContext ctx;
 
   if (datacache == NULL)
-    return;
+    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.key = *key;
   ctx.xquery = xquery;
   ctx.xquery_size = xquery_size;
@@ -256,6 +281,7 @@ GDS_DATACACHE_handle_get (const GNUNET_HashCode *key,
   ctx.reply_bf_mutator = reply_bf_mutator;
   (void) GNUNET_DATACACHE_get (datacache, key, type,
                               &datacache_get_iterator, &ctx);
+  return ctx.eval;
 }