From 2ad72938ec23fe1fc9637f1538535e4e795a33f0 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sun, 24 Jan 2016 20:30:33 +0100 Subject: [PATCH] Remove authentication for P2P network, UI improvements --- .../arbitration/ArbitratorManager.java | 16 +- .../bitsquare/arbitration/DisputeManager.java | 16 +- .../java/io/bitsquare/trade/TradeManager.java | 18 +- .../trade/offer/OpenOfferManager.java | 20 +- .../OfferAvailabilityProtocol.java | 4 +- .../trade/protocol/trade/TradeProtocol.java | 6 +- .../io/bitsquare/gui/main/MainViewModel.java | 31 +- .../ArbitratorRegistrationView.java | 8 +- .../ArbitratorRegistrationViewModel.java | 4 +- .../gui/main/funds/reserved/ReservedView.fxml | 2 +- .../gui/main/funds/reserved/ReservedView.java | 6 +- .../main/funds/withdrawal/WithdrawalView.fxml | 3 +- .../main/funds/withdrawal/WithdrawalView.java | 67 +- .../offer/createoffer/CreateOfferView.java | 4 +- .../createoffer/CreateOfferViewModel.java | 4 +- .../main/offer/offerbook/OfferBookView.java | 8 +- .../offer/offerbook/OfferBookViewModel.java | 4 +- .../portfolio/openoffer/OpenOffersView.java | 4 +- .../openoffer/OpenOffersViewModel.java | 4 +- .../pendingtrades/PendingTradesViewModel.java | 4 +- .../steps/ConfirmPaymentReceivedView.java | 4 +- .../pendingtrades/steps/StartPaymentView.java | 4 +- .../settings/network/NetworkSettingsView.fxml | 6 +- .../settings/network/NetworkSettingsView.java | 42 +- .../io/bitsquare/gui/util/Transitions.java | 2 +- .../p2p/AuthenticationException.java | 9 - ...istener.java => NetWorkReadyListener.java} | 4 +- .../p2p/NetworkNotReadyException.java | 9 + .../java/io/bitsquare/p2p/NodeAddress.java | 1 + .../java/io/bitsquare/p2p/P2PService.java | 439 ++++--- .../io/bitsquare/p2p/P2PServiceListener.java | 2 +- .../io/bitsquare/p2p/SeedNodeP2PService.java | 59 - .../p2p/messaging/DecryptedMsgWithPubKey.java | 1 + .../io/bitsquare/p2p/network/Connection.java | 144 ++- .../p2p/network/ConnectionPriority.java | 8 - .../bitsquare/p2p/network/IllegalRequest.java | 3 +- .../p2p/network/LocalhostNetworkNode.java | 4 +- .../io/bitsquare/p2p/network/NetworkNode.java | 93 +- .../java/io/bitsquare/p2p/network/Server.java | 4 +- .../bitsquare/p2p/network/TorNetworkNode.java | 25 +- .../p2p/peers/AuthenticationException.java | 8 - .../p2p/peers/AuthenticationHandshake.java | 357 ------ .../p2p/peers/AuthenticationListener.java | 8 - .../io/bitsquare/p2p/peers/Broadcaster.java | 60 + .../p2p/peers/PeerExchangeManager.java | 281 ++++- .../io/bitsquare/p2p/peers/PeerManager.java | 1061 ++++------------- .../p2p/peers/RequestDataManager.java | 351 +++--- .../p2p/peers/SeedNodePeerManager.java | 86 -- .../p2p/peers/SeedNodeRequestDataManager.java | 30 - .../auth/AuthenticationChallenge.java | 32 - .../auth/AuthenticationFinalResponse.java | 30 - .../messages/auth/AuthenticationMessage.java | 27 - .../auth/AuthenticationRejection.java | 19 - .../messages/auth/AuthenticationRequest.java | 24 - .../p2p/peers/messages/data/DataRequest.java | 11 +- .../java/io/bitsquare/p2p/seed/SeedNode.java | 26 +- .../p2p/seed/SeedNodesRepository.java | 23 +- .../bitsquare/p2p/storage/P2PDataStorage.java | 40 +- .../p2p/storage/data/DataAndSeqNr.java | 1 + .../java/io/bitsquare/p2p/P2PServiceTest.java | 4 +- .../test/java/io/bitsquare/p2p/TestUtils.java | 8 +- .../p2p/network/LocalhostNetworkNodeTest.java | 6 +- .../p2p/network/TorNetworkNodeTest.java | 1 + .../p2p/routing/PeerManagerTest.java | 22 +- .../p2p/storage/ProtectedDataStorageTest.java | 14 +- 65 files changed, 1351 insertions(+), 2275 deletions(-) delete mode 100644 network/src/main/java/io/bitsquare/p2p/AuthenticationException.java rename network/src/main/java/io/bitsquare/p2p/{FirstPeerAuthenticatedListener.java => NetWorkReadyListener.java} (75%) create mode 100644 network/src/main/java/io/bitsquare/p2p/NetworkNotReadyException.java delete mode 100644 network/src/main/java/io/bitsquare/p2p/SeedNodeP2PService.java delete mode 100644 network/src/main/java/io/bitsquare/p2p/network/ConnectionPriority.java delete mode 100644 network/src/main/java/io/bitsquare/p2p/peers/AuthenticationException.java delete mode 100644 network/src/main/java/io/bitsquare/p2p/peers/AuthenticationHandshake.java delete mode 100644 network/src/main/java/io/bitsquare/p2p/peers/AuthenticationListener.java create mode 100644 network/src/main/java/io/bitsquare/p2p/peers/Broadcaster.java delete mode 100644 network/src/main/java/io/bitsquare/p2p/peers/SeedNodePeerManager.java delete mode 100644 network/src/main/java/io/bitsquare/p2p/peers/SeedNodeRequestDataManager.java delete mode 100644 network/src/main/java/io/bitsquare/p2p/peers/messages/auth/AuthenticationChallenge.java delete mode 100644 network/src/main/java/io/bitsquare/p2p/peers/messages/auth/AuthenticationFinalResponse.java delete mode 100644 network/src/main/java/io/bitsquare/p2p/peers/messages/auth/AuthenticationMessage.java delete mode 100644 network/src/main/java/io/bitsquare/p2p/peers/messages/auth/AuthenticationRejection.java delete mode 100644 network/src/main/java/io/bitsquare/p2p/peers/messages/auth/AuthenticationRequest.java diff --git a/core/src/main/java/io/bitsquare/arbitration/ArbitratorManager.java b/core/src/main/java/io/bitsquare/arbitration/ArbitratorManager.java index b873048a79..296f66af4a 100644 --- a/core/src/main/java/io/bitsquare/arbitration/ArbitratorManager.java +++ b/core/src/main/java/io/bitsquare/arbitration/ArbitratorManager.java @@ -26,7 +26,7 @@ import io.bitsquare.common.crypto.KeyRing; import io.bitsquare.common.handlers.ErrorMessageHandler; import io.bitsquare.common.handlers.ResultHandler; import io.bitsquare.common.util.Utilities; -import io.bitsquare.p2p.FirstPeerAuthenticatedListener; +import io.bitsquare.p2p.NetWorkReadyListener; import io.bitsquare.p2p.NodeAddress; import io.bitsquare.p2p.P2PService; import io.bitsquare.p2p.storage.HashMapChangedListener; @@ -89,7 +89,7 @@ public class ArbitratorManager { )); private static final String publicKeyForTesting = "027a381b5333a56e1cc3d90d3a7d07f26509adf7029ed06fc997c656621f8da1ee"; private final boolean isDevTest; - private FirstPeerAuthenticatedListener firstPeerAuthenticatedListener; + private NetWorkReadyListener netWorkReadyListener; private ScheduledThreadPoolExecutor republishArbitratorExecutor; @Inject @@ -121,14 +121,14 @@ public class ArbitratorManager { if (user.getRegisteredArbitrator() != null) { P2PService p2PService = arbitratorService.getP2PService(); - if (!p2PService.isAuthenticated()) { - firstPeerAuthenticatedListener = new FirstPeerAuthenticatedListener() { + if (!p2PService.isNetworkReady()) { + netWorkReadyListener = new NetWorkReadyListener() { @Override - public void onFirstPeerAuthenticated() { + public void onBootstrapped() { republishArbitrator(); } }; - p2PService.addP2PServiceListener(firstPeerAuthenticatedListener); + p2PService.addP2PServiceListener(netWorkReadyListener); } else { republishArbitrator(); @@ -144,8 +144,8 @@ public class ArbitratorManager { } private void republishArbitrator() { - if (firstPeerAuthenticatedListener != null) - arbitratorService.getP2PService().removeP2PServiceListener(firstPeerAuthenticatedListener); + if (netWorkReadyListener != null) + arbitratorService.getP2PService().removeP2PServiceListener(netWorkReadyListener); Arbitrator registeredArbitrator = user.getRegisteredArbitrator(); if (registeredArbitrator != null) { diff --git a/core/src/main/java/io/bitsquare/arbitration/DisputeManager.java b/core/src/main/java/io/bitsquare/arbitration/DisputeManager.java index 0b35b944bf..6f24b37a08 100644 --- a/core/src/main/java/io/bitsquare/arbitration/DisputeManager.java +++ b/core/src/main/java/io/bitsquare/arbitration/DisputeManager.java @@ -26,8 +26,8 @@ import io.bitsquare.btc.exceptions.TransactionVerificationException; import io.bitsquare.btc.exceptions.WalletException; import io.bitsquare.common.crypto.KeyRing; import io.bitsquare.common.crypto.PubKeyRing; -import io.bitsquare.p2p.FirstPeerAuthenticatedListener; import io.bitsquare.p2p.Message; +import io.bitsquare.p2p.NetWorkReadyListener; import io.bitsquare.p2p.NodeAddress; import io.bitsquare.p2p.P2PService; import io.bitsquare.p2p.messaging.DecryptedMsgWithPubKey; @@ -67,7 +67,7 @@ public class DisputeManager { private final DisputeList disputes; transient private final ObservableList disputesObservableList; private final String disputeInfo; - private final FirstPeerAuthenticatedListener firstPeerAuthenticatedListener; + private final NetWorkReadyListener netWorkReadyListener; private final CopyOnWriteArraySet decryptedMailboxMessageWithPubKeys = new CopyOnWriteArraySet<>(); private final CopyOnWriteArraySet decryptedMailMessageWithPubKeys = new CopyOnWriteArraySet<>(); @@ -106,22 +106,22 @@ public class DisputeManager { p2PService.addDecryptedMailListener((decryptedMessageWithPubKey, senderAddress) -> { decryptedMailMessageWithPubKeys.add(decryptedMessageWithPubKey); - if (p2PService.isAuthenticated()) + if (p2PService.isNetworkReady()) applyMessages(); }); p2PService.addDecryptedMailboxListener((decryptedMessageWithPubKey, senderAddress) -> { decryptedMailboxMessageWithPubKeys.add(decryptedMessageWithPubKey); - if (p2PService.isAuthenticated()) + if (p2PService.isNetworkReady()) applyMessages(); }); - firstPeerAuthenticatedListener = new FirstPeerAuthenticatedListener() { + netWorkReadyListener = new NetWorkReadyListener() { @Override - public void onFirstPeerAuthenticated() { + public void onBootstrapped() { applyMessages(); } }; - p2PService.addP2PServiceListener(firstPeerAuthenticatedListener); + p2PService.addP2PServiceListener(netWorkReadyListener); } private void applyMessages() { @@ -143,7 +143,7 @@ public class DisputeManager { }); decryptedMailboxMessageWithPubKeys.clear(); - p2PService.removeP2PServiceListener(firstPeerAuthenticatedListener); + p2PService.removeP2PServiceListener(netWorkReadyListener); } diff --git a/core/src/main/java/io/bitsquare/trade/TradeManager.java b/core/src/main/java/io/bitsquare/trade/TradeManager.java index cc4fb586d7..06eb46e8e7 100644 --- a/core/src/main/java/io/bitsquare/trade/TradeManager.java +++ b/core/src/main/java/io/bitsquare/trade/TradeManager.java @@ -18,6 +18,7 @@ package io.bitsquare.trade; import com.google.common.util.concurrent.FutureCallback; +import io.bitsquare.app.Log; import io.bitsquare.arbitration.ArbitratorManager; import io.bitsquare.btc.AddressEntry; import io.bitsquare.btc.TradeWalletService; @@ -26,8 +27,8 @@ import io.bitsquare.common.UserThread; import io.bitsquare.common.crypto.KeyRing; import io.bitsquare.common.handlers.FaultHandler; import io.bitsquare.common.handlers.ResultHandler; -import io.bitsquare.p2p.FirstPeerAuthenticatedListener; import io.bitsquare.p2p.Message; +import io.bitsquare.p2p.NetWorkReadyListener; import io.bitsquare.p2p.NodeAddress; import io.bitsquare.p2p.P2PService; import io.bitsquare.p2p.messaging.DecryptedMailListener; @@ -81,7 +82,7 @@ public class TradeManager { private final Storage> tradableListStorage; private final TradableList trades; private final BooleanProperty pendingTradesInitialized = new SimpleBooleanProperty(); - private final FirstPeerAuthenticatedListener firstPeerAuthenticatedListener; + private final NetWorkReadyListener netWorkReadyListener; /////////////////////////////////////////////////////////////////////////////////////////// @@ -99,6 +100,7 @@ public class TradeManager { ArbitratorManager arbitratorManager, P2PService p2PService, @Named("storage.dir") File storageDir) { + Log.traceCall(); this.user = user; this.keyRing = keyRing; this.walletService = walletService; @@ -147,14 +149,15 @@ public class TradeManager { } }); - firstPeerAuthenticatedListener = new FirstPeerAuthenticatedListener() { + netWorkReadyListener = new NetWorkReadyListener() { @Override - public void onFirstPeerAuthenticated() { + public void onBootstrapped() { + Log.traceCall("onNetworkReady"); // give a bit delay to be sure other listeners have executed its work UserThread.runAfter(() -> initPendingTrades(), 100, TimeUnit.MILLISECONDS); } }; - p2PService.addP2PServiceListener(firstPeerAuthenticatedListener); + p2PService.addP2PServiceListener(netWorkReadyListener); } @@ -163,7 +166,8 @@ public class TradeManager { /////////////////////////////////////////////////////////////////////////////////////////// private void initPendingTrades() { - if (firstPeerAuthenticatedListener != null) p2PService.removeP2PServiceListener(firstPeerAuthenticatedListener); + Log.traceCall(); + if (netWorkReadyListener != null) p2PService.removeP2PServiceListener(netWorkReadyListener); //List failedTrades = new ArrayList<>(); for (Trade trade : trades) { @@ -178,7 +182,7 @@ public class TradeManager { trade.updateDepositTxFromWallet(tradeWalletService); initTrade(trade); - // after we are authenticated we remove mailbox messages. + // after network is ready we remove mailbox messages. DecryptedMsgWithPubKey mailboxMessage = trade.getMailboxMessage(); if (mailboxMessage != null) { log.trace("initPendingTrades/removeEntryFromMailbox mailboxMessage = " + mailboxMessage); diff --git a/core/src/main/java/io/bitsquare/trade/offer/OpenOfferManager.java b/core/src/main/java/io/bitsquare/trade/offer/OpenOfferManager.java index cc228c76bb..70b6b294dc 100644 --- a/core/src/main/java/io/bitsquare/trade/offer/OpenOfferManager.java +++ b/core/src/main/java/io/bitsquare/trade/offer/OpenOfferManager.java @@ -24,8 +24,8 @@ import io.bitsquare.common.UserThread; import io.bitsquare.common.crypto.KeyRing; import io.bitsquare.common.handlers.ErrorMessageHandler; import io.bitsquare.common.handlers.ResultHandler; -import io.bitsquare.p2p.FirstPeerAuthenticatedListener; import io.bitsquare.p2p.Message; +import io.bitsquare.p2p.NetWorkReadyListener; import io.bitsquare.p2p.NodeAddress; import io.bitsquare.p2p.P2PService; import io.bitsquare.p2p.messaging.SendMailMessageListener; @@ -67,7 +67,7 @@ public class OpenOfferManager { private final TradableList openOffers; private final Storage> openOffersStorage; private boolean shutDownRequested; - private FirstPeerAuthenticatedListener firstPeerAuthenticatedListener; + private NetWorkReadyListener netWorkReadyListener; private final Timer timer = new Timer(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -103,12 +103,12 @@ public class OpenOfferManager { "OpenOfferManager.ShutDownHook")); // Handler for incoming offer availability requests - p2PService.addDecryptedMailListener((decryptedMessageWithPubKey, peerAddress) -> { + p2PService.addDecryptedMailListener((decryptedMessageWithPubKey, peersNodeAddress) -> { // We get an encrypted message but don't do the signature check as we don't know the peer yet. // A basic sig check is in done also at decryption time Message message = decryptedMessageWithPubKey.message; if (message instanceof OfferAvailabilityRequest) - handleOfferAvailabilityRequest((OfferAvailabilityRequest) message, peerAddress); + handleOfferAvailabilityRequest((OfferAvailabilityRequest) message, peersNodeAddress); }); } @@ -126,14 +126,14 @@ public class OpenOfferManager { // Before the TTL is reached we re-publish our offers // If offer removal at shutdown fails we don't want to have long term dangling dead offers, so we set // TTL quite short and use re-publish as strategy. Offerers need to be online anyway. - if (!p2PService.isAuthenticated()) { - firstPeerAuthenticatedListener = new FirstPeerAuthenticatedListener() { + if (!p2PService.isNetworkReady()) { + netWorkReadyListener = new NetWorkReadyListener() { @Override - public void onFirstPeerAuthenticated() { + public void onBootstrapped() { startRePublishThread(); } }; - p2PService.addP2PServiceListener(firstPeerAuthenticatedListener); + p2PService.addP2PServiceListener(netWorkReadyListener); } else { startRePublishThread(); @@ -141,8 +141,8 @@ public class OpenOfferManager { } private void startRePublishThread() { - if (firstPeerAuthenticatedListener != null) - p2PService.removeP2PServiceListener(firstPeerAuthenticatedListener); + if (netWorkReadyListener != null) + p2PService.removeP2PServiceListener(netWorkReadyListener); long period = (long) (Offer.TTL * 0.8); // republish sufficiently before offer would expire TimerTask timerTask = new TimerTask() { diff --git a/core/src/main/java/io/bitsquare/trade/protocol/availability/OfferAvailabilityProtocol.java b/core/src/main/java/io/bitsquare/trade/protocol/availability/OfferAvailabilityProtocol.java index 115bf61287..de5ea23f43 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/availability/OfferAvailabilityProtocol.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/availability/OfferAvailabilityProtocol.java @@ -56,14 +56,14 @@ public class OfferAvailabilityProtocol { this.resultHandler = resultHandler; this.errorMessageHandler = errorMessageHandler; - decryptedMailListener = (decryptedMessageWithPubKey, peerAddress) -> { + decryptedMailListener = (decryptedMessageWithPubKey, peersNodeAddress) -> { Message message = decryptedMessageWithPubKey.message; if (message instanceof OfferMessage) { OfferMessage offerMessage = (OfferMessage) message; nonEmptyStringOf(offerMessage.offerId); if (message instanceof OfferAvailabilityResponse && model.offer.getId().equals(offerMessage.offerId)) { - log.trace("handle OfferAvailabilityResponse = " + message.getClass().getSimpleName() + " from " + peerAddress); + log.trace("handle OfferAvailabilityResponse = " + message.getClass().getSimpleName() + " from " + peersNodeAddress); handle((OfferAvailabilityResponse) message); } } diff --git a/core/src/main/java/io/bitsquare/trade/protocol/trade/TradeProtocol.java b/core/src/main/java/io/bitsquare/trade/protocol/trade/TradeProtocol.java index f6277cdb0c..d82802798e 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/trade/TradeProtocol.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/trade/TradeProtocol.java @@ -49,19 +49,19 @@ public abstract class TradeProtocol { this.trade = trade; this.processModel = trade.getProcessModel(); - decryptedMailListener = (decryptedMessageWithPubKey, peerAddress) -> { + decryptedMailListener = (decryptedMessageWithPubKey, peersNodeAddress) -> { // We check the sig only as soon we have stored the peers pubKeyRing. PubKeyRing tradingPeerPubKeyRing = processModel.tradingPeer.getPubKeyRing(); PublicKey signaturePubKey = decryptedMessageWithPubKey.signaturePubKey; if (tradingPeerPubKeyRing != null && signaturePubKey.equals(tradingPeerPubKeyRing.getSignaturePubKey())) { Message message = decryptedMessageWithPubKey.message; - log.trace("handleNewMessage: message = " + message.getClass().getSimpleName() + " from " + peerAddress); + log.trace("handleNewMessage: message = " + message.getClass().getSimpleName() + " from " + peersNodeAddress); if (message instanceof TradeMessage) { TradeMessage tradeMessage = (TradeMessage) message; nonEmptyStringOf(tradeMessage.tradeId); if (tradeMessage.tradeId.equals(processModel.getId())) { - doHandleDecryptedMessage(tradeMessage, peerAddress); + doHandleDecryptedMessage(tradeMessage, peersNodeAddress); } } } else { diff --git a/gui/src/main/java/io/bitsquare/gui/main/MainViewModel.java b/gui/src/main/java/io/bitsquare/gui/main/MainViewModel.java index c3b336e540..e3d56795ff 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/MainViewModel.java +++ b/gui/src/main/java/io/bitsquare/gui/main/MainViewModel.java @@ -113,7 +113,7 @@ public class MainViewModel implements ViewModel { private final User user; private int numBTCPeers = 0; private Timer checkForBtcSyncStateTimer; - private ChangeListener numAuthenticatedPeersListener, btcNumPeersListener; + private ChangeListener numConnectedPeersListener, btcNumPeersListener; private java.util.Timer numberofBtcPeersTimer; private java.util.Timer numberofP2PNetworkPeersTimer; @@ -176,8 +176,8 @@ public class MainViewModel implements ViewModel { } public void shutDown() { - if (numAuthenticatedPeersListener != null) - p2PService.getNumAuthenticatedPeers().removeListener(numAuthenticatedPeersListener); + if (numConnectedPeersListener != null) + p2PService.getNumConnectedPeers().removeListener(numConnectedPeersListener); if (btcNumPeersListener != null) walletService.numPeersProperty().removeListener(btcNumPeersListener); @@ -208,17 +208,17 @@ public class MainViewModel implements ViewModel { @Override public void onRequestingDataCompleted() { - if (p2PService.getNumAuthenticatedPeers().get() == 0) { + if (p2PService.getNumConnectedPeers().get() == 0) { p2PNetworkInfo.set("Initial data received"); } else { - updateP2pNetworkInfoWithPeersChanged(p2PService.getNumAuthenticatedPeers().get()); + updateP2pNetworkInfoWithPeersChanged(p2PService.getNumConnectedPeers().get()); } p2pNetworkInitialized.set(true); } @Override public void onNoSeedNodeAvailable() { - if (p2PService.getNumAuthenticatedPeers().get() == 0) { + if (p2PService.getNumConnectedPeers().get() == 0) { p2PNetworkInfo.set("No seed nodes available"); } p2pNetworkInitialized.set(true); @@ -226,7 +226,7 @@ public class MainViewModel implements ViewModel { @Override public void onNoPeersAvailable() { - if (p2PService.getNumAuthenticatedPeers().get() == 0) { + if (p2PService.getNumConnectedPeers().get() == 0) { p2PNetworkWarnMsg.set("There are no seed nodes or persisted peers available for requesting data.\n" + "Please check your internet connection or try to restart the application."); p2PNetworkInfo.set("No seed nodes and peers available"); @@ -236,8 +236,8 @@ public class MainViewModel implements ViewModel { } @Override - public void onFirstPeerAuthenticated() { - updateP2pNetworkInfoWithPeersChanged(p2PService.getNumAuthenticatedPeers().get()); + public void onBootstrapped() { + updateP2pNetworkInfoWithPeersChanged(p2PService.getNumConnectedPeers().get()); splashP2PNetworkProgress.set(1); } @@ -248,7 +248,7 @@ public class MainViewModel implements ViewModel { + throwable.getMessage() + ").\n" + "Please check your internet connection or try to restart the application."); splashP2PNetworkProgress.set(0); - if (p2PService.getNumAuthenticatedPeers().get() == 0) + if (p2PService.getNumConnectedPeers().get() == 0) p2PNetworkLabelId.set("splash-error-state-msg"); } }); @@ -385,14 +385,13 @@ public class MainViewModel implements ViewModel { .show(); // update nr of peers in footer - numAuthenticatedPeersListener = (observable, oldValue, newValue) -> { - + numConnectedPeersListener = (observable, oldValue, newValue) -> { if ((int) oldValue > 0 && (int) newValue == 0) { // give a bit of tolerance if (numberofP2PNetworkPeersTimer != null) numberofP2PNetworkPeersTimer.cancel(); numberofP2PNetworkPeersTimer = UserThread.runAfter(() -> { - if (p2PService.getNumAuthenticatedPeers().get() == 0) { + if (p2PService.getNumConnectedPeers().get() == 0) { p2PNetworkWarnMsg.set("You lost the connection to all P2P network peers.\n" + "Maybe you lost your internet connection or your computer was in hibernate/sleep mode."); p2PNetworkLabelId.set("splash-error-state-msg"); @@ -408,7 +407,7 @@ public class MainViewModel implements ViewModel { updateP2pNetworkInfoWithPeersChanged((int) newValue); }; - p2PService.getNumAuthenticatedPeers().addListener(numAuthenticatedPeersListener); + p2PService.getNumConnectedPeers().addListener(numConnectedPeersListener); // now show app showAppScreen.set(true); @@ -427,8 +426,8 @@ public class MainViewModel implements ViewModel { } } - private void updateP2pNetworkInfoWithPeersChanged(int numAuthenticatedPeers) { - p2PNetworkInfo.set("Nr. of connections: " + numAuthenticatedPeers); + private void updateP2pNetworkInfoWithPeersChanged(int numPeers) { + p2PNetworkInfo.set("Nr. of connections: " + numPeers); } private void displayAlertIfPresent(Alert alert) { diff --git a/gui/src/main/java/io/bitsquare/gui/main/account/arbitratorregistration/ArbitratorRegistrationView.java b/gui/src/main/java/io/bitsquare/gui/main/account/arbitratorregistration/ArbitratorRegistrationView.java index 58a2a9b5d2..21c27cc0de 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/account/arbitratorregistration/ArbitratorRegistrationView.java +++ b/gui/src/main/java/io/bitsquare/gui/main/account/arbitratorregistration/ArbitratorRegistrationView.java @@ -219,23 +219,23 @@ public class ArbitratorRegistrationView extends ActivatableViewAndModel new Popup().information("You have successfully removed your arbitrator from the P2P network.").show(), (errorMessage) -> new Popup().error("Could not remove arbitrator.\nError message: " + errorMessage).show()); } else { - new Popup().warning("You need to wait until your client is authenticated in the network.\n" + + new Popup().warning("You need to wait until your client is bootstrapped in the network.\n" + "That might take up to about 2 minutes at startup.").show(); } } private void onRegister() { - if (model.isAuthenticated()) { + if (model.isNetworkReady()) { model.onRegister( () -> new Popup().information("You have successfully registered your arbitrator to the P2P network.").show(), (errorMessage) -> new Popup().error("Could not register arbitrator.\nError message: " + errorMessage).show()); } else { - new Popup().warning("You need to wait until your client is authenticated in the network.\n" + + new Popup().warning("You need to wait until your client is bootstrapped in the network.\n" + "That might take up to about 2 minutes at startup.").show(); } } diff --git a/gui/src/main/java/io/bitsquare/gui/main/account/arbitratorregistration/ArbitratorRegistrationViewModel.java b/gui/src/main/java/io/bitsquare/gui/main/account/arbitratorregistration/ArbitratorRegistrationViewModel.java index c74900deda..1617303c1c 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/account/arbitratorregistration/ArbitratorRegistrationViewModel.java +++ b/gui/src/main/java/io/bitsquare/gui/main/account/arbitratorregistration/ArbitratorRegistrationViewModel.java @@ -183,7 +183,7 @@ class ArbitratorRegistrationViewModel extends ActivatableViewModel { revokeButtonDisabled.set(!allDataValid || myArbitratorProperty.get() == null); } - boolean isAuthenticated() { - return p2PService.isAuthenticated(); + boolean isNetworkReady() { + return p2PService.isNetworkReady(); } } diff --git a/gui/src/main/java/io/bitsquare/gui/main/funds/reserved/ReservedView.fxml b/gui/src/main/java/io/bitsquare/gui/main/funds/reserved/ReservedView.fxml index 533cfb8106..b912234187 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/funds/reserved/ReservedView.fxml +++ b/gui/src/main/java/io/bitsquare/gui/main/funds/reserved/ReservedView.fxml @@ -28,7 +28,7 @@ - + diff --git a/gui/src/main/java/io/bitsquare/gui/main/funds/reserved/ReservedView.java b/gui/src/main/java/io/bitsquare/gui/main/funds/reserved/ReservedView.java index 22a4b33234..09ab13bff8 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/funds/reserved/ReservedView.java +++ b/gui/src/main/java/io/bitsquare/gui/main/funds/reserved/ReservedView.java @@ -50,7 +50,7 @@ public class ReservedView extends ActivatableView { @FXML TableView table; @FXML - TableColumn labelColumn, addressColumn, balanceColumn, confidenceColumn; + TableColumn detailsColumn, addressColumn, balanceColumn, confidenceColumn; private final WalletService walletService; private final TradeManager tradeManager; @@ -123,8 +123,8 @@ public class ReservedView extends ActivatableView { } private void setLabelColumnCellFactory() { - labelColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper<>(addressListItem.getValue())); - labelColumn.setCellFactory(new Callback, + detailsColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper<>(addressListItem.getValue())); + detailsColumn.setCellFactory(new Callback, TableCell>() { diff --git a/gui/src/main/java/io/bitsquare/gui/main/funds/withdrawal/WithdrawalView.fxml b/gui/src/main/java/io/bitsquare/gui/main/funds/withdrawal/WithdrawalView.fxml index 4e61e63e66..04d70df55c 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/funds/withdrawal/WithdrawalView.fxml +++ b/gui/src/main/java/io/bitsquare/gui/main/funds/withdrawal/WithdrawalView.fxml @@ -29,7 +29,7 @@ - + @@ -37,6 +37,7 @@ + diff --git a/gui/src/main/java/io/bitsquare/gui/main/funds/withdrawal/WithdrawalView.java b/gui/src/main/java/io/bitsquare/gui/main/funds/withdrawal/WithdrawalView.java index 5083810da6..dc4f2b9969 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/funds/withdrawal/WithdrawalView.java +++ b/gui/src/main/java/io/bitsquare/gui/main/funds/withdrawal/WithdrawalView.java @@ -71,7 +71,7 @@ public class WithdrawalView extends ActivatableView { @FXML TextField withdrawFromTextField, withdrawToTextField, amountTextField; @FXML - TableColumn labelColumn, addressColumn, balanceColumn, confidenceColumn; + TableColumn detailsColumn, addressColumn, balanceColumn, confidenceColumn, selectColumn; private final WalletService walletService; private final TradeManager tradeManager; @@ -114,6 +114,7 @@ public class WithdrawalView extends ActivatableView { setAddressColumnCellFactory(); setBalanceColumnCellFactory(); setConfidenceColumnCellFactory(); + setSelectColumnCellFactory(); if (BitsquareApp.DEV_MODE) withdrawToTextField.setText("mxAkWWaQBqwqcYstKzqLku3kzR6pbu2zHq"); @@ -262,8 +263,8 @@ public class WithdrawalView extends ActivatableView { } private void setLabelColumnCellFactory() { - labelColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper<>(addressListItem.getValue())); - labelColumn.setCellFactory(new Callback, + detailsColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper<>(addressListItem.getValue())); + detailsColumn.setCellFactory(new Callback, TableCell>() { @@ -272,21 +273,25 @@ public class WithdrawalView extends ActivatableView { WithdrawalListItem> column) { return new TableCell() { - private Hyperlink hyperlink; - @Override public void updateItem(final WithdrawalListItem item, boolean empty) { super.updateItem(item, empty); if (item != null && !empty) { - hyperlink = new Hyperlink(item.getLabel()); - if (item.getAddressEntry().getOfferId() != null) { - Tooltip tooltip = new Tooltip(item.getAddressEntry().getShortOfferId()); - Tooltip.install(hyperlink, tooltip); + if (detailsAvailable(item)) { + Hyperlink hyperlink = new Hyperlink(item.getLabel()); + if (item.getAddressEntry().getOfferId() != null) { + Tooltip tooltip = new Tooltip(item.getAddressEntry().getShortOfferId()); + Tooltip.install(hyperlink, tooltip); - hyperlink.setOnAction(event -> openDetails(item)); + hyperlink.setOnAction(event -> openDetails(item)); + setGraphic(hyperlink); + } + } else { + Label label = new Label("No info available"); + setGraphic(label); } - setGraphic(hyperlink); + } else { setGraphic(null); setId(null); @@ -374,6 +379,42 @@ public class WithdrawalView extends ActivatableView { }); } + private void setSelectColumnCellFactory() { + selectColumn.setCellValueFactory((addressListItem) -> + new ReadOnlyObjectWrapper<>(addressListItem.getValue())); + selectColumn.setCellFactory( + new Callback, TableCell>() { + + @Override + public TableCell call(TableColumn column) { + return new TableCell() { + + Button button = new Button("Select"); + + @Override + public void updateItem(final WithdrawalListItem item, boolean empty) { + super.updateItem(item, empty); + if (item != null && !empty) { + button.setDefaultButton(true); + button.setMouseTransparent(true); + setGraphic(button); + } else { + setGraphic(null); + } + } + }; + } + }); + } + + private boolean detailsAvailable(WithdrawalListItem item) { + String offerId = item.getAddressEntry().getOfferId(); + return closedTradableManager.getTradableById(offerId).isPresent() || + failedTradesManager.getTradeById(offerId).isPresent(); + } + private void openDetails(WithdrawalListItem item) { String offerId = item.getAddressEntry().getOfferId(); Optional tradableOptional = closedTradableManager.getTradableById(offerId); @@ -384,8 +425,10 @@ public class WithdrawalView extends ActivatableView { } else if (tradable instanceof OpenOffer) { offerDetailsPopup.show(tradable.getOffer()); } + } else if (failedTradesManager.getTradeById(offerId).isPresent()) { + tradeDetailsPopup.show(failedTradesManager.getTradeById(offerId).get()); } else { - failedTradesManager.getTradeById(offerId).ifPresent(trade -> tradeDetailsPopup.show(trade)); + log.warn("no details available. A test with detailsAvailable() is missing."); } } } diff --git a/gui/src/main/java/io/bitsquare/gui/main/offer/createoffer/CreateOfferView.java b/gui/src/main/java/io/bitsquare/gui/main/offer/createoffer/CreateOfferView.java index 69cfe72e82..00aa6c5902 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/offer/createoffer/CreateOfferView.java +++ b/gui/src/main/java/io/bitsquare/gui/main/offer/createoffer/CreateOfferView.java @@ -199,7 +199,7 @@ public class CreateOfferView extends ActivatableViewAndModel model.onPlaceOffer(o)).show(offer); @@ -214,7 +214,7 @@ public class CreateOfferView extends ActivatableViewAndModel return formatter.formatDateTime(item.getOffer().getDate()); } - boolean isAuthenticated() { - return p2PService.isAuthenticated(); + boolean isNetworkReady() { + return p2PService.isNetworkReady(); } } diff --git a/gui/src/main/java/io/bitsquare/gui/main/portfolio/pendingtrades/PendingTradesViewModel.java b/gui/src/main/java/io/bitsquare/gui/main/portfolio/pendingtrades/PendingTradesViewModel.java index 3b9ea57366..77f0135006 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/portfolio/pendingtrades/PendingTradesViewModel.java +++ b/gui/src/main/java/io/bitsquare/gui/main/portfolio/pendingtrades/PendingTradesViewModel.java @@ -219,8 +219,8 @@ public class PendingTradesViewModel extends ActivatableWithDataModel