6 g "github.com/anacrolix/generics"
8 "github.com/anacrolix/torrent/metainfo"
11 type ClientImplCloser interface {
16 // Represents data storage for an unspecified torrent.
17 type ClientImpl interface {
18 OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (TorrentImpl, error)
21 type TorrentCapacity *func() (cap int64, capped bool)
23 // Data storage bound to a torrent.
24 type TorrentImpl struct {
25 // v2 infos might not have the piece hash available even if we have the info. The
26 // metainfo.Piece.Hash method was removed to enforce this.
27 Piece func(p metainfo.Piece) PieceImpl
28 // Preferred over PieceWithHash. Called with the piece hash if it's available.
29 PieceWithHash func(p metainfo.Piece, pieceHash g.Option[[]byte]) PieceImpl
32 // Storages that share the same space, will provide equal pointers. The function is called once
33 // to determine the storage for torrents sharing the same function pointer, and mutated in
35 Capacity TorrentCapacity
38 // Interacts with torrent piece data. Optional interfaces to implement include:
40 // io.WriterTo, such as when a piece supports a more efficient way to write out incomplete chunks.
41 // SelfHashing, such as when a piece supports a more efficient way to hash its contents.
42 type PieceImpl interface {
43 // These interfaces are not as strict as normally required. They can
44 // assume that the parameters are appropriate for the dimensions of the
48 // Called when the client believes the piece data will pass a hash check.
49 // The storage can move or mark the piece data as read-only as it sees
52 MarkNotComplete() error
53 // Returns true if the piece is complete.
54 Completion() Completion
57 type Completion struct {
63 // Allows a storage backend to override hashing (i.e. if it can do it more efficiently than the torrent client can)
64 type SelfHashing interface {
65 SelfHash() (metainfo.Hash, error)