From 652a394fc1ed7bbc780dffe6b8197b7be610ae79 Mon Sep 17 00:00:00 2001 From: "Miron Cuperman (devrandom)" Date: Mon, 25 Jul 2011 19:51:22 +0000 Subject: [PATCH] PeerGroup fixes for maxConnections and block timestamp --- src/com/google/bitcoin/core/Block.java | 2 +- src/com/google/bitcoin/core/DownloadListener.java | 2 +- src/com/google/bitcoin/core/PeerGroup.java | 9 +++------ 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/com/google/bitcoin/core/Block.java b/src/com/google/bitcoin/core/Block.java index 158974e6..460336c0 100644 --- a/src/com/google/bitcoin/core/Block.java +++ b/src/com/google/bitcoin/core/Block.java @@ -437,7 +437,7 @@ public class Block extends Message { this.hash = null; } - /** Returns the time at which the block was solved and broadcast, according to the clock of the solving node. */ + /** Returns the time in seconds at which the block was solved and broadcast, according to the clock of the solving node. */ public long getTime() { return time; } diff --git a/src/com/google/bitcoin/core/DownloadListener.java b/src/com/google/bitcoin/core/DownloadListener.java index a1848251..04191e8e 100644 --- a/src/com/google/bitcoin/core/DownloadListener.java +++ b/src/com/google/bitcoin/core/DownloadListener.java @@ -59,7 +59,7 @@ public class DownloadListener extends AbstractPeerEventListener { double pct = 100.0 - (100.0 * (blocksLeft / (double) originalBlocksLeft)); if ((int)pct != lastPercent) { - progress(pct, new Date(block.getTime())); + progress(pct, new Date(block.getTime() * 1000)); lastPercent = (int)pct; } } diff --git a/src/com/google/bitcoin/core/PeerGroup.java b/src/com/google/bitcoin/core/PeerGroup.java index db0aeff0..7d6c0d97 100644 --- a/src/com/google/bitcoin/core/PeerGroup.java +++ b/src/com/google/bitcoin/core/PeerGroup.java @@ -63,8 +63,6 @@ public class PeerGroup { private static final int CORE_THREADS = 1; private static final int THREAD_KEEP_ALIVE_SECONDS = 1; - // Maximum number of connections this peerGroup will make - private int maxConnections; // Addresses to try to connect to, excluding active peers private BlockingQueue inactives; // Connection initiation thread @@ -88,7 +86,6 @@ public class PeerGroup { * Create a PeerGroup */ public PeerGroup(BlockStore blockStore, NetworkParameters params, BlockChain chain) { - this.maxConnections = DEFAULT_CONNECTIONS; this.blockStore = blockStore; this.params = params; this.chain = chain; @@ -96,7 +93,7 @@ public class PeerGroup { inactives = new LinkedBlockingQueue(); peers = Collections.synchronizedSet(new HashSet()); - peerPool = new ThreadPoolExecutor(CORE_THREADS, this.maxConnections, + peerPool = new ThreadPoolExecutor(CORE_THREADS, DEFAULT_CONNECTIONS, THREAD_KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, new LinkedBlockingQueue(1), new PeerGroupThreadFactory()); @@ -108,11 +105,11 @@ public class PeerGroup { * @param maxConnections the maximum number of peer connections that this group will try to make. */ public void setMaxConnections(int maxConnections) { - this.maxConnections = maxConnections; + peerPool.setMaximumPoolSize(maxConnections); } public int getMaxConnections() { - return maxConnections; + return peerPool.getMaximumPoolSize(); } /** Add an address to the list of potential peers to connect to */