From: Matt Joiner Date: Wed, 20 Mar 2024 03:37:48 +0000 (+1100) Subject: Export PiecePriority X-Git-Tag: v1.56.0~41 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=42894ff02a018648b53ab73f8ed8d59169f54600;p=btrtrc.git Export PiecePriority It's used in some public methods already anyway, so it was a mistake. --- diff --git a/file.go b/file.go index ae802f13..a71055cf 100644 --- a/file.go +++ b/file.go @@ -18,7 +18,7 @@ type File struct { length int64 fi metainfo.FileInfo displayPath string - prio piecePriority + prio PiecePriority piecesRoot g.Option[[sha256.Size]byte] } @@ -180,7 +180,7 @@ func (f *File) NewReader() Reader { } // Sets the minimum priority for pieces in the File. -func (f *File) SetPriority(prio piecePriority) { +func (f *File) SetPriority(prio PiecePriority) { f.t.cl.lock() if prio != f.prio { f.prio = prio @@ -190,7 +190,7 @@ func (f *File) SetPriority(prio piecePriority) { } // Returns the priority per File.SetPriority. -func (f *File) Priority() (prio piecePriority) { +func (f *File) Priority() (prio PiecePriority) { f.t.cl.rLock() prio = f.prio f.t.cl.rUnlock() diff --git a/misc.go b/misc.go index 42c516f0..a76f216f 100644 --- a/misc.go +++ b/misc.go @@ -17,7 +17,7 @@ import ( type ( Request = types.Request ChunkSpec = types.ChunkSpec - piecePriority = types.PiecePriority + PiecePriority = types.PiecePriority ) const ( diff --git a/piece.go b/piece.go index 4eec6f28..3ca674d0 100644 --- a/piece.go +++ b/piece.go @@ -31,7 +31,7 @@ type Piece struct { storageCompletionOk bool publicPieceState PieceState - priority piecePriority + priority PiecePriority // Availability adjustment for this piece relative to len(Torrent.connsWithAllPieces). This is // incremented for any piece a peer has when a peer has a piece, Torrent.haveInfo is true, and // the Peer isn't recorded in Torrent.connsWithAllPieces. @@ -205,14 +205,14 @@ func (p *Piece) torrentEndOffset() int64 { return p.torrentBeginOffset() + int64(p.t.usualPieceSize()) } -func (p *Piece) SetPriority(prio piecePriority) { +func (p *Piece) SetPriority(prio PiecePriority) { p.t.cl.lock() defer p.t.cl.unlock() p.priority = prio p.t.updatePiecePriority(p.index, "Piece.SetPriority") } -func (p *Piece) purePriority() (ret piecePriority) { +func (p *Piece) purePriority() (ret PiecePriority) { for _, f := range p.files { ret.Raise(f.prio) } diff --git a/piecestate.go b/piecestate.go index 9e67907b..d41f38d9 100644 --- a/piecestate.go +++ b/piecestate.go @@ -6,7 +6,7 @@ import ( // The current state of a piece. type PieceState struct { - Priority piecePriority + Priority PiecePriority storage.Completion // The piece is being hashed, or is queued for hash. Deprecated: Use those fields instead. Checking bool diff --git a/requesting.go b/requesting.go index b48fc79f..af609356 100644 --- a/requesting.go +++ b/requesting.go @@ -99,9 +99,9 @@ func (p *desiredPeerRequests) lessByValue(leftRequest, rightRequest RequestIndex rightPiece := &p.pieceStates[rightPieceIndex] // Putting this first means we can steal requests from lesser-performing peers for our first few // new requests. - priority := func() piecePriority { + priority := func() PiecePriority { // Technically we would be happy with the cached priority here, except we don't actually - // cache it anymore, and Torrent.piecePriority just does another lookup of *Piece to resolve + // cache it anymore, and Torrent.PiecePriority just does another lookup of *Piece to resolve // the priority through Piece.purePriority, which is probably slower. leftPriority := leftPiece.Priority rightPriority := rightPiece.Priority