syncthing

package
v0.0.0-...-fa857ea Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIKeyHeader      = "X-Api-Key"
	APIKeyHeaderValue = "cnd"
)
View Source
const (

	// DefaultRemoteDeviceID remote syncthing device ID
	DefaultRemoteDeviceID = "ATOPHFJ-VPVLDFY-QVZDCF2-OQQ7IOW-OG4DIXF-OA7RWU3-ZYA4S22-SI4XVAU"
	// LocalDeviceID local syncthing device ID
	LocalDeviceID = "ABKAVQF-RUO4CYO-FSC2VIP-VRX4QDA-TQQRN2J-MRDXJUC-FXNWP6N-S6ZSAAR"

	// DefaultFileWatcherDelay how much to wait before starting a sync after a file change
	DefaultFileWatcherDelay = 5

	// ClusterPort is the port used by syncthing in the cluster
	ClusterPort = 22000

	// GUIPort is the port used by syncthing in the cluster for the http endpoint
	GUIPort = 8384
)

Variables

This section is empty.

Functions

func GetDownloadURL

func GetDownloadURL(os, arch, version string) (string, error)

GetDownloadURL returns the url of the syncthing package for the OS and ARCH

func GetFolderName

func GetFolderName(folder *Folder) string

func GetLogFile

func GetLogFile(namespace, name string) string

GetLogFile returns the path to the syncthing log file

func GetMinimumVersion

func GetMinimumVersion() *semver.Version

func Install

func Install(p getter.ProgressTracker) error

Install installs syncthing locally

func IsInstalled

func IsInstalled() bool

IsInstalled returns true if syncthing is installed

func NewAPIClient

func NewAPIClient() *http.Client

NewAPIClient returns a new syncthing api client configured to call the syncthing api

func RemoveFolder

func RemoveFolder(dev *model.Dev) error

RemoveFolder deletes all the files created by the syncthing instance

func ShouldUpgrade

func ShouldUpgrade() bool

ShouldUpgrade returns true if syncthing should be upgraded

Types

type Completion

type Completion struct {
	Completion  float64 `json:"completion"`
	GlobalBytes int64   `json:"globalBytes"`
	NeedBytes   int64   `json:"needBytes"`
	GlobalItems int64   `json:"globalItems"`
	NeedItems   int64   `json:"needItems"`
	NeedDeletes int64   `json:"needDeletes"`
}

Completion represents the completion of a syncthing folder.

type Connection

type Connection struct {
	Connected bool `json:"connected"`
}

Connection represents syncthing connection.

type Connections

type Connections struct {
	Connections map[string]Connection `json:"connections"`
}

Connections represents syncthing connections.

type DataFolderErrorEvent

type DataFolderErrorEvent struct {
	Errors []FolderError `json:"errors"`
}

DataFolderErrorEvent represents data folder errors in syncthing.

type DataFolderSummaryEvent

type DataFolderSummaryEvent struct {
	Summary Status `json:"summary"`
}

DataFolderSummaryEvent represents data folder summary in syncthing.

type DataStateChangedEvent

type DataStateChangedEvent struct {
	State string `json:"to"`
}

DataStateChangedEvent represents data state changed in syncthing.

type DownloadProgressData

type DownloadProgressData struct {
	BytesTotal int64 `json:"bytesTotal"`
}

DownloadProgressData represents an the information about a DownloadProgress event

type Folder

type Folder struct {
	Name        string `yaml:"name"`
	LocalPath   string `yaml:"localPath"`
	RemotePath  string `yaml:"remotePath"`
	Overwritten bool   `yaml:"-"`
}

Folder represents a sync folder

type FolderError

type FolderError struct {
	Error string `json:"error"`
	Path  string `json:"path"`
}

FolderError represents a folder error in syncthing.

type FolderErrorEvent

type FolderErrorEvent struct {
	Type string               `json:"type"`
	Data DataFolderErrorEvent `json:"data"`
}

FolderErrorEvent represents folder errors in syncthing.

type FolderSummaryEvent

type FolderSummaryEvent struct {
	Type string                 `json:"type"`
	Data DataFolderSummaryEvent `json:"data"`
}

FolderSummaryEvent represents folder summary in syncthing.

type ItemEvent

type ItemEvent struct {
	Time     time.Time                                  `json:"time"`
	Data     map[string]map[string]DownloadProgressData `json:"data"`
	Id       int                                        `json:"id"`
	GlobalId int                                        `json:"globalID"`
}

ItemEvent represents an item event of any type in syncthing.

type StateChangedEvent

type StateChangedEvent struct {
	Type string                `json:"type"`
	Data DataStateChangedEvent `json:"data"`
}

StateChangedEvent represents state changed in syncthing.

type Status

type Status struct {
	State      string `json:"state"`
	PullErrors int64  `json:"pullErrors"`
}

Status represents the status of a syncthing folder.

type Syncthing

type Syncthing struct {
	Client *http.Client `yaml:"-"`

	Type             string `yaml:"-"`
	APIKey           string `yaml:"apikey"`
	RemoteDeviceID   string `yaml:"-"`
	RemoteGUIAddress string `yaml:"remote"`
	GUIPassword      string `yaml:"password"`
	GUIPasswordHash  string `yaml:"-"`

	GUIAddress     string    `yaml:"local"`
	Home           string    `yaml:"-"`
	LogPath        string    `yaml:"-"`
	ListenAddress  string    `yaml:"-"`
	RemoteAddress  string    `yaml:"-"`
	RescanInterval string    `yaml:"-"`
	Compression    string    `yaml:"-"`
	Folders        []*Folder `yaml:"folders"`

	FileWatcherDelay int `yaml:"-"`
	RemoteGUIPort    int `yaml:"-"`
	RemotePort       int `yaml:"-"`
	LocalGUIPort     int `yaml:"-"`
	LocalPort        int `yaml:"-"`

	ForceSendOnly bool `yaml:"-"`
	ResetDatabase bool `yaml:"-"`
	IgnoreDelete  bool `yaml:"-"`
	Verbose       bool `yaml:"-"`
	// contains filtered or unexported fields
}

Syncthing represents the local syncthing process.

func Load

func Load(dev *model.Dev) (*Syncthing, error)

Load loads the syncthing object from the dev home folder

func New

func New(dev *model.Dev) (*Syncthing, error)

New constructs a new Syncthing.

func (*Syncthing) APICall

func (s *Syncthing) APICall(ctx context.Context, url, method string, code int, params map[string]string, local bool, body []byte, readBody bool, maxRetries int) ([]byte, error)

APICall calls the syncthing API and returns the parsed json or an error

func (*Syncthing) GetCompletion

func (s *Syncthing) GetCompletion(ctx context.Context, local bool, device string) (*Completion, error)

GetCompletion returns the syncthing completion

func (*Syncthing) GetFolderErrors

func (s *Syncthing) GetFolderErrors(ctx context.Context, local bool) error

GetFolderErrors returns the last folder errors

func (*Syncthing) GetInSynchronizationFile

func (s *Syncthing) GetInSynchronizationFile(ctx context.Context) string

GetInSynchronizationFile the files syncthing

func (*Syncthing) GetPullErrors

func (s *Syncthing) GetPullErrors(ctx context.Context, local bool) (int64, error)

GetPullErrors returns the syncthing current pull errors

func (*Syncthing) GetSyncthingStatus

func (s *Syncthing) GetSyncthingStatus(ctx context.Context, folder *Folder, local bool) (string, error)

GetSyncthingStatus returns the syncthing status

func (*Syncthing) GetSystemErrors

func (s *Syncthing) GetSystemErrors(ctx context.Context, local bool) (*SystemErrors, error)

GetSystemErrors returns the system errors identified by syncthing

func (*Syncthing) HardTerminate

func (s *Syncthing) HardTerminate() error

HardTerminate halts the background process, waits for 1s and kills the process if it is still running

func (*Syncthing) IdentifyReadinessIssue

func (s *Syncthing) IdentifyReadinessIssue(fs afero.Fs) error

IdentifyReadinessIssue attempts to identify the issue that is preventing syncthing from being ready

func (*Syncthing) IsAllOverwritten

func (s *Syncthing) IsAllOverwritten() bool

IsAllOverwritten checks if all overwrite operations has been completed

func (*Syncthing) IsHealthy

func (s *Syncthing) IsHealthy(ctx context.Context, local bool, max int) error

IsHealthy returns the syncthing error or nil

func (*Syncthing) IsLocalRunningOutOfSpace

func (s *Syncthing) IsLocalRunningOutOfSpace(ctx context.Context) bool

func (*Syncthing) Monitor

func (s *Syncthing) Monitor(ctx context.Context, disconnect chan error)

Monitor will send a message to disconnected if remote syncthing is disconnected for more than 10 seconds.

func (*Syncthing) MonitorStatus

func (s *Syncthing) MonitorStatus(ctx context.Context, disconnect chan error)

MonitorStatus will send a message to disconnected if there is a synchronization error

func (*Syncthing) Overwrite

func (s *Syncthing) Overwrite(ctx context.Context) error

Overwrite overwrites local changes to the remote syncthing

func (*Syncthing) Ping

func (s *Syncthing) Ping(ctx context.Context, local bool) bool

Ping checks if syncthing is available

func (*Syncthing) RegexMatchesLogs

func (s *Syncthing) RegexMatchesLogs(fs afero.Fs, regx *regexp.Regexp) bool

RegexMatchesLogs checks if a regex matches in the syncthing logs

func (*Syncthing) Restart

func (s *Syncthing) Restart(ctx context.Context) error

Restart restarts the syncthing process

func (*Syncthing) Run

func (s *Syncthing) Run() error

Run starts up a local syncthing process to serve files from.

func (*Syncthing) SaveConfig

func (s *Syncthing) SaveConfig(dev *model.Dev) error

SaveConfig saves the syncthing object in the dev home folder

func (*Syncthing) SoftTerminate

func (s *Syncthing) SoftTerminate() error

SoftTerminate halts the background process

func (*Syncthing) UpdateConfig

func (s *Syncthing) UpdateConfig() error

UpdateConfig updates the syncthing config file

func (*Syncthing) WaitForCompletion

func (s *Syncthing) WaitForCompletion(ctx context.Context, reporter chan float64) error

WaitForCompletion waits for the remote to be totally synched

func (*Syncthing) WaitForConnected

func (s *Syncthing) WaitForConnected(ctx context.Context) error

WaitForConnected waits for local and remote syncthing to be connected

func (*Syncthing) WaitForPing

func (s *Syncthing) WaitForPing(ctx context.Context, local bool, fs afero.Fs) error

WaitForPing waits for syncthing to be ready

func (*Syncthing) WaitForScanning

func (s *Syncthing) WaitForScanning(ctx context.Context, local bool) error

WaitForScanning waits for syncthing to finish initial scanning

type SystemError

type SystemError struct {
	Message string `json:"message"`
}

SystemError represents a system error in syncthing.

type SystemErrors

type SystemErrors struct {
	Errors []SystemError `json:"errors"`
}

SystemErrors represents a list of system errors

Jump to

Keyboard shortcuts

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