mirror of https://github.com/zlatinb/muwire
do not steal pieces from already queued requests
parent
17cc7d4275
commit
8f923ec06e
|
@ -44,7 +44,7 @@ class DownloadSession {
|
||||||
private MappedByteBuffer mapped
|
private MappedByteBuffer mapped
|
||||||
private boolean unclaim = true
|
private boolean unclaim = true
|
||||||
private boolean steal
|
private boolean steal
|
||||||
private int piece, position
|
int piece, position
|
||||||
private long pieceStart, start, end
|
private long pieceStart, start, end
|
||||||
|
|
||||||
DownloadSession(EventBus eventBus, String meB64, Pieces pieces, InfoHash infoHash, Endpoint endpoint, File file,
|
DownloadSession(EventBus eventBus, String meB64, Pieces pieces, InfoHash infoHash, Endpoint endpoint, File file,
|
||||||
|
|
|
@ -405,15 +405,18 @@ public class Downloader {
|
||||||
boolean feed = downloadManager.muSettings.fileFeed && downloadManager.muSettings.advertiseFeed
|
boolean feed = downloadManager.muSettings.fileFeed && downloadManager.muSettings.advertiseFeed
|
||||||
boolean chat = chatServer.isRunning() && downloadManager.muSettings.advertiseChat
|
boolean chat = chatServer.isRunning() && downloadManager.muSettings.advertiseChat
|
||||||
|
|
||||||
|
Set<Integer> queuedPieces = new HashSet<>()
|
||||||
boolean requestPerformed
|
boolean requestPerformed
|
||||||
while(!pieces.isComplete()) {
|
while(!pieces.isComplete()) {
|
||||||
if (sessionQueue.isEmpty()) {
|
if (sessionQueue.isEmpty()) {
|
||||||
boolean sentAnyRequests = false
|
boolean sentAnyRequests = false
|
||||||
queueSize.times {
|
queueSize.times {
|
||||||
|
available.removeAll(queuedPieces)
|
||||||
def currentSession = new DownloadSession(eventBus, me.toBase64(), pieces, getInfoHash(),
|
def currentSession = new DownloadSession(eventBus, me.toBase64(), pieces, getInfoHash(),
|
||||||
endpoint, incompleteFile, pieceSize, length, available, dataSinceLastRead,
|
endpoint, incompleteFile, pieceSize, length, available, dataSinceLastRead,
|
||||||
browse, feed, chat)
|
browse, feed, chat)
|
||||||
if (currentSession.sendRequest()) {
|
if (currentSession.sendRequest()) {
|
||||||
|
queuedPieces.add(currentSession.piece)
|
||||||
sessionQueue.addLast(currentSession)
|
sessionQueue.addLast(currentSession)
|
||||||
sentAnyRequests = true
|
sentAnyRequests = true
|
||||||
}
|
}
|
||||||
|
@ -422,13 +425,18 @@ public class Downloader {
|
||||||
break;
|
break;
|
||||||
endpoint.getOutputStream().flush()
|
endpoint.getOutputStream().flush()
|
||||||
}
|
}
|
||||||
|
available.removeAll(queuedPieces)
|
||||||
def nextSession = new DownloadSession(eventBus, me.toBase64(), pieces, getInfoHash(),
|
def nextSession = new DownloadSession(eventBus, me.toBase64(), pieces, getInfoHash(),
|
||||||
endpoint, incompleteFile, pieceSize, length, available, dataSinceLastRead,
|
endpoint, incompleteFile, pieceSize, length, available, dataSinceLastRead,
|
||||||
browse, feed, chat)
|
browse, feed, chat)
|
||||||
if (nextSession.sendRequest())
|
if (nextSession.sendRequest()) {
|
||||||
sessionQueue.addLast(nextSession)
|
sessionQueue.addLast(nextSession)
|
||||||
|
queuedPieces.add(nextSession.piece)
|
||||||
|
}
|
||||||
|
|
||||||
requestPerformed = sessionQueue.removeFirst().consumeResponse()
|
def currentSession = sessionQueue.removeFirst()
|
||||||
|
requestPerformed = currentSession.consumeResponse()
|
||||||
|
queuedPieces.remove(currentSession.piece)
|
||||||
if (!requestPerformed)
|
if (!requestPerformed)
|
||||||
break
|
break
|
||||||
successfulDestinations.add(endpoint.destination)
|
successfulDestinations.add(endpoint.destination)
|
||||||
|
|
Loading…
Reference in New Issue