model

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2014 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package model implements folder abstraction and file pulling mechanisms

Index

Constants

View Source
const (
	FolderIdle folderState = iota
	FolderScanning
	FolderSyncing
	FolderCleaning
)
View Source
const (
	IndexPerBlockSize = 40 // Each BlockInfo is approximately this big

)

How many files to send in each Index/IndexUpdate message.

Variables

View Source
var (
	ErrNoSuchFile = errors.New("no such file")
	ErrInvalid    = errors.New("file is invalid")
)

Functions

This section is empty.

Types

type ConnectionInfo

type ConnectionInfo struct {
	protocol.Statistics
	Address       string
	ClientVersion string
}

type Model

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

func NewModel

func NewModel(cfg *config.ConfigWrapper, deviceName, clientName, clientVersion string, db *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) 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) Completion

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

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]ConnectionInfo

ConnectionStats returns a map with connection statistics for each connected device.

func (*Model) CurrentFolderFile added in v0.10.0

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

func (*Model) CurrentGlobalFile

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

func (*Model) CurrentLocalVersion added in v0.10.0

func (m *Model) CurrentLocalVersion(folder string) uint64

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) GetIgnores

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

func (*Model) GlobalSize

func (m *Model) GlobalSize(folder string) (files, 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)

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)

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

func (*Model) LocalSize

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

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

func (*Model) NeedFolderFilesLimited added in v0.10.0

func (m *Model) NeedFolderFilesLimited(folder string, maxFiles, maxBlocks int) []protocol.FileInfo

NeedFiles returns the list of currently needed files, stopping at maxFiles files or maxBlocks blocks. Limits <= 0 are ignored.

func (*Model) NeedSize

func (m *Model) NeedSize(folder string) (files 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) RemoteLocalVersion added in v0.10.0

func (m *Model) RemoteLocalVersion(folder string) uint64

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

func (m *Model) ReplaceLocal(folder string, fs []protocol.FileInfo)

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) ([]byte, error)

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

func (*Model) ScanFolder added in v0.10.0

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

func (*Model) ScanFolderSub added in v0.10.0

func (m *Model) ScanFolderSub(folder, sub string) error

func (*Model) ScanFolders added in v0.10.0

func (m *Model) ScanFolders()

func (*Model) SetIgnores

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

func (*Model) StartFolderRO added in v0.10.0

func (m *Model) StartFolderRO(folder string)

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

func (m *Model) StartFolderRW(folder string)

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.

func (*Model) State

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

func (*Model) String added in v0.10.0

func (m *Model) String() string

type Puller added in v0.10.0

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

func (*Puller) Serve added in v0.10.0

func (p *Puller) Serve()

Serve will run scans and pulls. It will return when Stop()ed or on a critical error.

func (*Puller) Stop added in v0.10.0

func (p *Puller) Stop()

func (*Puller) String added in v0.10.0

func (p *Puller) String() string

type Scanner added in v0.10.0

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

func (*Scanner) Serve added in v0.10.0

func (s *Scanner) Serve()

func (*Scanner) Stop added in v0.10.0

func (s *Scanner) Stop()

func (*Scanner) String added in v0.10.0

func (s *Scanner) String() string

Jump to

Keyboard shortcuts

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