optionsconfiguration.go 6.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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"` // usage reporting URL
  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. CRURL string `xml:"crashReportingURL" json:"crURL" default:"https://crash.syncthing.net/newcrash"` // crash reporting URL
  52. CREnabled bool `xml:"crashReportingEnabled" json:"crashReportingEnabled" default:"true" restart:"true"`
  53. StunKeepaliveStartS int `xml:"stunKeepaliveStartS" json:"stunKeepaliveStartS" default:"180"` // 0 for off
  54. StunKeepaliveMinS int `xml:"stunKeepaliveMinS" json:"stunKeepaliveMinS" default:"20"` // 0 for off
  55. StunServers []string `xml:"stunServer" json:"stunServers" default:"default"`
  56. DeprecatedUPnPEnabled bool `xml:"upnpEnabled,omitempty" json:"-"`
  57. DeprecatedUPnPLeaseM int `xml:"upnpLeaseMinutes,omitempty" json:"-"`
  58. DeprecatedUPnPRenewalM int `xml:"upnpRenewalMinutes,omitempty" json:"-"`
  59. DeprecatedUPnPTimeoutS int `xml:"upnpTimeoutSeconds,omitempty" json:"-"`
  60. DeprecatedRelayServers []string `xml:"relayServer,omitempty" json:"-"`
  61. DeprecatedMinHomeDiskFreePct float64 `xml:"minHomeDiskFreePct,omitempty" json:"-"`
  62. }
  63. func (opts OptionsConfiguration) Copy() OptionsConfiguration {
  64. optsCopy := opts
  65. optsCopy.ListenAddresses = make([]string, len(opts.ListenAddresses))
  66. copy(optsCopy.ListenAddresses, opts.ListenAddresses)
  67. optsCopy.GlobalAnnServers = make([]string, len(opts.GlobalAnnServers))
  68. copy(optsCopy.GlobalAnnServers, opts.GlobalAnnServers)
  69. optsCopy.AlwaysLocalNets = make([]string, len(opts.AlwaysLocalNets))
  70. copy(optsCopy.AlwaysLocalNets, opts.AlwaysLocalNets)
  71. optsCopy.UnackedNotificationIDs = make([]string, len(opts.UnackedNotificationIDs))
  72. copy(optsCopy.UnackedNotificationIDs, opts.UnackedNotificationIDs)
  73. return optsCopy
  74. }
  75. // RequiresRestartOnly returns a copy with only the attributes that require
  76. // restart on change.
  77. func (opts OptionsConfiguration) RequiresRestartOnly() OptionsConfiguration {
  78. optsCopy := opts
  79. blank := OptionsConfiguration{}
  80. util.CopyMatchingTag(&blank, &optsCopy, "restart", func(v string) bool {
  81. if len(v) > 0 && v != "true" {
  82. panic(fmt.Sprintf(`unexpected tag value: %s. Expected untagged or "true"`, v))
  83. }
  84. return v != "true"
  85. })
  86. return optsCopy
  87. }
  88. func (opts OptionsConfiguration) IsStunDisabled() bool {
  89. return opts.StunKeepaliveMinS < 1 || opts.StunKeepaliveStartS < 1 || !opts.NATEnabled
  90. }