From: Matthias Wachs Date: Wed, 27 Oct 2010 10:08:46 +0000 (+0000) Subject: Refactoring gnunet time X-Git-Tag: initial-import-from-subversion-38251~19924 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d6dbee55aed867e1d4d519fea9e3768d85a19d88;p=oweals%2Fgnunet.git Refactoring gnunet time --- diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 3c8ed9434..ea70b9000 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c @@ -861,14 +861,16 @@ void GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle, struct GNUNET_TIME_Relative frequency) { - if (frequency.value > UINT16_MAX) + /* + if (frequency.abs_value > UINT16_MAX) { GNUNET_break (0); return; } send_control_message (handle, - GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET, frequency.value, + GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET, frequency.abs_value, NULL, NULL); + */ } /** @@ -882,14 +884,17 @@ void GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle, struct GNUNET_TIME_Relative frequency) { - if (frequency.value > UINT16_MAX) + /* + if (frequency.abs_value > UINT16_MAX) { GNUNET_break (0); return; } + send_control_message (handle, - GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT, frequency.value, + GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT, frequency.abs_value, NULL, NULL); + */ } diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c index 4424a45f3..649d8ff13 100644 --- a/src/dht/gnunet-dht-driver.c +++ b/src/dht/gnunet-dht-driver.c @@ -1065,7 +1065,7 @@ decrement_find_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) test_find_peer->find_peer_context->outstanding--; test_find_peer->find_peer_context->total--; if ((0 == test_find_peer->find_peer_context->total) && - (GNUNET_TIME_absolute_get_remaining(test_find_peer->find_peer_context->endtime).value > 60)) + (GNUNET_TIME_absolute_get_remaining(test_find_peer->find_peer_context->endtime).rel_value > 60)) { GNUNET_SCHEDULER_add_now(sched, &count_new_peers, test_find_peer->find_peer_context); } @@ -1101,7 +1101,7 @@ send_find_peer_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext * t } test_find_peer->find_peer_context->outstanding++; - if (GNUNET_TIME_absolute_get_remaining(test_find_peer->find_peer_context->endtime).value == 0) + if (GNUNET_TIME_absolute_get_remaining(test_find_peer->find_peer_context->endtime).rel_value == 0) { GNUNET_SCHEDULER_add_now(sched, &decrement_find_peers, test_find_peer); return; @@ -1192,13 +1192,13 @@ static int iterate_min_heap_peers (void *cls, /** Just try to connect the peers, don't worry about callbacks, etc. **/ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peer %s has 0 connections. Trying to connect to %s...\n", GNUNET_i2s(&peer_count->peer_id), d2->shortname); timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, DEFAULT_CONNECT_TIMEOUT); - if (GNUNET_TIME_relative_to_absolute(timeout).value > find_peer_context->endtime.value) + if (GNUNET_TIME_relative_to_absolute(timeout).abs_value > find_peer_context->endtime.abs_value) { timeout = GNUNET_TIME_absolute_get_remaining(find_peer_context->endtime); } GNUNET_TESTING_daemons_connect(d1, d2, timeout, DEFAULT_RECONNECT_ATTEMPTS, NULL, NULL); } - if (GNUNET_TIME_absolute_get_remaining(find_peer_context->endtime).value > 0) + if (GNUNET_TIME_absolute_get_remaining(find_peer_context->endtime).rel_value > 0) return GNUNET_YES; else return GNUNET_NO; @@ -1286,13 +1286,13 @@ count_peers_churn_cb (void *cls, * these are very specialized cases. */ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Out of %u peers, fewest connections is %d\n", GNUNET_CONTAINER_heap_get_size(find_peer_context->peer_min_heap), peer_count->count); - if ((peer_count->count == 0) && (GNUNET_TIME_absolute_get_remaining(find_peer_context->endtime).value > 0)) + if ((peer_count->count == 0) && (GNUNET_TIME_absolute_get_remaining(find_peer_context->endtime).rel_value > 0)) { GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Found peer with no connections, will choose some peer(s) at random to connect to!\n"); GNUNET_CONTAINER_heap_iterate (find_peer_context->peer_min_heap, &iterate_min_heap_peers, find_peer_context); GNUNET_SCHEDULER_add_now(sched, &schedule_churn_find_peer_requests, find_peer_context); } - else if ((GNUNET_TIME_absolute_get_remaining(find_peer_context->endtime).value > 0) && (find_peer_context->last_sent != 0)) + else if ((GNUNET_TIME_absolute_get_remaining(find_peer_context->endtime).rel_value > 0) && (find_peer_context->last_sent != 0)) { GNUNET_SCHEDULER_add_now(sched, &schedule_churn_find_peer_requests, find_peer_context); } @@ -1909,7 +1909,7 @@ count_peers_cb (void *cls, if ((find_peer_context->last_sent > 8) && (find_peer_context->current_peers - find_peer_context->previous_peers > FIND_PEER_THRESHOLD) && (find_peer_context->current_peers < 2 * connection_estimate(num_peers, DEFAULT_BUCKET_SIZE)) && - (GNUNET_TIME_absolute_get_remaining(find_peer_context->endtime).value > 0)) + (GNUNET_TIME_absolute_get_remaining(find_peer_context->endtime).rel_value > 0)) { GNUNET_SCHEDULER_add_now(sched, &schedule_find_peer_requests, find_peer_context); } @@ -2783,7 +2783,7 @@ run (void *cls, &temp_config_number)) all_get_timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number); else - all_get_timeout.value = get_timeout.value * num_gets; + all_get_timeout.rel_value = get_timeout.rel_value * num_gets; if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "get_delay", @@ -3011,8 +3011,8 @@ run (void *cls, trial_info.malicious_getters = malicious_getters; trial_info.malicious_putters = malicious_putters; trial_info.malicious_droppers = malicious_droppers; - trial_info.malicious_get_frequency = malicious_get_frequency.value; - trial_info.malicious_put_frequency = malicious_put_frequency.value; + trial_info.malicious_get_frequency = malicious_get_frequency.rel_value; + trial_info.malicious_put_frequency = malicious_put_frequency.rel_value; trial_info.stop_closest = stop_closest; trial_info.stop_found = stop_found; trial_info.strict_kademlia = strict_kademlia; diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 02cf9ae90..8b5de2157 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c @@ -947,7 +947,7 @@ static struct GNUNET_TIME_Relative get_average_send_delay() for (i = 0; i < MAX_REPLY_TIMES; i++) { average_time = GNUNET_TIME_relative_add(average_time, reply_times[i]); - if (reply_times[i].value == (uint64_t)0) + if (reply_times[i].abs_value == (uint64_t)0) continue; else divisor++; @@ -958,7 +958,7 @@ static struct GNUNET_TIME_Relative get_average_send_delay() } average_time = GNUNET_TIME_relative_divide(average_time, divisor); - fprintf(stderr, "Avg send delay: %u sends is %llu\n", divisor, (long long unsigned int)average_time.value); + fprintf(stderr, "Avg send delay: %u sends is %llu\n", divisor, (long long unsigned int)average_time.abs_value); return average_time; } #endif @@ -973,9 +973,9 @@ static void decrease_max_send_delay(struct GNUNET_TIME_Relative max_time) unsigned int i; for (i = 0; i < MAX_REPLY_TIMES; i++) { - if (reply_times[i].value == max_time.value) + if (reply_times[i].rel_value == max_time.rel_value) { - reply_times[i].value = reply_times[i].value / 2; + reply_times[i].rel_value = reply_times[i].rel_value / 2; return; } } @@ -995,12 +995,12 @@ static struct GNUNET_TIME_Relative get_max_send_delay() for (i = 0; i < MAX_REPLY_TIMES; i++) { - if (reply_times[i].value > max_time.value) - max_time.value = reply_times[i].value; + if (reply_times[i].rel_value > max_time.rel_value) + max_time.rel_value = reply_times[i].rel_value; } - if (max_time.value > MAX_REQUEST_TIME.value) - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Max send delay was %llu\n", (long long unsigned int)max_time.value); + if (max_time.rel_value > MAX_REQUEST_TIME.rel_value) + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Max send delay was %llu\n", (long long unsigned int)max_time.rel_value); return max_time; } @@ -3413,7 +3413,7 @@ static int cache_response(struct DHT_MessageContext *msg_ctx) } if ((pos != NULL) && (pos->client == msg_ctx->client)) /* Seen this already */ { - GNUNET_CONTAINER_heap_update_cost(forward_list.minHeap, pos->hnode, now.value); + GNUNET_CONTAINER_heap_update_cost(forward_list.minHeap, pos->hnode, now.abs_value); return GNUNET_NO; } } @@ -3435,7 +3435,7 @@ static int cache_response(struct DHT_MessageContext *msg_ctx) source_info->client = msg_ctx->client; now = GNUNET_TIME_absolute_get_forever(); } - source_info->hnode = GNUNET_CONTAINER_heap_insert(forward_list.minHeap, source_info, now.value); + source_info->hnode = GNUNET_CONTAINER_heap_insert(forward_list.minHeap, source_info, now.abs_value); #if DEBUG_DHT > 1 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': Created new forward source info for %s uid %llu\n", my_short_id, @@ -3554,7 +3554,7 @@ route_message(const struct GNUNET_MessageHeader *msg, recent_req->uid = message_context->unique_id; memcpy(&recent_req->key, &message_context->key, sizeof(GNUNET_HashCode)); recent_req->remove_task = GNUNET_SCHEDULER_add_delayed(sched, DEFAULT_RECENT_REMOVAL, &remove_recent, recent_req); - recent_req->heap_node = GNUNET_CONTAINER_heap_insert(recent.minHeap, recent_req, GNUNET_TIME_absolute_get().value); + recent_req->heap_node = GNUNET_CONTAINER_heap_insert(recent.minHeap, recent_req, GNUNET_TIME_absolute_get().abs_value); recent_req->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); GNUNET_CONTAINER_multihashmap_put(recent.hashmap, &unique_hash, recent_req, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); } @@ -4008,14 +4008,14 @@ send_find_peer_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc end = GNUNET_TIME_absolute_get(); time_diff = GNUNET_TIME_absolute_get_difference(find_peer_context.start, end); - if (time_diff.value > FIND_PEER_CALC_INTERVAL.value) + if (time_diff.abs_value > FIND_PEER_CALC_INTERVAL.abs_value) { - multiplier = time_diff.value / FIND_PEER_CALC_INTERVAL.value; + multiplier = time_diff.abs_value / FIND_PEER_CALC_INTERVAL.abs_value; count_per_interval = find_peer_context.count / multiplier; } else { - multiplier = FIND_PEER_CALC_INTERVAL.value / time_diff.value; + multiplier = FIND_PEER_CALC_INTERVAL.abs_value / time_diff.abs_value; count_per_interval = find_peer_context.count * multiplier; } #endif @@ -4049,18 +4049,18 @@ send_find_peer_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc "FIND PEER"); if (newly_found_peers < bucket_size) { - next_send_time.value = (DHT_MAXIMUM_FIND_PEER_INTERVAL.value / 2) + + next_send_time.rel_value = (DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 2) + GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, - DHT_MAXIMUM_FIND_PEER_INTERVAL.value / 2); + DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 2); } else { - next_send_time.value = DHT_MINIMUM_FIND_PEER_INTERVAL.value + + next_send_time.rel_value = DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, - DHT_MAXIMUM_FIND_PEER_INTERVAL.value - DHT_MINIMUM_FIND_PEER_INTERVAL.value); + DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value - DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value); } - GNUNET_assert (next_send_time.value != 0); + GNUNET_assert (next_send_time.rel_value != 0); find_peer_context.count = 0; newly_found_peers = 0; find_peer_context.start = GNUNET_TIME_absolute_get(); @@ -4257,7 +4257,7 @@ handle_dht_p2p_route_request (void *cls, struct GNUNET_MessageHeader *enc_msg = (struct GNUNET_MessageHeader *)&incoming[1]; struct DHT_MessageContext *message_context; - if (get_max_send_delay().value > MAX_REQUEST_TIME.value) + if (get_max_send_delay().rel_value > MAX_REQUEST_TIME.rel_value) { GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending of previous replies took too long, backing off!\n"); increment_stats("# route requests dropped due to high load"); @@ -4791,9 +4791,9 @@ run (void *cls, recent.minHeap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); if (GNUNET_YES == do_find_peer) { - next_send_time.value = DHT_MINIMUM_FIND_PEER_INTERVAL.value + + next_send_time.rel_value = DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, - (DHT_MAXIMUM_FIND_PEER_INTERVAL.value / 2) - DHT_MINIMUM_FIND_PEER_INTERVAL.value); + (DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 2) - DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value); find_peer_context.start = GNUNET_TIME_absolute_get(); GNUNET_SCHEDULER_add_delayed (sched, next_send_time, diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index 3d4e8dfb1..2145be843 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c @@ -249,7 +249,7 @@ retry_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_HashCode hash; memset (&hash, 42, sizeof (GNUNET_HashCode)); - if (GNUNET_TIME_absolute_get_remaining(retry_ctx->real_timeout).value > 0) + if (GNUNET_TIME_absolute_get_remaining(retry_ctx->real_timeout).rel_value > 0) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_find_peer timed out, retrying!\n");