aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-05-01 08:58:17 +0000
committerChristian Grothoff <christian@grothoff.org>2015-05-01 08:58:17 +0000
commit716959c44727dd2c04871df383b9cca511286113 (patch)
tree5788ad5391ae40f622af8903ef0a6a6fda3cbcb9 /src/dht
parent7f8bcc9eb8c0362c44682b9cdc5675ae9527a1e8 (diff)
downloadgnunet-716959c44727dd2c04871df383b9cca511286113.tar.gz
gnunet-716959c44727dd2c04871df383b9cca511286113.zip
-select random
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/gnunet-service-wdht_datacache.c15
-rw-r--r--src/dht/gnunet-service-wdht_datacache.h3
-rw-r--r--src/dht/gnunet-service-wdht_neighbours.c79
-rw-r--r--src/dht/gnunet-service-wdht_neighbours.h2
4 files changed, 77 insertions, 22 deletions
diff --git a/src/dht/gnunet-service-wdht_datacache.c b/src/dht/gnunet-service-wdht_datacache.c
index 63b946811..77591c502 100644
--- a/src/dht/gnunet-service-wdht_datacache.c
+++ b/src/dht/gnunet-service-wdht_datacache.c
@@ -155,6 +155,11 @@ struct GetRequestContext
155 */ 155 */
156 enum GNUNET_BLOCK_EvaluationResult eval; 156 enum GNUNET_BLOCK_EvaluationResult eval;
157 157
158 /**
159 * Routing options of the GET.
160 */
161 enum GNUNET_DHT_RouteOption options;
162
158}; 163};
159 164
160 165
@@ -211,6 +216,7 @@ datacache_get_iterator (void *cls,
211 ("# Good RESULTS found in datacache"), 1, 216 ("# Good RESULTS found in datacache"), 1,
212 GNUNET_NO); 217 GNUNET_NO);
213 GDS_NEIGHBOURS_send_get_result (ctx->trail_id, 218 GDS_NEIGHBOURS_send_get_result (ctx->trail_id,
219 ctx->options,
214 key, 220 key,
215 type, 221 type,
216 put_path_length, 222 put_path_length,
@@ -261,6 +267,7 @@ datacache_get_iterator (void *cls,
261 * Handle a GET request we've received from another peer. 267 * Handle a GET request we've received from another peer.
262 * 268 *
263 * @param trail_id trail identifying where to send the result to, NULL for us 269 * @param trail_id trail identifying where to send the result to, NULL for us
270 * @param options routing options (to be passed along)
264 * @param key the query 271 * @param key the query
265 * @param type requested data type 272 * @param type requested data type
266 * @param xquery extended query 273 * @param xquery extended query
@@ -271,6 +278,7 @@ datacache_get_iterator (void *cls,
271 */ 278 */
272enum GNUNET_BLOCK_EvaluationResult 279enum GNUNET_BLOCK_EvaluationResult
273GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *trail_id, 280GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *trail_id,
281 enum GNUNET_DHT_RouteOption options,
274 const struct GNUNET_HashCode *key, 282 const struct GNUNET_HashCode *key,
275 enum GNUNET_BLOCK_Type type, 283 enum GNUNET_BLOCK_Type type,
276 const void *xquery, 284 const void *xquery,
@@ -288,6 +296,7 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *trail_id,
288 1, GNUNET_NO); 296 1, GNUNET_NO);
289 ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 297 ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
290 ctx.trail_id = trail_id; 298 ctx.trail_id = trail_id;
299 ctx.options = options;
291 ctx.key = *key; 300 ctx.key = *key;
292 ctx.xquery = xquery; 301 ctx.xquery = xquery;
293 ctx.xquery_size = xquery_size; 302 ctx.xquery_size = xquery_size;
@@ -361,6 +370,7 @@ GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key)
361 return GNUNET_OK; 370 return GNUNET_OK;
362} 371}
363 372
373
364/** 374/**
365 * Iterator for local get request results, 375 * Iterator for local get request results,
366 * 376 *
@@ -387,7 +397,12 @@ datacache_get_successors_iterator (void *cls,
387{ 397{
388 const struct GNUNET_HashCode *trail_id = cls; 398 const struct GNUNET_HashCode *trail_id = cls;
389 399
400 /* NOTE: The datacache currently does not store the RO from
401 the original 'put', so we don't know the 'correct' option
402 at this point anymore. Thus, we conservatively assume
403 that recording is desired (for now). */
390 GDS_NEIGHBOURS_send_get_result (trail_id, 404 GDS_NEIGHBOURS_send_get_result (trail_id,
405 GNUNET_DHT_RO_RECORD_ROUTE,
391 key, 406 key,
392 type, 407 type,
393 put_path_length, put_path, 408 put_path_length, put_path,
diff --git a/src/dht/gnunet-service-wdht_datacache.h b/src/dht/gnunet-service-wdht_datacache.h
index 64b80081e..1012d2347 100644
--- a/src/dht/gnunet-service-wdht_datacache.h
+++ b/src/dht/gnunet-service-wdht_datacache.h
@@ -29,6 +29,7 @@
29 29
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_block_lib.h" 31#include "gnunet_block_lib.h"
32#include "gnunet_dht_service.h"
32 33
33/** 34/**
34 * Handle a datum we've received from another peer. Cache if 35 * Handle a datum we've received from another peer. Cache if
@@ -60,6 +61,7 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
60 * Handle a GET request we've received from another peer. 61 * Handle a GET request we've received from another peer.
61 * 62 *
62 * @param trail_id trail where the reply needs to be send to 63 * @param trail_id trail where the reply needs to be send to
64 * @param options routing options (to be passed along)
63 * @param key the query 65 * @param key the query
64 * @param type requested data type 66 * @param type requested data type
65 * @param xquery extended query 67 * @param xquery extended query
@@ -72,6 +74,7 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
72 */ 74 */
73enum GNUNET_BLOCK_EvaluationResult 75enum GNUNET_BLOCK_EvaluationResult
74GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *trail_id, 76GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *trail_id,
77 enum GNUNET_DHT_RouteOption options,
75 const struct GNUNET_HashCode *key, 78 const struct GNUNET_HashCode *key,
76 enum GNUNET_BLOCK_Type type, 79 enum GNUNET_BLOCK_Type type,
77 const void *xquery, 80 const void *xquery,
diff --git a/src/dht/gnunet-service-wdht_neighbours.c b/src/dht/gnunet-service-wdht_neighbours.c
index 4e6ccf432..2e9ae04ca 100644
--- a/src/dht/gnunet-service-wdht_neighbours.c
+++ b/src/dht/gnunet-service-wdht_neighbours.c
@@ -783,6 +783,7 @@ forward_message_on_trail (struct FriendInfo *next_target,
783 * Send the get result to requesting client. 783 * Send the get result to requesting client.
784 * 784 *
785 * @param trail_id trail identifying where to send the result to, NULL for us 785 * @param trail_id trail identifying where to send the result to, NULL for us
786 * @param options routing options (from GET request)
786 * @param key Key of the requested data. 787 * @param key Key of the requested data.
787 * @param type Block type 788 * @param type Block type
788 * @param put_path_length Number of peers in @a put_path 789 * @param put_path_length Number of peers in @a put_path
@@ -790,11 +791,10 @@ forward_message_on_trail (struct FriendInfo *next_target,
790 * @param expiration When will this result expire? 791 * @param expiration When will this result expire?
791 * @param data Payload to store 792 * @param data Payload to store
792 * @param data_size Size of the @a data 793 * @param data_size Size of the @a data
793 *
794 * FIXME: also pass options, so we know to record paths or not...
795 */ 794 */
796void 795void
797GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *trail_id, 796GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *trail_id,
797 enum GNUNET_DHT_RouteOption options,
798 const struct GNUNET_HashCode *key, 798 const struct GNUNET_HashCode *key,
799 enum GNUNET_BLOCK_Type type, 799 enum GNUNET_BLOCK_Type type,
800 unsigned int put_path_length, 800 unsigned int put_path_length,
@@ -804,12 +804,33 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *trail_id,
804 size_t data_size) 804 size_t data_size)
805{ 805{
806 struct GNUNET_MessageHeader *payload; 806 struct GNUNET_MessageHeader *payload;
807 struct Trail *trail;
807 808
808 payload = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader) + data_size); 809 trail = GNUNET_CONTAINER_multihashmap_get (trail_map,
810 trail_id);
811 if (NULL == trail)
812 {
813 /* TODO: inform statistics */
814 return;
815 }
816 if (NULL == trail->pred)
817 {
818 /* result is for *us* (local client) */
819 GDS_CLIENTS_handle_reply (expiration,
820 key,
821 0, NULL,
822 put_path_length, put_path,
823 type,
824 data_size,
825 data);
826 return;
827 }
828
829 payload = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader) + data_size);
809 payload->size = data_size; 830 payload->size = data_size;
810 payload->type = GNUNET_MESSAGE_TYPE_WDHT_GET_RESULT; 831 payload->type = GNUNET_MESSAGE_TYPE_WDHT_GET_RESULT;
811 832
812 forward_message_on_trail (NULL /* FIXME: put something right */, 833 forward_message_on_trail (trail->pred,
813 trail_id, 834 trail_id,
814 0 /* FIXME: put something right */, 835 0 /* FIXME: put something right */,
815 &my_identity, 836 &my_identity,
@@ -870,29 +891,43 @@ handle_core_disconnect (void *cls,
870 891
871 892
872/** 893/**
894 * Function called with a random friend to be returned.
895 *
896 * @param cls a `struct FriendInfo **` with where to store the result
897 * @param peer the peer identity of the friend (ignored)
898 * @param value the `struct FriendInfo *` that was selected at random
899 * @return #GNUNET_OK (all good)
900 */
901static int
902pick_random_helper (void *cls,
903 const struct GNUNET_PeerIdentity *peer,
904 void *value)
905{
906 struct FriendInfo **fi = cls;
907 struct FriendInfo *v = value;
908
909 *fi = v;
910 return GNUNET_OK;
911}
912
913
914/**
873 * Pick random friend from friends for random walk. 915 * Pick random friend from friends for random walk.
916 *
917 * @return NULL if we have no friends
874 */ 918 */
875static struct FriendInfo * 919static struct FriendInfo *
876pick_random_friend () 920pick_random_friend ()
877{ 921{
878 GNUNET_CONTAINER_PeerMapIterator *it; 922 struct FriendInfo *ret;
879 if (0 != GNUNET_CONTAINER_multipeermap_get_random (friends_peermap, 923
880 *it, 924 ret = NULL;
881 NULL) ){ 925 if (0 ==
882 static struct FriendInfo **friend; 926 GNUNET_CONTAINER_multipeermap_get_random (friends_peermap,
883 struct GNUNET_PeerIdentity *key; 927 &pick_random_helper,
884 928 &ret))
885 /* FIXME: i am not sure of this one */ 929 return NULL;
886 key = NULL; 930 return ret;
887
888 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (it,
889 key,
890 (void *) friend))
891 {
892 return *friend;
893 }
894 }
895 return NULL;
896} 931}
897 932
898 933
diff --git a/src/dht/gnunet-service-wdht_neighbours.h b/src/dht/gnunet-service-wdht_neighbours.h
index cc6be45a3..17043d804 100644
--- a/src/dht/gnunet-service-wdht_neighbours.h
+++ b/src/dht/gnunet-service-wdht_neighbours.h
@@ -72,6 +72,7 @@ GDS_NEIGHBOURS_handle_get (const struct GNUNET_HashCode *key,
72 * Send the get result to requesting client. 72 * Send the get result to requesting client.
73 * 73 *
74 * @param trail_id trail identifying where to send the result to, NULL for us 74 * @param trail_id trail identifying where to send the result to, NULL for us
75 * @param options routing options (from GET request)
75 * @param key key of the requested data. 76 * @param key key of the requested data.
76 * @param type block type 77 * @param type block type
77 * @param put_path_length number of peers in @a put_path 78 * @param put_path_length number of peers in @a put_path
@@ -82,6 +83,7 @@ GDS_NEIGHBOURS_handle_get (const struct GNUNET_HashCode *key,
82 */ 83 */
83void 84void
84GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *trail_id, 85GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *trail_id,
86 enum GNUNET_DHT_RouteOption options,
85 const struct GNUNET_HashCode *key, 87 const struct GNUNET_HashCode *key,
86 enum GNUNET_BLOCK_Type type, 88 enum GNUNET_BLOCK_Type type,
87 unsigned int put_path_length, 89 unsigned int put_path_length,