GNUnet  0.10.x
Data Structures | Macros | Typedefs | Functions
Bandwidth library

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...
 

Detailed Description

Functions related to bandwidth (unit)

Macro Definition Documentation

◆ GNUNET_BANDWIDTH_ZERO

#define GNUNET_BANDWIDTH_ZERO   GNUNET_BANDWIDTH_value_init (0)

Convenience definition to use for 0-bandwidth.

Definition at line 143 of file gnunet_bandwidth_lib.h.

Referenced by bandwidth_changed_cb(), force_reconnect(), free_address(), GAS_addresses_get_peer_info(), and GAS_handle_request_address_list().

◆ GNUNET_BANDWIDTH_VALUE_MAX

#define GNUNET_BANDWIDTH_VALUE_MAX   GNUNET_BANDWIDTH_value_init (UINT32_MAX)

Maximum possible bandwidth value.

Definition at line 159 of file gnunet_bandwidth_lib.h.

Typedef Documentation

◆ GNUNET_BANDWIDTH_TrackerUpdateCallback

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.

Parameters
clsa closure to pass

Definition at line 67 of file gnunet_bandwidth_lib.h.

◆ GNUNET_BANDWIDTH_ExcessNotificationCallback

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.

Parameters
clsa closure to pass

Definition at line 76 of file gnunet_bandwidth_lib.h.

Function Documentation

◆ GNUNET_BANDWIDTH_value_init()

struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_init ( uint32_t  bytes_per_second)

Create a new bandwidth value.

Parameters
bytes_per_secondvalue to create
Returns
the new bandwidth value

Definition at line 39 of file bandwidth.c.

References ret, and GNUNET_BANDWIDTH_Value32NBO::value__.

Referenced by bandwidth_changed_cb(), free_address(), GAS_addresses_add(), GAS_addresses_update(), GNUNET_BANDWIDTH_tracker_get_available(), GNUNET_BANDWIDTH_value_max(), GNUNET_BANDWIDTH_value_min(), GNUNET_BANDWIDTH_value_sum(), GST_neighbours_handle_quota_message(), LIBGNUNET_PLUGIN_TRANSPORT_INIT(), libgnunet_plugin_transport_udp_init(), peerinfo_it(), and unset_primary_address().

40 {
42 
43  ret.value__ = htonl (bytes_per_second);
44  return ret;
45 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
Here is the caller graph for this function:

◆ GNUNET_BANDWIDTH_value_get_available_until()

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.

Parameters
bpsbandwidth
deadlinewhen is the deadline
Returns
number of bytes available at bps until deadline

Definition at line 104 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().

107 {
108  uint64_t b;
109 
110  b = ntohl (bps.value__);
112  "Bandwidth has %llu bytes available until deadline in %s\n",
113  (unsigned long long) ((b * deadline.rel_value_us + 500000LL) /
114  1000000LL),
116  return (b * deadline.rel_value_us + 500000LL) / 1000000LL;
117 }
uint64_t rel_value_us
The actual value.
uint32_t value__
The actual value (bytes per second).
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:727
#define LOG(kind,...)
Definition: bandwidth.c:30
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BANDWIDTH_value_get_delay_for()

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.

Parameters
bpsbandwidth
sizenumber of bytes we want to have available
Returns
how long it would take

At the given bandwidth, calculate how long it would take for 'size' bytes to be transmitted.

Parameters
bpsbandwidth
sizenumber of bytes we want to have available
Returns
how long it would take

Definition at line 129 of file bandwidth.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, LOG, GNUNET_TIME_Relative::rel_value_us, ret, and size.

131 {
132  uint64_t b;
133  struct GNUNET_TIME_Relative ret;
134 
135  b = ntohl (bps.value__);
136  if (0 == b)
137  {
139  "Bandwidth suggests delay of infinity (zero bandwidth)\n");
141  }
142  ret.rel_value_us = size * 1000LL * 1000LL / b;
144  "Bandwidth suggests delay of %s for %llu bytes of traffic\n",
146  (unsigned long long) size);
147  return ret;
148 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint32_t value__
The actual value (bytes per second).
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:727
#define LOG(kind,...)
Definition: bandwidth.c:30
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define GNUNET_YES
Definition: gnunet_common.h:80
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:

◆ GNUNET_BANDWIDTH_value_min()

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.

Parameters
b1first value
b2second value
Returns
the min of b1 and b2

Definition at line 56 of file bandwidth.c.

References GNUNET_BANDWIDTH_value_init(), and GNUNET_MIN.

Referenced by neighbours_connect_notification(), and send_outbound_quota_to_clients().

58 {
60  GNUNET_MIN (ntohl (b1.value__), ntohl (b2.value__)));
61 }
uint32_t value__
The actual value (bytes per second).
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:83
struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_init(uint32_t bytes_per_second)
Create a new bandwidth value.
Definition: bandwidth.c:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BANDWIDTH_value_max()

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.

Parameters
b1first value
b2second value
Returns
the min of b1 and b2

Definition at line 72 of file bandwidth.c.

References GNUNET_BANDWIDTH_value_init(), and GNUNET_MAX.

Referenced by GST_neighbours_handle_quota_message().

74 {
76  GNUNET_MAX (ntohl (b1.value__), ntohl (b2.value__)));
77 }
uint32_t value__
The actual value (bytes per second).
#define GNUNET_MAX(a, b)
Definition: gnunet_common.h:85
struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_init(uint32_t bytes_per_second)
Create a new bandwidth value.
Definition: bandwidth.c:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BANDWIDTH_value_sum()

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.

Parameters
b1first value
b2second value
Returns
the sum of b1 and b2

Definition at line 88 of file bandwidth.c.

References GNUNET_BANDWIDTH_value_init().

90 {
91  return GNUNET_BANDWIDTH_value_init (ntohl (b1.value__) + ntohl (b2.value__));
92 }
uint32_t value__
The actual value (bytes per second).
struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_init(uint32_t bytes_per_second)
Create a new bandwidth value.
Definition: bandwidth.c:39
Here is the call graph for this function:

◆ GNUNET_BANDWIDTH_tracker_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).

Parameters
avtracker to initialize
update_cbcallback to notify a client about the tracker being updated
update_cb_clscls for the update_cb callback
bytes_per_second_limitinitial limit to assume
max_carry_smaximum number of seconds unused bandwidth may accumulate before it expires

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).

Parameters
avtracker to initialize
update_cbcallback to notify a client about the tracker being updated
update_cb_clscls for the callback
bytes_per_second_limitinitial limit to assume
max_carry_smaximum number of seconds unused bandwidth may accumulate before it expires

Definition at line 302 of file bandwidth.c.

References GNUNET_BANDWIDTH_tracker_init2().

Referenced by GAS_reservations_set_bandwidth(), LIBGNUNET_PLUGIN_TRANSPORT_INIT(), libgnunet_plugin_transport_udp_init(), and setup_neighbour().

308 {
310  update_cb,
311  update_cb_cls,
312  bytes_per_second_limit,
313  max_carry_s,
314  NULL,
315  NULL);
316 }
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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).

Parameters
avtracker to initialize
update_cbcallback to notify a client about the tracker being updated
update_cb_clscls for the update_cb callback
bytes_per_second_limitinitial limit to assume
max_carry_smaximum number of seconds unused bandwidth may accumulate before it expires
excess_cbcallback to notify if we have excess bandwidth
excess_cb_clsclosure 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().

Parameters
avtracker to initialize
update_cbcallback to notify a client about the tracker being updated
update_cb_clscls for the callback
bytes_per_second_limitinitial limit to assume
max_carry_smaximum number of seconds unused bandwidth may accumulate before it expires
excess_cbcallback to notify if we have excess bandwidth
excess_cb_clsclosure for excess_cb

Definition at line 259 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(), and handle_connect().

267 {
268  av->update_cb = update_cb;
269  av->update_cb_cls = update_cb_cls;
272  av->available_bytes_per_s__ = ntohl (bytes_per_second_limit.value__);
273  av->max_carry_s__ = max_carry_s;
274  av->excess_cb = excess_cb;
275  av->excess_cb_cls = excess_cb_cls;
277  "Tracker %p initialized with %u Bps and max carry %u\n",
278  av,
279  (unsigned int) av->available_bytes_per_s__,
280  (unsigned int) max_carry_s);
281  update_excess (av);
282 }
uint32_t max_carry_s__
Maximum number of seconds over which bandwidth may "accumulate".
GNUNET_BANDWIDTH_ExcessNotificationCallback excess_cb
Function we call if the tracker is about to throw away bandwidth due to excess (max carry exceeded)...
uint32_t value__
The actual value (bytes per second).
struct GNUNET_TIME_Absolute last_update__
Time when we last updated the tracker.
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.
#define LOG(kind,...)
Definition: bandwidth.c:30
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
GNUNET_BANDWIDTH_TrackerUpdateCallback update_cb
Function we call if the tracker's bandwidth is increased and a previously returned timeout might now ...
static void update_excess(struct GNUNET_BANDWIDTH_Tracker *av)
Recalculate when we might need to call the excess callback.
Definition: bandwidth.c:175
uint32_t available_bytes_per_s__
Bandwidth limit to enforce in bytes per second.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BANDWIDTH_tracker_notification_stop()

void GNUNET_BANDWIDTH_tracker_notification_stop ( struct GNUNET_BANDWIDTH_Tracker av)

Stop notifying about tracker updates and excess notifications.

Parameters
avthe respective trackers

Definition at line 325 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.

Referenced by neighbour_delete().

326 {
327  if (NULL != av->excess_task)
329  av->excess_task = NULL;
330  av->excess_cb = NULL;
331  av->excess_cb_cls = NULL;
332  av->update_cb = NULL;
333  av->update_cb_cls = NULL;
334 }
struct GNUNET_SCHEDULER_Task * excess_task
Task scheduled to call the excess_cb once we have reached the maximum bandwidth the tracker can hold...
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.
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 ...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BANDWIDTH_tracker_consume()

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).

Parameters
avtracker to update
sizenumber of bytes consumed
Returns
GNUNET_YES if this consumption is above the limit

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).

Parameters
avtracker to update
sizenumber of bytes consumed
Returns
GNUNET_YES if this consumption is above the limit

Definition at line 402 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().

Referenced by GST_neighbours_calculate_receive_delay(), notify_send_done(), reservations_reserve(), and transmit_next().

404 {
405  int64_t nc;
406 
408  "Tracker %p consumes %d bytes\n",
409  av,
410  (int) size);
411  if (size > 0)
412  {
414  if (nc < av->consumption_since_last_update__)
415  {
416  /* integer overflow, very bad */
417  GNUNET_break (0);
418  return GNUNET_SYSERR;
419  }
421  update_tracker (av);
422  update_excess (av);
424  {
426  "Tracker %p consumption %llu bytes above limit\n",
427  av,
428  (unsigned long long) av->consumption_since_last_update__);
429  return GNUNET_YES;
430  }
431  }
432  else
433  {
435  if (nc > av->consumption_since_last_update__)
436  {
437  /* integer underflow, very bad */
438  GNUNET_break (0);
439  return GNUNET_SYSERR;
440  }
442  update_excess (av);
443  }
444  return GNUNET_NO;
445 }
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
int64_t consumption_since_last_update__
Number of bytes consumed since we last updated the tracker.
#define LOG(kind,...)
Definition: bandwidth.c:30
static void update_tracker(struct GNUNET_BANDWIDTH_Tracker *av)
Update the tracker, looking at the current time and bandwidth consumption data.
Definition: bandwidth.c:344
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
static unsigned int size
Size of the "table".
Definition: peer.c:67
static void update_excess(struct GNUNET_BANDWIDTH_Tracker *av)
Recalculate when we might need to call the excess callback.
Definition: bandwidth.c:175
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BANDWIDTH_tracker_get_delay()

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.

Parameters
avtracker to query
sizenumber of bytes we would like to consume
Returns
time to wait for consumption to be OK

Compute how long we should wait until consuming size bytes of bandwidth in order to stay within the given quota.

Parameters
avtracker to query
sizenumber of bytes we would like to consume
Returns
time in ms to wait for consumption to be OK

Definition at line 458 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, GNUNET_TIME_Relative::rel_value_us, ret, size, and update_tracker().

Referenced by GST_neighbours_calculate_receive_delay(), notify_send_done(), outbound_bw_tracker_update(), reservations_reserve(), and transmit_next().

460 {
461  struct GNUNET_TIME_Relative ret;
462  int64_t bytes_needed;
463 
464  if (0 == av->available_bytes_per_s__)
465  {
466  LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay is infinity\n", av);
468  }
469  update_tracker (av);
470  bytes_needed = size + av->consumption_since_last_update__;
471  if (bytes_needed <= 0)
472  {
474  "Tracker %p delay for %u bytes is zero\n",
475  av,
476  (unsigned int) size);
477  return GNUNET_TIME_UNIT_ZERO;
478  }
479  ret.rel_value_us = (1000LL * 1000LL * bytes_needed) /
480  (unsigned long long) av->available_bytes_per_s__;
482  "Tracker %p delay for %u bytes is %s\n",
483  av,
484  (unsigned int) size,
486  return ret;
487 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
int64_t consumption_since_last_update__
Number of bytes consumed since we last updated the tracker.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:727
#define LOG(kind,...)
Definition: bandwidth.c:30
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void update_tracker(struct GNUNET_BANDWIDTH_Tracker *av)
Update the tracker, looking at the current time and bandwidth consumption data.
Definition: bandwidth.c:344
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
uint32_t available_bytes_per_s__
Bandwidth limit to enforce in bytes per second.
#define GNUNET_YES
Definition: gnunet_common.h:80
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BANDWIDTH_tracker_get_available()

int64_t GNUNET_BANDWIDTH_tracker_get_available ( struct GNUNET_BANDWIDTH_Tracker av)

Compute how many bytes are available for consumption right now.

quota.

Parameters
avtracker to query
Returns
number of bytes available for consumption right now

Definition at line 498 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().

499 {
500  struct GNUNET_BANDWIDTH_Value32NBO bps;
501  uint64_t avail;
502  int64_t used;
503 
504  update_tracker (av);
506  avail =
509  av->last_update__));
512  "Tracker %p available bandwidth is %lld bytes\n",
513  av,
514  (long long) (int64_t) (avail - used));
515  return (int64_t) (avail - used);
516 }
struct GNUNET_TIME_Absolute last_update__
Time when we last updated the tracker.
int64_t consumption_since_last_update__
Number of bytes consumed since we last updated the tracker.
#define LOG(kind,...)
Definition: bandwidth.c:30
static void update_tracker(struct GNUNET_BANDWIDTH_Tracker *av)
Update the tracker, looking at the current time and bandwidth consumption data.
Definition: bandwidth.c:344
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
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.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:373
Here is the call graph for this function:

◆ GNUNET_BANDWIDTH_tracker_update_quota()

void GNUNET_BANDWIDTH_tracker_update_quota ( struct GNUNET_BANDWIDTH_Tracker av,
struct GNUNET_BANDWIDTH_Value32NBO  bytes_per_second_limit 
)

Update quota of bandwidth tracker.

Parameters
avtracker to initialize
bytes_per_second_limitnew limit to assume

Definition at line 526 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__.

Referenced by GAS_reservations_set_bandwidth(), handle_connect(), handle_set_quota(), and set_incoming_quota().

529 {
530  uint32_t old_limit;
531  uint32_t new_limit;
532 
533  new_limit = ntohl (bytes_per_second_limit.value__);
535  "Tracker %p bandwidth changed to %u Bps\n",
536  av,
537  (unsigned int) new_limit);
538  update_tracker (av);
539  old_limit = av->available_bytes_per_s__;
540  av->available_bytes_per_s__ = new_limit;
541  if (NULL != av->update_cb)
542  av->update_cb (av->update_cb_cls);
543  if (old_limit > new_limit)
544  update_tracker (av); /* maximum excess might be less now */
545  update_excess (av);
546 }
uint32_t value__
The actual value (bytes per second).
void * update_cb_cls
Closure for update_cb.
#define LOG(kind,...)
Definition: bandwidth.c:30
static void update_tracker(struct GNUNET_BANDWIDTH_Tracker *av)
Update the tracker, looking at the current time and bandwidth consumption data.
Definition: bandwidth.c:344
GNUNET_BANDWIDTH_TrackerUpdateCallback update_cb
Function we call if the tracker&#39;s bandwidth is increased and a previously returned timeout might now ...
static void update_excess(struct GNUNET_BANDWIDTH_Tracker *av)
Recalculate when we might need to call the excess callback.
Definition: bandwidth.c:175
uint32_t available_bytes_per_s__
Bandwidth limit to enforce in bytes per second.
Here is the call graph for this function:
Here is the caller graph for this function: