From f47cc990ea9a89cb39acc9c6a9789e6474197708 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 27 Oct 2010 10:04:42 +0000 Subject: [PATCH] Refactoring gnunet time --- src/topology/gnunet-daemon-topology.c | 16 ++-- src/transport/gnunet-service-transport.c | 44 ++++----- src/transport/plugin_transport_http.c | 24 ++--- src/transport/plugin_transport_tcp.c | 10 +- src/transport/plugin_transport_wlan.c | 8 +- src/transport/test_quota_compliance.c | 91 +++++++++++++++---- .../test_transport_api_reliability.c | 2 +- src/transport/transport_api.c | 22 ++--- 8 files changed, 134 insertions(+), 83 deletions(-) diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index 5425c5e49..fa693f13a 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c @@ -389,7 +389,7 @@ attempt_connect (struct Peer *pos) return; if (GNUNET_OK != is_connection_allowed (pos)) return; - if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).value > 0) + if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value > 0) return; if (GNUNET_YES == pos->is_friend) rem = GREYLIST_AFTER_ATTEMPT_FRIEND; @@ -446,7 +446,7 @@ remove_from_greylist (void *cls, pos->greylist_clean_task = GNUNET_SCHEDULER_NO_TASK; rem = GNUNET_TIME_absolute_get_remaining (pos->greylisted_until); - if (rem.value == 0) + if (rem.rel_value == 0) { attempt_connect (pos); } @@ -586,7 +586,7 @@ find_advertisable_hello (void *cls, if (pos->hello == NULL) return GNUNET_YES; rst_time = GNUNET_TIME_absolute_get_remaining (pos->filter_expiration); - if (0 == rst_time.value) + if (0 == rst_time.rel_value) { /* time to discard... */ GNUNET_CONTAINER_bloomfilter_free (pos->filter); @@ -643,7 +643,7 @@ schedule_next_hello (void *cls, return; next_want = GNUNET_HELLO_size (fah.result->hello); delay = GNUNET_TIME_absolute_get_remaining (pl->next_hello_allowed); - if (delay.value == 0) + if (delay.rel_value == 0) { /* now! */ pl->hello_req = GNUNET_CORE_notify_transmit_ready (handle, 0, @@ -733,7 +733,7 @@ connect_notify (void *cls, else { GNUNET_assert (GNUNET_NO == pos->is_connected); - pos->greylisted_until.value = 0; /* remove greylisting */ + pos->greylisted_until.abs_value = 0; /* remove greylisting */ } pos->is_connected = GNUNET_YES; pos->connect_attempts = 0; /* re-set back-off factor */ @@ -893,7 +893,7 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello) dt = GNUNET_HELLO_equals (peer->hello, hello, GNUNET_TIME_absolute_get()); - if (dt.value == GNUNET_TIME_UNIT_FOREVER_ABS.value) + if (dt.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) return; /* nothing new here */ } #if DEBUG_TOPOLOGY @@ -961,7 +961,7 @@ process_peer (void *cls, } if ( (! pos->is_connected) && (! pos->is_friend) && - (0 == GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).value) ) + (0 == GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value) ) free_peer (NULL, &pos->pid.hashPubKey, pos); } return; @@ -981,7 +981,7 @@ process_peer (void *cls, #endif return; } - if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).value > 0) + if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value > 0) { #if DEBUG_TOPOLOGY GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 9d3e9d7c5..c1bb7bec6 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -1496,7 +1496,7 @@ find_ready_address(struct NeighbourList *neighbour) addresses = head->addresses; while (addresses != NULL) { - if ( (addresses->timeout.value < now.value) && + if ( (addresses->timeout.abs_value < now.abs_value) && (addresses->connected == GNUNET_YES) ) { #if DEBUG_TRANSPORT @@ -1528,7 +1528,7 @@ find_ready_address(struct NeighbourList *neighbour) addresses->in_transmit, addresses->validated, addresses->connect_attempts, - (unsigned long long) addresses->timeout.value, + (unsigned long long) addresses->timeout.abs_value, (unsigned int) addresses->distance); #endif if ( ( (best_address == NULL) || @@ -1536,7 +1536,7 @@ find_ready_address(struct NeighbourList *neighbour) (best_address->connected == GNUNET_NO) ) && (addresses->in_transmit == GNUNET_NO) && ( (best_address == NULL) || - (addresses->latency.value < best_address->latency.value)) ) + (addresses->latency.rel_value < best_address->latency.rel_value)) ) best_address = addresses; /* FIXME: also give lower-latency addresses that are not connected a chance some times... */ @@ -1554,7 +1554,7 @@ find_ready_address(struct NeighbourList *neighbour) best_address->addr, best_address->addrlen) : "", - best_address->latency.value); + best_address->latency.abs_value); #endif } else @@ -1627,7 +1627,7 @@ try_transmission_to_peer (struct NeighbourList *neighbour) 1, GNUNET_NO); timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout); - if (timeout.value == 0) + if (timeout.rel_value == 0) { #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -1667,7 +1667,7 @@ try_transmission_to_peer (struct NeighbourList *neighbour) "No validated destination address available to transmit message of size %u to peer `%4s', will wait %llums to find an address.\n", mq->message_buf_size, GNUNET_i2s (&mq->neighbour_id), - timeout.value); + timeout.abs_value); #endif /* FIXME: might want to trigger peerinfo lookup here (unless that's already pending...) */ @@ -1928,13 +1928,13 @@ update_addresses (struct TransportPlugin *plugin, int fresh) plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK; now = GNUNET_TIME_absolute_get (); min_remaining = GNUNET_TIME_UNIT_FOREVER_REL; - expired = (GNUNET_TIME_absolute_get_duration (last_update).value > (HELLO_ADDRESS_EXPIRATION.value / 4)); + expired = (GNUNET_TIME_absolute_get_duration (last_update).rel_value > (HELLO_ADDRESS_EXPIRATION.rel_value / 4)); prev = NULL; pos = plugin->addresses; while (pos != NULL) { next = pos->next; - if (pos->expires.value < now.value) + if (pos->expires.abs_value < now.abs_value) { expired = GNUNET_YES; if (prev == NULL) @@ -1946,7 +1946,7 @@ update_addresses (struct TransportPlugin *plugin, int fresh) else { remaining = GNUNET_TIME_absolute_get_remaining (pos->expires); - if (remaining.value < min_remaining.value) + if (remaining.rel_value < min_remaining.rel_value) min_remaining = remaining; prev = pos; } @@ -2191,7 +2191,7 @@ plugin_env_notify_address (void *cls, { if ((addrlen == al->addrlen) && (0 == memcmp (addr, &al[1], addrlen))) { - if (al->expires.value < abex.value) + if (al->expires.abs_value < abex.abs_value) al->expires = abex; return; } @@ -2631,7 +2631,7 @@ add_to_foreign_address_list (void *cls, a2s (tname, addr, addrlen), tname, GNUNET_i2s (&n->id), - expiration.value); + expiration.abs_value); #endif fal = add_peer_address (n, tname, NULL, addr, addrlen); if (fal == NULL) @@ -3364,7 +3364,7 @@ schedule_next_ping (struct ForeignAddressList *fal) if (fal->revalidate_task != GNUNET_SCHEDULER_NO_TASK) return; delay = GNUNET_TIME_absolute_get_remaining (fal->expires); - delay.value /= 2; /* do before expiration */ + delay.rel_value /= 2; /* do before expiration */ delay = GNUNET_TIME_relative_min (delay, LATENCY_EVALUATION_MAX_DELAY); if (GNUNET_YES != fal->estimated) @@ -3383,7 +3383,7 @@ schedule_next_ping (struct ForeignAddressList *fal) delay = GNUNET_TIME_relative_max (delay, GNUNET_TIME_UNIT_SECONDS); /* randomize a bit (to avoid doing all at the same time) */ - delay.value += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000); + delay.rel_value += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000); fal->revalidate_task = GNUNET_SCHEDULER_add_delayed(sched, delay, &send_periodic_ping, @@ -3627,7 +3627,7 @@ check_pending_validation (void *cls, GNUNET_break_op (0); return GNUNET_NO; } - if (GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (pong->expiration)).value == 0) + if (GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value == 0) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received expired signature. Check system time.\n")); @@ -3672,10 +3672,10 @@ check_pending_validation (void *cls, GNUNET_NO); fal->latency = GNUNET_TIME_absolute_get_duration (ve->send_time); schedule_next_ping (fal); - if (n->latency.value == GNUNET_TIME_UNIT_FOREVER_REL.value) + if (n->latency.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) n->latency = fal->latency; else - n->latency.value = (fal->latency.value + n->latency.value) / 2; + n->latency.rel_value = (fal->latency.rel_value + n->latency.rel_value) / 2; n->distance = fal->distance; if (GNUNET_NO == n->received_pong) @@ -4200,7 +4200,7 @@ process_hello (struct TransportPlugin *plugin, { if (GNUNET_HELLO_equals (hello, chvc->hello, - GNUNET_TIME_absolute_get ()).value > 0) + GNUNET_TIME_absolute_get ()).abs_value > 0) { #if DEBUG_TRANSPORT_HELLO > 2 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -4500,7 +4500,7 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message, memcpy (&((char*)&pong[1])[slen], sender_address, sender_address_len); - if (GNUNET_TIME_absolute_get_remaining (session_header->pong_sig_expires).value < PONG_SIGNATURE_LIFETIME.value / 4) + if (GNUNET_TIME_absolute_get_remaining (session_header->pong_sig_expires).rel_value < PONG_SIGNATURE_LIFETIME.rel_value / 4) { /* create / update cached sig */ #if DEBUG_TRANSPORT @@ -4568,7 +4568,7 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message, memcpy (&pong[1], plugin->short_name, slen); memcpy (&((char*)&pong[1])[slen], addr, alen); if ( (oal != NULL) && - (GNUNET_TIME_absolute_get_remaining (oal->pong_sig_expires).value < PONG_SIGNATURE_LIFETIME.value / 4) ) + (GNUNET_TIME_absolute_get_remaining (oal->pong_sig_expires).rel_value < PONG_SIGNATURE_LIFETIME.rel_value / 4) ) { /* create / update cached sig */ #if DEBUG_TRANSPORT @@ -4786,16 +4786,16 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer, } } ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 0); - if (ret.value > 0) + if (ret.rel_value > 0) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Throttling read (%llu bytes excess at %u b/s), waiting %llums before reading more.\n", (unsigned long long) n->in_tracker.consumption_since_last_update__, (unsigned int) n->in_tracker.available_bytes_per_s__, - (unsigned long long) ret.value); + (unsigned long long) ret.rel_value); GNUNET_STATISTICS_update (stats, gettext_noop ("# ms throttling suggested"), - (int64_t) ret.value, + (int64_t) ret.rel_value, GNUNET_NO); } return ret; diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index ac04610c1..e4c88903f 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c @@ -882,10 +882,10 @@ static void mhd_write_mst_cb (void *cls, if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (pc->plugin->env->sched, pc->reset_task); - if (delay.value > 0) + if (delay.rel_value > 0) { #if DEBUG_HTTP - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: Inbound quota management: delay next read for %llu ms \n", ps, delay.value); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: Inbound quota management: delay next read for %llu ms \n", ps, delay.rel_value); #endif pc->reset_task = GNUNET_SCHEDULER_add_delayed (pc->plugin->env->sched, delay, &reset_inbound_quota_delay, pc); } @@ -1182,7 +1182,7 @@ mhd_access_cb (void *cls, /* Recieving data */ if ((*upload_data_size > 0) && (ps->recv_active == GNUNET_YES)) { - if (pc->delay.value == 0) + if (pc->delay.rel_value == 0) { #if DEBUG_HTTP GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: PUT with %u bytes forwarded to MST\n", ps, *upload_data_size); @@ -1193,7 +1193,7 @@ mhd_access_cb (void *cls, else { #if DEBUG_HTTP - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n", ps, ps->peercontext->delay.value); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n", ps, ps->peercontext->delay.rel_value); #endif } return MHD_YES; @@ -1264,7 +1264,7 @@ http_server_daemon_prepare (struct Plugin *plugin , struct MHD_Daemon *daemon_ha &max)); haveto = MHD_get_timeout (daemon_handle, &timeout); if (haveto == MHD_YES) - tv.value = (uint64_t) timeout; + tv.rel_value = (uint64_t) timeout; else tv = GNUNET_TIME_UNIT_SECONDS; GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); @@ -1588,10 +1588,10 @@ static void curl_receive_mst_cb (void *cls, if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (pc->plugin->env->sched, pc->reset_task); - if (delay.value > 0) + if (delay.rel_value > 0) { #if DEBUG_HTTP - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: Inbound quota management: delay next read for %llu ms \n", ps, delay.value); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: Inbound quota management: delay next read for %llu ms \n", ps, delay.abs_value); #endif pc->reset_task = GNUNET_SCHEDULER_add_delayed (pc->plugin->env->sched, delay, &reset_inbound_quota_delay, pc); } @@ -1611,10 +1611,10 @@ static size_t curl_receive_cb( void *stream, size_t size, size_t nmemb, void *pt { struct Session * ps = ptr; - if (ps->peercontext->delay.value > 0) + if (ps->peercontext->delay.rel_value > 0) { #if DEBUG_HTTP - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n", ps, ps->peercontext->delay.value); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n", ps, ps->peercontext->delay.rel_value); #endif return (0); } @@ -1935,7 +1935,7 @@ static int send_check_connections (struct Plugin *plugin, struct Session *ps) curl_easy_setopt(ps->recv_endpoint, CURLOPT_READDATA, ps); curl_easy_setopt(ps->recv_endpoint, CURLOPT_WRITEFUNCTION, curl_receive_cb); curl_easy_setopt(ps->recv_endpoint, CURLOPT_WRITEDATA, ps); - curl_easy_setopt(ps->recv_endpoint, CURLOPT_TIMEOUT, (long) timeout.value); + curl_easy_setopt(ps->recv_endpoint, CURLOPT_TIMEOUT, (long) timeout.rel_value); curl_easy_setopt(ps->recv_endpoint, CURLOPT_PRIVATE, ps); curl_easy_setopt(ps->recv_endpoint, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT); curl_easy_setopt(ps->recv_endpoint, CURLOPT_BUFFERSIZE, 2*GNUNET_SERVER_MAX_MESSAGE_SIZE); @@ -2034,7 +2034,7 @@ static int send_check_connections (struct Plugin *plugin, struct Session *ps) curl_easy_setopt(ps->send_endpoint, CURLOPT_READDATA, ps); curl_easy_setopt(ps->send_endpoint, CURLOPT_WRITEFUNCTION, curl_receive_cb); curl_easy_setopt(ps->send_endpoint, CURLOPT_READDATA, ps); - curl_easy_setopt(ps->send_endpoint, CURLOPT_TIMEOUT, (long) timeout.value); + curl_easy_setopt(ps->send_endpoint, CURLOPT_TIMEOUT, (long) timeout.rel_value); curl_easy_setopt(ps->send_endpoint, CURLOPT_PRIVATE, ps); curl_easy_setopt(ps->send_endpoint, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT); curl_easy_setopt(ps->send_endpoint, CURLOPT_BUFFERSIZE, 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE); @@ -2982,7 +2982,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) GNUNET_assert ((port > 0) && (port <= 65535)); plugin->port_inbound = port; gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; - unsigned int timeout = (gn_timeout.value) / 1000; + unsigned int timeout = (gn_timeout.rel_value) / 1000; if ((plugin->http_server_daemon_v6 == NULL) && (plugin->use_ipv6 == GNUNET_YES) && (port != 0)) { struct sockaddr * tmp = (struct sockaddr *) plugin->bind6_address; diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index bf14092fb..7ac31ecb6 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -697,7 +697,7 @@ do_transmit (void *cls, size_t size, void *buf) ret = 0; now = GNUNET_TIME_absolute_get (); while ( (NULL != (pos = session->pending_messages_head)) && - (pos->timeout.value <= now.value) ) + (pos->timeout.abs_value <= now.abs_value) ) { GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, session->pending_messages_tail, @@ -930,9 +930,9 @@ select_better_session (struct Session *s1, if ( (s1->expecting_welcome == GNUNET_YES) && (s2->expecting_welcome == GNUNET_NO) ) return s2; - if (s1->last_activity.value < s2->last_activity.value) + if (s1->last_activity.abs_value < s2->last_activity.abs_value) return s2; - if (s1->last_activity.value > s2->last_activity.value) + if (s1->last_activity.abs_value > s2->last_activity.abs_value) return s1; if ( (GNUNET_YES == s1->inbound) && (GNUNET_NO == s2->inbound) ) @@ -1806,7 +1806,7 @@ delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) NULL, 0, session, NULL, 0); - if (delay.value == 0) + if (delay.rel_value == 0) GNUNET_SERVER_receive_done (session->client, GNUNET_OK); else session->receive_delay_task = @@ -1860,7 +1860,7 @@ handle_tcp_data (void *cls, session, (GNUNET_YES == session->inbound) ? NULL : session->connect_addr, (GNUNET_YES == session->inbound) ? 0 : session->connect_alen); - if (delay.value == 0) + if (delay.rel_value == 0) GNUNET_SERVER_receive_done (client, GNUNET_OK); else session->receive_delay_task = diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 765d8721d..54cc3f864 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -565,7 +565,7 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct GNUNET_TIME_Relative timeout; struct Sessionqueue * nextsession = NULL; - timeout.value = FRAGMENT_TIMEOUT; + timeout.rel_value = FRAGMENT_TIMEOUT; nextsend = GNUNET_TIME_absolute_get_forever(); queue = plugin->pending_Sessions; @@ -596,7 +596,7 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) //save next session nextsession = queue->next; // test if message timed out - while (GNUNET_TIME_absolute_get_remaining(pm->timeout).value == 0){ + while (GNUNET_TIME_absolute_get_remaining(pm->timeout).rel_value == 0){ //remove message //free the acks free_acks (pm); @@ -637,7 +637,7 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) nextsession = NULL; // test if retransmit is needed - if (GNUNET_TIME_absolute_get_duration(pm->last_ack).value < FRAGMENT_TIMEOUT) { + if (GNUNET_TIME_absolute_get_duration(pm->last_ack).rel_value < FRAGMENT_TIMEOUT) { // get last offset for this message copyoffset = pm->message_size /(WLAN_MTU - sizeof(struct FragmentationHeader)); // one more is the end @@ -693,7 +693,7 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (pm->message_size > WLAN_MTU) { size += sizeof(struct FragmentationHeader); // check for retransmission - if (GNUNET_TIME_absolute_get_duration(pm->last_ack).value > FRAGMENT_TIMEOUT) { + if (GNUNET_TIME_absolute_get_duration(pm->last_ack).rel_value > FRAGMENT_TIMEOUT) { // TODO retransmit // be positive and try again later :-D pm->last_ack = GNUNET_TIME_absolute_get(); diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index 018324a4e..a5a836d48 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c @@ -49,18 +49,20 @@ */ #define TOTAL_MSGS (10000 * 2) -#define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) -#define MEASUREMENT_MSG_SIZE 1024 +#define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) +#define MEASUREMENT_MSG_SIZE 10000 #define MEASUREMENT_MSG_SIZE_BIG 32768 -#define MEASUREMENT_MAX_QUOTA 1024*1024*1024 -#define MEASUREMENT_MIN_QUOTA 1024 - +#define MEASUREMENT_MAX_QUOTA 50000 +/*#define MEASUREMENT_MAX_QUOTA 1000000*/ +#define MEASUREMENT_MIN_QUOTA 1000 +#define SEND_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) /** * Testcase timeout */ #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 200) + #define MTYPE 11111 struct PeerContext @@ -73,6 +75,54 @@ struct PeerContext #endif }; +/** + * Handle for a transmission-ready request. + */ +struct GNUNET_TRANSPORT_TransmitHandle +{ + + /** + * Neighbour for this handle, NULL for control-traffic. + */ + struct NeighbourList *neighbour; + + /** + * Function to call when notify_size bytes are available + * for transmission. + */ + GNUNET_CONNECTION_TransmitReadyNotify notify; + + /** + * Closure for notify. + */ + void *notify_cls; + + /** + * transmit_ready task Id. The task is used to introduce the + * artificial delay that may be required to maintain the bandwidth + * limits. Later, this will be the ID of the "transmit_timeout" + * task which is used to signal a timeout if the transmission could + * not be done in a timely fashion. + */ + GNUNET_SCHEDULER_TaskIdentifier notify_delay_task; + + /** + * Timeout for this request. + */ + struct GNUNET_TIME_Absolute timeout; + + /** + * How many bytes is our notify callback waiting for? + */ + size_t notify_size; + + /** + * How important is this message? + */ + unsigned int priority; + +}; + static struct PeerContext p1; static struct PeerContext p2; @@ -177,7 +227,7 @@ struct TestMessage }; static unsigned int -get_size_new (unsigned int iter) +get_size (unsigned int iter) { return MEASUREMENT_MSG_SIZE + sizeof (struct TestMessage); } @@ -194,7 +244,7 @@ notify_receive_new (void *cls, const struct TestMessage *hdr; hdr = (const struct TestMessage*) message; - s = get_size_new (n); + s = get_size (n); if (MTYPE != ntohs (message->type)) return; #if DEBUG_MEASUREMENT @@ -234,7 +284,7 @@ notify_ready_new (void *cls, size_t size, void *buf) return 0; ret = 0; - s = get_size_new (n); + s = get_size (n); GNUNET_assert (size >= s); GNUNET_assert (buf != NULL); cbuf = buf; @@ -255,14 +305,14 @@ notify_ready_new (void *cls, size_t size, void *buf) } #endif n++; - s = get_size_new (n); + s = get_size (n); if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) break; /* sometimes pack buffer full, sometimes not */ } while (size - ret >= s); transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, &p1.id, - s, 0, TIMEOUT, + s, 0, SEND_TIMEOUT, ¬ify_ready_new, NULL); total_bytes += s; @@ -313,14 +363,14 @@ measurement_end (void *cls, GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); transmit_handle = NULL; } - if (current_quota_p1 < total_bytes/(duration.value / 1000)) + if ((total_bytes/(duration.rel_value / 1000)) > (current_quota_p1 + (current_quota_p1 / 10))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "\nQuota compliance failed: \n"\ - "Quota allowed: %10llu kb/s\n"\ - "Throughput : %10llu kb/s\n", (current_quota_p1 / (1024)) , (total_bytes/(duration.value / 1000)/1024)); + "Quota allowed: %10llu kB/s\n"\ + "Throughput : %10llu kB/s\n", (current_quota_p1 / (1024)) , (total_bytes/(duration.rel_value / 1000)/1024)); ok = 1; - end(); + //end(); return; } else @@ -328,14 +378,15 @@ measurement_end (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\nQuota compliance ok: \n"\ - "Quota allowed: %10llu kb/s\n"\ - "Throughput : %10llu kb/s\n", (current_quota_p1 / (1024)) , (total_bytes/(duration.value / 1000)/1024)); + "Quota allowed: %10llu kB/s\n"\ + "Throughput : %10llu kB/s\n", (current_quota_p1 / (1024)) , (total_bytes/(duration.rel_value / 1000)/1024)); ok = 0; } - if (current_quota_p1 < (MEASUREMENT_MIN_QUOTA)) + if (current_quota_p1 < MEASUREMENT_MIN_QUOTA) end(); else - measure (current_quota_p1/100, current_quota_p2/100); + + measure (current_quota_p1- 1000, current_quota_p2- 1000); } static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) @@ -344,7 +395,7 @@ static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) current_quota_p2 = quota_p2; #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting transport level measurement: Duration: %u Quota: %u\n", MEASUREMENT_INTERVALL, current_quota_p1); + "Starting transport level measurement: Duration: %u Quota: %llu\n", MEASUREMENT_INTERVALL, current_quota_p1); #endif GNUNET_TRANSPORT_set_quota (p1.th, &p2.id, @@ -383,7 +434,7 @@ static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, &p1.id, - get_size_new (0), 0, TIMEOUT, + get_size (0), 0, SEND_TIMEOUT, ¬ify_ready_new, NULL); } diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index 1f0fcfd3c..0625230a4 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c @@ -127,7 +127,7 @@ end () GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transports disconnected, returning success!\n"); #endif - delta = GNUNET_TIME_absolute_get_duration (start_time).value; + delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; fprintf (stderr, "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta); diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index f1c065780..53330d39e 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c @@ -465,13 +465,13 @@ schedule_peer_transmission (struct GNUNET_TRANSPORT_Handle *h) duration = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, th->notify_size - sizeof (struct OutboundMessage)); struct GNUNET_TIME_Absolute duration_abs = GNUNET_TIME_relative_to_absolute (duration); - if (th->timeout.value < duration_abs.value) + if (th->timeout.abs_value < duration_abs.abs_value) { /* signal timeout! */ #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Would need %llu ms before bandwidth is available for delivery to `%4s', that is too long. Signaling timeout.\n", - duration.value, + duration.abs_value, GNUNET_i2s (&n->id)); #endif if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK) @@ -484,7 +484,7 @@ schedule_peer_transmission (struct GNUNET_TRANSPORT_Handle *h) GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL)); continue; } - if (duration.value > 0) + if (duration.rel_value > 0) { #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -492,7 +492,7 @@ schedule_peer_transmission (struct GNUNET_TRANSPORT_Handle *h) (unsigned int) n->out_tracker.available_bytes_per_s__, (unsigned int) th->notify_size - sizeof (struct OutboundMessage), GNUNET_i2s (&n->id), - duration.value); + duration.abs_value); #endif retry_time = GNUNET_TIME_relative_min (retry_time, duration); @@ -608,7 +608,7 @@ transport_notify_ready (void *cls, size_t size, void *buf) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message of %u bytes with timeout %llums constructed for `%4s'\n", (unsigned int) mret, - (unsigned long long) GNUNET_TIME_absolute_get_remaining (th->timeout).value, + (unsigned long long) GNUNET_TIME_absolute_get_remaining (th->timeout).abs_value, GNUNET_i2s (&n->id)); #endif if (mret != 0) @@ -755,7 +755,7 @@ schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Control transmit of %u bytes within %llums requested\n", - size, (unsigned long long) timeout.value); + size, (unsigned long long) timeout.abs_value); #endif th = GNUNET_malloc (sizeof (struct ControlMessage)); th->h = h; @@ -1235,14 +1235,14 @@ schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h) #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduling task to reconnect to transport service in %llu ms.\n", - h->reconnect_delay.value); + h->reconnect_delay.abs_value); #endif GNUNET_assert (h->client == NULL); GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->sched, h->reconnect_delay, &reconnect, h); - if (h->reconnect_delay.value == 0) + if (h->reconnect_delay.rel_value == 0) { h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS; } @@ -1798,12 +1798,12 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle GNUNET_break (0); return NULL; } - +#if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking transport service for transmission of %u bytes to peer `%4s' within %llu ms.\n", size, GNUNET_i2s (target), - (unsigned long long) timeout.value); - + (unsigned long long) timeout.abs_value); +#endif n = neighbour_find (handle, target); if (n == NULL) { -- 2.25.1