model

package
v0.12.17 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2016 License: MPL-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package model implements folder abstraction and file pulling mechanisms

Index

Constants

View Source
const (
	FolderIdle folderState = iota
	FolderScanning
	FolderSyncing
	FolderError
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection added in v0.12.0

type Connection struct {
	net.Conn
	protocol.Connection
	Type ConnectionType
}

type ConnectionInfo

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

func (ConnectionInfo) MarshalJSON

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

type ConnectionType added in v0.12.0

type ConnectionType int
const (
	ConnectionTypeDirectAccept ConnectionType = iota
	ConnectionTypeDirectDial
	ConnectionTypeRelayAccept
	ConnectionTypeRelayDial
)

func (ConnectionType) IsDirect added in v0.12.0

func (t ConnectionType) IsDirect() bool

func (ConnectionType) String added in v0.12.0

func (t ConnectionType) String() string

type IntermediateConnection added in v0.12.0

type IntermediateConnection struct {
	*tls.Conn
	Type ConnectionType
}

type Model

type Model struct {
	*suture.Supervisor
	// contains filtered or unexported fields
}

func NewModel

func NewModel(cfg *config.Wrapper, id protocol.DeviceID, deviceName, clientName, clientVersion string, ldb *db.Instance, protectedFiles []string) *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.

func (*Model) AddConnection

func (m *Model) AddConnection(conn Connection)

AddConnection adds a new peer connection to the model. An initial index will be sent to the connected peer, thereafter index updates whenever the local folder changes.

func (*Model) AddFolder

func (m *Model) AddFolder(cfg config.FolderConfiguration)

func (*Model) Availability

func (m *Model) Availability(folder, file string) []protocol.DeviceID

func (*Model) BringToFront

func (m *Model) BringToFront(folder, file string)

BringToFront bumps the given files priority in the job queue.

func (*Model) CheckFolderHealth

func (m *Model) CheckFolderHealth(id string) error

CheckFolderHealth checks the folder for common errors and returns the current folder error, or nil if the folder is healthy.

func (*Model) Close

func (m *Model) Close(device protocol.DeviceID, err error)

Close removes the peer from the model and closes the underlying connection if possible. Implements the protocol.Model interface.

func (*Model) ClusterConfig

func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterConfigMessage)

func (*Model) CommitConfiguration

func (m *Model) CommitConfiguration(from, to config.Configuration) bool

func (*Model) Completion

func (m *Model) Completion(device protocol.DeviceID, folder string) float64

Completion returns the completion status, in percent, for the given device and folder.

func (*Model) ConnectedTo

func (m *Model) ConnectedTo(deviceID protocol.DeviceID) bool

ConnectedTo returns true if we are connected to the named device.

func (*Model) ConnectionStats

func (m *Model) ConnectionStats() map[string]interface{}

ConnectionStats returns a map with connection statistics for each device.

func (*Model) CurrentFolderFile

func (m *Model) CurrentFolderFile(folder string, file string) (protocol.FileInfo, bool)

func (*Model) CurrentGlobalFile

func (m *Model) CurrentGlobalFile(folder string, file string) (protocol.FileInfo, bool)

func (*Model) CurrentLocalVersion

func (m *Model) CurrentLocalVersion(folder string) (int64, bool)

CurrentLocalVersion returns the change version for the given folder. This is guaranteed to increment if the contents of the local folder has changed.

func (*Model) DelayScan

func (m *Model) DelayScan(folder string, next time.Duration)

func (*Model) DeviceStatistics

func (m *Model) DeviceStatistics() map[string]stats.DeviceStatistics

DeviceStatistics returns statistics about each device

func (*Model) FolderStatistics

func (m *Model) FolderStatistics() map[string]stats.FolderStatistics

FolderStatistics returns statistics about each folder

func (*Model) GetIgnores

func (m *Model) GetIgnores(folder string) ([]string, []string, error)

func (*Model) GlobalDirectoryTree

func (m *Model) GlobalDirectoryTree(folder, prefix string, levels int, dirsonly bool) map[string]interface{}

func (*Model) GlobalSize

func (m *Model) GlobalSize(folder string) (nfiles, deleted int, bytes int64)

GlobalSize returns the number of files, deleted files and total bytes for all files in the global model.

func (*Model) Index

func (m *Model) Index(deviceID protocol.DeviceID, folder string, fs []protocol.FileInfo, flags uint32, options []protocol.Option)

Index is called when a new device is connected and we receive their full index. Implements the protocol.Model interface.

func (*Model) IndexUpdate

func (m *Model) IndexUpdate(deviceID protocol.DeviceID, folder string, fs []protocol.FileInfo, flags uint32, options []protocol.Option)

IndexUpdate is called for incremental updates to connected devices' indexes. Implements the protocol.Model interface.

func (*Model) IsPaused added in v0.12.0

func (m *Model) IsPaused(device protocol.DeviceID) bool

func (*Model) LocalSize

func (m *Model) LocalSize(folder string) (nfiles, deleted int, bytes int64)

LocalSize returns the number of files, deleted files and total bytes for all files in the local folder.

func (*Model) NeedFolderFiles

func (m *Model) NeedFolderFiles(folder string, page, perpage int) ([]db.FileInfoTruncated, []db.FileInfoTruncated, []db.FileInfoTruncated, int)

NeedFolderFiles returns paginated list of currently needed files in progress, queued, and to be queued on next puller iteration, as well as the total number of files currently needed.

func (*Model) NeedSize

func (m *Model) NeedSize(folder string) (nfiles int, bytes int64)

NeedSize returns the number and total size of currently needed files.

func (*Model) Override

func (m *Model) Override(folder string)

func (*Model) PauseDevice added in v0.12.0

func (m *Model) PauseDevice(device protocol.DeviceID)

func (*Model) RemoteLocalVersion

func (m *Model) RemoteLocalVersion(folder string) (int64, bool)

RemoteLocalVersion returns the change version for the given folder, as sent by remote peers. This is guaranteed to increment if the contents of the remote or global folder has changed.

func (*Model) RemoveFolder added in v0.12.3

func (m *Model) RemoveFolder(folder string)

func (*Model) Request

func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset int64, hash []byte, flags uint32, options []protocol.Option, buf []byte) error

Request returns the specified data segment by reading it from local disk. Implements the protocol.Model interface.

func (*Model) ResetFolder

func (m *Model) ResetFolder(folder string)

func (*Model) ResumeDevice added in v0.12.0

func (m *Model) ResumeDevice(device protocol.DeviceID)

func (*Model) ScanFolder

func (m *Model) ScanFolder(folder string) error

func (*Model) ScanFolderSubs

func (m *Model) ScanFolderSubs(folder string, subs []string) error

func (*Model) ScanFolders

func (m *Model) ScanFolders() map[string]error

func (*Model) SetIgnores

func (m *Model) SetIgnores(folder string, content []string) error

func (*Model) StartDeadlockDetector

func (m *Model) StartDeadlockDetector(timeout time.Duration)

StartDeadlockDetector starts a deadlock detector on the models locks which causes panics in case the locks cannot be acquired in the given timeout period.

func (*Model) StartFolderRO

func (m *Model) StartFolderRO(folder string)

StartFolderRO starts read only processing on the current model. When in read only mode the model will announce files to the cluster but not pull in any external changes.

func (*Model) StartFolderRW

func (m *Model) StartFolderRW(folder string)

StartFolderRW starts read/write processing on the current model. When in read/write mode the model will attempt to keep in sync with the cluster by pulling needed files from peer devices.

func (*Model) State

func (m *Model) State(folder string) (string, time.Time, error)

func (*Model) String

func (m *Model) String() string

func (*Model) VerifyConfiguration

func (m *Model) VerifyConfiguration(from, to config.Configuration) error

type ProgressEmitter

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

func NewProgressEmitter

func NewProgressEmitter(cfg *config.Wrapper) *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(from, 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()

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

func (*ProgressEmitter) Stop

func (t *ProgressEmitter) Stop()

Stop stops the emitter.

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

Jump to

Keyboard shortcuts

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