1
// Copyright (c) 2016-2019 Uber Technologies, Inc.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
20
"github.com/uber/kraken/core"
22
"github.com/willf/bitset"
25
// ErrNotFound occurs when TorrentArchive cannot found a torrent.
26
var ErrNotFound = errors.New("torrent not found")
28
// ErrPieceComplete occurs when Torrent cannot write a piece because it is already
30
var ErrPieceComplete = errors.New("piece is already complete")
32
// PieceReader defines operations for lazy piece reading.
33
type PieceReader interface {
38
// Torrent represents a read/write interface for a torrent
39
type Torrent interface {
44
PieceLength(piece int) int64
45
MaxPieceLength() int64
46
InfoHash() core.InfoHash
48
BytesDownloaded() int64
49
Bitfield() *bitset.BitSet
52
HasPiece(piece int) bool
55
WritePiece(src PieceReader, piece int) error
56
GetPieceReader(piece int) (PieceReader, error)
59
// TorrentArchive creates and open torrent file
60
type TorrentArchive interface {
61
Stat(namespace string, d core.Digest) (*TorrentInfo, error)
62
CreateTorrent(namespace string, d core.Digest) (Torrent, error)
63
GetTorrent(namespace string, d core.Digest) (Torrent, error)
64
DeleteTorrent(d core.Digest) error