]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Storage cap wasn't passed to piece resource implementation
authorMatt Joiner <anacrolix@gmail.com>
Mon, 28 Apr 2025 00:42:00 +0000 (10:42 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 28 Apr 2025 00:42:00 +0000 (10:42 +1000)
This breaks the tests, because it was actually masking bad behaviour.

storage/piece-resource.go
test/transfer_test.go

index 9576fea5f77b5d76b2b757a553f84e241ed4de8a..404aec95d41e546e22c1bb73dafc0341f7e3f9ae 100644 (file)
@@ -28,7 +28,7 @@ type ResourcePiecesOpts struct {
        // Sized puts require being able to stream from a statement executed on another connection.
        // Without them, we buffer the entire read and then put that.
        NoSizedPuts bool
-       Capacity    *int64
+       Capacity    TorrentCapacity
 }
 
 func NewResourcePieces(p PieceProvider) ClientImpl {
@@ -60,7 +60,11 @@ func (s piecePerResource) OpenTorrent(
                s,
                make([]sync.RWMutex, info.NumPieces()),
        }
-       return TorrentImpl{PieceWithHash: t.Piece, Close: t.Close}, nil
+       return TorrentImpl{
+               PieceWithHash: t.Piece,
+               Close:         t.Close,
+               Capacity:      s.opts.Capacity,
+       }, nil
 }
 
 func (s piecePerResourceTorrentImpl) Piece(p metainfo.Piece, pieceHash g.Option[[]byte]) PieceImpl {
index 501872fd8fb642971aedd1134ce91f0df16b4574..6d3e460ba4b8291494df49b1ff2ffbc7ec6ce220 100644 (file)
@@ -31,11 +31,15 @@ func newFileCacheClientStorageFactory(ps fileCacheClientStorageFactoryParams) St
                if err != nil {
                        panic(err)
                }
-               var sharedCapacity *int64
+               var capFuncPtr storage.TorrentCapacity
                if ps.SetCapacity {
-                       sharedCapacity = &ps.Capacity
                        fc.SetCapacity(ps.Capacity)
+                       f := func() (cap int64, capped bool) {
+                               return ps.Capacity, ps.SetCapacity
+                       }
+                       capFuncPtr = &f
                }
+
                return struct {
                        storage.ClientImpl
                        io.Closer
@@ -43,7 +47,7 @@ func newFileCacheClientStorageFactory(ps fileCacheClientStorageFactoryParams) St
                        storage.NewResourcePiecesOpts(
                                fc.AsResourceProvider(),
                                storage.ResourcePiecesOpts{
-                                       Capacity: sharedCapacity,
+                                       Capacity: capFuncPtr,
                                }),
                        io.NopCloser(nil),
                }