Search in sources :

Example 1 with NodeAddress

use of bisq.network.p2p.NodeAddress in project bisq-core by bisq-network.

the class DisputeManager method sendPeerPublishedPayoutTxMessage.

// winner (or buyer in case of 50/50) sends tx to other peer
private void sendPeerPublishedPayoutTxMessage(Transaction transaction, Dispute dispute, Contract contract) {
    PubKeyRing peersPubKeyRing = dispute.isDisputeOpenerIsBuyer() ? contract.getSellerPubKeyRing() : contract.getBuyerPubKeyRing();
    NodeAddress peerNodeAddress = dispute.isDisputeOpenerIsBuyer() ? contract.getSellerNodeAddress() : contract.getBuyerNodeAddress();
    log.trace("sendPeerPublishedPayoutTxMessage to peerAddress " + peerNodeAddress);
    final PeerPublishedDisputePayoutTxMessage message = new PeerPublishedDisputePayoutTxMessage(transaction.bitcoinSerialize(), dispute.getTradeId(), p2PService.getAddress(), UUID.randomUUID().toString());
    p2PService.sendEncryptedMailboxMessage(peerNodeAddress, peersPubKeyRing, message, new SendMailboxMessageListener() {

        @Override
        public void onArrived() {
            log.info("Message arrived at peer. tradeId={}", message.getTradeId());
        }

        @Override
        public void onStoredInMailbox() {
            log.info("Message stored in mailbox. tradeId={}", message.getTradeId());
        }

        @Override
        public void onFault(String errorMessage) {
            log.error("sendEncryptedMailboxMessage failed. message=" + message);
        }
    });
}
Also used : PubKeyRing(bisq.common.crypto.PubKeyRing) NodeAddress(bisq.network.p2p.NodeAddress) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener) PeerPublishedDisputePayoutTxMessage(bisq.core.arbitration.messages.PeerPublishedDisputePayoutTxMessage)

Example 2 with NodeAddress

use of bisq.network.p2p.NodeAddress in project bisq-core by bisq-network.

the class DisputeManager method sendPeerOpenedDisputeMessage.

// arbitrator sends that to trading peer when he received openDispute request
private void sendPeerOpenedDisputeMessage(Dispute disputeFromOpener) {
    Contract contractFromOpener = disputeFromOpener.getContract();
    PubKeyRing pubKeyRing = disputeFromOpener.isDisputeOpenerIsBuyer() ? contractFromOpener.getSellerPubKeyRing() : contractFromOpener.getBuyerPubKeyRing();
    Dispute dispute = new Dispute(disputeStorage, disputeFromOpener.getTradeId(), pubKeyRing.hashCode(), !disputeFromOpener.isDisputeOpenerIsBuyer(), !disputeFromOpener.isDisputeOpenerIsMaker(), pubKeyRing, disputeFromOpener.getTradeDate().getTime(), contractFromOpener, disputeFromOpener.getContractHash(), disputeFromOpener.getDepositTxSerialized(), disputeFromOpener.getPayoutTxSerialized(), disputeFromOpener.getDepositTxId(), disputeFromOpener.getPayoutTxId(), disputeFromOpener.getContractAsJson(), disputeFromOpener.getMakerContractSignature(), disputeFromOpener.getTakerContractSignature(), disputeFromOpener.getArbitratorPubKeyRing(), disputeFromOpener.isSupportTicket());
    final Optional<Dispute> storedDisputeOptional = findDispute(dispute.getTradeId(), dispute.getTraderId());
    if (!storedDisputeOptional.isPresent()) {
        String sysMsg = dispute.isSupportTicket() ? Res.get("support.peerOpenedTicket") : Res.get("support.peerOpenedDispute", disputeInfo);
        DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(dispute.getTradeId(), keyRing.getPubKeyRing().hashCode(), false, Res.get("support.systemMsg", sysMsg), null, p2PService.getAddress(), new Date().getTime(), false, false, UUID.randomUUID().toString());
        disputeCommunicationMessage.setSystemMessage(true);
        dispute.addDisputeMessage(disputeCommunicationMessage);
        disputes.add(dispute);
        // we mirrored dispute already!
        Contract contract = dispute.getContract();
        PubKeyRing peersPubKeyRing = dispute.isDisputeOpenerIsBuyer() ? contract.getBuyerPubKeyRing() : contract.getSellerPubKeyRing();
        NodeAddress peerNodeAddress = dispute.isDisputeOpenerIsBuyer() ? contract.getBuyerNodeAddress() : contract.getSellerNodeAddress();
        log.trace("sendPeerOpenedDisputeMessage to peerAddress " + peerNodeAddress);
        p2PService.sendEncryptedMailboxMessage(peerNodeAddress, peersPubKeyRing, new PeerOpenedDisputeMessage(dispute, p2PService.getAddress(), UUID.randomUUID().toString()), new SendMailboxMessageListener() {

            @Override
            public void onArrived() {
                log.info("Message arrived at peer. tradeId={}", disputeCommunicationMessage.getTradeId());
                disputeCommunicationMessage.setArrived(true);
            }

            @Override
            public void onStoredInMailbox() {
                log.info("Message stored in mailbox. tradeId={}", disputeCommunicationMessage.getTradeId());
                disputeCommunicationMessage.setStoredInMailbox(true);
            }

            @Override
            public void onFault(String errorMessage) {
                log.error("sendEncryptedMailboxMessage failed. disputeCommunicationMessage=" + disputeCommunicationMessage);
            }
        });
    } else {
        log.warn("We got a dispute already open for that trade and trading peer.\n" + "TradeId = " + dispute.getTradeId());
    }
}
Also used : PubKeyRing(bisq.common.crypto.PubKeyRing) PeerOpenedDisputeMessage(bisq.core.arbitration.messages.PeerOpenedDisputeMessage) NodeAddress(bisq.network.p2p.NodeAddress) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener) Contract(bisq.core.trade.Contract) DisputeCommunicationMessage(bisq.core.arbitration.messages.DisputeCommunicationMessage) Date(java.util.Date)

Example 3 with NodeAddress

use of bisq.network.p2p.NodeAddress in project bisq-core by bisq-network.

the class ArbitratorService method getArbitrators.

public Map<NodeAddress, Arbitrator> getArbitrators() {
    final List<String> bannedArbitrators = filterManager.getFilter() != null ? filterManager.getFilter().getArbitrators() : null;
    if (bannedArbitrators != null)
        log.warn("bannedArbitrators=" + bannedArbitrators);
    Set<Arbitrator> arbitratorSet = p2PService.getDataMap().values().stream().filter(data -> data.getProtectedStoragePayload() instanceof Arbitrator).map(data -> (Arbitrator) data.getProtectedStoragePayload()).filter(a -> bannedArbitrators == null || !bannedArbitrators.contains(a.getNodeAddress().getHostName())).collect(Collectors.toSet());
    Map<NodeAddress, Arbitrator> map = new HashMap<>();
    for (Arbitrator arbitrator : arbitratorSet) {
        NodeAddress arbitratorNodeAddress = arbitrator.getNodeAddress();
        if (!map.containsKey(arbitratorNodeAddress))
            map.put(arbitratorNodeAddress, arbitrator);
        else
            log.warn("arbitratorAddress already exist in arbitrator map. Seems an arbitrator object is already registered with the same address.");
    }
    return map;
}
Also used : Logger(org.slf4j.Logger) P2PService(bisq.network.p2p.P2PService) Utilities(bisq.common.util.Utilities) FilterManager(bisq.core.filter.FilterManager) ResultHandler(bisq.common.handlers.ResultHandler) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) HashMap(java.util.HashMap) BisqEnvironment(bisq.core.app.BisqEnvironment) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) List(java.util.List) HashMapChangedListener(bisq.network.p2p.storage.HashMapChangedListener) DevEnv(bisq.common.app.DevEnv) NodeAddress(bisq.network.p2p.NodeAddress) Map(java.util.Map) ErrorMessageHandler(bisq.common.handlers.ErrorMessageHandler) HashMap(java.util.HashMap) NodeAddress(bisq.network.p2p.NodeAddress)

Example 4 with NodeAddress

use of bisq.network.p2p.NodeAddress in project bisq-core by bisq-network.

the class LiteNodeNetworkManager method closeHandler.

private void closeHandler(Connection connection) {
    Optional<NodeAddress> peersNodeAddressOptional = connection.getPeersNodeAddressOptional();
    if (peersNodeAddressOptional.isPresent()) {
        NodeAddress nodeAddress = peersNodeAddressOptional.get();
        removeFromRequestBlocksHandlerMap(nodeAddress);
    } else {
        log.trace("closeHandler: nodeAddress not set in connection " + connection);
    }
}
Also used : NodeAddress(bisq.network.p2p.NodeAddress)

Example 5 with NodeAddress

use of bisq.network.p2p.NodeAddress in project bisq-core by bisq-network.

the class MakerCreateAndSignContract method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        Preconditions.checkNotNull(trade.getTakerFeeTxId(), "trade.getTakeOfferFeeTxId() must not be null");
        TradingPeer taker = processModel.getTradingPeer();
        PaymentAccountPayload makerPaymentAccountPayload = processModel.getPaymentAccountPayload(trade);
        checkNotNull(makerPaymentAccountPayload, "makerPaymentAccountPayload must not be null");
        PaymentAccountPayload takerPaymentAccountPayload = taker.getPaymentAccountPayload();
        boolean isBuyerMakerAndSellerTaker = trade instanceof BuyerAsMakerTrade;
        NodeAddress buyerNodeAddress = isBuyerMakerAndSellerTaker ? processModel.getMyNodeAddress() : processModel.getTempTradingPeerNodeAddress();
        NodeAddress sellerNodeAddress = isBuyerMakerAndSellerTaker ? processModel.getTempTradingPeerNodeAddress() : processModel.getMyNodeAddress();
        BtcWalletService walletService = processModel.getBtcWalletService();
        String id = processModel.getOffer().getId();
        checkArgument(!walletService.getAddressEntry(id, AddressEntry.Context.MULTI_SIG).isPresent(), "addressEntry must not be set here.");
        AddressEntry makerAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.MULTI_SIG);
        byte[] makerMultiSigPubKey = makerAddressEntry.getPubKey();
        AddressEntry takerAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT);
        checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
        Contract contract = new Contract(processModel.getOffer().getOfferPayload(), trade.getTradeAmount().value, trade.getTradePrice().getValue(), trade.getTakerFeeTxId(), buyerNodeAddress, sellerNodeAddress, trade.getArbitratorNodeAddress(), trade.getMediatorNodeAddress(), isBuyerMakerAndSellerTaker, processModel.getAccountId(), taker.getAccountId(), makerPaymentAccountPayload, takerPaymentAccountPayload, processModel.getPubKeyRing(), taker.getPubKeyRing(), takerAddressEntry.getAddressString(), taker.getPayoutAddressString(), makerMultiSigPubKey, taker.getMultiSigPubKey());
        String contractAsJson = Utilities.objectToJson(contract);
        log.trace("Contract as json:{}", contractAsJson);
        String signature = Sig.sign(processModel.getKeyRing().getSignatureKeyPair().getPrivate(), contractAsJson);
        trade.setContract(contract);
        trade.setContractAsJson(contractAsJson);
        trade.setMakerContractSignature(signature);
        processModel.setMyMultiSigPubKey(makerMultiSigPubKey);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : TradingPeer(bisq.core.trade.protocol.TradingPeer) BuyerAsMakerTrade(bisq.core.trade.BuyerAsMakerTrade) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) AddressEntry(bisq.core.btc.AddressEntry) PaymentAccountPayload(bisq.core.payment.payload.PaymentAccountPayload) NodeAddress(bisq.network.p2p.NodeAddress) Contract(bisq.core.trade.Contract)

Aggregations

NodeAddress (bisq.network.p2p.NodeAddress)34 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)7 Offer (bisq.core.offer.Offer)5 Contract (bisq.core.trade.Contract)5 Test (org.junit.Test)5 PubKeyRing (bisq.common.crypto.PubKeyRing)4 AddressEntry (bisq.core.btc.AddressEntry)4 PaymentAccountPayload (bisq.core.payment.payload.PaymentAccountPayload)4 User (bisq.core.user.User)4 SendMailboxMessageListener (bisq.network.p2p.SendMailboxMessageListener)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Insets (javafx.geometry.Insets)4 BisqEnvironment (bisq.core.app.BisqEnvironment)3 BsqWalletService (bisq.core.btc.wallet.BsqWalletService)3 PeerInfoIcon (bisq.desktop.components.PeerInfoIcon)3 MailboxMessage (bisq.network.p2p.MailboxMessage)3 List (java.util.List)3 TableCell (javafx.scene.control.TableCell)3 TableColumn (javafx.scene.control.TableColumn)3