aboutsummaryrefslogtreecommitdiff
path: root/src/util/bandwidth.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-26 14:21:49 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-26 14:21:49 +0000
commit34961f382d98822d1fa3506e8bfdf163e2e915ea (patch)
tree855ac5770b741da80fc8c2fff1bfb283913e9685 /src/util/bandwidth.c
parent3d97cc0d1b93fd0ee2deb2440b3c3a59bfa506ed (diff)
downloadgnunet-34961f382d98822d1fa3506e8bfdf163e2e915ea.tar.gz
gnunet-34961f382d98822d1fa3506e8bfdf163e2e915ea.zip
-some more #if DEBUG elimination
Diffstat (limited to 'src/util/bandwidth.c')
-rw-r--r--src/util/bandwidth.c30
1 files changed, 1 insertions, 29 deletions
diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c
index 0920362f5..9d679493a 100644
--- a/src/util/bandwidth.c
+++ b/src/util/bandwidth.c
@@ -27,9 +27,8 @@
27#include "gnunet_bandwidth_lib.h" 27#include "gnunet_bandwidth_lib.h"
28#include "gnunet_server_lib.h" 28#include "gnunet_server_lib.h"
29 29
30#define DEBUG_BANDWIDTH GNUNET_EXTRA_LOGGING
31 30
32#define LOG(kind,...) GNUNET_log_from (kind, "util",__VA_ARGS__) 31#define LOG(kind,...) GNUNET_log_from (kind, "util-bandwidth", __VA_ARGS__)
33 32
34/** 33/**
35 * Create a new bandwidth value. 34 * Create a new bandwidth value.
@@ -42,10 +41,8 @@ GNUNET_BANDWIDTH_value_init (uint32_t bytes_per_second)
42{ 41{
43 struct GNUNET_BANDWIDTH_Value32NBO ret; 42 struct GNUNET_BANDWIDTH_Value32NBO ret;
44 43
45#if DEBUG_BANDWIDTH
46 LOG (GNUNET_ERROR_TYPE_DEBUG, "Initializing bandwidth of %u Bps\n", 44 LOG (GNUNET_ERROR_TYPE_DEBUG, "Initializing bandwidth of %u Bps\n",
47 (unsigned int) bytes_per_second); 45 (unsigned int) bytes_per_second);
48#endif
49 ret.value__ = htonl (bytes_per_second); 46 ret.value__ = htonl (bytes_per_second);
50 return ret; 47 return ret;
51} 48}
@@ -85,12 +82,10 @@ GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO
85 uint64_t b; 82 uint64_t b;
86 83
87 b = ntohl (bps.value__); 84 b = ntohl (bps.value__);
88#if DEBUG_BANDWIDTH
89 LOG (GNUNET_ERROR_TYPE_DEBUG, 85 LOG (GNUNET_ERROR_TYPE_DEBUG,
90 "Bandwidth has %llu bytes available until deadline in %llums\n", 86 "Bandwidth has %llu bytes available until deadline in %llums\n",
91 (unsigned long long) ((b * deadline.rel_value + 500LL) / 1000LL), 87 (unsigned long long) ((b * deadline.rel_value + 500LL) / 1000LL),
92 deadline.rel_value); 88 deadline.rel_value);
93#endif
94 return (b * deadline.rel_value + 500LL) / 1000LL; 89 return (b * deadline.rel_value + 500LL) / 1000LL;
95} 90}
96 91
@@ -113,18 +108,14 @@ GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps,
113 b = ntohl (bps.value__); 108 b = ntohl (bps.value__);
114 if (b == 0) 109 if (b == 0)
115 { 110 {
116#if DEBUG_BANDWIDTH
117 LOG (GNUNET_ERROR_TYPE_DEBUG, 111 LOG (GNUNET_ERROR_TYPE_DEBUG,
118 "Bandwidth suggests delay of infinity (zero bandwidth)\n"); 112 "Bandwidth suggests delay of infinity (zero bandwidth)\n");
119#endif
120 return GNUNET_TIME_UNIT_FOREVER_REL; 113 return GNUNET_TIME_UNIT_FOREVER_REL;
121 } 114 }
122 ret.rel_value = size * 1000LL / b; 115 ret.rel_value = size * 1000LL / b;
123#if DEBUG_BANDWIDTH
124 LOG (GNUNET_ERROR_TYPE_DEBUG, 116 LOG (GNUNET_ERROR_TYPE_DEBUG,
125 "Bandwidth suggests delay of %llu ms for %llu bytes of traffic\n", 117 "Bandwidth suggests delay of %llu ms for %llu bytes of traffic\n",
126 (unsigned long long) ret.rel_value, (unsigned long long) size); 118 (unsigned long long) ret.rel_value, (unsigned long long) size);
127#endif
128 return ret; 119 return ret;
129} 120}
130 121
@@ -152,11 +143,9 @@ GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av,
152 av->last_update__ = GNUNET_TIME_absolute_get (); 143 av->last_update__ = GNUNET_TIME_absolute_get ();
153 av->available_bytes_per_s__ = ntohl (bytes_per_second_limit.value__); 144 av->available_bytes_per_s__ = ntohl (bytes_per_second_limit.value__);
154 av->max_carry_s__ = max_carry_s; 145 av->max_carry_s__ = max_carry_s;
155#if DEBUG_BANDWIDTH
156 LOG (GNUNET_ERROR_TYPE_DEBUG, 146 LOG (GNUNET_ERROR_TYPE_DEBUG,
157 "Tracker %p initialized with %u Bps and max carry %u\n", av, 147 "Tracker %p initialized with %u Bps and max carry %u\n", av,
158 (unsigned int) av->available_bytes_per_s__, (unsigned int) max_carry_s); 148 (unsigned int) av->available_bytes_per_s__, (unsigned int) max_carry_s);
159#endif
160} 149}
161 150
162 151
@@ -193,13 +182,10 @@ update_tracker (struct GNUNET_BANDWIDTH_Tracker *av)
193 else 182 else
194 av->consumption_since_last_update__ = -max_carry; 183 av->consumption_since_last_update__ = -max_carry;
195 } 184 }
196#if DEBUG_BANDWIDTH
197 LOG (GNUNET_ERROR_TYPE_DEBUG, 185 LOG (GNUNET_ERROR_TYPE_DEBUG,
198 "Tracker %p updated, have %u Bps, last update was %llu ms ago\n", av, 186 "Tracker %p updated, have %u Bps, last update was %llu ms ago\n", av,
199 (unsigned int) av->available_bytes_per_s__, 187 (unsigned int) av->available_bytes_per_s__,
200 (unsigned long long) delta_time); 188 (unsigned long long) delta_time);
201#endif
202
203} 189}
204 190
205 191
@@ -220,10 +206,8 @@ GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av,
220{ 206{
221 int64_t nc; 207 int64_t nc;
222 208
223#if DEBUG_BANDWIDTH
224 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p consumes %d bytes\n", av, 209 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p consumes %d bytes\n", av,
225 (int) size); 210 (int) size);
226#endif
227 if (size > 0) 211 if (size > 0)
228 { 212 {
229 nc = av->consumption_since_last_update__ + size; 213 nc = av->consumption_since_last_update__ + size;
@@ -236,11 +220,9 @@ GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av,
236 update_tracker (av); 220 update_tracker (av);
237 if (av->consumption_since_last_update__ > 0) 221 if (av->consumption_since_last_update__ > 0)
238 { 222 {
239#if DEBUG_BANDWIDTH
240 LOG (GNUNET_ERROR_TYPE_DEBUG, 223 LOG (GNUNET_ERROR_TYPE_DEBUG,
241 "Tracker %p consumption %llu bytes above limit\n", av, 224 "Tracker %p consumption %llu bytes above limit\n", av,
242 (unsigned long long) av->consumption_since_last_update__); 225 (unsigned long long) av->consumption_since_last_update__);
243#endif
244 return GNUNET_YES; 226 return GNUNET_YES;
245 } 227 }
246 } 228 }
@@ -270,28 +252,22 @@ GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av,
270 252
271 if (av->available_bytes_per_s__ == 0) 253 if (av->available_bytes_per_s__ == 0)
272 { 254 {
273#if DEBUG_BANDWIDTH
274 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay is infinity\n", av); 255 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay is infinity\n", av);
275#endif
276 return GNUNET_TIME_UNIT_FOREVER_REL; 256 return GNUNET_TIME_UNIT_FOREVER_REL;
277 } 257 }
278 update_tracker (av); 258 update_tracker (av);
279 bytes_needed = size + av->consumption_since_last_update__; 259 bytes_needed = size + av->consumption_since_last_update__;
280 if (bytes_needed <= 0) 260 if (bytes_needed <= 0)
281 { 261 {
282#if DEBUG_BANDWIDTH
283 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay for %u bytes is zero\n", av, 262 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay for %u bytes is zero\n", av,
284 (unsigned int) size); 263 (unsigned int) size);
285#endif
286 return GNUNET_TIME_UNIT_ZERO; 264 return GNUNET_TIME_UNIT_ZERO;
287 } 265 }
288 ret.rel_value = 266 ret.rel_value =
289 (1000LL * bytes_needed) / 267 (1000LL * bytes_needed) /
290 (unsigned long long) av->available_bytes_per_s__; 268 (unsigned long long) av->available_bytes_per_s__;
291#if DEBUG_BANDWIDTH
292 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay for %u bytes is %llu ms\n", 269 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay for %u bytes is %llu ms\n",
293 av, (unsigned int) size, (unsigned long long) ret.rel_value); 270 av, (unsigned int) size, (unsigned long long) ret.rel_value);
294#endif
295 return ret; 271 return ret;
296} 272}
297 273
@@ -317,11 +293,9 @@ GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker * av)
317 GNUNET_TIME_absolute_get_duration 293 GNUNET_TIME_absolute_get_duration
318 (av->last_update__)); 294 (av->last_update__));
319 used = av->consumption_since_last_update__; 295 used = av->consumption_since_last_update__;
320#if DEBUG_BANDWIDTH
321 LOG (GNUNET_ERROR_TYPE_DEBUG, 296 LOG (GNUNET_ERROR_TYPE_DEBUG,
322 "Tracker %p available bandwidth is %lld bytes\n", av, 297 "Tracker %p available bandwidth is %lld bytes\n", av,
323 (long long) (int64_t) (avail - used)); 298 (long long) (int64_t) (avail - used));
324#endif
325 return (int64_t) (avail - used); 299 return (int64_t) (avail - used);
326} 300}
327 301
@@ -341,10 +315,8 @@ GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av,
341 uint32_t new_limit; 315 uint32_t new_limit;
342 316
343 new_limit = ntohl (bytes_per_second_limit.value__); 317 new_limit = ntohl (bytes_per_second_limit.value__);
344#if DEBUG_BANDWIDTH
345 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p bandwidth changed to %u Bps\n", av, 318 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p bandwidth changed to %u Bps\n", av,
346 (unsigned int) new_limit); 319 (unsigned int) new_limit);
347#endif
348 update_tracker (av); 320 update_tracker (av);
349 old_limit = av->available_bytes_per_s__; 321 old_limit = av->available_bytes_per_s__;
350 av->available_bytes_per_s__ = new_limit; 322 av->available_bytes_per_s__ = new_limit;