storage

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyWritten = errors.New("storage: trying to write at already written block")
View Source
var ErrNotReadyForVerification = errors.New("storage: not all piece's blocks are written")
View Source
var ErrReadNonVerified = errors.New("storage: trying to read non verified piece")

Functions

This section is empty.

Types

type FileStorage

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

FileStorage is a file-based storage for torrent data

func (*FileStorage) HashPiece

func (s *FileStorage) HashPiece(pieceIndex, len int) (correct bool)

HashPiece hashes `pieceIndex` whose length is `len` and returns if the hash was the expected.

func (*FileStorage) ReadAt

func (s *FileStorage) ReadAt(b []byte, off int64) (n int, err error)

Only returns EOF at the end of the torrent. Premature EOF is ErrUnexpectedEOF.

func (*FileStorage) ReadBlock

func (s *FileStorage) ReadBlock(b []byte, off int64) (n int, err error)

ReadBlock is like ReadAt but fails if the piece to be read is not verified

func (*FileStorage) WriteAt

func (s *FileStorage) WriteAt(p []byte, off int64) (n int, err error)

func (*FileStorage) WriteBlock

func (s *FileStorage) WriteBlock(p []byte, off int64) (n int, err error)

WriteBlock behaves like WriteAt but it fails if another write has occured at the same offset

type Open

type Open func(mi *metainfo.MetaInfo, baseDir string, blocks []int, logger *log.Logger) (s Storage, seed bool)

Open returns a Storage object

type Storage

type Storage interface {
	ReadBlock(b []byte, off int64) (n int, err error)
	WriteBlock(b []byte, off int64) (n int, err error)
	HashPiece(pieceIndex int, len int) (correct bool)
}

Storage is the interface every storage should adhere to

func OpenFileStorage

func OpenFileStorage(mi *metainfo.MetaInfo, baseDir string, blocks []int, logger *log.Logger) (s Storage, seed bool)

OpenFileStorage initializes the storage.`blocks` is a slice containing how many blocks each piece has. if returns true it means we are ready for seeding

Jump to

Keyboard shortcuts

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