piece

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const BlockSize = 16 * 1024

BlockSize is the size of smallest piece data that we are going to request from peers.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Begin  uint32 // Offset in piece
	Length uint32 // Cannot exceed BlockSize. It's shorter for last block or if the next file is a padding file.
}

Block is part of a Piece that is specified in peerprotocol.Request messages.

type Piece

type Piece struct {
	Index   uint32            // index in torrent
	Length  uint32            // always equal to Info.PieceLength except last piece
	Data    filesection.Piece // the place to write downloaded bytes
	Hash    []byte
	Writing bool
	Done    bool
}

Piece of a torrent.

func NewPieces

func NewPieces(info *metainfo.Info, files []allocator.File) []Piece

NewPieces returns a slice of Pieces by mapping files to the pieces.

func (*Piece) CalculateBlocks added in v1.12.1

func (p *Piece) CalculateBlocks() []Block

func (*Piece) VerifyHash

func (p *Piece) VerifyHash(buf []byte, h hash.Hash) bool

VerifyHash returns true if hash of piece data in buffer `buf` matches the hash of Piece.

Jump to

Keyboard shortcuts

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