GNUnet  0.19.5
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 
21 #if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22 #error "Only <gnunet_util_lib.h> can be included directly."
23 #endif
24 
40 #if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
41 #error "Only <gnunet_util_lib.h> can be included directly."
42 #endif
43 
44 #ifndef GNUNET_BANDWIDTH_LIB_H
45 #define GNUNET_BANDWIDTH_LIB_H
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #if 0 /* keep Emacsens' auto-indent happy */
50 }
51 #endif
52 #endif
53 
54 
55 #include "gnunet_time_lib.h"
56 
58 
63 {
68 };
69 
71 
72 
79 typedef void (*GNUNET_BANDWIDTH_TrackerUpdateCallback) (void *cls);
80 
81 
88 typedef void (*GNUNET_BANDWIDTH_ExcessNotificationCallback) (void *cls);
89 
90 
99 {
104 
110 
115 
121 
126 
132 
137 
142 
148  uint32_t max_carry_s__;
149 };
150 
151 
155 #define GNUNET_BANDWIDTH_ZERO GNUNET_BANDWIDTH_value_init (0)
156 
157 
165 GNUNET_BANDWIDTH_value_init (uint32_t bytes_per_second);
166 
167 
171 #define GNUNET_BANDWIDTH_VALUE_MAX GNUNET_BANDWIDTH_value_init (UINT32_MAX)
172 
173 
182 uint64_t
184  struct GNUNET_BANDWIDTH_Value32NBO bps,
186 
187 
198  uint64_t size);
199 
200 
210  struct GNUNET_BANDWIDTH_Value32NBO b2);
211 
212 
222  struct GNUNET_BANDWIDTH_Value32NBO b2);
223 
224 
234  struct GNUNET_BANDWIDTH_Value32NBO b2);
235 
236 
253 void
255  struct GNUNET_BANDWIDTH_Tracker *av,
257  void *update_cb_cls,
258  struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit,
259  uint32_t max_carry_s);
260 
261 
280 void
282  struct GNUNET_BANDWIDTH_Tracker *av,
284  void *update_cb_cls,
285  struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit,
286  uint32_t max_carry_s,
288  void *excess_cb_cls);
289 
290 
296 void
298  struct GNUNET_BANDWIDTH_Tracker *av);
299 
300 
312 int
314  ssize_t size);
315 
316 
328  size_t size);
329 
330 
338 int64_t
340 
341 
348 void
350  struct GNUNET_BANDWIDTH_Tracker *av,
351  struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit);
352 
353 
354 #if 0 /* keep Emacsens' auto-indent happy */
355 {
356 #endif
357 #ifdef __cplusplus
358 }
359 #endif
360 
361 /* ifndef GNUNET_BANDWIDTH_LIB_H */
362 #endif
363  /* end of group */
365  /* end of group addition */
367 
368 /* end of gnunet_bandwidth_lib.h */
static struct GNUNET_TIME_Absolute deadline
Deadline for all consensuses.
Functions related to time.
void GNUNET_BANDWIDTH_tracker_notification_stop(struct GNUNET_BANDWIDTH_Tracker *av)
Stop notifying about tracker updates and excess notifications.
Definition: bandwidth.c:302
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:368
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:492
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:97
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:40
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:252
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:73
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 'size' bytes to be transmitted.
Definition: bandwidth.c:122
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:89
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:279
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:57
void(* GNUNET_BANDWIDTH_TrackerUpdateCallback)(void *cls)
Callback to be called by the bandwidth tracker if the tracker was updated and the client should updat...
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:424
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:464
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_PACKED
gcc-ism to get packed structs.
static unsigned int size
Size of the "table".
Definition: peer.c:68
Struct to track available bandwidth.
struct GNUNET_SCHEDULER_Task * excess_task
Task scheduled to call the excess_cb once we have reached the maximum bandwidth the tracker can hold.
int64_t consumption_since_last_update__
Number of bytes consumed since we last updated the tracker.
GNUNET_BANDWIDTH_ExcessNotificationCallback excess_cb
Function we call if the tracker is about to throw away bandwidth due to excess (max carry exceeded).
void * update_cb_cls
Closure for update_cb.
struct GNUNET_TIME_Absolute last_update__
Time when we last updated the tracker.
void * excess_cb_cls
Closure for excess_cb.
GNUNET_BANDWIDTH_TrackerUpdateCallback update_cb
Function we call if the tracker's bandwidth is increased and a previously returned timeout might now ...
uint32_t available_bytes_per_s__
Bandwidth limit to enforce in bytes per second.
uint32_t max_carry_s__
Maximum number of seconds over which bandwidth may "accumulate".
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
uint32_t value__
The actual value (bytes per second).
Entry in list of pending tasks.
Definition: scheduler.c:136
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.