aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-09-21 09:45:07 +0000
committerNathan S. Evans <evans@in.tum.de>2010-09-21 09:45:07 +0000
commit8e2f9b241d28b1609a02b877965469b5428fcc76 (patch)
tree82f135b6069fb172c1f8110564d4515553718b3c /src
parent566e7833745056a73548c02d14717aa02cc816b9 (diff)
downloadgnunet-8e2f9b241d28b1609a02b877965469b5428fcc76.tar.gz
gnunet-8e2f9b241d28b1609a02b877965469b5428fcc76.zip
try new method for sending find peer requests
Diffstat (limited to 'src')
-rw-r--r--src/dht/gnunet-service-dht.c59
1 files changed, 53 insertions, 6 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 6655c76ba..c606f16ba 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -55,7 +55,13 @@
55/** 55/**
56 * Should the DHT issue FIND_PEER requests to get better routing tables? 56 * Should the DHT issue FIND_PEER requests to get better routing tables?
57 */ 57 */
58#define DO_FIND_PEER GNUNET_YES 58#define DEFAULT_DO_FIND_PEER GNUNET_YES
59
60/**
61 * Defines whether find peer requests send their HELLO's outgoing,
62 * or expect replies to contain hellos.
63 */
64#define FIND_PEER_WITH_HELLO GNUNET_YES
59 65
60/** 66/**
61 * What is the maximum number of peers in a given bucket. 67 * What is the maximum number of peers in a given bucket.
@@ -2248,11 +2254,42 @@ handle_dht_find_peer (void *cls,
2248 size_t hello_size; 2254 size_t hello_size;
2249 size_t tsize; 2255 size_t tsize;
2250 GNUNET_HashCode *recent_hash; 2256 GNUNET_HashCode *recent_hash;
2251#if RESTRICT_FIND_PEER 2257 struct GNUNET_MessageHeader *other_hello;
2258 size_t other_hello_size;
2252 struct GNUNET_PeerIdentity peer_id; 2259 struct GNUNET_PeerIdentity peer_id;
2253#endif
2254 2260
2255 find_peer_message = (struct GNUNET_DHT_FindPeerMessage *)find_msg; 2261 find_peer_message = (struct GNUNET_DHT_FindPeerMessage *)find_msg;
2262 GNUNET_break_op(ntohs(find_msg->size) >= (sizeof(struct GNUNET_DHT_FindPeerMessage)));
2263 if (ntohs(find_msg->size) < sizeof(struct GNUNET_DHT_FindPeerMessage))
2264 return;
2265 other_hello = NULL;
2266 other_hello_size = 0;
2267 if (ntohs(find_msg->size) > sizeof(struct GNUNET_DHT_FindPeerMessage))
2268 {
2269 other_hello_size = ntohs(find_msg->size) - sizeof(struct GNUNET_DHT_FindPeerMessage);
2270 other_hello = GNUNET_malloc(other_hello_size);
2271 memcpy(other_hello, &find_peer_message[1], other_hello_size);
2272 if ((GNUNET_HELLO_size((struct GNUNET_HELLO_Message *)other_hello) == 0) || (GNUNET_OK != GNUNET_HELLO_get_id((struct GNUNET_HELLO_Message *)other_hello, &peer_id)))
2273 {
2274 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Received invalid HELLO message in find peer request!\n");
2275 GNUNET_free(other_hello);
2276 return;
2277 }
2278#if FIND_PEER_WITH_HELLO
2279
2280 if (GNUNET_YES == consider_peer(&peer_id))
2281 {
2282 increment_stats(STAT_HELLOS_PROVIDED);
2283 GNUNET_TRANSPORT_offer_hello(transport_handle, other_hello);
2284 GNUNET_CORE_peer_request_connect(sched, cfg, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), &peer_id, NULL, NULL);
2285 }
2286 else /* We don't want this peer! */ /* Alternatively, just continue normally */
2287 return;
2288#endif
2289 }
2290
2291
2292
2256#if DEBUG_DHT 2293#if DEBUG_DHT
2257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2258 "`%s:%s': Received `%s' request from client, key %s (msg size %d, we expected %d)\n", 2295 "`%s:%s': Received `%s' request from client, key %s (msg size %d, we expected %d)\n",
@@ -2267,6 +2304,7 @@ handle_dht_find_peer (void *cls,
2267 "`%s': Our HELLO is null, can't return.\n", 2304 "`%s': Our HELLO is null, can't return.\n",
2268 "DHT"); 2305 "DHT");
2269#endif 2306#endif
2307 GNUNET_free_non_null(other_hello);
2270 return; 2308 return;
2271 } 2309 }
2272 2310
@@ -2275,6 +2313,7 @@ handle_dht_find_peer (void *cls,
2275 { 2313 {
2276 increment_stats(STAT_BLOOM_FIND_PEER); 2314 increment_stats(STAT_BLOOM_FIND_PEER);
2277 GNUNET_CONTAINER_bloomfilter_free(incoming_bloom); 2315 GNUNET_CONTAINER_bloomfilter_free(incoming_bloom);
2316 GNUNET_free_non_null(other_hello);
2278 return; /* We match the bloomfilter, do not send a response to this peer (they likely already know us!)*/ 2317 return; /* We match the bloomfilter, do not send a response to this peer (they likely already know us!)*/
2279 } 2318 }
2280 GNUNET_CONTAINER_bloomfilter_free(incoming_bloom); 2319 GNUNET_CONTAINER_bloomfilter_free(incoming_bloom);
@@ -2287,6 +2326,7 @@ handle_dht_find_peer (void *cls,
2287 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! */ 2326 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! */
2288 { 2327 {
2289 increment_stats("# dht find peer requests ignored (recently seen!)"); 2328 increment_stats("# dht find peer requests ignored (recently seen!)");
2329 GNUNET_free_non_null(other_hello);
2290 return; 2330 return;
2291 } 2331 }
2292 2332
@@ -2302,6 +2342,7 @@ handle_dht_find_peer (void *cls,
2302 if (GNUNET_NO == consider_peer(&peer_id)) 2342 if (GNUNET_NO == consider_peer(&peer_id))
2303 { 2343 {
2304 increment_stats("# dht find peer requests ignored (do not need!)"); 2344 increment_stats("# dht find peer requests ignored (do not need!)");
2345 GNUNET_free_non_null(other_hello);
2305 return; 2346 return;
2306 } 2347 }
2307#endif 2348#endif
@@ -2318,6 +2359,7 @@ handle_dht_find_peer (void *cls,
2318 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 2359 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
2319 { 2360 {
2320 GNUNET_break_op (0); 2361 GNUNET_break_op (0);
2362 GNUNET_free_non_null(other_hello);
2321 return; 2363 return;
2322 } 2364 }
2323 2365
@@ -2348,6 +2390,7 @@ handle_dht_find_peer (void *cls,
2348 &message_context->key); 2390 &message_context->key);
2349 } 2391 }
2350#endif 2392#endif
2393 GNUNET_free_non_null(other_hello);
2351 GNUNET_free(find_peer_result); 2394 GNUNET_free(find_peer_result);
2352} 2395}
2353 2396
@@ -3572,8 +3615,14 @@ send_find_peer_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
3572 } 3615 }
3573#endif 3616#endif
3574 3617
3618#if FIND_PEER_WITH_HELLO
3619 find_peer_msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_FindPeerMessage) + GNUNET_HELLO_size((struct GNUNET_HELLO_Message *)my_hello));
3620 find_peer_msg->header.size = htons(sizeof(struct GNUNET_DHT_FindPeerMessage) + GNUNET_HELLO_size((struct GNUNET_HELLO_Message *)my_hello));
3621 memcpy(&find_peer_msg[1], my_hello, GNUNET_HELLO_size((struct GNUNET_HELLO_Message *)my_hello));
3622#else
3575 find_peer_msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_FindPeerMessage)); 3623 find_peer_msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_FindPeerMessage));
3576 find_peer_msg->header.size = htons(sizeof(struct GNUNET_DHT_FindPeerMessage)); 3624 find_peer_msg->header.size = htons(sizeof(struct GNUNET_DHT_FindPeerMessage));
3625#endif
3577 find_peer_msg->header.type = htons(GNUNET_MESSAGE_TYPE_DHT_FIND_PEER); 3626 find_peer_msg->header.type = htons(GNUNET_MESSAGE_TYPE_DHT_FIND_PEER);
3578 temp_bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 3627 temp_bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
3579 GNUNET_CONTAINER_multihashmap_iterate(all_known_peers, &add_known_to_bloom, temp_bloom); 3628 GNUNET_CONTAINER_multihashmap_iterate(all_known_peers, &add_known_to_bloom, temp_bloom);
@@ -4092,9 +4141,7 @@ run (void *cls,
4092 struct GNUNET_SERVER_Handle *server, 4141 struct GNUNET_SERVER_Handle *server,
4093 const struct GNUNET_CONFIGURATION_Handle *c) 4142 const struct GNUNET_CONFIGURATION_Handle *c)
4094{ 4143{
4095#if DO_FIND_PEER
4096 struct GNUNET_TIME_Relative next_send_time; 4144 struct GNUNET_TIME_Relative next_send_time;
4097#endif
4098 unsigned long long temp_config_num; 4145 unsigned long long temp_config_num;
4099 char *converge_modifier_buf; 4146 char *converge_modifier_buf;
4100 sched = scheduler; 4147 sched = scheduler;
@@ -4167,7 +4214,7 @@ run (void *cls,
4167 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY; 4214 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
4168 } 4215 }
4169 4216
4170 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", 4217 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
4171 "MAX_HOPS", 4218 "MAX_HOPS",
4172 &max_hops)) 4219 &max_hops))
4173 { 4220 {