mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-05-16 21:42:26 -04:00
Renamed MailMessage to DirectMessage
This commit is contained in:
parent
602c503cea
commit
7b87c39ffd
33 changed files with 210 additions and 189 deletions
|
@ -18,7 +18,7 @@
|
|||
package io.bitsquare.arbitration;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.arbitration.messages.DisputeMailMessage;
|
||||
import io.bitsquare.arbitration.messages.DisputeDirectMessage;
|
||||
import io.bitsquare.common.crypto.PubKeyRing;
|
||||
import io.bitsquare.storage.Storage;
|
||||
import io.bitsquare.trade.Contract;
|
||||
|
@ -69,13 +69,13 @@ public class Dispute implements Serializable {
|
|||
private final PubKeyRing arbitratorPubKeyRing;
|
||||
private final boolean isSupportTicket;
|
||||
|
||||
private final List<DisputeMailMessage> disputeMailMessages = new ArrayList<>();
|
||||
private final List<DisputeDirectMessage> disputeDirectMessages = new ArrayList<>();
|
||||
|
||||
private boolean isClosed;
|
||||
private DisputeResult disputeResult;
|
||||
|
||||
transient private Storage<DisputeList<Dispute>> storage;
|
||||
transient private ObservableList<DisputeMailMessage> disputeMailMessagesAsObservableList = FXCollections.observableArrayList(disputeMailMessages);
|
||||
transient private ObservableList<DisputeDirectMessage> disputeDirectMessagesAsObservableList = FXCollections.observableArrayList(disputeDirectMessages);
|
||||
transient private BooleanProperty isClosedProperty = new SimpleBooleanProperty(isClosed);
|
||||
transient private ObjectProperty<DisputeResult> disputeResultProperty = new SimpleObjectProperty<>(disputeResult);
|
||||
|
||||
|
@ -126,7 +126,7 @@ public class Dispute implements Serializable {
|
|||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
try {
|
||||
in.defaultReadObject();
|
||||
disputeMailMessagesAsObservableList = FXCollections.observableArrayList(disputeMailMessages);
|
||||
disputeDirectMessagesAsObservableList = FXCollections.observableArrayList(disputeDirectMessages);
|
||||
disputeResultProperty = new SimpleObjectProperty<>(disputeResult);
|
||||
isClosedProperty = new SimpleBooleanProperty(isClosed);
|
||||
} catch (Throwable t) {
|
||||
|
@ -134,13 +134,13 @@ public class Dispute implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
public void addDisputeMessage(DisputeMailMessage disputeMailMessage) {
|
||||
if (!disputeMailMessages.contains(disputeMailMessage)) {
|
||||
disputeMailMessages.add(disputeMailMessage);
|
||||
disputeMailMessagesAsObservableList.add(disputeMailMessage);
|
||||
public void addDisputeMessage(DisputeDirectMessage disputeDirectMessage) {
|
||||
if (!disputeDirectMessages.contains(disputeDirectMessage)) {
|
||||
disputeDirectMessages.add(disputeDirectMessage);
|
||||
disputeDirectMessagesAsObservableList.add(disputeDirectMessage);
|
||||
storage.queueUpForSave();
|
||||
} else {
|
||||
log.error("disputeMailMessage already exists");
|
||||
log.error("disputeDirectMessage already exists");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,8 +234,8 @@ public class Dispute implements Serializable {
|
|||
return takerContractSignature;
|
||||
}
|
||||
|
||||
public ObservableList<DisputeMailMessage> getDisputeMailMessagesAsObservableList() {
|
||||
return disputeMailMessagesAsObservableList;
|
||||
public ObservableList<DisputeDirectMessage> getDisputeDirectMessagesAsObservableList() {
|
||||
return disputeDirectMessagesAsObservableList;
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
|
@ -298,7 +298,7 @@ public class Dispute implements Serializable {
|
|||
return false;
|
||||
if (arbitratorPubKeyRing != null ? !arbitratorPubKeyRing.equals(dispute.arbitratorPubKeyRing) : dispute.arbitratorPubKeyRing != null)
|
||||
return false;
|
||||
if (disputeMailMessages != null ? !disputeMailMessages.equals(dispute.disputeMailMessages) : dispute.disputeMailMessages != null)
|
||||
if (disputeDirectMessages != null ? !disputeDirectMessages.equals(dispute.disputeDirectMessages) : dispute.disputeDirectMessages != null)
|
||||
return false;
|
||||
return !(disputeResult != null ? !disputeResult.equals(dispute.disputeResult) : dispute.disputeResult != null);
|
||||
|
||||
|
@ -324,7 +324,7 @@ public class Dispute implements Serializable {
|
|||
result = 31 * result + (takerContractSignature != null ? takerContractSignature.hashCode() : 0);
|
||||
result = 31 * result + (arbitratorPubKeyRing != null ? arbitratorPubKeyRing.hashCode() : 0);
|
||||
result = 31 * result + (isSupportTicket ? 1 : 0);
|
||||
result = 31 * result + (disputeMailMessages != null ? disputeMailMessages.hashCode() : 0);
|
||||
result = 31 * result + (disputeDirectMessages != null ? disputeDirectMessages.hashCode() : 0);
|
||||
result = 31 * result + (isClosed ? 1 : 0);
|
||||
result = 31 * result + (disputeResult != null ? disputeResult.hashCode() : 0);
|
||||
return result;
|
||||
|
@ -344,8 +344,8 @@ public class Dispute implements Serializable {
|
|||
", buyerContractSignature='" + offererContractSignature + '\'' +
|
||||
", sellerContractSignature='" + takerContractSignature + '\'' +
|
||||
", arbitratorPubKeyRing=" + arbitratorPubKeyRing +
|
||||
", disputeMailMessages=" + disputeMailMessages +
|
||||
", disputeMailMessagesAsObservableList=" + disputeMailMessagesAsObservableList +
|
||||
", disputeDirectMessages=" + disputeDirectMessages +
|
||||
", disputeDirectMessagesAsObservableList=" + disputeDirectMessagesAsObservableList +
|
||||
", isClosed=" + isClosed +
|
||||
", disputeResult=" + disputeResult +
|
||||
", disputeResultProperty=" + disputeResultProperty +
|
||||
|
|
|
@ -19,6 +19,7 @@ package io.bitsquare.arbitration;
|
|||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.inject.Inject;
|
||||
import io.bitsquare.app.Log;
|
||||
import io.bitsquare.arbitration.messages.*;
|
||||
import io.bitsquare.btc.TradeWalletService;
|
||||
import io.bitsquare.btc.WalletService;
|
||||
|
@ -69,7 +70,7 @@ public class DisputeManager {
|
|||
private final String disputeInfo;
|
||||
private final NetWorkReadyListener netWorkReadyListener;
|
||||
private final CopyOnWriteArraySet<DecryptedMsgWithPubKey> decryptedMailboxMessageWithPubKeys = new CopyOnWriteArraySet<>();
|
||||
private final CopyOnWriteArraySet<DecryptedMsgWithPubKey> decryptedMailMessageWithPubKeys = new CopyOnWriteArraySet<>();
|
||||
private final CopyOnWriteArraySet<DecryptedMsgWithPubKey> decryptedDirectMessageWithPubKeys = new CopyOnWriteArraySet<>();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -104,8 +105,8 @@ public class DisputeManager {
|
|||
"Please read more in detail about the dispute process in our wiki:\nhttps://github" +
|
||||
".com/bitsquare/bitsquare/wiki/Dispute-process";
|
||||
|
||||
p2PService.addDecryptedMailListener((decryptedMessageWithPubKey, senderAddress) -> {
|
||||
decryptedMailMessageWithPubKeys.add(decryptedMessageWithPubKey);
|
||||
p2PService.addDecryptedDirectMessageListener((decryptedMessageWithPubKey, senderAddress) -> {
|
||||
decryptedDirectMessageWithPubKeys.add(decryptedMessageWithPubKey);
|
||||
if (p2PService.isNetworkReady())
|
||||
applyMessages();
|
||||
});
|
||||
|
@ -125,12 +126,12 @@ public class DisputeManager {
|
|||
}
|
||||
|
||||
private void applyMessages() {
|
||||
decryptedMailMessageWithPubKeys.forEach(decryptedMessageWithPubKey -> {
|
||||
decryptedDirectMessageWithPubKeys.forEach(decryptedMessageWithPubKey -> {
|
||||
Message message = decryptedMessageWithPubKey.message;
|
||||
if (message instanceof DisputeMessage)
|
||||
dispatchMessage((DisputeMessage) message);
|
||||
});
|
||||
decryptedMailMessageWithPubKeys.clear();
|
||||
decryptedDirectMessageWithPubKeys.clear();
|
||||
|
||||
decryptedMailboxMessageWithPubKeys.forEach(decryptedMessageWithPubKey -> {
|
||||
Message message = decryptedMessageWithPubKey.message;
|
||||
|
@ -159,8 +160,8 @@ public class DisputeManager {
|
|||
onOpenNewDisputeMessage((OpenNewDisputeMessage) message);
|
||||
else if (message instanceof PeerOpenedDisputeMessage)
|
||||
onPeerOpenedDisputeMessage((PeerOpenedDisputeMessage) message);
|
||||
else if (message instanceof DisputeMailMessage)
|
||||
onDisputeMailMessage((DisputeMailMessage) message);
|
||||
else if (message instanceof DisputeDirectMessage)
|
||||
onDisputeDirectMessage((DisputeDirectMessage) message);
|
||||
else if (message instanceof DisputeResultMessage)
|
||||
onDisputeResultMessage((DisputeResultMessage) message);
|
||||
else if (message instanceof PeerPublishedPayoutTxMessage)
|
||||
|
@ -169,15 +170,15 @@ public class DisputeManager {
|
|||
|
||||
public void sendOpenNewDisputeMessage(Dispute dispute) {
|
||||
if (!disputes.contains(dispute)) {
|
||||
DisputeMailMessage disputeMailMessage = new DisputeMailMessage(dispute.getTradeId(),
|
||||
DisputeDirectMessage disputeDirectMessage = new DisputeDirectMessage(dispute.getTradeId(),
|
||||
keyRing.getPubKeyRing().hashCode(),
|
||||
true,
|
||||
"System message: " + (dispute.isSupportTicket() ?
|
||||
"You opened a request for support."
|
||||
: "You opened a request for a dispute.\n\n" + disputeInfo),
|
||||
p2PService.getAddress());
|
||||
disputeMailMessage.setIsSystemMessage(true);
|
||||
dispute.addDisputeMessage(disputeMailMessage);
|
||||
disputeDirectMessage.setIsSystemMessage(true);
|
||||
dispute.addDisputeMessage(disputeDirectMessage);
|
||||
disputes.add(dispute);
|
||||
disputesObservableList.add(dispute);
|
||||
|
||||
|
@ -187,12 +188,12 @@ public class DisputeManager {
|
|||
new SendMailboxMessageListener() {
|
||||
@Override
|
||||
public void onArrived() {
|
||||
disputeMailMessage.setArrived(true);
|
||||
disputeDirectMessage.setArrived(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStoredInMailbox() {
|
||||
disputeMailMessage.setStoredInMailbox(true);
|
||||
disputeDirectMessage.setStoredInMailbox(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -231,15 +232,15 @@ public class DisputeManager {
|
|||
disputeFromOpener.getArbitratorPubKeyRing(),
|
||||
disputeFromOpener.isSupportTicket()
|
||||
);
|
||||
DisputeMailMessage disputeMailMessage = new DisputeMailMessage(dispute.getTradeId(),
|
||||
DisputeDirectMessage disputeDirectMessage = new DisputeDirectMessage(dispute.getTradeId(),
|
||||
keyRing.getPubKeyRing().hashCode(),
|
||||
true,
|
||||
"System message: " + (dispute.isSupportTicket() ?
|
||||
"Your trading peer has requested support due technical problems. Please wait for further instructions."
|
||||
: "Your trading peer has requested a dispute.\n\n" + disputeInfo),
|
||||
p2PService.getAddress());
|
||||
disputeMailMessage.setIsSystemMessage(true);
|
||||
dispute.addDisputeMessage(disputeMailMessage);
|
||||
disputeDirectMessage.setIsSystemMessage(true);
|
||||
dispute.addDisputeMessage(disputeDirectMessage);
|
||||
disputes.add(dispute);
|
||||
disputesObservableList.add(dispute);
|
||||
|
||||
|
@ -254,12 +255,12 @@ public class DisputeManager {
|
|||
new SendMailboxMessageListener() {
|
||||
@Override
|
||||
public void onArrived() {
|
||||
disputeMailMessage.setArrived(true);
|
||||
disputeDirectMessage.setArrived(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStoredInMailbox() {
|
||||
disputeMailMessage.setStoredInMailbox(true);
|
||||
disputeDirectMessage.setStoredInMailbox(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -271,22 +272,22 @@ public class DisputeManager {
|
|||
}
|
||||
|
||||
// traders send msg to the arbitrator or arbitrator to 1 trader (trader to trader is not allowed)
|
||||
public DisputeMailMessage sendDisputeMailMessage(Dispute dispute, String text, ArrayList<DisputeMailMessage.Attachment> attachments) {
|
||||
DisputeMailMessage disputeMailMessage = new DisputeMailMessage(dispute.getTradeId(),
|
||||
public DisputeDirectMessage sendDisputeDirectMessage(Dispute dispute, String text, ArrayList<DisputeDirectMessage.Attachment> attachments) {
|
||||
DisputeDirectMessage disputeDirectMessage = new DisputeDirectMessage(dispute.getTradeId(),
|
||||
dispute.getTraderPubKeyRing().hashCode(),
|
||||
isTrader(dispute),
|
||||
text,
|
||||
p2PService.getAddress());
|
||||
disputeMailMessage.addAllAttachments(attachments);
|
||||
disputeDirectMessage.addAllAttachments(attachments);
|
||||
PubKeyRing receiverPubKeyRing = null;
|
||||
NodeAddress peerNodeAddress = null;
|
||||
if (isTrader(dispute)) {
|
||||
dispute.addDisputeMessage(disputeMailMessage);
|
||||
dispute.addDisputeMessage(disputeDirectMessage);
|
||||
receiverPubKeyRing = dispute.getArbitratorPubKeyRing();
|
||||
peerNodeAddress = dispute.getContract().arbitratorNodeAddress;
|
||||
} else if (isArbitrator(dispute)) {
|
||||
if (!disputeMailMessage.isSystemMessage())
|
||||
dispute.addDisputeMessage(disputeMailMessage);
|
||||
if (!disputeDirectMessage.isSystemMessage())
|
||||
dispute.addDisputeMessage(disputeDirectMessage);
|
||||
receiverPubKeyRing = dispute.getTraderPubKeyRing();
|
||||
Contract contract = dispute.getContract();
|
||||
if (contract.getBuyerPubKeyRing().equals(receiverPubKeyRing))
|
||||
|
@ -297,19 +298,19 @@ public class DisputeManager {
|
|||
log.error("That must not happen. Trader cannot communicate to other trader.");
|
||||
}
|
||||
if (receiverPubKeyRing != null) {
|
||||
log.trace("sendDisputeMailMessage to peerAddress " + peerNodeAddress);
|
||||
log.trace("sendDisputeDirectMessage to peerAddress " + peerNodeAddress);
|
||||
p2PService.sendEncryptedMailboxMessage(peerNodeAddress,
|
||||
receiverPubKeyRing,
|
||||
disputeMailMessage,
|
||||
disputeDirectMessage,
|
||||
new SendMailboxMessageListener() {
|
||||
@Override
|
||||
public void onArrived() {
|
||||
disputeMailMessage.setArrived(true);
|
||||
disputeDirectMessage.setArrived(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStoredInMailbox() {
|
||||
disputeMailMessage.setStoredInMailbox(true);
|
||||
disputeDirectMessage.setStoredInMailbox(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -320,18 +321,18 @@ public class DisputeManager {
|
|||
);
|
||||
}
|
||||
|
||||
return disputeMailMessage;
|
||||
return disputeDirectMessage;
|
||||
}
|
||||
|
||||
// arbitrator send result to trader
|
||||
public void sendDisputeResultMessage(DisputeResult disputeResult, Dispute dispute, String text) {
|
||||
DisputeMailMessage disputeMailMessage = new DisputeMailMessage(dispute.getTradeId(),
|
||||
DisputeDirectMessage disputeDirectMessage = new DisputeDirectMessage(dispute.getTradeId(),
|
||||
dispute.getTraderPubKeyRing().hashCode(),
|
||||
false,
|
||||
text,
|
||||
p2PService.getAddress());
|
||||
dispute.addDisputeMessage(disputeMailMessage);
|
||||
disputeResult.setResultMailMessage(disputeMailMessage);
|
||||
dispute.addDisputeMessage(disputeDirectMessage);
|
||||
disputeResult.setDisputeDirectMessage(disputeDirectMessage);
|
||||
|
||||
NodeAddress peerNodeAddress;
|
||||
Contract contract = dispute.getContract();
|
||||
|
@ -345,12 +346,12 @@ public class DisputeManager {
|
|||
new SendMailboxMessageListener() {
|
||||
@Override
|
||||
public void onArrived() {
|
||||
disputeMailMessage.setArrived(true);
|
||||
disputeDirectMessage.setArrived(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStoredInMailbox() {
|
||||
disputeMailMessage.setStoredInMailbox(true);
|
||||
disputeDirectMessage.setStoredInMailbox(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -431,17 +432,17 @@ public class DisputeManager {
|
|||
}
|
||||
|
||||
// a trader can receive a msg from the arbitrator or the arbitrator form a trader. Trader to trader is not allowed.
|
||||
private void onDisputeMailMessage(DisputeMailMessage disputeMailMessage) {
|
||||
log.debug("onDisputeMailMessage " + disputeMailMessage);
|
||||
Optional<Dispute> disputeOptional = findDispute(disputeMailMessage.getTradeId(), disputeMailMessage.getTraderId());
|
||||
private void onDisputeDirectMessage(DisputeDirectMessage disputeDirectMessage) {
|
||||
Log.traceCall("disputeDirectMessage " + disputeDirectMessage);
|
||||
Optional<Dispute> disputeOptional = findDispute(disputeDirectMessage.getTradeId(), disputeDirectMessage.getTraderId());
|
||||
if (disputeOptional.isPresent()) {
|
||||
Dispute dispute = disputeOptional.get();
|
||||
if (!dispute.getDisputeMailMessagesAsObservableList().contains(disputeMailMessage))
|
||||
dispute.addDisputeMessage(disputeMailMessage);
|
||||
if (!dispute.getDisputeDirectMessagesAsObservableList().contains(disputeDirectMessage))
|
||||
dispute.addDisputeMessage(disputeDirectMessage);
|
||||
else
|
||||
log.warn("We got a dispute mail msg what we have already stored. TradeId = " + disputeMailMessage.getTradeId());
|
||||
log.warn("We got a dispute mail msg what we have already stored. TradeId = " + disputeDirectMessage.getTradeId());
|
||||
} else {
|
||||
log.warn("We got a dispute mail msg but we don't have a matching dispute. TradeId = " + disputeMailMessage.getTradeId());
|
||||
log.warn("We got a dispute mail msg but we don't have a matching dispute. TradeId = " + disputeDirectMessage.getTradeId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -453,11 +454,11 @@ public class DisputeManager {
|
|||
if (disputeOptional.isPresent()) {
|
||||
Dispute dispute = disputeOptional.get();
|
||||
|
||||
DisputeMailMessage disputeMailMessage = disputeResult.getResultMailMessage();
|
||||
if (!dispute.getDisputeMailMessagesAsObservableList().contains(disputeMailMessage))
|
||||
dispute.addDisputeMessage(disputeMailMessage);
|
||||
DisputeDirectMessage disputeDirectMessage = disputeResult.getDisputeDirectMessage();
|
||||
if (!dispute.getDisputeDirectMessagesAsObservableList().contains(disputeDirectMessage))
|
||||
dispute.addDisputeMessage(disputeDirectMessage);
|
||||
else
|
||||
log.warn("We got a dispute mail msg what we have already stored. TradeId = " + disputeMailMessage.getTradeId());
|
||||
log.warn("We got a dispute mail msg what we have already stored. TradeId = " + disputeDirectMessage.getTradeId());
|
||||
|
||||
dispute.setIsClosed(true);
|
||||
if (tradeManager.getTradeById(dispute.getTradeId()).isPresent())
|
||||
|
@ -529,11 +530,11 @@ public class DisputeManager {
|
|||
log.warn("We got a dispute msg what we have already stored. TradeId = " + disputeResult.tradeId);
|
||||
}
|
||||
|
||||
/* DisputeMailMessage disputeMailMessage = disputeResult.getResultMailMessage();
|
||||
if (!dispute.getDisputeMailMessagesAsObservableList().contains(disputeMailMessage))
|
||||
dispute.addDisputeMessage(disputeMailMessage);
|
||||
/* DisputeMailMessage disputeDirectMessage = disputeResult.getResultMailMessage();
|
||||
if (!dispute.getDisputeMailMessagesAsObservableList().contains(disputeDirectMessage))
|
||||
dispute.addDisputeMessage(disputeDirectMessage);
|
||||
else
|
||||
log.warn("We got a dispute mail msg what we have already stored. TradeId = " + disputeMailMessage.getTradeId());*/
|
||||
log.warn("We got a dispute mail msg what we have already stored. TradeId = " + disputeDirectMessage.getTradeId());*/
|
||||
|
||||
} else {
|
||||
log.warn("We got a dispute result msg but we don't have a matching dispute. TradeId = " + disputeResult.tradeId);
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
package io.bitsquare.arbitration;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.arbitration.messages.DisputeMailMessage;
|
||||
import io.bitsquare.arbitration.messages.DisputeDirectMessage;
|
||||
import javafx.beans.property.*;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -55,7 +55,7 @@ public class DisputeResult implements Serializable {
|
|||
private boolean idVerification;
|
||||
private boolean screenCast;
|
||||
private String summaryNotes;
|
||||
private DisputeMailMessage resultMailMessage;
|
||||
private DisputeDirectMessage disputeDirectMessage;
|
||||
private byte[] arbitratorSignature;
|
||||
private long buyerPayoutAmount;
|
||||
private long sellerPayoutAmount;
|
||||
|
@ -142,12 +142,12 @@ public class DisputeResult implements Serializable {
|
|||
return summaryNotesProperty;
|
||||
}
|
||||
|
||||
public void setResultMailMessage(DisputeMailMessage resultMailMessage) {
|
||||
this.resultMailMessage = resultMailMessage;
|
||||
public void setDisputeDirectMessage(DisputeDirectMessage disputeDirectMessage) {
|
||||
this.disputeDirectMessage = disputeDirectMessage;
|
||||
}
|
||||
|
||||
public DisputeMailMessage getResultMailMessage() {
|
||||
return resultMailMessage;
|
||||
public DisputeDirectMessage getDisputeDirectMessage() {
|
||||
return disputeDirectMessage;
|
||||
}
|
||||
|
||||
public void setArbitratorSignature(byte[] arbitratorSignature) {
|
||||
|
@ -232,7 +232,7 @@ public class DisputeResult implements Serializable {
|
|||
if (tradeId != null ? !tradeId.equals(that.tradeId) : that.tradeId != null) return false;
|
||||
if (feePaymentPolicy != that.feePaymentPolicy) return false;
|
||||
if (summaryNotes != null ? !summaryNotes.equals(that.summaryNotes) : that.summaryNotes != null) return false;
|
||||
if (resultMailMessage != null ? !resultMailMessage.equals(that.resultMailMessage) : that.resultMailMessage != null)
|
||||
if (disputeDirectMessage != null ? !disputeDirectMessage.equals(that.disputeDirectMessage) : that.disputeDirectMessage != null)
|
||||
return false;
|
||||
if (!Arrays.equals(arbitratorSignature, that.arbitratorSignature)) return false;
|
||||
if (arbitratorAddressAsString != null ? !arbitratorAddressAsString.equals(that.arbitratorAddressAsString) : that.arbitratorAddressAsString != null)
|
||||
|
@ -251,7 +251,7 @@ public class DisputeResult implements Serializable {
|
|||
result = 31 * result + (idVerification ? 1 : 0);
|
||||
result = 31 * result + (screenCast ? 1 : 0);
|
||||
result = 31 * result + (summaryNotes != null ? summaryNotes.hashCode() : 0);
|
||||
result = 31 * result + (resultMailMessage != null ? resultMailMessage.hashCode() : 0);
|
||||
result = 31 * result + (disputeDirectMessage != null ? disputeDirectMessage.hashCode() : 0);
|
||||
result = 31 * result + (arbitratorSignature != null ? Arrays.hashCode(arbitratorSignature) : 0);
|
||||
result = 31 * result + (int) (buyerPayoutAmount ^ (buyerPayoutAmount >>> 32));
|
||||
result = 31 * result + (int) (sellerPayoutAmount ^ (sellerPayoutAmount >>> 32));
|
||||
|
|
|
@ -32,10 +32,10 @@ import java.util.Arrays;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public final class DisputeMailMessage extends DisputeMessage {
|
||||
public final class DisputeDirectMessage extends DisputeMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
private static final Logger log = LoggerFactory.getLogger(DisputeMailMessage.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(DisputeDirectMessage.class);
|
||||
|
||||
private final long date;
|
||||
private final String tradeId;
|
||||
|
@ -52,7 +52,7 @@ public final class DisputeMailMessage extends DisputeMessage {
|
|||
transient private BooleanProperty arrivedProperty = new SimpleBooleanProperty();
|
||||
transient private BooleanProperty storedInMailboxProperty = new SimpleBooleanProperty();
|
||||
|
||||
public DisputeMailMessage(String tradeId, int traderId, boolean senderIsTrader, String message, NodeAddress myNodeAddress) {
|
||||
public DisputeDirectMessage(String tradeId, int traderId, boolean senderIsTrader, String message, NodeAddress myNodeAddress) {
|
||||
this.tradeId = tradeId;
|
||||
this.traderId = traderId;
|
||||
this.senderIsTrader = senderIsTrader;
|
||||
|
@ -137,9 +137,9 @@ public final class DisputeMailMessage extends DisputeMessage {
|
|||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof DisputeMailMessage)) return false;
|
||||
if (!(o instanceof DisputeDirectMessage)) return false;
|
||||
|
||||
DisputeMailMessage that = (DisputeMailMessage) o;
|
||||
DisputeDirectMessage that = (DisputeDirectMessage) o;
|
||||
|
||||
if (date != that.date) return false;
|
||||
if (traderId != that.traderId) return false;
|
||||
|
@ -171,7 +171,7 @@ public final class DisputeMailMessage extends DisputeMessage {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DisputeMailMessage{" +
|
||||
return "DisputeDirectMessage{" +
|
||||
"date=" + date +
|
||||
", tradeId='" + tradeId + '\'' +
|
||||
", traderId='" + traderId + '\'' +
|
|
@ -23,7 +23,6 @@ import io.bitsquare.arbitration.ArbitratorManager;
|
|||
import io.bitsquare.btc.AddressEntry;
|
||||
import io.bitsquare.btc.TradeWalletService;
|
||||
import io.bitsquare.btc.WalletService;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.common.handlers.FaultHandler;
|
||||
import io.bitsquare.common.handlers.ResultHandler;
|
||||
|
@ -31,7 +30,7 @@ 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;
|
||||
import io.bitsquare.p2p.messaging.DecryptedDirectMessageListener;
|
||||
import io.bitsquare.p2p.messaging.DecryptedMailboxListener;
|
||||
import io.bitsquare.p2p.messaging.DecryptedMsgWithPubKey;
|
||||
import io.bitsquare.storage.Storage;
|
||||
|
@ -62,7 +61,6 @@ import javax.inject.Named;
|
|||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static io.bitsquare.util.Validator.nonEmptyStringOf;
|
||||
|
||||
|
@ -114,9 +112,9 @@ public class TradeManager {
|
|||
tradableListStorage = new Storage<>(storageDir);
|
||||
this.trades = new TradableList<>(tradableListStorage, "PendingTrades");
|
||||
|
||||
p2PService.addDecryptedMailListener(new DecryptedMailListener() {
|
||||
p2PService.addDecryptedDirectMessageListener(new DecryptedDirectMessageListener() {
|
||||
@Override
|
||||
public void onMailMessage(DecryptedMsgWithPubKey decryptedMsgWithPubKey, NodeAddress peerNodeAddress) {
|
||||
public void onDirectMessage(DecryptedMsgWithPubKey decryptedMsgWithPubKey, NodeAddress peerNodeAddress) {
|
||||
Message message = decryptedMsgWithPubKey.message;
|
||||
|
||||
// Handler for incoming initial messages from taker
|
||||
|
@ -153,8 +151,8 @@ public class TradeManager {
|
|||
@Override
|
||||
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);
|
||||
// Get called after onMailboxMessageAdded from initial data request
|
||||
initPendingTrades();
|
||||
}
|
||||
};
|
||||
p2PService.addP2PServiceListener(netWorkReadyListener);
|
||||
|
|
|
@ -28,7 +28,7 @@ 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;
|
||||
import io.bitsquare.p2p.messaging.SendDirectMessageListener;
|
||||
import io.bitsquare.storage.Storage;
|
||||
import io.bitsquare.trade.TradableList;
|
||||
import io.bitsquare.trade.closed.ClosedTradableManager;
|
||||
|
@ -103,7 +103,7 @@ public class OpenOfferManager {
|
|||
"OpenOfferManager.ShutDownHook"));
|
||||
|
||||
// Handler for incoming offer availability requests
|
||||
p2PService.addDecryptedMailListener((decryptedMessageWithPubKey, peersNodeAddress) -> {
|
||||
p2PService.addDecryptedDirectMessageListener((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;
|
||||
|
@ -295,10 +295,10 @@ public class OpenOfferManager {
|
|||
Optional<OpenOffer> openOfferOptional = findOpenOffer(message.offerId);
|
||||
boolean isAvailable = openOfferOptional.isPresent() && openOfferOptional.get().getState() == OpenOffer.State.AVAILABLE;
|
||||
try {
|
||||
p2PService.sendEncryptedMailMessage(sender,
|
||||
p2PService.sendEncryptedDirectMessage(sender,
|
||||
message.getPubKeyRing(),
|
||||
new OfferAvailabilityResponse(message.offerId, isAvailable),
|
||||
new SendMailMessageListener() {
|
||||
new SendDirectMessageListener() {
|
||||
@Override
|
||||
public void onArrived() {
|
||||
log.trace("OfferAvailabilityResponse successfully arrived at peer");
|
||||
|
|
|
@ -22,7 +22,7 @@ import io.bitsquare.common.handlers.ErrorMessageHandler;
|
|||
import io.bitsquare.common.handlers.ResultHandler;
|
||||
import io.bitsquare.common.taskrunner.TaskRunner;
|
||||
import io.bitsquare.p2p.Message;
|
||||
import io.bitsquare.p2p.messaging.DecryptedMailListener;
|
||||
import io.bitsquare.p2p.messaging.DecryptedDirectMessageListener;
|
||||
import io.bitsquare.trade.offer.Offer;
|
||||
import io.bitsquare.trade.protocol.availability.messages.OfferAvailabilityResponse;
|
||||
import io.bitsquare.trade.protocol.availability.messages.OfferMessage;
|
||||
|
@ -41,7 +41,7 @@ public class OfferAvailabilityProtocol {
|
|||
private final OfferAvailabilityModel model;
|
||||
private final ResultHandler resultHandler;
|
||||
private final ErrorMessageHandler errorMessageHandler;
|
||||
private final DecryptedMailListener decryptedMailListener;
|
||||
private final DecryptedDirectMessageListener decryptedDirectMessageListener;
|
||||
|
||||
private TaskRunner<OfferAvailabilityModel> taskRunner;
|
||||
private java.util.Timer timeoutTimer;
|
||||
|
@ -56,7 +56,7 @@ public class OfferAvailabilityProtocol {
|
|||
this.resultHandler = resultHandler;
|
||||
this.errorMessageHandler = errorMessageHandler;
|
||||
|
||||
decryptedMailListener = (decryptedMessageWithPubKey, peersNodeAddress) -> {
|
||||
decryptedDirectMessageListener = (decryptedMessageWithPubKey, peersNodeAddress) -> {
|
||||
Message message = decryptedMessageWithPubKey.message;
|
||||
if (message instanceof OfferMessage) {
|
||||
OfferMessage offerMessage = (OfferMessage) message;
|
||||
|
@ -72,7 +72,7 @@ public class OfferAvailabilityProtocol {
|
|||
|
||||
private void cleanup() {
|
||||
stopTimeout();
|
||||
model.p2PService.removeDecryptedMailListener(decryptedMailListener);
|
||||
model.p2PService.removeDecryptedMailListener(decryptedDirectMessageListener);
|
||||
}
|
||||
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class OfferAvailabilityProtocol {
|
|||
// reset
|
||||
model.offer.setState(Offer.State.UNDEFINED);
|
||||
|
||||
model.p2PService.addDecryptedMailListener(decryptedMailListener);
|
||||
model.p2PService.addDecryptedDirectMessageListener(decryptedDirectMessageListener);
|
||||
model.setPeerNodeAddress(model.offer.getOffererNodeAddress());
|
||||
|
||||
taskRunner = new TaskRunner<>(model,
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
package io.bitsquare.trade.protocol.availability.messages;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.messaging.MailMessage;
|
||||
import io.bitsquare.p2p.messaging.DirectMessage;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
public abstract class OfferMessage implements MailMessage {
|
||||
public abstract class OfferMessage implements DirectMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ package io.bitsquare.trade.protocol.availability.tasks;
|
|||
|
||||
import io.bitsquare.common.taskrunner.Task;
|
||||
import io.bitsquare.common.taskrunner.TaskRunner;
|
||||
import io.bitsquare.p2p.messaging.SendMailMessageListener;
|
||||
import io.bitsquare.p2p.messaging.SendDirectMessageListener;
|
||||
import io.bitsquare.trade.offer.Offer;
|
||||
import io.bitsquare.trade.protocol.availability.OfferAvailabilityModel;
|
||||
import io.bitsquare.trade.protocol.availability.messages.OfferAvailabilityRequest;
|
||||
|
@ -38,10 +38,10 @@ public class SendOfferAvailabilityRequest extends Task<OfferAvailabilityModel> {
|
|||
try {
|
||||
runInterceptHook();
|
||||
|
||||
model.p2PService.sendEncryptedMailMessage(model.getPeerNodeAddress(),
|
||||
model.p2PService.sendEncryptedDirectMessage(model.getPeerNodeAddress(),
|
||||
model.offer.getPubKeyRing(),
|
||||
new OfferAvailabilityRequest(model.offer.getId(), model.getPubKeyRing()),
|
||||
new SendMailMessageListener() {
|
||||
new SendDirectMessageListener() {
|
||||
@Override
|
||||
public void onArrived() {
|
||||
complete();
|
||||
|
|
|
@ -113,7 +113,6 @@ public class ProcessModel implements Model, Serializable {
|
|||
this.p2PService = p2PService;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getter only
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -21,7 +21,7 @@ import io.bitsquare.common.UserThread;
|
|||
import io.bitsquare.common.crypto.PubKeyRing;
|
||||
import io.bitsquare.p2p.Message;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.messaging.DecryptedMailListener;
|
||||
import io.bitsquare.p2p.messaging.DecryptedDirectMessageListener;
|
||||
import io.bitsquare.p2p.messaging.DecryptedMsgWithPubKey;
|
||||
import io.bitsquare.trade.OffererTrade;
|
||||
import io.bitsquare.trade.TakerTrade;
|
||||
|
@ -41,7 +41,7 @@ public abstract class TradeProtocol {
|
|||
private static final long TIMEOUT_SEC = 30;
|
||||
|
||||
protected final ProcessModel processModel;
|
||||
private final DecryptedMailListener decryptedMailListener;
|
||||
private final DecryptedDirectMessageListener decryptedDirectMessageListener;
|
||||
protected Trade trade;
|
||||
private java.util.Timer timeoutTimer;
|
||||
|
||||
|
@ -49,7 +49,7 @@ public abstract class TradeProtocol {
|
|||
this.trade = trade;
|
||||
this.processModel = trade.getProcessModel();
|
||||
|
||||
decryptedMailListener = (decryptedMessageWithPubKey, peersNodeAddress) -> {
|
||||
decryptedDirectMessageListener = (decryptedMessageWithPubKey, peersNodeAddress) -> {
|
||||
// We check the sig only as soon we have stored the peers pubKeyRing.
|
||||
PubKeyRing tradingPeerPubKeyRing = processModel.tradingPeer.getPubKeyRing();
|
||||
PublicKey signaturePubKey = decryptedMessageWithPubKey.signaturePubKey;
|
||||
|
@ -77,7 +77,7 @@ public abstract class TradeProtocol {
|
|||
log.error("Signature used in seal message does not match the one stored with that trade for the trading peer or arbitrator.");*/
|
||||
}
|
||||
};
|
||||
processModel.getP2PService().addDecryptedMailListener(decryptedMailListener);
|
||||
processModel.getP2PService().addDecryptedDirectMessageListener(decryptedDirectMessageListener);
|
||||
}
|
||||
|
||||
public void completed() {
|
||||
|
@ -88,7 +88,7 @@ public abstract class TradeProtocol {
|
|||
log.debug("cleanup " + this);
|
||||
stopTimeout();
|
||||
|
||||
processModel.getP2PService().removeDecryptedMailListener(decryptedMailListener);
|
||||
processModel.getP2PService().removeDecryptedMailListener(decryptedDirectMessageListener);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
package io.bitsquare.trade.protocol.trade.messages;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.messaging.MailMessage;
|
||||
import io.bitsquare.p2p.messaging.DirectMessage;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
public abstract class TradeMessage implements MailMessage {
|
||||
public abstract class TradeMessage implements DirectMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ package io.bitsquare.trade.protocol.trade.tasks;
|
|||
|
||||
import io.bitsquare.common.taskrunner.Task;
|
||||
import io.bitsquare.common.taskrunner.TaskRunner;
|
||||
import io.bitsquare.p2p.messaging.DecryptedMsgWithPubKey;
|
||||
import io.bitsquare.p2p.messaging.MailboxMessage;
|
||||
import io.bitsquare.trade.Trade;
|
||||
import io.bitsquare.trade.protocol.trade.ProcessModel;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -57,4 +59,15 @@ public abstract class TradeTask extends Task<Trade> {
|
|||
trade.setErrorMessage(errorMessage);
|
||||
super.failed();
|
||||
}
|
||||
|
||||
protected void removeMailboxMessageAfterProcessing() {
|
||||
if (processModel.getTradeMessage() instanceof MailboxMessage) {
|
||||
DecryptedMsgWithPubKey mailboxMessage = trade.getMailboxMessage();
|
||||
if (mailboxMessage != null && mailboxMessage.message.equals(processModel.getTradeMessage())) {
|
||||
log.info("Remove mailboxMessage from P2P network. mailboxMessage = " + mailboxMessage);
|
||||
processModel.getP2PService().removeEntryFromMailbox(mailboxMessage);
|
||||
trade.setMailboxMessage(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,8 @@ public class ProcessFinalizePayoutTxRequest extends TradeTask {
|
|||
// update to the latest peer address of our peer if the message is correct
|
||||
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
||||
|
||||
removeMailboxMessageAfterProcessing();
|
||||
|
||||
complete();
|
||||
} catch (Throwable t) {
|
||||
failed(t);
|
||||
|
|
|
@ -57,6 +57,8 @@ public class ProcessDepositTxPublishedMessage extends TradeTask {
|
|||
// update to the latest peer address of our peer if the message is correct
|
||||
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
||||
|
||||
removeMailboxMessageAfterProcessing();
|
||||
|
||||
complete();
|
||||
} catch (Throwable t) {
|
||||
failed(t);
|
||||
|
|
|
@ -82,6 +82,8 @@ public class ProcessPayDepositRequest extends TradeTask {
|
|||
// update to the latest peer address of our peer if the payDepositRequest is correct
|
||||
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
||||
|
||||
removeMailboxMessageAfterProcessing();
|
||||
|
||||
complete();
|
||||
} catch (Throwable t) {
|
||||
failed(t);
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
package io.bitsquare.trade.protocol.trade.tasks.offerer;
|
||||
|
||||
import io.bitsquare.common.taskrunner.TaskRunner;
|
||||
import io.bitsquare.p2p.messaging.SendMailMessageListener;
|
||||
import io.bitsquare.p2p.messaging.SendDirectMessageListener;
|
||||
import io.bitsquare.trade.Trade;
|
||||
import io.bitsquare.trade.protocol.trade.messages.PublishDepositTxRequest;
|
||||
import io.bitsquare.trade.protocol.trade.tasks.TradeTask;
|
||||
|
@ -51,11 +51,11 @@ public class SendPublishDepositTxRequest extends TradeTask {
|
|||
trade.getCheckPaymentTimeAsBlockHeight()
|
||||
);
|
||||
|
||||
processModel.getP2PService().sendEncryptedMailMessage(
|
||||
processModel.getP2PService().sendEncryptedDirectMessage(
|
||||
trade.getTradingPeerNodeAddress(),
|
||||
processModel.tradingPeer.getPubKeyRing(),
|
||||
tradeMessage,
|
||||
new SendMailMessageListener() {
|
||||
new SendDirectMessageListener() {
|
||||
@Override
|
||||
public void onArrived() {
|
||||
log.trace("Message arrived at peer.");
|
||||
|
|
|
@ -51,6 +51,8 @@ public class ProcessFiatTransferStartedMessage extends TradeTask {
|
|||
// update to the latest peer address of our peer if the message is correct
|
||||
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
||||
|
||||
removeMailboxMessageAfterProcessing();
|
||||
|
||||
complete();
|
||||
} catch (Throwable t) {
|
||||
failed(t);
|
||||
|
|
|
@ -51,6 +51,8 @@ public class ProcessPayoutTxFinalizedMessage extends TradeTask {
|
|||
// update to the latest peer address of our peer if the message is correct
|
||||
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
||||
|
||||
removeMailboxMessageAfterProcessing();
|
||||
|
||||
complete();
|
||||
} catch (Throwable t) {
|
||||
failed(t);
|
||||
|
|
|
@ -22,7 +22,7 @@ import de.jensd.fx.fontawesome.AwesomeDude;
|
|||
import de.jensd.fx.fontawesome.AwesomeIcon;
|
||||
import io.bitsquare.arbitration.Dispute;
|
||||
import io.bitsquare.arbitration.DisputeManager;
|
||||
import io.bitsquare.arbitration.messages.DisputeMailMessage;
|
||||
import io.bitsquare.arbitration.messages.DisputeDirectMessage;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.gui.common.view.ActivatableView;
|
||||
|
@ -79,12 +79,12 @@ public class TraderDisputeView extends ActivatableView<VBox, Void> {
|
|||
private final ContractPopup contractPopup;
|
||||
private final TradeDetailsPopup tradeDetailsPopup;
|
||||
|
||||
private final List<DisputeMailMessage.Attachment> tempAttachments = new ArrayList<>();
|
||||
private final List<DisputeDirectMessage.Attachment> tempAttachments = new ArrayList<>();
|
||||
|
||||
private TableView<Dispute> disputesTable;
|
||||
private Dispute selectedDispute;
|
||||
private ChangeListener<Dispute> disputeChangeListener;
|
||||
private ListView<DisputeMailMessage> messageListView;
|
||||
private ListView<DisputeDirectMessage> messageListView;
|
||||
private TextArea inputTextArea;
|
||||
private AnchorPane messagesAnchorPane;
|
||||
private VBox messagesInputBox;
|
||||
|
@ -173,7 +173,7 @@ public class TraderDisputeView extends ActivatableView<VBox, Void> {
|
|||
}
|
||||
|
||||
private void onSendMessage(String inputText, Dispute dispute) {
|
||||
DisputeMailMessage disputeMailMessage = disputeManager.sendDisputeMailMessage(dispute, inputText, new ArrayList<>(tempAttachments));
|
||||
DisputeDirectMessage disputeDirectMessage = disputeManager.sendDisputeDirectMessage(dispute, inputText, new ArrayList<>(tempAttachments));
|
||||
tempAttachments.clear();
|
||||
scrollToBottom();
|
||||
|
||||
|
@ -190,12 +190,12 @@ public class TraderDisputeView extends ActivatableView<VBox, Void> {
|
|||
sendMsgProgressIndicator.setManaged(true);
|
||||
});
|
||||
|
||||
disputeMailMessage.arrivedProperty().addListener((observable, oldValue, newValue) -> {
|
||||
disputeDirectMessage.arrivedProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue) {
|
||||
hideSendMsgInfo(timer);
|
||||
}
|
||||
});
|
||||
disputeMailMessage.storedInMailboxProperty().addListener((observable, oldValue, newValue) -> {
|
||||
disputeDirectMessage.storedInMailboxProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue) {
|
||||
sendMsgInfoLabel.setVisible(true);
|
||||
sendMsgInfoLabel.setManaged(true);
|
||||
|
@ -235,7 +235,7 @@ public class TraderDisputeView extends ActivatableView<VBox, Void> {
|
|||
try (InputStream inputStream = url.openStream()) {
|
||||
byte[] filesAsBytes = ByteStreams.toByteArray(inputStream);
|
||||
if (filesAsBytes.length <= Connection.getMaxMsgSize()) {
|
||||
tempAttachments.add(new DisputeMailMessage.Attachment(result.getName(), filesAsBytes));
|
||||
tempAttachments.add(new DisputeDirectMessage.Attachment(result.getName(), filesAsBytes));
|
||||
inputTextArea.setText(inputTextArea.getText() + "\n[Attachment " + result.getName() + "]");
|
||||
} else {
|
||||
new Popup().error("The max. allowed file size is 100 kB.").show();
|
||||
|
@ -254,7 +254,7 @@ public class TraderDisputeView extends ActivatableView<VBox, Void> {
|
|||
}
|
||||
}
|
||||
|
||||
private void onOpenAttachment(DisputeMailMessage.Attachment attachment) {
|
||||
private void onOpenAttachment(DisputeDirectMessage.Attachment attachment) {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle("Save file to disk");
|
||||
fileChooser.setInitialFileName(attachment.getFileName());
|
||||
|
@ -290,10 +290,10 @@ public class TraderDisputeView extends ActivatableView<VBox, Void> {
|
|||
AnchorPane.setBottomAnchor(tableGroupHeadline, 0d);
|
||||
AnchorPane.setLeftAnchor(tableGroupHeadline, 0d);
|
||||
|
||||
ObservableList<DisputeMailMessage> list = dispute.getDisputeMailMessagesAsObservableList();
|
||||
SortedList<DisputeMailMessage> sortedList = new SortedList<>(list);
|
||||
ObservableList<DisputeDirectMessage> list = dispute.getDisputeDirectMessagesAsObservableList();
|
||||
SortedList<DisputeDirectMessage> sortedList = new SortedList<>(list);
|
||||
sortedList.setComparator((o1, o2) -> o1.getDate().compareTo(o2.getDate()));
|
||||
list.addListener((ListChangeListener<DisputeMailMessage>) c -> scrollToBottom());
|
||||
list.addListener((ListChangeListener<DisputeDirectMessage>) c -> scrollToBottom());
|
||||
messageListView = new ListView<>(sortedList);
|
||||
messageListView.setId("message-list-view");
|
||||
messageListView.prefWidthProperty().bind(root.widthProperty());
|
||||
|
@ -368,10 +368,10 @@ public class TraderDisputeView extends ActivatableView<VBox, Void> {
|
|||
messagesAnchorPane.getChildren().addAll(tableGroupHeadline, messageListView);
|
||||
}
|
||||
|
||||
messageListView.setCellFactory(new Callback<ListView<DisputeMailMessage>, ListCell<DisputeMailMessage>>() {
|
||||
messageListView.setCellFactory(new Callback<ListView<DisputeDirectMessage>, ListCell<DisputeDirectMessage>>() {
|
||||
@Override
|
||||
public ListCell<DisputeMailMessage> call(ListView<DisputeMailMessage> list) {
|
||||
return new ListCell<DisputeMailMessage>() {
|
||||
public ListCell<DisputeDirectMessage> call(ListView<DisputeDirectMessage> list) {
|
||||
return new ListCell<DisputeDirectMessage>() {
|
||||
final Pane bg = new Pane();
|
||||
final ImageView arrow = new ImageView();
|
||||
final Label headerLabel = new Label();
|
||||
|
@ -395,7 +395,7 @@ public class TraderDisputeView extends ActivatableView<VBox, Void> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateItem(final DisputeMailMessage item, boolean empty) {
|
||||
public void updateItem(final DisputeDirectMessage item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
|
||||
if (item != null && !empty) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import io.bitsquare.p2p.network.messages.SendersNodeAddressMessage;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class DirectMessage implements MailboxMessage, SendersNodeAddressMessage {
|
||||
public final class PrefixedSealedAndSignedMessage implements MailboxMessage, SendersNodeAddressMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
@ -17,7 +17,7 @@ public final class DirectMessage implements MailboxMessage, SendersNodeAddressMe
|
|||
public final SealedAndSigned sealedAndSigned;
|
||||
public final byte[] addressPrefixHash;
|
||||
|
||||
public DirectMessage(NodeAddress senderNodeAddress, SealedAndSigned sealedAndSigned, byte[] addressPrefixHash) {
|
||||
public PrefixedSealedAndSignedMessage(NodeAddress senderNodeAddress, SealedAndSigned sealedAndSigned, byte[] addressPrefixHash) {
|
||||
this.senderNodeAddress = senderNodeAddress;
|
||||
this.sealedAndSigned = sealedAndSigned;
|
||||
this.addressPrefixHash = addressPrefixHash;
|
|
@ -12,8 +12,8 @@ import io.bitsquare.common.UserThread;
|
|||
import io.bitsquare.common.crypto.CryptoException;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.common.crypto.PubKeyRing;
|
||||
import io.bitsquare.crypto.DirectMessage;
|
||||
import io.bitsquare.crypto.EncryptionService;
|
||||
import io.bitsquare.crypto.PrefixedSealedAndSignedMessage;
|
||||
import io.bitsquare.p2p.messaging.*;
|
||||
import io.bitsquare.p2p.network.*;
|
||||
import io.bitsquare.p2p.peers.Broadcaster;
|
||||
|
@ -66,7 +66,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private MonadicBinding<Boolean> networkReadyBinding;
|
||||
private final Set<DecryptedMailListener> decryptedMailListeners = new CopyOnWriteArraySet<>();
|
||||
private final Set<DecryptedDirectMessageListener> decryptedDirectMessageListeners = new CopyOnWriteArraySet<>();
|
||||
private final Set<DecryptedMailboxListener> decryptedMailboxListeners = new CopyOnWriteArraySet<>();
|
||||
private final Set<P2PServiceListener> p2pServiceListeners = new CopyOnWriteArraySet<>();
|
||||
private final Map<DecryptedMsgWithPubKey, ProtectedMailboxData> mailboxMap = new HashMap<>();
|
||||
|
@ -322,26 +322,26 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
|
||||
@Override
|
||||
public void onMessage(Message message, Connection connection) {
|
||||
if (message instanceof DirectMessage) {
|
||||
if (message instanceof PrefixedSealedAndSignedMessage) {
|
||||
Log.traceCall(message.toString());
|
||||
// Seed nodes don't have set the encryptionService
|
||||
if (optionalEncryptionService.isPresent()) {
|
||||
try {
|
||||
DirectMessage directMessage = (DirectMessage) message;
|
||||
if (verifyAddressPrefixHash(directMessage)) {
|
||||
PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage = (PrefixedSealedAndSignedMessage) message;
|
||||
if (verifyAddressPrefixHash(prefixedSealedAndSignedMessage)) {
|
||||
// We set connectionType to that connection to avoid that is get closed when
|
||||
// we get too many connection attempts.
|
||||
connection.setPeerType(Connection.PeerType.DIRECT_MSG_PEER);
|
||||
|
||||
DecryptedMsgWithPubKey decryptedMsgWithPubKey = optionalEncryptionService.get().decryptAndVerify(
|
||||
directMessage.sealedAndSigned);
|
||||
prefixedSealedAndSignedMessage.sealedAndSigned);
|
||||
|
||||
log.info("\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" +
|
||||
"Decrypted SealedAndSignedMessage:\ndecryptedMsgWithPubKey={}"
|
||||
+ "\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", decryptedMsgWithPubKey);
|
||||
connection.getPeersNodeAddressOptional().ifPresent(peersNodeAddress ->
|
||||
decryptedMailListeners.stream().forEach(
|
||||
e -> e.onMailMessage(decryptedMsgWithPubKey, peersNodeAddress)));
|
||||
decryptedDirectMessageListeners.stream().forEach(
|
||||
e -> e.onDirectMessage(decryptedMsgWithPubKey, peersNodeAddress)));
|
||||
} else {
|
||||
log.info("Wrong receiverAddressMaskHash. The message is not intended for us.");
|
||||
}
|
||||
|
@ -370,49 +370,49 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// MailMessages
|
||||
// DirectMessages
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void sendEncryptedMailMessage(NodeAddress peerNodeAddress, PubKeyRing pubKeyRing, MailMessage message,
|
||||
SendMailMessageListener sendMailMessageListener) {
|
||||
public void sendEncryptedDirectMessage(NodeAddress peerNodeAddress, PubKeyRing pubKeyRing, DirectMessage message,
|
||||
SendDirectMessageListener sendDirectMessageListener) {
|
||||
Log.traceCall();
|
||||
checkNotNull(peerNodeAddress, "PeerAddress must not be null (sendEncryptedMailMessage)");
|
||||
checkNotNull(peerNodeAddress, "PeerAddress must not be null (sendEncryptedDirectMessage)");
|
||||
if (isNetworkReady()) {
|
||||
doSendEncryptedMailMessage(peerNodeAddress, pubKeyRing, message, sendMailMessageListener);
|
||||
doSendEncryptedDirectMessage(peerNodeAddress, pubKeyRing, message, sendDirectMessageListener);
|
||||
} else {
|
||||
throw new NetworkNotReadyException();
|
||||
}
|
||||
}
|
||||
|
||||
private void doSendEncryptedMailMessage(@NotNull NodeAddress peersNodeAddress, PubKeyRing pubKeyRing, MailMessage message,
|
||||
SendMailMessageListener sendMailMessageListener) {
|
||||
private void doSendEncryptedDirectMessage(@NotNull NodeAddress peersNodeAddress, PubKeyRing pubKeyRing, DirectMessage message,
|
||||
SendDirectMessageListener sendDirectMessageListener) {
|
||||
Log.traceCall();
|
||||
checkNotNull(networkNode.getNodeAddress(), "My node address must not be null at doSendEncryptedMailMessage");
|
||||
checkNotNull(networkNode.getNodeAddress(), "My node address must not be null at doSendEncryptedDirectMessage");
|
||||
checkArgument(optionalEncryptionService.isPresent(), "EncryptionService not set. Seems that is called on a seed node which must not happen.");
|
||||
checkNotNull(networkNode.getNodeAddress(), "networkNode.getNodeAddress() must not be null.");
|
||||
try {
|
||||
log.info("\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" +
|
||||
"Encrypt message:\nmessage={}"
|
||||
+ "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n", message);
|
||||
DirectMessage directMessage = new DirectMessage(networkNode.getNodeAddress(),
|
||||
PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage = new PrefixedSealedAndSignedMessage(networkNode.getNodeAddress(),
|
||||
optionalEncryptionService.get().encryptAndSign(pubKeyRing, message),
|
||||
peersNodeAddress.getAddressPrefixHash());
|
||||
SettableFuture<Connection> future = networkNode.sendMessage(peersNodeAddress, directMessage);
|
||||
SettableFuture<Connection> future = networkNode.sendMessage(peersNodeAddress, prefixedSealedAndSignedMessage);
|
||||
Futures.addCallback(future, new FutureCallback<Connection>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable Connection connection) {
|
||||
sendMailMessageListener.onArrived();
|
||||
sendDirectMessageListener.onArrived();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
sendMailMessageListener.onFault();
|
||||
sendDirectMessageListener.onFault();
|
||||
}
|
||||
});
|
||||
} catch (CryptoException e) {
|
||||
e.printStackTrace();
|
||||
sendMailMessageListener.onFault();
|
||||
sendDirectMessageListener.onFault();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -428,11 +428,11 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
ExpirablePayload expirablePayload = mailboxData.expirablePayload;
|
||||
if (expirablePayload instanceof ExpirableMailboxPayload) {
|
||||
ExpirableMailboxPayload expirableMailboxPayload = (ExpirableMailboxPayload) expirablePayload;
|
||||
DirectMessage directMessage = expirableMailboxPayload.directMessage;
|
||||
if (verifyAddressPrefixHash(directMessage)) {
|
||||
PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage = expirableMailboxPayload.prefixedSealedAndSignedMessage;
|
||||
if (verifyAddressPrefixHash(prefixedSealedAndSignedMessage)) {
|
||||
try {
|
||||
DecryptedMsgWithPubKey decryptedMsgWithPubKey = optionalEncryptionService.get().decryptAndVerify(
|
||||
directMessage.sealedAndSigned);
|
||||
prefixedSealedAndSignedMessage.sealedAndSigned);
|
||||
if (decryptedMsgWithPubKey.message instanceof MailboxMessage) {
|
||||
MailboxMessage mailboxMessage = (MailboxMessage) decryptedMsgWithPubKey.message;
|
||||
NodeAddress senderNodeAddress = mailboxMessage.getSenderNodeAddress();
|
||||
|
@ -479,11 +479,11 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
log.info("\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" +
|
||||
"Encrypt message:\nmessage={}"
|
||||
+ "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n", message);
|
||||
DirectMessage directMessage = new DirectMessage(
|
||||
PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage = new PrefixedSealedAndSignedMessage(
|
||||
networkNode.getNodeAddress(),
|
||||
optionalEncryptionService.get().encryptAndSign(peersPubKeyRing, message),
|
||||
peersNodeAddress.getAddressPrefixHash());
|
||||
SettableFuture<Connection> future = networkNode.sendMessage(peersNodeAddress, directMessage);
|
||||
SettableFuture<Connection> future = networkNode.sendMessage(peersNodeAddress, prefixedSealedAndSignedMessage);
|
||||
Futures.addCallback(future, new FutureCallback<Connection>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable Connection connection) {
|
||||
|
@ -498,7 +498,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
log.info("We cannot send message to peer. Peer might be offline. We will store message in mailbox.");
|
||||
log.trace("create MailboxEntry with peerAddress " + peersNodeAddress);
|
||||
PublicKey receiverStoragePublicKey = peersPubKeyRing.getSignaturePubKey();
|
||||
addMailboxData(new ExpirableMailboxPayload(directMessage,
|
||||
addMailboxData(new ExpirableMailboxPayload(prefixedSealedAndSignedMessage,
|
||||
optionalKeyRing.get().getSignatureKeyPair().getPublic(),
|
||||
receiverStoragePublicKey),
|
||||
receiverStoragePublicKey,
|
||||
|
@ -657,12 +657,12 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
// Listeners
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void addDecryptedMailListener(DecryptedMailListener listener) {
|
||||
decryptedMailListeners.add(listener);
|
||||
public void addDecryptedDirectMessageListener(DecryptedDirectMessageListener listener) {
|
||||
decryptedDirectMessageListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeDecryptedMailListener(DecryptedMailListener listener) {
|
||||
decryptedMailListeners.remove(listener);
|
||||
public void removeDecryptedMailListener(DecryptedDirectMessageListener listener) {
|
||||
decryptedDirectMessageListeners.remove(listener);
|
||||
}
|
||||
|
||||
public void addDecryptedMailboxListener(DecryptedMailboxListener listener) {
|
||||
|
@ -715,11 +715,11 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
|||
// Private
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private boolean verifyAddressPrefixHash(DirectMessage directMessage) {
|
||||
private boolean verifyAddressPrefixHash(PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage) {
|
||||
if (networkNode.getNodeAddress() != null) {
|
||||
byte[] blurredAddressHash = networkNode.getNodeAddress().getAddressPrefixHash();
|
||||
return blurredAddressHash != null &&
|
||||
Arrays.equals(blurredAddressHash, directMessage.addressPrefixHash);
|
||||
Arrays.equals(blurredAddressHash, prefixedSealedAndSignedMessage.addressPrefixHash);
|
||||
} else {
|
||||
log.debug("myOnionAddress is null at verifyAddressPrefixHash. That is expected at startup.");
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package io.bitsquare.p2p.messaging;
|
||||
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
|
||||
public interface DecryptedDirectMessageListener {
|
||||
|
||||
void onDirectMessage(DecryptedMsgWithPubKey decryptedMsgWithPubKey, NodeAddress peerNodeAddress);
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package io.bitsquare.p2p.messaging;
|
||||
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
|
||||
public interface DecryptedMailListener {
|
||||
|
||||
void onMailMessage(DecryptedMsgWithPubKey decryptedMsgWithPubKey, NodeAddress peerNodeAddress);
|
||||
}
|
|
@ -22,7 +22,7 @@ import io.bitsquare.p2p.Message;
|
|||
|
||||
import java.security.PublicKey;
|
||||
|
||||
public final class DecryptedMsgWithPubKey implements MailMessage {
|
||||
public final class DecryptedMsgWithPubKey implements DirectMessage {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
|
|
|
@ -19,6 +19,6 @@ package io.bitsquare.p2p.messaging;
|
|||
|
||||
import io.bitsquare.p2p.Message;
|
||||
|
||||
public interface MailMessage extends Message {
|
||||
public interface DirectMessage extends Message {
|
||||
|
||||
}
|
|
@ -20,6 +20,6 @@ package io.bitsquare.p2p.messaging;
|
|||
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
|
||||
public interface MailboxMessage extends MailMessage {
|
||||
public interface MailboxMessage extends DirectMessage {
|
||||
NodeAddress getSenderNodeAddress();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.bitsquare.p2p.messaging;
|
||||
|
||||
public interface SendMailMessageListener {
|
||||
public interface SendDirectMessageListener {
|
||||
void onArrived();
|
||||
|
||||
void onFault();
|
|
@ -6,7 +6,7 @@ import io.bitsquare.app.Log;
|
|||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.ByteArrayUtils;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.crypto.DirectMessage;
|
||||
import io.bitsquare.crypto.PrefixedSealedAndSignedMessage;
|
||||
import io.bitsquare.p2p.Message;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.Utils;
|
||||
|
@ -152,7 +152,7 @@ public class Connection implements MessageListener {
|
|||
if (!stopped) {
|
||||
try {
|
||||
String peersNodeAddress = peersNodeAddressOptional.isPresent() ? peersNodeAddressOptional.get().toString() : "null";
|
||||
if (message instanceof DirectMessage && peersNodeAddressOptional.isPresent()) {
|
||||
if (message instanceof PrefixedSealedAndSignedMessage && peersNodeAddressOptional.isPresent()) {
|
||||
setPeerType(Connection.PeerType.DIRECT_MSG_PEER);
|
||||
|
||||
log.info("\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" +
|
||||
|
@ -644,7 +644,7 @@ public class Connection implements MessageListener {
|
|||
else
|
||||
connection.setPeersNodeAddress(senderNodeAddress);
|
||||
}
|
||||
if (message instanceof DirectMessage)
|
||||
if (message instanceof PrefixedSealedAndSignedMessage)
|
||||
connection.setPeerType(Connection.PeerType.DIRECT_MSG_PEER);
|
||||
|
||||
messageListener.onMessage(message, connection);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.bitsquare.p2p.storage.data;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.crypto.DirectMessage;
|
||||
import io.bitsquare.crypto.PrefixedSealedAndSignedMessage;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
|
@ -11,12 +11,12 @@ public final class ExpirableMailboxPayload implements ExpirablePayload {
|
|||
|
||||
private static final long TTL = 10 * 24 * 60 * 60 * 1000; // 10 days
|
||||
|
||||
public final DirectMessage directMessage;
|
||||
public final PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage;
|
||||
public final PublicKey senderStoragePublicKey;
|
||||
public final PublicKey receiverStoragePublicKey;
|
||||
|
||||
public ExpirableMailboxPayload(DirectMessage directMessage, PublicKey senderStoragePublicKey, PublicKey receiverStoragePublicKey) {
|
||||
this.directMessage = directMessage;
|
||||
public ExpirableMailboxPayload(PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage, PublicKey senderStoragePublicKey, PublicKey receiverStoragePublicKey) {
|
||||
this.prefixedSealedAndSignedMessage = prefixedSealedAndSignedMessage;
|
||||
this.senderStoragePublicKey = senderStoragePublicKey;
|
||||
this.receiverStoragePublicKey = receiverStoragePublicKey;
|
||||
}
|
||||
|
@ -33,20 +33,20 @@ public final class ExpirableMailboxPayload implements ExpirablePayload {
|
|||
|
||||
ExpirableMailboxPayload that = (ExpirableMailboxPayload) o;
|
||||
|
||||
return !(directMessage != null ? !directMessage.equals(that.directMessage) : that.directMessage != null);
|
||||
return !(prefixedSealedAndSignedMessage != null ? !prefixedSealedAndSignedMessage.equals(that.prefixedSealedAndSignedMessage) : that.prefixedSealedAndSignedMessage != null);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return directMessage != null ? directMessage.hashCode() : 0;
|
||||
return prefixedSealedAndSignedMessage != null ? prefixedSealedAndSignedMessage.hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MailboxEntry{" +
|
||||
"hashCode=" + hashCode() +
|
||||
", sealedAndSignedMessage=" + directMessage +
|
||||
", sealedAndSignedMessage=" + prefixedSealedAndSignedMessage +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class EncryptionServiceTests {
|
|||
public void testDecryptAndVerifyMessage() throws CryptoException {
|
||||
EncryptionService encryptionService = new EncryptionService(keyRing);
|
||||
TestMessage data = new TestMessage("test");
|
||||
DirectMessage encrypted = new DirectMessage(null,
|
||||
PrefixedSealedAndSignedMessage encrypted = new PrefixedSealedAndSignedMessage(null,
|
||||
encryptionService.encryptAndSign(pubKeyRing, data),
|
||||
Hash.getHash("aa"));
|
||||
DecryptedMsgWithPubKey decrypted = encryptionService.decryptAndVerify(encrypted.sealedAndSigned);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package io.bitsquare.p2p;
|
||||
|
||||
import io.bitsquare.common.crypto.*;
|
||||
import io.bitsquare.crypto.DirectMessage;
|
||||
import io.bitsquare.crypto.EncryptionService;
|
||||
import io.bitsquare.crypto.PrefixedSealedAndSignedMessage;
|
||||
import io.bitsquare.p2p.messaging.DecryptedMsgWithPubKey;
|
||||
import io.bitsquare.p2p.messaging.MailboxMessage;
|
||||
import io.bitsquare.p2p.messaging.SendMailboxMessageListener;
|
||||
|
@ -287,10 +287,10 @@ public class P2PServiceTest {
|
|||
MockMailboxMessage mockMessage = new MockMailboxMessage("MockMailboxMessage", p2PService2.getAddress());
|
||||
p2PService2.getNetworkNode().addMessageListener((message, connection) -> {
|
||||
log.trace("message " + message);
|
||||
if (message instanceof DirectMessage) {
|
||||
if (message instanceof PrefixedSealedAndSignedMessage) {
|
||||
try {
|
||||
DirectMessage directMessage = (DirectMessage) message;
|
||||
DecryptedMsgWithPubKey decryptedMsgWithPubKey = encryptionService2.decryptAndVerify(directMessage.sealedAndSigned);
|
||||
PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage = (PrefixedSealedAndSignedMessage) message;
|
||||
DecryptedMsgWithPubKey decryptedMsgWithPubKey = encryptionService2.decryptAndVerify(prefixedSealedAndSignedMessage.sealedAndSigned);
|
||||
Assert.assertEquals(mockMessage, decryptedMsgWithPubKey.message);
|
||||
Assert.assertEquals(p2PService2.getAddress(), ((MailboxMessage) decryptedMsgWithPubKey.message).getSenderNodeAddress());
|
||||
latch2.countDown();
|
||||
|
|
|
@ -3,8 +3,8 @@ package io.bitsquare.p2p.storage;
|
|||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.crypto.*;
|
||||
import io.bitsquare.common.util.Utilities;
|
||||
import io.bitsquare.crypto.DirectMessage;
|
||||
import io.bitsquare.crypto.EncryptionService;
|
||||
import io.bitsquare.crypto.PrefixedSealedAndSignedMessage;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.TestUtils;
|
||||
import io.bitsquare.p2p.mocks.MockMessage;
|
||||
|
@ -222,10 +222,10 @@ public class ProtectedDataStorageTest {
|
|||
KeyStoreException, IOException, CryptoException, SignatureException, InvalidKeyException, NoSuchProviderException {
|
||||
// sender
|
||||
MockMessage mockMessage = new MockMessage("MockMessage");
|
||||
DirectMessage directMessage = new DirectMessage(networkNode1.getNodeAddress(),
|
||||
PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage = new PrefixedSealedAndSignedMessage(networkNode1.getNodeAddress(),
|
||||
encryptionService1.encryptAndSign(keyRing1.getPubKeyRing(), mockMessage),
|
||||
Hash.getHash("aa"));
|
||||
ExpirableMailboxPayload expirableMailboxPayload = new ExpirableMailboxPayload(directMessage,
|
||||
ExpirableMailboxPayload expirableMailboxPayload = new ExpirableMailboxPayload(prefixedSealedAndSignedMessage,
|
||||
keyRing1.getSignatureKeyPair().getPublic(),
|
||||
keyRing2.getSignatureKeyPair().getPublic());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue