]> Sergey Matveev's repositories - btrtrc.git/blobdiff - storage/interface.go
Fix UseSources panicking when sqlite storage is closed
[btrtrc.git] / storage / interface.go
index 869556f80a547265fad99ba61d919f77e57e59c1..9e8de06c8f55313370e938d386f234f45b22e3d3 100644 (file)
@@ -16,14 +16,23 @@ type ClientImpl interface {
        OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (TorrentImpl, error)
 }
 
+type TorrentCapacity *func() (cap int64, capped bool)
+
 // Data storage bound to a torrent.
-type TorrentImpl interface {
-       Piece(metainfo.Piece) PieceImpl
-       Close() error
+type TorrentImpl struct {
+       Piece func(p metainfo.Piece) PieceImpl
+       Close func() error
+       Flush func() error
+       // 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
 }
 
-// Interacts with torrent piece data. Optional interfaces to implement include io.WriterTo, such as
-// when a piece supports a more efficient way to write out incomplete chunks
+// Interacts with torrent piece data. Optional interfaces to implement include:
+//
+//     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.
 type PieceImpl interface {
        // These interfaces are not as strict as normally required. They can
        // assume that the parameters are appropriate for the dimensions of the
@@ -42,4 +51,10 @@ type PieceImpl interface {
 type Completion struct {
        Complete bool
        Ok       bool
+       Err      error
+}
+
+// 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)
 }