Documentation ¶
Overview ¶
Package piece implements a data structure used for storing the actual contents of a torrent.
Index ¶
- Variables
- type Piece
- type Pieces
- func (ps *Pieces) AddData(index uint32, begin uint32, data []byte, peer uint32) (count uint32, complete bool, err error)
- func (ps *Pieces) All() bool
- func (ps *Pieces) Bitmap() bitmap.Bitmap
- func (ps *Pieces) Bytes() int64
- func (ps *Pieces) Complete(n uint32) bool
- func (ps *Pieces) Count() int
- func (ps *Pieces) Del()
- func (ps *Pieces) Expire(bytes int64, available []uint16, f func(index uint32)) int
- func (ps *Pieces) Finalise(index uint32, h hash.Hash) (done bool, peers []uint32, err error)
- func (ps *Pieces) Hole(index, offset uint32) (uint32, uint32)
- func (ps *Pieces) Length() int64
- func (ps *Pieces) MetadataComplete(psize uint32, length int64)
- func (ps *Pieces) Num() int
- func (ps *Pieces) PieceBitmap(n uint32) (int, bitmap.Bitmap)
- func (ps *Pieces) PieceEmpty(n uint32) bool
- func (ps *Pieces) PieceLength(index uint32) uint32
- func (ps *Pieces) PieceSize() uint32
- func (ps *Pieces) ReadAt(p []byte, off int64) (int, error)
- func (ps *Pieces) UpdateTime(index uint32) bool
Constants ¶
This section is empty.
Variables ¶
var ErrDeleted = errors.New("pieces deleted")
ErrDeleted indicates that the pieces structure has been deleted.
var ErrHashMismatch = errors.New("hash mismatch")
ErrHashMismatch is returned by AddData when hash validation fails.
Functions ¶
This section is empty.
Types ¶
type Piece ¶
type Piece struct {
// contains filtered or unexported fields
}
A Piece represents a single piece of a torrent. It can be in one of three states: incomplete, busy (hash is being computed), and complete.
func (*Piece) BusyOrComplete ¶
BusyOrComplete returns true if the piece is either busy or complete.
type Pieces ¶
type Pieces struct {
// contains filtered or unexported fields
}
Pieces represents the contents of a torrent.
func (*Pieces) AddData ¶
func (ps *Pieces) AddData(index uint32, begin uint32, data []byte, peer uint32) (count uint32, complete bool, err error)
AddData adds data to a torrent.
func (*Pieces) Expire ¶
Expire deletes pieces until the amount of space consumed is smaller than the value given by bytes. It calls f whenever it deletes a complete piece.
func (*Pieces) Finalise ¶
Finalise validates the hash of a piece and either marks it as complete or discards its data. This is a time-consuming operation, and should be called from its own goroutine.
func (*Pieces) MetadataComplete ¶
MetadataComplete must be called when a torrent's metadata becomes known.
func (*Pieces) PieceBitmap ¶
PieceBitmap returns a bitmap of complete pieces.
func (*Pieces) PieceEmpty ¶
PieceEmpty returns true if no data is available for a given piece.
func (*Pieces) PieceLength ¶
PieceLength returns the length in bytes of a given piece.
func (*Pieces) ReadAt ¶
ReadAt copies a range of bytes out of a torrent. It only returns data whose hash has been validated.
func (*Pieces) UpdateTime ¶
Update sets the last accessed time of a piece. It returns true if the piece is complete.