BandwidthManager
Schedules bandwidth fairly across competing consumers. This is a pure-Kotlin port of libtorrent's bandwidth_manager (aux_/bandwidth_manager.hpp, bandwidth_manager.cpp).
There is one manager per direction (channel is upload or download). Consumers call requestBandwidth; if their channels have quota banked the request is granted immediately, otherwise it joins queueSize and is serviced over subsequent updateQuotas rounds. Each round refills every involved BandwidthChannel's token bucket, splits the available quota in proportion to request priorities, and dispatches finished requests through BandwidthSocket.assignBandwidth.
This is the pure scheduling algorithm: the only outside interaction is the BandwidthSocket callback, so it ports without any I/O or timers. The driver decides when to call updateQuotas and with what elapsed time.
Parameters
which direction this manager assigns (upload or download); passed straight back to BandwidthSocket.assignBandwidth.
Functions
Shuts the manager down: clears the queue and immediately dispatches every pending request with whatever it had been BwRequest.assigned so far. Faithful to bandwidth_manager::close.
True if request is currently in the queue. (is_queued)
Total still-unassigned bytes across all queued requests. (queued_bytes)
Runs one scheduling round over an elapsed dtMilliseconds. Faithful to bandwidth_manager::update_quotas (which first converts its time_duration via total_milliseconds):