BwRequest

class BwRequest(val peer: BandwidthSocket, val requestSize: Int, val priority: Int)

One consumer's outstanding bandwidth request: pure-Kotlin port of libtorrent's bw_request (aux_/bandwidth_queue_entry.hpp, bandwidth_queue_entry.cpp).

A request asks for requestSize bytes on behalf of peer, competing at the given priority (1 is normal). It belongs to up to MAX_BANDWIDTH_CHANNELSs, the channels that need to ration it (its own limit, its torrent's, the global one, …). The BandwidthManager accumulates assigned bytes across rounds until it reaches requestSize or ttl runs out, then fires the consumer's assignBandwidth callback.

Constructors

Link copied to clipboard
constructor(peer: BandwidthSocket, requestSize: Int, priority: Int)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Bytes assigned to this request so far. (assigned)

Link copied to clipboard

The channels rationing this request, in order. libtorrent uses a fixed array of 10 slots terminated by a null; a list of at most MAX_BANDWIDTH_CHANNELS is the faithful equivalent.

Link copied to clipboard

The consumer awaiting bandwidth.

Link copied to clipboard

Scheduling priority; 1 is normal, higher gets a larger share. (priority)

Link copied to clipboard

Total bytes requested. (request_size)

Link copied to clipboard
var ttl: Int

Remaining scheduling rounds before the request is force-dispatched even if only partially filled. This guarantees progress at very low rate limits. Starts at 20, matching libtorrent. (ttl)

Functions

Link copied to clipboard

Assigns one round's worth of bandwidth from the most-limiting channel and withdraws it from every channel. Returns the number of bytes assigned this call. Faithful to bw_request::assign_bandwidth: