"github.com/anacrolix/torrent/mse"
+ "github.com/anacrolix/libtorgo/bencode"
+ "github.com/anacrolix/libtorgo/metainfo"
+ "github.com/anacrolix/sync"
"github.com/anacrolix/torrent/data"
filePkg "github.com/anacrolix/torrent/data/file"
"github.com/anacrolix/torrent/dht"
"github.com/anacrolix/torrent/tracker"
_ "github.com/anacrolix/torrent/tracker/udp"
. "github.com/anacrolix/torrent/util"
- "github.com/anacrolix/sync"
"github.com/anacrolix/utp"
- "github.com/anacrolix/libtorgo/bencode"
- "github.com/anacrolix/libtorgo/metainfo"
)
var (
return
}
pieceOff := pp.Integer(off % int64(t.usualPieceSize()))
- pieceLeft := int(t.PieceLength(index) - pieceOff)
+ pieceLeft := int(t.pieceLength(index) - pieceOff)
if pieceLeft <= 0 {
err = io.EOF
return
// routine.
// c.PeerRequests[request] = struct{}{}
p := make([]byte, msg.Length)
- n, err := dataReadAt(t.data, p, int64(t.PieceLength(0))*int64(msg.Index)+int64(msg.Begin))
+ n, err := dataReadAt(t.data, p, int64(t.pieceLength(0))*int64(msg.Index)+int64(msg.Begin))
if err != nil {
return fmt.Errorf("reading t data to serve request %q: %s", request, err)
}
return
}
-// For adding new torrents to a client.
+// Specifies a new torrent for adding to a client. There are helpers for
+// magnet URIs and torrent metainfo files.
type TorrentSpec struct {
Trackers [][]string
InfoHash InfoHash
"github.com/bradfitz/iter"
+ "github.com/anacrolix/libtorgo/bencode"
+ "github.com/anacrolix/libtorgo/metainfo"
"github.com/anacrolix/torrent/data"
pp "github.com/anacrolix/torrent/peer_protocol"
"github.com/anacrolix/torrent/tracker"
"github.com/anacrolix/torrent/util"
- "github.com/anacrolix/libtorgo/bencode"
- "github.com/anacrolix/libtorgo/metainfo"
)
func (t *torrent) pieceNumPendingBytes(index int) (count pp.Integer) {
}
piece := t.Pieces[index]
if !piece.EverHashed {
- return t.PieceLength(index)
+ return t.pieceLength(index)
}
pendingChunks := t.Pieces[index].PendingChunkSpecs
count = pp.Integer(len(pendingChunks)) * chunkSize
- _lastChunkSpec := lastChunkSpec(t.PieceLength(index))
+ _lastChunkSpec := lastChunkSpec(t.pieceLength(index))
if _lastChunkSpec.Length != chunkSize {
if _, ok := pendingChunks[_lastChunkSpec]; ok {
count += _lastChunkSpec.Length - chunkSize
}
type PieceStatusCharSequence struct {
- Char byte
- Count int
+ Char byte // The state of this sequence of pieces.
+ Count int // How many consecutive pieces have this state.
}
+// Returns the state of pieces of the torrent. They are grouped into runs of
+// same state. The sum of the Counts of the sequences is the number of pieces
+// in the torrent. See the function torrent.pieceStatusChar for the possible
+// states.
func (t *torrent) PieceStatusCharSequences() []PieceStatusCharSequence {
t.stateMu.Lock()
defer t.stateMu.Unlock()
}
func (t *torrent) piecePartiallyDownloaded(index int) bool {
- return t.pieceNumPendingBytes(index) != t.PieceLength(index)
+ return t.pieceNumPendingBytes(index) != t.pieceLength(index)
}
func numChunksForPiece(chunkSize int, pieceSize int) int {
}
func (t *torrent) lastPieceSize() int {
- return int(t.PieceLength(t.numPieces() - 1))
+ return int(t.pieceLength(t.numPieces() - 1))
}
func (t *torrent) numPieces() int {
}
func (t *torrent) pieceChunks(piece int) (css []chunkSpec) {
- css = make([]chunkSpec, 0, (t.PieceLength(piece)+chunkSize-1)/chunkSize)
+ css = make([]chunkSpec, 0, (t.pieceLength(piece)+chunkSize-1)/chunkSize)
var cs chunkSpec
- for left := t.PieceLength(piece); left != 0; left -= cs.Length {
+ for left := t.pieceLength(piece); left != 0; left -= cs.Length {
cs.Length = left
if cs.Length > chunkSize {
cs.Length = chunkSize
if piece.PendingChunkSpecs == nil {
piece.PendingChunkSpecs = make(
map[chunkSpec]struct{},
- (t.PieceLength(index)+chunkSize-1)/chunkSize)
+ (t.pieceLength(index)+chunkSize-1)/chunkSize)
}
pcss := piece.PendingChunkSpecs
for _, cs := range t.pieceChunks(int(index)) {
SupportsEncryption bool
}
-func (t *torrent) PieceLength(piece int) (len_ pp.Integer) {
+func (t *torrent) pieceLength(piece int) (len_ pp.Integer) {
if int(piece) == t.numPieces()-1 {
len_ = pp.Integer(t.Length() % t.Info.PieceLength)
}