mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-30 23:02:15 +00:00
Add basic support for using AbstractBlockChains in Peer/PeerGroup.
This commit is contained in:
parent
03d8c71df3
commit
8edd6c5399
@ -47,7 +47,7 @@ public class Peer {
|
||||
private static final Logger log = LoggerFactory.getLogger(Peer.class);
|
||||
|
||||
private final NetworkParameters params;
|
||||
private final BlockChain blockChain;
|
||||
private final AbstractBlockChain blockChain;
|
||||
// When an API user explicitly requests a block or transaction from a peer, the InventoryItem is put here
|
||||
// whilst waiting for the response. Synchronized on itself. Is not used for downloads Peer generates itself.
|
||||
// TODO: Make this work for transactions as well.
|
||||
@ -87,9 +87,9 @@ public class Peer {
|
||||
/**
|
||||
* Construct a peer that reads/writes from the given block chain.
|
||||
*/
|
||||
public Peer(NetworkParameters params, BlockChain blockChain, VersionMessage ver) {
|
||||
public Peer(NetworkParameters params, AbstractBlockChain chain2, VersionMessage ver) {
|
||||
this.params = params;
|
||||
this.blockChain = blockChain;
|
||||
this.blockChain = chain2;
|
||||
this.versionMessage = ver;
|
||||
this.pendingGetBlockFutures = new ArrayList<GetDataFuture<Block>>();
|
||||
this.eventListeners = new CopyOnWriteArrayList<PeerEventListener>();
|
||||
@ -103,7 +103,7 @@ public class Peer {
|
||||
* Construct a peer that reads/writes from the given chain. Automatically creates a VersionMessage for you from the
|
||||
* given software name/version strings, which should be something like "MySimpleTool", "1.0"
|
||||
*/
|
||||
public Peer(NetworkParameters params, BlockChain blockChain, String thisSoftwareName, String thisSoftwareVersion) {
|
||||
public Peer(NetworkParameters params, AbstractBlockChain blockChain, String thisSoftwareName, String thisSoftwareVersion) {
|
||||
this(params, blockChain, null);
|
||||
this.versionMessage = new VersionMessage(params, blockChain.getBestChainHeight());
|
||||
this.versionMessage.appendToSubVer(thisSoftwareName, thisSoftwareVersion, null);
|
||||
|
@ -94,6 +94,7 @@ public class PeerGroup {
|
||||
private int maxConnections;
|
||||
|
||||
private final NetworkParameters params;
|
||||
private final AbstractBlockChain chain;
|
||||
private int connectionDelayMillis;
|
||||
private long fastCatchupTimeSecs;
|
||||
private ArrayList<Wallet> wallets;
|
||||
@ -125,10 +126,10 @@ public class PeerGroup {
|
||||
* about blocks or pending transactions, you can just provide a MemoryBlockStore and a newly created Wallet.
|
||||
*
|
||||
* @param params Network parameters
|
||||
* @param chain a BlockChain object that will receive and handle block messages.
|
||||
* @param chain2 a BlockChain object that will receive and handle block messages.
|
||||
*/
|
||||
public PeerGroup(NetworkParameters params, BlockChain chain) {
|
||||
this(params, chain, DEFAULT_CONNECTION_DELAY_MILLIS);
|
||||
public PeerGroup(NetworkParameters params, AbstractBlockChain chain2) {
|
||||
this(params, chain2, DEFAULT_CONNECTION_DELAY_MILLIS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,7 +140,7 @@ public class PeerGroup {
|
||||
* @param connectionDelayMillis how long to wait between attempts to connect to nodes or read
|
||||
* from any added peer discovery sources
|
||||
*/
|
||||
public PeerGroup(final NetworkParameters params, final BlockChain chain,
|
||||
public PeerGroup(final NetworkParameters params, final AbstractBlockChain chain,
|
||||
int connectionDelayMillis) {
|
||||
this(params, chain, connectionDelayMillis, new ClientBootstrap(
|
||||
new NioClientSocketChannelFactory(
|
||||
@ -148,9 +149,10 @@ public class PeerGroup {
|
||||
bootstrap.setPipelineFactory(makePipelineFactory(params, chain));
|
||||
}
|
||||
|
||||
PeerGroup(final NetworkParameters params, final BlockChain chain,
|
||||
PeerGroup(final NetworkParameters params, final AbstractBlockChain chain,
|
||||
int connectionDelayMillis, ClientBootstrap bootstrap) {
|
||||
this.params = params;
|
||||
this.chain = chain;
|
||||
this.connectionDelayMillis = connectionDelayMillis;
|
||||
this.fastCatchupTimeSecs = params.genesisBlock.getTimeSeconds();
|
||||
this.wallets = new ArrayList<Wallet>(1);
|
||||
@ -188,7 +190,7 @@ public class PeerGroup {
|
||||
// of the higher level {@code Peer}. Received packets will first be decoded, then passed
|
||||
// {@code Peer}. Sent packets will be created by the {@code Peer}, then encoded and sent.
|
||||
private ChannelPipelineFactory makePipelineFactory(
|
||||
final NetworkParameters params, final BlockChain chain) {
|
||||
final NetworkParameters params, final AbstractBlockChain chain) {
|
||||
return new ChannelPipelineFactory() {
|
||||
public ChannelPipeline getPipeline() throws Exception {
|
||||
VersionMessage ver = getVersionMessage().duplicate();
|
||||
@ -726,6 +728,7 @@ public class PeerGroup {
|
||||
* {@link Peer#setFastCatchupTime(long)} for further explanation. Call this before starting block chain download.
|
||||
*/
|
||||
public synchronized void setFastCatchupTimeSecs(long secondsSinceEpoch) {
|
||||
Preconditions.checkState(!chain.shouldVerifyTransactions(), "Fast catchup is incompatible with fully verifying");
|
||||
fastCatchupTimeSecs = secondsSinceEpoch;
|
||||
if (downloadPeer != null) {
|
||||
downloadPeer.setFastCatchupTime(secondsSinceEpoch);
|
||||
|
Loading…
Reference in New Issue
Block a user