gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

commit e34f367380ed951b51895e24d99a81a12899278c
parent ff57ba65e29db50bd42e540ba95cb938a5ef8008
Author: Matthias Wachs <wachs@net.in.tum.de>
Date:   Thu, 30 Jan 2014 14:16:20 +0000

extending bandwidth tracker api to support notifications


Diffstat:
Msrc/ats/gnunet-service-ats_reservations.c | 2+-
Msrc/fragmentation/test_fragmentation.c | 2+-
Msrc/include/gnunet_bandwidth_lib.h | 23+++++++++++++++++++++--
Msrc/include/gnunet_transport_plugin.h | 7+++++++
Msrc/transport/gnunet-service-transport_neighbours.c | 20++++++++++++++++----
Msrc/transport/plugin_transport_bluetooth.c | 2+-
Msrc/transport/plugin_transport_udp.c | 2+-
Msrc/transport/plugin_transport_wlan.c | 2+-
Msrc/transport/transport_api.c | 18++++++++++++++++++
Msrc/util/bandwidth.c | 9+++++++++
10 files changed, 76 insertions(+), 11 deletions(-)

diff --git a/src/ats/gnunet-service-ats_reservations.c b/src/ats/gnunet-service-ats_reservations.c @@ -108,7 +108,7 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, if (NULL == tracker) { tracker = GNUNET_new (struct GNUNET_BANDWIDTH_Tracker); - GNUNET_BANDWIDTH_tracker_init (tracker, bandwidth_in, + GNUNET_BANDWIDTH_tracker_init (tracker, NULL, NULL, bandwidth_in, MAX_BANDWIDTH_CARRY_S); GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (trackers, peer, tracker, diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c @@ -241,7 +241,7 @@ main (int argc, char *argv[]) "WARNING", NULL); for (i = 0; i < NUM_MSGS; i++) - GNUNET_BANDWIDTH_tracker_init (&trackers[i], + GNUNET_BANDWIDTH_tracker_init (&trackers[i], NULL, NULL, GNUNET_BANDWIDTH_value_init ((i + 1) * 1024), 100); GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options, diff --git a/src/include/gnunet_bandwidth_lib.h b/src/include/gnunet_bandwidth_lib.h @@ -52,6 +52,17 @@ struct GNUNET_BANDWIDTH_Value32NBO }; GNUNET_NETWORK_STRUCT_END + +/** + * Callback to be called by the bandwidth tracker if the tracker + * was updated and the client should update it's delay values + * + * @param cls a closure to pass + */ +void +typedef (*GNUNET_BANDWIDTH_tracker_update_cb) (void *cls); + + /** * Struct to track available bandwidth. Combines a time stamp with a * number of bytes transmitted, a quota and a maximum amount that @@ -61,6 +72,10 @@ GNUNET_NETWORK_STRUCT_END */ struct GNUNET_BANDWIDTH_Tracker { + void *update_cb_cls; + + GNUNET_BANDWIDTH_tracker_update_cb update_cb; + /** * Number of bytes consumed since we last updated the tracker. */ @@ -129,7 +144,6 @@ GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps, uint64_t size); - /** * Compute the MIN of two bandwidth values. * @@ -152,14 +166,19 @@ GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1, * bytes). * * @param av tracker to initialize + * @param update_cb callback to notify a client about the tracker being updated + * @param update_cb_cls cls for the callback * @param bytes_per_second_limit initial limit to assume * @param max_carry_s maximum number of seconds unused bandwidth * may accumulate before it expires */ void GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av, + GNUNET_BANDWIDTH_tracker_update_cb update_cb, + void *update_cb_cls, struct GNUNET_BANDWIDTH_Value32NBO - bytes_per_second_limit, uint32_t max_carry_s); + bytes_per_second_limit, + uint32_t max_carry_s); /** diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h @@ -576,6 +576,13 @@ struct GNUNET_TRANSPORT_PluginFunctions GNUNET_TRANSPORT_UpdateSessionTimeout update_session_timeout; /** + * Function that will be called whenever the transport service wants to + * notify the plugin that the inbound quota changed and that the plugin + * should update it's delay for the next receive value + */ + //GNUNET_TRANSPORT_UpdateNextReceiveTimeout update_next_receive_timeout; + + /** * Function that is used to query keepalive factor. * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to * calculate the interval between keepalive packets. diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c @@ -1689,6 +1689,15 @@ send_session_connect_ack_message (const struct GNUNET_HELLO_Address *address, } +static void +inbound_bw_tracker_update (void *cls) +{ + struct Neighbour *n = cls; + + /* Quota was updated, tell plugins to update the time to receive next */ + +} + /** * Create a fresh entry in the neighbour map for the given peer @@ -1712,7 +1721,7 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer) n->util_payload_bytes_sent = 0; n->util_total_bytes_recv = 0; n->util_total_bytes_sent = 0; - GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, + GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, &inbound_bw_tracker_update, n, GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, MAX_BANDWIDTH_CARRY_S); n->task = GNUNET_SCHEDULER_add_now (&master_task, n); @@ -2535,6 +2544,7 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { struct NeighbourMapEntry *n; + struct GST_BlacklistCheck *blc; struct GNUNET_TRANSPORT_PluginFunctions *papi; struct BlacklistCheckSwitchContext *blc_ctx; int c; @@ -2601,8 +2611,11 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, } GNUNET_CONTAINER_DLL_insert (pending_bc_head, pending_bc_tail, blc_ctx); - blc_ctx->blc = GST_blacklist_test_allowed (peer, address->transport_name, - &switch_address_bl_check_cont, blc_ctx); + if (NULL != (blc = GST_blacklist_test_allowed (peer, address->transport_name, + &switch_address_bl_check_cont, blc_ctx))) + { + blc_ctx->blc = blc; + } } @@ -3338,7 +3351,6 @@ GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target) return test_connected (lookup_neighbour (target)); } - /** * Change the incoming quota for the given peer. * diff --git a/src/transport/plugin_transport_bluetooth.c b/src/transport/plugin_transport_bluetooth.c @@ -1943,7 +1943,7 @@ libgnunet_plugin_transport_bluetooth_init (void *cls) 0, GNUNET_NO); GNUNET_STATISTICS_set (plugin->env->stats, _("# Bluetooth MAC endpoints allocated"), 0, 0); - GNUNET_BANDWIDTH_tracker_init (&plugin->tracker, + GNUNET_BANDWIDTH_tracker_init (&plugin->tracker, NULL, NULL, GNUNET_BANDWIDTH_value_init (100 * 1024 * 1024 / 8), 100); plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin); diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c @@ -3007,7 +3007,7 @@ libgnunet_plugin_transport_udp_init (void *cls) p->defrag_ctxs = GNUNET_CONTAINER_heap_create ( GNUNET_CONTAINER_HEAP_ORDER_MIN); p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, p); - GNUNET_BANDWIDTH_tracker_init (&p->tracker, + GNUNET_BANDWIDTH_tracker_init (&p->tracker, NULL, NULL, GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps), 30); plugin = p; diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c @@ -1949,7 +1949,7 @@ libgnunet_plugin_transport_wlan_init (void *cls) 0, GNUNET_NO); GNUNET_STATISTICS_set (plugin->env->stats, _("# WLAN MAC endpoints allocated"), 0, 0); - GNUNET_BANDWIDTH_tracker_init (&plugin->tracker, + GNUNET_BANDWIDTH_tracker_init (&plugin->tracker, NULL, NULL, GNUNET_BANDWIDTH_value_init (100 * 1024 * 1024 / 8), 100); plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin); diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c @@ -419,6 +419,23 @@ neighbour_find (struct GNUNET_TRANSPORT_Handle *h, } + +static void +outbound_bw_tracker_update (void *cls) +{ + struct Neighbour *n = cls; + struct GNUNET_TIME_Relative delay; + if (NULL == n->hn) + return; + + delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, + n->th->notify_size + n->traffic_overhead); + GNUNET_CONTAINER_heap_update_cost (n->h->ready_heap, + n->hn, delay.rel_value_us); + schedule_transmission (n->h); +} + + /** * Add neighbour to our list * @@ -439,6 +456,7 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h, n->is_ready = GNUNET_YES; n->traffic_overhead = 0; GNUNET_BANDWIDTH_tracker_init (&n->out_tracker, + outbound_bw_tracker_update, n, GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, MAX_BANDWIDTH_CARRY_S); GNUNET_assert (GNUNET_OK == diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c @@ -120,6 +120,7 @@ GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps, } + /** * Initialize bandwidth tracker. Note that in addition to the * 'max_carry_s' limit, we also always allow at least @@ -130,15 +131,21 @@ GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps, * bytes). * * @param av tracker to initialize + * @param update_cb callback to notify a client about the tracker being updated + * @param update_cb_cls cls for the callback * @param bytes_per_second_limit initial limit to assume * @param max_carry_s maximum number of seconds unused bandwidth * may accumulate before it expires */ void GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av, + GNUNET_BANDWIDTH_tracker_update_cb update_cb, + void *update_cb_cls, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit, uint32_t max_carry_s) { + av->update_cb = update_cb; + av->update_cb_cls = update_cb_cls; av->consumption_since_last_update__ = 0; av->last_update__ = GNUNET_TIME_absolute_get (); av->available_bytes_per_s__ = ntohl (bytes_per_second_limit.value__); @@ -327,6 +334,8 @@ GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av, update_tracker (av); old_limit = av->available_bytes_per_s__; av->available_bytes_per_s__ = new_limit; + if (NULL != av->update_cb) + av->update_cb (av->update_cb_cls); if (old_limit > new_limit) update_tracker (av); /* maximum excess might be less now */ }