Search in sources :

Example 1 with ConnectionListener

use of bisq.network.p2p.network.ConnectionListener in project bisq-desktop by bisq-network.

the class TakeOfferViewModel method createListeners.

private void createListeners() {
    amountListener = (ov, oldValue, newValue) -> {
        if (isBtcInputValid(newValue).isValid) {
            setAmountToModel();
            calculateVolume();
            dataModel.calculateTotalToPay();
            applyTakerFee();
        }
        updateButtonDisableState();
    };
    amountAsCoinListener = (ov, oldValue, newValue) -> {
        amount.set(btcFormatter.formatCoin(newValue));
        applyTakerFee();
    };
    isWalletFundedListener = (ov, oldValue, newValue) -> updateButtonDisableState();
    tradeStateListener = (ov, oldValue, newValue) -> applyTradeState(newValue);
    tradeErrorListener = (ov, oldValue, newValue) -> applyTradeErrorMessage(newValue);
    offerStateListener = (ov, oldValue, newValue) -> applyOfferState(newValue);
    connectionListener = new ConnectionListener() {

        @Override
        public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
            if (connection.getPeersNodeAddressOptional().isPresent() && connection.getPeersNodeAddressOptional().get().equals(offer.getMakerNodeAddress())) {
                offerWarning.set(Res.get("takeOffer.warning.connectionToPeerLost"));
                updateSpinnerInfo();
            }
        }

        @Override
        public void onConnection(Connection connection) {
        }

        @Override
        public void onError(Throwable throwable) {
        }
    };
}
Also used : Connection(bisq.network.p2p.network.Connection) CloseConnectionReason(bisq.network.p2p.network.CloseConnectionReason) ConnectionListener(bisq.network.p2p.network.ConnectionListener)

Example 2 with ConnectionListener

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

the class AppSetupWithP2P method initP2PNetwork.

// /////////////////////////////////////////////////////////////////////////////////////////
// Initialisation
// /////////////////////////////////////////////////////////////////////////////////////////
private BooleanProperty initP2PNetwork() {
    log.info("initP2PNetwork");
    p2PService.getNetworkNode().addConnectionListener(new ConnectionListener() {

        @Override
        public void onConnection(Connection connection) {
        }

        @Override
        public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
            // Other disconnects might be caused by peers running an older version
            if (connection.getPeerType() == Connection.PeerType.SEED_NODE && closeConnectionReason == CloseConnectionReason.RULE_VIOLATION) {
                log.warn("RULE_VIOLATION onDisconnect closeConnectionReason=" + closeConnectionReason);
                log.warn("RULE_VIOLATION onDisconnect connection=" + connection);
            }
        }

        @Override
        public void onError(Throwable throwable) {
        }
    });
    final BooleanProperty p2pNetworkInitialized = new SimpleBooleanProperty();
    p2PService.start(new P2PServiceListener() {

        @Override
        public void onTorNodeReady() {
        }

        @Override
        public void onHiddenServicePublished() {
            log.info("onHiddenServicePublished");
        }

        @Override
        public void onDataReceived() {
            log.info("onRequestingDataCompleted");
            p2pNetworkInitialized.set(true);
        }

        @Override
        public void onNoSeedNodeAvailable() {
            log.info("onNoSeedNodeAvailable");
            p2pNetworkInitialized.set(true);
        }

        @Override
        public void onNoPeersAvailable() {
            log.info("onNoPeersAvailable");
            p2pNetworkInitialized.set(true);
        }

        @Override
        public void onUpdatedDataReceived() {
            log.info("onUpdatedDataReceived");
        }

        @Override
        public void onSetupFailed(Throwable throwable) {
            log.error(throwable.toString());
        }

        @Override
        public void onRequestCustomBridges() {
        }
    });
    return p2pNetworkInitialized;
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Connection(bisq.network.p2p.network.Connection) P2PServiceListener(bisq.network.p2p.P2PServiceListener) CloseConnectionReason(bisq.network.p2p.network.CloseConnectionReason) ConnectionListener(bisq.network.p2p.network.ConnectionListener)

Example 3 with ConnectionListener

use of bisq.network.p2p.network.ConnectionListener in project bisq-desktop by bisq-network.

the class MainViewModel method initP2PNetwork.

// /////////////////////////////////////////////////////////////////////////////////////////
// Initialisation
// /////////////////////////////////////////////////////////////////////////////////////////
private BooleanProperty initP2PNetwork() {
    log.info("initP2PNetwork");
    StringProperty bootstrapState = new SimpleStringProperty();
    StringProperty bootstrapWarning = new SimpleStringProperty();
    BooleanProperty hiddenServicePublished = new SimpleBooleanProperty();
    BooleanProperty initialP2PNetworkDataReceived = new SimpleBooleanProperty();
    p2PNetworkInfoBinding = EasyBind.combine(bootstrapState, bootstrapWarning, p2PService.getNumConnectedPeers(), hiddenServicePublished, initialP2PNetworkDataReceived, (state, warning, numPeers, hiddenService, dataReceived) -> {
        String result = "";
        int peers = (int) numPeers;
        if (warning != null && peers == 0) {
            result = warning;
        } else {
            String p2pInfo = Res.get("mainView.footer.p2pInfo", numPeers);
            if (dataReceived && hiddenService) {
                result = p2pInfo;
            } else if (peers == 0)
                result = state;
            else
                result = state + " / " + p2pInfo;
        }
        return result;
    });
    p2PNetworkInfoBinding.subscribe((observable, oldValue, newValue) -> {
        p2PNetworkInfo.set(newValue);
    });
    bootstrapState.set(Res.get("mainView.bootstrapState.connectionToTorNetwork"));
    p2PService.getNetworkNode().addConnectionListener(new ConnectionListener() {

        @Override
        public void onConnection(Connection connection) {
        }

        @Override
        public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
            // Other disconnects might be caused by peers running an older version
            if (connection.getPeerType() == Connection.PeerType.SEED_NODE && closeConnectionReason == CloseConnectionReason.RULE_VIOLATION) {
                log.warn("RULE_VIOLATION onDisconnect closeConnectionReason=" + closeConnectionReason);
                log.warn("RULE_VIOLATION onDisconnect connection=" + connection);
            }
        }

        @Override
        public void onError(Throwable throwable) {
        }
    });
    final BooleanProperty p2pNetworkInitialized = new SimpleBooleanProperty();
    p2PService.start(new P2PServiceListener() {

        @Override
        public void onTorNodeReady() {
            log.debug("onTorNodeReady");
            bootstrapState.set(Res.get("mainView.bootstrapState.torNodeCreated"));
            p2PNetworkIconId.set("image-connection-tor");
            if (preferences.getUseTorForBitcoinJ())
                initWalletService();
            // We want to get early connected to the price relay so we call it already now
            priceFeedService.setCurrencyCodeOnInit();
            priceFeedService.initialRequestPriceFeed();
        }

        @Override
        public void onHiddenServicePublished() {
            log.debug("onHiddenServicePublished");
            hiddenServicePublished.set(true);
            bootstrapState.set(Res.get("mainView.bootstrapState.hiddenServicePublished"));
        }

        @Override
        public void onDataReceived() {
            log.debug("onRequestingDataCompleted");
            initialP2PNetworkDataReceived.set(true);
            bootstrapState.set(Res.get("mainView.bootstrapState.initialDataReceived"));
            splashP2PNetworkAnimationVisible.set(false);
            p2pNetworkInitialized.set(true);
        }

        @Override
        public void onNoSeedNodeAvailable() {
            log.warn("onNoSeedNodeAvailable");
            if (p2PService.getNumConnectedPeers().get() == 0)
                bootstrapWarning.set(Res.get("mainView.bootstrapWarning.noSeedNodesAvailable"));
            else
                bootstrapWarning.set(null);
            splashP2PNetworkAnimationVisible.set(false);
            p2pNetworkInitialized.set(true);
        }

        @Override
        public void onNoPeersAvailable() {
            log.warn("onNoPeersAvailable");
            if (p2PService.getNumConnectedPeers().get() == 0) {
                p2pNetworkWarnMsg.set(Res.get("mainView.p2pNetworkWarnMsg.noNodesAvailable"));
                bootstrapWarning.set(Res.get("mainView.bootstrapWarning.noNodesAvailable"));
                p2pNetworkLabelId.set("splash-error-state-msg");
            } else {
                bootstrapWarning.set(null);
                p2pNetworkLabelId.set("footer-pane");
            }
            splashP2PNetworkAnimationVisible.set(false);
            p2pNetworkInitialized.set(true);
        }

        @Override
        public void onUpdatedDataReceived() {
            log.debug("onBootstrapComplete");
            splashP2PNetworkAnimationVisible.set(false);
            bootstrapComplete.set(true);
        }

        @Override
        public void onSetupFailed(Throwable throwable) {
            log.warn("onSetupFailed");
            p2pNetworkWarnMsg.set(Res.get("mainView.p2pNetworkWarnMsg.connectionToP2PFailed", throwable.getMessage()));
            splashP2PNetworkAnimationVisible.set(false);
            bootstrapWarning.set(Res.get("mainView.bootstrapWarning.bootstrappingToP2PFailed"));
            p2pNetworkLabelId.set("splash-error-state-msg");
        }

        @Override
        public void onRequestCustomBridges() {
            showTorNetworkSettingsWindow();
        }
    });
    return p2pNetworkInitialized;
}
Also used : OpenOffer(bisq.core.offer.OpenOffer) User(bisq.core.user.User) ChainFileLockedException(org.bitcoinj.store.ChainFileLockedException) ListChangeListener(javafx.collections.ListChangeListener) BootstrapListener(bisq.network.p2p.BootstrapListener) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Map(java.util.Map) BlockStoreException(org.bitcoinj.store.BlockStoreException) MonadicBinding(org.fxmisc.easybind.monadic.MonadicBinding) P2PServiceListener(bisq.network.p2p.P2PServiceListener) ClosedTradableManager(bisq.core.trade.closed.ClosedTradableManager) FilterManager(bisq.core.filter.FilterManager) Set(java.util.Set) PaymentMethod(bisq.core.payment.payload.PaymentMethod) BooleanProperty(javafx.beans.property.BooleanProperty) Slf4j(lombok.extern.slf4j.Slf4j) TxIdTextField(bisq.desktop.components.TxIdTextField) Stream(java.util.stream.Stream) TorNetworkSettingsWindow(bisq.desktop.main.overlays.windows.TorNetworkSettingsWindow) AddressEntry(bisq.core.btc.AddressEntry) WalletsSetup(bisq.core.btc.wallet.WalletsSetup) TradeManager(bisq.core.trade.TradeManager) UserThread(bisq.common.UserThread) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) FeeService(bisq.core.provider.fee.FeeService) ObservableList(javafx.collections.ObservableList) StringProperty(javafx.beans.property.StringProperty) CryptoException(bisq.common.crypto.CryptoException) AlertManager(bisq.core.alert.AlertManager) SetupUtils(bisq.core.app.SetupUtils) FXCollections(javafx.collections.FXCollections) Dispute(bisq.core.arbitration.Dispute) NotificationCenter(bisq.desktop.main.overlays.notifications.NotificationCenter) IntegerProperty(javafx.beans.property.IntegerProperty) ConnectionListener(bisq.network.p2p.network.ConnectionListener) Nullable(javax.annotation.Nullable) EncryptionService(bisq.network.crypto.EncryptionService) DontShowAgainLookup(bisq.core.user.DontShowAgainLookup) GlobalSettings(bisq.core.locale.GlobalSettings) IOException(java.io.IOException) BisqEnvironment(bisq.core.app.BisqEnvironment) OpenOfferManager(bisq.core.offer.OpenOfferManager) PriceFeedService(bisq.core.provider.price.PriceFeedService) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) CloseConnectionReason(bisq.network.p2p.network.CloseConnectionReason) KeyRing(bisq.common.crypto.KeyRing) InetAddresses(com.google.common.net.InetAddresses) SealedAndSigned(bisq.common.crypto.SealedAndSigned) Transaction(org.bitcoinj.core.Transaction) DisplayAlertMessageWindow(bisq.desktop.main.overlays.windows.DisplayAlertMessageWindow) Coin(org.bitcoinj.core.Coin) Date(java.util.Date) DaoManager(bisq.core.dao.DaoManager) Clock(bisq.common.Clock) Inject(com.google.inject.Inject) PerfectMoneyAccount(bisq.core.payment.PerfectMoneyAccount) Security(java.security.Security) TimeoutException(java.util.concurrent.TimeoutException) Random(java.util.Random) DisputeManager(bisq.core.arbitration.DisputeManager) BSFormatter(bisq.desktop.util.BSFormatter) Alert(bisq.core.alert.Alert) Res(bisq.core.locale.Res) Popup(bisq.desktop.main.overlays.popups.Popup) WalletPasswordWindow(bisq.desktop.main.overlays.windows.WalletPasswordWindow) P2PService(bisq.network.p2p.P2PService) ArbitratorManager(bisq.core.arbitration.ArbitratorManager) Subscription(org.fxmisc.easybind.Subscription) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) AccountAgeWitnessService(bisq.core.payment.AccountAgeWitnessService) PaymentAccount(bisq.core.payment.PaymentAccount) List(java.util.List) TacWindow(bisq.desktop.main.overlays.windows.TacWindow) DevEnv(bisq.common.app.DevEnv) AppOptionKeys(bisq.core.app.AppOptionKeys) Preferences(bisq.core.user.Preferences) Optional(java.util.Optional) Address(org.bitcoinj.core.Address) BalanceWithConfirmationTextField(bisq.desktop.components.BalanceWithConfirmationTextField) Ping(bisq.network.p2p.peers.keepalive.messages.Ping) MarketPrice(bisq.core.provider.price.MarketPrice) DisplayUpdateDownloadWindow(bisq.desktop.main.overlays.windows.downloadupdate.DisplayUpdateDownloadWindow) GUIUtil(bisq.desktop.util.GUIUtil) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) Socket(java.net.Socket) TradeCurrency(bisq.core.locale.TradeCurrency) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) SetChangeListener(javafx.collections.SetChangeListener) Timer(bisq.common.Timer) DoubleProperty(javafx.beans.property.DoubleProperty) HashMap(java.util.HashMap) TradeStatisticsManager(bisq.core.trade.statistics.TradeStatisticsManager) BalanceListener(bisq.core.btc.listeners.BalanceListener) WalletsManager(bisq.core.btc.wallet.WalletsManager) CurrencyUtil(bisq.core.locale.CurrencyUtil) Connection(bisq.network.p2p.network.Connection) PrivateNotificationManager(bisq.core.alert.PrivateNotificationManager) Version(bisq.common.app.Version) ObjectProperty(javafx.beans.property.ObjectProperty) CryptoCurrencyAccount(bisq.core.payment.CryptoCurrencyAccount) PrivateNotificationPayload(bisq.core.alert.PrivateNotificationPayload) Trade(bisq.core.trade.Trade) FailedTradesManager(bisq.core.trade.failed.FailedTradesManager) ViewModel(bisq.desktop.common.model.ViewModel) TimeUnit(java.util.concurrent.TimeUnit) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) EasyBind(org.fxmisc.easybind.EasyBind) DecryptedDataTuple(bisq.network.crypto.DecryptedDataTuple) ChangeListener(javafx.beans.value.ChangeListener) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Connection(bisq.network.p2p.network.Connection) P2PServiceListener(bisq.network.p2p.P2PServiceListener) StringProperty(javafx.beans.property.StringProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) CloseConnectionReason(bisq.network.p2p.network.CloseConnectionReason) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ConnectionListener(bisq.network.p2p.network.ConnectionListener)

Aggregations

CloseConnectionReason (bisq.network.p2p.network.CloseConnectionReason)3 Connection (bisq.network.p2p.network.Connection)3 ConnectionListener (bisq.network.p2p.network.ConnectionListener)3 P2PServiceListener (bisq.network.p2p.P2PServiceListener)2 BooleanProperty (javafx.beans.property.BooleanProperty)2 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)2 Clock (bisq.common.Clock)1 Timer (bisq.common.Timer)1 UserThread (bisq.common.UserThread)1 DevEnv (bisq.common.app.DevEnv)1 Version (bisq.common.app.Version)1 CryptoException (bisq.common.crypto.CryptoException)1 KeyRing (bisq.common.crypto.KeyRing)1 SealedAndSigned (bisq.common.crypto.SealedAndSigned)1 Alert (bisq.core.alert.Alert)1 AlertManager (bisq.core.alert.AlertManager)1 PrivateNotificationManager (bisq.core.alert.PrivateNotificationManager)1 PrivateNotificationPayload (bisq.core.alert.PrivateNotificationPayload)1 AppOptionKeys (bisq.core.app.AppOptionKeys)1 BisqEnvironment (bisq.core.app.BisqEnvironment)1