catalogue

package
v0.0.0-...-b8f7ae2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cat

type Cat struct {
	DataDir             string
	DefaultDownloadsDir string
	// contains filtered or unexported fields
}

Cat is a wrapper around the on-disk catalogue data for Flu clients. There should only be one cat per physical computer, and a single process accessing the cat files at any time. A cat consists of an index file (index.json) and several progress files (each named after the sha1 hash of the files whose progress is being tracked). Most file-system access should be performed with a mutex lock. Public methods simply acquire the lock and then call private methods that assume the lock exists.

func NewCat

func NewCat(dir, downloadsDir string) (*Cat, error)

NewCat returns a Cat struct, initialized to the given data directory

func (*Cat) Contains

func (c *Cat) Contains(hash *common.Sha1Hash) (*IndexRecordExport, error)

Contains returns the IndexRecordExport of the file specified by the hash, or an error if the file cannot be accessed for any reason.

func (*Cat) FileComplete

func (c *Cat) FileComplete(hash *common.Sha1Hash) bool

func (*Cat) Get

func (c *Cat) Get(hash *common.Sha1Hash) *IndexRecordExport

Get is the same as contains, except that if the record does not exist it will panic.

func (*Cat) GetChunkReader

func (c *Cat) GetChunkReader(hash *common.Sha1Hash, chunk int64) (*common.ChunkReader, error)

func (*Cat) Init

func (c *Cat) Init() error

Init initializes or attempts to acquire an exclusive user-space lock on the on-disk catalogue data. Returns a descriptive error if unable to acquire a lock. This should be called before invoking any other methods on Cat. Note, this lock is different from a mutex. Our user-space lock indicates that the process is unique, not that this thread has exclusive access to some resource.

func (*Cat) ListFiles

func (c *Cat) ListFiles() ([]IndexRecordExport, error)

ListFiles lists the files that exist in the catalogue. Not all indexed files have been downloaded in their entirety. The result is a deep copy of the underlying catalogue data, so mutating it is okay.

func (*Cat) MissingChunks

func (c *Cat) MissingChunks(hash *common.Sha1Hash, maxCount int) []common.Range

MissingChunks returns a list of ranges of missing chunks for the given hash

func (*Cat) RegisterDownload

func (c *Cat) RegisterDownload(
	sizeInBytes uint64,
	chunkCount uint32,
	chunkSizeInBytes uint32,
	sha1Hash *common.Sha1Hash,
	filename string,
) (*IndexRecordExport, error)

RegisterDownload creates a record of the download in flu's index. This is identical to c.ShareFile except that the progress file will register an empty bitset.

func (*Cat) Rehash

func (c *Cat) Rehash(hash *common.Sha1Hash) (*common.Sha1Hash, error)

Rehash attempts to recalculate the hash for a given indexRecord. If it fails, a blank hash and an error are returned.

func (*Cat) SaveChunk

func (c *Cat) SaveChunk(hash *common.Sha1Hash, chunk uint16, data []byte) error

func (*Cat) ShareFile

func (c *Cat) ShareFile(path string) (*indexRecord, error)

ShareFile generates an IndexRecord for the given filepath (unless an identical file has already been shared) and refreshes the inderlying indexFile. Sharing a file assumes that the file has been downloaded completely.

func (*Cat) UnshareFile

func (c *Cat) UnshareFile(hash *common.Sha1Hash) error

UnshareFile immediately deletes all references to it from flu's index. Any transfers in progress will throw errors and stop. The actual file is not affected in any way.

type IndexRecordExport

type IndexRecordExport struct {
	FilePath    string
	SizeInBytes int64
	Sha1Hash    common.Sha1Hash
	Progress    bitset.Bitset
	ChunkSize   int
}

IndexRecordExport is a copy of an underlying indexRecord intended for read-only access. Manipulations should be performed via an appropriate catalogue method. Note that since this is a copy, once it is created, there is no guarantee that its state is an accurate reflection of the underlying object it represents. For strong guarantees of consistency, use the appropriate method on the catalogue.

Jump to

Keyboard shortcuts

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