use of bisq.network.p2p.AckMessage in project bisq-core by bisq-network.
the class TradeProtocol method sendAckMessage.
private void sendAckMessage(@Nullable TradeMessage tradeMessage, boolean result, @Nullable String errorMessage) {
// In such cases we have not set any tradeMessage and we ignore the sendAckMessage call.
if (tradeMessage == null)
return;
String tradeId = tradeMessage.getTradeId();
String sourceUid = "";
if (tradeMessage instanceof MailboxMessage) {
sourceUid = ((MailboxMessage) tradeMessage).getUid();
} else {
// For direct msg we don't have a mandatory uid so we need to cast to get it
if (tradeMessage instanceof PayDepositRequest) {
sourceUid = tradeMessage.getUid();
}
}
AckMessage ackMessage = new AckMessage(processModel.getMyNodeAddress(), AckMessageSourceType.TRADE_MESSAGE, tradeMessage.getClass().getSimpleName(), sourceUid, tradeId, result, errorMessage);
final NodeAddress peersNodeAddress = trade.getTradingPeerNodeAddress();
log.info("Send AckMessage for {} to peer {}. tradeId={}, sourceUid={}", ackMessage.getSourceMsgClassName(), peersNodeAddress, tradeId, sourceUid);
String finalSourceUid = sourceUid;
processModel.getP2PService().sendEncryptedMailboxMessage(peersNodeAddress, processModel.getTradingPeer().getPubKeyRing(), ackMessage, new SendMailboxMessageListener() {
@Override
public void onArrived() {
log.info("AckMessage for {} arrived at peer {}. tradeId={}, sourceUid={}", ackMessage.getSourceMsgClassName(), peersNodeAddress, tradeId, finalSourceUid);
}
@Override
public void onStoredInMailbox() {
log.info("AckMessage for {} stored in mailbox for peer {}. tradeId={}, sourceUid={}", ackMessage.getSourceMsgClassName(), peersNodeAddress, tradeId, finalSourceUid);
}
@Override
public void onFault(String errorMessage) {
log.error("AckMessage for {} failed. Peer {}. tradeId={}, sourceUid={}, errorMessage={}", ackMessage.getSourceMsgClassName(), peersNodeAddress, tradeId, finalSourceUid, errorMessage);
}
});
}
Aggregations