[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r35703 - gnunet/src/dht
From: |
gnunet |
Subject: |
[GNUnet-SVN] r35703 - gnunet/src/dht |
Date: |
Fri, 1 May 2015 10:58:17 +0200 |
Author: grothoff
Date: 2015-05-01 10:58:17 +0200 (Fri, 01 May 2015)
New Revision: 35703
Modified:
gnunet/src/dht/gnunet-service-wdht_datacache.c
gnunet/src/dht/gnunet-service-wdht_datacache.h
gnunet/src/dht/gnunet-service-wdht_neighbours.c
gnunet/src/dht/gnunet-service-wdht_neighbours.h
Log:
-select random
Modified: gnunet/src/dht/gnunet-service-wdht_datacache.c
===================================================================
--- gnunet/src/dht/gnunet-service-wdht_datacache.c 2015-05-01 08:51:08 UTC
(rev 35702)
+++ gnunet/src/dht/gnunet-service-wdht_datacache.c 2015-05-01 08:58:17 UTC
(rev 35703)
@@ -155,6 +155,11 @@
*/
enum GNUNET_BLOCK_EvaluationResult eval;
+ /**
+ * Routing options of the GET.
+ */
+ enum GNUNET_DHT_RouteOption options;
+
};
@@ -211,6 +216,7 @@
("# Good RESULTS found in datacache"), 1,
GNUNET_NO);
GDS_NEIGHBOURS_send_get_result (ctx->trail_id,
+ ctx->options,
key,
type,
put_path_length,
@@ -261,6 +267,7 @@
* 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 options routing options (to be passed along)
* @param key the query
* @param type requested data type
* @param xquery extended query
@@ -271,6 +278,7 @@
*/
enum GNUNET_BLOCK_EvaluationResult
GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *trail_id,
+ enum GNUNET_DHT_RouteOption options,
const struct GNUNET_HashCode *key,
enum GNUNET_BLOCK_Type type,
const void *xquery,
@@ -288,6 +296,7 @@
1, GNUNET_NO);
ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
ctx.trail_id = trail_id;
+ ctx.options = options;
ctx.key = *key;
ctx.xquery = xquery;
ctx.xquery_size = xquery_size;
@@ -361,6 +370,7 @@
return GNUNET_OK;
}
+
/**
* Iterator for local get request results,
*
@@ -387,7 +397,12 @@
{
const struct GNUNET_HashCode *trail_id = cls;
+ /* NOTE: The datacache currently does not store the RO from
+ the original 'put', so we don't know the 'correct' option
+ at this point anymore. Thus, we conservatively assume
+ that recording is desired (for now). */
GDS_NEIGHBOURS_send_get_result (trail_id,
+ GNUNET_DHT_RO_RECORD_ROUTE,
key,
type,
put_path_length, put_path,
Modified: gnunet/src/dht/gnunet-service-wdht_datacache.h
===================================================================
--- gnunet/src/dht/gnunet-service-wdht_datacache.h 2015-05-01 08:51:08 UTC
(rev 35702)
+++ gnunet/src/dht/gnunet-service-wdht_datacache.h 2015-05-01 08:58:17 UTC
(rev 35703)
@@ -29,6 +29,7 @@
#include "gnunet_util_lib.h"
#include "gnunet_block_lib.h"
+#include "gnunet_dht_service.h"
/**
* Handle a datum we've received from another peer. Cache if
@@ -60,6 +61,7 @@
* Handle a GET request we've received from another peer.
*
* @param trail_id trail where the reply needs to be send to
+ * @param options routing options (to be passed along)
* @param key the query
* @param type requested data type
* @param xquery extended query
@@ -72,6 +74,7 @@
*/
enum GNUNET_BLOCK_EvaluationResult
GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *trail_id,
+ enum GNUNET_DHT_RouteOption options,
const struct GNUNET_HashCode *key,
enum GNUNET_BLOCK_Type type,
const void *xquery,
Modified: gnunet/src/dht/gnunet-service-wdht_neighbours.c
===================================================================
--- gnunet/src/dht/gnunet-service-wdht_neighbours.c 2015-05-01 08:51:08 UTC
(rev 35702)
+++ gnunet/src/dht/gnunet-service-wdht_neighbours.c 2015-05-01 08:58:17 UTC
(rev 35703)
@@ -783,6 +783,7 @@
* Send the get result to requesting client.
*
* @param trail_id trail identifying where to send the result to, NULL for us
+ * @param options routing options (from GET request)
* @param key Key of the requested data.
* @param type Block type
* @param put_path_length Number of peers in @a put_path
@@ -790,11 +791,10 @@
* @param expiration When will this result expire?
* @param data Payload to store
* @param data_size Size of the @a data
- *
- * FIXME: also pass options, so we know to record paths or not...
*/
void
GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *trail_id,
+ enum GNUNET_DHT_RouteOption options,
const struct GNUNET_HashCode *key,
enum GNUNET_BLOCK_Type type,
unsigned int put_path_length,
@@ -804,12 +804,33 @@
size_t data_size)
{
struct GNUNET_MessageHeader *payload;
+ struct Trail *trail;
- payload = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader) + data_size);
+ trail = GNUNET_CONTAINER_multihashmap_get (trail_map,
+ trail_id);
+ if (NULL == trail)
+ {
+ /* TODO: inform statistics */
+ return;
+ }
+ if (NULL == trail->pred)
+ {
+ /* result is for *us* (local client) */
+ GDS_CLIENTS_handle_reply (expiration,
+ key,
+ 0, NULL,
+ put_path_length, put_path,
+ type,
+ data_size,
+ data);
+ return;
+ }
+
+ payload = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader) + data_size);
payload->size = data_size;
payload->type = GNUNET_MESSAGE_TYPE_WDHT_GET_RESULT;
- forward_message_on_trail (NULL /* FIXME: put something right */,
+ forward_message_on_trail (trail->pred,
trail_id,
0 /* FIXME: put something right */,
&my_identity,
@@ -870,29 +891,43 @@
/**
+ * Function called with a random friend to be returned.
+ *
+ * @param cls a `struct FriendInfo **` with where to store the result
+ * @param peer the peer identity of the friend (ignored)
+ * @param value the `struct FriendInfo *` that was selected at random
+ * @return #GNUNET_OK (all good)
+ */
+static int
+pick_random_helper (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ void *value)
+{
+ struct FriendInfo **fi = cls;
+ struct FriendInfo *v = value;
+
+ *fi = v;
+ return GNUNET_OK;
+}
+
+
+/**
* Pick random friend from friends for random walk.
+ *
+ * @return NULL if we have no friends
*/
static struct FriendInfo *
pick_random_friend ()
{
- GNUNET_CONTAINER_PeerMapIterator *it;
- if (0 != GNUNET_CONTAINER_multipeermap_get_random (friends_peermap,
- *it,
- NULL) ){
- static struct FriendInfo **friend;
- struct GNUNET_PeerIdentity *key;
+ struct FriendInfo *ret;
- /* FIXME: i am not sure of this one */
- key = NULL;
-
- if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (it,
- key,
- (void *)
friend))
- {
- return *friend;
- }
- }
- return NULL;
+ ret = NULL;
+ if (0 ==
+ GNUNET_CONTAINER_multipeermap_get_random (friends_peermap,
+ &pick_random_helper,
+ &ret))
+ return NULL;
+ return ret;
}
Modified: gnunet/src/dht/gnunet-service-wdht_neighbours.h
===================================================================
--- gnunet/src/dht/gnunet-service-wdht_neighbours.h 2015-05-01 08:51:08 UTC
(rev 35702)
+++ gnunet/src/dht/gnunet-service-wdht_neighbours.h 2015-05-01 08:58:17 UTC
(rev 35703)
@@ -72,6 +72,7 @@
* Send the get result to requesting client.
*
* @param trail_id trail identifying where to send the result to, NULL for us
+ * @param options routing options (from GET request)
* @param key key of the requested data.
* @param type block type
* @param put_path_length number of peers in @a put_path
@@ -82,6 +83,7 @@
*/
void
GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *trail_id,
+ enum GNUNET_DHT_RouteOption options,
const struct GNUNET_HashCode *key,
enum GNUNET_BLOCK_Type type,
unsigned int put_path_length,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r35703 - gnunet/src/dht,
gnunet <=