}
+
/**
* Initialize bandwidth tracker. Note that in addition to the
* 'max_carry_s' limit, we also always allow at least
* bytes).
*
* @param av tracker to initialize
+ * @param update_cb callback to notify a client about the tracker being updated
+ * @param update_cb_cls cls for the callback
* @param bytes_per_second_limit initial limit to assume
* @param max_carry_s maximum number of seconds unused bandwidth
* may accumulate before it expires
*/
void
GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av,
+ GNUNET_BANDWIDTH_tracker_update_cb update_cb,
+ void *update_cb_cls,
struct GNUNET_BANDWIDTH_Value32NBO
bytes_per_second_limit, uint32_t max_carry_s)
{
+ av->update_cb = update_cb;
+ av->update_cb_cls = update_cb_cls;
av->consumption_since_last_update__ = 0;
av->last_update__ = GNUNET_TIME_absolute_get ();
av->available_bytes_per_s__ = ntohl (bytes_per_second_limit.value__);
if (av->available_bytes_per_s__ == 0)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Tracker %p delay is infinity\n", av);
return GNUNET_TIME_UNIT_FOREVER_REL;
}
ret.rel_value_us =
(1000LL * 1000LL * bytes_needed) /
(unsigned long long) av->available_bytes_per_s__;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Tracker %p delay for %u bytes is %s\n",
- av, (unsigned int) size,
+ av, (unsigned int) size,
GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
return ret;
}
uint32_t new_limit;
new_limit = ntohl (bytes_per_second_limit.value__);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Tracker %p bandwidth changed to %u Bps\n", av,
(unsigned int) new_limit);
update_tracker (av);
old_limit = av->available_bytes_per_s__;
av->available_bytes_per_s__ = new_limit;
+ if (NULL != av->update_cb)
+ av->update_cb (av->update_cb_cls);
if (old_limit > new_limit)
update_tracker (av); /* maximum excess might be less now */
}