diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-09-13 10:25:25 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-09-13 10:25:25 +0000 |
commit | 13686363c73d6f33d0f6adab48ed30ef83832984 (patch) | |
tree | f54d709522d549fffe81234bd6e7466808620b0d /src/dht/gnunet-service-dht.c | |
parent | 44a658f23e225e260c6837f4b9692caca1e91a4a (diff) | |
download | gnunet-13686363c73d6f33d0f6adab48ed30ef83832984.tar.gz gnunet-13686363c73d6f33d0f6adab48ed30ef83832984.zip |
integrate DHT with NSE
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r-- | src/dht/gnunet-service-dht.c | 64 |
1 files changed, 41 insertions, 23 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 419aadd46..793f5b9c7 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "gnunet_os_lib.h" | 32 | #include "gnunet_os_lib.h" |
33 | #include "gnunet_protocols.h" | 33 | #include "gnunet_protocols.h" |
34 | #include "gnunet_service_lib.h" | 34 | #include "gnunet_service_lib.h" |
35 | #include "gnunet_nse_service.h" | ||
35 | #include "gnunet_core_service.h" | 36 | #include "gnunet_core_service.h" |
36 | #include "gnunet_signal_lib.h" | 37 | #include "gnunet_signal_lib.h" |
37 | #include "gnunet_util_lib.h" | 38 | #include "gnunet_util_lib.h" |
@@ -648,9 +649,12 @@ struct RepublishContext | |||
648 | 649 | ||
649 | 650 | ||
650 | /** | 651 | /** |
651 | * Modifier for the convergence function | 652 | * log of the current network size estimate, used as the point where |
653 | * we switch between random and deterministic routing. Default | ||
654 | * value of 4.0 is used if NSE module is not available (i.e. not | ||
655 | * configured). | ||
652 | */ | 656 | */ |
653 | static float converge_modifier; | 657 | static double log_of_network_size_estimate = 4.0; |
654 | 658 | ||
655 | /** | 659 | /** |
656 | * Recent requests by hash/uid and by time inserted. | 660 | * Recent requests by hash/uid and by time inserted. |
@@ -883,6 +887,31 @@ static unsigned int reply_counter; | |||
883 | */ | 887 | */ |
884 | static struct GNUNET_BLOCK_Context *block_context; | 888 | static struct GNUNET_BLOCK_Context *block_context; |
885 | 889 | ||
890 | /** | ||
891 | * Network size estimation handle. | ||
892 | */ | ||
893 | static struct GNUNET_NSE_Handle *nse; | ||
894 | |||
895 | |||
896 | /** | ||
897 | * Callback that is called when network size estimate is updated. | ||
898 | * | ||
899 | * @param cls closure | ||
900 | * @param timestamp time when the estimate was received from the server (or created by the server) | ||
901 | * @param logestimate the log(Base 2) value of the current network size estimate | ||
902 | * @param std_dev standard deviation for the estimate | ||
903 | * | ||
904 | */ | ||
905 | static void | ||
906 | update_network_size_estimate (void *cls, | ||
907 | struct GNUNET_TIME_Absolute timestamp, | ||
908 | double logestimate, double std_dev) | ||
909 | { | ||
910 | log_of_network_size_estimate = logestimate; | ||
911 | } | ||
912 | |||
913 | |||
914 | |||
886 | 915 | ||
887 | /** | 916 | /** |
888 | * Forward declaration. | 917 | * Forward declaration. |
@@ -895,6 +924,7 @@ send_generic_reply (void *cls, size_t size, void *buf); | |||
895 | static size_t | 924 | static size_t |
896 | core_transmit_notify (void *cls, size_t size, void *buf); | 925 | core_transmit_notify (void *cls, size_t size, void *buf); |
897 | 926 | ||
927 | |||
898 | /** | 928 | /** |
899 | * Convert unique ID to hash code. | 929 | * Convert unique ID to hash code. |
900 | * | 930 | * |
@@ -3147,7 +3177,7 @@ am_closest_peer (const GNUNET_HashCode * target, | |||
3147 | { | 3177 | { |
3148 | if (strict_kademlia != GNUNET_YES) /* Return that we at as close as any other peer */ | 3178 | if (strict_kademlia != GNUNET_YES) /* Return that we at as close as any other peer */ |
3149 | return GNUNET_YES; | 3179 | return GNUNET_YES; |
3150 | else if (distance (&pos->id.hashPubKey, target) < my_distance) /* Check all known peers, only return if we are the true closest */ | 3180 | if (distance (&pos->id.hashPubKey, target) < my_distance) /* Check all known peers, only return if we are the true closest */ |
3151 | return GNUNET_NO; | 3181 | return GNUNET_NO; |
3152 | } | 3182 | } |
3153 | pos = pos->next; | 3183 | pos = pos->next; |
@@ -3187,7 +3217,7 @@ select_peer (const GNUNET_HashCode * target, | |||
3187 | 3217 | ||
3188 | /** If we are doing kademlia routing (saves some cycles) */ | 3218 | /** If we are doing kademlia routing (saves some cycles) */ |
3189 | if ( (strict_kademlia == GNUNET_YES) || | 3219 | if ( (strict_kademlia == GNUNET_YES) || |
3190 | (hops >= converge_modifier) ) | 3220 | (hops >= log_of_network_size_estimate) ) |
3191 | { | 3221 | { |
3192 | /* greedy selection (closest peer that is not in bloomfilter) */ | 3222 | /* greedy selection (closest peer that is not in bloomfilter) */ |
3193 | largest_distance = 0; | 3223 | largest_distance = 0; |
@@ -4628,6 +4658,11 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
4628 | GNUNET_TRANSPORT_disconnect (transport_handle); | 4658 | GNUNET_TRANSPORT_disconnect (transport_handle); |
4629 | transport_handle = NULL; | 4659 | transport_handle = NULL; |
4630 | } | 4660 | } |
4661 | if (NULL != nse) | ||
4662 | { | ||
4663 | GNUNET_NSE_disconnect (nse); | ||
4664 | nse = NULL; | ||
4665 | } | ||
4631 | if (coreAPI != NULL) | 4666 | if (coreAPI != NULL) |
4632 | { | 4667 | { |
4633 | #if DEBUG_DHT | 4668 | #if DEBUG_DHT |
@@ -4716,9 +4751,6 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, | |||
4716 | "%s Receive CORE INIT message but have already been initialized! Did CORE fail?\n", | 4751 | "%s Receive CORE INIT message but have already been initialized! Did CORE fail?\n", |
4717 | "DHT SERVICE"); | 4752 | "DHT SERVICE"); |
4718 | my_short_id = GNUNET_strdup (GNUNET_i2s (&my_identity)); | 4753 | my_short_id = GNUNET_strdup (GNUNET_i2s (&my_identity)); |
4719 | /* Set the server to local variable */ | ||
4720 | coreAPI = server; | ||
4721 | |||
4722 | if (dhtlog_handle != NULL) | 4754 | if (dhtlog_handle != NULL) |
4723 | dhtlog_handle->insert_node (NULL, &my_identity); | 4755 | dhtlog_handle->insert_node (NULL, &my_identity); |
4724 | } | 4756 | } |
@@ -4901,12 +4933,13 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
4901 | { | 4933 | { |
4902 | struct GNUNET_TIME_Relative next_send_time; | 4934 | struct GNUNET_TIME_Relative next_send_time; |
4903 | unsigned long long temp_config_num; | 4935 | unsigned long long temp_config_num; |
4904 | char *converge_modifier_buf; | ||
4905 | 4936 | ||
4906 | cfg = c; | 4937 | cfg = c; |
4907 | datacache = GNUNET_DATACACHE_create (cfg, "dhtcache"); | 4938 | datacache = GNUNET_DATACACHE_create (cfg, "dhtcache"); |
4908 | GNUNET_SERVER_add_handlers (server, plugin_handlers); | 4939 | GNUNET_SERVER_add_handlers (server, plugin_handlers); |
4909 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | 4940 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
4941 | nse = GNUNET_NSE_connect (cfg, | ||
4942 | &update_network_size_estimate, NULL); | ||
4910 | coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */ | 4943 | coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */ |
4911 | DEFAULT_CORE_QUEUE_SIZE, /* queue size */ | 4944 | DEFAULT_CORE_QUEUE_SIZE, /* queue size */ |
4912 | NULL, /* Closure passed to DHT functions */ | 4945 | NULL, /* Closure passed to DHT functions */ |
@@ -5065,21 +5098,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
5065 | } | 5098 | } |
5066 | #endif | 5099 | #endif |
5067 | 5100 | ||
5068 | converge_modifier = 4.0; | ||
5069 | if (GNUNET_OK == | ||
5070 | GNUNET_CONFIGURATION_get_value_string (cfg, "dht", "converge_modifier", | ||
5071 | &converge_modifier_buf)) | ||
5072 | { | ||
5073 | if (1 != sscanf (converge_modifier_buf, "%f", &converge_modifier)) | ||
5074 | { | ||
5075 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
5076 | "Failed to read decimal value for %s from `%s'\n", | ||
5077 | "CONVERGE_MODIFIER", converge_modifier_buf); | ||
5078 | converge_modifier = 0.0; | ||
5079 | } | ||
5080 | GNUNET_free (converge_modifier_buf); | ||
5081 | } | ||
5082 | |||
5083 | if (GNUNET_YES == | 5101 | if (GNUNET_YES == |
5084 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "paper_forwarding")) | 5102 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "paper_forwarding")) |
5085 | paper_forwarding = GNUNET_YES; | 5103 | paper_forwarding = GNUNET_YES; |