aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-04-30 09:32:23 +0000
committerChristian Grothoff <christian@grothoff.org>2015-04-30 09:32:23 +0000
commite9b8cd447a2f21f48414e94c8e9ad38b9f78b9b0 (patch)
tree8f078ed8311ff6b53d8605aedf0445d83c6318ca /src/dht
parent1e2d6a79ff39e54c2a1a73432e26e02c77775726 (diff)
downloadgnunet-e9b8cd447a2f21f48414e94c8e9ad38b9f78b9b0.tar.gz
gnunet-e9b8cd447a2f21f48414e94c8e9ad38b9f78b9b0.zip
-more datacache integration work
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/gnunet-service-wdht_datacache.c165
-rw-r--r--src/dht/gnunet-service-wdht_datacache.h14
-rw-r--r--src/dht/gnunet-service-wdht_neighbours.c24
-rw-r--r--src/dht/gnunet-service-wdht_neighbours.h12
4 files changed, 83 insertions, 132 deletions
diff --git a/src/dht/gnunet-service-wdht_datacache.c b/src/dht/gnunet-service-wdht_datacache.c
index 978c8f177..577aa8699 100644
--- a/src/dht/gnunet-service-wdht_datacache.c
+++ b/src/dht/gnunet-service-wdht_datacache.c
@@ -106,28 +106,6 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
106 106
107 107
108/** 108/**
109 * List of peers in the get path.
110 */
111struct GetPath
112{
113 /**
114 * Pointer to next item in the list
115 */
116 struct GetPath *next;
117
118 /**
119 * Pointer to previous item in the list
120 */
121 struct GetPath *prev;
122
123 /**
124 * An element in the get path.
125 */
126 struct GNUNET_PeerIdentity peer;
127};
128
129
130/**
131 * Context containing information about a GET request. 109 * Context containing information about a GET request.
132 */ 110 */
133struct GetRequestContext 111struct GetRequestContext
@@ -148,6 +126,11 @@ struct GetRequestContext
148 struct GNUNET_HashCode key; 126 struct GNUNET_HashCode key;
149 127
150 /** 128 /**
129 * The trail this request was for
130 */
131 const struct GNUNET_HashCode *trail_id;
132
133 /**
151 * Number of bytes in @e xquery. 134 * Number of bytes in @e xquery.
152 */ 135 */
153 size_t xquery_size; 136 size_t xquery_size;
@@ -158,36 +141,10 @@ struct GetRequestContext
158 uint32_t reply_bf_mutator; 141 uint32_t reply_bf_mutator;
159 142
160 /** 143 /**
161 * Total number of peers in @e head.
162 */
163 unsigned int get_path_length;
164
165 /**
166 * Return value to give back. 144 * Return value to give back.
167 */ 145 */
168 enum GNUNET_BLOCK_EvaluationResult eval; 146 enum GNUNET_BLOCK_EvaluationResult eval;
169 147
170 /**
171 * Peeer which has the data for the key.
172 */
173 struct GNUNET_PeerIdentity source_peer;
174
175 /**
176 * Next hop to forward the get result to.
177 */
178 struct GNUNET_PeerIdentity next_hop;
179
180 /**
181 * Head of get path.
182 */
183 struct GetPath *head;
184
185 /**
186 * Tail of get path.
187 */
188 struct GetPath *tail;
189
190 /* get_path */
191}; 148};
192 149
193 150
@@ -243,23 +200,14 @@ datacache_get_iterator (void *cls,
243 gettext_noop 200 gettext_noop
244 ("# Good RESULTS found in datacache"), 1, 201 ("# Good RESULTS found in datacache"), 1,
245 GNUNET_NO); 202 GNUNET_NO);
246 struct GNUNET_PeerIdentity *get_path; 203 GDS_NEIGHBOURS_send_get_result (ctx->trail_id,
247 get_path = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * 204 key,
248 ctx->get_path_length); 205 type,
249 struct GetPath *iterator; 206 put_path_length,
250 iterator = ctx->head; 207 put_path,
251 int i = 0; 208 exp,
252 while (i < ctx->get_path_length) 209 data,
253 { 210 size);
254 get_path[i] = iterator->peer;
255 i++;
256 iterator = iterator->next;
257 }
258 GDS_NEIGHBOURS_send_get_result (key,type, &(ctx->next_hop),&(ctx->source_peer),
259 put_path_length, put_path, ctx->get_path_length,
260 get_path, exp, data, size );
261 GNUNET_free_non_null (get_path);
262
263 break; 211 break;
264 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 212 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
265 GNUNET_STATISTICS_update (GDS_stats, 213 GNUNET_STATISTICS_update (GDS_stats,
@@ -302,64 +250,39 @@ datacache_get_iterator (void *cls,
302/** 250/**
303 * Handle a GET request we've received from another peer. 251 * Handle a GET request we've received from another peer.
304 * 252 *
253 * @param trail_id trail identifying where to send the result to, NULL for us
305 * @param key the query 254 * @param key the query
306 * @param type requested data type 255 * @param type requested data type
307 * @param xquery extended query 256 * @param xquery extended query
308 * @param xquery_size number of bytes in @a xquery 257 * @param xquery_size number of bytes in @a xquery
309 * @param reply_bf where the reply bf is (to be) stored, possibly updated, can be NULL 258 * @param reply_bf where the reply bf is (to be) stored, possibly updated, can be NULL
310 * @param reply_bf_mutator mutation value for @a reply_bf 259 * @param reply_bf_mutator mutation value for @a reply_bf
311 * @param get_path_length Total number of peers in @a get_path
312 * @param get_path Peers query has traversed during GET
313 * @return evaluation result for the local replies 260 * @return evaluation result for the local replies
314 */ 261 */
315enum GNUNET_BLOCK_EvaluationResult 262enum GNUNET_BLOCK_EvaluationResult
316GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, 263GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *trail_id,
264 const struct GNUNET_HashCode *key,
317 enum GNUNET_BLOCK_Type type, 265 enum GNUNET_BLOCK_Type type,
318 const void *xquery, 266 const void *xquery,
319 size_t xquery_size, 267 size_t xquery_size,
320 struct GNUNET_CONTAINER_BloomFilter **reply_bf, 268 struct GNUNET_CONTAINER_BloomFilter **reply_bf,
321 uint32_t reply_bf_mutator, 269 uint32_t reply_bf_mutator)
322 uint32_t get_path_length,
323 struct GNUNET_PeerIdentity *get_path,
324 struct GNUNET_PeerIdentity *next_hop,
325 struct GNUNET_PeerIdentity *source_peer)
326{ 270{
327 struct GetRequestContext ctx; 271 struct GetRequestContext ctx;
328 unsigned int r; 272 unsigned int r;
329 273
330 if (datacache == NULL) 274 if (NULL == datacache)
331 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 275 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
332 GNUNET_STATISTICS_update (GDS_stats, 276 GNUNET_STATISTICS_update (GDS_stats,
333 gettext_noop ("# GET requests given to datacache"), 277 gettext_noop ("# GET requests given to datacache"),
334 1, GNUNET_NO); 278 1, GNUNET_NO);
335 ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 279 ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
280 ctx.trail_id = trail_id;
336 ctx.key = *key; 281 ctx.key = *key;
337 ctx.xquery = xquery; 282 ctx.xquery = xquery;
338 ctx.xquery_size = xquery_size; 283 ctx.xquery_size = xquery_size;
339 ctx.reply_bf = reply_bf; 284 ctx.reply_bf = reply_bf;
340 ctx.reply_bf_mutator = reply_bf_mutator; 285 ctx.reply_bf_mutator = reply_bf_mutator;
341 ctx.get_path_length = get_path_length;
342
343 if (NULL != next_hop)
344 ctx.next_hop = *next_hop;
345 unsigned int i = 0;
346
347 ctx.head = NULL;
348 ctx.tail = NULL;
349 if (NULL != get_path)
350 {
351 while (i < get_path_length)
352 {
353 struct GetPath *element;
354 element = GNUNET_new (struct GetPath);
355 element->next = NULL;
356 element->prev = NULL;
357 element->peer = get_path[i];
358 GNUNET_CONTAINER_DLL_insert_tail (ctx.head, ctx.tail, element);
359 i++;
360 }
361 }
362
363 r = GNUNET_DATACACHE_get (datacache, 286 r = GNUNET_DATACACHE_get (datacache,
364 key, 287 key,
365 type, 288 type,
@@ -428,21 +351,59 @@ GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key)
428 return GNUNET_OK; 351 return GNUNET_OK;
429} 352}
430 353
354/**
355 * Iterator for local get request results,
356 *
357 * @param cls closure with the `struct GNUNET_HashCode *` with the trail ID
358 * @param key the key this data is stored under
359 * @param size the size of the data identified by key
360 * @param data the actual data
361 * @param type the type of the data
362 * @param exp when does this value expire?
363 * @param put_path_length number of peers in @a put_path
364 * @param put_path path the reply took on put
365 * @return #GNUNET_OK to continue iteration, anything else
366 * to stop iteration.
367 */
368static int
369datacache_get_successors_iterator (void *cls,
370 const struct GNUNET_HashCode *key,
371 size_t size,
372 const char *data,
373 enum GNUNET_BLOCK_Type type,
374 struct GNUNET_TIME_Absolute exp,
375 unsigned int put_path_length,
376 const struct GNUNET_PeerIdentity *put_path)
377{
378 const struct GNUNET_HashCode *trail_id = cls;
379
380 GDS_NEIGHBOURS_send_get_result (trail_id,
381 key,
382 type,
383 put_path_length, put_path,
384 exp,
385 data,
386 size);
387 return GNUNET_OK;
388}
389
431 390
432/** 391/**
433 * Handle a request for data close to a key that we have received from 392 * Handle a request for data close to a key that we have received from
434 * another peer. 393 * another peer.
435 * 394 *
395 * @param trail_id trail where the reply needs to be send to
436 * @param key the location at which the peer is looking for data that is close 396 * @param key the location at which the peer is looking for data that is close
437 */ 397 */
438void 398void
439GDS_DATACACHE_get_successors (const struct GNUNET_HashCode *key) 399GDS_DATACACHE_get_successors (const struct GNUNET_HashCode *trail_id,
400 const struct GNUNET_HashCode *key)
440{ 401{
441 GNUNET_DATACACHE_get_closest (datacache, 402 (void) GNUNET_DATACACHE_get_closest (datacache,
442 key, 403 key,
443 NUM_CLOSEST, 404 NUM_CLOSEST,
444 NULL /* FIXME */, 405 &datacache_get_successors_iterator,
445 NULL); 406 (void *) trail_id);
446} 407}
447 408
448 409
diff --git a/src/dht/gnunet-service-wdht_datacache.h b/src/dht/gnunet-service-wdht_datacache.h
index 818138a87..39edbbb59 100644
--- a/src/dht/gnunet-service-wdht_datacache.h
+++ b/src/dht/gnunet-service-wdht_datacache.h
@@ -54,6 +54,7 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
54/** 54/**
55 * Handle a GET request we've received from another peer. 55 * Handle a GET request we've received from another peer.
56 * 56 *
57 * @param trail_id trail where the reply needs to be send to
57 * @param key the query 58 * @param key the query
58 * @param type requested data type 59 * @param type requested data type
59 * @param xquery extended query 60 * @param xquery extended query
@@ -63,16 +64,13 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
63 * @return evaluation result for the local replies 64 * @return evaluation result for the local replies
64 */ 65 */
65enum GNUNET_BLOCK_EvaluationResult 66enum GNUNET_BLOCK_EvaluationResult
66GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, 67GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *trail_id,
68 const struct GNUNET_HashCode *key,
67 enum GNUNET_BLOCK_Type type, 69 enum GNUNET_BLOCK_Type type,
68 const void *xquery, 70 const void *xquery,
69 size_t xquery_size, 71 size_t xquery_size,
70 struct GNUNET_CONTAINER_BloomFilter **reply_bf, 72 struct GNUNET_CONTAINER_BloomFilter **reply_bf,
71 uint32_t reply_bf_mutator, 73 uint32_t reply_bf_mutator);
72 uint32_t get_path_length,
73 struct GNUNET_PeerIdentity *get_path,
74 struct GNUNET_PeerIdentity *next_hop,
75 struct GNUNET_PeerIdentity *source_peer);
76 74
77 75
78/** 76/**
@@ -91,10 +89,12 @@ GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key);
91 * Handle a request for data close to a key that we have received from 89 * Handle a request for data close to a key that we have received from
92 * another peer. 90 * another peer.
93 * 91 *
92 * @param trail_id trail where the reply needs to be send to
94 * @param key the location at which the peer is looking for data that is close 93 * @param key the location at which the peer is looking for data that is close
95 */ 94 */
96void 95void
97GDS_DATACACHE_get_successors (const struct GNUNET_HashCode *key); 96GDS_DATACACHE_get_successors (const struct GNUNET_HashCode *trail_id,
97 const struct GNUNET_HashCode *key);
98 98
99 99
100/** 100/**
diff --git a/src/dht/gnunet-service-wdht_neighbours.c b/src/dht/gnunet-service-wdht_neighbours.c
index d9cee4196..fd6c62540 100644
--- a/src/dht/gnunet-service-wdht_neighbours.c
+++ b/src/dht/gnunet-service-wdht_neighbours.c
@@ -625,14 +625,14 @@ delete_trail (struct Trail *trail,
625 struct TrailDestroyMessage *tdm; 625 struct TrailDestroyMessage *tdm;
626 struct Finger *finger; 626 struct Finger *finger;
627 627
628 friend = current->pred; 628 friend = trail->pred;
629 if (NULL != friend) 629 if (NULL != friend)
630 { 630 {
631 if (GNUNET_YES == inform_pred) 631 if (GNUNET_YES == inform_pred)
632 { 632 {
633 env = GNUNET_MQ_msg (tdm, 633 env = GNUNET_MQ_msg (tdm,
634 GNUNET_MESSAGE_TYPE_WDHT_TRAIL_DESTROY); 634 GNUNET_MESSAGE_TYPE_WDHT_TRAIL_DESTROY);
635 tdm->trail_id = current->pred_id; 635 tdm->trail_id = trail->pred_id;
636 GNUNET_MQ_send (friend->mq, 636 GNUNET_MQ_send (friend->mq,
637 env); 637 env);
638 } 638 }
@@ -641,14 +641,14 @@ delete_trail (struct Trail *trail,
641 friend->pred_tail, 641 friend->pred_tail,
642 trail); 642 trail);
643 } 643 }
644 friend = current->succ; 644 friend = trail->succ;
645 if (NULL != friend) 645 if (NULL != friend)
646 { 646 {
647 if (GNUNET_YES == inform_succ) 647 if (GNUNET_YES == inform_succ)
648 { 648 {
649 env = GNUNET_MQ_msg (tdm, 649 env = GNUNET_MQ_msg (tdm,
650 GNUNET_MESSAGE_TYPE_WDHT_TRAIL_DESTROY); 650 GNUNET_MESSAGE_TYPE_WDHT_TRAIL_DESTROY);
651 tdm->trail_id = current->pred_id; 651 tdm->trail_id = trail->pred_id;
652 GNUNET_MQ_send (friend->mq, 652 GNUNET_MQ_send (friend->mq,
653 env); 653 env);
654 } 654 }
@@ -672,34 +672,30 @@ delete_trail (struct Trail *trail,
672/** 672/**
673 * Send the get result to requesting client. 673 * Send the get result to requesting client.
674 * 674 *
675 * @param trail_id trail identifying where to send the result to, NULL for us
675 * @param key Key of the requested data. 676 * @param key Key of the requested data.
676 * @param type Block type 677 * @param type Block type
677 * @param target_peer Next peer to forward the message to.
678 * @param source_peer Peer which has the data for the key.
679 * @param put_path_length Number of peers in @a put_path 678 * @param put_path_length Number of peers in @a put_path
680 * @param put_path Path taken to put the data at its stored location. 679 * @param put_path Path taken to put the data at its stored location.
681 * @param get_path_length Number of peers in @a get_path
682 * @param get_path Path taken to reach to the location of the key.
683 * @param expiration When will this result expire? 680 * @param expiration When will this result expire?
684 * @param data Payload to store 681 * @param data Payload to store
685 * @param data_size Size of the @a data 682 * @param data_size Size of the @a data
686 */ 683 */
687void 684void
688GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, 685GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *trail_id,
686 const struct GNUNET_HashCode *key,
689 enum GNUNET_BLOCK_Type type, 687 enum GNUNET_BLOCK_Type type,
690 const struct GNUNET_PeerIdentity *target_peer,
691 const struct GNUNET_PeerIdentity *source_peer,
692 unsigned int put_path_length, 688 unsigned int put_path_length,
693 const struct GNUNET_PeerIdentity *put_path, 689 const struct GNUNET_PeerIdentity *put_path,
694 unsigned int get_path_length,
695 const struct GNUNET_PeerIdentity *get_path,
696 struct GNUNET_TIME_Absolute expiration, 690 struct GNUNET_TIME_Absolute expiration,
697 const void *data, size_t data_size) 691 const void *data,
692 size_t data_size)
698{ 693{
699 // TRICKY: need to introduce some context to remember trail from 694 // TRICKY: need to introduce some context to remember trail from
700 // the lookup... 695 // the lookup...
701} 696}
702 697
698
703/** 699/**
704 * Method called whenever a peer disconnects. 700 * Method called whenever a peer disconnects.
705 * 701 *
diff --git a/src/dht/gnunet-service-wdht_neighbours.h b/src/dht/gnunet-service-wdht_neighbours.h
index a46c63c48..4dba04da2 100644
--- a/src/dht/gnunet-service-wdht_neighbours.h
+++ b/src/dht/gnunet-service-wdht_neighbours.h
@@ -71,27 +71,21 @@ GDS_NEIGHBOURS_handle_get (const struct GNUNET_HashCode *key,
71/** 71/**
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 key Key of the requested data. 75 * @param key Key of the requested data.
75 * @param type Block type 76 * @param type Block type
76 * @param target_peer Next peer to forward the message to.
77 * @param source_peer Peer which has the data for the key.
78 * @param put_path_length Number of peers in @a put_path 77 * @param put_path_length Number of peers in @a put_path
79 * @param put_path Path taken to put the data at its stored location. 78 * @param put_path Path taken to put the data at its stored location.
80 * @param get_path_length Number of peers in @a get_path
81 * @param get_path Path taken to reach to the location of the key.
82 * @param expiration When will this result expire? 79 * @param expiration When will this result expire?
83 * @param data Payload to store 80 * @param data Payload to store
84 * @param data_size Size of the @a data 81 * @param data_size Size of the @a data
85 */ 82 */
86void 83void
87GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, 84GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *trail_id,
85 const struct GNUNET_HashCode *key,
88 enum GNUNET_BLOCK_Type type, 86 enum GNUNET_BLOCK_Type type,
89 const struct GNUNET_PeerIdentity *target_peer,
90 const struct GNUNET_PeerIdentity *source_peer,
91 unsigned int put_path_length, 87 unsigned int put_path_length,
92 const struct GNUNET_PeerIdentity *put_path, 88 const struct GNUNET_PeerIdentity *put_path,
93 unsigned int get_path_length,
94 const struct GNUNET_PeerIdentity *get_path,
95 struct GNUNET_TIME_Absolute expiration, 89 struct GNUNET_TIME_Absolute expiration,
96 const void *data, size_t data_size); 90 const void *data, size_t data_size);
97 91