"sync"
"github.com/anacrolix/chansync"
- g "github.com/anacrolix/generics"
"github.com/anacrolix/missinggo/v2/bitmap"
"github.com/anacrolix/torrent/metainfo"
pp "github.com/anacrolix/torrent/peer_protocol"
"github.com/anacrolix/torrent/storage"
- infohash_v2 "github.com/anacrolix/torrent/types/infohash-v2"
)
type Piece struct {
- // The completed piece SHA1 hash, from the metainfo "pieces" field. Nil if the info is not V1
- // compatible.
- hash *metainfo.Hash
- hashV2 g.Option[infohash_v2.T]
- t *Torrent
- index pieceIndex
- files []*File
+ // The completed piece SHA1 hash, from the metainfo "pieces" field.
+ hash *metainfo.Hash
+ t *Torrent
+ index pieceIndex
+ files []*File
readerCond chansync.BroadcastCond
}
func (p *Piece) String() string {
- return fmt.Sprintf("%s/%d", p.t.canonicalShortInfohash().HexString(), p.index)
+ return fmt.Sprintf("%s/%d", p.t.infoHash.HexString(), p.index)
}
func (p *Piece) Info() metainfo.Piece {
func (p *Piece) unpendChunkIndex(i chunkIndexType) {
p.t.dirtyChunks.Add(p.requestIndexOffset() + i)
- p.t.updatePieceRequestOrderPiece(p.index)
+ p.t.updatePieceRequestOrder(p.index)
p.readerCond.Broadcast()
}
func (p *Piece) pendChunkIndex(i RequestIndex) {
p.t.dirtyChunks.Remove(p.requestIndexOffset() + i)
- p.t.updatePieceRequestOrderPiece(p.index)
+ p.t.updatePieceRequestOrder(p.index)
}
func (p *Piece) numChunks() chunkIndexType {
}
func (p *Piece) torrentEndOffset() int64 {
- return p.torrentBeginOffset() + int64(p.t.usualPieceSize())
+ return p.torrentBeginOffset() + int64(p.length())
}
func (p *Piece) SetPriority(prio piecePriority) {
func (p *Piece) availability() int {
return len(p.t.connsWithAllPieces) + p.relativeAvailability
}
-
-// For v2 torrents, files are aligned to pieces so there should always only be a single file for a
-// given piece.
-func (p *Piece) mustGetOnlyFile() *File {
- if len(p.files) != 1 {
- panic(len(p.files))
- }
- return p.files[0]
-}