From 817bbb71e3e583ec85d6d63ca3e0cbb90ccd7462 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 27 Mar 2011 10:32:30 +0000 Subject: [PATCH] communicate res delay in capi --- contrib/defaults.conf | 2 +- src/core/core.h | 7 +++++++ src/core/core_api.c | 17 ++++------------- src/core/gnunet-service-core.c | 7 +++++-- src/dht/gnunet-service-dht.c | 6 +++++- src/fs/gnunet-service-fs.c | 9 +++++++-- src/fs/gnunet-service-fs_cp.c | 6 +++++- src/include/gauger.h | 2 +- src/include/gnunet_core_service.h | 9 ++++++--- src/util/connection.c | 25 +++++++++++++++++++++---- 10 files changed, 62 insertions(+), 28 deletions(-) diff --git a/contrib/defaults.conf b/contrib/defaults.conf index f0ee4e3e0..fe98f1d18 100644 --- a/contrib/defaults.conf +++ b/contrib/defaults.conf @@ -295,7 +295,7 @@ PORT = 2094 HOSTNAME = localhost HOME = $SERVICEHOME CONFIG = $DEFAULTCONFIG -BINARY = gnunet-service-fs +BINARY = gnunet-service-fs-new ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; diff --git a/src/core/core.h b/src/core/core.h index fff4c3fa8..8a8962124 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -300,6 +300,13 @@ struct ConfigurationInfoMessage */ int32_t reserved_amount GNUNET_PACKED; + /** + * If the reservation request could not be satisfied (reserved_amount + * was zero), how long should the client wait until retrying? 0 if + * bandwidth was reserved. + */ + struct GNUNET_TIME_RelativeNBO reserve_delay; + /** * Unique request ID. */ diff --git a/src/core/core_api.c b/src/core/core_api.c index 767ee2957..3b5440135 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c @@ -422,7 +422,9 @@ disconnect_and_free_peer_entry (void *cls, pcic (pr->pcic_cls, &pr->peer, zero, - 0, 0); + 0, + GNUNET_TIME_UNIT_FOREVER_REL, + 0); } if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK) { @@ -1252,6 +1254,7 @@ main_notify_handler (void *cls, &pr->peer, cim->bw_out, ntohl (cim->reserved_amount), + GNUNET_TIME_relative_ntoh (cim->reserve_delay), GNUNET_ntohll (cim->preference)); break; default: @@ -1809,16 +1812,6 @@ struct GNUNET_CORE_InformationRequestContext */ struct GNUNET_CORE_Handle *h; - /** - * Function to call with the information. - */ - GNUNET_CORE_PeerConfigurationInfoCallback info; - - /** - * Closure for info. - */ - void *info_cls; - /** * Link to control message, NULL if CM was sent. */ @@ -1903,8 +1896,6 @@ GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h, irc = GNUNET_malloc (sizeof (struct GNUNET_CORE_InformationRequestContext)); irc->h = h; irc->pr = pr; - irc->info = info; - irc->info_cls = info_cls; cm = GNUNET_malloc (sizeof (struct ControlMessage) + sizeof (struct RequestInfoMessage)); cm->cont = &change_preference_send_continuation; diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 3068fd408..223430805 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c @@ -1571,6 +1571,7 @@ handle_client_request_info (void *cls, int32_t want_reserv; int32_t got_reserv; unsigned long long old_preference; + struct GNUNET_TIME_Relative rdelay; #if DEBUG_CORE_CLIENT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -1621,8 +1622,9 @@ handle_client_request_info (void *cls, } else if (want_reserv > 0) { - if (GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window, - want_reserv).rel_value == 0) + rdelay = GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window, + want_reserv); + if (rdelay.rel_value == 0) got_reserv = want_reserv; else got_reserv = 0; /* all or nothing */ @@ -1647,6 +1649,7 @@ handle_client_request_info (void *cls, (int) got_reserv); #endif cim.reserved_amount = htonl (got_reserv); + cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay); cim.rim_id = rcm->rim_id; cim.bw_out = n->bw_out; cim.preference = n->current_preference; diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 08cc7dc88..3311763cb 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c @@ -1466,13 +1466,17 @@ update_core_preference (void *cls, * @param bpm_out set to the current bandwidth limit (sending) for this peer * @param amount set to the amount that was actually reserved or unreserved; * either the full requested amount or zero (no partial reservations) + * @param res_delay if the reservation could not be satisfied (amount was 0), how + * long should the client wait until re-trying? * @param preference current traffic preference for the given peer */ static void update_core_preference_finish (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_BANDWIDTH_Value32NBO bpm_out, - int amount, uint64_t preference) + int32_t amount, + struct GNUNET_TIME_Relative res_delay, + uint64_t preference) { struct PeerInfo *peer_info = cls; peer_info->info_ctx = NULL; diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 687f131d1..74a88e7b2 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -2658,6 +2658,8 @@ refresh_bloomfilter (struct PendingRequest *pr) * @param peer identifies the peer * @param bpm_out set to the current bandwidth limit (sending) for this peer * @param amount set to the amount that was actually reserved or unreserved + * @param res_delay if the reservation could not be satisfied (amount was 0), how + * long should the client wait until re-trying? * @param preference current traffic preference for the given peer */ static void @@ -2665,7 +2667,8 @@ target_reservation_cb (void *cls, const struct GNUNET_PeerIdentity * peer, struct GNUNET_BANDWIDTH_Value32NBO bpm_out, - int amount, + int32_t amount, + struct GNUNET_TIME_Relative res_delay, uint64_t preference) { struct PendingRequest *pr = cls; @@ -3175,7 +3178,9 @@ forward_request_task (void *cls, /* force forwarding */ static struct GNUNET_BANDWIDTH_Value32NBO zerobw; target_reservation_cb (pr, &psc.target, - zerobw, 0, 0.0); + zerobw, 0, + GNUNET_TIME_UNIT_FOREVER_REL, + 0.0); } } diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c index 783bd4024..05638b657 100644 --- a/src/fs/gnunet-service-fs_cp.c +++ b/src/fs/gnunet-service-fs_cp.c @@ -330,13 +330,16 @@ peer_transmit_ready_cb (void *cls, * @param bandwidth_out available amount of outbound bandwidth * @param amount set to the amount that was actually reserved or unreserved; * either the full requested amount or zero (no partial reservations) + * @param res_delay if the reservation could not be satisfied (amount was 0), how + * long should the client wait until re-trying? * @param preference current traffic preference for the given peer */ static void core_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - int amount, + int32_t amount, + struct GNUNET_TIME_Relative res_delay, uint64_t preference) { struct GSF_ConnectedPeer *cp = cls; @@ -347,6 +350,7 @@ core_reserve_callback (void *cls, if (0 == amount) { /* failed; retry! (how did we get here!?) */ + /* FIXME: wait res_delay before re-trying! */ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to reserve bandwidth to peer `%s'\n"), GNUNET_i2s (peer)); diff --git a/src/include/gauger.h b/src/include/gauger.h index 8c4e9e3fb..206921d35 100644 --- a/src/include/gauger.h +++ b/src/include/gauger.h @@ -15,7 +15,7 @@ #include #include -#define GAUGER(category, counter, value, unit) {char* __gauger_v[10];char __gauger_s[32];pid_t __gauger_p; if(!(__gauger_p=fork())){if(!fork()){sprintf(__gauger_s,"%llu", (unsigned long long) (value));__gauger_v[0] = "gauger-cli.py";__gauger_v[1] = "-n";__gauger_v[2] = counter;__gauger_v[3] = "-d";__gauger_v[4] = __gauger_s;__gauger_v[5] = "-u";__gauger_v[6] = unit;__gauger_v[7] = "-c";__gauger_v[8] = category;__gauger_v[9] = (char *)NULL; close(2); execvp("gauger-cli.py",__gauger_v);perror("gauger");_exit(1);}else{_exit(0);}}else{waitpid(__gauger_p,NULL,0);}} +#define GAUGER(category, counter, value, unit) {char* __gauger_v[10];char __gauger_s[32];pid_t __gauger_p; if(!(__gauger_p=fork())){if(!fork()){sprintf(__gauger_s,"%llu", (unsigned long long) (value));__gauger_v[0] = "gauger-cli.py";__gauger_v[1] = "-n";__gauger_v[2] = counter;__gauger_v[3] = "-d";__gauger_v[4] = __gauger_s;__gauger_v[5] = "-u";__gauger_v[6] = unit;__gauger_v[7] = "-c";__gauger_v[8] = category;__gauger_v[9] = (char *)NULL; close (2); execvp("gauger-cli.py",__gauger_v);perror("gauger");_exit(1);}else{_exit(0);}}else{waitpid(__gauger_p,NULL,0);}} #define GAUGER_ID(category, counter, value, unit, id) {char* __gauger_v[12];char __gauger_s[32];pid_t __gauger_p; if(!(__gauger_p=fork())){if(!fork()){sprintf(__gauger_s,"%llu", (unsigned long long) (value));__gauger_v[0] = "gauger-cli.py";__gauger_v[1] = "-n";__gauger_v[2] = counter;__gauger_v[3] = "-d";__gauger_v[4] = __gauger_s;__gauger_v[5] = "-u";__gauger_v[6] = unit;__gauger_v[7] = "-i";__gauger_v[8] = id;__gauger_v[9] = "-c";__gauger_v[10] = category;__gauger_v[11] = (char *)NULL; close(2); execvp("gauger-cli.py",__gauger_v);perror("gauger");_exit(1);}else{_exit(0);}}else{waitpid(__gauger_p,NULL,0);}} diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h index 755604b88..fd4375355 100644 --- a/src/include/gnunet_core_service.h +++ b/src/include/gnunet_core_service.h @@ -77,7 +77,7 @@ typedef void (*GNUNET_CORE_ConnectEventHandler) (void *cls, */ typedef void (*GNUNET_CORE_PeerStatusEventHandler) (void *cls, const struct - GNUNET_PeerIdentity * peer, + GNUNET_PeerIdentity *peer, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_TIME_Absolute timeout, @@ -298,14 +298,17 @@ GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle *r * @param bandwidth_out available amount of outbound bandwidth * @param amount set to the amount that was actually reserved or unreserved; * either the full requested amount or zero (no partial reservations) + * @param res_delay if the reservation could not be satisfied (amount was 0), how + * long should the client wait until re-trying? * @param preference current traffic preference for the given peer */ typedef void (*GNUNET_CORE_PeerConfigurationInfoCallback) (void *cls, const struct - GNUNET_PeerIdentity * peer, + GNUNET_PeerIdentity *peer, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - int amount, + int32_t amount, + struct GNUNET_TIME_Relative res_delay, uint64_t preference); diff --git a/src/util/connection.c b/src/util/connection.c index 737a6e15c..5dbc9916b 100644 --- a/src/util/connection.c +++ b/src/util/connection.c @@ -1372,9 +1372,13 @@ process_notify (struct GNUNET_CONNECTION_Handle *sock) * expired). * * This task notifies the client about the timeout. + * + * @param cls the 'struct GNUNET_CONNECTION_Handle' + * @param tc scheduler context */ static void -transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +transmit_timeout (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CONNECTION_Handle *sock = cls; GNUNET_CONNECTION_TransmitReadyNotify notify; @@ -1403,15 +1407,23 @@ transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * at the time of being asked to transmit. * * This task notifies the client about the error. + * + * @param cls the 'struct GNUNET_CONNECTION_Handle' + * @param tc scheduler context */ static void -connect_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +connect_error (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CONNECTION_Handle *sock = cls; GNUNET_CONNECTION_TransmitReadyNotify notify; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Transmission request of size %u fails, connection failed (%p).\n", - sock->nth.notify_size, sock); + "Transmission request of size %u fails (%s/%u), connection failed (%p).\n", + sock->nth.notify_size, + sock->hostname, + sock->port, + sock); #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission request of size %u fails, connection failed (%p).\n", @@ -1424,6 +1436,11 @@ connect_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } +/** + * FIXME + * + * @param sock FIXME + */ static void transmit_error (struct GNUNET_CONNECTION_Handle *sock) { -- 2.25.1