deviceconfiguration.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. }
  16. func NewDeviceConfiguration(id protocol.DeviceID, name string) DeviceConfiguration {
  17. return DeviceConfiguration{
  18. DeviceID: id,
  19. Name: name,
  20. }
  21. }
  22. func (orig DeviceConfiguration) Copy() DeviceConfiguration {
  23. c := orig
  24. c.Addresses = make([]string, len(orig.Addresses))
  25. copy(c.Addresses, orig.Addresses)
  26. return c
  27. }
  28. type DeviceConfigurationList []DeviceConfiguration
  29. func (l DeviceConfigurationList) Less(a, b int) bool {
  30. return l[a].DeviceID.Compare(l[b].DeviceID) == -1
  31. }
  32. func (l DeviceConfigurationList) Swap(a, b int) {
  33. l[a], l[b] = l[b], l[a]
  34. }
  35. func (l DeviceConfigurationList) Len() int {
  36. return len(l)
  37. }