optionsconfiguration.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 (
  8. "encoding/json"
  9. "encoding/xml"
  10. "fmt"
  11. )
  12. type WeakHashSelectionMethod int
  13. const (
  14. WeakHashAuto WeakHashSelectionMethod = iota
  15. WeakHashAlways
  16. WeakHashNever
  17. )
  18. func (m WeakHashSelectionMethod) MarshalString() (string, error) {
  19. switch m {
  20. case WeakHashAuto:
  21. return "auto", nil
  22. case WeakHashAlways:
  23. return "always", nil
  24. case WeakHashNever:
  25. return "never", nil
  26. default:
  27. return "", fmt.Errorf("unrecognized hash selection method")
  28. }
  29. }
  30. func (m WeakHashSelectionMethod) String() string {
  31. s, err := m.MarshalString()
  32. if err != nil {
  33. panic(err)
  34. }
  35. return s
  36. }
  37. func (m *WeakHashSelectionMethod) UnmarshalString(value string) error {
  38. switch value {
  39. case "auto":
  40. *m = WeakHashAuto
  41. return nil
  42. case "always":
  43. *m = WeakHashAlways
  44. return nil
  45. case "never":
  46. *m = WeakHashNever
  47. return nil
  48. }
  49. return fmt.Errorf("unrecognized hash selection method")
  50. }
  51. func (m WeakHashSelectionMethod) MarshalJSON() ([]byte, error) {
  52. val, err := m.MarshalString()
  53. if err != nil {
  54. return nil, err
  55. }
  56. return json.Marshal(val)
  57. }
  58. func (m *WeakHashSelectionMethod) UnmarshalJSON(data []byte) error {
  59. var value string
  60. if err := json.Unmarshal(data, &value); err != nil {
  61. return err
  62. }
  63. return m.UnmarshalString(value)
  64. }
  65. func (m WeakHashSelectionMethod) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
  66. val, err := m.MarshalString()
  67. if err != nil {
  68. return err
  69. }
  70. return e.EncodeElement(val, start)
  71. }
  72. func (m *WeakHashSelectionMethod) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
  73. var value string
  74. if err := d.DecodeElement(&value, &start); err != nil {
  75. return err
  76. }
  77. return m.UnmarshalString(value)
  78. }
  79. func (WeakHashSelectionMethod) ParseDefault(value string) (interface{}, error) {
  80. var m WeakHashSelectionMethod
  81. err := m.UnmarshalString(value)
  82. return m, err
  83. }
  84. type OptionsConfiguration struct {
  85. ListenAddresses []string `xml:"listenAddress" json:"listenAddresses" default:"default"`
  86. GlobalAnnServers []string `xml:"globalAnnounceServer" json:"globalAnnounceServers" json:"globalAnnounceServer" default:"default"`
  87. GlobalAnnEnabled bool `xml:"globalAnnounceEnabled" json:"globalAnnounceEnabled" default:"true"`
  88. LocalAnnEnabled bool `xml:"localAnnounceEnabled" json:"localAnnounceEnabled" default:"true"`
  89. LocalAnnPort int `xml:"localAnnouncePort" json:"localAnnouncePort" default:"21027"`
  90. LocalAnnMCAddr string `xml:"localAnnounceMCAddr" json:"localAnnounceMCAddr" default:"[ff12::8384]:21027"`
  91. MaxSendKbps int `xml:"maxSendKbps" json:"maxSendKbps"`
  92. MaxRecvKbps int `xml:"maxRecvKbps" json:"maxRecvKbps"`
  93. ReconnectIntervalS int `xml:"reconnectionIntervalS" json:"reconnectionIntervalS" default:"60"`
  94. RelaysEnabled bool `xml:"relaysEnabled" json:"relaysEnabled" default:"true"`
  95. RelayReconnectIntervalM int `xml:"relayReconnectIntervalM" json:"relayReconnectIntervalM" default:"10"`
  96. StartBrowser bool `xml:"startBrowser" json:"startBrowser" default:"true"`
  97. NATEnabled bool `xml:"natEnabled" json:"natEnabled" default:"true"`
  98. NATLeaseM int `xml:"natLeaseMinutes" json:"natLeaseMinutes" default:"60"`
  99. NATRenewalM int `xml:"natRenewalMinutes" json:"natRenewalMinutes" default:"30"`
  100. NATTimeoutS int `xml:"natTimeoutSeconds" json:"natTimeoutSeconds" default:"10"`
  101. URAccepted int `xml:"urAccepted" json:"urAccepted"` // Accepted usage reporting version; 0 for off (undecided), -1 for off (permanently)
  102. URUniqueID string `xml:"urUniqueID" json:"urUniqueId"` // Unique ID for reporting purposes, regenerated when UR is turned on.
  103. URURL string `xml:"urURL" json:"urURL" default:"https://data.syncthing.net/newdata"`
  104. URPostInsecurely bool `xml:"urPostInsecurely" json:"urPostInsecurely" default:"false"` // For testing
  105. URInitialDelayS int `xml:"urInitialDelayS" json:"urInitialDelayS" default:"1800"`
  106. RestartOnWakeup bool `xml:"restartOnWakeup" json:"restartOnWakeup" default:"true"`
  107. AutoUpgradeIntervalH int `xml:"autoUpgradeIntervalH" json:"autoUpgradeIntervalH" default:"12"` // 0 for off
  108. UpgradeToPreReleases bool `xml:"upgradeToPreReleases" json:"upgradeToPreReleases"` // when auto upgrades are enabled
  109. KeepTemporariesH int `xml:"keepTemporariesH" json:"keepTemporariesH" default:"24"` // 0 for off
  110. CacheIgnoredFiles bool `xml:"cacheIgnoredFiles" json:"cacheIgnoredFiles" default:"false"`
  111. ProgressUpdateIntervalS int `xml:"progressUpdateIntervalS" json:"progressUpdateIntervalS" default:"5"`
  112. LimitBandwidthInLan bool `xml:"limitBandwidthInLan" json:"limitBandwidthInLan" default:"false"`
  113. MinHomeDiskFreePct float64 `xml:"minHomeDiskFreePct" json:"minHomeDiskFreePct" default:"1"`
  114. ReleasesURL string `xml:"releasesURL" json:"releasesURL" default:"https://upgrades.syncthing.net/meta.json"`
  115. AlwaysLocalNets []string `xml:"alwaysLocalNet" json:"alwaysLocalNets"`
  116. OverwriteRemoteDevNames bool `xml:"overwriteRemoteDeviceNamesOnConnect" json:"overwriteRemoteDeviceNamesOnConnect" default:"false"`
  117. TempIndexMinBlocks int `xml:"tempIndexMinBlocks" json:"tempIndexMinBlocks" default:"10"`
  118. UnackedNotificationIDs []string `xml:"unackedNotificationID" json:"unackedNotificationIDs"`
  119. TrafficClass int `xml:"trafficClass" json:"trafficClass"`
  120. WeakHashSelectionMethod WeakHashSelectionMethod `xml:"weakHashSelectionMethod" json:"weakHashSelectionMethod"`
  121. DeprecatedUPnPEnabled bool `xml:"upnpEnabled,omitempty" json:"-"`
  122. DeprecatedUPnPLeaseM int `xml:"upnpLeaseMinutes,omitempty" json:"-"`
  123. DeprecatedUPnPRenewalM int `xml:"upnpRenewalMinutes,omitempty" json:"-"`
  124. DeprecatedUPnPTimeoutS int `xml:"upnpTimeoutSeconds,omitempty" json:"-"`
  125. DeprecatedRelayServers []string `xml:"relayServer,omitempty" json:"-"`
  126. }
  127. func (orig OptionsConfiguration) Copy() OptionsConfiguration {
  128. c := orig
  129. c.ListenAddresses = make([]string, len(orig.ListenAddresses))
  130. copy(c.ListenAddresses, orig.ListenAddresses)
  131. c.GlobalAnnServers = make([]string, len(orig.GlobalAnnServers))
  132. copy(c.GlobalAnnServers, orig.GlobalAnnServers)
  133. c.AlwaysLocalNets = make([]string, len(orig.AlwaysLocalNets))
  134. copy(c.AlwaysLocalNets, orig.AlwaysLocalNets)
  135. c.UnackedNotificationIDs = make([]string, len(orig.UnackedNotificationIDs))
  136. copy(c.UnackedNotificationIDs, orig.UnackedNotificationIDs)
  137. return c
  138. }