GNUnet  0.11.x
gnunet_bandwidth_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2010 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
32 #ifndef GNUNET_BANDWIDTH_LIB_H
33 #define GNUNET_BANDWIDTH_LIB_H
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #if 0 /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41 
42 #include "gnunet_common.h"
43 #include "gnunet_time_lib.h"
44 
46 
51 {
56 };
57 
59 
60 
67 typedef void (*GNUNET_BANDWIDTH_TrackerUpdateCallback) (void *cls);
68 
69 
76 typedef void (*GNUNET_BANDWIDTH_ExcessNotificationCallback) (void *cls);
77 
78 
87 {
92 
98 
103 
109 
114 
120 
124  struct GNUNET_TIME_Absolute last_update__;
125 
130 
136  uint32_t max_carry_s__;
137 };
138 
139 
143 #define GNUNET_BANDWIDTH_ZERO GNUNET_BANDWIDTH_value_init (0)
144 
145 
153 GNUNET_BANDWIDTH_value_init (uint32_t bytes_per_second);
154 
155 
159 #define GNUNET_BANDWIDTH_VALUE_MAX GNUNET_BANDWIDTH_value_init (UINT32_MAX)
160 
161 
170 uint64_t
172  struct GNUNET_BANDWIDTH_Value32NBO bps,
174 
175 
186  uint64_t size);
187 
188 
198  struct GNUNET_BANDWIDTH_Value32NBO b2);
199 
200 
210  struct GNUNET_BANDWIDTH_Value32NBO b2);
211 
212 
222  struct GNUNET_BANDWIDTH_Value32NBO b2);
223 
224 
241 void
243  struct GNUNET_BANDWIDTH_Tracker *av,
245  void *update_cb_cls,
246  struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit,
247  uint32_t max_carry_s);
248 
249 
268 void
270  struct GNUNET_BANDWIDTH_Tracker *av,
272  void *update_cb_cls,
273  struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit,
274  uint32_t max_carry_s,
276  void *excess_cb_cls);
277 
278 
284 void
286  struct GNUNET_BANDWIDTH_Tracker *av);
287 
288 
300 int
302  ssize_t size);
303 
304 
316  size_t size);
317 
318 
326 int64_t
328 
329 
336 void
338  struct GNUNET_BANDWIDTH_Tracker *av,
339  struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit);
340 
341 
342 #if 0 /* keep Emacsens' auto-indent happy */
343 {
344 #endif
345 #ifdef __cplusplus
346 }
347 #endif
348 
349 /* ifndef GNUNET_BANDWIDTH_LIB_H */
350 #endif
351  /* end of group */
353 
354 /* end of gnunet_bandwidth_lib.h */
int GNUNET_BANDWIDTH_tracker_consume(struct GNUNET_BANDWIDTH_Tracker *av, ssize_t size)
Notify the tracker that a certain number of bytes of bandwidth have been consumed.
Definition: bandwidth.c:402
void GNUNET_BANDWIDTH_tracker_init(struct GNUNET_BANDWIDTH_Tracker *av, GNUNET_BANDWIDTH_TrackerUpdateCallback update_cb, void *update_cb_cls, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit, uint32_t max_carry_s)
Initialize bandwidth tracker.
Definition: bandwidth.c:302
struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_min(struct GNUNET_BANDWIDTH_Value32NBO b1, struct GNUNET_BANDWIDTH_Value32NBO b2)
Compute the MIN of two bandwidth values.
Definition: bandwidth.c:56
void GNUNET_BANDWIDTH_tracker_update_quota(struct GNUNET_BANDWIDTH_Tracker *av, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit)
Update quota of bandwidth tracker.
Definition: bandwidth.c:526
int64_t GNUNET_BANDWIDTH_tracker_get_available(struct GNUNET_BANDWIDTH_Tracker *av)
Compute how many bytes are available for consumption right now.
Definition: bandwidth.c:498
struct GNUNET_SCHEDULER_Task * excess_task
Task scheduled to call the excess_cb once we have reached the maximum bandwidth the tracker can hold...
struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_max(struct GNUNET_BANDWIDTH_Value32NBO b1, struct GNUNET_BANDWIDTH_Value32NBO b2)
Compute the MAX of two bandwidth values.
Definition: bandwidth.c:72
uint32_t max_carry_s__
Maximum number of seconds over which bandwidth may "accumulate".
Struct to track available bandwidth.
struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_sum(struct GNUNET_BANDWIDTH_Value32NBO b1, struct GNUNET_BANDWIDTH_Value32NBO b2)
Compute the SUM of two bandwidth values.
Definition: bandwidth.c:88
struct GNUNET_TIME_Relative GNUNET_BANDWIDTH_value_get_delay_for(struct GNUNET_BANDWIDTH_Value32NBO bps, uint64_t size)
At the given bandwidth, calculate how long it would take for &#39;size&#39; bytes to be transmitted.
Definition: bandwidth.c:129
GNUNET_BANDWIDTH_ExcessNotificationCallback excess_cb
Function we call if the tracker is about to throw away bandwidth due to excess (max carry exceeded)...
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32.
uint32_t value__
The actual value (bytes per second).
void * update_cb_cls
Closure for update_cb.
void * excess_cb_cls
Closure for excess_cb.
int64_t consumption_since_last_update__
Number of bytes consumed since we last updated the tracker.
void(* GNUNET_BANDWIDTH_TrackerUpdateCallback)(void *cls)
Callback to be called by the bandwidth tracker if the tracker was updated and the client should updat...
void GNUNET_BANDWIDTH_tracker_init2(struct GNUNET_BANDWIDTH_Tracker *av, GNUNET_BANDWIDTH_TrackerUpdateCallback update_cb, void *update_cb_cls, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit, uint32_t max_carry_s, GNUNET_BANDWIDTH_ExcessNotificationCallback excess_cb, void *excess_cb_cls)
Initialize bandwidth tracker.
Definition: bandwidth.c:259
struct GNUNET_TIME_Relative GNUNET_BANDWIDTH_tracker_get_delay(struct GNUNET_BANDWIDTH_Tracker *av, size_t size)
Compute how long we should wait until consuming size bytes of bandwidth in order to stay within the g...
Definition: bandwidth.c:458
GNUNET_BANDWIDTH_TrackerUpdateCallback update_cb
Function we call if the tracker&#39;s bandwidth is increased and a previously returned timeout might now ...
uint64_t GNUNET_BANDWIDTH_value_get_available_until(struct GNUNET_BANDWIDTH_Value32NBO bps, struct GNUNET_TIME_Relative deadline)
At the given bandwidth, calculate how much traffic will be available until the given deadline...
Definition: bandwidth.c:104
static unsigned int size
Size of the "table".
Definition: peer.c:67
void(* GNUNET_BANDWIDTH_ExcessNotificationCallback)(void *cls)
Callback to be called by the bandwidth tracker if the tracker was updated and the client should updat...
struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_init(uint32_t bytes_per_second)
Create a new bandwidth value.
Definition: bandwidth.c:39
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
uint32_t available_bytes_per_s__
Bandwidth limit to enforce in bytes per second.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32;.
#define GNUNET_PACKED
gcc-ism to get packed structs.
void GNUNET_BANDWIDTH_tracker_notification_stop(struct GNUNET_BANDWIDTH_Tracker *av)
Stop notifying about tracker updates and excess notifications.
Definition: bandwidth.c:325
Entry in list of pending tasks.
Definition: scheduler.c:134
static struct GNUNET_TIME_Absolute deadline
Deadline for all consensuses.
Time for absolute times used by GNUnet, in microseconds.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
Time for relative time used by GNUnet, in microseconds.