config

package
v0.12.0-beta3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2015 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package config implements reading and writing of the syncthing configuration file.

Index

Constants

View Source
const (
	OldestHandledVersion = 5
	CurrentVersion       = 12
	MaxRescanIntervalS   = 365 * 24 * 60 * 60
)

Variables

View Source
var (
	// DefaultDiscoveryServers should be substituted when the configuration
	// contains <globalAnnounceServer>default</globalAnnounceServer>. This is
	// done by the "consumer" of the configuration, as we don't want these
	// saved to the config.
	DefaultDiscoveryServers = []string{
		"https://discovery-v4-1.syncthing.net/?id=SR7AARM-TCBUZ5O-VFAXY4D-CECGSDE-3Q6IZ4G-XG7AH75-OBIXJQV-QJ6NLQA",
		"https://discovery-v4-2.syncthing.net/?id=AQEHEO2-XOS7QRA-X2COH5K-PO6OPVA-EWOSEGO-KZFMD32-XJ4ZV46-CUUVKAS",
		"https://discovery-v4-3.syncthing.net/?id=7WT2BVR-FX62ZOW-TNVVW25-6AHFJGD-XEXQSBW-VO3MPL2-JBTLL4T-P4572Q4",
		"https://discovery-v6-1.syncthing.net/?id=SR7AARM-TCBUZ5O-VFAXY4D-CECGSDE-3Q6IZ4G-XG7AH75-OBIXJQV-QJ6NLQA",
		"https://discovery-v6-2.syncthing.net/?id=AQEHEO2-XOS7QRA-X2COH5K-PO6OPVA-EWOSEGO-KZFMD32-XJ4ZV46-CUUVKAS",
		"https://discovery-v6-3.syncthing.net/?id=7WT2BVR-FX62ZOW-TNVVW25-6AHFJGD-XEXQSBW-VO3MPL2-JBTLL4T-P4572Q4",
	}

	// DefaultDiscoveryServersIP is used by the usage reporting.
	// XXX: Detect Android, and use this is we still don't have working DNS?
	DefaultDiscoveryServersIP = []string{
		"https://194.126.249.5/?id=SR7AARM-TCBUZ5O-VFAXY4D-CECGSDE-3Q6IZ4G-XG7AH75-OBIXJQV-QJ6NLQA",
		"https://45.55.230.38/?id=AQEHEO2-XOS7QRA-X2COH5K-PO6OPVA-EWOSEGO-KZFMD32-XJ4ZV46-CUUVKAS",
		"https://128.199.95.124/?id=7WT2BVR-FX62ZOW-TNVVW25-6AHFJGD-XEXQSBW-VO3MPL2-JBTLL4T-P4572Q4",
		"https://[2001:470:28:4d6::5]/?id=SR7AARM-TCBUZ5O-VFAXY4D-CECGSDE-3Q6IZ4G-XG7AH75-OBIXJQV-QJ6NLQA",
		"https://[2604:a880:800:10::182:a001]/?id=AQEHEO2-XOS7QRA-X2COH5K-PO6OPVA-EWOSEGO-KZFMD32-XJ4ZV46-CUUVKAS",
		"https://[2400:6180:0:d0::d9:d001]/?id=7WT2BVR-FX62ZOW-TNVVW25-6AHFJGD-XEXQSBW-VO3MPL2-JBTLL4T-P4572Q4",
	}
)
View Source
var ResponseNoRestart = CommitResponse{
	ValidationError: nil,
	RequiresRestart: false,
}

Functions

func ChangeRequiresRestart

func ChangeRequiresRestart(from, to Configuration) bool

ChangeRequiresRestart returns true if updating the configuration requires a complete restart.

Types

type CommitResponse

type CommitResponse struct {
	ValidationError error
	RequiresRestart bool
}

type Committer

type Committer interface {
	VerifyConfiguration(from, to Configuration) error
	CommitConfiguration(from, to Configuration) (handled bool)
	String() string
}

The Committer interface is implemented by objects that need to know about or have a say in configuration changes.

When the configuration is about to be changed, VerifyConfiguration() is called for each subscribing object, with the old and new configuration. A nil error is returned if the new configuration is acceptable (i.e. does not contain any errors that would prevent it from being a valid config). Otherwise an error describing the problem is returned.

If any subscriber returns an error from VerifyConfiguration(), the configuration change is not committed and an error is returned to whoever tried to commit the broken config.

If all verification calls returns nil, CommitConfiguration() is called for each subscribing object. The callee returns true if the new configuration has been successfully applied, otherwise false. Any Commit() call returning false will result in a "restart needed" respone to the API/user. Note that the new configuration will still have been applied by those who were capable of doing so.

type Configuration

type Configuration struct {
	Version        int                   `xml:"version,attr" json:"version"`
	Folders        []FolderConfiguration `xml:"folder" json:"folders"`
	Devices        []DeviceConfiguration `xml:"device" json:"devices"`
	GUI            GUIConfiguration      `xml:"gui" json:"gui"`
	Options        OptionsConfiguration  `xml:"options" json:"options"`
	IgnoredDevices []protocol.DeviceID   `xml:"ignoredDevice" json:"ignoredDevices"`
	XMLName        xml.Name              `xml:"configuration" json:"-"`

	OriginalVersion int `xml:"-" json:"-"` // The version we read from disk, before any conversion
}

func New

func ReadXML

func ReadXML(r io.Reader, myID protocol.DeviceID) (Configuration, error)

func (Configuration) Copy

func (cfg Configuration) Copy() Configuration

func (*Configuration) WriteXML

func (cfg *Configuration) WriteXML(w io.Writer) error

type DeviceConfiguration

type DeviceConfiguration struct {
	DeviceID    protocol.DeviceID    `xml:"id,attr" json:"deviceID"`
	Name        string               `xml:"name,attr,omitempty" json:"name"`
	Addresses   []string             `xml:"address,omitempty" json:"addresses"`
	Compression protocol.Compression `xml:"compression,attr" json:"compression"`
	CertName    string               `xml:"certName,attr,omitempty" json:"certName"`
	Introducer  bool                 `xml:"introducer,attr" json:"introducer"`
}

func (DeviceConfiguration) Copy

type DeviceConfigurationList

type DeviceConfigurationList []DeviceConfiguration

func (DeviceConfigurationList) Len

func (l DeviceConfigurationList) Len() int

func (DeviceConfigurationList) Less

func (l DeviceConfigurationList) Less(a, b int) bool

func (DeviceConfigurationList) Swap

func (l DeviceConfigurationList) Swap(a, b int)

type FolderConfiguration

type FolderConfiguration struct {
	ID                    string                      `xml:"id,attr" json:"id"`
	RawPath               string                      `xml:"path,attr" json:"path"`
	Devices               []FolderDeviceConfiguration `xml:"device" json:"devices"`
	ReadOnly              bool                        `xml:"ro,attr" json:"readOnly"`
	RescanIntervalS       int                         `xml:"rescanIntervalS,attr" json:"rescanIntervalS"`
	IgnorePerms           bool                        `xml:"ignorePerms,attr" json:"ignorePerms"`
	AutoNormalize         bool                        `xml:"autoNormalize,attr" json:"autoNormalize"`
	MinDiskFreePct        float64                     `xml:"minDiskFreePct" json:"minDiskFreePct"`
	Versioning            VersioningConfiguration     `xml:"versioning" json:"versioning"`
	Copiers               int                         `xml:"copiers" json:"copiers"` // This defines how many files are handled concurrently.
	Pullers               int                         `xml:"pullers" json:"pullers"` // Defines how many blocks are fetched at the same time, possibly between separate copier routines.
	Hashers               int                         `xml:"hashers" json:"hashers"` // Less than one sets the value to the number of cores. These are CPU bound due to hashing.
	Order                 PullOrder                   `xml:"order" json:"order"`
	IgnoreDelete          bool                        `xml:"ignoreDelete" json:"ignoreDelete"`
	ScanProgressIntervalS int                         `xml:"scanProgressIntervalS" json:"scanProgressIntervalS"` // Set to a negative value to disable. Value of 0 will get replaced with value of 2 (default value)
	PullerSleepS          int                         `xml:"pullerSleepS" json:"pullerSleepS"`
	PullerPauseS          int                         `xml:"pullerPauseS" json:"pullerPauseS"`

	Invalid string `xml:"-" json:"invalid"` // Set at runtime when there is an error, not saved
}

func (FolderConfiguration) Copy

func (*FolderConfiguration) CreateMarker

func (f *FolderConfiguration) CreateMarker() error

func (*FolderConfiguration) DeviceIDs

func (f *FolderConfiguration) DeviceIDs() []protocol.DeviceID

func (*FolderConfiguration) HasMarker

func (f *FolderConfiguration) HasMarker() bool

func (FolderConfiguration) Path

func (f FolderConfiguration) Path() string

type FolderDeviceConfiguration

type FolderDeviceConfiguration struct {
	DeviceID protocol.DeviceID `xml:"id,attr" json:"deviceID"`
}

type FolderDeviceConfigurationList

type FolderDeviceConfigurationList []FolderDeviceConfiguration

func (FolderDeviceConfigurationList) Len

func (FolderDeviceConfigurationList) Less

func (l FolderDeviceConfigurationList) Less(a, b int) bool

func (FolderDeviceConfigurationList) Swap

func (l FolderDeviceConfigurationList) Swap(a, b int)

type GUIConfiguration

type GUIConfiguration struct {
	Enabled  bool   `xml:"enabled,attr" json:"enabled" default:"true"`
	Address  string `xml:"address" json:"address" default:"127.0.0.1:8384"`
	User     string `xml:"user,omitempty" json:"user"`
	Password string `xml:"password,omitempty" json:"password"`
	UseTLS   bool   `xml:"tls,attr" json:"useTLS"`
	APIKey   string `xml:"apikey,omitempty" json:"apiKey"`
}

type InternalParam

type InternalParam struct {
	Key string `xml:"key,attr"`
	Val string `xml:"val,attr"`
}

type InternalVersioningConfiguration

type InternalVersioningConfiguration struct {
	Type   string          `xml:"type,attr,omitempty"`
	Params []InternalParam `xml:"param"`
}

type OptionsConfiguration

type OptionsConfiguration struct {
	ListenAddress           []string `xml:"listenAddress" json:"listenAddress" default:"tcp://0.0.0.0:22000"`
	GlobalAnnServers        []string `xml:"globalAnnounceServer" json:"globalAnnounceServers" json:"globalAnnounceServer" default:"default"`
	GlobalAnnEnabled        bool     `xml:"globalAnnounceEnabled" json:"globalAnnounceEnabled" default:"true"`
	LocalAnnEnabled         bool     `xml:"localAnnounceEnabled" json:"localAnnounceEnabled" default:"true"`
	LocalAnnPort            int      `xml:"localAnnouncePort" json:"localAnnouncePort" default:"21027"`
	LocalAnnMCAddr          string   `xml:"localAnnounceMCAddr" json:"localAnnounceMCAddr" default:"[ff12::8384]:21027"`
	RelayServers            []string `xml:"relayServer" json:"relayServers" default:"dynamic+https://relays.syncthing.net"`
	MaxSendKbps             int      `xml:"maxSendKbps" json:"maxSendKbps"`
	MaxRecvKbps             int      `xml:"maxRecvKbps" json:"maxRecvKbps"`
	ReconnectIntervalS      int      `xml:"reconnectionIntervalS" json:"reconnectionIntervalS" default:"60"`
	RelaysEnabled           bool     `xml:"relaysEnabled" json:"relaysEnabled" default:"true"`
	RelayReconnectIntervalM int      `xml:"relayReconnectIntervalM" json:"relayReconnectIntervalM" default:"10"`
	RelayWithoutGlobalAnn   bool     `xml:"relayWithoutGlobalAnn" json:"relayWithoutGlobalAnn" default:"false"`
	StartBrowser            bool     `xml:"startBrowser" json:"startBrowser" default:"true"`
	UPnPEnabled             bool     `xml:"upnpEnabled" json:"upnpEnabled" default:"true"`
	UPnPLeaseM              int      `xml:"upnpLeaseMinutes" json:"upnpLeaseMinutes" default:"60"`
	UPnPRenewalM            int      `xml:"upnpRenewalMinutes" json:"upnpRenewalMinutes" default:"30"`
	UPnPTimeoutS            int      `xml:"upnpTimeoutSeconds" json:"upnpTimeoutSeconds" default:"10"`
	URAccepted              int      `xml:"urAccepted" json:"urAccepted"` // Accepted usage reporting version; 0 for off (undecided), -1 for off (permanently)
	URUniqueID              string   `xml:"urUniqueID" json:"urUniqueId"` // Unique ID for reporting purposes, regenerated when UR is turned on.
	URURL                   string   `xml:"urURL" json:"urURL" default:"https://data.syncthing.net/newdata"`
	URPostInsecurely        bool     `xml:"urPostInsecurely" json:"urPostInsecurely" default:"false"` // For testing
	URInitialDelayS         int      `xml:"urInitialDelayS" json:"urInitialDelayS" default:"1800"`
	RestartOnWakeup         bool     `xml:"restartOnWakeup" json:"restartOnWakeup" default:"true"`
	AutoUpgradeIntervalH    int      `xml:"autoUpgradeIntervalH" json:"autoUpgradeIntervalH" default:"12"` // 0 for off
	KeepTemporariesH        int      `xml:"keepTemporariesH" json:"keepTemporariesH" default:"24"`         // 0 for off
	CacheIgnoredFiles       bool     `xml:"cacheIgnoredFiles" json:"cacheIgnoredFiles" default:"true"`
	ProgressUpdateIntervalS int      `xml:"progressUpdateIntervalS" json:"progressUpdateIntervalS" default:"5"`
	SymlinksEnabled         bool     `xml:"symlinksEnabled" json:"symlinksEnabled" default:"true"`
	LimitBandwidthInLan     bool     `xml:"limitBandwidthInLan" json:"limitBandwidthInLan" default:"false"`
	DatabaseBlockCacheMiB   int      `xml:"databaseBlockCacheMiB" json:"databaseBlockCacheMiB" default:"0"`
	MinHomeDiskFreePct      float64  `xml:"minHomeDiskFreePct" json:"minHomeDiskFreePct" default:"1"`
	ReleasesURL             string   `xml:"releasesURL" json:"releasesURL" default:"https://api.github.com/repos/syncthing/syncthing/releases?per_page=30"`
	AlwaysLocalNets         []string `xml:"alwaysLocalNet" json:"alwaysLocalNets"`
}

func (OptionsConfiguration) Copy

type PullOrder

type PullOrder int
const (
	OrderRandom PullOrder = iota // default is random
	OrderAlphabetic
	OrderSmallestFirst
	OrderLargestFirst
	OrderOldestFirst
	OrderNewestFirst
)

func (PullOrder) MarshalText

func (o PullOrder) MarshalText() ([]byte, error)

func (PullOrder) String

func (o PullOrder) String() string

func (*PullOrder) UnmarshalText

func (o *PullOrder) UnmarshalText(bs []byte) error

type VersioningConfiguration

type VersioningConfiguration struct {
	Type   string            `xml:"type,attr" json:"type"`
	Params map[string]string `json:"params"`
}

func (*VersioningConfiguration) MarshalXML

func (c *VersioningConfiguration) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*VersioningConfiguration) UnmarshalXML

func (c *VersioningConfiguration) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Wrapper

type Wrapper struct {
	// contains filtered or unexported fields
}

func Load

func Load(path string, myID protocol.DeviceID) (*Wrapper, error)

Load loads an existing file on disk and returns a new configuration wrapper.

func Wrap

func Wrap(path string, cfg Configuration) *Wrapper

Wrap wraps an existing Configuration structure and ties it to a file on disk.

func (*Wrapper) ConfigPath

func (w *Wrapper) ConfigPath() string

func (*Wrapper) Devices

func (w *Wrapper) Devices() map[protocol.DeviceID]DeviceConfiguration

Devices returns a map of devices. Device structures should not be changed, other than for the purpose of updating via SetDevice().

func (*Wrapper) Folders

func (w *Wrapper) Folders() map[string]FolderConfiguration

Folders returns a map of folders. Folder structures should not be changed, other than for the purpose of updating via SetFolder().

func (*Wrapper) GUI

func (w *Wrapper) GUI() GUIConfiguration

GUI returns the current GUI configuration object.

func (*Wrapper) GlobalDiscoveryServers added in v0.12.0

func (w *Wrapper) GlobalDiscoveryServers() []string

func (*Wrapper) IgnoredDevice

func (w *Wrapper) IgnoredDevice(id protocol.DeviceID) bool

IgnoredDevice returns whether or not connection attempts from the given device should be silently ignored.

func (*Wrapper) Options

func (w *Wrapper) Options() OptionsConfiguration

Options returns the current options configuration object.

func (*Wrapper) Raw

func (w *Wrapper) Raw() Configuration

Raw returns the currently wrapped Configuration object.

func (*Wrapper) Replace

func (w *Wrapper) Replace(cfg Configuration) CommitResponse

Replace swaps the current configuration object for the given one.

func (*Wrapper) Save

func (w *Wrapper) Save() error

Save writes the configuration to disk, and generates a ConfigSaved event.

func (*Wrapper) SetDevice

func (w *Wrapper) SetDevice(dev DeviceConfiguration) CommitResponse

SetDevice adds a new device to the configuration, or overwrites an existing device with the same ID.

func (*Wrapper) SetFolder

func (w *Wrapper) SetFolder(fld FolderConfiguration) CommitResponse

SetFolder adds a new folder to the configuration, or overwrites an existing folder with the same ID.

func (*Wrapper) SetGUI

func (w *Wrapper) SetGUI(gui GUIConfiguration) CommitResponse

SetGUI replaces the current GUI configuration object.

func (*Wrapper) SetOptions

func (w *Wrapper) SetOptions(opts OptionsConfiguration) CommitResponse

SetOptions replaces the current options configuration object.

func (*Wrapper) Stop

func (w *Wrapper) Stop()

Stop stops the Serve() loop. Set and Replace operations will panic after a Stop.

func (*Wrapper) Subscribe

func (w *Wrapper) Subscribe(c Committer)

Subscribe registers the given handler to be called on any future configuration changes.

func (*Wrapper) Unsubscribe added in v0.12.0

func (w *Wrapper) Unsubscribe(c Committer)

Unsubscribe de-registers the given handler from any future calls to configuration changes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL