diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-09-16 14:14:32 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-09-16 14:14:32 +0000 |
commit | 6d15bc3f382bddb55c6678e839d25728e1512af4 (patch) | |
tree | c8df83f82b3d012bcb4659875627a79c06b07eb5 /src | |
parent | 797a58626759227befd9b055f01d2505216e2ccb (diff) | |
download | gnunet-6d15bc3f382bddb55c6678e839d25728e1512af4.tar.gz gnunet-6d15bc3f382bddb55c6678e839d25728e1512af4.zip |
mostly options fixes, new convergence formula for testing
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/gnunet-service-dht.c | 109 |
1 files changed, 94 insertions, 15 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 5eb7590b4..3668b3847 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -161,7 +161,7 @@ | |||
161 | * Real maximum number of hops, at which point we refuse | 161 | * Real maximum number of hops, at which point we refuse |
162 | * to forward the message. | 162 | * to forward the message. |
163 | */ | 163 | */ |
164 | #define MAX_HOPS 10 | 164 | #define DEFAULT_MAX_HOPS 10 |
165 | 165 | ||
166 | /** | 166 | /** |
167 | * How many time differences between requesting a core send and | 167 | * How many time differences between requesting a core send and |
@@ -639,6 +639,11 @@ struct RepublishContext | |||
639 | enum ConvergenceOptions converge_option; | 639 | enum ConvergenceOptions converge_option; |
640 | 640 | ||
641 | /** | 641 | /** |
642 | * Modifier for the convergence function | ||
643 | */ | ||
644 | float converge_modifier; | ||
645 | |||
646 | /** | ||
642 | * Recent requests by hash/uid and by time inserted. | 647 | * Recent requests by hash/uid and by time inserted. |
643 | */ | 648 | */ |
644 | static struct RecentRequests recent; | 649 | static struct RecentRequests recent; |
@@ -750,6 +755,21 @@ static GNUNET_SCHEDULER_TaskIdentifier cleanup_task; | |||
750 | static unsigned int lowest_bucket; /* Initially equal to MAX_BUCKETS - 1 */ | 755 | static unsigned int lowest_bucket; /* Initially equal to MAX_BUCKETS - 1 */ |
751 | 756 | ||
752 | /** | 757 | /** |
758 | * The maximum number of hops before we stop routing messages. | ||
759 | */ | ||
760 | static unsigned long long max_hops; | ||
761 | |||
762 | /** | ||
763 | * How often to republish content we have previously stored. | ||
764 | */ | ||
765 | static struct GNUNET_TIME_Relative dht_republish_frequency; | ||
766 | |||
767 | /** | ||
768 | * GNUNET_YES to stop at max_hops, GNUNET_NO to heuristically decide when to stop forwarding. | ||
769 | */ | ||
770 | static int use_max_hops; | ||
771 | |||
772 | /** | ||
753 | * The buckets (Kademlia routing table, complete with growth). | 773 | * The buckets (Kademlia routing table, complete with growth). |
754 | * Array of size MAX_BUCKET_SIZE. | 774 | * Array of size MAX_BUCKET_SIZE. |
755 | */ | 775 | */ |
@@ -1409,7 +1429,9 @@ add_peer(const struct GNUNET_PeerIdentity *peer, | |||
1409 | 1429 | ||
1410 | if ((matching_bits(&my_identity.hashPubKey, &peer->hashPubKey) > 0) && (k_buckets[bucket].peers_size <= bucket_size)) | 1430 | if ((matching_bits(&my_identity.hashPubKey, &peer->hashPubKey) > 0) && (k_buckets[bucket].peers_size <= bucket_size)) |
1411 | { | 1431 | { |
1432 | #if DO_UPDATE_PREFERENCE | ||
1412 | new_peer->preference_task = GNUNET_SCHEDULER_add_now(sched, &update_core_preference, new_peer); | 1433 | new_peer->preference_task = GNUNET_SCHEDULER_add_now(sched, &update_core_preference, new_peer); |
1434 | #endif | ||
1413 | } | 1435 | } |
1414 | 1436 | ||
1415 | return new_peer; | 1437 | return new_peer; |
@@ -1936,7 +1958,7 @@ static int route_result_message(void *cls, | |||
1936 | { | 1958 | { |
1937 | increment_stats(STAT_HELLOS_PROVIDED); | 1959 | increment_stats(STAT_HELLOS_PROVIDED); |
1938 | GNUNET_TRANSPORT_offer_hello(transport_handle, hello_msg); | 1960 | GNUNET_TRANSPORT_offer_hello(transport_handle, hello_msg); |
1939 | GNUNET_CORE_peer_request_connect(sched, cfg, GNUNET_TIME_UNIT_FOREVER_REL, &new_peer, NULL, NULL); | 1961 | GNUNET_CORE_peer_request_connect(sched, cfg, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), &new_peer, NULL, NULL); |
1940 | } | 1962 | } |
1941 | } | 1963 | } |
1942 | } | 1964 | } |
@@ -2415,7 +2437,7 @@ handle_dht_put (void *cls, | |||
2415 | put_context = GNUNET_malloc(sizeof(struct RepublishContext)); | 2437 | put_context = GNUNET_malloc(sizeof(struct RepublishContext)); |
2416 | memcpy(&put_context->key, &message_context->key, sizeof(GNUNET_HashCode)); | 2438 | memcpy(&put_context->key, &message_context->key, sizeof(GNUNET_HashCode)); |
2417 | put_context->type = put_type; | 2439 | put_context->type = put_type; |
2418 | GNUNET_SCHEDULER_add_delayed (sched, DHT_REPUBLISH_FREQUENCY, &republish_content, put_context); | 2440 | GNUNET_SCHEDULER_add_delayed (sched, dht_republish_frequency, &republish_content, put_context); |
2419 | } | 2441 | } |
2420 | } | 2442 | } |
2421 | else | 2443 | else |
@@ -2470,7 +2492,7 @@ get_forward_count (unsigned int hop_count, size_t target_replication) | |||
2470 | { | 2492 | { |
2471 | if (hop_count == 0) | 2493 | if (hop_count == 0) |
2472 | return DHT_KADEMLIA_REPLICATION; | 2494 | return DHT_KADEMLIA_REPLICATION; |
2473 | else if (hop_count < MAX_HOPS) | 2495 | else if (hop_count < max_hops) |
2474 | return 1; | 2496 | return 1; |
2475 | else | 2497 | else |
2476 | return 0; | 2498 | return 0; |
@@ -2490,7 +2512,7 @@ get_forward_count (unsigned int hop_count, size_t target_replication) | |||
2490 | #endif | 2512 | #endif |
2491 | return 0; | 2513 | return 0; |
2492 | } | 2514 | } |
2493 | else if (hop_count > MAX_HOPS) | 2515 | else if (hop_count > max_hops) |
2494 | { | 2516 | { |
2495 | #if DEBUG_DHT | 2517 | #if DEBUG_DHT |
2496 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2518 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -2633,8 +2655,14 @@ route_closer (const GNUNET_HashCode *target, | |||
2633 | struct PeerInfo *pos; | 2655 | struct PeerInfo *pos; |
2634 | int have_closer; | 2656 | int have_closer; |
2635 | int count; | 2657 | int count; |
2658 | int curr_max_hops; | ||
2659 | double calc_value; | ||
2636 | my_matching_bits = matching_bits(target, &my_identity.hashPubKey); | 2660 | my_matching_bits = matching_bits(target, &my_identity.hashPubKey); |
2637 | 2661 | ||
2662 | if (GNUNET_YES == use_max_hops) | ||
2663 | curr_max_hops = max_hops; | ||
2664 | else | ||
2665 | curr_max_hops = max_hops; /* FIXME: replace with heuristic! */ | ||
2638 | /** | 2666 | /** |
2639 | * First check if we know any close (as close as us or closer) peers. | 2667 | * First check if we know any close (as close as us or closer) peers. |
2640 | */ | 2668 | */ |
@@ -2669,7 +2697,7 @@ route_closer (const GNUNET_HashCode *target, | |||
2669 | * Simple linear curve for choosing whether or not to converge. | 2697 | * Simple linear curve for choosing whether or not to converge. |
2670 | * Choose to route only closer with probability hops/MAX_HOPS. | 2698 | * Choose to route only closer with probability hops/MAX_HOPS. |
2671 | */ | 2699 | */ |
2672 | random_value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, MAX_HOPS); | 2700 | random_value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, curr_max_hops); |
2673 | if (random_value < hops) | 2701 | if (random_value < hops) |
2674 | return GNUNET_YES; | 2702 | return GNUNET_YES; |
2675 | else | 2703 | else |
@@ -2678,12 +2706,26 @@ route_closer (const GNUNET_HashCode *target, | |||
2678 | /** | 2706 | /** |
2679 | * Simple square based curve. | 2707 | * Simple square based curve. |
2680 | */ | 2708 | */ |
2681 | if ((GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, (uint32_t)-1) / (double)(uint32_t)-1) < (sqrt(hops) / sqrt(MAX_HOPS))) | 2709 | if ((GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, (uint32_t)-1) / (double)(uint32_t)-1) < (sqrt(hops) / sqrt(curr_max_hops))) |
2710 | return GNUNET_YES; | ||
2711 | else | ||
2712 | return GNUNET_NO; | ||
2713 | case DHT_CONVERGE_EXPONENTIAL: | ||
2714 | /** | ||
2715 | * Simple exponential curve. | ||
2716 | */ | ||
2717 | if (converge_modifier > 0) | ||
2718 | calc_value = ((converge_modifier * (hops * hops)) / (curr_max_hops * curr_max_hops)) / curr_max_hops; | ||
2719 | else | ||
2720 | calc_value = ((hops * hops) / (curr_max_hops * curr_max_hops)) / curr_max_hops; | ||
2721 | |||
2722 | if ((GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, (uint32_t)-1) / (double)(uint32_t)-1) < calc_value) | ||
2682 | return GNUNET_YES; | 2723 | return GNUNET_YES; |
2683 | else | 2724 | else |
2684 | return GNUNET_NO; | 2725 | return GNUNET_NO; |
2685 | default: | 2726 | default: |
2686 | return GNUNET_NO; | 2727 | return GNUNET_NO; |
2728 | |||
2687 | } | 2729 | } |
2688 | } | 2730 | } |
2689 | 2731 | ||
@@ -3178,14 +3220,14 @@ static int route_message(void *cls, | |||
3178 | } | 3220 | } |
3179 | 3221 | ||
3180 | GNUNET_CONTAINER_bloomfilter_add (message_context->bloom, &my_identity.hashPubKey); | 3222 | GNUNET_CONTAINER_bloomfilter_add (message_context->bloom, &my_identity.hashPubKey); |
3181 | hash_from_uid(message_context->unique_id, &unique_hash); | 3223 | hash_from_uid (message_context->unique_id, &unique_hash); |
3182 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(recent.hashmap, &unique_hash)) | 3224 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (recent.hashmap, &unique_hash)) |
3183 | { | 3225 | { |
3184 | recent_req = GNUNET_CONTAINER_multihashmap_get(recent.hashmap, &unique_hash); | 3226 | recent_req = GNUNET_CONTAINER_multihashmap_get(recent.hashmap, &unique_hash); |
3185 | GNUNET_assert(recent_req != NULL); | 3227 | GNUNET_assert(recent_req != NULL); |
3186 | if (0 != memcmp(&recent_req->key, &message_context->key, sizeof(GNUNET_HashCode))) | 3228 | if (0 != memcmp(&recent_req->key, &message_context->key, sizeof(GNUNET_HashCode))) |
3187 | increment_stats(STAT_DUPLICATE_UID); | 3229 | increment_stats(STAT_DUPLICATE_UID); |
3188 | else | 3230 | else |
3189 | { | 3231 | { |
3190 | increment_stats(STAT_RECENT_SEEN); | 3232 | increment_stats(STAT_RECENT_SEEN); |
3191 | GNUNET_CONTAINER_bloomfilter_or2(message_context->bloom, recent_req->bloom, DHT_BLOOM_SIZE); | 3233 | GNUNET_CONTAINER_bloomfilter_or2(message_context->bloom, recent_req->bloom, DHT_BLOOM_SIZE); |
@@ -3339,7 +3381,7 @@ republish_content(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3339 | if (results == 0) /* Data must have expired */ | 3381 | if (results == 0) /* Data must have expired */ |
3340 | GNUNET_free(put_context); | 3382 | GNUNET_free(put_context); |
3341 | else /* Reschedule task for next time period */ | 3383 | else /* Reschedule task for next time period */ |
3342 | GNUNET_SCHEDULER_add_delayed(sched, DHT_REPUBLISH_FREQUENCY, &republish_content, put_context); | 3384 | GNUNET_SCHEDULER_add_delayed(sched, dht_republish_frequency, &republish_content, put_context); |
3343 | 3385 | ||
3344 | } | 3386 | } |
3345 | 3387 | ||
@@ -4051,6 +4093,8 @@ run (void *cls, | |||
4051 | #if DO_FIND_PEER | 4093 | #if DO_FIND_PEER |
4052 | struct GNUNET_TIME_Relative next_send_time; | 4094 | struct GNUNET_TIME_Relative next_send_time; |
4053 | #endif | 4095 | #endif |
4096 | unsigned long long temp_config_num; | ||
4097 | char *converge_modifier_buf; | ||
4054 | sched = scheduler; | 4098 | sched = scheduler; |
4055 | cfg = c; | 4099 | cfg = c; |
4056 | datacache = GNUNET_DATACACHE_create (sched, cfg, "dhtcache"); | 4100 | datacache = GNUNET_DATACACHE_create (sched, cfg, "dhtcache"); |
@@ -4121,6 +4165,19 @@ run (void *cls, | |||
4121 | malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY; | 4165 | malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY; |
4122 | } | 4166 | } |
4123 | 4167 | ||
4168 | if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", | ||
4169 | "MAX_HOPS", | ||
4170 | &max_hops)) | ||
4171 | { | ||
4172 | max_hops = DEFAULT_MAX_HOPS; | ||
4173 | } | ||
4174 | |||
4175 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT", | ||
4176 | "USE_MAX_HOPS")) | ||
4177 | { | ||
4178 | use_max_hops = GNUNET_YES; | ||
4179 | } | ||
4180 | |||
4124 | if (GNUNET_YES == | 4181 | if (GNUNET_YES == |
4125 | GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", | 4182 | GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", |
4126 | "malicious_putter")) | 4183 | "malicious_putter")) |
@@ -4132,6 +4189,12 @@ run (void *cls, | |||
4132 | malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY; | 4189 | malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY; |
4133 | } | 4190 | } |
4134 | 4191 | ||
4192 | dht_republish_frequency = DEFAULT_DHT_REPUBLISH_FREQUENCY; | ||
4193 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "DHT", "REPLICATION_FREQUENCY", &temp_config_num)) | ||
4194 | { | ||
4195 | dht_republish_frequency = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, temp_config_num); | ||
4196 | } | ||
4197 | |||
4135 | if (GNUNET_YES == | 4198 | if (GNUNET_YES == |
4136 | GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", | 4199 | GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", |
4137 | "malicious_dropper")) | 4200 | "malicious_dropper")) |
@@ -4185,6 +4248,22 @@ run (void *cls, | |||
4185 | { | 4248 | { |
4186 | converge_option = DHT_CONVERGE_LINEAR; | 4249 | converge_option = DHT_CONVERGE_LINEAR; |
4187 | } | 4250 | } |
4251 | else if (GNUNET_YES == | ||
4252 | GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", | ||
4253 | "converge_exponential")) | ||
4254 | { | ||
4255 | converge_option = DHT_CONVERGE_EXPONENTIAL; | ||
4256 | } | ||
4257 | |||
4258 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "dht_testing", "converge_modifier", &converge_modifier_buf)) | ||
4259 | { | ||
4260 | if (1 != sscanf(converge_modifier_buf, "%f", &converge_modifier)) | ||
4261 | { | ||
4262 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to read decimal value for %s from `%s'\n", "CONVERGE_MODIFIER", converge_modifier_buf); | ||
4263 | converge_modifier = 0.0; | ||
4264 | } | ||
4265 | GNUNET_free(converge_modifier_buf); | ||
4266 | } | ||
4188 | 4267 | ||
4189 | stats = GNUNET_STATISTICS_create(sched, "dht", cfg); | 4268 | stats = GNUNET_STATISTICS_create(sched, "dht", cfg); |
4190 | 4269 | ||