aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-08-10 15:23:21 +0000
committerNathan S. Evans <evans@in.tum.de>2010-08-10 15:23:21 +0000
commit0cd34604e5497edad8fa3a761ef626ad7168c90a (patch)
tree980215ff8a81f9b897e32c8ccad833652c3bf6d6 /src/dht/gnunet-service-dht.c
parentda1d8fd60b46ccdeb9c9e09b58e0a2bb89db3bfd (diff)
downloadgnunet-0cd34604e5497edad8fa3a761ef626ad7168c90a.tar.gz
gnunet-0cd34604e5497edad8fa3a761ef626ad7168c90a.zip
lots of little things, mainly report statistics at end of dht profiling testcase
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r--src/dht/gnunet-service-dht.c163
1 files changed, 154 insertions, 9 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 1201b5a2f..33c85c7d4 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -38,6 +38,7 @@
38#include "gnunet_transport_service.h" 38#include "gnunet_transport_service.h"
39#include "gnunet_hello_lib.h" 39#include "gnunet_hello_lib.h"
40#include "gnunet_dht_service.h" 40#include "gnunet_dht_service.h"
41#include "gnunet_statistics_service.h"
41#include "dhtlog.h" 42#include "dhtlog.h"
42#include "dht.h" 43#include "dht.h"
43 44
@@ -70,7 +71,18 @@
70 71
71#define DHT_DEFAULT_FIND_PEER_OPTIONS GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE 72#define DHT_DEFAULT_FIND_PEER_OPTIONS GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
72 73
73#define DHT_DEFAULT_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1) 74#define DHT_MINIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1)
75#define DHT_MAXIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
76
77/*
78 * Default frequency for sending malicious get messages
79 */
80#define DEFAULT_MALICIOUS_GET_FREQUENCY 1 /* Number of seconds */
81
82/*
83 * Default frequency for sending malicious put messages
84 */
85#define DEFAULT_MALICIOUS_PUT_FREQUENCY 1 /* Default is seconds */
74 86
75#define DHT_DEFAULT_PING_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1) 87#define DHT_DEFAULT_PING_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1)
76 88
@@ -112,6 +124,7 @@ struct P2PPendingMessage
112 124
113}; 125};
114 126
127
115/** 128/**
116 * Per-peer information. 129 * Per-peer information.
117 */ 130 */
@@ -437,6 +450,11 @@ static struct DHTResults forward_list;
437static struct GNUNET_DATACACHE_Handle *datacache; 450static struct GNUNET_DATACACHE_Handle *datacache;
438 451
439/** 452/**
453 * Handle for the statistics service.
454 */
455struct GNUNET_STATISTICS_Handle *stats;
456
457/**
440 * The main scheduler to use for the DHT service 458 * The main scheduler to use for the DHT service
441 */ 459 */
442static struct GNUNET_SCHEDULER_Handle *sched; 460static struct GNUNET_SCHEDULER_Handle *sched;
@@ -519,6 +537,28 @@ static unsigned int debug_routes;
519 */ 537 */
520static unsigned int debug_routes_extended; 538static unsigned int debug_routes_extended;
521 539
540/*
541 * GNUNET_YES or GNUNET_NO, whether or not to act as
542 * a malicious node which drops all messages
543 */
544static unsigned int malicious_dropper;
545
546/*
547 * GNUNET_YES or GNUNET_NO, whether or not to act as
548 * a malicious node which sends out lots of GETS
549 */
550static unsigned int malicious_getter;
551
552/*
553 * GNUNET_YES or GNUNET_NO, whether or not to act as
554 * a malicious node which sends out lots of PUTS
555 */
556static unsigned int malicious_putter;
557
558static unsigned long long malicious_get_frequency;
559
560static unsigned long long malicious_put_frequency;
561
522/** 562/**
523 * Forward declaration. 563 * Forward declaration.
524 */ 564 */
@@ -528,6 +568,15 @@ static size_t send_generic_reply (void *cls, size_t size, void *buf);
528size_t core_transmit_notify (void *cls, 568size_t core_transmit_notify (void *cls,
529 size_t size, void *buf); 569 size_t size, void *buf);
530 570
571static void
572increment_stats(const char *value)
573{
574 if (stats != NULL)
575 {
576 GNUNET_STATISTICS_update (stats, value, 1, GNUNET_NO);
577 }
578}
579
531/** 580/**
532 * Try to send another message from our core send list 581 * Try to send another message from our core send list
533 */ 582 */
@@ -582,6 +631,7 @@ static void forward_result_message (void *cls,
582 size_t msize; 631 size_t msize;
583 size_t psize; 632 size_t psize;
584 633
634 increment_stats(STAT_RESULT_FORWARDS);
585 msize = sizeof (struct GNUNET_DHT_P2PRouteResultMessage) + ntohs(msg->size); 635 msize = sizeof (struct GNUNET_DHT_P2PRouteResultMessage) + ntohs(msg->size);
586 GNUNET_assert(msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE); 636 GNUNET_assert(msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE);
587 psize = sizeof(struct P2PPendingMessage) + msize; 637 psize = sizeof(struct P2PPendingMessage) + msize;
@@ -1087,6 +1137,7 @@ static void forward_message (void *cls,
1087 size_t msize; 1137 size_t msize;
1088 size_t psize; 1138 size_t psize;
1089 1139
1140 increment_stats(STAT_ROUTE_FORWARDS);
1090 msize = sizeof (struct GNUNET_DHT_P2PRouteMessage) + ntohs(msg->size); 1141 msize = sizeof (struct GNUNET_DHT_P2PRouteMessage) + ntohs(msg->size);
1091 GNUNET_assert(msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE); 1142 GNUNET_assert(msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE);
1092 psize = sizeof(struct P2PPendingMessage) + msize; 1143 psize = sizeof(struct P2PPendingMessage) + msize;
@@ -1348,6 +1399,8 @@ static int consider_peer (struct GNUNET_PeerIdentity *peer)
1348{ 1399{
1349 int bucket; 1400 int bucket;
1350 1401
1402 if (GNUNET_CONTAINER_multihashmap_contains(all_known_peers, &peer->hashPubKey))
1403 return GNUNET_NO; /* We already know this peer (are connected even!) */
1351 bucket = find_current_bucket(&peer->hashPubKey); 1404 bucket = find_current_bucket(&peer->hashPubKey);
1352 if ((k_buckets[bucket].peers_size < bucket_size) || ((bucket == lowest_bucket) && (lowest_bucket > 0))) 1405 if ((k_buckets[bucket].peers_size < bucket_size) || ((bucket == lowest_bucket) && (lowest_bucket > 0)))
1353 return GNUNET_YES; 1406 return GNUNET_YES;
@@ -1373,6 +1426,7 @@ static int route_result_message(void *cls,
1373 struct PeerInfo *peer_info; 1426 struct PeerInfo *peer_info;
1374 const struct GNUNET_MessageHeader *hello_msg; 1427 const struct GNUNET_MessageHeader *hello_msg;
1375 1428
1429 increment_stats(STAT_RESULTS);
1376 /** 1430 /**
1377 * If a find peer result message is received and contains a valid 1431 * If a find peer result message is received and contains a valid
1378 * HELLO for another peer, offer it to the transport service. 1432 * HELLO for another peer, offer it to the transport service.
@@ -1390,6 +1444,7 @@ static int route_result_message(void *cls,
1390 } 1444 }
1391 else /* We have a valid hello, and peer id stored in new_peer */ 1445 else /* We have a valid hello, and peer id stored in new_peer */
1392 { 1446 {
1447 increment_stats(STAT_FIND_PEER_REPLY);
1393 if (GNUNET_YES == consider_peer(&new_peer)) 1448 if (GNUNET_YES == consider_peer(&new_peer))
1394 { 1449 {
1395 GNUNET_TRANSPORT_offer_hello(transport_handle, hello_msg); 1450 GNUNET_TRANSPORT_offer_hello(transport_handle, hello_msg);
@@ -1449,6 +1504,10 @@ static int route_result_message(void *cls,
1449 message_context->peer, NULL); 1504 message_context->peer, NULL);
1450 } 1505 }
1451#endif 1506#endif
1507 increment_stats(STAT_RESULTS_TO_CLIENT);
1508 if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET_RESULT)
1509 increment_stats(STAT_GET_REPLY);
1510
1452 send_reply_to_client(pos->client, msg, message_context->unique_id); 1511 send_reply_to_client(pos->client, msg, message_context->unique_id);
1453 } 1512 }
1454 else /* Send to peer */ 1513 else /* Send to peer */
@@ -1537,6 +1596,7 @@ datacache_get_iterator (void *cls,
1537 new_msg_ctx->peer = &my_identity; 1596 new_msg_ctx->peer = &my_identity;
1538 new_msg_ctx->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 1597 new_msg_ctx->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
1539 new_msg_ctx->hop_count = 0; 1598 new_msg_ctx->hop_count = 0;
1599 increment_stats(STAT_GET_RESPONSE_START);
1540 route_result_message(cls, &get_result->header, new_msg_ctx); 1600 route_result_message(cls, &get_result->header, new_msg_ctx);
1541 GNUNET_free(new_msg_ctx); 1601 GNUNET_free(new_msg_ctx);
1542 //send_reply_to_client (datacache_get_ctx->client, &get_result->header, 1602 //send_reply_to_client (datacache_get_ctx->client, &get_result->header,
@@ -1575,11 +1635,11 @@ handle_dht_get (void *cls,
1575 get_type = ntohs (get_msg->type); 1635 get_type = ntohs (get_msg->type);
1576#if DEBUG_DHT 1636#if DEBUG_DHT
1577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1578 "`%s:%s': Received `%s' request from client, message type %u, key %s, uid %llu\n", my_short_id, 1638 "`%s:%s': Received `%s' request, message type %u, key %s, uid %llu\n", my_short_id,
1579 "DHT", "GET", get_type, GNUNET_h2s (message_context->key), 1639 "DHT", "GET", get_type, GNUNET_h2s (message_context->key),
1580 message_context->unique_id); 1640 message_context->unique_id);
1581#endif 1641#endif
1582 1642 increment_stats(STAT_GETS);
1583 results = 0; 1643 results = 0;
1584 if (datacache != NULL) 1644 if (datacache != NULL)
1585 results = 1645 results =
@@ -1685,6 +1745,7 @@ handle_dht_find_peer (void *cls,
1685 new_msg_ctx->peer = &my_identity; 1745 new_msg_ctx->peer = &my_identity;
1686 new_msg_ctx->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 1746 new_msg_ctx->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
1687 new_msg_ctx->hop_count = 0; 1747 new_msg_ctx->hop_count = 0;
1748 increment_stats(STAT_FIND_PEER_ANSWER);
1688 route_result_message(cls, find_peer_result, new_msg_ctx); 1749 route_result_message(cls, find_peer_result, new_msg_ctx);
1689 GNUNET_free(new_msg_ctx); 1750 GNUNET_free(new_msg_ctx);
1690#if DEBUG_DHT_ROUTING 1751#if DEBUG_DHT_ROUTING
@@ -1726,8 +1787,8 @@ handle_dht_put (void *cls,
1726 "`%s:%s': Received `%s' request (inserting data!), message type %d, key %s, uid %llu\n", 1787 "`%s:%s': Received `%s' request (inserting data!), message type %d, key %s, uid %llu\n",
1727 my_short_id, "DHT", "PUT", put_type, GNUNET_h2s (message_context->key), message_context->unique_id); 1788 my_short_id, "DHT", "PUT", put_type, GNUNET_h2s (message_context->key), message_context->unique_id);
1728#endif 1789#endif
1790 increment_stats(STAT_PUTS_INSERTED);
1729#if DEBUG_DHT_ROUTING 1791#if DEBUG_DHT_ROUTING
1730
1731 if ((debug_routes) && (dhtlog_handle != NULL)) 1792 if ((debug_routes) && (dhtlog_handle != NULL))
1732 { 1793 {
1733 dhtlog_handle->insert_query (NULL, message_context->unique_id, DHTLOG_PUT, 1794 dhtlog_handle->insert_query (NULL, message_context->unique_id, DHTLOG_PUT,
@@ -2178,6 +2239,7 @@ static int route_message(void *cls,
2178 int ret; 2239 int ret;
2179#endif 2240#endif
2180 2241
2242 increment_stats(STAT_ROUTES);
2181 message_context->closest = am_closest_peer(message_context->key); 2243 message_context->closest = am_closest_peer(message_context->key);
2182 forward_count = get_forward_count(message_context->hop_count, message_context->replication); 2244 forward_count = get_forward_count(message_context->hop_count, message_context->replication);
2183 nearest = find_closest_peer(message_context->key); 2245 nearest = find_closest_peer(message_context->key);
@@ -2212,6 +2274,7 @@ static int route_message(void *cls,
2212 forward_count = 0; 2274 forward_count = 0;
2213 break; 2275 break;
2214 case GNUNET_MESSAGE_TYPE_DHT_PUT: /* Check if closest, if so insert data. FIXME: thresholding to reduce complexity?*/ 2276 case GNUNET_MESSAGE_TYPE_DHT_PUT: /* Check if closest, if so insert data. FIXME: thresholding to reduce complexity?*/
2277 increment_stats(STAT_PUTS);
2215 if (message_context->closest == GNUNET_YES) 2278 if (message_context->closest == GNUNET_YES)
2216 { 2279 {
2217#if DEBUG_DHT_ROUTING 2280#if DEBUG_DHT_ROUTING
@@ -2238,6 +2301,7 @@ static int route_message(void *cls,
2238#endif 2301#endif
2239 break; 2302 break;
2240 case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */ 2303 case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */
2304 increment_stats(STAT_FIND_PEER);
2241 if (((message_context->hop_count > 0) && (0 != memcmp(message_context->peer, &my_identity, sizeof(struct GNUNET_PeerIdentity)))) || (message_context->client != NULL)) 2305 if (((message_context->hop_count > 0) && (0 != memcmp(message_context->peer, &my_identity, sizeof(struct GNUNET_PeerIdentity)))) || (message_context->client != NULL))
2242 { 2306 {
2243 cache_response (cls, message_context); 2307 cache_response (cls, message_context);
@@ -2356,6 +2420,8 @@ send_find_peer_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
2356 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 2420 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
2357 return; 2421 return;
2358 2422
2423 increment_stats(STAT_FIND_PEER_START);
2424
2359 find_peer_msg = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader)); 2425 find_peer_msg = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
2360 find_peer_msg->size = htons(sizeof(struct GNUNET_MessageHeader)); 2426 find_peer_msg->size = htons(sizeof(struct GNUNET_MessageHeader));
2361 find_peer_msg->type = htons(GNUNET_MESSAGE_TYPE_DHT_FIND_PEER); 2427 find_peer_msg->type = htons(GNUNET_MESSAGE_TYPE_DHT_FIND_PEER);
@@ -2372,8 +2438,9 @@ send_find_peer_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
2372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2373 "`%s:%s': Sent `%s' request to %d peers\n", my_short_id, "DHT", 2439 "`%s:%s': Sent `%s' request to %d peers\n", my_short_id, "DHT",
2374 "FIND PEER", ret); 2440 "FIND PEER", ret);
2375 next_send_time = DHT_DEFAULT_FIND_PEER_INTERVAL; 2441 next_send_time.value = DHT_MINIMUM_FIND_PEER_INTERVAL.value +
2376 next_send_time.value = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, next_send_time.value * 3); 2442 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG,
2443 DHT_MAXIMUM_FIND_PEER_INTERVAL.value - DHT_MINIMUM_FIND_PEER_INTERVAL.value);
2377 GNUNET_SCHEDULER_add_delayed (sched, 2444 GNUNET_SCHEDULER_add_delayed (sched,
2378 next_send_time, 2445 next_send_time,
2379 &send_find_peer_message, NULL); 2446 &send_find_peer_message, NULL);
@@ -2419,6 +2486,13 @@ handle_dht_local_route_request (void *cls, struct GNUNET_SERVER_Client *client,
2419 message_context.network_size = estimate_diameter(); 2486 message_context.network_size = estimate_diameter();
2420 message_context.peer = &my_identity; 2487 message_context.peer = &my_identity;
2421 2488
2489 if (ntohs(enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_GET)
2490 increment_stats(STAT_GET_START);
2491 else if (ntohs(enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)
2492 increment_stats(STAT_PUT_START);
2493 else if (ntohs(enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_FIND_PEER)
2494 increment_stats(STAT_FIND_PEER_START);
2495
2422 route_message(cls, enc_msg, &message_context); 2496 route_message(cls, enc_msg, &message_context);
2423 2497
2424 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2498 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -2541,6 +2615,7 @@ handle_dht_p2p_route_result (void *cls,
2541 GNUNET_break_op(0); 2615 GNUNET_break_op(0);
2542 return GNUNET_YES; 2616 return GNUNET_YES;
2543 } 2617 }
2618
2544 memset(&message_context, 0, sizeof(struct DHT_MessageContext)); 2619 memset(&message_context, 0, sizeof(struct DHT_MessageContext));
2545 message_context.bloom = GNUNET_CONTAINER_bloomfilter_init(incoming->bloomfilter, DHT_BLOOM_SIZE, DHT_BLOOM_K); 2620 message_context.bloom = GNUNET_CONTAINER_bloomfilter_init(incoming->bloomfilter, DHT_BLOOM_SIZE, DHT_BLOOM_K);
2546 GNUNET_assert(message_context.bloom != NULL); 2621 GNUNET_assert(message_context.bloom != NULL);
@@ -2576,6 +2651,7 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message)
2576 memcpy(my_hello, message, ntohs(message->size)); 2651 memcpy(my_hello, message, ntohs(message->size));
2577} 2652}
2578 2653
2654
2579/** 2655/**
2580 * Task run during shutdown. 2656 * Task run during shutdown.
2581 * 2657 *
@@ -2587,7 +2663,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2587{ 2663{
2588 int bucket_count; 2664 int bucket_count;
2589 struct PeerInfo *pos; 2665 struct PeerInfo *pos;
2590
2591 if (transport_handle != NULL) 2666 if (transport_handle != NULL)
2592 { 2667 {
2593 GNUNET_free_non_null(my_hello); 2668 GNUNET_free_non_null(my_hello);
@@ -2624,6 +2699,11 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2624 GNUNET_DATACACHE_destroy (datacache); 2699 GNUNET_DATACACHE_destroy (datacache);
2625 } 2700 }
2626 2701
2702 if (stats != NULL)
2703 {
2704 GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
2705 }
2706
2627 if (dhtlog_handle != NULL) 2707 if (dhtlog_handle != NULL)
2628 GNUNET_DHTLOG_disconnect(dhtlog_handle); 2708 GNUNET_DHTLOG_disconnect(dhtlog_handle);
2629 2709
@@ -2662,8 +2742,11 @@ core_init (void *cls,
2662 "%s: Core connection initialized, I am peer: %s\n", "dht", 2742 "%s: Core connection initialized, I am peer: %s\n", "dht",
2663 GNUNET_i2s (identity)); 2743 GNUNET_i2s (identity));
2664#endif 2744#endif
2745
2665 /* Copy our identity so we can use it */ 2746 /* Copy our identity so we can use it */
2666 memcpy (&my_identity, identity, sizeof (struct GNUNET_PeerIdentity)); 2747 memcpy (&my_identity, identity, sizeof (struct GNUNET_PeerIdentity));
2748 if (my_short_id != NULL)
2749 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s Receive CORE INIT message but have already been initialized! Did CORE fail?\n", "DHT SERVICE");
2667 my_short_id = GNUNET_strdup(GNUNET_i2s(&my_identity)); 2750 my_short_id = GNUNET_strdup(GNUNET_i2s(&my_identity));
2668 /* Set the server to local variable */ 2751 /* Set the server to local variable */
2669 coreAPI = server; 2752 coreAPI = server;
@@ -2705,6 +2788,13 @@ void handle_core_connect (void *cls,
2705 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2706 "%s:%s Receives core connect message for peer %s distance %d!\n", my_short_id, "dht", GNUNET_i2s(peer), distance); 2789 "%s:%s Receives core connect message for peer %s distance %d!\n", my_short_id, "dht", GNUNET_i2s(peer), distance);
2707#endif 2790#endif
2791
2792 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(all_known_peers, &peer->hashPubKey))
2793 {
2794 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s:%s Received %s message for peer %s, but already have peer in RT!", my_short_id, "DHT", "CORE CONNECT", GNUNET_i2s(peer));
2795 return;
2796 }
2797
2708 if (datacache != NULL) 2798 if (datacache != NULL)
2709 GNUNET_DATACACHE_put(datacache, &peer->hashPubKey, sizeof(struct GNUNET_PeerIdentity), (const char *)peer, 0, GNUNET_TIME_absolute_get_forever()); 2799 GNUNET_DATACACHE_put(datacache, &peer->hashPubKey, sizeof(struct GNUNET_PeerIdentity), (const char *)peer, 0, GNUNET_TIME_absolute_get_forever());
2710 ret = try_add_peer(peer, 2800 ret = try_add_peer(peer,
@@ -2736,6 +2826,11 @@ void handle_core_disconnect (void *cls,
2736 2826
2737 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s:%s: Received peer disconnect message for peer `%s' from %s\n", my_short_id, "DHT", GNUNET_i2s(peer), "CORE"); 2827 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s:%s: Received peer disconnect message for peer `%s' from %s\n", my_short_id, "DHT", GNUNET_i2s(peer), "CORE");
2738 2828
2829 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains(all_known_peers, &peer->hashPubKey))
2830 {
2831 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s: do not have peer `%s' in RT, can't disconnect!\n", my_short_id, "DHT", GNUNET_i2s(peer));
2832 return;
2833 }
2739 GNUNET_assert(GNUNET_CONTAINER_multihashmap_contains(all_known_peers, &peer->hashPubKey)); 2834 GNUNET_assert(GNUNET_CONTAINER_multihashmap_contains(all_known_peers, &peer->hashPubKey));
2740 to_remove = GNUNET_CONTAINER_multihashmap_get(all_known_peers, &peer->hashPubKey); 2835 to_remove = GNUNET_CONTAINER_multihashmap_get(all_known_peers, &peer->hashPubKey);
2741 GNUNET_assert(0 == memcmp(peer, &to_remove->id, sizeof(struct GNUNET_PeerIdentity))); 2836 GNUNET_assert(0 == memcmp(peer, &to_remove->id, sizeof(struct GNUNET_PeerIdentity)));
@@ -2768,7 +2863,7 @@ run (void *cls,
2768 NULL, /* Closure passed to DHT functionas around? */ 2863 NULL, /* Closure passed to DHT functionas around? */
2769 &core_init, /* Call core_init once connected */ 2864 &core_init, /* Call core_init once connected */
2770 &handle_core_connect, /* Handle connects */ 2865 &handle_core_connect, /* Handle connects */
2771 &handle_core_disconnect, /* FIXME: remove peers on disconnects */ 2866 &handle_core_disconnect, /* remove peers on disconnects */
2772 NULL, /* Do we care about "status" updates? */ 2867 NULL, /* Do we care about "status" updates? */
2773 NULL, /* Don't want notified about all incoming messages */ 2868 NULL, /* Don't want notified about all incoming messages */
2774 GNUNET_NO, /* For header only inbound notification */ 2869 GNUNET_NO, /* For header only inbound notification */
@@ -2810,6 +2905,35 @@ run (void *cls,
2810 } 2905 }
2811 2906
2812 if (GNUNET_YES == 2907 if (GNUNET_YES ==
2908 GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht",
2909 "malicious_getter"))
2910 {
2911 malicious_getter = GNUNET_YES;
2912 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
2913 "MALICIOUS_GET_FREQUENCY",
2914 &malicious_get_frequency))
2915 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
2916 }
2917
2918 if (GNUNET_YES ==
2919 GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht",
2920 "malicious_putter"))
2921 {
2922 malicious_putter = GNUNET_YES;
2923 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
2924 "MALICIOUS_PUT_FREQUENCY",
2925 &malicious_put_frequency))
2926 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
2927 }
2928
2929 if (GNUNET_YES ==
2930 GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht",
2931 "malicious_dropper"))
2932 {
2933 malicious_dropper = GNUNET_YES;
2934 }
2935
2936 if (GNUNET_YES ==
2813 GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", 2937 GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing",
2814 "mysql_logging_extended")) 2938 "mysql_logging_extended"))
2815 { 2939 {
@@ -2827,10 +2951,31 @@ run (void *cls,
2827 } 2951 }
2828 } 2952 }
2829 2953
2954 stats = GNUNET_STATISTICS_create(sched, "dht", cfg);
2955
2956 if (stats != NULL)
2957 {
2958 GNUNET_STATISTICS_set(stats, STAT_ROUTES, 0, GNUNET_NO);
2959 GNUNET_STATISTICS_set(stats, STAT_ROUTE_FORWARDS, 0, GNUNET_NO);
2960 GNUNET_STATISTICS_set(stats, STAT_RESULTS, 0, GNUNET_NO);
2961 GNUNET_STATISTICS_set(stats, STAT_RESULTS_TO_CLIENT, 0, GNUNET_NO);
2962 GNUNET_STATISTICS_set(stats, STAT_RESULT_FORWARDS, 0, GNUNET_NO);
2963 GNUNET_STATISTICS_set(stats, STAT_GETS, 0, GNUNET_NO);
2964 GNUNET_STATISTICS_set(stats, STAT_PUTS, 0, GNUNET_NO);
2965 GNUNET_STATISTICS_set(stats, STAT_PUTS_INSERTED, 0, GNUNET_NO);
2966 GNUNET_STATISTICS_set(stats, STAT_FIND_PEER, 0, GNUNET_NO);
2967 GNUNET_STATISTICS_set(stats, STAT_FIND_PEER_START, 0, GNUNET_NO);
2968 GNUNET_STATISTICS_set(stats, STAT_GET_START, 0, GNUNET_NO);
2969 GNUNET_STATISTICS_set(stats, STAT_PUT_START, 0, GNUNET_NO);
2970 GNUNET_STATISTICS_set(stats, STAT_FIND_PEER_REPLY, 0, GNUNET_NO);
2971 GNUNET_STATISTICS_set(stats, STAT_FIND_PEER_ANSWER, 0, GNUNET_NO);
2972 GNUNET_STATISTICS_set(stats, STAT_GET_REPLY, 0, GNUNET_NO);
2973 GNUNET_STATISTICS_set(stats, STAT_GET_RESPONSE_START, 0, GNUNET_NO);
2974 }
2830#if DO_FIND_PEER 2975#if DO_FIND_PEER
2831 random_seconds = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 180); 2976 random_seconds = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 180);
2832 GNUNET_SCHEDULER_add_delayed (sched, 2977 GNUNET_SCHEDULER_add_delayed (sched,
2833 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), 2978 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, random_seconds),
2834 &send_find_peer_message, NULL); 2979 &send_find_peer_message, NULL);
2835#endif 2980#endif
2836 2981