Minor requested changes (non-github batch)

This commit is contained in:
Dominykas Mostauskis 2020-02-26 14:20:40 +01:00
parent 6dec780ab4
commit a92b6ad9dc
No known key found for this signature in database
GPG Key ID: 97B407C08F2499EB
2 changed files with 32 additions and 32 deletions

View File

@ -492,8 +492,12 @@ public class BisqSetup {
// local node is detected, but badly configured.
var detectedButMisconfigured = localBitcoinNode.isDetectedButMisconfigured();
if (detectedButMisconfigured) {
displayLocalNodeMisconfigurationHandler.accept(nextStep);
return;
if (displayLocalNodeMisconfigurationHandler != null) {
displayLocalNodeMisconfigurationHandler.accept(nextStep);
return;
} else {
log.error("displayLocalNodeMisconfigurationHandler undefined", new RuntimeException());
}
}
nextStep.run();
@ -566,7 +570,8 @@ public class BisqSetup {
// We only init wallet service here if not using Tor for bitcoinj.
// When using Tor, wallet init must be deferred until Tor is ready.
if (!preferences.getUseTorForBitcoinJ()) {
// TODO encapsulate below conditional inside getUseTorForBitcoinJ
if (!preferences.getUseTorForBitcoinJ() || localBitcoinNode.willUse()) {
initWallet();
}

View File

@ -37,6 +37,8 @@ import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Level;
import org.jetbrains.annotations.NotNull;
/**
* Detects whether a Bitcoin node is running on localhost and whether it is well
* configured (meaning it's not pruning and has bloom filters enabled). The public
@ -285,10 +287,7 @@ public class LocalBitcoinNode {
var localPeerAddress = new PeerAddress(InetAddress.getLocalHost(), port);
AbstractBlockChain blockchain = null;
var peer = new Peer(networkParameters, ourVersionMessage, localPeerAddress, blockchain);
return peer;
return new Peer(networkParameters, ourVersionMessage, localPeerAddress, null);
}
/* Creates an NioClient that is expected to only be used to coerce a VersionMessage
@ -300,9 +299,8 @@ public class LocalBitcoinNode {
// This initiates the handshake procedure, which, if successful, will complete
// the peerVersionMessageFuture, or be cancelled, in case of failure.
NioClient client = new NioClient(serverAddress, peer, connectionTimeout);
return client;
return new NioClient(serverAddress, peer, connectionTimeout);
}
private static Level silence(Class<?> klass) {
@ -338,29 +336,26 @@ public class LocalBitcoinNode {
);
PeerDisconnectedEventListener cancelIfConnectionFails =
new PeerDisconnectedEventListener() {
public void onPeerDisconnected(Peer peer, int peerCount) {
var peerVersionMessageAlreadyReceived =
peerVersionMessageFuture.isDone();
if (peerVersionMessageAlreadyReceived) {
// This method is called whether or not the handshake was
// successful. In case it was successful, we don't want to do
// anything here.
return;
}
// In some cases Peer will self-disconnect after receiving
// node's VersionMessage, but before completing the handshake.
// In such a case, we want to retrieve the VersionMessage.
var peerVersionMessage = peer.getPeerVersionMessage();
if (peerVersionMessage != null) {
log.info("Handshake attempt was interrupted;"
+ " however, the local node's version message was coerced.");
peerVersionMessageFuture.set(peerVersionMessage);
} else {
log.info("Handshake attempt did not result in a version message exchange.");
var mayInterruptWhileRunning = true;
peerVersionMessageFuture.cancel(mayInterruptWhileRunning);
}
(Peer disconnectedPeer, int peerCount) -> {
var peerVersionMessageAlreadyReceived =
peerVersionMessageFuture.isDone();
if (peerVersionMessageAlreadyReceived) {
// This method is called whether or not the handshake was
// successful. In case it was successful, we don't want to do
// anything here.
return;
}
// In some cases Peer will self-disconnect after receiving
// node's VersionMessage, but before completing the handshake.
// In such a case, we want to retrieve the VersionMessage.
var peerVersionMessage = disconnectedPeer.getPeerVersionMessage();
if (peerVersionMessage != null) {
log.info("Handshake attempt was interrupted;"
+ " however, the local node's version message was coerced.");
peerVersionMessageFuture.set(peerVersionMessage);
} else {
log.info("Handshake attempt did not result in a version message exchange.");
peerVersionMessageFuture.cancel(true);
}
};