do not steal pieces from already queued requests

pull/53/head
Zlatin Balevsky 2020-10-11 15:32:56 +01:00
parent 17cc7d4275
commit 8f923ec06e
No known key found for this signature in database
GPG Key ID: A72832072D525E41
2 changed files with 12 additions and 4 deletions

View File

@ -44,7 +44,7 @@ class DownloadSession {
private MappedByteBuffer mapped
private boolean unclaim = true
private boolean steal
private int piece, position
int piece, position
private long pieceStart, start, end
DownloadSession(EventBus eventBus, String meB64, Pieces pieces, InfoHash infoHash, Endpoint endpoint, File file,

View File

@ -405,15 +405,18 @@ public class Downloader {
boolean feed = downloadManager.muSettings.fileFeed && downloadManager.muSettings.advertiseFeed
boolean chat = chatServer.isRunning() && downloadManager.muSettings.advertiseChat
Set<Integer> queuedPieces = new HashSet<>()
boolean requestPerformed
while(!pieces.isComplete()) {
if (sessionQueue.isEmpty()) {
boolean sentAnyRequests = false
queueSize.times {
available.removeAll(queuedPieces)
def currentSession = new DownloadSession(eventBus, me.toBase64(), pieces, getInfoHash(),
endpoint, incompleteFile, pieceSize, length, available, dataSinceLastRead,
browse, feed, chat)
if (currentSession.sendRequest()) {
queuedPieces.add(currentSession.piece)
sessionQueue.addLast(currentSession)
sentAnyRequests = true
}
@ -422,13 +425,18 @@ public class Downloader {
break;
endpoint.getOutputStream().flush()
}
available.removeAll(queuedPieces)
def nextSession = new DownloadSession(eventBus, me.toBase64(), pieces, getInfoHash(),
endpoint, incompleteFile, pieceSize, length, available, dataSinceLastRead,
browse, feed, chat)
if (nextSession.sendRequest())
if (nextSession.sendRequest()) {
sessionQueue.addLast(nextSession)
requestPerformed = sessionQueue.removeFirst().consumeResponse()
queuedPieces.add(nextSession.piece)
}
def currentSession = sessionQueue.removeFirst()
requestPerformed = currentSession.consumeResponse()
queuedPieces.remove(currentSession.piece)
if (!requestPerformed)
break
successfulDestinations.add(endpoint.destination)