Skip to content

Commit

Permalink
Don't roll back progress measurement when download peer changes in Do…
Browse files Browse the repository at this point in the history
…wnloadListener.
  • Loading branch information
mikehearn committed Aug 6, 2014
1 parent b7a83f9 commit 32a5ed3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions core/src/main/java/com/google/bitcoin/core/DownloadListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.Date;
import java.util.concurrent.Semaphore;

// TODO: Rename this to DownloadProgressTracker or something more appropriate.

/**
* <p>An implementation of {@link AbstractPeerEventListener} that listens to chain download events and tracks progress
* as a percentage. The default implementation prints progress to stdout, but you can subclass it and override the
Expand All @@ -38,7 +40,12 @@ public class DownloadListener extends AbstractPeerEventListener {
@Override
public void onChainDownloadStarted(Peer peer, int blocksLeft) {
startDownload(blocksLeft);
originalBlocksLeft = blocksLeft;
// Only mark this the first time, because this method can be called more than once during a chain download
// if we switch peers during it.
if (originalBlocksLeft == -1)
originalBlocksLeft = blocksLeft;
else
log.info("Chain download switched to {}", peer);
if (blocksLeft == 0) {
doneDownload();
done.release();
Expand Down Expand Up @@ -83,9 +90,10 @@ protected void progress(double pct, int blocksSoFar, Date date) {
* @param blocks the number of blocks to download, estimated
*/
protected void startDownload(int blocks) {
if (blocks > 0)
if (blocks > 0 && originalBlocksLeft == -1)
log.info("Downloading block chain of size " + blocks + ". " +
(blocks > 1000 ? "This may take a while." : ""));

}

/**
Expand Down

0 comments on commit 32a5ed3

Please sign in to comment.