This commit is contained in:
Matt Joiner 2015-06-01 18:17:14 +10:00
parent b34b583919
commit bc4aa06c91
4 changed files with 14 additions and 4 deletions

View File

@ -1975,6 +1975,7 @@ func (t Torrent) Files() (ret []File) {
return return
} }
// Marks the pieces in the given region for download.
func (t Torrent) SetRegionPriority(off, len int64) { func (t Torrent) SetRegionPriority(off, len int64) {
t.cl.mu.Lock() t.cl.mu.Lock()
defer t.cl.mu.Unlock() defer t.cl.mu.Unlock()

View File

@ -39,7 +39,8 @@ type connection struct {
post chan pp.Message post chan pp.Message
writeCh chan []byte writeCh chan []byte
// The connections preferred order to download pieces. // The connection's preferred order to download pieces. The index is the
// piece, the value is its priority.
piecePriorities []int piecePriorities []int
// The piece request order based on piece priorities. // The piece request order based on piece priorities.
pieceRequestOrder *pieceordering.Instance pieceRequestOrder *pieceordering.Instance
@ -109,6 +110,7 @@ func (cn *connection) pendPiece(piece int, priority piecePriority) {
// Priority regions not to scale. Within each region, piece is randomized // Priority regions not to scale. Within each region, piece is randomized
// according to connection. // according to connection.
// <-request first -- last->
// [ Now ] // [ Now ]
// [ Next ] // [ Next ]
// [ Readahead ] // [ Readahead ]

View File

@ -10,7 +10,11 @@ import (
// Maintains piece integers by their ascending assigned keys. // Maintains piece integers by their ascending assigned keys.
type Instance struct { type Instance struct {
sl *skiplist.SkipList // Contains the ascending priority keys. The keys contain a slice of piece
// indices.
sl *skiplist.SkipList
// Maps from piece index back to its key, so that it can be remove
// efficiently from the skip list.
pieceKeys map[int]int pieceKeys map[int]int
} }
@ -41,6 +45,7 @@ func (me *Instance) SetPiece(piece, key int) {
me.shuffleItem(key) me.shuffleItem(key)
} }
// Shuffle the piece indices that share a given key.
func (me *Instance) shuffleItem(key int) { func (me *Instance) shuffleItem(key int) {
_item, ok := me.sl.Get(key) _item, ok := me.sl.Get(key)
if !ok { if !ok {

View File

@ -7,6 +7,8 @@ import (
pp "github.com/anacrolix/torrent/peer_protocol" pp "github.com/anacrolix/torrent/peer_protocol"
) )
// Piece priority describes the importance of obtaining a particular piece.
type piecePriority byte type piecePriority byte
const ( const (
@ -18,8 +20,8 @@ const (
) )
type piece struct { type piece struct {
Hash pieceSum Hash pieceSum // The completed piece SHA1 hash, from the metainfo "pieces" field.
// Chunks we don't have. The offset and length can be determined by our // Chunks we don't have. The offset and length can be determined by the
// request chunkSize in use. // request chunkSize in use.
PendingChunkSpecs []bool PendingChunkSpecs []bool
Hashing bool Hashing bool