3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 06:44:16 +00:00

PeerGroup fixes for maxConnections and block timestamp

This commit is contained in:
Miron Cuperman (devrandom) 2011-07-25 19:51:22 +00:00
parent 7dd1fce5aa
commit 652a394fc1
3 changed files with 5 additions and 8 deletions

View File

@ -437,7 +437,7 @@ public class Block extends Message {
this.hash = null; 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() { public long getTime() {
return time; return time;
} }

View File

@ -59,7 +59,7 @@ public class DownloadListener extends AbstractPeerEventListener {
double pct = 100.0 - (100.0 * (blocksLeft / (double) originalBlocksLeft)); double pct = 100.0 - (100.0 * (blocksLeft / (double) originalBlocksLeft));
if ((int)pct != lastPercent) { if ((int)pct != lastPercent) {
progress(pct, new Date(block.getTime())); progress(pct, new Date(block.getTime() * 1000));
lastPercent = (int)pct; lastPercent = (int)pct;
} }
} }

View File

@ -63,8 +63,6 @@ public class PeerGroup {
private static final int CORE_THREADS = 1; private static final int CORE_THREADS = 1;
private static final int THREAD_KEEP_ALIVE_SECONDS = 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 // Addresses to try to connect to, excluding active peers
private BlockingQueue<PeerAddress> inactives; private BlockingQueue<PeerAddress> inactives;
// Connection initiation thread // Connection initiation thread
@ -88,7 +86,6 @@ public class PeerGroup {
* Create a PeerGroup * Create a PeerGroup
*/ */
public PeerGroup(BlockStore blockStore, NetworkParameters params, BlockChain chain) { public PeerGroup(BlockStore blockStore, NetworkParameters params, BlockChain chain) {
this.maxConnections = DEFAULT_CONNECTIONS;
this.blockStore = blockStore; this.blockStore = blockStore;
this.params = params; this.params = params;
this.chain = chain; this.chain = chain;
@ -96,7 +93,7 @@ public class PeerGroup {
inactives = new LinkedBlockingQueue<PeerAddress>(); inactives = new LinkedBlockingQueue<PeerAddress>();
peers = Collections.synchronizedSet(new HashSet<Peer>()); peers = Collections.synchronizedSet(new HashSet<Peer>());
peerPool = new ThreadPoolExecutor(CORE_THREADS, this.maxConnections, peerPool = new ThreadPoolExecutor(CORE_THREADS, DEFAULT_CONNECTIONS,
THREAD_KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, THREAD_KEEP_ALIVE_SECONDS, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(1), new LinkedBlockingQueue<Runnable>(1),
new PeerGroupThreadFactory()); new PeerGroupThreadFactory());
@ -108,11 +105,11 @@ public class PeerGroup {
* @param maxConnections the maximum number of peer connections that this group will try to make. * @param maxConnections the maximum number of peer connections that this group will try to make.
*/ */
public void setMaxConnections(int maxConnections) { public void setMaxConnections(int maxConnections) {
this.maxConnections = maxConnections; peerPool.setMaximumPoolSize(maxConnections);
} }
public int getMaxConnections() { public int getMaxConnections() {
return maxConnections; return peerPool.getMaximumPoolSize();
} }
/** Add an address to the list of potential peers to connect to */ /** Add an address to the list of potential peers to connect to */