diff options
Diffstat (limited to 'src/dht/gnunet-service-dht_routing.c')
-rw-r--r-- | src/dht/gnunet-service-dht_routing.c | 128 |
1 files changed, 49 insertions, 79 deletions
diff --git a/src/dht/gnunet-service-dht_routing.c b/src/dht/gnunet-service-dht_routing.c index b05fb76d3..ef3aded77 100644 --- a/src/dht/gnunet-service-dht_routing.c +++ b/src/dht/gnunet-service-dht_routing.c | |||
@@ -62,11 +62,6 @@ struct RecentRequest | |||
62 | struct GNUNET_BLOCK_Group *bg; | 62 | struct GNUNET_BLOCK_Group *bg; |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Type of the requested block. | ||
66 | */ | ||
67 | enum GNUNET_BLOCK_Type type; | ||
68 | |||
69 | /** | ||
70 | * extended query (see gnunet_block_lib.h). Allocated at the | 65 | * extended query (see gnunet_block_lib.h). Allocated at the |
71 | * end of this struct. | 66 | * end of this struct. |
72 | */ | 67 | */ |
@@ -78,6 +73,11 @@ struct RecentRequest | |||
78 | size_t xquery_size; | 73 | size_t xquery_size; |
79 | 74 | ||
80 | /** | 75 | /** |
76 | * Type of the requested block. | ||
77 | */ | ||
78 | enum GNUNET_BLOCK_Type type; | ||
79 | |||
80 | /** | ||
81 | * Request options. | 81 | * Request options. |
82 | */ | 82 | */ |
83 | enum GNUNET_DHT_RouteOption options; | 83 | enum GNUNET_DHT_RouteOption options; |
@@ -148,17 +148,16 @@ struct ProcessContext | |||
148 | * @param cls the `struct ProcessContext` with the result | 148 | * @param cls the `struct ProcessContext` with the result |
149 | * @param key the query | 149 | * @param key the query |
150 | * @param value the `struct RecentRequest` with the request | 150 | * @param value the `struct RecentRequest` with the request |
151 | * @return #GNUNET_OK (continue to iterate), | 151 | * @return #GNUNET_OK (continue to iterate) |
152 | * #GNUNET_SYSERR if the result is malformed or type unsupported | ||
153 | */ | 152 | */ |
154 | static int | 153 | static enum GNUNET_GenericReturnValue |
155 | process (void *cls, | 154 | process (void *cls, |
156 | const struct GNUNET_HashCode *key, | 155 | const struct GNUNET_HashCode *key, |
157 | void *value) | 156 | void *value) |
158 | { | 157 | { |
159 | struct ProcessContext *pc = cls; | 158 | struct ProcessContext *pc = cls; |
160 | struct RecentRequest *rr = value; | 159 | struct RecentRequest *rr = value; |
161 | enum GNUNET_BLOCK_EvaluationResult eval; | 160 | enum GNUNET_BLOCK_ReplyEvaluationResult eval; |
162 | unsigned int gpl; | 161 | unsigned int gpl; |
163 | unsigned int ppl; | 162 | unsigned int ppl; |
164 | struct GNUNET_HashCode hc; | 163 | struct GNUNET_HashCode hc; |
@@ -178,8 +177,11 @@ process (void *cls, | |||
178 | gpl = 0; | 177 | gpl = 0; |
179 | ppl = 0; | 178 | ppl = 0; |
180 | } | 179 | } |
181 | if ((0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) && | 180 | /* FIXME-SCHANZEN: should we modify FIND_PEER to |
182 | (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO)) | 181 | be a generic approximate search and not check |
182 | for the DHT_HELLO type here? */ | ||
183 | if ( (0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) && | ||
184 | (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO) ) | ||
183 | { | 185 | { |
184 | /* key may not match HELLO, which is OK since | 186 | /* key may not match HELLO, which is OK since |
185 | * the search is approximate. Still, the evaluation | 187 | * the search is approximate. Still, the evaluation |
@@ -197,15 +199,14 @@ process (void *cls, | |||
197 | eval_key = key; | 199 | eval_key = key; |
198 | } | 200 | } |
199 | eval | 201 | eval |
200 | = GNUNET_BLOCK_evaluate (GDS_block_context, | 202 | = GNUNET_BLOCK_check_reply (GDS_block_context, |
201 | pc->type, | 203 | pc->type, |
202 | rr->bg, | 204 | rr->bg, |
203 | GNUNET_BLOCK_EO_NONE, | 205 | eval_key, |
204 | eval_key, | 206 | rr->xquery, |
205 | rr->xquery, | 207 | rr->xquery_size, |
206 | rr->xquery_size, | 208 | pc->data, |
207 | pc->data, | 209 | pc->data_size); |
208 | pc->data_size); | ||
209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
210 | "Result for %s of type %d was evaluated as %d\n", | 211 | "Result for %s of type %d was evaluated as %d\n", |
211 | GNUNET_h2s (key), | 212 | GNUNET_h2s (key), |
@@ -213,12 +214,13 @@ process (void *cls, | |||
213 | eval); | 214 | eval); |
214 | switch (eval) | 215 | switch (eval) |
215 | { | 216 | { |
216 | case GNUNET_BLOCK_EVALUATION_OK_MORE: | 217 | case GNUNET_BLOCK_REPLY_OK_MORE: |
217 | case GNUNET_BLOCK_EVALUATION_OK_LAST: | 218 | case GNUNET_BLOCK_REPLY_OK_LAST: |
219 | case GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED: | ||
218 | GNUNET_STATISTICS_update (GDS_stats, | 220 | GNUNET_STATISTICS_update (GDS_stats, |
219 | gettext_noop | 221 | "# Good REPLIES matched against routing table", |
220 | ("# Good REPLIES matched against routing table"), | 222 | 1, |
221 | 1, GNUNET_NO); | 223 | GNUNET_NO); |
222 | GDS_NEIGHBOURS_handle_reply (&rr->peer, | 224 | GDS_NEIGHBOURS_handle_reply (&rr->peer, |
223 | pc->type, | 225 | pc->type, |
224 | pc->expiration_time, | 226 | pc->expiration_time, |
@@ -228,50 +230,28 @@ process (void *cls, | |||
228 | pc->data, | 230 | pc->data, |
229 | pc->data_size); | 231 | pc->data_size); |
230 | break; | 232 | break; |
231 | 233 | case GNUNET_BLOCK_REPLY_OK_DUPLICATE: | |
232 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | ||
233 | GNUNET_STATISTICS_update (GDS_stats, | 234 | GNUNET_STATISTICS_update (GDS_stats, |
234 | gettext_noop | 235 | "# Duplicate REPLIES matched against routing table", |
235 | ( | 236 | 1, |
236 | "# Duplicate REPLIES matched against routing table"), | 237 | GNUNET_NO); |
237 | 1, GNUNET_NO); | ||
238 | return GNUNET_OK; | 238 | return GNUNET_OK; |
239 | 239 | case GNUNET_BLOCK_REPLY_INVALID: | |
240 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: | ||
241 | GNUNET_STATISTICS_update (GDS_stats, | ||
242 | gettext_noop | ||
243 | ( | ||
244 | "# Invalid REPLIES matched against routing table"), | ||
245 | 1, GNUNET_NO); | ||
246 | return GNUNET_SYSERR; | ||
247 | |||
248 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: | ||
249 | GNUNET_STATISTICS_update (GDS_stats, | ||
250 | gettext_noop | ||
251 | ( | ||
252 | "# Irrelevant REPLIES matched against routing table"), | ||
253 | 1, GNUNET_NO); | ||
254 | return GNUNET_OK; | ||
255 | |||
256 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: | ||
257 | GNUNET_break (0); | ||
258 | return GNUNET_OK; | ||
259 | |||
260 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: | ||
261 | GNUNET_break (0); | 240 | GNUNET_break (0); |
241 | GNUNET_STATISTICS_update (GDS_stats, | ||
242 | "# Invalid REPLIES matched against routing table", | ||
243 | 1, | ||
244 | GNUNET_NO); | ||
262 | return GNUNET_OK; | 245 | return GNUNET_OK; |
263 | 246 | case GNUNET_BLOCK_REPLY_IRRELEVANT: | |
264 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: | ||
265 | GNUNET_STATISTICS_update (GDS_stats, | 247 | GNUNET_STATISTICS_update (GDS_stats, |
266 | gettext_noop | 248 | "# Irrelevant REPLIES matched against routing table", |
267 | ( | 249 | 1, |
268 | "# Unsupported REPLIES matched against routing table"), | 250 | GNUNET_NO); |
269 | 1, GNUNET_NO); | 251 | return GNUNET_OK; |
270 | return GNUNET_SYSERR; | ||
271 | |||
272 | default: | 252 | default: |
273 | GNUNET_break (0); | 253 | GNUNET_break (0); |
274 | return GNUNET_SYSERR; | 254 | return GNUNET_OK; |
275 | } | 255 | } |
276 | return GNUNET_OK; | 256 | return GNUNET_OK; |
277 | } | 257 | } |
@@ -281,7 +261,7 @@ process (void *cls, | |||
281 | * Handle a reply (route to origin). Only forwards the reply back to | 261 | * Handle a reply (route to origin). Only forwards the reply back to |
282 | * other peers waiting for it. Does not do local caching or | 262 | * other peers waiting for it. Does not do local caching or |
283 | * forwarding to local clients. Essentially calls | 263 | * forwarding to local clients. Essentially calls |
284 | * GDS_NEIGHBOURS_handle_reply for all peers that sent us a matching | 264 | * GDS_NEIGHBOURS_handle_reply() for all peers that sent us a matching |
285 | * request recently. | 265 | * request recently. |
286 | * | 266 | * |
287 | * @param type type of the block | 267 | * @param type type of the block |
@@ -315,16 +295,6 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, | |||
315 | pc.get_path = get_path; | 295 | pc.get_path = get_path; |
316 | pc.data = data; | 296 | pc.data = data; |
317 | pc.data_size = data_size; | 297 | pc.data_size = data_size; |
318 | if (NULL == data) | ||
319 | { | ||
320 | /* Some apps might have an 'empty' reply as a valid reply; however, | ||
321 | 'process' will call GNUNET_BLOCK_evaluate' which treats a 'NULL' | ||
322 | reply as request-validation (but we need response-validation). | ||
323 | So we set 'data' to a 0-byte non-NULL value just to be sure */ | ||
324 | GNUNET_break (0 == data_size); | ||
325 | pc.data_size = 0; | ||
326 | pc.data = ""; /* something not null */ | ||
327 | } | ||
328 | GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, | 298 | GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, |
329 | key, | 299 | key, |
330 | &process, | 300 | &process, |
@@ -338,13 +308,13 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, | |||
338 | * in the heap and hashmap. | 308 | * in the heap and hashmap. |
339 | */ | 309 | */ |
340 | static void | 310 | static void |
341 | expire_oldest_entry () | 311 | expire_oldest_entry (void) |
342 | { | 312 | { |
343 | struct RecentRequest *recent_req; | 313 | struct RecentRequest *recent_req; |
344 | 314 | ||
345 | GNUNET_STATISTICS_update (GDS_stats, | 315 | GNUNET_STATISTICS_update (GDS_stats, |
346 | gettext_noop | 316 | "# Entries removed from routing table", |
347 | ("# Entries removed from routing table"), 1, | 317 | 1, |
348 | GNUNET_NO); | 318 | GNUNET_NO); |
349 | recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); | 319 | recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); |
350 | GNUNET_assert (recent_req != NULL); | 320 | GNUNET_assert (recent_req != NULL); |
@@ -362,13 +332,13 @@ expire_oldest_entry () | |||
362 | * Try to combine multiple recent requests for the same value | 332 | * Try to combine multiple recent requests for the same value |
363 | * (if they come from the same peer). | 333 | * (if they come from the same peer). |
364 | * | 334 | * |
365 | * @param cls the new 'struct RecentRequest' (to discard upon successful combination) | 335 | * @param cls the new `struct RecentRequest` (to discard upon successful combination) |
366 | * @param key the query | 336 | * @param key the query |
367 | * @param value the existing 'struct RecentRequest' (to update upon successful combination) | 337 | * @param value the existing 'struct RecentRequest' (to update upon successful combination) |
368 | * @return #GNUNET_OK (continue to iterate), | 338 | * @return #GNUNET_OK (continue to iterate), |
369 | * #GNUNET_SYSERR if the request was successfully combined | 339 | * #GNUNET_SYSERR if the request was successfully combined |
370 | */ | 340 | */ |
371 | static int | 341 | static enum GNUNET_GenericReturnValue |
372 | try_combine_recent (void *cls, | 342 | try_combine_recent (void *cls, |
373 | const struct GNUNET_HashCode *key, | 343 | const struct GNUNET_HashCode *key, |
374 | void *value) | 344 | void *value) |
@@ -419,7 +389,7 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, | |||
419 | while (GNUNET_CONTAINER_heap_get_size (recent_heap) >= DHT_MAX_RECENT) | 389 | while (GNUNET_CONTAINER_heap_get_size (recent_heap) >= DHT_MAX_RECENT) |
420 | expire_oldest_entry (); | 390 | expire_oldest_entry (); |
421 | GNUNET_STATISTICS_update (GDS_stats, | 391 | GNUNET_STATISTICS_update (GDS_stats, |
422 | gettext_noop ("# Entries added to routing table"), | 392 | "# Entries added to routing table", |
423 | 1, | 393 | 1, |
424 | GNUNET_NO); | 394 | GNUNET_NO); |
425 | recent_req = GNUNET_malloc (sizeof(struct RecentRequest) + xquery_size); | 395 | recent_req = GNUNET_malloc (sizeof(struct RecentRequest) + xquery_size); |