rem: int desired_queue_size = static_cast<int>(queue_time * c.statistics().download_rate() / (16 * 1024));
add: const int block_size = t.block_size(); assert(block_size > 0);  int desired_queue_size = static_cast<int>(queue_time * c.statistics().download_rate() / block_size);
context: 	void request_a_block(		torrent& t		, peer_connection& c		, std::vector<peer_connection*> ignore = std::vector<peer_connection*>())	{		// this will make the number of requests linearly dependent		// on the rate in which we download from the peer.		// we want the queue to represent:		const int queue_time = 5; // seconds		// (if the latency is more than this, the download will stall)		// so, the queue size is 5 * down_rate / 16 kiB (16 kB is the size of each request)		// the minimum request size is 2 and the maximum is 48		int desired_queue_size = static_cast<int>(queue_time * c.statistics().download_rate() / (16 * 1024));		if (desired_queue_size > max_request_queue) desired_queue_size = max_request_queue;		if (desired_queue_size < min_request_queue) desired_queue_size = min_request_queue;		assert(desired_queue_size >= min_request_queue);		int num_requests = desired_queue_size - (int)c.download_queue().size();		// if our request queue is already full, we		// don't have to make any new requests yet		if (num_requests <= 0) return;		piece_picker& p = t.picker();		std::vector<piece_block> interesting_pieces;		interesting_pieces.reserve(100);		// picks the interesting pieces from this peer		// the integer is the number of pieces that		// should be guaranteed to be available for download		// (if num_requests is too big, too many pieces are		// picked and cpu-time is wasted)		p.pick_pieces(c.get_bitfield(), interesting_pieces, num_requests);		// this vector is filled with the interesting pieces		// that some other peer is currently downloading		// we should then compare this peer's download speed		// with the other's, to see if we should abort another		// peer_connection in favour of this one		std::vector<piece_block> busy_pieces;		busy_pieces.reserve(10);		for (std::vector<piece_block>::iterator i = interesting_pieces.begin();			i != interesting_pieces.end(); ++i)		{			if (p.is_downloading(*i))			{				busy_pieces.push_back(*i);				continue;			}			// ok, we found a piece that's not being downloaded			// by somebody else. request it from this peer			// and return			c.send_request(*i);			num_requests--;			if (num_requests <= 0) return;		}		// in this case, we could not find any blocks		// that was free. If we couldn't find any busy		// blocks as well, we cannot download anything		// more from this peer.		if (busy_pieces.empty()) return;		// first look for blocks that are just queued		// and not actually sent to us yet		// (then we can cancel those and request them		// from this peer instead)		while (num_requests > 0)		{			peer_connection* peer = 0;			float min_weight = std::numeric_limits<float>::max();			// find the peer with the lowest download			// speed that also has a piece that this			// peer could send us			for (torrent::peer_iterator i = t.begin();				i != t.end();				++i)			{				// don't try to take over blocks from ourself				if (i->second == &c)					continue;				// ignore all peers in the ignore list				if (std::find(ignore.begin(), ignore.end(), i->second) != ignore.end())					continue;				const std::deque<piece_block>& queue = i->second->download_queue();				const int queue_size = (int)i->second->download_queue().size();				const float weight = queue_size == 0					? std::numeric_limits<float>::max()					: i->second->statistics().download_payload_rate() / queue_size;				if (weight < min_weight					&& std::find_first_of(						busy_pieces.begin()						, busy_pieces.end()						, queue.begin()						, queue.end()) != busy_pieces.end())				{					peer = i->second;					min_weight = weight;				}			}			if (peer == 0)			{				// we probably couldn't request the block because				// we are ignoring some peers				break;			}			// find a suitable block to take over from this peer			std::deque<piece_block>::const_reverse_iterator common_block =				std::find_first_of(					peer->download_queue().rbegin()					, peer->download_queue().rend()					, busy_pieces.begin()					, busy_pieces.end());			assert(common_block != peer->download_queue().rend());			piece_block block = *common_block;			peer->send_cancel(block);			c.send_request(block);			// the one we interrupted may need to request a new piece			// make sure it doesn't take over a block from the peer			// that just took over its block			ignore.push_back(&c);			request_a_block(t, *peer, ignore);			num_requests--;			// this peer doesn't have a faster connection than the			// slowest peer. Don't take over any blocks			const int queue_size = (int)c.download_queue().size();			const float weight = queue_size == 0				? std::numeric_limits<float>::max()				: c.statistics().download_payload_rate() / queue_size;			if (weight <= min_weight) break;		}	}