diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-10 10:39:43 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-10 10:39:43 +0000 |
commit | 094a3aa5ed1723f6cf17498b3d233c61736b399a (patch) | |
tree | c786e8ad0afce06100b58655ec54671f7c91b1eb /src/ats/ats_api.c | |
parent | e93cd1377e5a3a5d7e4327eaef0c9e38daa98b3f (diff) | |
download | gnunet-094a3aa5ed1723f6cf17498b3d233c61736b399a.tar.gz gnunet-094a3aa5ed1723f6cf17498b3d233c61736b399a.zip |
ATS API: do inbound and outbound bw
Diffstat (limited to 'src/ats/ats_api.c')
-rw-r--r-- | src/ats/ats_api.c | 55 |
1 files changed, 39 insertions, 16 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 | |||
77 | uint32_t ats_count; | 77 | uint32_t ats_count; |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * Bandwidth assigned to this address right now, 0 for none. | 80 | * Inbound bandwidth assigned to this address right now, 0 for none. |
81 | */ | 81 | */ |
82 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth; | 82 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; |
83 | |||
84 | /** | ||
85 | * Outbound bandwidth assigned to this address right now, 0 for none. | ||
86 | */ | ||
87 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; | ||
83 | 88 | ||
84 | /** | 89 | /** |
85 | * Set to GNUNET_YES if this is the connected address of a connected peer. | 90 | * Set to GNUNET_YES if this is the connected address of a connected peer. |
@@ -156,9 +161,14 @@ struct GNUNET_ATS_Handle | |||
156 | GNUNET_SCHEDULER_TaskIdentifier ba_task; | 161 | GNUNET_SCHEDULER_TaskIdentifier ba_task; |
157 | 162 | ||
158 | /** | 163 | /** |
159 | * Total bandwidth per configuration. | 164 | * Total inbound bandwidth per configuration. |
165 | */ | ||
166 | unsigned long long total_bps_in; | ||
167 | |||
168 | /** | ||
169 | * Total outbound bandwidth per configuration. | ||
160 | */ | 170 | */ |
161 | unsigned long long total_bps; | 171 | unsigned long long total_bps_out; |
162 | }; | 172 | }; |
163 | 173 | ||
164 | 174 | ||
@@ -193,9 +203,14 @@ struct SetBandwidthContext | |||
193 | struct GNUNET_ATS_Handle *atc; | 203 | struct GNUNET_ATS_Handle *atc; |
194 | 204 | ||
195 | /** | 205 | /** |
196 | * Bandwidth to assign. | 206 | * Inbound bandwidth to assign. |
197 | */ | 207 | */ |
198 | struct GNUNET_BANDWIDTH_Value32NBO bw; | 208 | struct GNUNET_BANDWIDTH_Value32NBO bw_in; |
209 | |||
210 | /** | ||
211 | * Outbound bandwidth to assign. | ||
212 | */ | ||
213 | struct GNUNET_BANDWIDTH_Value32NBO bw_out; | ||
199 | }; | 214 | }; |
200 | 215 | ||
201 | 216 | ||
@@ -215,19 +230,21 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value) | |||
215 | 230 | ||
216 | if (GNUNET_YES == ar->connected) | 231 | if (GNUNET_YES == ar->connected) |
217 | { | 232 | { |
218 | ar->bandwidth = sbc->bw; | 233 | ar->bandwidth_in = sbc->bw_in; |
234 | ar->bandwidth_out = sbc->bw_out; | ||
219 | sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, | 235 | sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, |
220 | (const struct GNUNET_PeerIdentity *) key, | 236 | (const struct GNUNET_PeerIdentity *) key, |
221 | ar->plugin_name, ar->session, ar->plugin_addr, | 237 | ar->plugin_name, ar->session, ar->plugin_addr, |
222 | ar->plugin_addr_len, ar->bandwidth); | 238 | ar->plugin_addr_len, ar->bandwidth_out, ar->bandwidth_in); |
223 | } | 239 | } |
224 | else if (ntohl (ar->bandwidth.value__) > 0) | 240 | else if (ntohl (ar->bandwidth_out.value__) > 0) |
225 | { | 241 | { |
226 | ar->bandwidth = GNUNET_BANDWIDTH_value_init (0); | 242 | ar->bandwidth_in = GNUNET_BANDWIDTH_value_init (0); |
243 | ar->bandwidth_out = GNUNET_BANDWIDTH_value_init (0); | ||
227 | sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, | 244 | sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, |
228 | (const struct GNUNET_PeerIdentity *) key, | 245 | (const struct GNUNET_PeerIdentity *) key, |
229 | ar->plugin_name, ar->session, ar->plugin_addr, | 246 | ar->plugin_name, ar->session, ar->plugin_addr, |
230 | ar->plugin_addr_len, ar->bandwidth); | 247 | ar->plugin_addr_len, ar->bandwidth_out, ar->bandwidth_in); |
231 | } | 248 | } |
232 | return GNUNET_YES; | 249 | return GNUNET_YES; |
233 | } | 250 | } |
@@ -253,7 +270,8 @@ update_bandwidth_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
253 | if (ac == 0) | 270 | if (ac == 0) |
254 | ac++; | 271 | ac++; |
255 | GNUNET_assert (ac > 0); | 272 | GNUNET_assert (ac > 0); |
256 | bwc.bw = GNUNET_BANDWIDTH_value_init (atc->total_bps / ac); | 273 | bwc.bw_in = GNUNET_BANDWIDTH_value_init (atc->total_bps_in / ac); |
274 | bwc.bw_out = GNUNET_BANDWIDTH_value_init (atc->total_bps_out / ac); | ||
257 | GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc); | 275 | GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc); |
258 | } | 276 | } |
259 | 277 | ||
@@ -296,7 +314,9 @@ suggest_address (void *cls, const GNUNET_HashCode * key, void *value) | |||
296 | /* trivial strategy: pick first available address... */ | 314 | /* trivial strategy: pick first available address... */ |
297 | asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr, | 315 | asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr, |
298 | ar->plugin_addr_len, ar->session, | 316 | ar->plugin_addr_len, ar->session, |
299 | GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), ar->ats, | 317 | GNUNET_BANDWIDTH_value_init (asc->atc->total_bps_out / 32), |
318 | GNUNET_BANDWIDTH_value_init (asc->atc->total_bps_in / 32), | ||
319 | ar->ats, | ||
300 | ar->ats_count); | 320 | ar->ats_count); |
301 | asc->cb = NULL; | 321 | asc->cb = NULL; |
302 | return GNUNET_NO; | 322 | return GNUNET_NO; |
@@ -392,7 +412,9 @@ GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
392 | atc->peers = GNUNET_CONTAINER_multihashmap_create (256); | 412 | atc->peers = GNUNET_CONTAINER_multihashmap_create (256); |
393 | atc->notify_map = GNUNET_CONTAINER_multihashmap_create (256); | 413 | atc->notify_map = GNUNET_CONTAINER_multihashmap_create (256); |
394 | GNUNET_CONFIGURATION_get_value_number (cfg, "core", "TOTAL_QUOTA_OUT", | 414 | GNUNET_CONFIGURATION_get_value_number (cfg, "core", "TOTAL_QUOTA_OUT", |
395 | &atc->total_bps); | 415 | &atc->total_bps_out); |
416 | GNUNET_CONFIGURATION_get_value_number (cfg, "core", "TOTAL_QUOTA_IN", | ||
417 | &atc->total_bps_in); | ||
396 | return atc; | 418 | return atc; |
397 | } | 419 | } |
398 | 420 | ||
@@ -767,8 +789,9 @@ notify_valid (void *cls, const GNUNET_HashCode * key, void *value) | |||
767 | 789 | ||
768 | asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr, | 790 | asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr, |
769 | ar->plugin_addr_len, ar->session, | 791 | ar->plugin_addr_len, ar->session, |
770 | GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), ar->ats, | 792 | GNUNET_BANDWIDTH_value_init (asc->atc->total_bps_out / 32), |
771 | ar->ats_count); | 793 | GNUNET_BANDWIDTH_value_init (asc->atc->total_bps_in / 32), |
794 | ar->ats, ar->ats_count); | ||
772 | GNUNET_ATS_suggest_address_cancel (asc); | 795 | GNUNET_ATS_suggest_address_cancel (asc); |
773 | asc = NULL; | 796 | asc = NULL; |
774 | return GNUNET_OK; | 797 | return GNUNET_OK; |