Search in sources :

Example 1 with ProtectedStoragePayload

use of bisq.network.p2p.storage.payload.ProtectedStoragePayload in project bisq-core by bisq-network.

the class ProposalCollectionsService method onAllServicesInitialized.

// /////////////////////////////////////////////////////////////////////////////////////////
// API
// /////////////////////////////////////////////////////////////////////////////////////////
public void onAllServicesInitialized() {
    p2PService.addHashSetChangedListener(this);
    // At startup the P2PDataStorage initializes earlier, otherwise we get the listener called.
    p2PService.getP2PDataStorage().getMap().values().forEach(e -> {
        final ProtectedStoragePayload protectedStoragePayload = e.getProtectedStoragePayload();
        if (protectedStoragePayload instanceof ProposalPayload)
            addProposal((ProposalPayload) protectedStoragePayload, false);
    });
    // Republish own active proposals once we are well connected
    numConnectedPeersListener = (observable, oldValue, newValue) -> {
        // Delay a bit for localhost testing to not fail as isBootstrapped is false
        UserThread.runAfter(() -> {
            if (((int) newValue > 4 && p2PService.isBootstrapped()) || DevEnv.isDevMode()) {
                p2PService.getNumConnectedPeers().removeListener(numConnectedPeersListener);
                activeProposals.stream().filter(this::isMine).forEach(e -> addToP2PNetwork(e.getProposalPayload()));
            }
        }, 2);
    };
    p2PService.getNumConnectedPeers().addListener(numConnectedPeersListener);
    bsqWalletService.getChainHeightProperty().addListener((observable, oldValue, newValue) -> {
        onChainHeightChanged();
    });
    onChainHeightChanged();
}
Also used : ProtectedStoragePayload(bisq.network.p2p.storage.payload.ProtectedStoragePayload)

Example 2 with ProtectedStoragePayload

use of bisq.network.p2p.storage.payload.ProtectedStoragePayload in project bisq-core by bisq-network.

the class ProposalCollectionsService method onRemoved.

@Override
public void onRemoved(ProtectedStorageEntry data) {
    final ProtectedStoragePayload protectedStoragePayload = data.getProtectedStoragePayload();
    if (protectedStoragePayload instanceof ProposalPayload) {
        findProposal((ProposalPayload) protectedStoragePayload).ifPresent(proposal -> {
            if (isInPhaseOrUnconfirmed(proposal.getProposalPayload())) {
                removeProposalFromList(proposal);
            } else {
                final String msg = "onRemoved called of a Proposal which is outside of the Request phase is invalid and we ignore it.";
                log.warn(msg);
                if (DevEnv.isDevMode())
                    throw new RuntimeException(msg);
            }
        });
    }
}
Also used : ProtectedStoragePayload(bisq.network.p2p.storage.payload.ProtectedStoragePayload)

Example 3 with ProtectedStoragePayload

use of bisq.network.p2p.storage.payload.ProtectedStoragePayload in project bisq-core by bisq-network.

the class VoteService method onAllServicesInitialized.

// /////////////////////////////////////////////////////////////////////////////////////////
// API
// /////////////////////////////////////////////////////////////////////////////////////////
public void onAllServicesInitialized() {
    p2PService.addHashSetChangedListener(this);
    // At startup the P2PDataStorage initializes earlier, otherwise we get the listener called.
    p2PService.getP2PDataStorage().getMap().values().forEach(e -> {
        final ProtectedStoragePayload protectedStoragePayload = e.getProtectedStoragePayload();
        if (protectedStoragePayload instanceof BlindVote)
            addBlindVote((BlindVote) protectedStoragePayload);
    });
    // Republish own active blindVotes once we are well connected
    numConnectedPeersListener = (observable, oldValue, newValue) -> {
        // Delay a bit for localhost testing to not fail as isBootstrapped is false
        UserThread.runAfter(() -> {
            if (((int) newValue > 4 && p2PService.isBootstrapped()) || DevEnv.isDevMode()) {
                p2PService.getNumConnectedPeers().removeListener(numConnectedPeersListener);
                myVotesList.stream().filter(myVote -> daoPeriodService.isTxInPhase(myVote.getTxId(), DaoPeriodService.Phase.BLIND_VOTE)).forEach(myVote -> addBlindVoteToP2PNetwork(myVote.getBlindVote()));
            }
        }, 2);
    };
    p2PService.getNumConnectedPeers().addListener(numConnectedPeersListener);
    daoPeriodService.getPhaseProperty().addListener((observable, oldValue, newValue) -> {
        onPhaseChanged(newValue);
    });
    onPhaseChanged(daoPeriodService.getPhaseProperty().get());
}
Also used : Transaction(org.bitcoinj.core.Transaction) ChangeBelowDustException(bisq.core.btc.wallet.ChangeBelowDustException) Utilities(bisq.common.util.Utilities) Coin(org.bitcoinj.core.Coin) ReadableBsqBlockChain(bisq.core.dao.blockchain.ReadableBsqBlockChain) Proposal(bisq.core.dao.proposal.Proposal) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BsqBlockChain(bisq.core.dao.blockchain.BsqBlockChain) SortedList(javafx.collections.transformation.SortedList) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) WalletException(bisq.core.btc.exceptions.WalletException) P2PService(bisq.network.p2p.P2PService) PersistedDataHost(bisq.common.proto.persistable.PersistedDataHost) Utils(org.bitcoinj.core.Utils) FilteredList(javafx.collections.transformation.FilteredList) Set(java.util.Set) TxOutput(bisq.core.dao.blockchain.vo.TxOutput) BsqWalletService(bisq.core.btc.wallet.BsqWalletService) Encryption(bisq.common.crypto.Encryption) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) DevEnv(bisq.common.app.DevEnv) VoteConsensus(bisq.core.dao.vote.consensus.VoteConsensus) ProtectedStorageEntry(bisq.network.p2p.storage.payload.ProtectedStorageEntry) UserThread(bisq.common.UserThread) Optional(java.util.Optional) ProtectedStoragePayload(bisq.network.p2p.storage.payload.ProtectedStoragePayload) ObservableList(javafx.collections.ObservableList) SecretKey(javax.crypto.SecretKey) NotNull(org.jetbrains.annotations.NotNull) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) CryptoException(bisq.common.crypto.CryptoException) Getter(lombok.Getter) FXCollections(javafx.collections.FXCollections) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) TransactionVerificationException(bisq.core.btc.exceptions.TransactionVerificationException) Nullable(javax.annotation.Nullable) DaoPeriodService(bisq.core.dao.DaoPeriodService) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PublicKey(java.security.PublicKey) BisqEnvironment(bisq.core.app.BisqEnvironment) InsufficientMoneyException(org.bitcoinj.core.InsufficientMoneyException) FutureCallback(com.google.common.util.concurrent.FutureCallback) HashMapChangedListener(bisq.network.p2p.storage.HashMapChangedListener) Storage(bisq.common.storage.Storage) ProposalList(bisq.core.dao.proposal.ProposalList) KeyRing(bisq.common.crypto.KeyRing) ChangeListener(javafx.beans.value.ChangeListener) ProposalCollectionsService(bisq.core.dao.proposal.ProposalCollectionsService) ProtectedStoragePayload(bisq.network.p2p.storage.payload.ProtectedStoragePayload)

Example 4 with ProtectedStoragePayload

use of bisq.network.p2p.storage.payload.ProtectedStoragePayload in project bisq-core by bisq-network.

the class FilterManager method onAllServicesInitialized.

public void onAllServicesInitialized() {
    if (!ignoreDevMsg) {
        final List<ProtectedStorageEntry> list = new ArrayList<>(p2PService.getP2PDataStorage().getMap().values());
        list.forEach(e -> {
            final ProtectedStoragePayload protectedStoragePayload = e.getProtectedStoragePayload();
            if (protectedStoragePayload instanceof Filter)
                addFilter((Filter) protectedStoragePayload);
        });
        p2PService.addHashSetChangedListener(new HashMapChangedListener() {

            @Override
            public void onAdded(ProtectedStorageEntry data) {
                if (data.getProtectedStoragePayload() instanceof Filter) {
                    Filter filter = (Filter) data.getProtectedStoragePayload();
                    addFilter(filter);
                }
            }

            @Override
            public void onRemoved(ProtectedStorageEntry data) {
                if (data.getProtectedStoragePayload() instanceof Filter) {
                    Filter filter = (Filter) data.getProtectedStoragePayload();
                    if (verifySignature(filter))
                        resetFilters();
                }
            }
        });
    }
    p2PService.addP2PServiceListener(new P2PServiceListener() {

        @Override
        public void onDataReceived() {
        }

        @Override
        public void onNoSeedNodeAvailable() {
        }

        @Override
        public void onNoPeersAvailable() {
        }

        @Override
        public void onUpdatedDataReceived() {
            // We should have received all data at that point and if the filers was not set we
            // clean up as it might be that we missed the filter remove message if we have not been online.
            UserThread.runAfter(() -> {
                if (filterProperty.get() == null)
                    resetFilters();
            }, 1);
        }

        @Override
        public void onTorNodeReady() {
        }

        @Override
        public void onHiddenServicePublished() {
        }

        @Override
        public void onSetupFailed(Throwable throwable) {
        }

        @Override
        public void onRequestCustomBridges() {
        }
    });
}
Also used : HashMapChangedListener(bisq.network.p2p.storage.HashMapChangedListener) ArrayList(java.util.ArrayList) P2PServiceListener(bisq.network.p2p.P2PServiceListener) ProtectedStoragePayload(bisq.network.p2p.storage.payload.ProtectedStoragePayload) ProtectedStorageEntry(bisq.network.p2p.storage.payload.ProtectedStorageEntry)

Example 5 with ProtectedStoragePayload

use of bisq.network.p2p.storage.payload.ProtectedStoragePayload in project bisq-core by bisq-network.

the class TradeStatisticsManager method onAllServicesInitialized.

public void onAllServicesInitialized() {
    if (dumpStatistics) {
        ArrayList<CurrencyTuple> fiatCurrencyList = new ArrayList<>(CurrencyUtil.getAllSortedFiatCurrencies().stream().map(e -> new CurrencyTuple(e.getCode(), e.getName(), 8)).collect(Collectors.toList()));
        jsonFileManager.writeToDisc(Utilities.objectToJson(fiatCurrencyList), "fiat_currency_list");
        ArrayList<CurrencyTuple> cryptoCurrencyList = new ArrayList<>(CurrencyUtil.getAllSortedCryptoCurrencies().stream().map(e -> new CurrencyTuple(e.getCode(), e.getName(), 8)).collect(Collectors.toList()));
        cryptoCurrencyList.add(0, new CurrencyTuple(Res.getBaseCurrencyCode(), Res.getBaseCurrencyName(), 8));
        jsonFileManager.writeToDisc(Utilities.objectToJson(cryptoCurrencyList), "crypto_currency_list");
    }
    p2PService.getP2PDataStorage().addPersistableNetworkPayloadMapListener(payload -> {
        if (payload instanceof TradeStatistics2)
            addToMap((TradeStatistics2) payload, true);
    });
    p2PService.getP2PDataStorage().getPersistableNetworkPayloadList().getMap().values().forEach(e -> {
        if (e instanceof TradeStatistics2)
            addToMap((TradeStatistics2) e, false);
    });
    // TODO can be removed after version older than v0.6.0 are not used anymore
    // We listen to TradeStatistics objects from old clients as well and convert them into TradeStatistics2 objects
    p2PService.addHashSetChangedListener(new HashMapChangedListener() {

        @Override
        public void onAdded(ProtectedStorageEntry data) {
            final ProtectedStoragePayload protectedStoragePayload = data.getProtectedStoragePayload();
            if (protectedStoragePayload instanceof TradeStatistics)
                p2PService.getP2PDataStorage().addPersistableNetworkPayload(ConvertToTradeStatistics2((TradeStatistics) protectedStoragePayload), p2PService.getNetworkNode().getNodeAddress(), true, false, false, false);
        }

        @Override
        public void onRemoved(ProtectedStorageEntry data) {
        // We don't remove items
        }
    });
    priceFeedService.applyLatestBisqMarketPrice(tradeStatisticsSet);
    dump();
// print all currencies sorted by nr. of trades
// printAllCurrencyStats();
}
Also used : CurrencyTuple(bisq.core.locale.CurrencyTuple) HashMapChangedListener(bisq.network.p2p.storage.HashMapChangedListener) ArrayList(java.util.ArrayList) ProtectedStoragePayload(bisq.network.p2p.storage.payload.ProtectedStoragePayload) ProtectedStorageEntry(bisq.network.p2p.storage.payload.ProtectedStorageEntry)

Aggregations

ProtectedStoragePayload (bisq.network.p2p.storage.payload.ProtectedStoragePayload)5 HashMapChangedListener (bisq.network.p2p.storage.HashMapChangedListener)3 ProtectedStorageEntry (bisq.network.p2p.storage.payload.ProtectedStorageEntry)3 ArrayList (java.util.ArrayList)3 UserThread (bisq.common.UserThread)1 DevEnv (bisq.common.app.DevEnv)1 CryptoException (bisq.common.crypto.CryptoException)1 Encryption (bisq.common.crypto.Encryption)1 KeyRing (bisq.common.crypto.KeyRing)1 PersistedDataHost (bisq.common.proto.persistable.PersistedDataHost)1 Storage (bisq.common.storage.Storage)1 Utilities (bisq.common.util.Utilities)1 BisqEnvironment (bisq.core.app.BisqEnvironment)1 TransactionVerificationException (bisq.core.btc.exceptions.TransactionVerificationException)1 WalletException (bisq.core.btc.exceptions.WalletException)1 BsqWalletService (bisq.core.btc.wallet.BsqWalletService)1 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)1 ChangeBelowDustException (bisq.core.btc.wallet.ChangeBelowDustException)1 DaoPeriodService (bisq.core.dao.DaoPeriodService)1 BsqBlockChain (bisq.core.dao.blockchain.BsqBlockChain)1