model

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2014 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const BlockSize = 128 * 1024
View Source
const (
	MAX_CHANGE_HISTORY = 4
)

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 int64
	Size   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 int64, size uint32, hash []byte) ([]byte, error)
	Statistics() protocol.Statistics
	Option(key string) string
}

type ConnectionInfo

type ConnectionInfo struct {
	protocol.Statistics
	Address       string
	ClientID      string
	ClientVersion 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)

func (File) String added in v0.4.2

func (f File) String() string

type FileQueue added in v0.4.2

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

func NewFileQueue added in v0.4.3

func NewFileQueue() *FileQueue

func (*FileQueue) Add added in v0.4.2

func (q *FileQueue) Add(name string, blocks []Block, monitor Monitor)

func (*FileQueue) Done added in v0.4.2

func (q *FileQueue) Done(file string, offset int64, data []byte)

func (*FileQueue) Get added in v0.4.2

func (q *FileQueue) Get(nodeID string) (queuedBlock, bool)

func (*FileQueue) Len added in v0.4.2

func (q *FileQueue) Len() int

func (*FileQueue) QueuedFiles added in v0.4.2

func (q *FileQueue) QueuedFiles() (files []string)

func (*FileQueue) RemoveAvailable added in v0.4.2

func (q *FileQueue) RemoveAvailable(toRemove string)

func (*FileQueue) SetAvailable added in v0.4.2

func (q *FileQueue) SetAvailable(file string, nodes []string)

type Model

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

func NewModel

func NewModel(dir string, maxChangeBw int) *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 underlying 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) LimitRate added in v0.4.2

func (m *Model) LimitRate(kbps int)

func (*Model) LocalAge added in v0.4.3

func (m *Model) LocalAge() float64

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. Must be called with the read lock held.

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 int64, 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, threads 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.

func (*Model) WhoHas added in v0.4.2

func (m *Model) WhoHas(name string) []string

type Monitor added in v0.4.2

type Monitor interface {
	FileBegins(<-chan content) error
	FileDone() error
}

Jump to

Keyboard shortcuts

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