model

package
v0.4.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const BlockSize = 128 * 1024

Variables

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

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 Connection added in v0.4.1

type Connection interface {
	ID() string
	Index([]protocol.FileInfo)
	Request(name string, offset uint64, size uint32, hash []byte) ([]byte, error)
	Statistics() protocol.Statistics
}

type ConnectionInfo

type ConnectionInfo struct {
	protocol.Statistics
	Address string
}

type File

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

func (File) Equals added in v0.4.0

func (f File) Equals(o File) bool

func (File) NewerThan added in v0.4.0

func (f File) NewerThan(o File) bool

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(rawConn io.Closer, protoConn 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 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) 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. Change suppression is applied to files changing too often.

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