]> Sergey Matveev's repositories - btrtrc.git/blob - storage/interface.go
Drop bradfitz/iter dependency (#605)
[btrtrc.git] / storage / interface.go
1 package storage
2
3 import (
4         "io"
5
6         "github.com/anacrolix/torrent/metainfo"
7 )
8
9 type ClientImplCloser interface {
10         ClientImpl
11         Close() error
12 }
13
14 // Represents data storage for an unspecified torrent.
15 type ClientImpl interface {
16         OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (TorrentImpl, error)
17 }
18
19 // Data storage bound to a torrent.
20 type TorrentImpl struct {
21         Piece func(p metainfo.Piece) PieceImpl
22         Close func() error
23         // Storages that share the same value, will provide a pointer to the same function.
24         Capacity *func() *int64
25 }
26
27 // Interacts with torrent piece data. Optional interfaces to implement include:
28 //   io.WriterTo, such as when a piece supports a more efficient way to write out incomplete chunks.
29 //   SelfHashing, such as when a piece supports a more efficient way to hash its contents.
30 type PieceImpl interface {
31         // These interfaces are not as strict as normally required. They can
32         // assume that the parameters are appropriate for the dimensions of the
33         // piece.
34         io.ReaderAt
35         io.WriterAt
36         // Called when the client believes the piece data will pass a hash check.
37         // The storage can move or mark the piece data as read-only as it sees
38         // fit.
39         MarkComplete() error
40         MarkNotComplete() error
41         // Returns true if the piece is complete.
42         Completion() Completion
43 }
44
45 type Completion struct {
46         Complete bool
47         Ok       bool
48 }
49
50 // Allows a storage backend to override hashing (i.e. if it can do it more efficiently than the torrent client can)
51 type SelfHashing interface {
52         SelfHash() (metainfo.Hash, error)
53 }