model

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: MPL-2.0 Imports: 39 Imported by: 3

Documentation

Overview

Package model implements folder abstraction and file pulling mechanisms

Index

Constants

View Source
const (
	FolderIdle folderState = iota
	FolderScanning
	FolderScanWaiting
	FolderSyncWaiting
	FolderSyncPreparing
	FolderSyncing
	FolderCleaning
	FolderCleanWaiting
	FolderError
)

Variables

View Source
var (
	ErrFolderPaused     = errors.New("folder is paused")
	ErrFolderNotRunning = errors.New("folder is not running")
	ErrFolderMissing    = errors.New("no such folder")
)

Functions

This section is empty.

Types

type Availability added in v0.13.0

type Availability struct {
	ID            protocol.DeviceID `json:"id"`
	FromTemporary bool              `json:"fromTemporary"`
}

type ConnectionInfo

type ConnectionInfo struct {
	protocol.Statistics
	Connected     bool
	Paused        bool
	Address       string
	ClientVersion string
	Type          string
	Crypto        string
}

func (ConnectionInfo) MarshalJSON

func (info ConnectionInfo) MarshalJSON() ([]byte, error)

type FileError added in v0.14.44

type FileError struct {
	Path string `json:"path"`
	Err  string `json:"error"`
}

A []FileError is sent as part of an event and will be JSON serialized.

type FolderCompletion added in v0.14.5

type FolderCompletion struct {
	CompletionPct float64
	GlobalBytes   int64
	NeedBytes     int64
	GlobalItems   int
	NeedItems     int
	NeedDeletes   int
	Sequence      int64
}

func (FolderCompletion) Map added in v1.1.2

func (comp FolderCompletion) Map() map[string]interface{}

Map returns the members as a map, e.g. used in api to serialize as Json.

type FolderSummaryService added in v1.1.2

type FolderSummaryService interface {
	suture.Service
	Summary(folder string) (map[string]interface{}, error)
	OnEventRequest()
}

func NewFolderSummaryService added in v1.1.2

func NewFolderSummaryService(cfg config.Wrapper, m Model, id protocol.DeviceID, evLogger events.Logger) FolderSummaryService

type Holdable added in v0.14.11

type Holdable interface {
	Holders() string
}

type Model

type Model interface {
	suture.Service

	connections.Model

	ResetFolder(folder string)
	DelayScan(folder string, next time.Duration)
	ScanFolder(folder string) error
	ScanFolders() map[string]error
	ScanFolderSubdirs(folder string, subs []string) error
	State(folder string) (string, time.Time, error)
	FolderErrors(folder string) ([]FileError, error)
	WatchError(folder string) error
	Override(folder string)
	Revert(folder string)
	BringToFront(folder, file string)
	LoadIgnores(folder string) ([]string, []string, error)
	CurrentIgnores(folder string) ([]string, []string, error)
	SetIgnores(folder string, content []string) error

	GetFolderVersions(folder string) (map[string][]versioner.FileVersion, error)
	RestoreFolderVersions(folder string, versions map[string]time.Time) (map[string]error, error)

	DBSnapshot(folder string) (*db.Snapshot, error)
	NeedFolderFiles(folder string, page, perpage int) ([]db.FileInfoTruncated, []db.FileInfoTruncated, []db.FileInfoTruncated, error)
	RemoteNeedFolderFiles(folder string, device protocol.DeviceID, page, perpage int) ([]db.FileInfoTruncated, error)
	LocalChangedFolderFiles(folder string, page, perpage int) ([]db.FileInfoTruncated, error)
	FolderProgressBytesCompleted(folder string) int64

	CurrentFolderFile(folder string, file string) (protocol.FileInfo, bool, error)
	CurrentGlobalFile(folder string, file string) (protocol.FileInfo, bool, error)
	Availability(folder string, file protocol.FileInfo, block protocol.BlockInfo) ([]Availability, error)

	Completion(device protocol.DeviceID, folder string) (FolderCompletion, error)
	ConnectionStats() map[string]interface{}
	DeviceStatistics() (map[protocol.DeviceID]stats.DeviceStatistics, error)
	FolderStatistics() (map[string]stats.FolderStatistics, error)
	UsageReportingStats(report *contract.Report, version int, preview bool)

	PendingDevices() (map[protocol.DeviceID]db.ObservedDevice, error)
	PendingFolders(device protocol.DeviceID) (map[string]db.PendingFolder, error)

	StartDeadlockDetector(timeout time.Duration)
	GlobalDirectoryTree(folder, prefix string, levels int, dirsOnly bool) ([]*TreeEntry, error)
}

func NewModel

func NewModel(cfg config.Wrapper, id protocol.DeviceID, clientName, clientVersion string, ldb *db.Lowlevel, protectedFiles []string, evLogger events.Logger) Model

NewModel creates and starts a new model. The model starts in read-only mode, where it sends index information to connected peers and responds to requests for file data without altering the local folder in any way.

type ProgressEmitter

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

func NewProgressEmitter

func NewProgressEmitter(cfg config.Wrapper, evLogger events.Logger) *ProgressEmitter

NewProgressEmitter creates a new progress emitter which emits DownloadProgress events every interval.

func (*ProgressEmitter) BytesCompleted

func (t *ProgressEmitter) BytesCompleted(folder string) (bytes int64)

BytesCompleted returns the number of bytes completed in the given folder.

func (*ProgressEmitter) CommitConfiguration

func (t *ProgressEmitter) CommitConfiguration(_, to config.Configuration) bool

CommitConfiguration implements the config.Committer interface

func (*ProgressEmitter) Deregister

func (t *ProgressEmitter) Deregister(s *sharedPullerState)

Deregister a puller which will stop broadcasting pullers state.

func (*ProgressEmitter) Register

func (t *ProgressEmitter) Register(s *sharedPullerState)

Register a puller with the emitter which will start broadcasting pullers progress.

func (*ProgressEmitter) Serve

func (t *ProgressEmitter) Serve(ctx context.Context) error

serve starts the progress emitter which starts emitting DownloadProgress events as the progress happens.

func (*ProgressEmitter) String

func (t *ProgressEmitter) String() string

func (*ProgressEmitter) VerifyConfiguration

func (t *ProgressEmitter) VerifyConfiguration(from, to config.Configuration) error

VerifyConfiguration implements the config.Committer interface

type TreeEntry added in v1.14.0

type TreeEntry struct {
	Name     string                `json:"name"`
	ModTime  time.Time             `json:"modTime"`
	Size     int64                 `json:"size"`
	Type     protocol.FileInfoType `json:"type"`
	Children []*TreeEntry          `json:"children,omitempty"`
}

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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