From 3160c1a8f3086f539e18503aca4cc39be483419c Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sun, 16 Jun 2019 13:01:14 +0100 Subject: [PATCH] fix for silent uploader exceptions --- .../muwire/core/upload/ContentUploader.groovy | 19 ++++++++++++++++++ .../core/upload/HashListUploader.groovy | 20 +++++++++++++++++++ .../com/muwire/core/upload/Uploader.groovy | 9 +++++++++ .../views/com/muwire/gui/MainFrameView.groovy | 9 +++------ 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/upload/ContentUploader.groovy b/core/src/main/groovy/com/muwire/core/upload/ContentUploader.groovy index 1b5d13cb..49da55d5 100644 --- a/core/src/main/groovy/com/muwire/core/upload/ContentUploader.groovy +++ b/core/src/main/groovy/com/muwire/core/upload/ContentUploader.groovy @@ -51,4 +51,23 @@ class ContentUploader extends Uploader { } } + @Override + public String getName() { + return file.getName(); + } + + @Override + public synchronized int getProgress() { + if (mapped == null) + return 0 + int position = mapped.position() + int total = request.getRange().end - request.getRange().start + (int)(position * 100.0 / total) + } + + @Override + public String getDownloader() { + request.downloader.getHumanReadableName() + } + } diff --git a/core/src/main/groovy/com/muwire/core/upload/HashListUploader.groovy b/core/src/main/groovy/com/muwire/core/upload/HashListUploader.groovy index c302338b..9085f0aa 100644 --- a/core/src/main/groovy/com/muwire/core/upload/HashListUploader.groovy +++ b/core/src/main/groovy/com/muwire/core/upload/HashListUploader.groovy @@ -6,6 +6,8 @@ import java.nio.charset.StandardCharsets import com.muwire.core.InfoHash import com.muwire.core.connection.Endpoint +import net.i2p.data.Base64 + class HashListUploader extends Uploader { private final InfoHash infoHash private final HashListRequest request @@ -14,6 +16,7 @@ class HashListUploader extends Uploader { super(endpoint) this.infoHash = infoHash mapped = ByteBuffer.wrap(infoHash.getHashList()) + this.request = request } void respond() { @@ -32,4 +35,21 @@ class HashListUploader extends Uploader { } endpoint.getOutputStream().flush() } + + @Override + public String getName() { + return "Hash list for " + Base64.encode(infoHash.getRoot()); + } + + @Override + public synchronized int getProgress() { + (int)(mapped.position() * 100.0 / mapped.capacity()) + } + + @Override + public String getDownloader() { + request.downloader.getHumanReadableName() + } + + } diff --git a/core/src/main/groovy/com/muwire/core/upload/Uploader.groovy b/core/src/main/groovy/com/muwire/core/upload/Uploader.groovy index d2e3b6df..c0bbfbd6 100644 --- a/core/src/main/groovy/com/muwire/core/upload/Uploader.groovy +++ b/core/src/main/groovy/com/muwire/core/upload/Uploader.groovy @@ -23,4 +23,13 @@ abstract class Uploader { return -1 mapped.position() } + + abstract String getName(); + + /** + * @return an integer between 0 and 100 + */ + abstract int getProgress(); + + abstract String getDownloader(); } diff --git a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy index 89ad302e..10b87775 100644 --- a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy @@ -160,16 +160,13 @@ class MainFrameView { scrollPane (constraints : BorderLayout.CENTER) { table(id : "uploads-table") { tableModel(list : model.uploads) { - closureColumn(header : "Name", type : String, read : {row -> row.file.getName() }) + closureColumn(header : "Name", type : String, read : {row -> row.getName() }) closureColumn(header : "Progress", type : String, read : { row -> - int position = row.getPosition() - def range = row.request.getRange() - int total = range.end - range.start - int percent = (int)((position * 100.0) / total) + int percent = row.getProgress() "$percent%" }) closureColumn(header : "Downloader", type : String, read : { row -> - row.request.downloader?.getHumanReadableName() + row.getDownloader() }) } }