2016-03-28 20:38:30 +11:00
|
|
|
package storage
|
2015-10-02 00:09:04 +10:00
|
|
|
|
2016-03-28 20:38:30 +11:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/anacrolix/torrent/metainfo"
|
|
|
|
)
|
2015-10-02 00:09:04 +10:00
|
|
|
|
2016-03-28 22:40:29 +11:00
|
|
|
// Represents data storage for an unspecified torrent.
|
2016-09-02 15:10:57 +10:00
|
|
|
type ClientImpl interface {
|
|
|
|
OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (TorrentImpl, error)
|
2016-10-25 20:00:09 +11:00
|
|
|
Close() error
|
2016-03-28 22:40:29 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
// Data storage bound to a torrent.
|
2016-09-02 15:10:57 +10:00
|
|
|
type TorrentImpl interface {
|
|
|
|
Piece(metainfo.Piece) PieceImpl
|
2016-03-28 22:40:29 +11:00
|
|
|
Close() error
|
2016-03-28 20:38:30 +11:00
|
|
|
}
|
|
|
|
|
2016-03-28 22:40:29 +11:00
|
|
|
// Interacts with torrent piece data.
|
2016-09-02 15:10:57 +10:00
|
|
|
type PieceImpl interface {
|
|
|
|
// These interfaces are not as strict as normally required. They can
|
2016-10-25 19:57:35 +11:00
|
|
|
// assume that the parameters are appropriate for the dimensions of the
|
2016-09-02 15:10:57 +10:00
|
|
|
// piece.
|
2015-10-04 00:22:46 +10:00
|
|
|
io.ReaderAt
|
|
|
|
io.WriterAt
|
2016-03-26 18:27:28 +11:00
|
|
|
// Called when the client believes the piece data will pass a hash check.
|
|
|
|
// The storage can move or mark the piece data as read-only as it sees
|
|
|
|
// fit.
|
2016-03-28 20:38:30 +11:00
|
|
|
MarkComplete() error
|
2016-09-02 15:10:57 +10:00
|
|
|
MarkNotComplete() error
|
2015-10-02 00:09:04 +10:00
|
|
|
// Returns true if the piece is complete.
|
2017-10-12 16:09:32 +11:00
|
|
|
Completion() Completion
|
|
|
|
}
|
|
|
|
|
|
|
|
type Completion struct {
|
|
|
|
Complete bool
|
|
|
|
Ok bool
|
2015-10-02 00:09:04 +10:00
|
|
|
}
|