diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-02-09 18:45:18 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-02-09 18:45:18 +0000 |
commit | 9e9b96a4ad14008284c61b475b0ad783469fb74d (patch) | |
tree | 00aa4e0f5f1f9eab8b9b12793ad837de35631904 /src/include/gnunet_bandwidth_lib.h | |
parent | 5caf86f236b1a819abdfdc5c2515bdc087b56a69 (diff) | |
download | gnunet-9e9b96a4ad14008284c61b475b0ad783469fb74d.tar.gz gnunet-9e9b96a4ad14008284c61b475b0ad783469fb74d.zip |
add api to bandwidth tracker to notify clients about excess bandwidth available
Diffstat (limited to 'src/include/gnunet_bandwidth_lib.h')
-rw-r--r-- | src/include/gnunet_bandwidth_lib.h | 70 |
1 files changed, 61 insertions, 9 deletions
diff --git a/src/include/gnunet_bandwidth_lib.h b/src/include/gnunet_bandwidth_lib.h index a97a318c7..2dde8b226 100644 --- a/src/include/gnunet_bandwidth_lib.h +++ b/src/include/gnunet_bandwidth_lib.h | |||
@@ -60,7 +60,17 @@ GNUNET_NETWORK_STRUCT_END | |||
60 | * @param cls a closure to pass | 60 | * @param cls a closure to pass |
61 | */ | 61 | */ |
62 | typedef void | 62 | typedef void |
63 | (*GNUNET_BANDWIDTH_tracker_update_cb) (void *cls); | 63 | (*GNUNET_BANDWIDTH_TrackerUpdateCallback) (void *cls); |
64 | |||
65 | |||
66 | /** | ||
67 | * Callback to be called by the bandwidth tracker if the tracker | ||
68 | * was updated and the client should update it's delay values | ||
69 | * | ||
70 | * @param cls a closure to pass | ||
71 | */ | ||
72 | typedef void | ||
73 | (*GNUNET_BANDWIDTH_ExcessNotificationCallback) (void *cls); | ||
64 | 74 | ||
65 | 75 | ||
66 | /** | 76 | /** |
@@ -81,7 +91,18 @@ struct GNUNET_BANDWIDTH_Tracker | |||
81 | * Function we call if the tracker's bandwidth is increased and a | 91 | * Function we call if the tracker's bandwidth is increased and a |
82 | * previously returned timeout might now expire earlier. | 92 | * previously returned timeout might now expire earlier. |
83 | */ | 93 | */ |
84 | GNUNET_BANDWIDTH_tracker_update_cb update_cb; | 94 | GNUNET_BANDWIDTH_TrackerUpdateCallback update_cb; |
95 | |||
96 | /** | ||
97 | * Closure for @e excess_cb. | ||
98 | */ | ||
99 | void *excess_cb_cls; | ||
100 | |||
101 | /** | ||
102 | * Function we call if the tracker is about to throw | ||
103 | * away bandwidth due to excess (max carry exceeded). | ||
104 | */ | ||
105 | GNUNET_BANDWIDTH_ExcessNotificationCallback excess_cb; | ||
85 | 106 | ||
86 | /** | 107 | /** |
87 | * Number of bytes consumed since we last updated the tracker. | 108 | * Number of bytes consumed since we last updated the tracker. |
@@ -89,6 +110,12 @@ struct GNUNET_BANDWIDTH_Tracker | |||
89 | int64_t consumption_since_last_update__; | 110 | int64_t consumption_since_last_update__; |
90 | 111 | ||
91 | /** | 112 | /** |
113 | * Task scheduled to call the @e excess_cb once we have | ||
114 | * reached the maximum bandwidth the tracker can hold. | ||
115 | */ | ||
116 | GNUNET_SCHEDULER_TaskIdentifier excess_task; | ||
117 | |||
118 | /** | ||
92 | * Time when we last updated the tracker. | 119 | * Time when we last updated the tracker. |
93 | */ | 120 | */ |
94 | struct GNUNET_TIME_Absolute last_update__; | 121 | struct GNUNET_TIME_Absolute last_update__; |
@@ -132,10 +159,8 @@ GNUNET_BANDWIDTH_value_init (uint32_t bytes_per_second); | |||
132 | * @return number of bytes available at bps until deadline | 159 | * @return number of bytes available at bps until deadline |
133 | */ | 160 | */ |
134 | uint64_t | 161 | uint64_t |
135 | GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO | 162 | GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO bps, |
136 | bps, | 163 | struct GNUNET_TIME_Relative deadline); |
137 | struct GNUNET_TIME_Relative | ||
138 | deadline); | ||
139 | 164 | ||
140 | 165 | ||
141 | /** | 166 | /** |
@@ -181,14 +206,41 @@ GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1, | |||
181 | */ | 206 | */ |
182 | void | 207 | void |
183 | GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av, | 208 | GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av, |
184 | GNUNET_BANDWIDTH_tracker_update_cb update_cb, | 209 | GNUNET_BANDWIDTH_TrackerUpdateCallback update_cb, |
185 | void *update_cb_cls, | 210 | void *update_cb_cls, |
186 | struct GNUNET_BANDWIDTH_Value32NBO | 211 | struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit, |
187 | bytes_per_second_limit, | ||
188 | uint32_t max_carry_s); | 212 | uint32_t max_carry_s); |
189 | 213 | ||
190 | 214 | ||
191 | /** | 215 | /** |
216 | * Initialize bandwidth tracker. Note that in addition to the | ||
217 | * 'max_carry_s' limit, we also always allow at least | ||
218 | * GNUNET_SERVER_MAX_MESSAGE_SIZE to accumulate. So if the | ||
219 | * bytes-per-second limit is so small that within 'max_carry_s' not | ||
220 | * even GNUNET_SERVER_MAX_MESSAGE_SIZE is allowed to accumulate, it is | ||
221 | * ignored and replaced by GNUNET_SERVER_MAX_MESSAGE_SIZE (which is in | ||
222 | * bytes). | ||
223 | * | ||
224 | * @param av tracker to initialize | ||
225 | * @param update_cb callback to notify a client about the tracker being updated | ||
226 | * @param update_cb_cls cls for the @a update_cb callback | ||
227 | * @param bytes_per_second_limit initial limit to assume | ||
228 | * @param max_carry_s maximum number of seconds unused bandwidth | ||
229 | * may accumulate before it expires | ||
230 | * @param excess_cb callback to notify if we have excess bandwidth | ||
231 | * @param excess_cb_cls closure for @a excess_cb | ||
232 | */ | ||
233 | void | ||
234 | GNUNET_BANDWIDTH_tracker_init2 (struct GNUNET_BANDWIDTH_Tracker *av, | ||
235 | GNUNET_BANDWIDTH_TrackerUpdateCallback update_cb, | ||
236 | void *update_cb_cls, | ||
237 | struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit, | ||
238 | uint32_t max_carry_s, | ||
239 | GNUNET_BANDWIDTH_ExcessNotificationCallback excess_cb, | ||
240 | void *excess_cb_cls); | ||
241 | |||
242 | |||
243 | /** | ||
192 | * Notify the tracker that a certain number of bytes of bandwidth have | 244 | * Notify the tracker that a certain number of bytes of bandwidth have |
193 | * been consumed. Note that it is legal to consume bytes even if not | 245 | * been consumed. Note that it is legal to consume bytes even if not |
194 | * enough bandwidth is available (in that case, | 246 | * enough bandwidth is available (in that case, |