mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-18 13:22:42 +01:00
Replace peerGroup.startAsync/awaitRunning with start() and awaitTerminated with stop().
This commit is contained in:
parent
10340b13a6
commit
e7c00df740
@ -145,8 +145,7 @@ public class FilteredBlockAndPartialMerkleTreeTests extends TestWithPeerGroup {
|
||||
|
||||
blockChain.addWallet(wallet);
|
||||
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
|
||||
// Create a peer.
|
||||
InboundMessageQueuer p1 = connectPeer(1);
|
||||
|
@ -112,8 +112,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
|
||||
@Test
|
||||
public void listener() throws Exception {
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
peerGroup.addEventListener(listener);
|
||||
|
||||
// Create a couple of peers.
|
||||
@ -155,6 +154,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
return new InetSocketAddress[]{new InetSocketAddress("localhost", 1)};
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
}
|
||||
@ -196,15 +196,13 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
assertEquals(99, peerAddresses.size());
|
||||
}
|
||||
});
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveTxBroadcast() throws Exception {
|
||||
// Check that when we receive transactions on all our peers, we do the right thing.
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
|
||||
// Create a couple of peers.
|
||||
InboundMessageQueuer p1 = connectPeer(1);
|
||||
@ -241,10 +239,9 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
|
||||
|
||||
@Test
|
||||
public void receiveTxBroadcastOnAddedWallet() throws Exception {
|
||||
public void receiveTxBroadcastOnAddeweldWallet() throws Exception {
|
||||
// Check that when we receive transactions on all our peers, we do the right thing.
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
|
||||
// Create a peer.
|
||||
InboundMessageQueuer p1 = connectPeer(1);
|
||||
@ -256,8 +253,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
peerGroup.addWallet(wallet2);
|
||||
blockChain.addWallet(wallet2);
|
||||
|
||||
assertTrue(outbound(p1) instanceof BloomFilter);
|
||||
assertTrue(outbound(p1) instanceof MemoryPoolMessage);
|
||||
assertEquals(BloomFilter.class, waitForOutbound(p1).getClass());
|
||||
assertEquals(MemoryPoolMessage.class, waitForOutbound(p1).getClass());
|
||||
|
||||
Coin value = COIN;
|
||||
Transaction t1 = FakeTxBuilder.createFakeTx(unitTestParams, value, address2);
|
||||
@ -278,8 +275,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
@Test
|
||||
public void singleDownloadPeer1() throws Exception {
|
||||
// Check that we don't attempt to retrieve blocks on multiple peers.
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
|
||||
// Create a couple of peers.
|
||||
InboundMessageQueuer p1 = connectPeer(1);
|
||||
@ -322,8 +318,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
// Check that we don't attempt multiple simultaneous block chain downloads, when adding a new peer in the
|
||||
// middle of an existing chain download.
|
||||
// Create a couple of peers.
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
|
||||
// Create a couple of peers.
|
||||
InboundMessageQueuer p1 = connectPeer(1);
|
||||
@ -358,8 +353,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
public void transactionConfidence() throws Exception {
|
||||
// Checks that we correctly count how many peers broadcast a transaction, so we can establish some measure of
|
||||
// its trustworthyness assuming an untampered with internet connection.
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
|
||||
final Transaction[] event = new Transaction[2];
|
||||
peerGroup.addEventListener(new AbstractPeerEventListener() {
|
||||
@ -422,8 +416,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
// The wallet was already added to the peer in setup.
|
||||
final int WEEK = 86400 * 7;
|
||||
final long now = Utils.currentTimeSeconds();
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
assertTrue(peerGroup.getFastCatchupTimeSecs() > now - WEEK - 10000);
|
||||
Wallet w2 = new Wallet(params);
|
||||
ECKey key1 = new ECKey();
|
||||
@ -443,8 +436,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
|
||||
@Test
|
||||
public void noPings() throws Exception {
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
peerGroup.setPingIntervalMsec(0);
|
||||
VersionMessage versionMessage = new VersionMessage(params, 2);
|
||||
versionMessage.clientVersion = FilteredBlock.MIN_PROTOCOL_VERSION;
|
||||
@ -456,8 +448,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
|
||||
@Test
|
||||
public void pings() throws Exception {
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
peerGroup.setPingIntervalMsec(100);
|
||||
VersionMessage versionMessage = new VersionMessage(params, 2);
|
||||
versionMessage.clientVersion = FilteredBlock.MIN_PROTOCOL_VERSION;
|
||||
@ -475,8 +466,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
|
||||
@Test
|
||||
public void downloadPeerSelection() throws Exception {
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
VersionMessage versionMessage2 = new VersionMessage(params, 2);
|
||||
versionMessage2.clientVersion = FilteredBlock.MIN_PROTOCOL_VERSION;
|
||||
versionMessage2.localServices = VersionMessage.NODE_NETWORK;
|
||||
@ -508,8 +498,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
|
||||
@Test
|
||||
public void peerTimeoutTest() throws Exception {
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
peerGroup.setConnectTimeoutMillis(100);
|
||||
|
||||
final SettableFuture<Void> peerConnectedFuture = SettableFuture.create();
|
||||
@ -557,8 +546,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
blockJobs = true;
|
||||
|
||||
jobBlocks.release(2); // startup + first peer discovery
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
|
||||
jobBlocks.release(3); // One for each peer.
|
||||
handleConnectToPeer(0);
|
||||
@ -608,8 +596,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
// Cover bug 513. When a relevant transaction with a p2pubkey output is found, the Bloom filter should be
|
||||
// recalculated to include that transaction hash but not re-broadcast as the remote nodes should have followed
|
||||
// the same procedure. However a new node that's connected should get the fresh filter.
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
final ECKey key = wallet.currentReceiveKey();
|
||||
// Create a couple of peers.
|
||||
InboundMessageQueuer p1 = connectPeer(1);
|
||||
@ -642,8 +629,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
// we exceed the lookahead threshold.
|
||||
wallet.setKeychainLookaheadSize(5);
|
||||
wallet.setKeychainLookaheadThreshold(4);
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
// Create a couple of peers.
|
||||
InboundMessageQueuer p1 = connectPeer(1);
|
||||
InboundMessageQueuer p2 = connectPeer(2);
|
||||
@ -674,8 +660,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
@Test
|
||||
public void waitForNumPeers1() throws Exception {
|
||||
ListenableFuture<List<Peer>> future = peerGroup.waitForPeers(3);
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
assertFalse(future.isDone());
|
||||
connectPeer(1);
|
||||
assertFalse(future.isDone());
|
||||
@ -700,8 +685,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
VersionMessage ver2 = new VersionMessage(params, 10);
|
||||
ver2.clientVersion = newVer;
|
||||
ver2.localServices = VersionMessage.NODE_NETWORK;
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
assertFalse(future.isDone());
|
||||
connectPeer(1, ver1);
|
||||
assertFalse(future.isDone());
|
||||
@ -733,8 +717,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
|
||||
try {
|
||||
peerGroup.setUseLocalhostPeerWhenPossible(true);
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
local.accept().close(); // Probe connect
|
||||
local.accept(); // Real connect
|
||||
// If we get here it used the local peer. Check no others are in use.
|
||||
@ -768,8 +751,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
wallet.setKeychainLookaheadSize(4);
|
||||
wallet.setKeychainLookaheadThreshold(2);
|
||||
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
InboundMessageQueuer p1 = connectPeer(1);
|
||||
assertTrue(p1.lastReceivedFilter.contains(keys.get(0).getPubKey()));
|
||||
assertTrue(p1.lastReceivedFilter.contains(keys.get(5).getPubKeyHash()));
|
||||
|
@ -59,8 +59,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
|
||||
// Fix the random permutation that TransactionBroadcast uses to shuffle the peers.
|
||||
TransactionBroadcast.random = new Random(0);
|
||||
peerGroup.setMinBroadcastConnections(2);
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,8 +38,7 @@ public class FetchBlock {
|
||||
BlockStore blockStore = new MemoryBlockStore(params);
|
||||
BlockChain chain = new BlockChain(params, blockStore);
|
||||
PeerGroup peerGroup = new PeerGroup(params, chain);
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
PeerAddress addr = new PeerAddress(InetAddress.getLocalHost(), params.getPort());
|
||||
peerGroup.addAddress(addr);
|
||||
peerGroup.waitForPeers(1).get();
|
||||
|
@ -39,8 +39,7 @@ public class FetchTransactions {
|
||||
BlockStore blockStore = new MemoryBlockStore(params);
|
||||
BlockChain chain = new BlockChain(params, blockStore);
|
||||
PeerGroup peerGroup = new PeerGroup(params, chain);
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
peerGroup.addAddress(new PeerAddress(InetAddress.getLocalHost(), params.getPort()));
|
||||
peerGroup.waitForPeers(1).get();
|
||||
Peer peer = peerGroup.getConnectedPeers().get(0);
|
||||
@ -58,7 +57,6 @@ public class FetchTransactions {
|
||||
}
|
||||
|
||||
System.out.println("Done.");
|
||||
peerGroup.stopAsync();
|
||||
peerGroup.awaitTerminated();
|
||||
peerGroup.stop();
|
||||
}
|
||||
}
|
||||
|
@ -115,8 +115,7 @@ public class PeerMonitor {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent windowEvent) {
|
||||
System.out.println("Shutting down ...");
|
||||
peerGroup.stopAsync();
|
||||
peerGroup.awaitTerminated();
|
||||
peerGroup.stop();
|
||||
System.out.println("Shutdown complete.");
|
||||
System.exit(0);
|
||||
}
|
||||
|
@ -58,8 +58,7 @@ public class RestoreFromSeed {
|
||||
};
|
||||
|
||||
// Now we re-download the blockchain. This replays the chain into the wallet. Once this is completed our wallet should know of all its transactions and print the correct balance.
|
||||
peers.startAsync();
|
||||
peers.awaitRunning();
|
||||
peers.start();
|
||||
peers.startBlockChainDownload(bListener);
|
||||
|
||||
bListener.await();
|
||||
@ -68,8 +67,6 @@ public class RestoreFromSeed {
|
||||
System.out.println(wallet.toString());
|
||||
|
||||
// shutting down again
|
||||
peers.stopAsync();
|
||||
peers.awaitTerminated();
|
||||
|
||||
peers.stop();
|
||||
}
|
||||
}
|
||||
|
@ -80,8 +80,7 @@ public class BuildCheckpoints {
|
||||
}
|
||||
}, Threading.SAME_THREAD);
|
||||
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
peerGroup.start();
|
||||
peerGroup.downloadBlockChain();
|
||||
|
||||
checkState(checkpoints.size() > 0);
|
||||
@ -90,8 +89,7 @@ public class BuildCheckpoints {
|
||||
writeBinaryCheckpoints(checkpoints, PLAIN_CHECKPOINTS_FILE);
|
||||
writeTextualCheckpoints(checkpoints, TEXTUAL_CHECKPOINTS_FILE);
|
||||
|
||||
peerGroup.stopAsync();
|
||||
peerGroup.awaitTerminated();
|
||||
peerGroup.stop();
|
||||
store.close();
|
||||
|
||||
// Sanity check the created files.
|
||||
|
@ -445,8 +445,7 @@ public class WalletTool {
|
||||
|
||||
private static void rotate() throws BlockStoreException {
|
||||
setup();
|
||||
peers.startAsync();
|
||||
peers.awaitRunning();
|
||||
peers.start();
|
||||
// Set a key rotation time and possibly broadcast the resulting maintenance transactions.
|
||||
long rotationTimeSecs = Utils.currentTimeSeconds();
|
||||
if (options.has(dateFlag)) {
|
||||
@ -583,8 +582,7 @@ public class WalletTool {
|
||||
}
|
||||
|
||||
setup();
|
||||
peers.startAsync();
|
||||
peers.awaitRunning();
|
||||
peers.start();
|
||||
// Wait for peers to connect, the tx to be sent to one of them and for it to be propagated across the
|
||||
// network. Once propagation is complete and we heard the transaction back from all our peers, it will
|
||||
// be committed to the wallet.
|
||||
@ -700,8 +698,7 @@ public class WalletTool {
|
||||
ListenableFuture<PaymentProtocol.Ack> future = session.sendPayment(ImmutableList.of(req.tx), null, null);
|
||||
if (future == null) {
|
||||
// No payment_url for submission so, broadcast and wait.
|
||||
peers.startAsync();
|
||||
peers.awaitRunning();
|
||||
peers.start();
|
||||
peers.broadcastTransaction(req.tx).get();
|
||||
} else {
|
||||
PaymentProtocol.Ack ack = future.get();
|
||||
@ -864,8 +861,7 @@ public class WalletTool {
|
||||
setup();
|
||||
int startTransactions = wallet.getTransactions(true).size();
|
||||
DownloadListener listener = new DownloadListener();
|
||||
peers.startAsync();
|
||||
peers.awaitRunning();
|
||||
peers.start();
|
||||
peers.startBlockChainDownload(listener);
|
||||
try {
|
||||
listener.await();
|
||||
@ -886,8 +882,7 @@ public class WalletTool {
|
||||
private static void shutdown() {
|
||||
try {
|
||||
if (peers == null) return; // setup() never called so nothing to do.
|
||||
peers.stopAsync();
|
||||
peers.awaitTerminated();
|
||||
peers.stop();
|
||||
saveWallet(walletFile);
|
||||
store.close();
|
||||
wallet = null;
|
||||
|
Loading…
Reference in New Issue
Block a user