+/**
+ * At the given bandwidth, calculate how much traffic will be
+ * available until the given deadline.
+ *
+ * @param bps bandwidth
+ * @param deadline when is the deadline
+ * @return number of bytes available at bps until deadline
+ */
+uint64_t
+GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO bps,
+ struct GNUNET_TIME_Relative deadline)
+{
+ uint64_t b;
+
+ b = ntohl (bps.value__);
+#if DEBUG_BANDWIDTH
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Bandwidth has %llu bytes available until deadline in %llums\n",
+ (unsigned long long) ((b * deadline.rel_value + 500LL) / 1000LL),
+ deadline.rel_value);
+#endif
+ return (b * deadline.rel_value + 500LL) / 1000LL;
+}
+
+
+/**
+ * At the given bandwidth, calculate how long it would take for
+ * 'size' bytes to be transmitted.
+ *
+ * @param bps bandwidth
+ * @param size number of bytes we want to have available
+ * @return how long it would take
+ */
+struct GNUNET_TIME_Relative
+GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps,
+ uint64_t size)
+{
+ uint64_t b;
+ struct GNUNET_TIME_Relative ret;
+
+ b = ntohl (bps.value__);
+ if (b == 0)
+ {
+#if DEBUG_BANDWIDTH
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Bandwidth suggests delay of infinity (zero bandwidth)\n");
+#endif
+ return GNUNET_TIME_UNIT_FOREVER_REL;
+ }
+ ret.rel_value = size * 1000LL / b;
+#if DEBUG_BANDWIDTH
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Bandwidth suggests delay of %llu ms for %llu bytes of traffic\n",
+ (unsigned long long) ret.rel_value,
+ (unsigned long long) size);
+#endif
+ return ret;
+}
+
+