config

package
v0.10.9 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2014 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const CurrentVersion = 6

Variables

This section is empty.

Functions

func ChangeRequiresRestart

func ChangeRequiresRestart(from, to Configuration) bool

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

Types

type ConfigWrapper added in v0.10.0

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

func Load

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

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

func Wrap added in v0.10.0

func Wrap(path string, cfg Configuration) *ConfigWrapper

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

func (*ConfigWrapper) Devices added in v0.10.0

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

func (*ConfigWrapper) Folders added in v0.10.0

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

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

func (*ConfigWrapper) GUI added in v0.10.0

GUI returns the current GUI configuration object.

func (*ConfigWrapper) InvalidateFolder added in v0.10.0

func (w *ConfigWrapper) InvalidateFolder(id string, err string)

InvalidateFolder sets the invalid marker on the given folder.

func (*ConfigWrapper) Options added in v0.10.0

func (w *ConfigWrapper) Options() OptionsConfiguration

Options returns the current options configuration object.

func (*ConfigWrapper) Raw added in v0.10.0

func (w *ConfigWrapper) Raw() Configuration

Raw returns the currently wrapped Configuration object.

func (*ConfigWrapper) Replace added in v0.10.0

func (w *ConfigWrapper) Replace(cfg Configuration)

Replace swaps the current configuration object for the given one.

func (*ConfigWrapper) Save added in v0.10.0

func (w *ConfigWrapper) Save() error

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

func (*ConfigWrapper) Serve added in v0.10.0

func (w *ConfigWrapper) Serve()

Serve handles configuration replace events and calls any interested handlers. It is started automatically by Wrap() and Load() and should not be run manually.

func (*ConfigWrapper) SetDevice added in v0.10.0

func (w *ConfigWrapper) SetDevice(dev DeviceConfiguration)

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

func (*ConfigWrapper) SetFolder added in v0.10.0

func (w *ConfigWrapper) SetFolder(fld FolderConfiguration)

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

func (*ConfigWrapper) SetGUI added in v0.10.0

func (w *ConfigWrapper) SetGUI(gui GUIConfiguration)

SetGUI replaces the current GUI configuration object.

func (*ConfigWrapper) SetOptions added in v0.10.0

func (w *ConfigWrapper) SetOptions(opts OptionsConfiguration)

SetOptions replaces the current options configuration object.

func (*ConfigWrapper) Stop added in v0.10.0

func (w *ConfigWrapper) Stop()

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

func (*ConfigWrapper) Subscribe added in v0.10.0

func (w *ConfigWrapper) Subscribe(h Handler)

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

type Configuration

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

	OriginalVersion         int                   `xml:"-" json:"-"` // The version we read from disk, before any conversion
	Deprecated_Repositories []FolderConfiguration `xml:"repository" json:"-"`
	Deprecated_Nodes        []DeviceConfiguration `xml:"node" json:"-"`
}

func New

func ReadXML added in v0.10.0

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

func (*Configuration) WriteXML added in v0.10.0

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

type DeviceConfiguration added in v0.10.0

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

type DeviceConfigurationList added in v0.10.0

type DeviceConfigurationList []DeviceConfiguration

func (DeviceConfigurationList) Len added in v0.10.0

func (l DeviceConfigurationList) Len() int

func (DeviceConfigurationList) Less added in v0.10.0

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

func (DeviceConfigurationList) Swap added in v0.10.0

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

type FolderConfiguration added in v0.10.0

type FolderConfiguration struct {
	ID              string                      `xml:"id,attr"`
	Path            string                      `xml:"path,attr"`
	Devices         []FolderDeviceConfiguration `xml:"device"`
	ReadOnly        bool                        `xml:"ro,attr"`
	RescanIntervalS int                         `xml:"rescanIntervalS,attr" default:"60"`
	IgnorePerms     bool                        `xml:"ignorePerms,attr"`
	Versioning      VersioningConfiguration     `xml:"versioning"`
	LenientMtimes   bool                        `xml:"lenientMtimes"`
	Copiers         int                         `xml:"copiers" default:"1"`   // This defines how many files are handled concurrently.
	Pullers         int                         `xml:"pullers" default:"16"`  // Defines how many blocks are fetched at the same time, possibly between separate copier routines.
	Finishers       int                         `xml:"finishers" default:"1"` // Most of the time, should be equal to the number of copiers. These are CPU bound due to hashing.

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

	Deprecated_Directory string                      `xml:"directory,omitempty,attr" json:"-"`
	Deprecated_Nodes     []FolderDeviceConfiguration `xml:"node" json:"-"`
	// contains filtered or unexported fields
}

func (*FolderConfiguration) CreateMarker added in v0.10.2

func (f *FolderConfiguration) CreateMarker() error

func (*FolderConfiguration) DeviceIDs added in v0.10.0

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

func (*FolderConfiguration) HasMarker added in v0.10.2

func (f *FolderConfiguration) HasMarker() bool

type FolderDeviceConfiguration added in v0.10.0

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

	Deprecated_Name      string   `xml:"name,attr,omitempty" json:"-"`
	Deprecated_Addresses []string `xml:"address,omitempty" json:"-"`
}

type FolderDeviceConfigurationList added in v0.10.0

type FolderDeviceConfigurationList []FolderDeviceConfiguration

func (FolderDeviceConfigurationList) Len added in v0.10.0

func (FolderDeviceConfigurationList) Less added in v0.10.0

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

func (FolderDeviceConfigurationList) Swap added in v0.10.0

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

type GUIConfiguration

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

type Handler added in v0.10.0

type Handler interface {
	Changed(Configuration) error
}

type HandlerFunc added in v0.10.0

type HandlerFunc func(Configuration) error

func (HandlerFunc) Changed added in v0.10.0

func (fn HandlerFunc) Changed(cfg Configuration) error

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" default:"0.0.0.0:22000"`
	GlobalAnnServers        []string `xml:"globalAnnounceServer" default:"announce.syncthing.net:22026"`
	GlobalAnnEnabled        bool     `xml:"globalAnnounceEnabled" default:"true"`
	LocalAnnEnabled         bool     `xml:"localAnnounceEnabled" default:"true"`
	LocalAnnPort            int      `xml:"localAnnouncePort" default:"21025"`
	LocalAnnMCAddr          string   `xml:"localAnnounceMCAddr" default:"[ff32::5222]:21026"`
	MaxSendKbps             int      `xml:"maxSendKbps"`
	MaxRecvKbps             int      `xml:"maxRecvKbps"`
	ReconnectIntervalS      int      `xml:"reconnectionIntervalS" default:"60"`
	StartBrowser            bool     `xml:"startBrowser" default:"true"`
	UPnPEnabled             bool     `xml:"upnpEnabled" default:"true"`
	UPnPLease               int      `xml:"upnpLeaseMinutes" default:"0"`
	UPnPRenewal             int      `xml:"upnpRenewalMinutes" default:"30"`
	URAccepted              int      `xml:"urAccepted"` // Accepted usage reporting version; 0 for off (undecided), -1 for off (permanently)
	URUniqueID              string   `xml:"urUniqueID"` // Unique ID for reporting purposes, regenerated when UR is turned on.
	RestartOnWakeup         bool     `xml:"restartOnWakeup" default:"true"`
	AutoUpgradeIntervalH    int      `xml:"autoUpgradeIntervalH" default:"12"` // 0 for off
	KeepTemporariesH        int      `xml:"keepTemporariesH" default:"24"`     // 0 for off
	CacheIgnoredFiles       bool     `xml:"cacheIgnoredFiles" default:"true"`
	ProgressUpdateIntervalS int      `xml:"progressUpdateIntervalS" default:"5"`

	Deprecated_RescanIntervalS int    `xml:"rescanIntervalS,omitempty" json:"-"`
	Deprecated_UREnabled       bool   `xml:"urEnabled,omitempty" json:"-"`
	Deprecated_URDeclined      bool   `xml:"urDeclined,omitempty" json:"-"`
	Deprecated_ReadOnly        bool   `xml:"readOnly,omitempty" json:"-"`
	Deprecated_GUIEnabled      bool   `xml:"guiEnabled,omitempty" json:"-"`
	Deprecated_GUIAddress      string `xml:"guiAddress,omitempty" json:"-"`
}

type VersioningConfiguration

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

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

Jump to

Keyboard shortcuts

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