Search in sources :

Example 6 with AckMessage

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);
        }
    });
}
Also used : PayDepositRequest(bisq.core.trade.messages.PayDepositRequest) AckMessage(bisq.network.p2p.AckMessage) NodeAddress(bisq.network.p2p.NodeAddress) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener) MailboxMessage(bisq.network.p2p.MailboxMessage)

Aggregations

AckMessage (bisq.network.p2p.AckMessage)6 NodeAddress (bisq.network.p2p.NodeAddress)5 PubKeyRing (bisq.common.crypto.PubKeyRing)3 SendMailboxMessageListener (bisq.network.p2p.SendMailboxMessageListener)3 NetworkEnvelope (bisq.common.proto.network.NetworkEnvelope)2 DisputeMessage (bisq.core.arbitration.messages.DisputeMessage)2 OpenNewDisputeMessage (bisq.core.arbitration.messages.OpenNewDisputeMessage)2 PeerOpenedDisputeMessage (bisq.core.arbitration.messages.PeerOpenedDisputeMessage)2 SendDirectMessageListener (bisq.network.p2p.SendDirectMessageListener)2 Timer (bisq.common.Timer)1 UserThread (bisq.common.UserThread)1 KeyRing (bisq.common.crypto.KeyRing)1 FaultHandler (bisq.common.handlers.FaultHandler)1 ResultHandler (bisq.common.handlers.ResultHandler)1 PersistedDataHost (bisq.common.proto.persistable.PersistedDataHost)1 PersistenceProtoResolver (bisq.common.proto.persistable.PersistenceProtoResolver)1 Storage (bisq.common.storage.Storage)1 Tuple2 (bisq.common.util.Tuple2)1 DisputeCommunicationMessage (bisq.core.arbitration.messages.DisputeCommunicationMessage)1 DisputeResultMessage (bisq.core.arbitration.messages.DisputeResultMessage)1