optionsconfiguration.go 6.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 https://mozilla.org/MPL/2.0/.
  6. package config
  7. import (
  8. "fmt"
  9. "github.com/syncthing/syncthing/lib/util"
  10. )
  11. type OptionsConfiguration struct {
  12. ListenAddresses []string `xml:"listenAddress" json:"listenAddresses" default:"default"`
  13. GlobalAnnServers []string `xml:"globalAnnounceServer" json:"globalAnnounceServers" default:"default" restart:"true"`
  14. GlobalAnnEnabled bool `xml:"globalAnnounceEnabled" json:"globalAnnounceEnabled" default:"true" restart:"true"`
  15. LocalAnnEnabled bool `xml:"localAnnounceEnabled" json:"localAnnounceEnabled" default:"true" restart:"true"`
  16. LocalAnnPort int `xml:"localAnnouncePort" json:"localAnnouncePort" default:"21027" restart:"true"`
  17. LocalAnnMCAddr string `xml:"localAnnounceMCAddr" json:"localAnnounceMCAddr" default:"[ff12::8384]:21027" restart:"true"`
  18. MaxSendKbps int `xml:"maxSendKbps" json:"maxSendKbps"`
  19. MaxRecvKbps int `xml:"maxRecvKbps" json:"maxRecvKbps"`
  20. ReconnectIntervalS int `xml:"reconnectionIntervalS" json:"reconnectionIntervalS" default:"60"`
  21. RelaysEnabled bool `xml:"relaysEnabled" json:"relaysEnabled" default:"true"`
  22. RelayReconnectIntervalM int `xml:"relayReconnectIntervalM" json:"relayReconnectIntervalM" default:"10"`
  23. StartBrowser bool `xml:"startBrowser" json:"startBrowser" default:"true"`
  24. NATEnabled bool `xml:"natEnabled" json:"natEnabled" default:"true"`
  25. NATLeaseM int `xml:"natLeaseMinutes" json:"natLeaseMinutes" default:"60"`
  26. NATRenewalM int `xml:"natRenewalMinutes" json:"natRenewalMinutes" default:"30"`
  27. NATTimeoutS int `xml:"natTimeoutSeconds" json:"natTimeoutSeconds" default:"10"`
  28. URAccepted int `xml:"urAccepted" json:"urAccepted"` // Accepted usage reporting version; 0 for off (undecided), -1 for off (permanently)
  29. URSeen int `xml:"urSeen" json:"urSeen"` // Report which the user has been prompted for.
  30. URUniqueID string `xml:"urUniqueID" json:"urUniqueId"` // Unique ID for reporting purposes, regenerated when UR is turned on.
  31. URURL string `xml:"urURL" json:"urURL" default:"https://data.syncthing.net/newdata"`
  32. URPostInsecurely bool `xml:"urPostInsecurely" json:"urPostInsecurely" default:"false"` // For testing
  33. URInitialDelayS int `xml:"urInitialDelayS" json:"urInitialDelayS" default:"1800"`
  34. RestartOnWakeup bool `xml:"restartOnWakeup" json:"restartOnWakeup" default:"true" restart:"true"`
  35. AutoUpgradeIntervalH int `xml:"autoUpgradeIntervalH" json:"autoUpgradeIntervalH" default:"12" restart:"true"` // 0 for off
  36. UpgradeToPreReleases bool `xml:"upgradeToPreReleases" json:"upgradeToPreReleases" restart:"true"` // when auto upgrades are enabled
  37. KeepTemporariesH int `xml:"keepTemporariesH" json:"keepTemporariesH" default:"24"` // 0 for off
  38. CacheIgnoredFiles bool `xml:"cacheIgnoredFiles" json:"cacheIgnoredFiles" default:"false" restart:"true"`
  39. ProgressUpdateIntervalS int `xml:"progressUpdateIntervalS" json:"progressUpdateIntervalS" default:"5"`
  40. LimitBandwidthInLan bool `xml:"limitBandwidthInLan" json:"limitBandwidthInLan" default:"false"`
  41. MinHomeDiskFree Size `xml:"minHomeDiskFree" json:"minHomeDiskFree" default:"1 %"`
  42. ReleasesURL string `xml:"releasesURL" json:"releasesURL" default:"https://upgrades.syncthing.net/meta.json" restart:"true"`
  43. AlwaysLocalNets []string `xml:"alwaysLocalNet" json:"alwaysLocalNets"`
  44. OverwriteRemoteDevNames bool `xml:"overwriteRemoteDeviceNamesOnConnect" json:"overwriteRemoteDeviceNamesOnConnect" default:"false"`
  45. TempIndexMinBlocks int `xml:"tempIndexMinBlocks" json:"tempIndexMinBlocks" default:"10"`
  46. UnackedNotificationIDs []string `xml:"unackedNotificationID" json:"unackedNotificationIDs"`
  47. TrafficClass int `xml:"trafficClass" json:"trafficClass"`
  48. DefaultFolderPath string `xml:"defaultFolderPath" json:"defaultFolderPath" default:"~"`
  49. SetLowPriority bool `xml:"setLowPriority" json:"setLowPriority" default:"true"`
  50. MaxConcurrentScans int `xml:"maxConcurrentScans" json:"maxConcurrentScans"`
  51. DeprecatedUPnPEnabled bool `xml:"upnpEnabled,omitempty" json:"-"`
  52. DeprecatedUPnPLeaseM int `xml:"upnpLeaseMinutes,omitempty" json:"-"`
  53. DeprecatedUPnPRenewalM int `xml:"upnpRenewalMinutes,omitempty" json:"-"`
  54. DeprecatedUPnPTimeoutS int `xml:"upnpTimeoutSeconds,omitempty" json:"-"`
  55. DeprecatedRelayServers []string `xml:"relayServer,omitempty" json:"-"`
  56. DeprecatedMinHomeDiskFreePct float64 `xml:"minHomeDiskFreePct,omitempty" json:"-"`
  57. }
  58. func (orig OptionsConfiguration) Copy() OptionsConfiguration {
  59. c := orig
  60. c.ListenAddresses = make([]string, len(orig.ListenAddresses))
  61. copy(c.ListenAddresses, orig.ListenAddresses)
  62. c.GlobalAnnServers = make([]string, len(orig.GlobalAnnServers))
  63. copy(c.GlobalAnnServers, orig.GlobalAnnServers)
  64. c.AlwaysLocalNets = make([]string, len(orig.AlwaysLocalNets))
  65. copy(c.AlwaysLocalNets, orig.AlwaysLocalNets)
  66. c.UnackedNotificationIDs = make([]string, len(orig.UnackedNotificationIDs))
  67. copy(c.UnackedNotificationIDs, orig.UnackedNotificationIDs)
  68. return c
  69. }
  70. // RequiresRestartOnly returns a copy with only the attributes that require
  71. // restart on change.
  72. func (orig OptionsConfiguration) RequiresRestartOnly() OptionsConfiguration {
  73. copy := orig
  74. blank := OptionsConfiguration{}
  75. util.CopyMatchingTag(&blank, &copy, "restart", func(v string) bool {
  76. if len(v) > 0 && v != "true" {
  77. panic(fmt.Sprintf(`unexpected tag value: %s. expected untagged or "true"`, v))
  78. }
  79. return v != "true"
  80. })
  81. return copy
  82. }