client.go | 10 ++++++---- torrent.go | 8 +++++++- diff --git a/client.go b/client.go index 5f7f332f82ab9b099022539a4681796caf6a3a36..281e956691b0f5e689bfb7b5301f33f903dcc081 100644 --- a/client.go +++ b/client.go @@ -1749,8 +1749,11 @@ func (t *torrent) needData() bool { if !t.haveInfo() { return true } - for i := range t.Pieces { - if t.wantPiece(i) { + if len(t.urgent) != 0 { + return true + } + for _, p := range t.Pieces { + if p.Priority != PiecePriorityNone { return true } } @@ -2618,8 +2621,7 @@ conn.Cancel(r) } } conn.pieceRequestOrder.DeletePiece(int(piece)) - } - if t.wantPiece(piece) && conn.PeerHasPiece(piece) { + } else if t.wantPiece(piece) && conn.PeerHasPiece(piece) { t.connPendPiece(conn, int(piece)) me.replenishConnRequests(t, conn) } diff --git a/torrent.go b/torrent.go index 43d45d5c8c99f16aa53cab968b83dd60605ca484..c263dcafce477e402c9738618bc68defc0c77847 100644 --- a/torrent.go +++ b/torrent.go @@ -307,7 +307,7 @@ } if p.QueuedForHash || p.Hashing { ret.Checking = true } - if t.piecePartiallyDownloaded(index) { + if !ret.Complete && t.piecePartiallyDownloaded(index) { ret.Partial = true } return @@ -674,7 +674,13 @@ func (t *torrent) haveChunk(r request) bool { if !t.haveInfo() { return false } + if t.pieceComplete(int(r.Index)) { + return true + } p := t.Pieces[r.Index] + if p.PendingChunkSpecs == nil { + return false + } return !p.pendingChunk(r.chunkSpec, t.chunkSize) }