deviceconfiguration.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at http://mozilla.org/MPL/2.0/.
  6. package config
  7. import "github.com/syncthing/syncthing/lib/protocol"
  8. type DeviceConfiguration struct {
  9. DeviceID protocol.DeviceID `xml:"id,attr" json:"deviceID"`
  10. Name string `xml:"name,attr,omitempty" json:"name"`
  11. Addresses []string `xml:"address,omitempty" json:"addresses"`
  12. Compression protocol.Compression `xml:"compression,attr" json:"compression"`
  13. CertName string `xml:"certName,attr,omitempty" json:"certName"`
  14. Introducer bool `xml:"introducer,attr" json:"introducer"`
  15. SkipIntroductionRemovals bool `xml:"skipIntroductionRemovals,attr" json:"skipIntroductionRemovals"`
  16. IntroducedBy protocol.DeviceID `xml:"introducedBy,attr" json:"introducedBy"`
  17. }
  18. func NewDeviceConfiguration(id protocol.DeviceID, name string) DeviceConfiguration {
  19. return DeviceConfiguration{
  20. DeviceID: id,
  21. Name: name,
  22. }
  23. }
  24. func (orig DeviceConfiguration) Copy() DeviceConfiguration {
  25. c := orig
  26. c.Addresses = make([]string, len(orig.Addresses))
  27. copy(c.Addresses, orig.Addresses)
  28. return c
  29. }
  30. type DeviceConfigurationList []DeviceConfiguration
  31. func (l DeviceConfigurationList) Less(a, b int) bool {
  32. return l[a].DeviceID.Compare(l[b].DeviceID) == -1
  33. }
  34. func (l DeviceConfigurationList) Swap(a, b int) {
  35. l[a], l[b] = l[b], l[a]
  36. }
  37. func (l DeviceConfigurationList) Len() int {
  38. return len(l)
  39. }