From 30eb1f80431ef30dee21107fac077a68496ede5b Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Fri, 12 Apr 2013 15:28:46 +0200 Subject: [PATCH] DownloadListener: don't print redundant noise after catching up with the chain. --- .../com/google/bitcoin/core/DownloadListener.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/core/DownloadListener.java b/core/src/main/java/com/google/bitcoin/core/DownloadListener.java index b7cc9e1e..bd8a9728 100644 --- a/core/src/main/java/com/google/bitcoin/core/DownloadListener.java +++ b/core/src/main/java/com/google/bitcoin/core/DownloadListener.java @@ -29,6 +29,7 @@ public class DownloadListener extends AbstractPeerEventListener { private int originalBlocksLeft = -1; private int lastPercent = 0; private Semaphore done = new Semaphore(0); + private boolean caughtUp = false; @Override public void onChainDownloadStarted(Peer peer, int blocksLeft) { @@ -42,7 +43,11 @@ public class DownloadListener extends AbstractPeerEventListener { @Override public void onBlocksDownloaded(Peer peer, Block block, int blocksLeft) { + if (caughtUp) + return; + if (blocksLeft == 0) { + caughtUp = true; doneDownload(); done.release(); } @@ -74,15 +79,15 @@ public class DownloadListener extends AbstractPeerEventListener { * @param blocks the number of blocks to download, estimated */ protected void startDownload(int blocks) { - System.out.println("Downloading block chain of size " + blocks + ". " + - (blocks > 1000 ? "This may take a while." : "")); + if (blocks > 0) + System.out.println("Downloading block chain of size " + blocks + ". " + + (blocks > 1000 ? "This may take a while." : "")); } /** * Called when we are done downloading the block chain. */ protected void doneDownload() { - System.out.println("Done downloading block chain"); } /** @@ -91,4 +96,4 @@ public class DownloadListener extends AbstractPeerEventListener { public void await() throws InterruptedException { done.acquire(); } -} \ No newline at end of file +}