diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-09-02 15:06:42 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-09-02 15:06:42 +0000 |
commit | 017907f0af8c44ae86d20c241cb9662e0ac8be2b (patch) | |
tree | 348c3b94b59857231afec0eca852c39f1ebc3597 /src/dht/gnunet-service-dht.c | |
parent | b4de9504de19ea989bfe00b2047fa84be9c90cf3 (diff) | |
download | gnunet-017907f0af8c44ae86d20c241cb9662e0ac8be2b.tar.gz gnunet-017907f0af8c44ae86d20c241cb9662e0ac8be2b.zip |
dht changes, mostly making the driver do find peers adaptively... currently not seeing any crazy issues
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r-- | src/dht/gnunet-service-dht.c | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index f2379d72c..eb8a53ff4 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -104,7 +104,8 @@ | |||
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. |
106 | */ | 106 | */ |
107 | #define DHT_DEFAULT_FIND_PEER_OPTIONS GNUNET_DHT_RO_NONE | 107 | #define DHT_DEFAULT_FIND_PEER_OPTIONS GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE |
108 | /*#define DHT_DEFAULT_FIND_PEER_OPTIONS GNUNET_DHT_RO_NONE*/ | ||
108 | 109 | ||
109 | /** | 110 | /** |
110 | * How long at least to wait before sending another find peer request. | 111 | * How long at least to wait before sending another find peer request. |
@@ -833,6 +834,24 @@ static struct GNUNET_TIME_Relative get_average_send_delay() | |||
833 | #endif | 834 | #endif |
834 | 835 | ||
835 | /** | 836 | /** |
837 | * Given the largest send delay, artificially decrease it | ||
838 | * so the next time around we may have a chance at sending | ||
839 | * again. | ||
840 | */ | ||
841 | static void decrease_max_send_delay(struct GNUNET_TIME_Relative max_time) | ||
842 | { | ||
843 | unsigned int i; | ||
844 | for (i = 0; i < MAX_REPLY_TIMES; i++) | ||
845 | { | ||
846 | if (reply_times[i].value == max_time.value) | ||
847 | { | ||
848 | reply_times[i].value = reply_times[i].value / 2; | ||
849 | return; | ||
850 | } | ||
851 | } | ||
852 | } | ||
853 | |||
854 | /** | ||
836 | * Find the maximum send time of the recently sent values. | 855 | * Find the maximum send time of the recently sent values. |
837 | * | 856 | * |
838 | * @return the average time between asking core to send a message | 857 | * @return the average time between asking core to send a message |
@@ -1899,6 +1918,7 @@ static int route_result_message(void *cls, | |||
1899 | pos = record->head; | 1918 | pos = record->head; |
1900 | while (pos != NULL) | 1919 | while (pos != NULL) |
1901 | { | 1920 | { |
1921 | #if STRICT_FORWARDING | ||
1902 | if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT) /* If we have already forwarded this peer id, don't do it again! */ | 1922 | if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT) /* If we have already forwarded this peer id, don't do it again! */ |
1903 | { | 1923 | { |
1904 | if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (pos->find_peers_responded, &new_peer.hashPubKey)) | 1924 | if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (pos->find_peers_responded, &new_peer.hashPubKey)) |
@@ -1910,6 +1930,7 @@ static int route_result_message(void *cls, | |||
1910 | else | 1930 | else |
1911 | GNUNET_CONTAINER_bloomfilter_add(pos->find_peers_responded, &new_peer.hashPubKey); | 1931 | GNUNET_CONTAINER_bloomfilter_add(pos->find_peers_responded, &new_peer.hashPubKey); |
1912 | } | 1932 | } |
1933 | #endif | ||
1913 | 1934 | ||
1914 | if (0 == memcmp(&pos->source, &my_identity, sizeof(struct GNUNET_PeerIdentity))) /* Local client (or DHT) initiated request! */ | 1935 | if (0 == memcmp(&pos->source, &my_identity, sizeof(struct GNUNET_PeerIdentity))) /* Local client (or DHT) initiated request! */ |
1915 | { | 1936 | { |
@@ -2175,13 +2196,17 @@ handle_dht_find_peer (void *cls, | |||
2175 | } | 2196 | } |
2176 | GNUNET_CONTAINER_bloomfilter_free(incoming_bloom); | 2197 | GNUNET_CONTAINER_bloomfilter_free(incoming_bloom); |
2177 | 2198 | ||
2199 | #if RESTRICT_FIND_PEER | ||
2200 | |||
2201 | /** | ||
2202 | * Ignore any find peer requests from a peer we have seen very recently. | ||
2203 | */ | ||
2178 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(recent_find_peer_requests, &message_context->key)) /* We have recently responded to a find peer request for this peer! */ | 2204 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(recent_find_peer_requests, &message_context->key)) /* We have recently responded to a find peer request for this peer! */ |
2179 | { | 2205 | { |
2180 | increment_stats("# dht find peer requests ignored (recently seen!)"); | 2206 | increment_stats("# dht find peer requests ignored (recently seen!)"); |
2181 | return; | 2207 | return; |
2182 | } | 2208 | } |
2183 | 2209 | ||
2184 | #if RESTRICT_FIND_PEER | ||
2185 | /** | 2210 | /** |
2186 | * Use this check to only allow the peer to respond to find peer requests if | 2211 | * 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 | 2212 | * it would be beneficial to have the requesting peer in this peers routing |
@@ -2201,7 +2226,7 @@ handle_dht_find_peer (void *cls, | |||
2201 | recent_hash = GNUNET_malloc(sizeof(GNUNET_HashCode)); | 2226 | recent_hash = GNUNET_malloc(sizeof(GNUNET_HashCode)); |
2202 | memcpy(recent_hash, &message_context->key, sizeof(GNUNET_HashCode)); | 2227 | memcpy(recent_hash, &message_context->key, sizeof(GNUNET_HashCode)); |
2203 | GNUNET_CONTAINER_multihashmap_put (recent_find_peer_requests, &message_context->key, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 2228 | GNUNET_CONTAINER_multihashmap_put (recent_find_peer_requests, &message_context->key, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
2204 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120), &remove_recent_find_peer, &recent_hash); | 2229 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), &remove_recent_find_peer, &recent_hash); |
2205 | 2230 | ||
2206 | /* Simplistic find_peer functionality, always return our hello */ | 2231 | /* Simplistic find_peer functionality, always return our hello */ |
2207 | hello_size = ntohs(my_hello->size); | 2232 | hello_size = ntohs(my_hello->size); |
@@ -2416,7 +2441,7 @@ get_forward_count (unsigned int hop_count, size_t target_replication) | |||
2416 | target_value++; | 2441 | target_value++; |
2417 | #endif | 2442 | #endif |
2418 | 2443 | ||
2419 | random_value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, target_replication * (hop_count + 1) + diameter) + 1; | 2444 | random_value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 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)); | 2445 | 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; | 2446 | 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); | 2447 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "random %u, target %u, max %u\n", random_value, target_replication, target_replication * (hop_count + 1) + diameter); |
@@ -3263,7 +3288,7 @@ handle_dht_control_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
3263 | switch (ntohs(dht_control_msg->command)) | 3288 | switch (ntohs(dht_control_msg->command)) |
3264 | { | 3289 | { |
3265 | case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: | 3290 | case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: |
3266 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending self seeking find peer request!\n"); | 3291 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending self seeking find peer request!\n"); |
3267 | GNUNET_SCHEDULER_add_now(sched, &send_find_peer_message, NULL); | 3292 | GNUNET_SCHEDULER_add_now(sched, &send_find_peer_message, NULL); |
3268 | break; | 3293 | break; |
3269 | case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET: | 3294 | case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET: |
@@ -3361,7 +3386,8 @@ handle_dht_p2p_route_request (void *cls, | |||
3361 | 3386 | ||
3362 | if (get_max_send_delay().value > MAX_REQUEST_TIME.value) | 3387 | if (get_max_send_delay().value > MAX_REQUEST_TIME.value) |
3363 | { | 3388 | { |
3364 | fprintf(stderr, "Sending of previous requests has taken far too long, backing off!\n"); | 3389 | fprintf(stderr, "Sending of previous replies took far too long, backing off!\n"); |
3390 | decrease_max_send_delay(get_max_send_delay()); | ||
3365 | return GNUNET_YES; | 3391 | return GNUNET_YES; |
3366 | } | 3392 | } |
3367 | 3393 | ||