piece

package
v0.0.0-...-5e8434a Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewManager

func NewManager(info torrent.Info, pieceRepo Repository) *manager

NewManager creates new piece manager

func NewRepoDb

func NewRepoDb(db *db.DB, info *torrent.Info) (*repoDb, error)

Types

type Manager

type Manager interface {
	//SetPeerPieces associates remote peer and pieces it possess
	SetPeerPieces(peerID string, pieces []bool)
	//PieceSize returns size of a piece corresponding to given index,
	//often last piece has different size than preceding pieces.
	PieceSize(index uint32) uint32
	ChunkSize() uint32
	//Get retrieves piece corresponding to given index
	Get(index uint32) (pieceData []byte, err error)
	//PieceDone saves piece in the storage
	PieceDone(index uint32, pieceData []byte) error
	//NextPiece checks if peers has more pieces to offer.
	// (false, 0) -> peer has no more pieces
	// (true, index) -> index is the next piece index to request
	NextPiece(peerID string) (hasNext bool, index uint32)
	//IsLastChunk checks if the whole piece was downloaded
	IsLastChunk(pieceIndex, offset uint32) bool
}

Manager manages file pieces, in bittorent protocol file is divided into pieces. Torrent file contains information about piece size and piece hash. Implementation of this interface must be thread safe.

type Repository

type Repository interface {
	Save(piece uint32, data []byte) error
	Get(piece uint32) ([]byte, error)
}

func NewRepo

func NewRepo(n uint32) Repository

Jump to

Keyboard shortcuts

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