2016-03-28 17:38:30 +08:00
|
|
|
package storage
|
2015-10-01 22:09:04 +08:00
|
|
|
|
2016-03-28 17:38:30 +08:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/anacrolix/torrent/metainfo"
|
|
|
|
)
|
2015-10-01 22:09:04 +08:00
|
|
|
|
2020-02-21 11:12:44 +08:00
|
|
|
type ClientImplCloser interface {
|
|
|
|
ClientImpl
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
2016-03-28 19:40:29 +08:00
|
|
|
// Represents data storage for an unspecified torrent.
|
2016-09-02 13:10:57 +08:00
|
|
|
type ClientImpl interface {
|
|
|
|
OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (TorrentImpl, error)
|
2016-03-28 19:40:29 +08:00
|
|
|
}
|
|
|
|
|
2021-09-15 08:30:37 +08:00
|
|
|
type TorrentCapacity *func() (cap int64, capped bool)
|
|
|
|
|
2016-03-28 19:40:29 +08:00
|
|
|
// Data storage bound to a torrent.
|
2021-05-09 21:40:44 +08:00
|
|
|
type TorrentImpl struct {
|
2021-05-24 16:06:42 +08:00
|
|
|
Piece func(p metainfo.Piece) PieceImpl
|
2021-05-09 21:40:44 +08:00
|
|
|
Close func() error
|
2022-07-07 13:46:27 +08:00
|
|
|
Flush func() error
|
2021-09-15 08:30:37 +08:00
|
|
|
// 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
|
2016-03-28 17:38:30 +08:00
|
|
|
}
|
|
|
|
|
2021-06-08 13:45:35 +08:00
|
|
|
// Interacts with torrent piece data. Optional interfaces to implement include:
|
2022-12-05 14:49:27 +08:00
|
|
|
//
|
|
|
|
// io.WriterTo, such as when a piece supports a more efficient way to write out incomplete chunks.
|
|
|
|
// SelfHashing, such as when a piece supports a more efficient way to hash its contents.
|
2016-09-02 13:10:57 +08:00
|
|
|
type PieceImpl interface {
|
|
|
|
// These interfaces are not as strict as normally required. They can
|
2016-10-25 16:57:35 +08:00
|
|
|
// assume that the parameters are appropriate for the dimensions of the
|
2016-09-02 13:10:57 +08:00
|
|
|
// piece.
|
2015-10-03 22:22:46 +08:00
|
|
|
io.ReaderAt
|
|
|
|
io.WriterAt
|
2016-03-26 15:27:28 +08:00
|
|
|
// Called when the client believes the piece data will pass a hash check.
|
|
|
|
// The storage can move or mark the piece data as read-only as it sees
|
|
|
|
// fit.
|
2016-03-28 17:38:30 +08:00
|
|
|
MarkComplete() error
|
2016-09-02 13:10:57 +08:00
|
|
|
MarkNotComplete() error
|
2015-10-01 22:09:04 +08:00
|
|
|
// Returns true if the piece is complete.
|
2017-10-12 13:09:32 +08:00
|
|
|
Completion() Completion
|
|
|
|
}
|
|
|
|
|
|
|
|
type Completion struct {
|
|
|
|
Complete bool
|
|
|
|
Ok bool
|
2015-10-01 22:09:04 +08:00
|
|
|
}
|
2021-06-08 13:45:35 +08:00
|
|
|
|
|
|
|
// Allows a storage backend to override hashing (i.e. if it can do it more efficiently than the torrent client can)
|
|
|
|
type SelfHashing interface {
|
|
|
|
SelfHash() (metainfo.Hash, error)
|
|
|
|
}
|