2015-10-27 11:37:03 +01:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 07:52:18 +01:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2015-10-27 11:37:03 +01:00
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import "github.com/syncthing/syncthing/lib/protocol"
|
|
|
|
|
|
|
|
type DeviceConfiguration struct {
|
2016-11-07 17:40:48 +01:00
|
|
|
DeviceID protocol.DeviceID `xml:"id,attr" json:"deviceID"`
|
|
|
|
Name string `xml:"name,attr,omitempty" json:"name"`
|
|
|
|
Addresses []string `xml:"address,omitempty" json:"addresses"`
|
|
|
|
Compression protocol.Compression `xml:"compression,attr" json:"compression"`
|
|
|
|
CertName string `xml:"certName,attr,omitempty" json:"certName"`
|
|
|
|
Introducer bool `xml:"introducer,attr" json:"introducer"`
|
|
|
|
SkipIntroductionRemovals bool `xml:"skipIntroductionRemovals,attr" json:"skipIntroductionRemovals"`
|
|
|
|
IntroducedBy protocol.DeviceID `xml:"introducedBy,attr" json:"introducedBy"`
|
2016-12-21 19:41:25 +01:00
|
|
|
Paused bool `xml:"paused" json:"paused"`
|
2017-04-01 11:52:31 +02:00
|
|
|
AllowedNetworks []string `xml:"allowedNetwork,omitempty" json:"allowedNetworks"`
|
2017-12-07 08:08:24 +01:00
|
|
|
AutoAcceptFolders bool `xml:"autoAcceptFolders" json:"autoAcceptFolders"`
|
2018-03-26 12:01:59 +02:00
|
|
|
MaxSendKbps int `xml:"maxSendKbps" json:"maxSendKbps"`
|
|
|
|
MaxRecvKbps int `xml:"maxRecvKbps" json:"maxRecvKbps"`
|
2015-10-27 11:37:03 +01:00
|
|
|
}
|
|
|
|
|
2015-11-07 09:47:31 +01:00
|
|
|
func NewDeviceConfiguration(id protocol.DeviceID, name string) DeviceConfiguration {
|
2017-04-01 11:52:31 +02:00
|
|
|
d := DeviceConfiguration{
|
2015-11-07 09:47:31 +01:00
|
|
|
DeviceID: id,
|
|
|
|
Name: name,
|
|
|
|
}
|
2017-04-01 11:52:31 +02:00
|
|
|
d.prepare()
|
|
|
|
return d
|
2015-11-07 09:47:31 +01:00
|
|
|
}
|
|
|
|
|
2017-04-01 11:52:31 +02:00
|
|
|
func (cfg DeviceConfiguration) Copy() DeviceConfiguration {
|
|
|
|
c := cfg
|
|
|
|
c.Addresses = make([]string, len(cfg.Addresses))
|
|
|
|
copy(c.Addresses, cfg.Addresses)
|
|
|
|
c.AllowedNetworks = make([]string, len(cfg.AllowedNetworks))
|
|
|
|
copy(c.AllowedNetworks, cfg.AllowedNetworks)
|
2015-10-27 11:37:03 +01:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2017-04-01 11:52:31 +02:00
|
|
|
func (cfg *DeviceConfiguration) prepare() {
|
|
|
|
if len(cfg.Addresses) == 0 || len(cfg.Addresses) == 1 && cfg.Addresses[0] == "" {
|
|
|
|
cfg.Addresses = []string{"dynamic"}
|
|
|
|
}
|
|
|
|
if len(cfg.AllowedNetworks) == 0 {
|
|
|
|
cfg.AllowedNetworks = []string{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-27 11:37:03 +01:00
|
|
|
type DeviceConfigurationList []DeviceConfiguration
|
|
|
|
|
|
|
|
func (l DeviceConfigurationList) Less(a, b int) bool {
|
|
|
|
return l[a].DeviceID.Compare(l[b].DeviceID) == -1
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l DeviceConfigurationList) Swap(a, b int) {
|
|
|
|
l[a], l[b] = l[b], l[a]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l DeviceConfigurationList) Len() int {
|
|
|
|
return len(l)
|
|
|
|
}
|