* @author Christian Grothoff
* @author Nathan Evans
*/
+#include "platform.h"
+#include "gnunet_datacache_lib.h"
+#include "gnunet-service-dht_clients.h"
#include "gnunet-service-dht_datacache.h"
+#include "gnunet-service-dht_routing.h"
+#include "gnunet-service-dht.h"
/**
const GNUNET_HashCode *key,
unsigned int put_path_length,
const struct GNUNET_PeerIdentity *put_path,
- uint32_t type,
+ enum GNUNET_BLOCK_Type type,
size_t data_size,
const void *data)
{
char buf[plen];
struct DHTPutEntry *pe;
struct GNUNET_PeerIdentity *pp;
- char *path_offset;
if (datacache == NULL)
{
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);
*/
uint32_t reply_bf_mutator;
+ /**
+ * Return value to give back.
+ */
+ enum GNUNET_BLOCK_EvaluationResult eval;
};
struct GetRequestContext *ctx = cls;
const struct DHTPutEntry *pe;
const struct GNUNET_PeerIdentity *pp;
- const char *data;
- size_t data_size;
+ const char *rdata;
+ size_t rdata_size;
uint16_t put_path_length;
enum GNUNET_BLOCK_EvaluationResult eval;
pe = (const struct DHTPutEntry *) data;
put_path_length = ntohs (pe->path_length);
- data_size = ntohs (pe->data_size);
+ rdata_size = ntohs (pe->data_size);
if (size !=
- sizeof (struct DHTPutEntry) + data_size +
+ sizeof (struct DHTPutEntry) + rdata_size +
(put_path_length * sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_break (0);
return GNUNET_OK;
}
pp = (const struct GNUNET_PeerIdentity *) &pe[1];
- data = (const char*) &pp[put_path_length];
+ rdata = (const char*) &pp[put_path_length];
eval =
- GNUNET_BLOCK_evaluate (block_context, type, key,
+ GNUNET_BLOCK_evaluate (GDS_block_context, type, key,
ctx->reply_bf,
ctx->reply_bf_mutator,
ctx->xquery,
ctx->xquery_size,
- data,
- data_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,
- type, data_size, data);
+ type, rdata_size, rdata);
/* forward to other peers */
- GDS_NEIGHBOURS_handle_reply (type, exp,
- key, put_path_length, pp,
- 0, NULL, data, data_size);
+ GDS_ROUTING_process (type, exp,
+ key, put_path_length, pp,
+ 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);
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;
}
-/**
- * Context containing information about a GET request.
- */
-struct GetRequestContext
-{
- /**
- * extended query (see gnunet_block_lib.h).
- */
- const void *xquery;
-
- /**
- * Bloomfilter to filter out duplicate replies (updated)
- */
- struct GNUNET_CONTAINER_BloomFilter **reply_bf;
-
- /**
- * The key this request was about
- */
- GNUNET_HashCode key;
-
- /**
- * Number of bytes in xquery.
- */
- size_t xquery_size;
-
- /**
- * Mutator value for the reply_bf, see gnunet_block_lib.h
- */
- uint32_t reply_bf_mutator;
-
-};
-
-
/**
* Handle a GET request we've received from another peer.
*
* @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,
- uint32_t type,
+ enum GNUNET_BLOCK_Type type,
const void *xquery,
size_t xquery_size,
struct GNUNET_CONTAINER_BloomFilter **reply_bf,
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;
ctx.reply_bf = reply_bf;
ctx.reply_bf_mutator = reply_bf_mutator;
- (void) GNUNET_DATACACHE_get (datacache, &msg_ctx->key, type,
+ (void) GNUNET_DATACACHE_get (datacache, key, type,
&datacache_get_iterator, &ctx);
+ return ctx.eval;
}
void
GDS_DATACACHE_init ()
{
- datacache = GNUNET_DATACACHE_create (cfg, "dhtcache");
+ datacache = GNUNET_DATACACHE_create (GDS_cfg, "dhtcache");
}