From 262f045fd1846b43861531f099c28015e132912e Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 9 Dec 2014 00:22:05 -0600 Subject: [PATCH] Fixes due to not pending chunk specs prematurely --- client.go | 4 +++- torrent.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index aeff48c0..602f99c7 100644 --- a/client.go +++ b/client.go @@ -941,6 +941,7 @@ func (me *Client) runConnection(sock net.Conn, torrent *torrent, discovery peerS } if torrent.haveInfo() { torrent.initRequestOrdering(conn) + me.replenishConnRequests(torrent, conn) } err = me.connectionLoop(torrent, conn) if err != nil { @@ -2139,7 +2140,8 @@ func (me *Client) pieceHashed(t *torrent, piece pp.Integer, correct bool) { conn.pieceRequestOrder.DeletePiece(int(piece)) } if t.wantPiece(int(piece)) && conn.PeerHasPiece(piece) { - conn.pendPiece(int(piece), t.Pieces[piece].Priority) + t.connPendPiece(conn, int(piece)) + me.replenishConnRequests(t, conn) } } if t.haveAllPieces() && me.noUpload { diff --git a/torrent.go b/torrent.go index 891e0060..469d2b15 100644 --- a/torrent.go +++ b/torrent.go @@ -21,6 +21,10 @@ import ( ) func (t *torrent) PieceNumPendingBytes(index pp.Integer) (count pp.Integer) { + piece := t.Pieces[index] + if !piece.EverHashed { + return t.PieceLength(index) + } pendingChunks := t.Pieces[index].PendingChunkSpecs count = pp.Integer(len(pendingChunks)) * chunkSize _lastChunkSpec := lastChunkSpec(t.PieceLength(index)) -- 2.48.1