Documentation ¶
Overview ¶
Package model implements folder abstraction and file pulling mechanisms
Index ¶
- Constants
- Variables
- type ConnectionInfo
- type Model
- func (m *Model) AddConnection(rawConn io.Closer, protoConn protocol.Connection)
- func (m *Model) AddFolder(cfg config.FolderConfiguration)
- func (m *Model) Availability(folder, file string) []protocol.DeviceID
- func (m *Model) BringToFront(folder, file string)
- func (m *Model) CheckFolderHealth(id string) error
- func (m *Model) Close(device protocol.DeviceID, err error)
- func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterConfigMessage)
- func (m *Model) Completion(device protocol.DeviceID, folder string) float64
- func (m *Model) ConnectedTo(deviceID protocol.DeviceID) 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) CurrentLocalVersion(folder string) int64
- func (m *Model) DeviceStatistics() map[string]stats.DeviceStatistics
- func (m *Model) FolderStatistics() map[string]stats.FolderStatistics
- 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) (nfiles, deleted int, bytes int64)
- 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) (nfiles, deleted int, bytes int64)
- func (m *Model) NeedFolderFiles(folder string, max int) ([]db.FileInfoTruncated, []db.FileInfoTruncated, []db.FileInfoTruncated)
- func (m *Model) NeedSize(folder string) (nfiles int, bytes int64)
- func (m *Model) Override(folder string)
- func (m *Model) RemoteLocalVersion(folder string) int64
- func (m *Model) ReplaceLocal(folder string, fs []protocol.FileInfo)
- func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset int64, size int, ...) ([]byte, error)
- func (m *Model) ResetFolder(folder string) error
- func (m *Model) ScanFolder(folder string) error
- func (m *Model) ScanFolderSubs(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) StartFolderRO(folder string)
- func (m *Model) StartFolderRW(folder string)
- func (m *Model) State(folder string) (string, time.Time, error)
- func (m *Model) String() string
- type ProgressEmitter
- func (t *ProgressEmitter) BytesCompleted(folder string) (bytes int64)
- func (t *ProgressEmitter) Changed(cfg config.Configuration) error
- func (t *ProgressEmitter) Deregister(s *sharedPullerState)
- func (t *ProgressEmitter) Register(s *sharedPullerState)
- func (t *ProgressEmitter) Serve()
- func (t *ProgressEmitter) Stop()
Constants ¶
const ( FolderIdle folderState = iota FolderScanning FolderSyncing FolderError )
const (
IndexPerBlockSize = 40 // Each BlockInfo is approximately this big
)
How many files to send in each Index/IndexUpdate message.
Variables ¶
var (
SymlinkWarning = sync.Once{}
)
Functions ¶
This section is empty.
Types ¶
type ConnectionInfo ¶
type ConnectionInfo struct { protocol.Statistics Address string ClientVersion string }
func (ConnectionInfo) MarshalJSON ¶ added in v0.11.0
func (info ConnectionInfo) MarshalJSON() ([]byte, error)
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
func NewModel ¶
func NewModel(cfg *config.Wrapper, id protocol.DeviceID, deviceName, clientName, clientVersion string, ldb *leveldb.DB) *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(rawConn io.Closer, protoConn protocol.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 ¶ added in v0.10.0
func (m *Model) AddFolder(cfg config.FolderConfiguration)
func (*Model) Availability ¶ added in v0.10.28
func (*Model) BringToFront ¶ added in v0.10.15
Bump the given files priority in the job queue
func (*Model) CheckFolderHealth ¶ added in v0.11.0
Returns current folder error, or nil if the folder is healthy. Updates the Invalid field on the folder configuration struct, and emits a ConfigSaved event which causes a GUI refresh.
func (*Model) Close ¶
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) Completion ¶
Returns the completion status, in percent, for the given device and folder.
func (*Model) ConnectedTo ¶
ConnectedTo returns true if we are connected to the named device.
func (*Model) ConnectionStats ¶
ConnectionStats returns a map with connection statistics for each connected device.
func (*Model) CurrentFolderFile ¶ added in v0.10.0
func (*Model) CurrentGlobalFile ¶
func (*Model) CurrentLocalVersion ¶ added in v0.10.0
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) DeviceStatistics ¶ added in v0.10.0
func (m *Model) DeviceStatistics() map[string]stats.DeviceStatistics
Returns statistics about each device
func (*Model) FolderStatistics ¶ added in v0.10.12
func (m *Model) FolderStatistics() map[string]stats.FolderStatistics
Returns statistics about each folder
func (*Model) GlobalDirectoryTree ¶ added in v0.10.25
func (*Model) GlobalSize ¶
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) LocalSize ¶
LocalSize returns the number of files, deleted files and total bytes for all files in the local folder.
func (*Model) NeedFolderFiles ¶ added in v0.10.15
func (m *Model) NeedFolderFiles(folder string, max int) ([]db.FileInfoTruncated, []db.FileInfoTruncated, []db.FileInfoTruncated)
NeedFiles returns the list of currently needed files in progress, queued, and to be queued on next puller iteration. Also takes a soft cap which is only respected when adding files from the model rather than the runner queue.
func (*Model) RemoteLocalVersion ¶ added in v0.10.0
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) ReplaceLocal ¶
ReplaceLocal replaces the local folder index with the given list of files.
func (*Model) Request ¶
func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset int64, size int, hash []byte, flags uint32, options []protocol.Option) ([]byte, error)
Request returns the specified data segment by reading it from local disk. Implements the protocol.Model interface.
func (*Model) ResetFolder ¶ added in v0.11.0
func (*Model) ScanFolder ¶ added in v0.10.0
func (*Model) ScanFolderSubs ¶ added in v0.11.0
func (*Model) ScanFolders ¶ added in v0.10.0
func (*Model) StartDeadlockDetector ¶ added in v0.11.0
Starts deadlock detector on the models locks which causes panics in case the locks cannot be acquired in the given timeout period.
func (*Model) StartFolderRO ¶ added in v0.10.0
StartRO 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 ¶ added in v0.10.0
StartRW 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.
type ProgressEmitter ¶ added in v0.10.9
type ProgressEmitter struct {
// contains filtered or unexported fields
}
func NewProgressEmitter ¶ added in v0.10.9
func NewProgressEmitter(cfg *config.Wrapper) *ProgressEmitter
Creates a new progress emitter which emits DownloadProgress events every interval.
func (*ProgressEmitter) BytesCompleted ¶ added in v0.10.9
func (t *ProgressEmitter) BytesCompleted(folder string) (bytes int64)
Returns number of bytes completed in the given folder.
func (*ProgressEmitter) Changed ¶ added in v0.10.9
func (t *ProgressEmitter) Changed(cfg config.Configuration) error
Interface method to handle configuration changes
func (*ProgressEmitter) Deregister ¶ added in v0.10.9
func (t *ProgressEmitter) Deregister(s *sharedPullerState)
Deregister a puller which will stop boardcasting pullers state.
func (*ProgressEmitter) Register ¶ added in v0.10.9
func (t *ProgressEmitter) Register(s *sharedPullerState)
Register a puller with the emitter which will start broadcasting pullers progress.
func (*ProgressEmitter) Serve ¶ added in v0.10.9
func (t *ProgressEmitter) Serve()
Starts progress emitter which starts emitting DownloadProgress events as the progress happens.