diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index 1853e1ee..7f8874a1 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -23,6 +23,7 @@ import com.muwire.core.connection.I2PAcceptor import com.muwire.core.connection.I2PConnector import com.muwire.core.connection.LeafConnectionManager import com.muwire.core.connection.UltrapeerConnectionManager +import com.muwire.core.download.DownloadHopelessEvent import com.muwire.core.download.DownloadManager import com.muwire.core.download.SourceDiscoveredEvent import com.muwire.core.download.SourceVerifiedEvent @@ -391,6 +392,7 @@ public class Core { eventBus.register(SourceDiscoveredEvent.class, downloadManager) eventBus.register(UIDownloadPausedEvent.class, downloadManager) eventBus.register(UIDownloadResumedEvent.class, downloadManager) + eventBus.register(DownloadHopelessEvent.class, downloadManager) log.info("initializing upload manager") uploadManager = new UploadManager(eventBus, fileManager, meshManager, downloadManager, persisterFolderService, props) diff --git a/core/src/main/groovy/com/muwire/core/download/DownloadHopelessEvent.groovy b/core/src/main/groovy/com/muwire/core/download/DownloadHopelessEvent.groovy new file mode 100644 index 00000000..a0fe2d36 --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/download/DownloadHopelessEvent.groovy @@ -0,0 +1,7 @@ +package com.muwire.core.download + +import com.muwire.core.Event + +class DownloadHopelessEvent extends Event { + Downloader downloader +} diff --git a/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy b/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy index 75bff753..69e1e832 100644 --- a/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy +++ b/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy @@ -112,6 +112,11 @@ public class DownloadManager { persistDownloaders() } + public void onDownloadHopelessEvent(DownloadHopelessEvent e) { + downloaders.remove(e.downloader.infoHash) + persistDownloaders() + } + public void onUIDownloadPausedEvent(UIDownloadPausedEvent e) { persistDownloaders() } diff --git a/core/src/main/groovy/com/muwire/core/download/Downloader.groovy b/core/src/main/groovy/com/muwire/core/download/Downloader.groovy index c1310fbd..da449d60 100644 --- a/core/src/main/groovy/com/muwire/core/download/Downloader.groovy +++ b/core/src/main/groovy/com/muwire/core/download/Downloader.groovy @@ -66,6 +66,7 @@ public class Downloader { private volatile boolean cancelled, paused private final AtomicBoolean eventFired = new AtomicBoolean() + private final AtomicBoolean hopelessEventFired = new AtomicBoolean() private boolean piecesFileClosed private final AtomicLong dataSinceLastRead = new AtomicLong(0) @@ -436,6 +437,8 @@ public class Downloader { } catch (Exception bad) { log.log(Level.WARNING,"Exception while downloading",DataUtil.findRoot(bad)) markFailed(destination) + if (!hasLiveSources() && hopelessEventFired.compareAndSet(false, true)) + eventBus.publish(new DownloadHopelessEvent(downloader : Downloader.this)) } finally { writePieces() currentState = WorkerState.FINISHED