From: Matt Joiner Date: Thu, 22 May 2014 14:33:07 +0000 (+1000) Subject: ResponsiveDownloadStrategy will readahead blocks X-Git-Tag: v1.0.0~1738 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=96f85be99ab9d8590ed929ea605ceab2f7a69115;p=btrtrc.git ResponsiveDownloadStrategy will readahead blocks Test peers don't play well with short "up request" buffers, so we need to fill these with the most likely blocks to achieve maximum download speeds. --- diff --git a/client.go b/client.go index ae246f9f..5170db9c 100644 --- a/client.go +++ b/client.go @@ -130,6 +130,7 @@ func (cl *Client) TorrentReadAt(ih InfoHash, off int64, p []byte) (n int, err er err = io.EOF return } + t.lastReadPiece = int(index) piece := t.Pieces[index] if !piece.EverHashed { cl.queuePieceCheck(t, index) @@ -714,8 +715,26 @@ type ResponsiveDownloadStrategy struct{} func (ResponsiveDownloadStrategy) FillRequests(t *torrent, c *connection) { for e := t.Priorities.Front(); e != nil; e = e.Next() { if !c.Request(e.Value.(request)) { + return + } + } + for i := t.lastReadPiece; i < t.lastReadPiece+5 && i < t.NumPieces(); i++ { + for cs := range t.Pieces[i].PendingChunkSpecs { + if !c.Request(request{pp.Integer(i), cs}) { + return + } + } + } + // Then finish off incomplete pieces in order of bytes remaining. + for _, index := range t.piecesByPendingBytes() { + if t.PieceNumPendingBytes(index) == t.PieceLength(index) { break } + for chunkSpec := range t.Pieces[index].PendingChunkSpecs { + if !c.Request(request{index, chunkSpec}) { + return + } + } } } diff --git a/torrent.go b/torrent.go index 4f94b89b..39d85e5d 100644 --- a/torrent.go +++ b/torrent.go @@ -34,7 +34,8 @@ type torrent struct { Priorities *list.List // BEP 12 Multitracker Metadata Extension. The tracker.Client instances // mirror their respective URLs from the announce-list key. - Trackers [][]tracker.Client + Trackers [][]tracker.Client + lastReadPiece int } func (t *torrent) String() string {