Search in sources :

Example 26 with NodeAddress

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

the class SeedNodeAddressesTest method testExcludeByFullAddress.

@Test
public void testExcludeByFullAddress() {
    Set<NodeAddress> delegate = Sets.newHashSet(new NodeAddress("192.168.0.1:1111"), new NodeAddress("192.168.0.2:2222"));
    SeedNodeAddresses addresses = new SeedNodeAddresses(delegate);
    SeedNodeAddresses actual = addresses.excludeByFullAddress("192.168.0.1:1111");
    assertEquals(1, actual.size());
}
Also used : NodeAddress(bisq.network.p2p.NodeAddress) Test(org.junit.Test)

Example 27 with NodeAddress

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

the class SeedNodeAddressesTest method testExcludeByHost.

@Test
public void testExcludeByHost() {
    Set<NodeAddress> delegate = Sets.newHashSet(new NodeAddress("aaa:1111"), new NodeAddress("aaa:2222"), new NodeAddress("bbb:1111"), new NodeAddress("bbb:2222"), new NodeAddress("ccc:1111"), new NodeAddress("ccc:2222"));
    SeedNodeAddresses addresses = new SeedNodeAddresses(delegate);
    Set<String> hosts = Sets.newHashSet("aaa", "bbb");
    SeedNodeAddresses actual = addresses.excludeByHost(hosts);
    Set<NodeAddress> expected = Sets.newHashSet(new NodeAddress("ccc:1111"), new NodeAddress("ccc:2222"));
    assertEquals(expected, actual);
}
Also used : NodeAddress(bisq.network.p2p.NodeAddress) Test(org.junit.Test)

Example 28 with NodeAddress

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

the class TakerVerifyAndSignContract method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        checkNotNull(trade.getTakerFeeTxId(), "TakeOfferFeeTxId must not be null");
        TradingPeer maker = processModel.getTradingPeer();
        PaymentAccountPayload makerPaymentAccountPayload = maker.getPaymentAccountPayload();
        PaymentAccountPayload takerPaymentAccountPayload = processModel.getPaymentAccountPayload(trade);
        boolean isBuyerMakerAndSellerTaker = trade instanceof SellerAsTakerTrade;
        NodeAddress buyerNodeAddress = isBuyerMakerAndSellerTaker ? processModel.getTempTradingPeerNodeAddress() : processModel.getMyNodeAddress();
        NodeAddress sellerNodeAddress = isBuyerMakerAndSellerTaker ? processModel.getMyNodeAddress() : processModel.getTempTradingPeerNodeAddress();
        log.debug("isBuyerMakerAndSellerTaker " + isBuyerMakerAndSellerTaker);
        log.debug("buyerAddress " + buyerNodeAddress);
        log.debug("sellerAddress " + sellerNodeAddress);
        BtcWalletService walletService = processModel.getBtcWalletService();
        String id = processModel.getOffer().getId();
        AddressEntry takerPayoutAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT);
        String takerPayoutAddressString = takerPayoutAddressEntry.getAddressString();
        AddressEntry takerMultiSigAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.MULTI_SIG);
        byte[] takerMultiSigPubKey = processModel.getMyMultiSigPubKey();
        checkArgument(Arrays.equals(takerMultiSigPubKey, takerMultiSigAddressEntry.getPubKey()), "takerMultiSigPubKey from AddressEntry must match the one from the trade data. trade id =" + id);
        final Coin tradeAmount = trade.getTradeAmount();
        checkNotNull(tradeAmount, "tradeAmount must not be null");
        Contract contract = new Contract(processModel.getOffer().getOfferPayload(), tradeAmount.value, trade.getTradePrice().getValue(), trade.getTakerFeeTxId(), buyerNodeAddress, sellerNodeAddress, trade.getArbitratorNodeAddress(), trade.getMediatorNodeAddress(), isBuyerMakerAndSellerTaker, maker.getAccountId(), processModel.getAccountId(), makerPaymentAccountPayload, takerPaymentAccountPayload, maker.getPubKeyRing(), processModel.getPubKeyRing(), maker.getPayoutAddressString(), takerPayoutAddressString, maker.getMultiSigPubKey(), takerMultiSigPubKey);
        String contractAsJson = Utilities.objectToJson(contract);
        log.trace("Contract as json:{}", contractAsJson);
        contract.printDiff(processModel.getTradingPeer().getContractAsJson());
        checkArgument(contractAsJson.equals(processModel.getTradingPeer().getContractAsJson()), "Contracts are not matching");
        String signature = Sig.sign(processModel.getKeyRing().getSignatureKeyPair().getPrivate(), contractAsJson);
        trade.setContract(contract);
        trade.setContractAsJson(contractAsJson);
        trade.setTakerContractSignature(signature);
        try {
            checkNotNull(maker.getPubKeyRing(), "maker.getPubKeyRing() must nto be null");
            Sig.verify(maker.getPubKeyRing().getSignaturePubKey(), contractAsJson, maker.getContractSignature());
            complete();
        } catch (Throwable t) {
            failed("Signature verification failed. " + t.getMessage());
        }
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Coin(org.bitcoinj.core.Coin) TradingPeer(bisq.core.trade.protocol.TradingPeer) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) AddressEntry(bisq.core.btc.AddressEntry) PaymentAccountPayload(bisq.core.payment.payload.PaymentAccountPayload) SellerAsTakerTrade(bisq.core.trade.SellerAsTakerTrade) NodeAddress(bisq.network.p2p.NodeAddress) Contract(bisq.core.trade.Contract)

Example 29 with NodeAddress

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

the class MakerVerifyArbitratorSelection method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        final NodeAddress selectedAddress = ArbitratorSelectionRule.select(processModel.getTakerAcceptedArbitratorNodeAddresses(), processModel.getOffer());
        if (trade.getArbitratorNodeAddress() != null && trade.getArbitratorNodeAddress().equals(selectedAddress))
            complete();
        else
            failed("Arbitrator selection verification failed");
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : NodeAddress(bisq.network.p2p.NodeAddress)

Example 30 with NodeAddress

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

the class MediatorSelectionRule method select.

public static NodeAddress select(List<NodeAddress> acceptedMediatorNodeAddresses, Offer offer) {
    List<NodeAddress> candidates = new ArrayList<>();
    for (NodeAddress offerMediatorNodeAddress : offer.getMediatorNodeAddresses()) {
        candidates.addAll(acceptedMediatorNodeAddresses.stream().filter(offerMediatorNodeAddress::equals).collect(Collectors.toList()));
    }
    checkArgument(candidates.size() > 0, "candidates.size() <= 0");
    int index = Math.abs(Arrays.hashCode(Hash.getSha256Hash(offer.getId().getBytes()))) % candidates.size();
    NodeAddress selectedMediator = candidates.get(index);
    log.debug("selectedMediator " + selectedMediator);
    return selectedMediator;
}
Also used : ArrayList(java.util.ArrayList) NodeAddress(bisq.network.p2p.NodeAddress)

Aggregations

NodeAddress (bisq.network.p2p.NodeAddress)32 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)6 Contract (bisq.core.trade.Contract)5 Test (org.junit.Test)5 PubKeyRing (bisq.common.crypto.PubKeyRing)4 AddressEntry (bisq.core.btc.AddressEntry)4 Offer (bisq.core.offer.Offer)4 PaymentAccountPayload (bisq.core.payment.payload.PaymentAccountPayload)4 SendMailboxMessageListener (bisq.network.p2p.SendMailboxMessageListener)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Insets (javafx.geometry.Insets)4 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 ErrorMessageHandler (bisq.common.handlers.ErrorMessageHandler)2 ResultHandler (bisq.common.handlers.ResultHandler)2 BisqEnvironment (bisq.core.app.BisqEnvironment)2