code: func (cm *ClientManager) updateCapFactor(now mclock.AbsTime, refresh bool) {
  	if cm.totalRecharge == 0 {
  		return
  	}
  	dt := now - cm.capLastUpdate
  	cm.capLastUpdate = now
  
  	var d float64
  	if cm.sumRecharge > cm.totalRecharge {
  		d = (1 - float64(cm.sumRecharge)/float64(cm.totalRecharge)) * capFactorDropTC
  	} else {
  		totalConnected := float64(cm.totalConnected)
  		var connRatio float64
  		if totalConnected < cm.totalCapacity {
  			connRatio = totalConnected / cm.totalCapacity
  		} else {
  			connRatio = 1
  		}
  		if connRatio > capFactorRaiseThreshold {
  			sumRecharge := float64(cm.sumRecharge)
  			limit := float64(cm.totalRecharge) * connRatio
  			if sumRecharge < limit {
  				d = (1 - sumRecharge/limit) * (connRatio - capFactorRaiseThreshold) * (1 / (1 - capFactorRaiseThreshold)) * capFactorRaiseTC
  			}
  		}
  	}
  	if d != 0 {
  		cm.capLogFactor += d * float64(dt)
  		if cm.capLogFactor < 0 {
  			cm.capLogFactor = 0
  		}
  		if refresh {
  			cm.refreshCapacity()
  		}
  	}
  }
docs: // updateCapFactor updates the total capacity factor. The capacity factor allows
  // the total capacity of the system to go over the allowed total recharge value
  // if the sum of momentarily recharging clients only exceeds the total recharge
  // allowance in a very small fraction of time.
  // The capacity factor is dropped quickly (with a small time constant) if sumRecharge
  // exceeds totalRecharge. It is raised slowly (with a large time constant) if most
  // of the total capacity is used by connected clients (totalConnected is larger than
  // totalCapacity*capFactorRaiseThreshold) and sumRecharge stays under
  // totalRecharge*totalConnected/totalCapacity.