]> Sergey Matveev's repositories - btrtrc.git/blob - storage/interface.go
Rework storage.TorrentImpl to support shared capacity key
[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(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 io.WriterTo, such as
28 // when a piece supports a more efficient way to write out incomplete chunks
29 type PieceImpl interface {
30         // These interfaces are not as strict as normally required. They can
31         // assume that the parameters are appropriate for the dimensions of the
32         // piece.
33         io.ReaderAt
34         io.WriterAt
35         // Called when the client believes the piece data will pass a hash check.
36         // The storage can move or mark the piece data as read-only as it sees
37         // fit.
38         MarkComplete() error
39         MarkNotComplete() error
40         // Returns true if the piece is complete.
41         Completion() Completion
42 }
43
44 type Completion struct {
45         Complete bool
46         Ok       bool
47 }