diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-05-30 18:47:17 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-05-30 18:47:17 +0200 |
commit | adef29b3ed00afd42669ae35a73951c59f08a41b (patch) | |
tree | c8d6c7f60716c551b587aed7a1efe0d6e756833f /src/dht | |
parent | f5a18b7466f342ac9624adcdb65f104aef8ecb5e (diff) | |
download | gnunet-adef29b3ed00afd42669ae35a73951c59f08a41b.tar.gz gnunet-adef29b3ed00afd42669ae35a73951c59f08a41b.zip |
add proximity considerations to datacache
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-dht-get.c | 22 | ||||
-rw-r--r-- | src/dht/gnunet-dht-monitor.c | 27 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_datacache.c | 6 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 12 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.h | 16 |
5 files changed, 57 insertions, 26 deletions
diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c index 842ec6270..afcd5422c 100644 --- a/src/dht/gnunet-dht-get.c +++ b/src/dht/gnunet-dht-get.c | |||
@@ -154,7 +154,9 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
154 | const void *data) | 154 | const void *data) |
155 | { | 155 | { |
156 | FPRINTF (stdout, | 156 | FPRINTF (stdout, |
157 | _("Result %d, type %d:\n%.*s\n"), | 157 | (GNUNET_BLOCK_TYPE_TEST == type) |
158 | ? _("Result %d, type %d:\n%.*s\n") | ||
159 | : _("Result %d, type %d:\n"), | ||
158 | result_count, | 160 | result_count, |
159 | type, | 161 | type, |
160 | (unsigned int) size, | 162 | (unsigned int) size, |
@@ -196,8 +198,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
196 | { | 198 | { |
197 | struct GNUNET_HashCode key; | 199 | struct GNUNET_HashCode key; |
198 | 200 | ||
199 | |||
200 | |||
201 | cfg = c; | 201 | cfg = c; |
202 | if (NULL == query_key) | 202 | if (NULL == query_key) |
203 | { | 203 | { |
@@ -215,17 +215,22 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
215 | query_type = GNUNET_BLOCK_TYPE_TEST; | 215 | query_type = GNUNET_BLOCK_TYPE_TEST; |
216 | GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); | 216 | GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); |
217 | if (verbose) | 217 | if (verbose) |
218 | FPRINTF (stderr, "%s `%s' \n", _("Issueing DHT GET with key"), GNUNET_h2s_full (&key)); | 218 | FPRINTF (stderr, "%s `%s' \n", |
219 | _("Issueing DHT GET with key"), | ||
220 | GNUNET_h2s_full (&key)); | ||
219 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); | 221 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); |
220 | tt = GNUNET_SCHEDULER_add_delayed (timeout_request, | 222 | tt = GNUNET_SCHEDULER_add_delayed (timeout_request, |
221 | &timeout_task, NULL); | 223 | &timeout_task, |
224 | NULL); | ||
222 | get_handle = | 225 | get_handle = |
223 | GNUNET_DHT_get_start (dht_handle, query_type, &key, replication, | 226 | GNUNET_DHT_get_start (dht_handle, query_type, &key, replication, |
224 | (demultixplex_everywhere) ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE : GNUNET_DHT_RO_NONE, | 227 | (demultixplex_everywhere) ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE : GNUNET_DHT_RO_NONE, |
225 | NULL, 0, &get_result_iterator, NULL); | 228 | NULL, 0, |
226 | 229 | &get_result_iterator, | |
230 | NULL); | ||
227 | } | 231 | } |
228 | 232 | ||
233 | |||
229 | /** | 234 | /** |
230 | * Entry point for gnunet-dht-get | 235 | * Entry point for gnunet-dht-get |
231 | * | 236 | * |
@@ -236,15 +241,12 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
236 | int | 241 | int |
237 | main (int argc, char *const *argv) | 242 | main (int argc, char *const *argv) |
238 | { | 243 | { |
239 | |||
240 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 244 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
241 | |||
242 | GNUNET_GETOPT_option_string ('k', | 245 | GNUNET_GETOPT_option_string ('k', |
243 | "key", | 246 | "key", |
244 | "KEY", | 247 | "KEY", |
245 | gettext_noop ("the query key"), | 248 | gettext_noop ("the query key"), |
246 | &query_key), | 249 | &query_key), |
247 | |||
248 | GNUNET_GETOPT_option_uint ('r', | 250 | GNUNET_GETOPT_option_uint ('r', |
249 | "replication", | 251 | "replication", |
250 | "LEVEL", | 252 | "LEVEL", |
diff --git a/src/dht/gnunet-dht-monitor.c b/src/dht/gnunet-dht-monitor.c index b7360bbab..a699b3d17 100644 --- a/src/dht/gnunet-dht-monitor.c +++ b/src/dht/gnunet-dht-monitor.c | |||
@@ -141,7 +141,8 @@ get_callback (void *cls, | |||
141 | const struct GNUNET_PeerIdentity *path, | 141 | const struct GNUNET_PeerIdentity *path, |
142 | const struct GNUNET_HashCode * key) | 142 | const struct GNUNET_HashCode * key) |
143 | { | 143 | { |
144 | FPRINTF (stdout, "GET #%u: type %d, key `%s'\n", | 144 | FPRINTF (stdout, |
145 | "GET #%u: type %d, key `%s'\n", | ||
145 | result_count, | 146 | result_count, |
146 | (int) type, | 147 | (int) type, |
147 | GNUNET_h2s_full(key)); | 148 | GNUNET_h2s_full(key)); |
@@ -176,8 +177,11 @@ get_resp_callback (void *cls, | |||
176 | size_t size) | 177 | size_t size) |
177 | { | 178 | { |
178 | FPRINTF (stdout, | 179 | FPRINTF (stdout, |
179 | "RESPONSE #%u: type %d, key `%s', data `%.*s'\n", | 180 | (GNUNET_BLOCK_TYPE_TEST == type) |
181 | ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n" | ||
182 | : "RESPONSE #%u (%s): type %d, key `%s'\n", | ||
180 | result_count, | 183 | result_count, |
184 | GNUNET_STRINGS_absolute_time_to_string (exp), | ||
181 | (int) type, | 185 | (int) type, |
182 | GNUNET_h2s_full (key), | 186 | GNUNET_h2s_full (key), |
183 | (unsigned int) size, | 187 | (unsigned int) size, |
@@ -215,8 +219,11 @@ put_callback (void *cls, | |||
215 | size_t size) | 219 | size_t size) |
216 | { | 220 | { |
217 | FPRINTF (stdout, | 221 | FPRINTF (stdout, |
218 | "PUT %u: type %d, key `%s', data `%.*s'\n", | 222 | (GNUNET_BLOCK_TYPE_TEST == type) |
223 | ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n" | ||
224 | : "PUT %u (%s): type %d, key `%s'\n", | ||
219 | result_count, | 225 | result_count, |
226 | GNUNET_STRINGS_absolute_time_to_string (exp), | ||
220 | (int) type, | 227 | (int) type, |
221 | GNUNET_h2s_full(key), | 228 | GNUNET_h2s_full(key), |
222 | (unsigned int) size, | 229 | (unsigned int) size, |
@@ -234,7 +241,9 @@ put_callback (void *cls, | |||
234 | * @param c configuration | 241 | * @param c configuration |
235 | */ | 242 | */ |
236 | static void | 243 | static void |
237 | run (void *cls, char *const *args, const char *cfgfile, | 244 | run (void *cls, |
245 | char *const *args, | ||
246 | const char *cfgfile, | ||
238 | const struct GNUNET_CONFIGURATION_Handle *c) | 247 | const struct GNUNET_CONFIGURATION_Handle *c) |
239 | { | 248 | { |
240 | struct GNUNET_HashCode *key; | 249 | struct GNUNET_HashCode *key; |
@@ -291,30 +300,30 @@ int | |||
291 | main (int argc, char *const *argv) | 300 | main (int argc, char *const *argv) |
292 | { | 301 | { |
293 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 302 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
294 | 303 | ||
295 | GNUNET_GETOPT_option_string ('k', | 304 | GNUNET_GETOPT_option_string ('k', |
296 | "key", | 305 | "key", |
297 | "KEY", | 306 | "KEY", |
298 | gettext_noop ("the query key"), | 307 | gettext_noop ("the query key"), |
299 | &query_key), | 308 | &query_key), |
300 | 309 | ||
301 | GNUNET_GETOPT_option_uint ('t', | 310 | GNUNET_GETOPT_option_uint ('t', |
302 | "type", | 311 | "type", |
303 | "TYPE", | 312 | "TYPE", |
304 | gettext_noop ("the type of data to look for"), | 313 | gettext_noop ("the type of data to look for"), |
305 | &block_type), | 314 | &block_type), |
306 | 315 | ||
307 | GNUNET_GETOPT_option_relative_time ('T', | 316 | GNUNET_GETOPT_option_relative_time ('T', |
308 | "timeout", | 317 | "timeout", |
309 | "TIMEOUT", | 318 | "TIMEOUT", |
310 | gettext_noop ("how long should the monitor command run"), | 319 | gettext_noop ("how long should the monitor command run"), |
311 | &timeout_request), | 320 | &timeout_request), |
312 | 321 | ||
313 | GNUNET_GETOPT_option_flag ('V', | 322 | GNUNET_GETOPT_option_flag ('V', |
314 | "verbose", | 323 | "verbose", |
315 | gettext_noop ("be verbose (print progress information)"), | 324 | gettext_noop ("be verbose (print progress information)"), |
316 | &verbose), | 325 | &verbose), |
317 | 326 | ||
318 | GNUNET_GETOPT_OPTION_END | 327 | GNUNET_GETOPT_OPTION_END |
319 | }; | 328 | }; |
320 | 329 | ||
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c index 36047d561..81b7184ed 100644 --- a/src/dht/gnunet-service-dht_datacache.c +++ b/src/dht/gnunet-service-dht_datacache.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_datacache_lib.h" | 27 | #include "gnunet_datacache_lib.h" |
28 | #include "gnunet-service-dht_datacache.h" | 28 | #include "gnunet-service-dht_datacache.h" |
29 | #include "gnunet-service-dht_neighbours.h" | ||
29 | #include "gnunet-service-dht_routing.h" | 30 | #include "gnunet-service-dht_routing.h" |
30 | #include "gnunet-service-dht.h" | 31 | #include "gnunet-service-dht.h" |
31 | 32 | ||
@@ -79,10 +80,13 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, | |||
79 | } | 80 | } |
80 | /* Put size is actual data size plus struct overhead plus path length (if any) */ | 81 | /* Put size is actual data size plus struct overhead plus path length (if any) */ |
81 | GNUNET_STATISTICS_update (GDS_stats, | 82 | GNUNET_STATISTICS_update (GDS_stats, |
82 | gettext_noop ("# ITEMS stored in datacache"), 1, | 83 | gettext_noop ("# ITEMS stored in datacache"), |
84 | 1, | ||
83 | GNUNET_NO); | 85 | GNUNET_NO); |
84 | r = GNUNET_DATACACHE_put (datacache, | 86 | r = GNUNET_DATACACHE_put (datacache, |
85 | key, | 87 | key, |
88 | GDS_am_closest_peer (key, | ||
89 | NULL), | ||
86 | data_size, | 90 | data_size, |
87 | data, | 91 | data, |
88 | type, | 92 | type, |
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 0309bea88..b120091af 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -421,7 +421,7 @@ static struct GNUNET_ATS_ConnectivityHandle *ats_ch; | |||
421 | * Find the optimal bucket for this key. | 421 | * Find the optimal bucket for this key. |
422 | * | 422 | * |
423 | * @param hc the hashcode to compare our identity to | 423 | * @param hc the hashcode to compare our identity to |
424 | * @return the proper bucket index, or GNUNET_SYSERR | 424 | * @return the proper bucket index, or #GNUNET_SYSERR |
425 | * on error (same hashcode) | 425 | * on error (same hashcode) |
426 | */ | 426 | */ |
427 | static int | 427 | static int |
@@ -941,9 +941,9 @@ get_distance (const struct GNUNET_HashCode *target, | |||
941 | * @return #GNUNET_YES if node location is closest, | 941 | * @return #GNUNET_YES if node location is closest, |
942 | * #GNUNET_NO otherwise. | 942 | * #GNUNET_NO otherwise. |
943 | */ | 943 | */ |
944 | static int | 944 | int |
945 | am_closest_peer (const struct GNUNET_HashCode *key, | 945 | GDS_am_closest_peer (const struct GNUNET_HashCode *key, |
946 | const struct GNUNET_CONTAINER_BloomFilter *bloom) | 946 | const struct GNUNET_CONTAINER_BloomFilter *bloom) |
947 | { | 947 | { |
948 | int bits; | 948 | int bits; |
949 | int other_bits; | 949 | int other_bits; |
@@ -1803,7 +1803,7 @@ handle_dht_p2p_put (void *cls, | |||
1803 | payload); | 1803 | payload); |
1804 | /* store locally */ | 1804 | /* store locally */ |
1805 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | 1805 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || |
1806 | (am_closest_peer (&put->key, bf))) | 1806 | (GDS_am_closest_peer (&put->key, bf))) |
1807 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), | 1807 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), |
1808 | &put->key, | 1808 | &put->key, |
1809 | putlen, | 1809 | putlen, |
@@ -2122,7 +2122,7 @@ handle_dht_p2p_get (void *cls, | |||
2122 | (unsigned int) ntohl (get->hop_count)); | 2122 | (unsigned int) ntohl (get->hop_count)); |
2123 | /* local lookup (this may update the reply_bf) */ | 2123 | /* local lookup (this may update the reply_bf) */ |
2124 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | 2124 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || |
2125 | (am_closest_peer (&get->key, | 2125 | (GDS_am_closest_peer (&get->key, |
2126 | peer_bf))) | 2126 | peer_bf))) |
2127 | { | 2127 | { |
2128 | if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) | 2128 | if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) |
diff --git a/src/dht/gnunet-service-dht_neighbours.h b/src/dht/gnunet-service-dht_neighbours.h index 34b76ee8a..bb1867fe9 100644 --- a/src/dht/gnunet-service-dht_neighbours.h +++ b/src/dht/gnunet-service-dht_neighbours.h | |||
@@ -123,6 +123,22 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, | |||
123 | 123 | ||
124 | 124 | ||
125 | /** | 125 | /** |
126 | * Check whether my identity is closer than any known peers. If a | ||
127 | * non-null bloomfilter is given, check if this is the closest peer | ||
128 | * that hasn't already been routed to. | ||
129 | * | ||
130 | * @param key hash code to check closeness to | ||
131 | * @param bloom bloomfilter, exclude these entries from the decision | ||
132 | * @return #GNUNET_YES if node location is closest, | ||
133 | * #GNUNET_NO otherwise. | ||
134 | */ | ||
135 | int | ||
136 | GDS_am_closest_peer (const struct GNUNET_HashCode *key, | ||
137 | const struct GNUNET_CONTAINER_BloomFilter *bloom); | ||
138 | |||
139 | |||
140 | |||
141 | /** | ||
126 | * Initialize neighbours subsystem. | 142 | * Initialize neighbours subsystem. |
127 | * | 143 | * |
128 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 144 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |