diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-08-20 15:35:45 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-08-20 15:35:45 +0000 |
commit | 004afd8bc5dbd6ff57c94f08b73213ec65e719fd (patch) | |
tree | 3fa974b7ef1c34556b036f2d2df19bc3670d3353 /src/dht/gnunet-service-dht.c | |
parent | 4981e720cb71b9bf5e51dd90b5a9abacf21665ca (diff) | |
download | gnunet-004afd8bc5dbd6ff57c94f08b73213ec65e719fd.tar.gz gnunet-004afd8bc5dbd6ff57c94f08b73213ec65e719fd.zip |
minor dht alterations
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r-- | src/dht/gnunet-service-dht.c | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 73ac9b97a..98e02d2a0 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -1934,10 +1934,12 @@ handle_dht_find_peer (void *cls, | |||
1934 | struct DHT_MessageContext *message_context) | 1934 | struct DHT_MessageContext *message_context) |
1935 | { | 1935 | { |
1936 | struct GNUNET_MessageHeader *find_peer_result; | 1936 | struct GNUNET_MessageHeader *find_peer_result; |
1937 | struct GNUNET_DHT_FindPeerMessage *find_peer_message; | ||
1937 | struct DHT_MessageContext *new_msg_ctx; | 1938 | struct DHT_MessageContext *new_msg_ctx; |
1939 | struct GNUNET_CONTAINER_BloomFilter *incoming_bloom; | ||
1938 | size_t hello_size; | 1940 | size_t hello_size; |
1939 | size_t tsize; | 1941 | size_t tsize; |
1940 | 1942 | find_peer_message = (struct GNUNET_DHT_FindPeerMessage *)find_msg; | |
1941 | #if DEBUG_DHT | 1943 | #if DEBUG_DHT |
1942 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1944 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1943 | "`%s:%s': Received `%s' request from client, key %s (msg size %d, we expected %d)\n", | 1945 | "`%s:%s': Received `%s' request from client, key %s (msg size %d, we expected %d)\n", |
@@ -1955,9 +1957,14 @@ handle_dht_find_peer (void *cls, | |||
1955 | return; | 1957 | return; |
1956 | } | 1958 | } |
1957 | 1959 | ||
1958 | 1960 | incoming_bloom = GNUNET_CONTAINER_bloomfilter_init(find_peer_message->bloomfilter, DHT_BLOOM_SIZE, DHT_BLOOM_K); | |
1959 | if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test(message_context->bloom, &my_identity.hashPubKey)) | 1961 | if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test(incoming_bloom, &my_identity.hashPubKey)) |
1960 | return; /* We match the bloomfilter, do not send a response to this peer (they likely already know us!)*/ | 1962 | { |
1963 | increment_stats(STAT_BLOOM_FIND_PEER); | ||
1964 | GNUNET_CONTAINER_bloomfilter_free(incoming_bloom); | ||
1965 | return; /* We match the bloomfilter, do not send a response to this peer (they likely already know us!)*/ | ||
1966 | } | ||
1967 | GNUNET_CONTAINER_bloomfilter_free(incoming_bloom); | ||
1961 | 1968 | ||
1962 | /* Simplistic find_peer functionality, always return our hello */ | 1969 | /* Simplistic find_peer functionality, always return our hello */ |
1963 | hello_size = ntohs(my_hello->size); | 1970 | hello_size = ntohs(my_hello->size); |
@@ -1996,7 +2003,6 @@ handle_dht_find_peer (void *cls, | |||
1996 | message_context->key); | 2003 | message_context->key); |
1997 | } | 2004 | } |
1998 | #endif | 2005 | #endif |
1999 | //send_reply_to_client(message_context->client, find_peer_result, message_context->unique_id); | ||
2000 | GNUNET_free(find_peer_result); | 2006 | GNUNET_free(find_peer_result); |
2001 | } | 2007 | } |
2002 | 2008 | ||
@@ -2269,8 +2275,7 @@ select_peer (const GNUNET_HashCode * target, | |||
2269 | count = 0; | 2275 | count = 0; |
2270 | while ((pos != NULL) && (count < bucket_size)) | 2276 | while ((pos != NULL) && (count < bucket_size)) |
2271 | { | 2277 | { |
2272 | /* If we are doing strict Kademlia like routing, then checking the bloomfilter is basically cheating! */ | 2278 | /* If we are doing strict Kademlia like routing, then checking the bloomfilter is basically cheating! */ |
2273 | |||
2274 | if (GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) | 2279 | if (GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) |
2275 | { | 2280 | { |
2276 | distance = inverse_distance (target, &pos->id.hashPubKey); | 2281 | distance = inverse_distance (target, &pos->id.hashPubKey); |
@@ -2462,7 +2467,9 @@ static int cache_response(void *cls, struct DHT_MessageContext *msg_ctx) | |||
2462 | * Main function that handles whether or not to route a message to other | 2467 | * Main function that handles whether or not to route a message to other |
2463 | * peers. | 2468 | * peers. |
2464 | * | 2469 | * |
2470 | * @param cls closure for dht service (NULL) | ||
2465 | * @param msg the message to be routed | 2471 | * @param msg the message to be routed |
2472 | * @param message_context the context containing all pertinent information about the message | ||
2466 | * | 2473 | * |
2467 | * @return the number of peers the message was routed to, | 2474 | * @return the number of peers the message was routed to, |
2468 | * GNUNET_SYSERR on failure | 2475 | * GNUNET_SYSERR on failure |
@@ -2505,7 +2512,6 @@ static int route_message(void *cls, | |||
2505 | 2512 | ||
2506 | if (message_context->bloom == NULL) | 2513 | if (message_context->bloom == NULL) |
2507 | message_context->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); | 2514 | message_context->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); |
2508 | GNUNET_CONTAINER_bloomfilter_add (message_context->bloom, &my_identity.hashPubKey); | ||
2509 | 2515 | ||
2510 | if ((stop_on_closest == GNUNET_YES) && (message_context->closest == GNUNET_YES) && (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)) | 2516 | if ((stop_on_closest == GNUNET_YES) && (message_context->closest == GNUNET_YES) && (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)) |
2511 | /* || ((strict_kademlia == GNUNET_YES) && (message_context->closest == GNUNET_YES))) */ | 2517 | /* || ((strict_kademlia == GNUNET_YES) && (message_context->closest == GNUNET_YES))) */ |
@@ -2562,6 +2568,8 @@ static int route_message(void *cls, | |||
2562 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2568 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2563 | "`%s': Message type (%d) not handled\n", "DHT", ntohs(msg->type)); | 2569 | "`%s': Message type (%d) not handled\n", "DHT", ntohs(msg->type)); |
2564 | } | 2570 | } |
2571 | |||
2572 | GNUNET_CONTAINER_bloomfilter_add (message_context->bloom, &my_identity.hashPubKey); | ||
2565 | #if 0 | 2573 | #if 0 |
2566 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(recent->hashmap, message_context->key)) | 2574 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(recent->hashmap, message_context->key)) |
2567 | { | 2575 | { |
@@ -2589,6 +2597,7 @@ static int route_message(void *cls, | |||
2589 | remove_oldest_recent(); | 2597 | remove_oldest_recent(); |
2590 | } | 2598 | } |
2591 | #endif | 2599 | #endif |
2600 | |||
2592 | for (i = 0; i < forward_count; i++) | 2601 | for (i = 0; i < forward_count; i++) |
2593 | { | 2602 | { |
2594 | selected = select_peer(message_context->key, message_context->bloom); | 2603 | selected = select_peer(message_context->key, message_context->bloom); |
@@ -2783,19 +2792,23 @@ add_known_to_bloom (void *cls, | |||
2783 | static void | 2792 | static void |
2784 | send_find_peer_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 2793 | send_find_peer_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2785 | { | 2794 | { |
2786 | struct GNUNET_MessageHeader *find_peer_msg; | 2795 | struct GNUNET_DHT_FindPeerMessage *find_peer_msg; |
2787 | struct DHT_MessageContext message_context; | 2796 | struct DHT_MessageContext message_context; |
2788 | int ret; | 2797 | int ret; |
2789 | struct GNUNET_TIME_Relative next_send_time; | 2798 | struct GNUNET_TIME_Relative next_send_time; |
2799 | struct GNUNET_CONTAINER_BloomFilter *temp_bloom; | ||
2790 | 2800 | ||
2791 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 2801 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
2792 | return; | 2802 | return; |
2793 | 2803 | ||
2794 | increment_stats(STAT_FIND_PEER_START); | 2804 | increment_stats(STAT_FIND_PEER_START); |
2795 | 2805 | ||
2796 | find_peer_msg = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader)); | 2806 | find_peer_msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_FindPeerMessage)); |
2797 | find_peer_msg->size = htons(sizeof(struct GNUNET_MessageHeader)); | 2807 | find_peer_msg->header.size = htons(sizeof(struct GNUNET_DHT_FindPeerMessage)); |
2798 | find_peer_msg->type = htons(GNUNET_MESSAGE_TYPE_DHT_FIND_PEER); | 2808 | find_peer_msg->header.type = htons(GNUNET_MESSAGE_TYPE_DHT_FIND_PEER); |
2809 | temp_bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); | ||
2810 | GNUNET_CONTAINER_multihashmap_iterate(all_known_peers, &add_known_to_bloom, temp_bloom); | ||
2811 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_bloomfilter_get_raw_data(temp_bloom, find_peer_msg->bloomfilter, DHT_BLOOM_SIZE)); | ||
2799 | memset(&message_context, 0, sizeof(struct DHT_MessageContext)); | 2812 | memset(&message_context, 0, sizeof(struct DHT_MessageContext)); |
2800 | message_context.key = &my_identity.hashPubKey; | 2813 | message_context.key = &my_identity.hashPubKey; |
2801 | message_context.unique_id = GNUNET_ntohll (GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, (uint64_t)-1)); | 2814 | message_context.unique_id = GNUNET_ntohll (GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, (uint64_t)-1)); |
@@ -2806,11 +2819,7 @@ send_find_peer_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
2806 | message_context.importance = DHT_DEFAULT_FIND_PEER_IMPORTANCE; | 2819 | message_context.importance = DHT_DEFAULT_FIND_PEER_IMPORTANCE; |
2807 | message_context.timeout = DHT_DEFAULT_FIND_PEER_TIMEOUT; | 2820 | message_context.timeout = DHT_DEFAULT_FIND_PEER_TIMEOUT; |
2808 | 2821 | ||
2809 | message_context.bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); | 2822 | ret = route_message(NULL, &find_peer_msg->header, &message_context); |
2810 | GNUNET_CONTAINER_multihashmap_iterate(all_known_peers, &add_known_to_bloom, message_context.bloom); | ||
2811 | /*GNUNET_CONTAINER_bloomfilter_add (message_context->bloom, &my_identity.hashPubKey);*/ | ||
2812 | |||
2813 | ret = route_message(NULL, find_peer_msg, &message_context); | ||
2814 | GNUNET_free(find_peer_msg); | 2823 | GNUNET_free(find_peer_msg); |
2815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2824 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2816 | "`%s:%s': Sent `%s' request to %d peers\n", my_short_id, "DHT", | 2825 | "`%s:%s': Sent `%s' request to %d peers\n", my_short_id, "DHT", |
@@ -3021,7 +3030,6 @@ handle_dht_p2p_route_request (void *cls, | |||
3021 | GNUNET_break_op(0); | 3030 | GNUNET_break_op(0); |
3022 | return GNUNET_YES; | 3031 | return GNUNET_YES; |
3023 | } | 3032 | } |
3024 | //memset(&message_context, 0, sizeof(struct DHT_MessageContext)); | ||
3025 | message_context = GNUNET_malloc(sizeof (struct DHT_MessageContext)); | 3033 | message_context = GNUNET_malloc(sizeof (struct DHT_MessageContext)); |
3026 | message_context->bloom = GNUNET_CONTAINER_bloomfilter_init(incoming->bloomfilter, DHT_BLOOM_SIZE, DHT_BLOOM_K); | 3034 | message_context->bloom = GNUNET_CONTAINER_bloomfilter_init(incoming->bloomfilter, DHT_BLOOM_SIZE, DHT_BLOOM_K); |
3027 | GNUNET_assert(message_context->bloom != NULL); | 3035 | GNUNET_assert(message_context->bloom != NULL); |
@@ -3418,6 +3426,7 @@ run (void *cls, | |||
3418 | { | 3426 | { |
3419 | GNUNET_STATISTICS_set(stats, STAT_ROUTES, 0, GNUNET_NO); | 3427 | GNUNET_STATISTICS_set(stats, STAT_ROUTES, 0, GNUNET_NO); |
3420 | GNUNET_STATISTICS_set(stats, STAT_ROUTE_FORWARDS, 0, GNUNET_NO); | 3428 | GNUNET_STATISTICS_set(stats, STAT_ROUTE_FORWARDS, 0, GNUNET_NO); |
3429 | GNUNET_STATISTICS_set(stats, STAT_ROUTE_FORWARDS_CLOSEST, 0, GNUNET_NO); | ||
3421 | GNUNET_STATISTICS_set(stats, STAT_RESULTS, 0, GNUNET_NO); | 3430 | GNUNET_STATISTICS_set(stats, STAT_RESULTS, 0, GNUNET_NO); |
3422 | GNUNET_STATISTICS_set(stats, STAT_RESULTS_TO_CLIENT, 0, GNUNET_NO); | 3431 | GNUNET_STATISTICS_set(stats, STAT_RESULTS_TO_CLIENT, 0, GNUNET_NO); |
3423 | GNUNET_STATISTICS_set(stats, STAT_RESULT_FORWARDS, 0, GNUNET_NO); | 3432 | GNUNET_STATISTICS_set(stats, STAT_RESULT_FORWARDS, 0, GNUNET_NO); |
@@ -3430,8 +3439,11 @@ run (void *cls, | |||
3430 | GNUNET_STATISTICS_set(stats, STAT_PUT_START, 0, GNUNET_NO); | 3439 | GNUNET_STATISTICS_set(stats, STAT_PUT_START, 0, GNUNET_NO); |
3431 | GNUNET_STATISTICS_set(stats, STAT_FIND_PEER_REPLY, 0, GNUNET_NO); | 3440 | GNUNET_STATISTICS_set(stats, STAT_FIND_PEER_REPLY, 0, GNUNET_NO); |
3432 | GNUNET_STATISTICS_set(stats, STAT_FIND_PEER_ANSWER, 0, GNUNET_NO); | 3441 | GNUNET_STATISTICS_set(stats, STAT_FIND_PEER_ANSWER, 0, GNUNET_NO); |
3442 | GNUNET_STATISTICS_set(stats, STAT_BLOOM_FIND_PEER, 0, GNUNET_NO); | ||
3433 | GNUNET_STATISTICS_set(stats, STAT_GET_REPLY, 0, GNUNET_NO); | 3443 | GNUNET_STATISTICS_set(stats, STAT_GET_REPLY, 0, GNUNET_NO); |
3434 | GNUNET_STATISTICS_set(stats, STAT_GET_RESPONSE_START, 0, GNUNET_NO); | 3444 | GNUNET_STATISTICS_set(stats, STAT_GET_RESPONSE_START, 0, GNUNET_NO); |
3445 | GNUNET_STATISTICS_set(stats, STAT_HELLOS_PROVIDED, 0, GNUNET_NO); | ||
3446 | GNUNET_STATISTICS_set(stats, STAT_DISCONNECTS, 0, GNUNET_NO); | ||
3435 | } | 3447 | } |
3436 | #if DO_FIND_PEER | 3448 | #if DO_FIND_PEER |
3437 | next_send_time.value = DHT_MINIMUM_FIND_PEER_INTERVAL.value + | 3449 | next_send_time.value = DHT_MINIMUM_FIND_PEER_INTERVAL.value + |