]> Sergey Matveev's repositories - btrtrc.git/blob - storage/interface.go
Allow Storage Backends to do their own Hashing (#518)
[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 interface {
21         Piece(metainfo.Piece) PieceImpl
22         Close() error
23 }
24
25 // Interacts with torrent piece data. Optional interfaces to implement include:
26 //   io.WriterTo, such as when a piece supports a more efficient way to write out incomplete chunks.
27 //   SelfHashing, such as when a piece supports a more efficient way to hash its contents.
28 type PieceImpl interface {
29         // These interfaces are not as strict as normally required. They can
30         // assume that the parameters are appropriate for the dimensions of the
31         // piece.
32         io.ReaderAt
33         io.WriterAt
34         // Called when the client believes the piece data will pass a hash check.
35         // The storage can move or mark the piece data as read-only as it sees
36         // fit.
37         MarkComplete() error
38         MarkNotComplete() error
39         // Returns true if the piece is complete.
40         Completion() Completion
41 }
42
43 type Completion struct {
44         Complete bool
45         Ok       bool
46 }
47
48 // Allows a storage backend to override hashing (i.e. if it can do it more efficiently than the torrent client can)
49 type SelfHashing interface {
50         SelfHash() (metainfo.Hash, error)
51 }