Documentation ¶
Overview ¶
Package model implements folder abstraction and file pulling mechanisms
Index ¶
- Constants
- Variables
- type Availability
- type ConnectionInfo
- type FileError
- type FolderCompletion
- type Holdable
- type Model
- func (m *Model) AddConnection(conn connections.Connection, hello protocol.HelloResult)
- func (m *Model) AddFolder(cfg config.FolderConfiguration)
- func (m *Model) Availability(folder string, file protocol.FileInfo, block protocol.BlockInfo) []Availability
- func (m *Model) BringToFront(folder, file string)
- func (m *Model) Closed(conn protocol.Connection, err error)
- func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterConfig)
- func (m *Model) CommitConfiguration(from, to config.Configuration) bool
- func (m *Model) Completion(device protocol.DeviceID, folder string) FolderCompletion
- func (m *Model) Connection(deviceID protocol.DeviceID) (connections.Connection, bool)
- func (m *Model) ConnectionStats() map[string]interface{}
- func (m *Model) CurrentFolderFile(folder string, file string) (protocol.FileInfo, bool)
- func (m *Model) CurrentGlobalFile(folder string, file string) (protocol.FileInfo, bool)
- func (m *Model) CurrentSequence(folder string) (int64, bool)
- func (m *Model) DelayScan(folder string, next time.Duration)
- func (m *Model) DeviceStatistics() map[string]stats.DeviceStatistics
- func (m *Model) DownloadProgress(device protocol.DeviceID, folder string, ...)
- func (m *Model) FolderStatistics() map[string]stats.FolderStatistics
- func (m *Model) GetFolderVersions(folder string) (map[string][]versioner.FileVersion, error)
- func (m *Model) GetHello(id protocol.DeviceID) protocol.HelloIntf
- func (m *Model) GetIgnores(folder string) ([]string, []string, error)
- func (m *Model) GlobalDirectoryTree(folder, prefix string, levels int, dirsonly bool) map[string]interface{}
- func (m *Model) GlobalSize(folder string) db.Counts
- func (m *Model) Index(deviceID protocol.DeviceID, folder string, fs []protocol.FileInfo)
- func (m *Model) IndexUpdate(deviceID protocol.DeviceID, folder string, fs []protocol.FileInfo)
- func (m *Model) LocalSize(folder string) db.Counts
- func (m *Model) NeedFolderFiles(folder string, page, perpage int) ([]db.FileInfoTruncated, []db.FileInfoTruncated, []db.FileInfoTruncated)
- func (m *Model) NeedSize(folder string) db.Counts
- func (m *Model) OnHello(remoteID protocol.DeviceID, addr net.Addr, hello protocol.HelloResult) error
- func (m *Model) Override(folder string)
- func (m *Model) PullErrors(folder string) ([]FileError, error)
- func (m *Model) RemoteNeedFolderFiles(device protocol.DeviceID, folder string, page, perpage int) ([]db.FileInfoTruncated, error)
- func (m *Model) RemoteSequence(folder string) (int64, bool)
- func (m *Model) RemoveFolder(cfg config.FolderConfiguration)
- func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset int64, hash []byte, ...) error
- func (m *Model) ResetFolder(folder string)
- func (m *Model) RestartFolder(from, to config.FolderConfiguration)
- func (m *Model) RestoreFolderVersions(folder string, versions map[string]time.Time) (map[string]string, error)
- func (m *Model) ScanFolder(folder string) error
- func (m *Model) ScanFolderSubdirs(folder string, subs []string) error
- func (m *Model) ScanFolders() map[string]error
- func (m *Model) SetIgnores(folder string, content []string) error
- func (m *Model) StartDeadlockDetector(timeout time.Duration)
- func (m *Model) StartFolder(folder string)
- func (m *Model) State(folder string) (string, time.Time, error)
- func (m *Model) String() string
- func (m *Model) UsageReportingStats(version int, preview bool) map[string]interface{}
- func (m *Model) VerifyConfiguration(from, to config.Configuration) error
- func (m *Model) WatchError(folder string) error
- type ProgressEmitter
- func (t *ProgressEmitter) BytesCompleted(folder string) (bytes int64)
- func (t *ProgressEmitter) CommitConfiguration(from, to config.Configuration) bool
- func (t *ProgressEmitter) Deregister(s *sharedPullerState)
- func (t *ProgressEmitter) Register(s *sharedPullerState)
- func (t *ProgressEmitter) Serve()
- func (t *ProgressEmitter) Stop()
- func (t *ProgressEmitter) String() string
- func (t *ProgressEmitter) VerifyConfiguration(from, to config.Configuration) error
Constants ¶
const ( FolderIdle folderState = iota FolderScanning FolderSyncing FolderError )
Variables ¶
var (
ErrFolderPaused = errors.New("folder is paused")
)
Functions ¶
This section is empty.
Types ¶
type Availability ¶ added in v0.13.0
type ConnectionInfo ¶
type ConnectionInfo struct { protocol.Statistics Connected bool Paused bool Address string ClientVersion string Type string }
func (ConnectionInfo) MarshalJSON ¶
func (info ConnectionInfo) MarshalJSON() ([]byte, error)
type FileError ¶ added in v0.14.44
A []FileError is sent as part of an event and will be JSON serialized.
type FolderCompletion ¶ added in v0.14.5
type Model ¶
type Model struct { *suture.Supervisor // contains filtered or unexported fields }
func NewModel ¶
func NewModel(cfg *config.Wrapper, id protocol.DeviceID, 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 connections.Connection, hello protocol.HelloResult)
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 (*Model) BringToFront ¶
BringToFront bumps the given files priority in the job queue.
func (*Model) Closed ¶ added in v0.14.4
func (m *Model) Closed(conn protocol.Connection, err error)
Closed is called when a connection has been closed
func (*Model) ClusterConfig ¶
func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterConfig)
func (*Model) CommitConfiguration ¶
func (m *Model) CommitConfiguration(from, to config.Configuration) bool
func (*Model) Completion ¶
func (m *Model) Completion(device protocol.DeviceID, folder string) FolderCompletion
Completion returns the completion status, in percent, for the given device and folder.
func (*Model) Connection ¶ added in v0.14.41
func (m *Model) Connection(deviceID protocol.DeviceID) (connections.Connection, bool)
Connection returns the current connection for device, and a boolean whether a connection was found.
func (*Model) ConnectionStats ¶
ConnectionStats returns a map with connection statistics for each device.
func (*Model) CurrentFolderFile ¶
func (*Model) CurrentGlobalFile ¶
func (*Model) CurrentSequence ¶ added in v0.14.4
CurrentSequence returns the change version for the given folder. This is guaranteed to increment if the contents of the local folder has changed.
func (*Model) DeviceStatistics ¶
func (m *Model) DeviceStatistics() map[string]stats.DeviceStatistics
DeviceStatistics returns statistics about each device
func (*Model) DownloadProgress ¶ added in v0.13.0
func (*Model) FolderStatistics ¶
func (m *Model) FolderStatistics() map[string]stats.FolderStatistics
FolderStatistics returns statistics about each folder
func (*Model) GetFolderVersions ¶ added in v0.14.44
func (*Model) GetHello ¶ added in v0.13.0
GetHello is called when we are about to connect to some remote device.
func (*Model) GlobalDirectoryTree ¶
func (*Model) GlobalSize ¶
GlobalSize returns the number of files, deleted files and total bytes for all files in the global model.
func (*Model) Index ¶
Index is called when a new device is connected and we receive their full index. Implements the protocol.Model interface.
func (*Model) IndexUpdate ¶
IndexUpdate is called for incremental updates to connected devices' indexes. Implements the protocol.Model interface.
func (*Model) LocalSize ¶
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)
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) OnHello ¶ added in v0.13.0
func (m *Model) OnHello(remoteID protocol.DeviceID, addr net.Addr, hello protocol.HelloResult) error
OnHello is called when an device connects to us. This allows us to extract some information from the Hello message and add it to a list of known devices ahead of any checks.
func (*Model) PullErrors ¶ added in v0.14.44
func (*Model) RemoteNeedFolderFiles ¶ added in v0.14.43
func (m *Model) RemoteNeedFolderFiles(device protocol.DeviceID, folder string, page, perpage int) ([]db.FileInfoTruncated, error)
RemoteNeedFolderFiles 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) RemoteSequence ¶ added in v0.14.4
RemoteSequence 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(cfg config.FolderConfiguration)
func (*Model) Request ¶
func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset int64, hash []byte, weakHash uint32, fromTemporary bool, buf []byte) error
Request returns the specified data segment by reading it from local disk. Implements the protocol.Model interface.
func (*Model) ResetFolder ¶
func (*Model) RestartFolder ¶ added in v0.14.4
func (m *Model) RestartFolder(from, to config.FolderConfiguration)
func (*Model) RestoreFolderVersions ¶ added in v0.14.44
func (*Model) ScanFolder ¶
func (*Model) ScanFolderSubdirs ¶ added in v0.13.10
func (*Model) ScanFolders ¶
func (*Model) StartDeadlockDetector ¶
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) StartFolder ¶ added in v0.13.0
StartFolder constructs the folder service and starts it.
func (*Model) UsageReportingStats ¶ added in v0.14.40
func (*Model) VerifyConfiguration ¶
func (m *Model) VerifyConfiguration(from, to config.Configuration) error
func (*Model) WatchError ¶ added in v0.14.45
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) String ¶
func (t *ProgressEmitter) String() string
func (*ProgressEmitter) VerifyConfiguration ¶
func (t *ProgressEmitter) VerifyConfiguration(from, to config.Configuration) error
VerifyConfiguration implements the config.Committer interface