]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add PendingData call to download strategy interface
authorMatt Joiner <anacrolix@gmail.com>
Fri, 21 Nov 2014 06:05:09 +0000 (00:05 -0600)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 21 Nov 2014 06:05:09 +0000 (00:05 -0600)
download_strategies.go

index a21321b223fee608993f86743719036533825754..8973bcae642085c7e358217881ec870541dc125c 100644 (file)
@@ -22,12 +22,17 @@ type DownloadStrategy interface {
        TorrentGotPiece(t *torrent, piece int)
        WriteStatus(w io.Writer)
        AssertNotRequested(*torrent, request)
+       PendingData(*torrent) bool
 }
 
 type DefaultDownloadStrategy struct {
        heat map[*torrent]map[request]int
 }
 
+func (me *DefaultDownloadStrategy) PendingData(t *torrent) bool {
+       return !t.haveAllPieces()
+}
+
 func (me *DefaultDownloadStrategy) AssertNotRequested(t *torrent, r request) {
        if me.heat[t][r] != 0 {
                panic("outstanding requests break invariant")
@@ -135,6 +140,7 @@ type responsiveDownloadStrategy struct {
        priorities     map[*torrent]map[request]struct{}
        requestHeat    map[*torrent]map[request]int
        rand           *rand.Rand // Avoid global lock
+       dummyConn      *connection
 }
 
 func (me *responsiveDownloadStrategy) WriteStatus(w io.Writer) {
@@ -151,6 +157,7 @@ func (me *responsiveDownloadStrategy) WriteStatus(w io.Writer) {
 func (me *responsiveDownloadStrategy) TorrentStarted(t *torrent) {
        me.priorities[t] = make(map[request]struct{})
        me.requestHeat[t] = make(map[request]int)
+       me.dummyConn = &connection{}
 }
 
 func (me *responsiveDownloadStrategy) TorrentStopped(t *torrent) {
@@ -179,6 +186,7 @@ func (me *requestFiller) request(req request) bool {
        if me.pieces == nil {
                me.pieces = make(map[int]struct{})
        }
+       // log.Print(req)
        me.pieces[int(req.Index)] = struct{}{}
        if me.c.RequestPending(req) {
                return true
@@ -375,3 +383,7 @@ func (s *responsiveDownloadStrategy) AssertNotRequested(t *torrent, r request) {
                panic("outstanding requests invariant broken")
        }
 }
+
+func (me *responsiveDownloadStrategy) PendingData(t *torrent) bool {
+       return len(me.FillRequests(t, me.dummyConn)) != 0
+}