fileinfo

package
v0.0.0-...-8cd3384 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ERR_FILEINFO_ASSEMBLE_BLOCKS = errors.New("ERR_FILEINFO_ASSEMBLE_BLOCKS")
View Source
var ERR_FILEINFO_ASSEMBLE_BLOCKS__ALREADY_EXISTS = errors.New(
	"ERR_FILEINFO_ASSEMBLE_BLOCKS__ALREADY_EXISTS")
View Source
var ERR_FILEINFO_READ_DOWNLOADED_DATA = errors.New("ERR_FILEINFO_READ_DOWNLOADED_DATA")

Functions

func DefaultFinalizeFunc

func DefaultFinalizeFunc(fileInfo *FileInfo) error

Finalize is called when all self.Pieces are done downloading. It is called from the PIECE msg handler of the last PIECE msg we receive. It does the following:

  • Assemble all downloaded blocks (in 'self.DownloadedBlocksDir') to 'self.FinalDownloadDir'
  • Enters 'seeding' state

Types

type FileInfo

type FileInfo struct {
	DownloadedBlocksDir string
	// TODO For now, this is only accommodating for single-file torrents
	FinalDownloadDir string
	IsSeeding        bool
	Pieces           piece.SafePieces

	FinalizeFunc FinalizeFunc
	// contains filtered or unexported fields
}

For simplicity, we can limit one peer to one torrent

since the AnnounceResponse gives me back specific peers for a specific
torrent, we can couple a peer with a torrent cleanly

func NewFileInfo

func NewFileInfo(
	totalPieces int,
	pieceLength int64,
	blockLength int,
	finalDownloadDir string,
	downloadedBlocksDir string,
	torrentInfo *metainfo.Info,
	finalizeFunc FinalizeFunc,
	isSeeding bool,
) (*FileInfo, error)

NewFileInfo takes 'totalPieces' and 'pieceLength' and constructs blocks and pieces out of it XXX We're NOT allocating empty bytes for each block: this will be very wasteful: we will just write directly to disk

func NewFileInfoFilledWithRandomData

func NewFileInfoFilledWithRandomData(
	totalPieces int,
	pieceLength int64,
	blockLength int,
	finalDownloadDir string,
	downloadedBlocksDir string,
	torrentInfo *metainfo.Info,
	finalizeFunc FinalizeFunc,
	isSeeding bool,
) (*FileInfo, error)

func (*FileInfo) DeleteBlocksDir

func (self *FileInfo) DeleteBlocksDir()

func (*FileInfo) DeleteFinalDownloadDir

func (self *FileInfo) DeleteFinalDownloadDir()

func (*FileInfo) GetBlock

func (self *FileInfo) GetBlock(
	pieceIdx int,
	blockBegin uint32,
	blockLength uint32,
	isSeeding bool,
) (*piece.Block, error)

func (*FileInfo) SaveBlock

func (self *FileInfo) SaveBlock(targetBlock *piece.Block) error

type FinalizeFunc

type FinalizeFunc func(*FileInfo) error

Jump to

Keyboard shortcuts

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