model

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2014 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const BlockSize = 128 * 1024
View Source
const (
	FlagDeleted = 1 << 12
)

Variables

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

Functions

This section is empty.

Types

type Block

type Block struct {
	Offset uint64
	Length uint32
	Hash   []byte
}

func BlockDiff

func BlockDiff(src, tgt []Block) (have, need []Block)

BlockDiff returns lists of common and missing (to transform src into tgt) blocks. Both block lists must have been created with the same block size.

func Blocks

func Blocks(r io.Reader, blocksize int) ([]Block, error)

Blocks returns the blockwise hash of the reader.

type ConnectionInfo

type ConnectionInfo struct {
	protocol.Statistics
	Address string
}

type File

type File struct {
	Name     string
	Flags    uint32
	Modified int64
	Blocks   []Block
}

func (File) Size

func (f File) Size() (bytes int)

type Model

type Model struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewModel

func NewModel(dir 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 repository in any way.

func (*Model) AddConnection

func (m *Model) AddConnection(conn io.ReadWriteCloser, nodeID string)

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 repository changes.

func (*Model) Close

func (m *Model) Close(node string, err error)

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

func (*Model) ConnectedTo

func (m *Model) ConnectedTo(nodeID string) bool

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

func (*Model) ConnectionStats

func (m *Model) ConnectionStats() map[string]ConnectionInfo

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

func (*Model) FilteredWalk

func (m *Model) FilteredWalk(followSymlinks bool) []File

Walk returns the list of files found in the local repository by scanning the file system. Files are blockwise hashed. Patterns marked in .stignore files are removed from the results.

func (*Model) Generation

func (m *Model) Generation() int64

Generation returns an opaque integer that is guaranteed to increment on every change to the local repository or global model.

func (*Model) GlobalSize

func (m *Model) GlobalSize() (files, deleted, bytes int)

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

func (*Model) InSyncSize

func (m *Model) InSyncSize() (files, bytes int)

InSyncSize returns the number and total byte size of the local files that are in sync with the global model.

func (*Model) Index

func (m *Model) Index(nodeID string, fs []protocol.FileInfo)

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

func (*Model) IndexUpdate

func (m *Model) IndexUpdate(nodeID string, fs []protocol.FileInfo)

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

func (*Model) LocalSize

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

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

func (*Model) NeedFiles

func (m *Model) NeedFiles() (files []File, bytes int)

NeedFiles returns the list of currently needed files and the total size.

func (*Model) ProtocolIndex

func (m *Model) ProtocolIndex() []protocol.FileInfo

ProtocolIndex returns the current local index in protocol data types.

func (*Model) ReplaceLocal

func (m *Model) ReplaceLocal(fs []File)

ReplaceLocal replaces the local repository index with the given list of files.

func (*Model) RepoID

func (m *Model) RepoID() string

RepoID returns a unique ID representing the current repository location.

func (*Model) Request

func (m *Model) Request(nodeID, name string, offset uint64, size uint32, hash []byte) ([]byte, error)

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

func (*Model) SeedLocal

func (m *Model) SeedLocal(fs []protocol.FileInfo)

SeedLocal replaces the local repository index with the given list of files, in protocol data types. Does not track deletes, should only be used to seed the local index from a cache file at startup.

func (*Model) StartRW

func (m *Model) StartRW(del bool, pfiles, preqs int)

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 nodes.

func (*Model) Trace

func (m *Model) Trace(t string)

Trace enables trace logging of the given facility. This is a debugging function; grep for m.trace.

func (*Model) Walk

func (m *Model) Walk(followSymlinks bool) (files []File, ignore map[string][]string)

Walk returns the list of files found in the local repository by scanning the file system. Files are blockwise hashed.

Jump to

Keyboard shortcuts

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