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