aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r--src/dht/gnunet-service-dht.c93
1 files changed, 45 insertions, 48 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 237db023c..a68ba5563 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -858,10 +858,9 @@ static struct GNUNET_NSE_Handle *nse;
858 * @param std_dev standard deviation for the estimate 858 * @param std_dev standard deviation for the estimate
859 * 859 *
860 */ 860 */
861static void 861static void
862update_network_size_estimate (void *cls, 862update_network_size_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
863 struct GNUNET_TIME_Absolute timestamp, 863 double logestimate, double std_dev)
864 double logestimate, double std_dev)
865{ 864{
866 log_of_network_size_estimate = logestimate; 865 log_of_network_size_estimate = logestimate;
867} 866}
@@ -947,7 +946,7 @@ increment_stats (const char *value)
947{ 946{
948 if (stats == NULL) 947 if (stats == NULL)
949 return; 948 return;
950 GNUNET_STATISTICS_update (stats, value, 1, GNUNET_NO); 949 GNUNET_STATISTICS_update (stats, value, 1, GNUNET_NO);
951} 950}
952 951
953 952
@@ -956,7 +955,7 @@ decrement_stats (const char *value)
956{ 955{
957 if (stats == NULL) 956 if (stats == NULL)
958 return; 957 return;
959 GNUNET_STATISTICS_update (stats, value, -1, GNUNET_NO); 958 GNUNET_STATISTICS_update (stats, value, -1, GNUNET_NO);
960} 959}
961 960
962 961
@@ -1630,8 +1629,7 @@ forward_message (const struct GNUNET_MessageHeader *msg, struct PeerInfo *peer,
1630static void 1629static void
1631process_pending_messages (struct ClientList *client) 1630process_pending_messages (struct ClientList *client)
1632{ 1631{
1633 if ( (client->pending_head == NULL) || 1632 if ((client->pending_head == NULL) || (client->transmit_handle != NULL))
1634 (client->transmit_handle != NULL) )
1635 return; 1633 return;
1636 client->transmit_handle = 1634 client->transmit_handle =
1637 GNUNET_SERVER_notify_transmit_ready (client->client_handle, 1635 GNUNET_SERVER_notify_transmit_ready (client->client_handle,
@@ -2659,7 +2657,8 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2659#endif 2657#endif
2660 2658
2661// GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "******************************************************** PUT 1\n"); 2659// GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "******************************************************** PUT 1\n");
2662 record = GNUNET_CONTAINER_multihashmap_get(forward_list.hashmap, &msg_ctx->key); 2660 record =
2661 GNUNET_CONTAINER_multihashmap_get (forward_list.hashmap, &msg_ctx->key);
2663 if (NULL != record) 2662 if (NULL != record)
2664 { 2663 {
2665 struct DHTRouteSource *pos; 2664 struct DHTRouteSource *pos;
@@ -2675,16 +2674,16 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2675 if (NULL == pos->client) 2674 if (NULL == pos->client)
2676 continue; 2675 continue;
2677 2676
2678 gsize = data_size + sizeof(struct GNUNET_DHT_GetMessage); 2677 gsize = data_size + sizeof (struct GNUNET_DHT_GetMessage);
2679 gmsg = GNUNET_malloc(gsize); 2678 gmsg = GNUNET_malloc (gsize);
2680 gmsg->header.type = htons(GNUNET_MESSAGE_TYPE_DHT_GET_RESULT); 2679 gmsg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET_RESULT);
2681 gmsg->header.size = htons(gsize); 2680 gmsg->header.size = htons (gsize);
2682 gmsg->type = put_msg->type; 2681 gmsg->type = put_msg->type;
2683 memcpy(&gmsg[1], &put_msg[1], data_size); 2682 memcpy (&gmsg[1], &put_msg[1], data_size);
2684 2683
2685 /* TODO: duplicate and reverse order of path_history? */ 2684 /* TODO: duplicate and reverse order of path_history? */
2686 send_reply_to_client (pos->client, &gmsg->header, msg_ctx); 2685 send_reply_to_client (pos->client, &gmsg->header, msg_ctx);
2687 GNUNET_free(gmsg); 2686 GNUNET_free (gmsg);
2688 } 2687 }
2689 } 2688 }
2690// GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "******************************************************** PUT END\n"); 2689// GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "******************************************************** PUT END\n");
@@ -2783,20 +2782,20 @@ get_forward_count (unsigned int hop_count, size_t target_replication)
2783 { 2782 {
2784 if (hop_count == 0) 2783 if (hop_count == 0)
2785 return kademlia_replication; 2784 return kademlia_replication;
2786 if (hop_count < log_of_network_size_estimate * 2.0) 2785 if (hop_count < log_of_network_size_estimate * 2.0)
2787 return 1; 2786 return 1;
2788 return 0; 2787 return 0;
2789 } 2788 }
2790 2789
2791 if (hop_count > log_of_network_size_estimate * 2.0) 2790 if (hop_count > log_of_network_size_estimate * 2.0)
2792 { 2791 {
2793 if (GNUNET_YES == paper_forwarding) 2792 if (GNUNET_YES == paper_forwarding)
2794 { 2793 {
2795 /* Once we have reached our ideal number of hops, don't stop forwarding! */ 2794 /* Once we have reached our ideal number of hops, don't stop forwarding! */
2796 return 1; 2795 return 1;
2797 } 2796 }
2798#if DEBUG_DHT 2797#if DEBUG_DHT
2799 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2800 "Hop count too high (est %f, lowest %d), NOT Forwarding request\n", 2799 "Hop count too high (est %f, lowest %d), NOT Forwarding request\n",
2801 log_of_network_size_estimate * 2.0, lowest_bucket); 2800 log_of_network_size_estimate * 2.0, lowest_bucket);
2802#endif 2801#endif
@@ -2893,7 +2892,7 @@ am_closest_peer (const GNUNET_HashCode * target,
2893 { 2892 {
2894 if (strict_kademlia != GNUNET_YES) /* Return that we at as close as any other peer */ 2893 if (strict_kademlia != GNUNET_YES) /* Return that we at as close as any other peer */
2895 return GNUNET_YES; 2894 return GNUNET_YES;
2896 if (distance (&pos->id.hashPubKey, target) < my_distance) /* Check all known peers, only return if we are the true closest */ 2895 if (distance (&pos->id.hashPubKey, target) < my_distance) /* Check all known peers, only return if we are the true closest */
2897 return GNUNET_NO; 2896 return GNUNET_NO;
2898 } 2897 }
2899 pos = pos->next; 2898 pos = pos->next;
@@ -2932,8 +2931,7 @@ select_peer (const GNUNET_HashCode * target,
2932 struct PeerInfo *chosen; 2931 struct PeerInfo *chosen;
2933 2932
2934 /** If we are doing kademlia routing (saves some cycles) */ 2933 /** If we are doing kademlia routing (saves some cycles) */
2935 if ( (strict_kademlia == GNUNET_YES) || 2934 if ((strict_kademlia == GNUNET_YES) || (hops >= log_of_network_size_estimate))
2936 (hops >= log_of_network_size_estimate) )
2937 { 2935 {
2938 /* greedy selection (closest peer that is not in bloomfilter) */ 2936 /* greedy selection (closest peer that is not in bloomfilter) */
2939 largest_distance = 0; 2937 largest_distance = 0;
@@ -2964,7 +2962,7 @@ select_peer (const GNUNET_HashCode * target,
2964 GNUNET_CONTAINER_bloomfilter_add (bloom, &chosen->id.hashPubKey); 2962 GNUNET_CONTAINER_bloomfilter_add (bloom, &chosen->id.hashPubKey);
2965 return chosen; 2963 return chosen;
2966 } 2964 }
2967 return NULL; /* no peer available or we are the closest */ 2965 return NULL; /* no peer available or we are the closest */
2968 } 2966 }
2969 2967
2970 2968
@@ -2986,14 +2984,13 @@ select_peer (const GNUNET_HashCode * target,
2986 pos = pos->next; 2984 pos = pos->next;
2987 } 2985 }
2988 } 2986 }
2989 if (count == 0) /* No peers to select from! */ 2987 if (count == 0) /* No peers to select from! */
2990 { 2988 {
2991 increment_stats ("# failed to select peer"); 2989 increment_stats ("# failed to select peer");
2992 return NULL; 2990 return NULL;
2993 } 2991 }
2994 /* Now actually choose a peer */ 2992 /* Now actually choose a peer */
2995 selected = 2993 selected = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, count);
2996 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, count);
2997 count = 0; 2994 count = 0;
2998 for (bc = lowest_bucket; bc < MAX_BUCKETS; bc++) 2995 for (bc = lowest_bucket; bc < MAX_BUCKETS; bc++)
2999 { 2996 {
@@ -3007,7 +3004,7 @@ select_peer (const GNUNET_HashCode * target,
3007 continue; /* Ignore bloomfiltered peers */ 3004 continue; /* Ignore bloomfiltered peers */
3008 } 3005 }
3009 if (0 == selected--) 3006 if (0 == selected--)
3010 return pos; 3007 return pos;
3011 pos = pos->next; 3008 pos = pos->next;
3012 } 3009 }
3013 } 3010 }
@@ -3105,10 +3102,10 @@ cache_response (struct DHT_MessageContext *msg_ctx)
3105 pos = record->head; 3102 pos = record->head;
3106 while (pos != NULL) 3103 while (pos != NULL)
3107 { 3104 {
3108 if ( (NULL != msg_ctx->peer) && 3105 if ((NULL != msg_ctx->peer) &&
3109 (0 == 3106 (0 ==
3110 memcmp (msg_ctx->peer, &pos->source, 3107 memcmp (msg_ctx->peer, &pos->source,
3111 sizeof (struct GNUNET_PeerIdentity))) ) 3108 sizeof (struct GNUNET_PeerIdentity))))
3112 break; /* Already have this peer in reply list! */ 3109 break; /* Already have this peer in reply list! */
3113 pos = pos->next; 3110 pos = pos->next;
3114 } 3111 }
@@ -3280,7 +3277,7 @@ route_message (const struct GNUNET_MessageHeader *msg,
3280 recent_req = GNUNET_CONTAINER_heap_peek (recent.minHeap); 3277 recent_req = GNUNET_CONTAINER_heap_peek (recent.minHeap);
3281 GNUNET_assert (recent_req != NULL); 3278 GNUNET_assert (recent_req != NULL);
3282 GNUNET_SCHEDULER_cancel (recent_req->remove_task); 3279 GNUNET_SCHEDULER_cancel (recent_req->remove_task);
3283 recent_req->remove_task = 3280 recent_req->remove_task =
3284 GNUNET_SCHEDULER_add_now (&remove_recent, recent_req); 3281 GNUNET_SCHEDULER_add_now (&remove_recent, recent_req);
3285 } 3282 }
3286 3283
@@ -3591,8 +3588,8 @@ malicious_put_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3591 "%s:%s Sending malicious PUT message with hash %s\n", my_short_id, 3588 "%s:%s Sending malicious PUT message with hash %s\n", my_short_id,
3592 "DHT", GNUNET_h2s (&key)); 3589 "DHT", GNUNET_h2s (&key));
3593 demultiplex_message (&put_message.header, &msg_ctx); 3590 demultiplex_message (&put_message.header, &msg_ctx);
3594 GNUNET_SCHEDULER_add_delayed (malicious_put_frequency, 3591 GNUNET_SCHEDULER_add_delayed (malicious_put_frequency, &malicious_put_task,
3595 &malicious_put_task, NULL); 3592 NULL);
3596} 3593}
3597 3594
3598 3595
@@ -3639,8 +3636,8 @@ malicious_get_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3639 "%s:%s Sending malicious GET message with hash %s\n", my_short_id, 3636 "%s:%s Sending malicious GET message with hash %s\n", my_short_id,
3640 "DHT", GNUNET_h2s (&key)); 3637 "DHT", GNUNET_h2s (&key));
3641 demultiplex_message (&get_message.header, &msg_ctx); 3638 demultiplex_message (&get_message.header, &msg_ctx);
3642 GNUNET_SCHEDULER_add_delayed (malicious_get_frequency, 3639 GNUNET_SCHEDULER_add_delayed (malicious_get_frequency, &malicious_get_task,
3643 &malicious_get_task, NULL); 3640 NULL);
3644} 3641}
3645#endif 3642#endif
3646 3643
@@ -3811,7 +3808,7 @@ handle_dht_local_route_request (void *cls, struct GNUNET_SERVER_Client *client,
3811 msg_ctx.path_history_len = 1; 3808 msg_ctx.path_history_len = 1;
3812 } 3809 }
3813 msg_ctx.network_size = log_of_network_size_estimate; 3810 msg_ctx.network_size = log_of_network_size_estimate;
3814 msg_ctx.peer = &my_identity; /* FIXME bart NULL? Fix doxygen? */ 3811 msg_ctx.peer = &my_identity; /* FIXME bart NULL? Fix doxygen? */
3815 msg_ctx.importance = DHT_DEFAULT_P2P_IMPORTANCE + 4; /* Make local routing a higher priority */ 3812 msg_ctx.importance = DHT_DEFAULT_P2P_IMPORTANCE + 4; /* Make local routing a higher priority */
3816 msg_ctx.timeout = DHT_DEFAULT_P2P_TIMEOUT; 3813 msg_ctx.timeout = DHT_DEFAULT_P2P_TIMEOUT;
3817 3814
@@ -4066,10 +4063,10 @@ handle_dht_p2p_route_request (void *cls, const struct GNUNET_PeerIdentity *peer,
4066 ntohl (incoming->outgoing_path_length) * 4063 ntohl (incoming->outgoing_path_length) *
4067 sizeof (struct GNUNET_PeerIdentity); 4064 sizeof (struct GNUNET_PeerIdentity);
4068 if (ntohs (message->size) != 4065 if (ntohs (message->size) !=
4069 (sizeof (struct GNUNET_DHT_P2PRouteMessage) + 4066 (sizeof (struct GNUNET_DHT_P2PRouteMessage) + ntohs (enc_msg->size) +
4070 ntohs (enc_msg->size) + path_size)) 4067 path_size))
4071 { 4068 {
4072 GNUNET_break_op(0); 4069 GNUNET_break_op (0);
4073 return GNUNET_YES; 4070 return GNUNET_YES;
4074 } 4071 }
4075 route_path = (char *) &incoming[1]; 4072 route_path = (char *) &incoming[1];
@@ -4524,8 +4521,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
4524 datacache = GNUNET_DATACACHE_create (cfg, "dhtcache"); 4521 datacache = GNUNET_DATACACHE_create (cfg, "dhtcache");
4525 GNUNET_SERVER_add_handlers (server, plugin_handlers); 4522 GNUNET_SERVER_add_handlers (server, plugin_handlers);
4526 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 4523 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
4527 nse = GNUNET_NSE_connect (cfg, 4524 nse = GNUNET_NSE_connect (cfg, &update_network_size_estimate, NULL);
4528 &update_network_size_estimate, NULL);
4529 coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */ 4525 coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */
4530 DEFAULT_CORE_QUEUE_SIZE, /* queue size */ 4526 DEFAULT_CORE_QUEUE_SIZE, /* queue size */
4531 NULL, /* Closure passed to DHT functions */ 4527 NULL, /* Closure passed to DHT functions */
@@ -4587,8 +4583,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
4587 malicious_getter = GNUNET_YES; 4583 malicious_getter = GNUNET_YES;
4588 if (GNUNET_NO == 4584 if (GNUNET_NO ==
4589 GNUNET_CONFIGURATION_get_value_time (cfg, "DHT", 4585 GNUNET_CONFIGURATION_get_value_time (cfg, "DHT",
4590 "MALICIOUS_GET_FREQUENCY", 4586 "MALICIOUS_GET_FREQUENCY",
4591 &malicious_get_frequency)) 4587 &malicious_get_frequency))
4592 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY; 4588 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
4593 } 4589 }
4594 4590
@@ -4598,8 +4594,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
4598 malicious_putter = GNUNET_YES; 4594 malicious_putter = GNUNET_YES;
4599 if (GNUNET_NO == 4595 if (GNUNET_NO ==
4600 GNUNET_CONFIGURATION_get_value_time (cfg, "DHT", 4596 GNUNET_CONFIGURATION_get_value_time (cfg, "DHT",
4601 "MALICIOUS_PUT_FREQUENCY", 4597 "MALICIOUS_PUT_FREQUENCY",
4602 &malicious_put_frequency)) 4598 &malicious_put_frequency))
4603 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY; 4599 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
4604 } 4600 }
4605 4601
@@ -4721,7 +4717,8 @@ main (int argc, char *const *argv)
4721 int ret; 4717 int ret;
4722 4718
4723 recent.hashmap = GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT / 2); 4719 recent.hashmap = GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT / 2);
4724 recent.minHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 4720 recent.minHeap =
4721 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
4725 recent_find_peer_requests = 4722 recent_find_peer_requests =
4726 GNUNET_CONTAINER_multihashmap_create (MAX_BUCKETS / 8); 4723 GNUNET_CONTAINER_multihashmap_create (MAX_BUCKETS / 8);
4727 ret = 4724 ret =
@@ -4730,12 +4727,12 @@ main (int argc, char *const *argv)
4730 NULL)) ? 0 : 1; 4727 NULL)) ? 0 : 1;
4731 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (recent.hashmap)); 4728 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (recent.hashmap));
4732 GNUNET_CONTAINER_multihashmap_destroy (recent.hashmap); 4729 GNUNET_CONTAINER_multihashmap_destroy (recent.hashmap);
4733 recent.hashmap = NULL; 4730 recent.hashmap = NULL;
4734 GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (recent.minHeap)); 4731 GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (recent.minHeap));
4735 GNUNET_CONTAINER_heap_destroy (recent.minHeap); 4732 GNUNET_CONTAINER_heap_destroy (recent.minHeap);
4736 recent.minHeap = NULL; 4733 recent.minHeap = NULL;
4737 GNUNET_CONTAINER_multihashmap_destroy (recent_find_peer_requests); 4734 GNUNET_CONTAINER_multihashmap_destroy (recent_find_peer_requests);
4738 recent_find_peer_requests = NULL; 4735 recent_find_peer_requests = NULL;
4739 return ret; 4736 return ret;
4740} 4737}
4741 4738