Documentation ¶
Index ¶
- type Cat
- func (c *Cat) Contains(hash *common.Sha1Hash) (*IndexRecordExport, error)
- func (c *Cat) FileComplete(hash *common.Sha1Hash) bool
- func (c *Cat) Get(hash *common.Sha1Hash) *IndexRecordExport
- func (c *Cat) GetChunkReader(hash *common.Sha1Hash, chunk int64) (*common.ChunkReader, error)
- func (c *Cat) Init() error
- func (c *Cat) ListFiles() ([]IndexRecordExport, error)
- func (c *Cat) MissingChunks(hash *common.Sha1Hash, maxCount int) []common.Range
- func (c *Cat) RegisterDownload(sizeInBytes uint64, chunkCount uint32, chunkSizeInBytes uint32, ...) (*IndexRecordExport, error)
- func (c *Cat) Rehash(hash *common.Sha1Hash) (*common.Sha1Hash, error)
- func (c *Cat) SaveChunk(hash *common.Sha1Hash, chunk uint16, data []byte) error
- func (c *Cat) ShareFile(path string) (*indexRecord, error)
- func (c *Cat) UnshareFile(hash *common.Sha1Hash) error
- type IndexRecordExport
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 (*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) 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 (*Cat) Init ¶
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 ¶
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 ¶
Rehash attempts to recalculate the hash for a given indexRecord. If it fails, a blank hash and an error are returned.
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.