*/
/**
- * @file dht/gnunet-service-xdht_datacache.c
+ * @file dht/gnunet-service-dht_datacache.c
* @brief GNUnet DHT service's datacache integration
* @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-xdht_clients.h"
+#include "gnunet-service-xdht_datacache.h"
+#include "gnunet-service-xdht_routing.h"
+#include "gnunet-service-xdht_neighbours.h"
#include "gnunet-service-dht.h"
#define LOG(kind,...) GNUNET_log_from (kind, "dht-dtcache",__VA_ARGS__)
GNUNET_h2s (key), data_size, r, put_path_length);
}
+/**
+ * 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.
* Mutator value for the reply_bf, see gnunet_block_lib.h
*/
uint32_t reply_bf_mutator;
-
+
+ /**
+ * Total number of peers in get path.
+ */
+ 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 */
};
datacache_get_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)
+ struct GNUNET_TIME_Absolute exp,
+ unsigned int put_path_length,
+ const struct GNUNET_PeerIdentity *put_path)
{
struct GetRequestContext *ctx = cls;
enum GNUNET_BLOCK_EvaluationResult eval;
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, put_path,
- type, size, data);
- /* forward to other peers */
- GDS_ROUTING_process (type, exp, key, put_path_length, put_path, 0, NULL,
- data, size);
+ GNUNET_NO);
+ struct GNUNET_PeerIdentity *get_path;
+ get_path = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
+ struct GetPath *iterator;
+ iterator = ctx->head;
+ int i = 0;
+ while (i < ctx->get_path_length)
+ {
+ memcpy (&get_path[i], &(iterator->peer), sizeof (struct GNUNET_PeerIdentity));
+ 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 );
+
break;
case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
GNUNET_STATISTICS_update (GDS_stats,
* @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
+ * @get_path_length Total number of peers in get path
+ * @get_path Peers in get path.
*/
enum GNUNET_BLOCK_EvaluationResult
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)
+ 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)
{
struct GetRequestContext ctx;
unsigned int r;
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 (next_hop != NULL)
+ memcpy (&(ctx.next_hop), next_hop, sizeof (struct GNUNET_PeerIdentity));
+
+ int i = 0;
+
+ if(get_path != NULL)
+ {
+ while (i < get_path_length)
+ {
+ struct GetPath *element;
+ element = GNUNET_malloc (sizeof (struct GetPath));
+ element->next = NULL;
+ element->prev = NULL;
+
+ memcpy (&(element->peer), &get_path[i], sizeof(struct GNUNET_PeerIdentity));
+ GNUNET_CONTAINER_DLL_insert (ctx.head, ctx.tail, element);
+ i++;
+ }
+ }
+
r = GNUNET_DATACACHE_get (datacache, key, type, &datacache_get_iterator,
&ctx);
LOG (GNUNET_ERROR_TYPE_DEBUG,