diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-10-05 14:16:45 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-10-05 14:16:45 +0000 |
commit | b3cdbf13244b4c1b3ac84464209dedb4d3ee59c7 (patch) | |
tree | 68e79980fcd3240558897fc09ded6eec6cac6582 /src | |
parent | 0f8fe7f9eedfe9f70333b9bc7105cbc096af5f05 (diff) | |
download | gnunet-b3cdbf13244b4c1b3ac84464209dedb4d3ee59c7.tar.gz gnunet-b3cdbf13244b4c1b3ac84464209dedb4d3ee59c7.zip |
fix
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/dht.h | 2 | ||||
-rw-r--r-- | src/dht/dht_api.c | 2 | ||||
-rw-r--r-- | src/dht/gnunet-dht-driver.c | 17 | ||||
-rw-r--r-- | src/dht/gnunet-dht-get.c | 4 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht.c | 204 |
5 files changed, 134 insertions, 95 deletions
diff --git a/src/dht/dht.h b/src/dht/dht.h index 9c2e889a7..0f9d28fe4 100644 --- a/src/dht/dht.h +++ b/src/dht/dht.h | |||
@@ -447,7 +447,7 @@ struct GNUNET_DHT_FindPeerMessage | |||
447 | */ | 447 | */ |
448 | struct GNUNET_MessageHeader header; | 448 | struct GNUNET_MessageHeader header; |
449 | 449 | ||
450 | /* | 450 | /** |
451 | * Bloomfilter to reduce find peer responses | 451 | * Bloomfilter to reduce find peer responses |
452 | */ | 452 | */ |
453 | char bloomfilter[DHT_BLOOM_SIZE]; | 453 | char bloomfilter[DHT_BLOOM_SIZE]; |
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 62078b5cf..d7c05684c 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -137,7 +137,7 @@ struct GNUNET_DHT_RouteHandle | |||
137 | GNUNET_HashCode key; | 137 | GNUNET_HashCode key; |
138 | 138 | ||
139 | /** | 139 | /** |
140 | * Unique identifier for this request (for key collisions) | 140 | * Unique identifier for this request (for key collisions). FIXME: redundant!? |
141 | */ | 141 | */ |
142 | uint64_t uid; | 142 | uint64_t uid; |
143 | 143 | ||
diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c index 0238c6416..81ca94f17 100644 --- a/src/dht/gnunet-dht-driver.c +++ b/src/dht/gnunet-dht-driver.c | |||
@@ -1644,14 +1644,15 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
1644 | * @param size number of bytes in data | 1644 | * @param size number of bytes in data |
1645 | * @param data pointer to the result data | 1645 | * @param data pointer to the result data |
1646 | */ | 1646 | */ |
1647 | void get_result_iterator (void *cls, | 1647 | static void |
1648 | struct GNUNET_TIME_Absolute exp, | 1648 | get_result_iterator (void *cls, |
1649 | const GNUNET_HashCode * key, | 1649 | struct GNUNET_TIME_Absolute exp, |
1650 | const struct GNUNET_PeerIdentity * const *get_path, | 1650 | const GNUNET_HashCode * key, |
1651 | const struct GNUNET_PeerIdentity * const *put_path, | 1651 | const struct GNUNET_PeerIdentity * const *get_path, |
1652 | enum GNUNET_BLOCK_Type type, | 1652 | const struct GNUNET_PeerIdentity * const *put_path, |
1653 | uint32_t size, | 1653 | enum GNUNET_BLOCK_Type type, |
1654 | const void *data) | 1654 | size_t size, |
1655 | const void *data) | ||
1655 | { | 1656 | { |
1656 | struct TestGetContext *test_get = cls; | 1657 | struct TestGetContext *test_get = cls; |
1657 | 1658 | ||
diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c index fabe4aeb9..55d606716 100644 --- a/src/dht/gnunet-dht-get.c +++ b/src/dht/gnunet-dht-get.c | |||
@@ -130,7 +130,9 @@ get_result_iterator (void *cls, | |||
130 | size_t size, | 130 | size_t size, |
131 | const void *data) | 131 | const void *data) |
132 | { | 132 | { |
133 | fprintf (stdout, "Result %d, type %d:\n%.*s\n", result_count, type, size, | 133 | fprintf (stdout, "Result %d, type %d:\n%.*s\n", |
134 | result_count, type, | ||
135 | (unsigned int) size, | ||
134 | (char *) data); | 136 | (char *) data); |
135 | result_count++; | 137 | result_count++; |
136 | } | 138 | } |
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index e8f45feb3..577519268 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -414,11 +414,21 @@ struct DHT_MessageContext | |||
414 | const struct GNUNET_PeerIdentity *peer; | 414 | const struct GNUNET_PeerIdentity *peer; |
415 | 415 | ||
416 | /** | 416 | /** |
417 | * Bloomfilter for this routing request. | ||
418 | */ | ||
419 | struct GNUNET_CONTAINER_BloomFilter *bloom; | ||
420 | |||
421 | /** | ||
417 | * The key this request was about | 422 | * The key this request was about |
418 | */ | 423 | */ |
419 | GNUNET_HashCode key; | 424 | GNUNET_HashCode key; |
420 | 425 | ||
421 | /** | 426 | /** |
427 | * How long should we wait to transmit this request? | ||
428 | */ | ||
429 | struct GNUNET_TIME_Relative timeout; | ||
430 | |||
431 | /** | ||
422 | * The unique identifier of this request | 432 | * The unique identifier of this request |
423 | */ | 433 | */ |
424 | uint64_t unique_id; | 434 | uint64_t unique_id; |
@@ -451,16 +461,6 @@ struct DHT_MessageContext | |||
451 | unsigned int importance; | 461 | unsigned int importance; |
452 | 462 | ||
453 | /** | 463 | /** |
454 | * How long should we wait to transmit this request? | ||
455 | */ | ||
456 | struct GNUNET_TIME_Relative timeout; | ||
457 | |||
458 | /** | ||
459 | * Bloomfilter for this routing request. | ||
460 | */ | ||
461 | struct GNUNET_CONTAINER_BloomFilter *bloom; | ||
462 | |||
463 | /** | ||
464 | * Did we forward this message? (may need to remember it!) | 464 | * Did we forward this message? (may need to remember it!) |
465 | */ | 465 | */ |
466 | int forwarded; | 466 | int forwarded; |
@@ -1633,13 +1633,11 @@ find_closest_peer (const GNUNET_HashCode *hc) | |||
1633 | * Called both for locally initiated requests and those | 1633 | * Called both for locally initiated requests and those |
1634 | * received from other peers. | 1634 | * received from other peers. |
1635 | * | 1635 | * |
1636 | * @param cls DHT service closure argument (unused) | ||
1637 | * @param msg the encapsulated message | 1636 | * @param msg the encapsulated message |
1638 | * @param peer the peer to forward the message to | 1637 | * @param peer the peer to forward the message to |
1639 | * @param msg_ctx the context of the message (hop count, bloom, etc.) | 1638 | * @param msg_ctx the context of the message (hop count, bloom, etc.) |
1640 | */ | 1639 | */ |
1641 | static void forward_message (void *cls, | 1640 | static void forward_message (const struct GNUNET_MessageHeader *msg, |
1642 | const struct GNUNET_MessageHeader *msg, | ||
1643 | struct PeerInfo *peer, | 1641 | struct PeerInfo *peer, |
1644 | struct DHT_MessageContext *msg_ctx) | 1642 | struct DHT_MessageContext *msg_ctx) |
1645 | { | 1643 | { |
@@ -1705,7 +1703,7 @@ periodic_ping_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1705 | #if DEBUG_PING | 1703 | #if DEBUG_PING |
1706 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Sending periodic ping to %s\n", my_short_id, "DHT", GNUNET_i2s(&peer->id)); | 1704 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Sending periodic ping to %s\n", my_short_id, "DHT", GNUNET_i2s(&peer->id)); |
1707 | #endif | 1705 | #endif |
1708 | forward_message(NULL, &ping_message, peer, &message_context); | 1706 | forward_message(&ping_message, peer, &message_context); |
1709 | peer->ping_task = GNUNET_SCHEDULER_add_delayed(sched, DHT_DEFAULT_PING_DELAY, &periodic_ping_task, peer); | 1707 | peer->ping_task = GNUNET_SCHEDULER_add_delayed(sched, DHT_DEFAULT_PING_DELAY, &periodic_ping_task, peer); |
1710 | } | 1708 | } |
1711 | 1709 | ||
@@ -2156,6 +2154,18 @@ datacache_get_iterator (void *cls, | |||
2156 | 2154 | ||
2157 | 2155 | ||
2158 | /** | 2156 | /** |
2157 | * Main function that handles whether or not to route a message to other | ||
2158 | * peers. | ||
2159 | * | ||
2160 | * @param msg the message to be routed | ||
2161 | * @param message_context the context containing all pertinent information about the message | ||
2162 | */ | ||
2163 | static void | ||
2164 | route_message2(const struct GNUNET_MessageHeader *msg, | ||
2165 | struct DHT_MessageContext *message_context); | ||
2166 | |||
2167 | |||
2168 | /** | ||
2159 | * Server handler for all dht get requests, look for data, | 2169 | * Server handler for all dht get requests, look for data, |
2160 | * if found, send response either to clients or other peers. | 2170 | * if found, send response either to clients or other peers. |
2161 | * | 2171 | * |
@@ -2279,6 +2289,7 @@ handle_dht_get (void *cls, | |||
2279 | } | 2289 | } |
2280 | #endif | 2290 | #endif |
2281 | } | 2291 | } |
2292 | route_message2 (msg, message_context); | ||
2282 | GNUNET_CONTAINER_bloomfilter_free (bf); | 2293 | GNUNET_CONTAINER_bloomfilter_free (bf); |
2283 | return results; | 2294 | return results; |
2284 | } | 2295 | } |
@@ -2287,10 +2298,9 @@ static void | |||
2287 | remove_recent_find_peer(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 2298 | remove_recent_find_peer(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2288 | { | 2299 | { |
2289 | GNUNET_HashCode *key = cls; | 2300 | GNUNET_HashCode *key = cls; |
2290 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(recent_find_peer_requests, key, key)) | 2301 | |
2291 | { | 2302 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(recent_find_peer_requests, key, key)); |
2292 | GNUNET_free(key); | 2303 | GNUNET_free (key); |
2293 | } | ||
2294 | } | 2304 | } |
2295 | 2305 | ||
2296 | /** | 2306 | /** |
@@ -2340,10 +2350,14 @@ handle_dht_find_peer (void *cls, | |||
2340 | increment_stats(STAT_HELLOS_PROVIDED); | 2350 | increment_stats(STAT_HELLOS_PROVIDED); |
2341 | GNUNET_TRANSPORT_offer_hello(transport_handle, other_hello); | 2351 | GNUNET_TRANSPORT_offer_hello(transport_handle, other_hello); |
2342 | GNUNET_CORE_peer_request_connect(sched, cfg, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), &peer_id, NULL, NULL); | 2352 | GNUNET_CORE_peer_request_connect(sched, cfg, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), &peer_id, NULL, NULL); |
2353 | route_message2 (find_msg, message_context); | ||
2343 | return; | 2354 | return; |
2344 | } | 2355 | } |
2345 | else /* We don't want this peer! */ | 2356 | else /* We don't want this peer! */ |
2346 | return; | 2357 | { |
2358 | route_message2 (find_msg, message_context); | ||
2359 | return; | ||
2360 | } | ||
2347 | #endif | 2361 | #endif |
2348 | } | 2362 | } |
2349 | 2363 | ||
@@ -2361,7 +2375,8 @@ handle_dht_find_peer (void *cls, | |||
2361 | "`%s': Our HELLO is null, can't return.\n", | 2375 | "`%s': Our HELLO is null, can't return.\n", |
2362 | "DHT"); | 2376 | "DHT"); |
2363 | #endif | 2377 | #endif |
2364 | GNUNET_free_non_null(other_hello); | 2378 | GNUNET_free_non_null (other_hello); |
2379 | route_message2 (find_msg, message_context); | ||
2365 | return; | 2380 | return; |
2366 | } | 2381 | } |
2367 | 2382 | ||
@@ -2371,6 +2386,7 @@ handle_dht_find_peer (void *cls, | |||
2371 | increment_stats(STAT_BLOOM_FIND_PEER); | 2386 | increment_stats(STAT_BLOOM_FIND_PEER); |
2372 | GNUNET_CONTAINER_bloomfilter_free(incoming_bloom); | 2387 | GNUNET_CONTAINER_bloomfilter_free(incoming_bloom); |
2373 | GNUNET_free_non_null(other_hello); | 2388 | GNUNET_free_non_null(other_hello); |
2389 | route_message2 (find_msg, message_context); | ||
2374 | return; /* We match the bloomfilter, do not send a response to this peer (they likely already know us!)*/ | 2390 | return; /* We match the bloomfilter, do not send a response to this peer (they likely already know us!)*/ |
2375 | } | 2391 | } |
2376 | GNUNET_CONTAINER_bloomfilter_free(incoming_bloom); | 2392 | GNUNET_CONTAINER_bloomfilter_free(incoming_bloom); |
@@ -2400,14 +2416,18 @@ handle_dht_find_peer (void *cls, | |||
2400 | { | 2416 | { |
2401 | increment_stats("# dht find peer requests ignored (do not need!)"); | 2417 | increment_stats("# dht find peer requests ignored (do not need!)"); |
2402 | GNUNET_free_non_null(other_hello); | 2418 | GNUNET_free_non_null(other_hello); |
2419 | route_message2 (find_msg, message_context); | ||
2403 | return; | 2420 | return; |
2404 | } | 2421 | } |
2405 | #endif | 2422 | #endif |
2406 | 2423 | ||
2407 | recent_hash = GNUNET_malloc(sizeof(GNUNET_HashCode)); | 2424 | recent_hash = GNUNET_malloc(sizeof(GNUNET_HashCode)); |
2408 | memcpy(recent_hash, &message_context->key, sizeof(GNUNET_HashCode)); | 2425 | memcpy(recent_hash, &message_context->key, sizeof(GNUNET_HashCode)); |
2409 | GNUNET_CONTAINER_multihashmap_put (recent_find_peer_requests, &message_context->key, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 2426 | GNUNET_CONTAINER_multihashmap_put (recent_find_peer_requests, |
2410 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), &remove_recent_find_peer, &recent_hash); | 2427 | &message_context->key, NULL, |
2428 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
2429 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), | ||
2430 | &remove_recent_find_peer, recent_hash); | ||
2411 | 2431 | ||
2412 | /* Simplistic find_peer functionality, always return our hello */ | 2432 | /* Simplistic find_peer functionality, always return our hello */ |
2413 | hello_size = ntohs(my_hello->size); | 2433 | hello_size = ntohs(my_hello->size); |
@@ -2449,6 +2469,7 @@ handle_dht_find_peer (void *cls, | |||
2449 | #endif | 2469 | #endif |
2450 | GNUNET_free_non_null(other_hello); | 2470 | GNUNET_free_non_null(other_hello); |
2451 | GNUNET_free(find_peer_result); | 2471 | GNUNET_free(find_peer_result); |
2472 | route_message2 (find_msg, message_context); | ||
2452 | } | 2473 | } |
2453 | 2474 | ||
2454 | /** | 2475 | /** |
@@ -2546,6 +2567,7 @@ handle_dht_put (void *cls, | |||
2546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2567 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2547 | "`%s:%s': %s request received, but have no datacache!\n", | 2568 | "`%s:%s': %s request received, but have no datacache!\n", |
2548 | my_short_id, "DHT", "PUT"); | 2569 | my_short_id, "DHT", "PUT"); |
2570 | route_message2 (msg, message_context); | ||
2549 | } | 2571 | } |
2550 | 2572 | ||
2551 | /** | 2573 | /** |
@@ -3300,19 +3322,14 @@ static int cache_response(void *cls, struct DHT_MessageContext *msg_ctx) | |||
3300 | * Main function that handles whether or not to route a message to other | 3322 | * Main function that handles whether or not to route a message to other |
3301 | * peers. | 3323 | * peers. |
3302 | * | 3324 | * |
3303 | * @param cls closure for dht service (NULL) | ||
3304 | * @param msg the message to be routed | 3325 | * @param msg the message to be routed |
3305 | * @param message_context the context containing all pertinent information about the message | 3326 | * @param message_context the context containing all pertinent information about the message |
3306 | * | ||
3307 | * @return the number of peers the message was routed to, | ||
3308 | * GNUNET_SYSERR on failure | ||
3309 | */ | 3327 | */ |
3310 | static int route_message(void *cls, | 3328 | static void |
3311 | const struct GNUNET_MessageHeader *msg, | 3329 | route_message2(const struct GNUNET_MessageHeader *msg, |
3312 | struct DHT_MessageContext *message_context) | 3330 | struct DHT_MessageContext *message_context) |
3313 | { | 3331 | { |
3314 | int i; | 3332 | int i; |
3315 | int global_closest; | ||
3316 | struct PeerInfo *selected; | 3333 | struct PeerInfo *selected; |
3317 | #if DEBUG_DHT_ROUTING > 1 | 3334 | #if DEBUG_DHT_ROUTING > 1 |
3318 | struct PeerInfo *nearest; | 3335 | struct PeerInfo *nearest; |
@@ -3339,15 +3356,13 @@ static int route_message(void *cls, | |||
3339 | #endif | 3356 | #endif |
3340 | if (message_context->bloom != NULL) | 3357 | if (message_context->bloom != NULL) |
3341 | GNUNET_CONTAINER_bloomfilter_free(message_context->bloom); | 3358 | GNUNET_CONTAINER_bloomfilter_free(message_context->bloom); |
3342 | return 0; | 3359 | return; |
3343 | } | 3360 | } |
3344 | 3361 | ||
3345 | increment_stats(STAT_ROUTES); | 3362 | increment_stats(STAT_ROUTES); |
3346 | /* Semantics of this call means we find whether we are the closest peer out of those already | 3363 | /* Semantics of this call means we find whether we are the closest peer out of those already |
3347 | * routed to on this messages path. | 3364 | * routed to on this messages path. |
3348 | */ | 3365 | */ |
3349 | global_closest = am_closest_peer(&message_context->key, NULL); | ||
3350 | message_context->closest = am_closest_peer(&message_context->key, message_context->bloom); | ||
3351 | forward_count = get_forward_count(message_context->hop_count, message_context->replication); | 3366 | forward_count = get_forward_count(message_context->hop_count, message_context->replication); |
3352 | GNUNET_asprintf(&stat_forward_count, "# forward counts of %d", forward_count); | 3367 | GNUNET_asprintf(&stat_forward_count, "# forward counts of %d", forward_count); |
3353 | increment_stats(stat_forward_count); | 3368 | increment_stats(stat_forward_count); |
@@ -3355,7 +3370,7 @@ static int route_message(void *cls, | |||
3355 | if (message_context->bloom == NULL) | 3370 | if (message_context->bloom == NULL) |
3356 | message_context->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); | 3371 | message_context->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); |
3357 | 3372 | ||
3358 | if ((stop_on_closest == GNUNET_YES) && (global_closest == GNUNET_YES) && (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)) | 3373 | if ((stop_on_closest == GNUNET_YES) && (message_context->closest == GNUNET_YES) && (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)) |
3359 | forward_count = 0; | 3374 | forward_count = 0; |
3360 | 3375 | ||
3361 | /** | 3376 | /** |
@@ -3373,7 +3388,7 @@ static int route_message(void *cls, | |||
3373 | * testing driver) we will ignore this restriction for FIND_PEER messages so that | 3388 | * testing driver) we will ignore this restriction for FIND_PEER messages so that |
3374 | * routing tables still get constructed. | 3389 | * routing tables still get constructed. |
3375 | */ | 3390 | */ |
3376 | if ((GNUNET_YES == strict_kademlia) && (global_closest == GNUNET_YES) && (message_context->hop_count > 0) && (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_DHT_FIND_PEER)) | 3391 | if ((GNUNET_YES == strict_kademlia) && (message_context->closest == GNUNET_YES) && (message_context->hop_count > 0) && (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_DHT_FIND_PEER)) |
3377 | forward_count = 0; | 3392 | forward_count = 0; |
3378 | 3393 | ||
3379 | #if DEBUG_DHT_ROUTING | 3394 | #if DEBUG_DHT_ROUTING |
@@ -3391,43 +3406,6 @@ static int route_message(void *cls, | |||
3391 | } | 3406 | } |
3392 | #endif | 3407 | #endif |
3393 | 3408 | ||
3394 | switch (ntohs(msg->type)) | ||
3395 | { | ||
3396 | case GNUNET_MESSAGE_TYPE_DHT_GET: /* Add to hashmap of requests seen, search for data (always) */ | ||
3397 | cache_response (cls, message_context); | ||
3398 | if ((handle_dht_get (cls, msg, message_context) > 0) && (stop_on_found == GNUNET_YES)) | ||
3399 | forward_count = 0; | ||
3400 | break; | ||
3401 | case GNUNET_MESSAGE_TYPE_DHT_PUT: /* Check if closest, if so insert data. FIXME: thresholding to reduce complexity?*/ | ||
3402 | increment_stats(STAT_PUTS); | ||
3403 | message_context->closest = global_closest; | ||
3404 | handle_dht_put (cls, msg, message_context); | ||
3405 | break; | ||
3406 | case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */ | ||
3407 | increment_stats(STAT_FIND_PEER); | ||
3408 | if (((message_context->hop_count > 0) && (0 != memcmp(message_context->peer, &my_identity, sizeof(struct GNUNET_PeerIdentity)))) || (message_context->client != NULL)) | ||
3409 | { | ||
3410 | cache_response (cls, message_context); | ||
3411 | if ((message_context->closest == GNUNET_YES) || (message_context->msg_options == GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) | ||
3412 | handle_dht_find_peer (cls, msg, message_context); | ||
3413 | } | ||
3414 | #if DEBUG_DHT_ROUTING | ||
3415 | if (message_context->hop_count == 0) /* Locally initiated request */ | ||
3416 | { | ||
3417 | if ((debug_routes) && (dhtlog_handle != NULL)) | ||
3418 | { | ||
3419 | dhtlog_handle->insert_dhtkey(NULL, &message_context->key); | ||
3420 | dhtlog_handle->insert_query (NULL, message_context->unique_id, DHTLOG_FIND_PEER, | ||
3421 | message_context->hop_count, GNUNET_NO, &my_identity, | ||
3422 | &message_context->key); | ||
3423 | } | ||
3424 | } | ||
3425 | #endif | ||
3426 | break; | ||
3427 | default: | ||
3428 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
3429 | "`%s': Message type (%d) not handled\n", "DHT", ntohs(msg->type)); | ||
3430 | } | ||
3431 | 3409 | ||
3432 | GNUNET_CONTAINER_bloomfilter_add (message_context->bloom, &my_identity.hashPubKey); | 3410 | GNUNET_CONTAINER_bloomfilter_add (message_context->bloom, &my_identity.hashPubKey); |
3433 | hash_from_uid (message_context->unique_id, &unique_hash); | 3411 | hash_from_uid (message_context->unique_id, &unique_hash); |
@@ -3495,7 +3473,7 @@ static int route_message(void *cls, | |||
3495 | &selected->id); | 3473 | &selected->id); |
3496 | } | 3474 | } |
3497 | #endif | 3475 | #endif |
3498 | forward_message(cls, msg, selected, message_context); | 3476 | forward_message(msg, selected, message_context); |
3499 | } | 3477 | } |
3500 | } | 3478 | } |
3501 | 3479 | ||
@@ -3504,10 +3482,65 @@ static int route_message(void *cls, | |||
3504 | GNUNET_CONTAINER_bloomfilter_or2(recent_req->bloom, message_context->bloom, DHT_BLOOM_SIZE); | 3482 | GNUNET_CONTAINER_bloomfilter_or2(recent_req->bloom, message_context->bloom, DHT_BLOOM_SIZE); |
3505 | GNUNET_CONTAINER_bloomfilter_free(message_context->bloom); | 3483 | GNUNET_CONTAINER_bloomfilter_free(message_context->bloom); |
3506 | } | 3484 | } |
3485 | } | ||
3486 | |||
3507 | 3487 | ||
3508 | return forward_count; | 3488 | |
3489 | /** | ||
3490 | * Main function that handles whether or not to route a message to other | ||
3491 | * peers. | ||
3492 | * | ||
3493 | * @param cls closure for dht service (NULL) | ||
3494 | * @param msg the message to be routed | ||
3495 | * @param message_context the context containing all pertinent information about the message | ||
3496 | */ | ||
3497 | static void | ||
3498 | route_message(void *cls, | ||
3499 | const struct GNUNET_MessageHeader *msg, | ||
3500 | struct DHT_MessageContext *message_context) | ||
3501 | { | ||
3502 | message_context->closest = am_closest_peer(&message_context->key, NULL); | ||
3503 | switch (ntohs(msg->type)) | ||
3504 | { | ||
3505 | case GNUNET_MESSAGE_TYPE_DHT_GET: /* Add to hashmap of requests seen, search for data (always) */ | ||
3506 | cache_response (cls, message_context); | ||
3507 | handle_dht_get (cls, msg, message_context); | ||
3508 | break; | ||
3509 | case GNUNET_MESSAGE_TYPE_DHT_PUT: /* Check if closest, if so insert data. FIXME: thresholding to reduce complexity?*/ | ||
3510 | increment_stats(STAT_PUTS); | ||
3511 | handle_dht_put (cls, msg, message_context); | ||
3512 | break; | ||
3513 | case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */ | ||
3514 | increment_stats(STAT_FIND_PEER); | ||
3515 | if (((message_context->hop_count > 0) && (0 != memcmp(message_context->peer, &my_identity, sizeof(struct GNUNET_PeerIdentity)))) || (message_context->client != NULL)) | ||
3516 | { | ||
3517 | cache_response (cls, message_context); | ||
3518 | if ((message_context->closest == GNUNET_YES) || (message_context->msg_options == GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) | ||
3519 | handle_dht_find_peer (cls, msg, message_context); | ||
3520 | } | ||
3521 | #if DEBUG_DHT_ROUTING | ||
3522 | if (message_context->hop_count == 0) /* Locally initiated request */ | ||
3523 | { | ||
3524 | if ((debug_routes) && (dhtlog_handle != NULL)) | ||
3525 | { | ||
3526 | dhtlog_handle->insert_dhtkey(NULL, &message_context->key); | ||
3527 | dhtlog_handle->insert_query (NULL, message_context->unique_id, DHTLOG_FIND_PEER, | ||
3528 | message_context->hop_count, GNUNET_NO, &my_identity, | ||
3529 | &message_context->key); | ||
3530 | } | ||
3531 | } | ||
3532 | #endif | ||
3533 | break; | ||
3534 | default: | ||
3535 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
3536 | "`%s': Message type (%d) not handled\n", "DHT", ntohs(msg->type)); | ||
3537 | route_message (cls, msg, message_context); | ||
3538 | } | ||
3509 | } | 3539 | } |
3510 | 3540 | ||
3541 | |||
3542 | |||
3543 | |||
3511 | /** | 3544 | /** |
3512 | * Iterator for local get request results, | 3545 | * Iterator for local get request results, |
3513 | * | 3546 | * |
@@ -3823,7 +3856,6 @@ send_find_peer_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
3823 | { | 3856 | { |
3824 | struct GNUNET_DHT_FindPeerMessage *find_peer_msg; | 3857 | struct GNUNET_DHT_FindPeerMessage *find_peer_msg; |
3825 | struct DHT_MessageContext message_context; | 3858 | struct DHT_MessageContext message_context; |
3826 | int ret; | ||
3827 | struct GNUNET_TIME_Relative next_send_time; | 3859 | struct GNUNET_TIME_Relative next_send_time; |
3828 | struct GNUNET_CONTAINER_BloomFilter *temp_bloom; | 3860 | struct GNUNET_CONTAINER_BloomFilter *temp_bloom; |
3829 | #if COUNT_INTERVAL | 3861 | #if COUNT_INTERVAL |
@@ -3884,11 +3916,11 @@ send_find_peer_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
3884 | message_context.importance = DHT_DEFAULT_FIND_PEER_IMPORTANCE; | 3916 | message_context.importance = DHT_DEFAULT_FIND_PEER_IMPORTANCE; |
3885 | message_context.timeout = DHT_DEFAULT_FIND_PEER_TIMEOUT; | 3917 | message_context.timeout = DHT_DEFAULT_FIND_PEER_TIMEOUT; |
3886 | 3918 | ||
3887 | ret = route_message(NULL, &find_peer_msg->header, &message_context); | 3919 | route_message(NULL, &find_peer_msg->header, &message_context); |
3888 | GNUNET_free(find_peer_msg); | 3920 | GNUNET_free(find_peer_msg); |
3889 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3921 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3890 | "`%s:%s': Sent `%s' request to %d peers\n", my_short_id, "DHT", | 3922 | "`%s:%s': Sent `%s' request to some (?) peers\n", my_short_id, "DHT", |
3891 | "FIND PEER", ret); | 3923 | "FIND PEER"); |
3892 | if (newly_found_peers < bucket_size) | 3924 | if (newly_found_peers < bucket_size) |
3893 | { | 3925 | { |
3894 | next_send_time.value = (DHT_MAXIMUM_FIND_PEER_INTERVAL.value / 2) + | 3926 | next_send_time.value = (DHT_MAXIMUM_FIND_PEER_INTERVAL.value / 2) + |
@@ -4651,10 +4683,14 @@ run (void *cls, | |||
4651 | int | 4683 | int |
4652 | main (int argc, char *const *argv) | 4684 | main (int argc, char *const *argv) |
4653 | { | 4685 | { |
4654 | return (GNUNET_OK == | 4686 | int ret; |
4655 | GNUNET_SERVICE_run (argc, | 4687 | |
4656 | argv, | 4688 | ret = (GNUNET_OK == |
4657 | "dht", | 4689 | GNUNET_SERVICE_run (argc, |
4658 | GNUNET_SERVICE_OPTION_NONE, | 4690 | argv, |
4659 | &run, NULL)) ? 0 : 1; | 4691 | "dht", |
4692 | GNUNET_SERVICE_OPTION_NONE, | ||
4693 | &run, NULL)) ? 0 : 1; | ||
4694 | GNUNET_CONTAINER_multihashmap_destroy (recent_find_peer_requests); | ||
4695 | return ret; | ||
4660 | } | 4696 | } |