optionsconfiguration.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. DatabaseTuning Tuning `xml:"databaseTuning" json:"databaseTuning" restart:"true"`
  57. DeprecatedUPnPEnabled bool `xml:"upnpEnabled,omitempty" json:"-"`
  58. DeprecatedUPnPLeaseM int `xml:"upnpLeaseMinutes,omitempty" json:"-"`
  59. DeprecatedUPnPRenewalM int `xml:"upnpRenewalMinutes,omitempty" json:"-"`
  60. DeprecatedUPnPTimeoutS int `xml:"upnpTimeoutSeconds,omitempty" json:"-"`
  61. DeprecatedRelayServers []string `xml:"relayServer,omitempty" json:"-"`
  62. DeprecatedMinHomeDiskFreePct float64 `xml:"minHomeDiskFreePct,omitempty" json:"-"`
  63. }
  64. func (opts OptionsConfiguration) Copy() OptionsConfiguration {
  65. optsCopy := opts
  66. optsCopy.ListenAddresses = make([]string, len(opts.ListenAddresses))
  67. copy(optsCopy.ListenAddresses, opts.ListenAddresses)
  68. optsCopy.GlobalAnnServers = make([]string, len(opts.GlobalAnnServers))
  69. copy(optsCopy.GlobalAnnServers, opts.GlobalAnnServers)
  70. optsCopy.AlwaysLocalNets = make([]string, len(opts.AlwaysLocalNets))
  71. copy(optsCopy.AlwaysLocalNets, opts.AlwaysLocalNets)
  72. optsCopy.UnackedNotificationIDs = make([]string, len(opts.UnackedNotificationIDs))
  73. copy(optsCopy.UnackedNotificationIDs, opts.UnackedNotificationIDs)
  74. return optsCopy
  75. }
  76. // RequiresRestartOnly returns a copy with only the attributes that require
  77. // restart on change.
  78. func (opts OptionsConfiguration) RequiresRestartOnly() OptionsConfiguration {
  79. optsCopy := opts
  80. blank := OptionsConfiguration{}
  81. util.CopyMatchingTag(&blank, &optsCopy, "restart", func(v string) bool {
  82. if len(v) > 0 && v != "true" {
  83. panic(fmt.Sprintf(`unexpected tag value: %s. Expected untagged or "true"`, v))
  84. }
  85. return v != "true"
  86. })
  87. return optsCopy
  88. }
  89. func (opts OptionsConfiguration) IsStunDisabled() bool {
  90. return opts.StunKeepaliveMinS < 1 || opts.StunKeepaliveStartS < 1 || !opts.NATEnabled
  91. }