]> Sergey Matveev's repositories - btrtrc.git/blobdiff - piece.go
cmd/btrtrc client
[btrtrc.git] / piece.go
index 607e2f883f475f4b8db5abf16a8c314591d23693..e08b2609690e385663c4df716d22d05ab3c7808b 100644 (file)
--- a/piece.go
+++ b/piece.go
@@ -5,23 +5,19 @@ import (
        "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
 
@@ -48,7 +44,7 @@ type Piece struct {
 }
 
 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 {
@@ -86,13 +82,13 @@ func (p *Piece) numDirtyChunks() chunkIndexType {
 
 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 {
@@ -196,7 +192,7 @@ func (p *Piece) torrentBeginOffset() int64 {
 }
 
 func (p *Piece) torrentEndOffset() int64 {
-       return p.torrentBeginOffset() + int64(p.t.usualPieceSize())
+       return p.torrentBeginOffset() + int64(p.length())
 }
 
 func (p *Piece) SetPriority(prio piecePriority) {
@@ -259,12 +255,3 @@ func (p *Piece) requestIndexOffset() RequestIndex {
 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]
-}