From 094a3aa5ed1723f6cf17498b3d233c61736b399a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 10 Oct 2011 10:39:43 +0000 Subject: [PATCH] ATS API: do inbound and outbound bw --- src/ats/ats_api.c | 55 +++++++++++++------ src/include/gnunet_ats_service.h | 16 ++++-- src/transport/gnunet-service-transport.c | 9 ++- .../gnunet-service-transport_neighbours.c | 6 +- 4 files changed, 61 insertions(+), 25 deletions(-) diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c index f7f3c9552..ce598c4e3 100644 --- a/src/ats/ats_api.c +++ b/src/ats/ats_api.c @@ -77,9 +77,14 @@ struct AllocationRecord uint32_t ats_count; /** - * Bandwidth assigned to this address right now, 0 for none. + * Inbound bandwidth assigned to this address right now, 0 for none. */ - struct GNUNET_BANDWIDTH_Value32NBO bandwidth; + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; + + /** + * Outbound bandwidth assigned to this address right now, 0 for none. + */ + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; /** * Set to GNUNET_YES if this is the connected address of a connected peer. @@ -156,9 +161,14 @@ struct GNUNET_ATS_Handle GNUNET_SCHEDULER_TaskIdentifier ba_task; /** - * Total bandwidth per configuration. + * Total inbound bandwidth per configuration. + */ + unsigned long long total_bps_in; + + /** + * Total outbound bandwidth per configuration. */ - unsigned long long total_bps; + unsigned long long total_bps_out; }; @@ -193,9 +203,14 @@ struct SetBandwidthContext struct GNUNET_ATS_Handle *atc; /** - * Bandwidth to assign. + * Inbound bandwidth to assign. */ - struct GNUNET_BANDWIDTH_Value32NBO bw; + struct GNUNET_BANDWIDTH_Value32NBO bw_in; + + /** + * Outbound bandwidth to assign. + */ + struct GNUNET_BANDWIDTH_Value32NBO bw_out; }; @@ -215,19 +230,21 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value) if (GNUNET_YES == ar->connected) { - ar->bandwidth = sbc->bw; + ar->bandwidth_in = sbc->bw_in; + ar->bandwidth_out = sbc->bw_out; sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, (const struct GNUNET_PeerIdentity *) key, ar->plugin_name, ar->session, ar->plugin_addr, - ar->plugin_addr_len, ar->bandwidth); + ar->plugin_addr_len, ar->bandwidth_out, ar->bandwidth_in); } - else if (ntohl (ar->bandwidth.value__) > 0) + else if (ntohl (ar->bandwidth_out.value__) > 0) { - ar->bandwidth = GNUNET_BANDWIDTH_value_init (0); + ar->bandwidth_in = GNUNET_BANDWIDTH_value_init (0); + ar->bandwidth_out = GNUNET_BANDWIDTH_value_init (0); sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, (const struct GNUNET_PeerIdentity *) key, ar->plugin_name, ar->session, ar->plugin_addr, - ar->plugin_addr_len, ar->bandwidth); + ar->plugin_addr_len, ar->bandwidth_out, ar->bandwidth_in); } return GNUNET_YES; } @@ -253,7 +270,8 @@ update_bandwidth_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (ac == 0) ac++; GNUNET_assert (ac > 0); - bwc.bw = GNUNET_BANDWIDTH_value_init (atc->total_bps / ac); + bwc.bw_in = GNUNET_BANDWIDTH_value_init (atc->total_bps_in / ac); + bwc.bw_out = GNUNET_BANDWIDTH_value_init (atc->total_bps_out / ac); GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc); } @@ -296,7 +314,9 @@ suggest_address (void *cls, const GNUNET_HashCode * key, void *value) /* trivial strategy: pick first available address... */ asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr, ar->plugin_addr_len, ar->session, - GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), ar->ats, + GNUNET_BANDWIDTH_value_init (asc->atc->total_bps_out / 32), + GNUNET_BANDWIDTH_value_init (asc->atc->total_bps_in / 32), + ar->ats, ar->ats_count); asc->cb = NULL; return GNUNET_NO; @@ -392,7 +412,9 @@ GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg, atc->peers = GNUNET_CONTAINER_multihashmap_create (256); atc->notify_map = GNUNET_CONTAINER_multihashmap_create (256); GNUNET_CONFIGURATION_get_value_number (cfg, "core", "TOTAL_QUOTA_OUT", - &atc->total_bps); + &atc->total_bps_out); + GNUNET_CONFIGURATION_get_value_number (cfg, "core", "TOTAL_QUOTA_IN", + &atc->total_bps_in); return atc; } @@ -767,8 +789,9 @@ notify_valid (void *cls, const GNUNET_HashCode * key, void *value) asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr, ar->plugin_addr_len, ar->session, - GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), ar->ats, - ar->ats_count); + GNUNET_BANDWIDTH_value_init (asc->atc->total_bps_out / 32), + GNUNET_BANDWIDTH_value_init (asc->atc->total_bps_in / 32), + ar->ats, ar->ats_count); GNUNET_ATS_suggest_address_cancel (asc); asc = NULL; return GNUNET_OK; diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index 9317ace43..5e302da5c 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h @@ -56,7 +56,8 @@ struct GNUNET_ATS_Handle; * @param session session to use (if available) * @param plugin_addr address to use (if available) * @param plugin_addr_len number of bytes in addr - * @param bandwidth assigned outbound bandwidth for the connection + * @param bandwidth_out assigned outbound bandwidth for the connection + * @param bandwidth_in assigned inbound bandwidth for the connection */ typedef void (*GNUNET_TRANSPORT_ATS_AllocationNotification) (void *cls, const struct @@ -72,7 +73,10 @@ typedef void (*GNUNET_TRANSPORT_ATS_AllocationNotification) (void *cls, plugin_addr_len, struct GNUNET_BANDWIDTH_Value32NBO - bandwidth); + bandwidth_out, + struct + GNUNET_BANDWIDTH_Value32NBO + bandwidth_in); /** @@ -106,7 +110,8 @@ GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc); * @param plugin_name name of the plugin, NULL if we have no suggestion * @param plugin_addr suggested address, NULL if we have no suggestion * @param plugin_addr_len number of bytes in plugin_addr - * @param bandwidth assigned outbound bandwidth for the connection + * @param bandwidth_out assigned outbound bandwidth for the connection + * @param bandwidth_in assigned inbound bandwidth for the connection * @param ats performance data for the address (as far as known) * @param ats_count number of performance records in 'ats' */ @@ -120,7 +125,10 @@ typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls, struct Session * session, struct GNUNET_BANDWIDTH_Value32NBO - bandwidth, + bandwidth_out, + struct + GNUNET_BANDWIDTH_Value32NBO + bandwidth_in, const struct GNUNET_TRANSPORT_ATS_Information * ats, diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 3693bcf2e..fb5a5c5e6 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -322,17 +322,20 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, * @param session session to use (if available) * @param plugin_addr address to use (if available) * @param plugin_addr_len number of bytes in addr - * @param bandwidth assigned outbound bandwidth for the connection + * @param bandwidth_out assigned outbound bandwidth for the connection + * @param bandwidth_in assigned inbound bandwidth for the connection */ static void ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, const char *plugin_name, struct Session *session, const void *plugin_addr, size_t plugin_addr_len, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth) + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) { GST_neighbours_switch_to_address (peer, plugin_name, plugin_addr, plugin_addr_len, session, NULL, 0); - GST_neighbours_set_incoming_quota (peer, bandwidth); + GST_neighbours_set_incoming_quota (peer, bandwidth_in); + // FIXME: use 'bandwidth_out'! } diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index c4d880d0a..e4d0057ae 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -702,7 +702,8 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, * @param plugin_address binary address * @param plugin_address_len length of address * @param session session to use - * @param bandwidth available bandwidth + * @param bandwidth_out available outbound bandwidth + * @param bandwidth_in available inbound bandwidth * @param ats performance data for the address (as far as known) * @param ats_count number of performance records in 'ats' */ @@ -710,7 +711,8 @@ static void try_connect_using_address (void *cls, const struct GNUNET_PeerIdentity *target, const char *plugin_name, const void *plugin_address, size_t plugin_address_len, struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count) { -- 2.25.1