rem: assert(std::min(upload_limit,sum_quota_limit) - sum_quota < 100);
add: assert(sum_quota == std::min(upload_limit,sum_quota_limit));
context: 	void control_upload_rates(		int upload_limit		, libtorrent::detail::session_impl::connection_map connections)	{		using namespace libtorrent;		if (connections.empty()) return;		assert(upload_limit != 0);		if (upload_limit == -1)		{			for (detail::session_impl::connection_map::iterator i = connections.begin();				i != connections.end();				++i)			{				// there's no limit, set the quota to max				// allowed				peer_connection& p = *i->second;				p.set_send_quota(p.send_quota_limit());			}			return;		}		else		{			// There's an upload limit, so we need to distribute the available			// upload bandwidth among the peer_connections fairly, but not			// wastefully.			// For each peer_connection, keep some local data about their			// quota limit and estimated upload capacity, and how much quota			// has been allocated to them.			std::vector<connection_info> peer_info;			for (detail::session_impl::connection_map::iterator i = connections.begin();				i != connections.end();				++i)			{				peer_connection& p = *i->second;				connection_info pi;				pi.p=&p;				pi.allocated_quota=0; // we haven't given it any bandwith yet				pi.quota_limit=p.send_quota_limit();				pi.estimated_upload_capacity=					p.has_data() ? std::max(10,(int)p.statistics().upload_rate()*11/10)					// If there's no data to send, upload capacity is practically 0.					// Here we set it to 1 though, because otherwise it will not be able					// to accept any quota at all, which may upset quota_limit balances.					              : 1;				peer_info.push_back(pi);			}			// Sum all peer_connections' quota limit to get the total quota limit.			int sum_total_of_quota_limits=0;			for(int i=0;i<peer_info.size();i++)				sum_total_of_quota_limits+=peer_info[i].quota_limit;			// This is how much total bandwidth that can be distributed.			int quota_left_to_distribute=std::min(upload_limit,sum_total_of_quota_limits);			// Sort w.r.t. channel capacitiy, lowest channel capacity first.			// Makes it easy to traverse the list in sorted order.			std::sort(peer_info.begin(),peer_info.end());			// Distribute quota until there's nothing more to distribute			while(quota_left_to_distribute!=0)			{				assert(quota_left_to_distribute>0);				for(int i=0;i<peer_info.size();i++)				{					// Traverse the peer list from slowest connection to fastest.					// In each step, share bandwidth equally between this peer_connection					// and the following faster peer_connections.					//					// Rounds upwards to avoid trying to give 0 bandwidth to someone (may get caught in an endless loop otherwise)										int num_peers_left_to_share_quota=peer_info.size()-i;					int try_to_give_to_this_peer=(quota_left_to_distribute + num_peers_left_to_share_quota-1)/num_peers_left_to_share_quota;					// But do not allocate more than the estimated upload capacity.					try_to_give_to_this_peer=std::min(						peer_info[i].estimated_upload_capacity,						try_to_give_to_this_peer);					// Also, when the peer is given quota, it will not accept more than it's quota_limit.					int quota_actually_given_to_peer=peer_info[i].give(try_to_give_to_this_peer);					quota_left_to_distribute-=quota_actually_given_to_peer;				}			}						// Finally, inform the peers of how much quota they get.			for(int i=0;i<peer_info.size();i++)				peer_info[i].p->set_send_quota(peer_info[i].allocated_quota);		}#ifndef NDEBUG		{		int sum_quota = 0;		int sum_quota_limit = 0;		for (detail::session_impl::connection_map::iterator i = connections.begin();			i != connections.end();			++i)		{			peer_connection& p = *i->second;			sum_quota += p.send_quota();			sum_quota_limit += p.send_quota_limit();		}		assert(std::min(upload_limit,sum_quota_limit) - sum_quota < 100);		}#endif	}