aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-04-06 11:09:44 +0000
committerChristian Grothoff <christian@grothoff.org>2010-04-06 11:09:44 +0000
commit85a2e0d5b24495e0b2595a76a3205c4970a71fce (patch)
treedb95c013f061d68ae4b6a65e0d196703ea33777a
parent46c8217e87a0be0550b88ae9bafc4760305eabfa (diff)
downloadgnunet-85a2e0d5b24495e0b2595a76a3205c4970a71fce.tar.gz
gnunet-85a2e0d5b24495e0b2595a76a3205c4970a71fce.zip
bwtracking
-rw-r--r--src/fs/fs_test_lib_data.conf3
-rw-r--r--src/fs/test_fs_data.conf1
-rw-r--r--src/transport/gnunet-service-transport.c10
-rw-r--r--src/util/bandwidth.c94
4 files changed, 103 insertions, 5 deletions
diff --git a/src/fs/fs_test_lib_data.conf b/src/fs/fs_test_lib_data.conf
index b2fbd5ee0..dc18d8c15 100644
--- a/src/fs/fs_test_lib_data.conf
+++ b/src/fs/fs_test_lib_data.conf
@@ -12,7 +12,7 @@ HOSTNAME = localhost
12[transport] 12[transport]
13PORT = 43465 13PORT = 43465
14PLUGINS = tcp 14PLUGINS = tcp
15#DEBUG = YES 15DEBUG = YES
16 16
17[arm] 17[arm]
18PORT = 43466 18PORT = 43466
@@ -32,6 +32,7 @@ HOSTNAME = localhost
32ALLOW_SHUTDOWN = NO 32ALLOW_SHUTDOWN = NO
33TIMEOUT = 300000 33TIMEOUT = 300000
34#PORT = 43468 34#PORT = 43468
35DEBUG = YES
35 36
36[peerinfo] 37[peerinfo]
37PORT = 43469 38PORT = 43469
diff --git a/src/fs/test_fs_data.conf b/src/fs/test_fs_data.conf
index 632c23ea7..c5fd6ec0c 100644
--- a/src/fs/test_fs_data.conf
+++ b/src/fs/test_fs_data.conf
@@ -12,6 +12,7 @@ HOSTNAME = localhost
12[transport] 12[transport]
13PORT = 42465 13PORT = 42465
14PLUGINS = 14PLUGINS =
15DEBUG = YES
15 16
16[arm] 17[arm]
17PORT = 42466 18PORT = 42466
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 7c2c0eadd..5dcbc4baa 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -1161,6 +1161,7 @@ find_ready_address(struct NeighbourList *neighbour)
1161 addresses = head->addresses; 1161 addresses = head->addresses;
1162 while (addresses != NULL) 1162 while (addresses != NULL)
1163 { 1163 {
1164#if DEBUG_TRANSPORT > 1
1164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1165 "Have address `%s' for peer `%4s' (status: %d, %d, %d, %u, %llums, %u)\n", 1166 "Have address `%s' for peer `%4s' (status: %d, %d, %d, %u, %llums, %u)\n",
1166 GNUNET_a2s (addresses->addr, 1167 GNUNET_a2s (addresses->addr,
@@ -1172,6 +1173,7 @@ find_ready_address(struct NeighbourList *neighbour)
1172 addresses->connect_attempts, 1173 addresses->connect_attempts,
1173 (unsigned long long) addresses->timeout.value, 1174 (unsigned long long) addresses->timeout.value,
1174 (unsigned int) addresses->distance); 1175 (unsigned int) addresses->distance);
1176#endif
1175 if ( ( (best_address == NULL) || 1177 if ( ( (best_address == NULL) ||
1176 (addresses->connected == GNUNET_YES) || 1178 (addresses->connected == GNUNET_YES) ||
1177 (best_address->connected == GNUNET_NO) ) && 1179 (best_address->connected == GNUNET_NO) ) &&
@@ -1237,9 +1239,11 @@ try_transmission_to_peer (struct NeighbourList *neighbour)
1237 1239
1238 if (neighbour->messages_head == NULL) 1240 if (neighbour->messages_head == NULL)
1239 { 1241 {
1242#if DEBUG_TRANSPORT
1240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1241 "Transmission queue for `%4s' is empty\n", 1244 "Transmission queue for `%4s' is empty\n",
1242 GNUNET_i2s (&neighbour->id)); 1245 GNUNET_i2s (&neighbour->id));
1246#endif
1243 return; /* nothing to do */ 1247 return; /* nothing to do */
1244 } 1248 }
1245 rl = NULL; 1249 rl = NULL;
@@ -3174,6 +3178,12 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
3174 (ssize_t) msize)) 3178 (ssize_t) msize))
3175 { 3179 {
3176 n->quota_violation_count++; 3180 n->quota_violation_count++;
3181 GNUNET_log (GNUNET_ERROR_TYPE_WARNING |
3182 GNUNET_ERROR_TYPE_BULK,
3183 _
3184 ("Bandwidth quota (%u b/s) violation detected (total of %u).\n"),
3185 n->in_tracker.available_bytes_per_s__,
3186 n->quota_violation_count);
3177 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD) 3187 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
3178 { 3188 {
3179 /* since we'll be dropping, only count this message for half so that 3189 /* since we'll be dropping, only count this message for half so that
diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c
index 52b0dd0e5..6cca58995 100644
--- a/src/util/bandwidth.c
+++ b/src/util/bandwidth.c
@@ -27,6 +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_YES
31
30/** 32/**
31 * Create a new bandwidth value. 33 * Create a new bandwidth value.
32 * 34 *
@@ -38,6 +40,11 @@ GNUNET_BANDWIDTH_value_init (uint32_t bytes_per_second)
38{ 40{
39 struct GNUNET_BANDWIDTH_Value32NBO ret; 41 struct GNUNET_BANDWIDTH_Value32NBO ret;
40 42
43#if DEBUG_BANDWIDTH
44 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
45 "Initializing bandwidth of %u bps\n",
46 (unsigned int) bytes_per_second);
47#endif
41 ret.value__ = htonl (bytes_per_second); 48 ret.value__ = htonl (bytes_per_second);
42 return ret; 49 return ret;
43} 50}
@@ -74,6 +81,12 @@ GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO b
74 uint64_t b; 81 uint64_t b;
75 82
76 b = ntohl (bps.value__); 83 b = ntohl (bps.value__);
84#if DEBUG_BANDWIDTH
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
86 "Bandwidth has %llu bytes available until deadline in %llums\n",
87 (unsigned long long) (b * deadline.value / 1000LL),
88 deadline.value);
89#endif
77 return b * deadline.value / 1000LL; 90 return b * deadline.value / 1000LL;
78} 91}
79 92
@@ -95,8 +108,20 @@ GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps,
95 108
96 b = ntohl (bps.value__); 109 b = ntohl (bps.value__);
97 if (b == 0) 110 if (b == 0)
98 return GNUNET_TIME_UNIT_FOREVER_REL; 111 {
112#if DEBUG_BANDWIDTH
113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
114 "Bandwidth suggests delay of infinity (zero bandwidth)\n");
115#endif
116 return GNUNET_TIME_UNIT_FOREVER_REL;
117 }
99 ret.value = size * 1000LL / b; 118 ret.value = size * 1000LL / b;
119#if DEBUG_BANDWIDTH
120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
121 "Bandwidth suggests delay of %llu ms for %llu bytes of traffic\n",
122 (unsigned long long) ret.value,
123 (unsigned long long) size);
124#endif
100 return ret; 125 return ret;
101} 126}
102 127
@@ -124,6 +149,13 @@ GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av,
124 av->last_update__ = GNUNET_TIME_absolute_get (); 149 av->last_update__ = GNUNET_TIME_absolute_get ();
125 av->available_bytes_per_s__ = ntohl (bytes_per_second_limit.value__); 150 av->available_bytes_per_s__ = ntohl (bytes_per_second_limit.value__);
126 av->max_carry_s__ = max_carry_s; 151 av->max_carry_s__ = max_carry_s;
152#if DEBUG_BANDWIDTH
153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
154 "Tracker %p initialized with %u bps and max carry %u\n",
155 av,
156 (unsigned int) av->available_bytes_per_s__,
157 (unsigned int) max_carry_s);
158#endif
127} 159}
128 160
129 161
@@ -178,6 +210,13 @@ update_tracker (struct GNUNET_BANDWIDTH_Tracker *av)
178 av->consumption_since_last_update__ = 0; 210 av->consumption_since_last_update__ = 0;
179 av->last_update__.value = now.value - left_time_ms; 211 av->last_update__.value = now.value - left_time_ms;
180 } 212 }
213#if DEBUG_BANDWIDTH
214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
215 "Tracker %p updated, have %u bps last update was %llu ms ago\n",
216 av,
217 (unsigned int) av->available_bytes_per_s__,
218 (unsigned long long) (now.value - av->last_update__.value));
219#endif
181} 220}
182 221
183 222
@@ -198,6 +237,12 @@ GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av,
198{ 237{
199 uint64_t nc; 238 uint64_t nc;
200 239
240#if DEBUG_BANDWIDTH
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "Tracker %p consumes %d bytes\n",
243 av,
244 (int) size);
245#endif
201 if (size > 0) 246 if (size > 0)
202 { 247 {
203 nc = av->consumption_since_last_update__ + size; 248 nc = av->consumption_since_last_update__ + size;
@@ -209,7 +254,14 @@ GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av,
209 av->consumption_since_last_update__ = nc; 254 av->consumption_since_last_update__ = nc;
210 update_tracker (av); 255 update_tracker (av);
211 if (av->consumption_since_last_update__ > 0) 256 if (av->consumption_since_last_update__ > 0)
212 return GNUNET_YES; 257 {
258#if DEBUG_BANDWIDTH
259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
260 "Tracker %p consumption is above limit\n",
261 av);
262#endif
263 return GNUNET_YES;
264 }
213 } 265 }
214 else 266 else
215 { 267 {
@@ -240,15 +292,37 @@ GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av,
240 uint64_t bytes_needed; 292 uint64_t bytes_needed;
241 293
242 if (av->available_bytes_per_s__ == 0) 294 if (av->available_bytes_per_s__ == 0)
243 return GNUNET_TIME_UNIT_FOREVER_REL; 295 {
296#if DEBUG_BANDWIDTH
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
298 "Tracker %p delay is infinity\n",
299 av);
300#endif
301 return GNUNET_TIME_UNIT_FOREVER_REL;
302 }
244 update_tracker (av); 303 update_tracker (av);
245 now = GNUNET_TIME_absolute_get (); 304 now = GNUNET_TIME_absolute_get ();
246 delta_time = now.value - av->last_update__.value; 305 delta_time = now.value - av->last_update__.value;
247 delta_avail = (delta_time * ((unsigned long long) av->available_bytes_per_s__)) / 1000LL; 306 delta_avail = (delta_time * ((unsigned long long) av->available_bytes_per_s__)) / 1000LL;
248 if (delta_avail >= size) 307 if (delta_avail >= size)
249 return GNUNET_TIME_UNIT_ZERO; 308 {
309#if DEBUG_BANDWIDTH
310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
311 "Tracker %p delay for %u bytes is zero\n",
312 av,
313 (unsigned int) size);
314#endif
315 return GNUNET_TIME_UNIT_ZERO;
316 }
250 bytes_needed = size - delta_avail; 317 bytes_needed = size - delta_avail;
251 ret.value = 1000LL * bytes_needed / (unsigned long long) av->available_bytes_per_s__; 318 ret.value = 1000LL * bytes_needed / (unsigned long long) av->available_bytes_per_s__;
319#if DEBUG_BANDWIDTH
320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
321 "Tracker %p delay for %u bytes is %llu ms\n",
322 av,
323 (unsigned int) size,
324 (unsigned long long) ret.value);
325#endif
252 return ret; 326 return ret;
253} 327}
254 328
@@ -272,6 +346,12 @@ GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker *av)
272 avail = GNUNET_BANDWIDTH_value_get_available_until (bps, 346 avail = GNUNET_BANDWIDTH_value_get_available_until (bps,
273 GNUNET_TIME_absolute_get_duration (av->last_update__)); 347 GNUNET_TIME_absolute_get_duration (av->last_update__));
274 used = av->consumption_since_last_update__; 348 used = av->consumption_since_last_update__;
349#if DEBUG_BANDWIDTH
350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
351 "Tracker %p available bandwith is %lld ms\n",
352 av,
353 (long long) (int64_t) (avail - used));
354#endif
275 return (int64_t) (avail - used); 355 return (int64_t) (avail - used);
276} 356}
277 357
@@ -290,6 +370,12 @@ GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av,
290 uint32_t new_limit; 370 uint32_t new_limit;
291 371
292 new_limit = ntohl (bytes_per_second_limit.value__); 372 new_limit = ntohl (bytes_per_second_limit.value__);
373#if DEBUG_BANDWIDTH
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "Tracker %p bandwith changed to %u bps\n",
376 av,
377 (unsigned int) new_limit);
378#endif
293 update_tracker (av); 379 update_tracker (av);
294 old_limit = av->available_bytes_per_s__; 380 old_limit = av->available_bytes_per_s__;
295 av->available_bytes_per_s__ = new_limit; 381 av->available_bytes_per_s__ = new_limit;