GNUnet 0.21.1
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
36#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
37#error "Only <gnunet_util_lib.h> can be included directly."
38#endif
39
40#ifndef GNUNET_BANDWIDTH_LIB_H
41#define GNUNET_BANDWIDTH_LIB_H
42
43#ifdef __cplusplus
44extern "C" {
45#if 0 /* keep Emacsens' auto-indent happy */
46}
47#endif
48#endif
49
50
51#include "gnunet_time_lib.h"
52
54
59{
64};
65
67
68
75typedef void (*GNUNET_BANDWIDTH_TrackerUpdateCallback) (void *cls);
76
77
85
86
95{
100
106
111
117
122
128
133
138
145};
146
147
151#define GNUNET_BANDWIDTH_ZERO GNUNET_BANDWIDTH_value_init (0)
152
153
161GNUNET_BANDWIDTH_value_init (uint32_t bytes_per_second);
162
163
167#define GNUNET_BANDWIDTH_VALUE_MAX GNUNET_BANDWIDTH_value_init (UINT32_MAX)
168
169
178uint64_t
181 struct GNUNET_TIME_Relative deadline);
182
183
194 uint64_t size);
195
196
207
208
219
220
231
232
249void
251 struct GNUNET_BANDWIDTH_Tracker *av,
253 void *update_cb_cls,
254 struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit,
255 uint32_t max_carry_s);
256
257
276void
278 struct GNUNET_BANDWIDTH_Tracker *av,
280 void *update_cb_cls,
281 struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit,
282 uint32_t max_carry_s,
284 void *excess_cb_cls);
285
286
292void
294 struct GNUNET_BANDWIDTH_Tracker *av);
295
296
308int
310 ssize_t size);
311
312
324 size_t size);
325
326
334int64_t
336
337
344void
346 struct GNUNET_BANDWIDTH_Tracker *av,
347 struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit);
348
349
350#if 0 /* keep Emacsens' auto-indent happy */
351{
352#endif
353#ifdef __cplusplus
354}
355#endif
356
357/* ifndef GNUNET_BANDWIDTH_LIB_H */
358#endif
359 /* end of group */
361 /* end of group addition */
363
364/* end of gnunet_bandwidth_lib.h */
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.