lib/connections: Slightly refactor limiter juggling

Two small behavior changes: don't "charge" the data to the global rate
limit until it's been accepted by the device specific limiter, and fix
the send/recv direction in the log print on per device rate limits.
This commit is contained in:
Jakob Borg
2018-03-26 06:56:50 -04:00
parent 2621c6fd2f
commit c49d864f14
2 changed files with 74 additions and 54 deletions

View File

@@ -377,6 +377,15 @@ func (cfg *Configuration) clean() error {
return nil
}
// DeviceMap returns a map of device ID to device configuration for the given configuration.
func (cfg *Configuration) DeviceMap() map[protocol.DeviceID]DeviceConfiguration {
m := make(map[protocol.DeviceID]DeviceConfiguration, len(cfg.Devices))
for _, dev := range cfg.Devices {
m[dev.DeviceID] = dev
}
return m
}
func convertV27V28(cfg *Configuration) {
// Show a notification about enabling filesystem watching
cfg.Options.UnackedNotificationIDs = append(cfg.Options.UnackedNotificationIDs, "fsWatcherNotification")
@@ -797,12 +806,3 @@ func filterURLSchemePrefix(addrs []string, prefix string) []string {
}
return addrs
}
// mapDeviceConfigs returns a map of device ID to device configuration for the given configuration.
func (cfg *Configuration) DeviceMap() map[protocol.DeviceID]DeviceConfiguration {
m := make(map[protocol.DeviceID]DeviceConfiguration, len(cfg.Devices))
for _, dev := range cfg.Devices {
m[dev.DeviceID] = dev
}
return m
}