lib/connections, lib/config: Bandwidth throttling per remote device (fixes #4516) (#4603)

This commit is contained in:
qepasa
2018-03-26 12:01:59 +02:00
committed by Jakob Borg
parent 3c920c61e9
commit 2621c6fd2f
6 changed files with 360 additions and 39 deletions

View File

@@ -2625,8 +2625,8 @@ func (m *Model) CommitConfiguration(from, to config.Configuration) bool {
// clean residue device state that is not part of any folder.
// Pausing a device, unpausing is handled by the connection service.
fromDevices := mapDeviceConfigs(from.Devices)
toDevices := mapDeviceConfigs(to.Devices)
fromDevices := from.DeviceMap()
toDevices := to.DeviceMap()
for deviceID, toCfg := range toDevices {
fromCfg, ok := fromDevices[deviceID]
if !ok || fromCfg.Paused == toCfg.Paused {
@@ -2715,16 +2715,6 @@ func mapDevices(devices []protocol.DeviceID) map[protocol.DeviceID]struct{} {
return m
}
// mapDeviceConfigs returns a map of device ID to device configuration for the given
// slice of folder configurations.
func mapDeviceConfigs(devices []config.DeviceConfiguration) map[protocol.DeviceID]config.DeviceConfiguration {
m := make(map[protocol.DeviceID]config.DeviceConfiguration, len(devices))
for _, dev := range devices {
m[dev.DeviceID] = dev
}
return m
}
// Skips `skip` elements and retrieves up to `get` elements from a given slice.
// Returns the resulting slice, plus how much elements are left to skip or
// copy to satisfy the values which were provided, given the slice is not