From 96f208f82bb26ace99453f28c43ee6fac3417d29 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 6 Mar 2017 14:49:29 -0500 Subject: [PATCH] Allow re-opening of a dispute (in case the arbitrator has not received it) --- .../DisputeAlreadyOpenException.java | 24 ++++++++++++++++++ .../bitsquare/arbitration/DisputeManager.java | 19 ++++++++------ .../MessageDeliveryFailedException.java | 24 ++++++++++++++++++ .../pendingtrades/PendingTradesDataModel.java | 25 ++++++++++++++++--- 4 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 core/src/main/java/io/bitsquare/arbitration/DisputeAlreadyOpenException.java create mode 100644 core/src/main/java/io/bitsquare/arbitration/MessageDeliveryFailedException.java diff --git a/core/src/main/java/io/bitsquare/arbitration/DisputeAlreadyOpenException.java b/core/src/main/java/io/bitsquare/arbitration/DisputeAlreadyOpenException.java new file mode 100644 index 0000000000..78fab81d05 --- /dev/null +++ b/core/src/main/java/io/bitsquare/arbitration/DisputeAlreadyOpenException.java @@ -0,0 +1,24 @@ +/* + * This file is part of Bitsquare. + * + * Bitsquare is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bitsquare is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bitsquare. If not, see . + */ + +package io.bitsquare.arbitration; + +public class DisputeAlreadyOpenException extends Exception { + public DisputeAlreadyOpenException() { + super(); + } +} diff --git a/core/src/main/java/io/bitsquare/arbitration/DisputeManager.java b/core/src/main/java/io/bitsquare/arbitration/DisputeManager.java index eb6f85bdc0..646d916670 100644 --- a/core/src/main/java/io/bitsquare/arbitration/DisputeManager.java +++ b/core/src/main/java/io/bitsquare/arbitration/DisputeManager.java @@ -31,7 +31,7 @@ import io.bitsquare.common.Timer; import io.bitsquare.common.UserThread; import io.bitsquare.common.crypto.KeyRing; import io.bitsquare.common.crypto.PubKeyRing; -import io.bitsquare.common.handlers.ErrorMessageHandler; +import io.bitsquare.common.handlers.FaultHandler; import io.bitsquare.common.handlers.ResultHandler; import io.bitsquare.crypto.DecryptedMsgWithPubKey; import io.bitsquare.p2p.BootstrapListener; @@ -183,6 +183,7 @@ public class DisputeManager { private void applyMessages() { decryptedDirectMessageWithPubKeys.forEach(decryptedMessageWithPubKey -> { Message message = decryptedMessageWithPubKey.message; + log.debug("decryptedDirectMessageWithPubKeys.message " + message); if (message instanceof DisputeMessage) dispatchMessage((DisputeMessage) message); }); @@ -214,10 +215,10 @@ public class DisputeManager { log.warn("Unsupported message at dispatchMessage.\nmessage=" + message); } - public void sendOpenNewDisputeMessage(Dispute dispute, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + public void sendOpenNewDisputeMessage(Dispute dispute, boolean reOpen, ResultHandler resultHandler, FaultHandler faultHandler) { if (!disputes.contains(dispute)) { final Optional storedDisputeOptional = findDispute(dispute.getTradeId(), dispute.getTraderId()); - if (!storedDisputeOptional.isPresent()) { + if (!storedDisputeOptional.isPresent() || reOpen) { DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(dispute.getTradeId(), keyRing.getPubKeyRing().hashCode(), true, @@ -227,8 +228,10 @@ public class DisputeManager { p2PService.getAddress()); disputeCommunicationMessage.setIsSystemMessage(true); dispute.addDisputeMessage(disputeCommunicationMessage); - disputes.add(dispute); - disputesObservableList.add(dispute); + if (!reOpen) { + disputes.add(dispute); + disputesObservableList.add(dispute); + } p2PService.sendEncryptedMailboxMessage(dispute.getContract().arbitratorNodeAddress, dispute.getArbitratorPubKeyRing(), @@ -249,7 +252,7 @@ public class DisputeManager { @Override public void onFault(String errorMessage) { log.error("sendEncryptedMessage failed"); - errorMessageHandler.handleErrorMessage("Sending dispute message failed: " + errorMessage); + faultHandler.handleFault("Sending dispute message failed: " + errorMessage, new MessageDeliveryFailedException()); } } ); @@ -257,12 +260,12 @@ public class DisputeManager { final String msg = "We got a dispute already open for that trade and trading peer.\n" + "TradeId = " + dispute.getTradeId(); log.warn(msg); - errorMessageHandler.handleErrorMessage(msg); + faultHandler.handleFault(msg, new DisputeAlreadyOpenException()); } } else { final String msg = "We got a dispute msg what we have already stored. TradeId = " + dispute.getTradeId(); log.warn(msg); - errorMessageHandler.handleErrorMessage(msg); + faultHandler.handleFault(msg, new DisputeAlreadyOpenException()); } } diff --git a/core/src/main/java/io/bitsquare/arbitration/MessageDeliveryFailedException.java b/core/src/main/java/io/bitsquare/arbitration/MessageDeliveryFailedException.java new file mode 100644 index 0000000000..0cf682a9fd --- /dev/null +++ b/core/src/main/java/io/bitsquare/arbitration/MessageDeliveryFailedException.java @@ -0,0 +1,24 @@ +/* + * This file is part of Bitsquare. + * + * Bitsquare is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bitsquare is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bitsquare. If not, see . + */ + +package io.bitsquare.arbitration; + +public class MessageDeliveryFailedException extends Exception { + public MessageDeliveryFailedException() { + super(); + } +} diff --git a/gui/src/main/java/io/bitsquare/gui/main/portfolio/pendingtrades/PendingTradesDataModel.java b/gui/src/main/java/io/bitsquare/gui/main/portfolio/pendingtrades/PendingTradesDataModel.java index 820b84550f..9830b38499 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/portfolio/pendingtrades/PendingTradesDataModel.java +++ b/gui/src/main/java/io/bitsquare/gui/main/portfolio/pendingtrades/PendingTradesDataModel.java @@ -21,6 +21,7 @@ import com.google.inject.Inject; import io.bitsquare.app.Log; import io.bitsquare.arbitration.Arbitrator; import io.bitsquare.arbitration.Dispute; +import io.bitsquare.arbitration.DisputeAlreadyOpenException; import io.bitsquare.arbitration.DisputeManager; import io.bitsquare.btc.FeePolicy; import io.bitsquare.btc.TradeWalletService; @@ -383,9 +384,7 @@ public class PendingTradesDataModel extends ActivatableDataModel { trade.setDisputeState(Trade.DisputeState.DISPUTE_REQUESTED); if (p2PService.isBootstrapped()) { - disputeManager.sendOpenNewDisputeMessage(dispute, - () -> navigation.navigateTo(MainView.class, DisputesView.class), - errorMessage -> new Popup().warning(errorMessage).show()); + sendOpenNewDisputeMessage(dispute, false); } else { new Popup().information("You need to wait until you are fully connected to the network.\n" + "That might take up to about 2 minutes at startup.").show(); @@ -394,5 +393,25 @@ public class PendingTradesDataModel extends ActivatableDataModel { log.warn("trade is null at doOpenDispute"); } } + + private void sendOpenNewDisputeMessage(Dispute dispute, boolean reOpen) { + disputeManager.sendOpenNewDisputeMessage(dispute, + reOpen, + () -> navigation.navigateTo(MainView.class, DisputesView.class), + (errorMessage, throwable) -> { + if ((throwable instanceof DisputeAlreadyOpenException)) { + errorMessage += "\n\n" + + "If you are not sure that the message to the arbitrator arrived (e.g. if you did not got " + + "a response after 1 day) feel free to open a dispute again."; + new Popup().warning(errorMessage) + .actionButtonText("Open dispute again") + .onAction(() -> sendOpenNewDisputeMessage(dispute, true)) + .closeButtonText("Cancel") + .show(); + } else { + new Popup().warning(errorMessage).show(); + } + }); + } }