It's an unnecessary complication for a storage implementer.
github.com/anacrolix/missinggo/perf v1.0.0
github.com/anacrolix/missinggo/v2 v2.5.2
github.com/anacrolix/multiless v0.1.1-0.20210529082330-de2f6cf29619
- github.com/anacrolix/squirrel v0.1.0
+ github.com/anacrolix/squirrel v0.1.1-0.20210914065657-81bc5ecdc43a
github.com/anacrolix/sync v0.4.0
github.com/anacrolix/tagflag v1.3.0
github.com/anacrolix/upnp v0.1.2-0.20200416075019-5e9378ed1425
github.com/anacrolix/multiless v0.1.1-0.20210529082330-de2f6cf29619/go.mod h1:TrCLEZfIDbMVfLoQt5tOoiBS/uq4y8+ojuEVVvTNPX4=
github.com/anacrolix/squirrel v0.1.0 h1:Zz7XUFUr2ozhsTvzwLdmrFpduoTHtBNTB/KZQ4Ivh00=
github.com/anacrolix/squirrel v0.1.0/go.mod h1:YzgVvikMdFD441oTWlNG189bpKabO9Sbf3uCSVgca04=
+github.com/anacrolix/squirrel v0.1.1-0.20210914065657-81bc5ecdc43a h1:8LAUQgDPqnzuF/WrGQzTY6i+bVO/FpA90Hi6jXA+2vQ=
+github.com/anacrolix/squirrel v0.1.1-0.20210914065657-81bc5ecdc43a/go.mod h1:YzgVvikMdFD441oTWlNG189bpKabO9Sbf3uCSVgca04=
github.com/anacrolix/stm v0.1.0/go.mod h1:ZKz7e7ERWvP0KgL7WXfRjBXHNRhlVRlbBQecqFtPq+A=
github.com/anacrolix/stm v0.1.1-0.20191106051447-e749ba3531cf/go.mod h1:zoVQRvSiGjGoTmbM0vSLIiaKjWtNPeTvXUSdJQA4hsg=
github.com/anacrolix/stm v0.2.0/go.mod h1:zoVQRvSiGjGoTmbM0vSLIiaKjWtNPeTvXUSdJQA4hsg=
"sync"
"github.com/anacrolix/multiless"
+ "github.com/anacrolix/torrent/storage"
pp "github.com/anacrolix/torrent/peer_protocol"
"github.com/anacrolix/torrent/types"
pieces := make([]filterPiece, 0, maxPieces)
ret = make([]requestablePiece, 0, maxPieces)
// Storage capacity left for this run, keyed by the storage capacity pointer on the storage
- // TorrentImpl.
- storageLeft := make(map[*func() *int64]*int64)
+ // TorrentImpl. A nil value means no capacity limit.
+ storageLeft := make(map[storage.TorrentCapacity]*int64)
for _t := range input.Torrents {
// TODO: We could do metainfo requests here.
t := &filterTorrent{
key := t.Capacity
if key != nil {
if _, ok := storageLeft[key]; !ok {
- storageLeft[key] = (*key)()
+ capacity, ok := (*key)()
+ if ok {
+ storageLeft[key] = &capacity
+ } else {
+ storageLeft[key] = nil
+ }
}
t.storageLeft = storageLeft[key]
}
package request_strategy
+import (
+ "github.com/anacrolix/torrent/storage"
+)
+
type Torrent struct {
Pieces []Piece
- Capacity *func() *int64
+ Capacity storage.TorrentCapacity
Peers []Peer // not closed.
// Some value that's unique and stable between runs. Could even use the infohash?
StableId uintptr
type Client struct{}
-var capacity int64
-
func (c Client) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (storage.TorrentImpl, error) {
- capFunc := func() *int64 {
- return &capacity
+ capFunc := func() (int64, bool) {
+ return 0, true
}
return storage.TorrentImpl{
Piece: func(piece metainfo.Piece) storage.PieceImpl {
}, nil
}
-func (c Client) capacity() *int64 {
- return &capacity
-}
-
type Piece struct{}
func (Piece) ReadAt(p []byte, off int64) (n int, err error) {
OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (TorrentImpl, error)
}
+type TorrentCapacity *func() (cap int64, capped bool)
+
// Data storage bound to a torrent.
type TorrentImpl struct {
Piece func(p metainfo.Piece) PieceImpl
Close func() error
- // Storages that share the same value, will provide a pointer to the same function.
- Capacity *func() *int64
+ // Storages that share the same space, will provide equal pointers. The function is called once
+ // to determine the storage for torrents sharing the same function pointer, and mutated in
+ // place.
+ Capacity TorrentCapacity
}
// Interacts with torrent piece data. Optional interfaces to implement include:
type client struct {
*squirrel.Cache
- capacity func() *int64
+ capacity func() (int64, bool)
}
func (c *client) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (storage.TorrentImpl, error) {