mirror of
https://github.com/boldsuck/haveno.git
synced 2025-01-09 09:39:23 +00:00
message handlers return synchronously
This commit is contained in:
parent
a266fab6ec
commit
7062fa9e79
2 changed files with 199 additions and 209 deletions
|
@ -227,6 +227,7 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
|
|||
@Override
|
||||
public void onDirectMessage(DecryptedMessageWithPubKey message, NodeAddress peer) {
|
||||
NetworkEnvelope networkEnvelope = message.getNetworkEnvelope();
|
||||
new Thread(() -> {
|
||||
if (networkEnvelope instanceof InitTradeRequest) {
|
||||
handleInitTradeRequest((InitTradeRequest) networkEnvelope, peer);
|
||||
} else if (networkEnvelope instanceof InitMultisigRequest) {
|
||||
|
@ -240,6 +241,7 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
|
|||
} else if (networkEnvelope instanceof DepositResponse) {
|
||||
handleDepositResponse((DepositResponse) networkEnvelope, peer);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -104,17 +104,16 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||
|
||||
protected void onTradeMessage(TradeMessage message, NodeAddress peerNodeAddress) {
|
||||
log.info("Received {} as TradeMessage from {} with tradeId {} and uid {}", message.getClass().getSimpleName(), peerNodeAddress, message.getTradeId(), message.getUid());
|
||||
if (message instanceof DepositsConfirmedMessage) {
|
||||
handle((DepositsConfirmedMessage) message, peerNodeAddress);
|
||||
} else if (message instanceof PaymentSentMessage) {
|
||||
handle((PaymentSentMessage) message, peerNodeAddress);
|
||||
} else if (message instanceof PaymentReceivedMessage) {
|
||||
handle((PaymentReceivedMessage) message, peerNodeAddress);
|
||||
}
|
||||
handle(message, peerNodeAddress);
|
||||
}
|
||||
|
||||
protected void onMailboxMessage(TradeMessage message, NodeAddress peerNodeAddress) {
|
||||
log.info("Received {} as MailboxMessage from {} with tradeId {} and uid {}", message.getClass().getSimpleName(), peerNodeAddress, message.getTradeId(), message.getUid());
|
||||
handle(message, peerNodeAddress);
|
||||
}
|
||||
|
||||
private void handle(TradeMessage message, NodeAddress peerNodeAddress) {
|
||||
new Thread(() -> {
|
||||
if (message instanceof DepositsConfirmedMessage) {
|
||||
handle((DepositsConfirmedMessage) message, peerNodeAddress);
|
||||
} else if (message instanceof PaymentSentMessage) {
|
||||
|
@ -122,6 +121,7 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||
} else if (message instanceof PaymentReceivedMessage) {
|
||||
handle((PaymentReceivedMessage) message, peerNodeAddress);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -242,7 +242,9 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||
|
||||
// handle trade events
|
||||
EasyBind.subscribe(trade.stateProperty(), state -> {
|
||||
if (state == Trade.State.DEPOSIT_TXS_CONFIRMED_IN_BLOCKCHAIN) sendDepositsConfirmedMessage();
|
||||
if (state == Trade.State.DEPOSIT_TXS_CONFIRMED_IN_BLOCKCHAIN) {
|
||||
new Thread(() -> sendDepositsConfirmedMessage()).start();
|
||||
}
|
||||
});
|
||||
|
||||
// initialize trade
|
||||
|
@ -256,7 +258,6 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||
|
||||
public void handleInitMultisigRequest(InitMultisigRequest request, NodeAddress sender) {
|
||||
System.out.println(getClass().getSimpleName() + ".handleInitMultisigRequest()");
|
||||
new Thread(() -> {
|
||||
synchronized (trade) {
|
||||
latchTrade();
|
||||
Validator.checkTradeId(processModel.getOfferId(), request);
|
||||
|
@ -279,12 +280,10 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||
.executeTasks(true);
|
||||
awaitTradeLatch();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void handleSignContractRequest(SignContractRequest message, NodeAddress sender) {
|
||||
System.out.println(getClass().getSimpleName() + ".handleSignContractRequest() " + trade.getId());
|
||||
new Thread(() -> {
|
||||
synchronized (trade) {
|
||||
Validator.checkTradeId(processModel.getOfferId(), message);
|
||||
if (trade.getState() == Trade.State.MULTISIG_COMPLETED || trade.getState() == Trade.State.CONTRACT_SIGNATURE_REQUESTED) {
|
||||
|
@ -315,12 +314,10 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||
});
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void handleSignContractResponse(SignContractResponse message, NodeAddress sender) {
|
||||
System.out.println(getClass().getSimpleName() + ".handleSignContractResponse() " + trade.getId());
|
||||
new Thread(() -> {
|
||||
synchronized (trade) {
|
||||
Validator.checkTradeId(processModel.getOfferId(), message);
|
||||
if (trade.getState() == Trade.State.CONTRACT_SIGNED) {
|
||||
|
@ -352,12 +349,10 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||
});
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void handleDepositResponse(DepositResponse response, NodeAddress sender) {
|
||||
System.out.println(getClass().getSimpleName() + ".handleDepositResponse()");
|
||||
new Thread(() -> {
|
||||
synchronized (trade) {
|
||||
latchTrade();
|
||||
Validator.checkTradeId(processModel.getOfferId(), response);
|
||||
|
@ -382,12 +377,10 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||
.executeTasks(true);
|
||||
awaitTradeLatch();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void handle(DepositsConfirmedMessage response, NodeAddress sender) {
|
||||
System.out.println(getClass().getSimpleName() + ".handle(DepositsConfirmedMessage)");
|
||||
new Thread(() -> {
|
||||
synchronized (trade) {
|
||||
latchTrade();
|
||||
expect(new Condition(trade)
|
||||
|
@ -404,7 +397,6 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||
.executeTasks();
|
||||
awaitTradeLatch();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
// received by seller and arbitrator
|
||||
|
@ -414,7 +406,6 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||
log.warn("Ignoring PaymentSentMessage since not seller or arbitrator");
|
||||
return;
|
||||
}
|
||||
new Thread(() -> {
|
||||
// We are more tolerant with expected phase and allow also DEPOSITS_PUBLISHED as it can be the case
|
||||
// that the wallet is still syncing and so the DEPOSITS_CONFIRMED state to yet triggered when we received
|
||||
// a mailbox message with PaymentSentMessage.
|
||||
|
@ -450,7 +441,6 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||
.executeTasks(true);
|
||||
awaitTradeLatch();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
// received by buyer and arbitrator
|
||||
|
@ -761,7 +751,6 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||
}
|
||||
|
||||
private void sendDepositsConfirmedMessage() {
|
||||
new Thread(() -> {
|
||||
synchronized (trade) {
|
||||
latchTrade();
|
||||
expect(new Condition(trade))
|
||||
|
@ -776,6 +765,5 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||
.executeTasks(true);
|
||||
awaitTradeLatch();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue