diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-09-01 13:19:43 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-09-01 13:19:43 +0000 |
commit | 05186db103486d199c2dc9357264a265e9c33117 (patch) | |
tree | f0fba3bc564c59e9ef13de8fe44aa2181268c179 /src/dht/gnunet-service-dht.c | |
parent | c34548d2d6629269e689a9b2685df7e375a9c7a8 (diff) | |
download | gnunet-05186db103486d199c2dc9357264a265e9c33117.tar.gz gnunet-05186db103486d199c2dc9357264a265e9c33117.zip |
klocwork fixes, dht routing changes (hopefully fixes)
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r-- | src/dht/gnunet-service-dht.c | 68 |
1 files changed, 57 insertions, 11 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 958b1d8b2..f2379d72c 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -99,7 +99,7 @@ | |||
99 | /** | 99 | /** |
100 | * Default replication parameter for find peer messages sent by the dht service. | 100 | * Default replication parameter for find peer messages sent by the dht service. |
101 | */ | 101 | */ |
102 | #define DHT_DEFAULT_FIND_PEER_REPLICATION 1 | 102 | #define DHT_DEFAULT_FIND_PEER_REPLICATION 2 |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * Default options for find peer requests sent by the dht service. | 105 | * Default options for find peer requests sent by the dht service. |
@@ -153,7 +153,7 @@ | |||
153 | * Real maximum number of hops, at which point we refuse | 153 | * Real maximum number of hops, at which point we refuse |
154 | * to forward the message. | 154 | * to forward the message. |
155 | */ | 155 | */ |
156 | #define MAX_HOPS 20 | 156 | #define MAX_HOPS 10 |
157 | 157 | ||
158 | /** | 158 | /** |
159 | * How many time differences between requesting a core send and | 159 | * How many time differences between requesting a core send and |
@@ -198,7 +198,6 @@ struct P2PPendingMessage | |||
198 | 198 | ||
199 | }; | 199 | }; |
200 | 200 | ||
201 | |||
202 | /** | 201 | /** |
203 | * Per-peer information. | 202 | * Per-peer information. |
204 | */ | 203 | */ |
@@ -2119,7 +2118,10 @@ static void | |||
2119 | remove_recent_find_peer(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 2118 | remove_recent_find_peer(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2120 | { | 2119 | { |
2121 | GNUNET_HashCode *key = cls; | 2120 | GNUNET_HashCode *key = cls; |
2122 | GNUNET_CONTAINER_multihashmap_remove(recent_find_peer_requests, key, key); | 2121 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(recent_find_peer_requests, key, key)) |
2122 | { | ||
2123 | GNUNET_free(key); | ||
2124 | } | ||
2123 | } | 2125 | } |
2124 | 2126 | ||
2125 | /** | 2127 | /** |
@@ -2142,6 +2144,9 @@ handle_dht_find_peer (void *cls, | |||
2142 | size_t hello_size; | 2144 | size_t hello_size; |
2143 | size_t tsize; | 2145 | size_t tsize; |
2144 | GNUNET_HashCode *recent_hash; | 2146 | GNUNET_HashCode *recent_hash; |
2147 | #if RESTRICT_FIND_PEER | ||
2148 | struct GNUNET_PeerIdentity peer_id; | ||
2149 | #endif | ||
2145 | 2150 | ||
2146 | find_peer_message = (struct GNUNET_DHT_FindPeerMessage *)find_msg; | 2151 | find_peer_message = (struct GNUNET_DHT_FindPeerMessage *)find_msg; |
2147 | #if DEBUG_DHT | 2152 | #if DEBUG_DHT |
@@ -2175,10 +2180,28 @@ handle_dht_find_peer (void *cls, | |||
2175 | increment_stats("# dht find peer requests ignored (recently seen!)"); | 2180 | increment_stats("# dht find peer requests ignored (recently seen!)"); |
2176 | return; | 2181 | return; |
2177 | } | 2182 | } |
2183 | |||
2184 | #if RESTRICT_FIND_PEER | ||
2185 | /** | ||
2186 | * Use this check to only allow the peer to respond to find peer requests if | ||
2187 | * it would be beneficial to have the requesting peer in this peers routing | ||
2188 | * table. Can be used to thwart peers flooding the network with find peer | ||
2189 | * requests that we don't care about. However, if a new peer is joining | ||
2190 | * the network and has no other peers this is a problem (assume all buckets | ||
2191 | * full, no one will respond!). | ||
2192 | */ | ||
2193 | memcpy(&peer_id.hashPubKey, &message_context->key, sizeof(GNUNET_HashCode)); | ||
2194 | if (GNUNET_NO == consider_peer(&peer_id)) | ||
2195 | { | ||
2196 | increment_stats("# dht find peer requests ignored (do not need!)"); | ||
2197 | return; | ||
2198 | } | ||
2199 | #endif | ||
2200 | |||
2178 | recent_hash = GNUNET_malloc(sizeof(GNUNET_HashCode)); | 2201 | recent_hash = GNUNET_malloc(sizeof(GNUNET_HashCode)); |
2179 | memcpy(recent_hash, &message_context->key, sizeof(GNUNET_HashCode)); | 2202 | memcpy(recent_hash, &message_context->key, sizeof(GNUNET_HashCode)); |
2180 | GNUNET_CONTAINER_multihashmap_put (recent_find_peer_requests, &message_context->key, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 2203 | GNUNET_CONTAINER_multihashmap_put (recent_find_peer_requests, &message_context->key, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
2181 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), &remove_recent_find_peer, &message_context->key); | 2204 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120), &remove_recent_find_peer, &recent_hash); |
2182 | 2205 | ||
2183 | /* Simplistic find_peer functionality, always return our hello */ | 2206 | /* Simplistic find_peer functionality, always return our hello */ |
2184 | hello_size = ntohs(my_hello->size); | 2207 | hello_size = ntohs(my_hello->size); |
@@ -2325,7 +2348,12 @@ static unsigned int estimate_diameter() | |||
2325 | static unsigned int | 2348 | static unsigned int |
2326 | get_forward_count (unsigned int hop_count, size_t target_replication) | 2349 | get_forward_count (unsigned int hop_count, size_t target_replication) |
2327 | { | 2350 | { |
2351 | #if DOUBLE | ||
2328 | double target_count; | 2352 | double target_count; |
2353 | double random_probability; | ||
2354 | #else | ||
2355 | uint32_t random_value; | ||
2356 | #endif | ||
2329 | unsigned int target_value; | 2357 | unsigned int target_value; |
2330 | unsigned int diameter; | 2358 | unsigned int diameter; |
2331 | 2359 | ||
@@ -2366,17 +2394,35 @@ get_forward_count (unsigned int hop_count, size_t target_replication) | |||
2366 | #endif | 2394 | #endif |
2367 | return 0; | 2395 | return 0; |
2368 | } | 2396 | } |
2397 | |||
2398 | #if DOUBLE | ||
2399 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Replication %d, hop_count %u, diameter %u\n", target_replication, hop_count, diameter); | ||
2400 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Numerator %f, denominator %f\n", (double)target_replication, ((double)target_replication * (hop_count + 1) + diameter)); | ||
2369 | target_count = /* target_count is ALWAYS < 1 unless replication is < 1 */ | 2401 | target_count = /* target_count is ALWAYS < 1 unless replication is < 1 */ |
2370 | (double)target_replication / ((double)target_replication * (hop_count + 1) + diameter); | 2402 | (double)target_replication / ((double)target_replication * (hop_count + 1) + diameter); |
2403 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Target count is %f\n", target_count); | ||
2404 | random_probability = ((double)GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
2405 | RAND_MAX)) / RAND_MAX; | ||
2406 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Random is %f\n", random_probability); | ||
2371 | 2407 | ||
2372 | target_value = 0; | 2408 | target_value = 0; |
2373 | while (target_value < target_count) | 2409 | //while (target_value < target_count) |
2410 | if (target_value < target_count) | ||
2374 | target_value++; /* target_value is ALWAYS 1 after this "loop", right? Because target_count is always > 0, right? Or does it become 0.00000... at some point because the hop count is so high? */ | 2411 | target_value++; /* target_value is ALWAYS 1 after this "loop", right? Because target_count is always > 0, right? Or does it become 0.00000... at some point because the hop count is so high? */ |
2375 | 2412 | ||
2376 | if ((target_count + 1 - target_value) > | 2413 | |
2377 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 2414 | //if ((target_count + 1 - (double)target_value) > random_probability) |
2378 | RAND_MAX) / RAND_MAX) | 2415 | if ((target_count) > random_probability) |
2379 | target_value++; | 2416 | target_value++; |
2417 | #endif | ||
2418 | |||
2419 | random_value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, target_replication * (hop_count + 1) + diameter) + 1; | ||
2420 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "replication %u, at hop %d, will split with probability %f\n", target_replication, hop_count, target_replication / (double)((target_replication * (hop_count + 1) + diameter) + 1)); | ||
2421 | target_value = 1; | ||
2422 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "random %u, target %u, max %u\n", random_value, target_replication, target_replication * (hop_count + 1) + diameter); | ||
2423 | if (random_value < target_replication) | ||
2424 | target_value++; | ||
2425 | |||
2380 | return target_value; | 2426 | return target_value; |
2381 | } | 2427 | } |
2382 | 2428 | ||
@@ -2776,10 +2822,9 @@ static int route_message(void *cls, | |||
2776 | if (message_context->bloom == NULL) | 2822 | if (message_context->bloom == NULL) |
2777 | message_context->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); | 2823 | message_context->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); |
2778 | 2824 | ||
2779 | if ((stop_on_closest == GNUNET_YES) && (message_context->closest == GNUNET_YES) && (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)) | 2825 | if ((stop_on_closest == GNUNET_YES) && (global_closest == GNUNET_YES) && (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)) |
2780 | forward_count = 0; | 2826 | forward_count = 0; |
2781 | 2827 | ||
2782 | |||
2783 | #if DEBUG_DHT_ROUTING | 2828 | #if DEBUG_DHT_ROUTING |
2784 | if (forward_count == 0) | 2829 | if (forward_count == 0) |
2785 | ret = GNUNET_SYSERR; | 2830 | ret = GNUNET_SYSERR; |
@@ -2804,6 +2849,7 @@ static int route_message(void *cls, | |||
2804 | break; | 2849 | break; |
2805 | case GNUNET_MESSAGE_TYPE_DHT_PUT: /* Check if closest, if so insert data. FIXME: thresholding to reduce complexity?*/ | 2850 | case GNUNET_MESSAGE_TYPE_DHT_PUT: /* Check if closest, if so insert data. FIXME: thresholding to reduce complexity?*/ |
2806 | increment_stats(STAT_PUTS); | 2851 | increment_stats(STAT_PUTS); |
2852 | message_context->closest = global_closest; | ||
2807 | handle_dht_put (cls, msg, message_context); | 2853 | handle_dht_put (cls, msg, message_context); |
2808 | break; | 2854 | break; |
2809 | case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */ | 2855 | case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */ |