From 64cb5bb50cba9c390664ce5fe1cf5a52fadebf8e Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 21 Nov 2014 00:05:09 -0600 Subject: [PATCH] Add PendingData call to download strategy interface --- download_strategies.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/download_strategies.go b/download_strategies.go index a21321b2..8973bcae 100644 --- a/download_strategies.go +++ b/download_strategies.go @@ -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 +} -- 2.48.1