From 09e867b19492ab9c22993aaec100d0051741b169 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Tue, 2 Jun 2015 20:14:33 +0000 Subject: [PATCH] i2psnark: Don't say 'download finished' unless we downloaded something atomics --- .../src/org/klomp/snark/PeerCoordinator.java | 17 +++++++++-------- .../java/src/org/klomp/snark/SnarkManager.java | 3 ++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/apps/i2psnark/java/src/org/klomp/snark/PeerCoordinator.java b/apps/i2psnark/java/src/org/klomp/snark/PeerCoordinator.java index e6014becd0..63da5f2961 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/PeerCoordinator.java +++ b/apps/i2psnark/java/src/org/klomp/snark/PeerCoordinator.java @@ -33,6 +33,7 @@ import java.util.Map; import java.util.Random; import java.util.Set; import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.atomic.AtomicLong; import net.i2p.I2PAppContext; import net.i2p.data.ByteArray; @@ -87,8 +88,8 @@ class PeerCoordinator implements PeerListener // final static int MAX_DOWNLOADERS = MAX_CONNECTIONS; // int downloaders = 0; - private long uploaded; - private long downloaded; + private final AtomicLong uploaded = new AtomicLong(); + private final AtomicLong downloaded = new AtomicLong(); final static int RATE_DEPTH = 3; // make following arrays RATE_DEPTH long private final long uploaded_old[] = {-1,-1,-1}; private final long downloaded_old[] = {-1,-1,-1}; @@ -279,7 +280,7 @@ class PeerCoordinator implements PeerListener */ public long getUploaded() { - return uploaded; + return uploaded.get(); } /** @@ -287,7 +288,7 @@ class PeerCoordinator implements PeerListener * @since 0.9.15 */ public void setUploaded(long up) { - uploaded = up; + uploaded.set(up); } /** @@ -295,7 +296,7 @@ class PeerCoordinator implements PeerListener */ public long getDownloaded() { - return downloaded; + return downloaded.get(); } /** @@ -944,7 +945,7 @@ class PeerCoordinator implements PeerListener */ public void uploaded(Peer peer, int size) { - uploaded += size; + uploaded.addAndGet(size); //if (listener != null) // listener.peerChange(this, peer); @@ -955,7 +956,7 @@ class PeerCoordinator implements PeerListener */ public void downloaded(Peer peer, int size) { - downloaded += size; + downloaded.addAndGet(size); //if (listener != null) // listener.peerChange(this, peer); @@ -1004,7 +1005,7 @@ class PeerCoordinator implements PeerListener else { // Oops. We didn't actually download this then... :( - downloaded -= metainfo.getPieceLength(piece); + downloaded.addAndGet(0 - metainfo.getPieceLength(piece)); _log.warn("Got BAD piece " + piece + "/" + metainfo.getPieces() + " from " + peer + " for " + metainfo.getName()); return false; // No need to announce BAD piece to peers. } diff --git a/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java b/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java index b9370439c7..62f66f68fc 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java +++ b/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java @@ -1976,7 +1976,8 @@ public class SnarkManager implements CompleteListener { if (meta.getFiles() != null) buf.append('/'); buf.append("\">").append(base).append("</a>"); - addMessageNoEscape(_("Download finished: {0}", buf.toString())); // + " (" + _("size: {0}B", DataHelper.formatSize2(len)) + ')'); + if (snark.getDownloaded() > 0) + addMessageNoEscape(_("Download finished: {0}", buf.toString())); // + " (" + _("size: {0}B", DataHelper.formatSize2(len)) + ')'); updateStatus(snark); } -- GitLab