Functions related to bandwidth (unit) More...
Data Structures | |
struct | GNUNET_BANDWIDTH_Value32NBO |
32-bit bandwidth used for network exchange by GNUnet, in bytes per second. More... | |
struct | GNUNET_BANDWIDTH_Tracker |
Struct to track available bandwidth. More... | |
Macros | |
#define | GNUNET_BANDWIDTH_ZERO GNUNET_BANDWIDTH_value_init (0) |
Convenience definition to use for 0-bandwidth. More... | |
#define | GNUNET_BANDWIDTH_VALUE_MAX GNUNET_BANDWIDTH_value_init (UINT32_MAX) |
Maximum possible bandwidth value. More... | |
Typedefs | |
typedef void(* | GNUNET_BANDWIDTH_TrackerUpdateCallback) (void *cls) |
Callback to be called by the bandwidth tracker if the tracker was updated and the client should update it's delay values. More... | |
typedef void(* | GNUNET_BANDWIDTH_ExcessNotificationCallback) (void *cls) |
Callback to be called by the bandwidth tracker if the tracker was updated and the client should update it's delay values. More... | |
Functions | |
struct GNUNET_BANDWIDTH_Value32NBO | GNUNET_BANDWIDTH_value_init (uint32_t bytes_per_second) |
Create a new bandwidth value. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
void | GNUNET_BANDWIDTH_tracker_notification_stop (struct GNUNET_BANDWIDTH_Tracker *av) |
Stop notifying about tracker updates and excess notifications. More... | |
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. More... | |
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 given quota. More... | |
int64_t | GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker *av) |
Compute how many bytes are available for consumption right now. More... | |
void | GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit) |
Update quota of bandwidth tracker. More... | |
Functions related to bandwidth (unit)
#define GNUNET_BANDWIDTH_ZERO GNUNET_BANDWIDTH_value_init (0) |
Convenience definition to use for 0-bandwidth.
Definition at line 151 of file gnunet_bandwidth_lib.h.
#define GNUNET_BANDWIDTH_VALUE_MAX GNUNET_BANDWIDTH_value_init (UINT32_MAX) |
Maximum possible bandwidth value.
Definition at line 167 of file gnunet_bandwidth_lib.h.
typedef void(* GNUNET_BANDWIDTH_TrackerUpdateCallback) (void *cls) |
Callback to be called by the bandwidth tracker if the tracker was updated and the client should update it's delay values.
cls | a closure to pass |
Definition at line 75 of file gnunet_bandwidth_lib.h.
typedef void(* GNUNET_BANDWIDTH_ExcessNotificationCallback) (void *cls) |
Callback to be called by the bandwidth tracker if the tracker was updated and the client should update it's delay values.
cls | a closure to pass |
Definition at line 84 of file gnunet_bandwidth_lib.h.
struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_init | ( | uint32_t | bytes_per_second | ) |
Create a new bandwidth value.
bytes_per_second | value to create |
Definition at line 40 of file bandwidth.c.
References ret.
Referenced by GNUNET_BANDWIDTH_tracker_get_available(), GNUNET_BANDWIDTH_value_max(), GNUNET_BANDWIDTH_value_min(), and GNUNET_BANDWIDTH_value_sum().
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.
bps | bandwidth |
deadline | when is the deadline |
Definition at line 97 of file bandwidth.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_STRINGS_relative_time_to_string(), GNUNET_YES, LOG, GNUNET_TIME_Relative::rel_value_us, and GNUNET_BANDWIDTH_Value32NBO::value__.
Referenced by GNUNET_BANDWIDTH_tracker_get_available().
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.
bps | bandwidth |
size | number of bytes we want to have available |
At the given bandwidth, calculate how long it would take for 'size' bytes to be transmitted.
bps | bandwidth |
size | number of bytes we want to have available |
Definition at line 122 of file bandwidth.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, LOG, ret, and size.
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.
b1 | first value |
b2 | second value |
Definition at line 57 of file bandwidth.c.
References GNUNET_BANDWIDTH_value_init(), and GNUNET_MIN.
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.
b1 | first value |
b2 | second value |
Definition at line 73 of file bandwidth.c.
References GNUNET_BANDWIDTH_value_init(), and GNUNET_MAX.
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.
b1 | first value |
b2 | second value |
Definition at line 89 of file bandwidth.c.
References GNUNET_BANDWIDTH_value_init().
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.
Note that in addition to the 'max_carry_s' limit, we also always allow at least GNUNET_MAX_MESSAGE_SIZE to accumulate. So if the bytes-per-second limit is so small that within 'max_carry_s' not even GNUNET_MAX_MESSAGE_SIZE is allowed to accumulate, it is ignored and replaced by GNUNET_MAX_MESSAGE_SIZE (which is in bytes).
av | tracker to initialize |
update_cb | callback to notify a client about the tracker being updated |
update_cb_cls | cls for the update_cb callback |
bytes_per_second_limit | initial limit to assume |
max_carry_s | maximum number of seconds unused bandwidth may accumulate before it expires |
Definition at line 279 of file bandwidth.c.
References GNUNET_BANDWIDTH_tracker_init2().
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.
Note that in addition to the 'max_carry_s' limit, we also always allow at least GNUNET_MAX_MESSAGE_SIZE to accumulate. So if the bytes-per-second limit is so small that within 'max_carry_s' not even GNUNET_MAX_MESSAGE_SIZE is allowed to accumulate, it is ignored and replaced by GNUNET_MAX_MESSAGE_SIZE (which is in bytes).
av | tracker to initialize |
update_cb | callback to notify a client about the tracker being updated |
update_cb_cls | cls for the update_cb callback |
bytes_per_second_limit | initial limit to assume |
max_carry_s | maximum number of seconds unused bandwidth may accumulate before it expires |
excess_cb | callback to notify if we have excess bandwidth |
excess_cb_cls | closure for excess_cb |
Note that in addition to the 'max_carry_s' limit, we also always allow at least GNUNET_MAX_MESSAGE_SIZE to accumulate. So if the bytes-per-second limit is so small that within 'max_carry_s' not even GNUNET_MAX_MESSAGE_SIZE is allowed to accumulate, it is ignored and replaced by GNUNET_MAX_MESSAGE_SIZE (which is in bytes).
To stop notifications about updates and excess callbacks use GNUNET_BANDWIDTH_tracker_notification_stop().
av | tracker to initialize |
update_cb | callback to notify a client about the tracker being updated |
update_cb_cls | cls for the callback |
bytes_per_second_limit | initial limit to assume |
max_carry_s | maximum number of seconds unused bandwidth may accumulate before it expires |
excess_cb | callback to notify if we have excess bandwidth |
excess_cb_cls | closure for excess_cb |
Definition at line 252 of file bandwidth.c.
References GNUNET_BANDWIDTH_Tracker::available_bytes_per_s__, GNUNET_BANDWIDTH_Tracker::consumption_since_last_update__, GNUNET_BANDWIDTH_Tracker::excess_cb, GNUNET_BANDWIDTH_Tracker::excess_cb_cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_TIME_absolute_get(), GNUNET_BANDWIDTH_Tracker::last_update__, LOG, GNUNET_BANDWIDTH_Tracker::max_carry_s__, GNUNET_BANDWIDTH_Tracker::update_cb, GNUNET_BANDWIDTH_Tracker::update_cb_cls, update_excess(), and GNUNET_BANDWIDTH_Value32NBO::value__.
Referenced by GNUNET_BANDWIDTH_tracker_init().
void GNUNET_BANDWIDTH_tracker_notification_stop | ( | struct GNUNET_BANDWIDTH_Tracker * | av | ) |
Stop notifying about tracker updates and excess notifications.
av | the respective trackers |
Definition at line 302 of file bandwidth.c.
References GNUNET_BANDWIDTH_Tracker::excess_cb, GNUNET_BANDWIDTH_Tracker::excess_cb_cls, GNUNET_BANDWIDTH_Tracker::excess_task, GNUNET_SCHEDULER_cancel(), GNUNET_BANDWIDTH_Tracker::update_cb, and GNUNET_BANDWIDTH_Tracker::update_cb_cls.
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.
Note that it is legal to consume bytes even if not enough bandwidth is available (in that case, GNUNET_BANDWIDTH_tracker_get_delay() may return non-zero delay values even for a size of zero for a while).
av | tracker to update |
size | number of bytes consumed |
Definition at line 368 of file bandwidth.c.
References GNUNET_BANDWIDTH_Tracker::consumption_since_last_update__, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, LOG, nc, size, update_excess(), and update_tracker().
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 given quota.
av | tracker to query |
size | number of bytes we would like to consume |
Compute how long we should wait until consuming size bytes of bandwidth in order to stay within the given quota.
av | tracker to query |
size | number of bytes we would like to consume |
Definition at line 424 of file bandwidth.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_ZERO, GNUNET_YES, LOG, ret, size, and update_tracker().
int64_t GNUNET_BANDWIDTH_tracker_get_available | ( | struct GNUNET_BANDWIDTH_Tracker * | av | ) |
Compute how many bytes are available for consumption right now.
quota.
av | tracker to query |
Definition at line 464 of file bandwidth.c.
References GNUNET_BANDWIDTH_Tracker::available_bytes_per_s__, GNUNET_BANDWIDTH_Tracker::consumption_since_last_update__, GNUNET_BANDWIDTH_value_get_available_until(), GNUNET_BANDWIDTH_value_init(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_TIME_absolute_get_duration(), GNUNET_BANDWIDTH_Tracker::last_update__, LOG, and update_tracker().
void GNUNET_BANDWIDTH_tracker_update_quota | ( | struct GNUNET_BANDWIDTH_Tracker * | av, |
struct GNUNET_BANDWIDTH_Value32NBO | bytes_per_second_limit | ||
) |
Update quota of bandwidth tracker.
av | tracker to initialize |
bytes_per_second_limit | new limit to assume |
Definition at line 492 of file bandwidth.c.
References GNUNET_BANDWIDTH_Tracker::available_bytes_per_s__, GNUNET_ERROR_TYPE_DEBUG, LOG, GNUNET_BANDWIDTH_Tracker::update_cb, GNUNET_BANDWIDTH_Tracker::update_cb_cls, update_excess(), update_tracker(), and GNUNET_BANDWIDTH_Value32NBO::value__.