Search in sources :

Example 1 with P2PServiceListener

use of io.bitsquare.p2p.P2PServiceListener in project bitsquare by bitsquare.

the class PeerManagerTest method test2SeedNodes.

@Test
public void test2SeedNodes() throws InterruptedException {
    LocalhostNetworkNode.setSimulateTorDelayTorNode(0);
    LocalhostNetworkNode.setSimulateTorDelayHiddenService(0);
    seedNodes = new HashSet<>();
    NodeAddress nodeAddress1 = new NodeAddress("localhost:8001");
    seedNodes.add(nodeAddress1);
    NodeAddress nodeAddress2 = new NodeAddress("localhost:8002");
    seedNodes.add(nodeAddress2);
    latch = new CountDownLatch(6);
    seedNode1 = new DummySeedNode("test_dummy_dir");
    seedNode1.createAndStartP2PService(nodeAddress1, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() {

        @Override
        public void onRequestingDataCompleted() {
            latch.countDown();
        }

        @Override
        public void onNoSeedNodeAvailable() {
        }

        @Override
        public void onTorNodeReady() {
        }

        @Override
        public void onNoPeersAvailable() {
        }

        @Override
        public void onBootstrapComplete() {
            latch.countDown();
        }

        @Override
        public void onHiddenServicePublished() {
            latch.countDown();
        }

        @Override
        public void onSetupFailed(Throwable throwable) {
        }
    });
    P2PService p2PService1 = seedNode1.getSeedNodeP2PService();
    Thread.sleep(500);
    seedNode2 = new DummySeedNode("test_dummy_dir");
    seedNode2.createAndStartP2PService(nodeAddress2, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() {

        @Override
        public void onRequestingDataCompleted() {
            latch.countDown();
        }

        @Override
        public void onNoSeedNodeAvailable() {
        }

        @Override
        public void onTorNodeReady() {
        }

        @Override
        public void onNoPeersAvailable() {
        }

        @Override
        public void onBootstrapComplete() {
            latch.countDown();
        }

        @Override
        public void onHiddenServicePublished() {
            latch.countDown();
        }

        @Override
        public void onSetupFailed(Throwable throwable) {
        }
    });
    P2PService p2PService2 = seedNode2.getSeedNodeP2PService();
    latch.await();
// Assert.assertEquals(1, p2PService1.getPeerManager().getAuthenticatedAndReportedPeers().size());
// Assert.assertEquals(1, p2PService2.getPeerManager().getAuthenticatedAndReportedPeers().size());
}
Also used : P2PServiceListener(io.bitsquare.p2p.P2PServiceListener) DummySeedNode(io.bitsquare.p2p.DummySeedNode) NodeAddress(io.bitsquare.p2p.NodeAddress) CountDownLatch(java.util.concurrent.CountDownLatch) P2PService(io.bitsquare.p2p.P2PService) Test(org.junit.Test)

Example 2 with P2PServiceListener

use of io.bitsquare.p2p.P2PServiceListener in project bitsquare by bitsquare.

the class PeerManagerTest method testSingleSeedNode.

// @Test
public void testSingleSeedNode() throws InterruptedException {
    LocalhostNetworkNode.setSimulateTorDelayTorNode(0);
    LocalhostNetworkNode.setSimulateTorDelayHiddenService(0);
    seedNodes = new HashSet<>();
    NodeAddress nodeAddress = new NodeAddress("localhost:8001");
    seedNodes.add(nodeAddress);
    seedNode1 = new DummySeedNode("test_dummy_dir");
    latch = new CountDownLatch(2);
    seedNode1.createAndStartP2PService(nodeAddress, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() {

        @Override
        public void onRequestingDataCompleted() {
            latch.countDown();
        }

        @Override
        public void onTorNodeReady() {
        }

        @Override
        public void onNoSeedNodeAvailable() {
        }

        @Override
        public void onNoPeersAvailable() {
        }

        @Override
        public void onBootstrapComplete() {
        }

        @Override
        public void onHiddenServicePublished() {
            latch.countDown();
        }

        @Override
        public void onSetupFailed(Throwable throwable) {
        }
    });
    P2PService p2PService1 = seedNode1.getSeedNodeP2PService();
    latch.await();
    Thread.sleep(500);
//Assert.assertEquals(0, p2PService1.getPeerManager().getAuthenticatedAndReportedPeers().size());
}
Also used : P2PServiceListener(io.bitsquare.p2p.P2PServiceListener) DummySeedNode(io.bitsquare.p2p.DummySeedNode) NodeAddress(io.bitsquare.p2p.NodeAddress) CountDownLatch(java.util.concurrent.CountDownLatch) P2PService(io.bitsquare.p2p.P2PService)

Example 3 with P2PServiceListener

use of io.bitsquare.p2p.P2PServiceListener in project bitsquare by bitsquare.

the class MainViewModel method initP2PNetwork.

///////////////////////////////////////////////////////////////////////////////////////////
// Initialisation
///////////////////////////////////////////////////////////////////////////////////////////
private BooleanProperty initP2PNetwork() {
    Log.traceCall();
    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 {
            if (dataReceived && hiddenService)
                result = "P2P network peers: " + numPeers;
            else if (peers == 0)
                result = state;
            else
                result = state + " / P2P network peers: " + numPeers;
        }
        return result;
    });
    p2PNetworkInfoBinding.subscribe((observable, oldValue, newValue) -> {
        p2PNetworkInfo.set(newValue);
    });
    bootstrapState.set("Connecting to Tor network...");
    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);
            //TODO
            /* new Popup()
                            .warning("You got disconnected from a seed node.\n\n" +
                                    "Reason for getting disconnected: " + connection.getRuleViolation().name() + "\n\n" +
                                    "It might be that your installed version is not compatible with " +
                                    "the network.\n\n" +
                                    "Please check if you run the latest software version.\n" +
                                    "You can download the latest version of Bitsquare at:\n" +
                                    "https://github.com/bitsquare/bitsquare/releases")
                            .show();*/
            }
        }

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

        @Override
        public void onTorNodeReady() {
            bootstrapState.set("Tor node created");
            p2PNetworkIconId.set("image-connection-tor");
            if (preferences.getUseTorForBitcoinJ())
                initWalletService();
        }

        @Override
        public void onHiddenServicePublished() {
            hiddenServicePublished.set(true);
            bootstrapState.set("Hidden Service published");
        }

        @Override
        public void onRequestingDataCompleted() {
            initialP2PNetworkDataReceived.set(true);
            bootstrapState.set("Initial data received");
            splashP2PNetworkAnimationVisible.set(false);
            p2pNetworkInitialized.set(true);
        }

        @Override
        public void onNoSeedNodeAvailable() {
            if (p2PService.getNumConnectedPeers().get() == 0)
                bootstrapWarning.set("No seed nodes available");
            else
                bootstrapWarning.set(null);
            splashP2PNetworkAnimationVisible.set(false);
            p2pNetworkInitialized.set(true);
        }

        @Override
        public void onNoPeersAvailable() {
            if (p2PService.getNumConnectedPeers().get() == 0) {
                p2pNetworkWarnMsg.set("There are no seed nodes or persisted peers available for requesting data.\n" + "Please check your internet connection or try to restart the application.");
                bootstrapWarning.set("No seed nodes and peers available");
                p2pNetworkLabelId.set("splash-error-state-msg");
            } else {
                bootstrapWarning.set(null);
                p2pNetworkLabelId.set("footer-pane");
            }
            splashP2PNetworkAnimationVisible.set(false);
            p2pNetworkInitialized.set(true);
        }

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

        @Override
        public void onSetupFailed(Throwable throwable) {
            p2pNetworkWarnMsg.set("Connecting to the P2P network failed (reported error: " + throwable.getMessage() + ").\n" + "Please check your internet connection or try to restart the application.");
            splashP2PNetworkAnimationVisible.set(false);
            bootstrapWarning.set("Bootstrapping to P2P network failed");
            p2pNetworkLabelId.set("splash-error-state-msg");
        }
    });
    return p2pNetworkInitialized;
}
Also used : Clock(io.bitsquare.common.Clock) OpenOffer(io.bitsquare.trade.offer.OpenOffer) PriceFeedService(io.bitsquare.btc.pricefeed.PriceFeedService) Popup(io.bitsquare.gui.main.overlays.popups.Popup) Transaction(org.bitcoinj.core.Transaction) MarketPrice(io.bitsquare.btc.pricefeed.MarketPrice) Coin(org.bitcoinj.core.Coin) Inject(com.google.inject.Inject) ViewModel(io.bitsquare.gui.common.model.ViewModel) LoggerFactory(org.slf4j.LoggerFactory) TradeCurrency(io.bitsquare.locale.TradeCurrency) Security(java.security.Security) TimeoutException(java.util.concurrent.TimeoutException) DisputeManager(io.bitsquare.arbitration.DisputeManager) BalanceWithConfirmationTextField(io.bitsquare.gui.components.BalanceWithConfirmationTextField) Trade(io.bitsquare.trade.Trade) GUIUtil(io.bitsquare.gui.util.GUIUtil) DevFlags(io.bitsquare.app.DevFlags) PaymentAccount(io.bitsquare.payment.PaymentAccount) NotificationCenter(io.bitsquare.gui.main.overlays.notifications.NotificationCenter) ListChangeListener(javafx.collections.ListChangeListener) Navigation(io.bitsquare.gui.Navigation) TradeWalletService(io.bitsquare.btc.TradeWalletService) BlockStoreException(org.bitcoinj.store.BlockStoreException) MonadicBinding(org.fxmisc.easybind.monadic.MonadicBinding) AddressEntry(io.bitsquare.btc.AddressEntry) WalletPasswordWindow(io.bitsquare.gui.main.overlays.windows.WalletPasswordWindow) FilterManager(io.bitsquare.filter.FilterManager) Subscription(org.fxmisc.easybind.Subscription) Collectors(java.util.stream.Collectors) PrivateNotificationManager(io.bitsquare.alert.PrivateNotificationManager) ConnectionListener(io.bitsquare.p2p.network.ConnectionListener) Preferences(io.bitsquare.user.Preferences) CryptoCurrencyAccount(io.bitsquare.payment.CryptoCurrencyAccount) Dispute(io.bitsquare.arbitration.Dispute) BalanceTextField(io.bitsquare.gui.components.BalanceTextField) Address(org.bitcoinj.core.Address) Ping(io.bitsquare.p2p.peers.keepalive.messages.Ping) ObservableList(javafx.collections.ObservableList) CurrencyUtil(io.bitsquare.locale.CurrencyUtil) io.bitsquare.common.crypto(io.bitsquare.common.crypto) PrivateNotification(io.bitsquare.alert.PrivateNotification) Version(io.bitsquare.app.Version) P2PServiceListener(io.bitsquare.p2p.P2PServiceListener) java.util(java.util) P2PService(io.bitsquare.p2p.P2PService) SetChangeListener(javafx.collections.SetChangeListener) FXCollections(javafx.collections.FXCollections) BitsquareApp(io.bitsquare.app.BitsquareApp) AddBitcoinNodesWindow(io.bitsquare.gui.main.overlays.windows.AddBitcoinNodesWindow) Connection(io.bitsquare.p2p.network.Connection) Timer(io.bitsquare.common.Timer) BalanceListener(io.bitsquare.btc.listeners.BalanceListener) OKPayAccount(io.bitsquare.payment.OKPayAccount) TradeManager(io.bitsquare.trade.TradeManager) User(io.bitsquare.user.User) WalletService(io.bitsquare.btc.WalletService) TacWindow(io.bitsquare.gui.main.overlays.windows.TacWindow) Alert(io.bitsquare.alert.Alert) DisplayAlertMessageWindow(io.bitsquare.gui.main.overlays.windows.DisplayAlertMessageWindow) Nullable(javax.annotation.Nullable) Log(io.bitsquare.app.Log) BSFormatter(io.bitsquare.gui.util.BSFormatter) javafx.beans.property(javafx.beans.property) Logger(org.slf4j.Logger) UserThread(io.bitsquare.common.UserThread) TxIdTextField(io.bitsquare.gui.components.TxIdTextField) Wallet(org.bitcoinj.core.Wallet) TimeUnit(java.util.concurrent.TimeUnit) EasyBind(org.fxmisc.easybind.EasyBind) OpenOfferManager(io.bitsquare.trade.offer.OpenOfferManager) ArbitratorManager(io.bitsquare.arbitration.ArbitratorManager) CloseConnectionReason(io.bitsquare.p2p.network.CloseConnectionReason) ChangeListener(javafx.beans.value.ChangeListener) AlertManager(io.bitsquare.alert.AlertManager) Connection(io.bitsquare.p2p.network.Connection) P2PServiceListener(io.bitsquare.p2p.P2PServiceListener) CloseConnectionReason(io.bitsquare.p2p.network.CloseConnectionReason) ConnectionListener(io.bitsquare.p2p.network.ConnectionListener)

Example 4 with P2PServiceListener

use of io.bitsquare.p2p.P2PServiceListener in project bitsquare by bitsquare.

the class PeerManagerTest method getAndStartSeedNode.

private DummySeedNode getAndStartSeedNode(int port) throws InterruptedException {
    DummySeedNode seedNode = new DummySeedNode("test_dummy_dir");
    latch = new CountDownLatch(1);
    seedNode.createAndStartP2PService(new NodeAddress("localhost", port), MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() {

        @Override
        public void onRequestingDataCompleted() {
            latch.countDown();
        }

        @Override
        public void onNoSeedNodeAvailable() {
        }

        @Override
        public void onTorNodeReady() {
        }

        @Override
        public void onNoPeersAvailable() {
        }

        @Override
        public void onBootstrapComplete() {
        }

        @Override
        public void onHiddenServicePublished() {
        }

        @Override
        public void onSetupFailed(Throwable throwable) {
        }
    });
    latch.await();
    Thread.sleep(sleepTime);
    return seedNode;
}
Also used : P2PServiceListener(io.bitsquare.p2p.P2PServiceListener) DummySeedNode(io.bitsquare.p2p.DummySeedNode) NodeAddress(io.bitsquare.p2p.NodeAddress) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

P2PServiceListener (io.bitsquare.p2p.P2PServiceListener)4 DummySeedNode (io.bitsquare.p2p.DummySeedNode)3 NodeAddress (io.bitsquare.p2p.NodeAddress)2 P2PService (io.bitsquare.p2p.P2PService)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Inject (com.google.inject.Inject)1 Alert (io.bitsquare.alert.Alert)1 AlertManager (io.bitsquare.alert.AlertManager)1 PrivateNotification (io.bitsquare.alert.PrivateNotification)1 PrivateNotificationManager (io.bitsquare.alert.PrivateNotificationManager)1 BitsquareApp (io.bitsquare.app.BitsquareApp)1 DevFlags (io.bitsquare.app.DevFlags)1 Log (io.bitsquare.app.Log)1 Version (io.bitsquare.app.Version)1 ArbitratorManager (io.bitsquare.arbitration.ArbitratorManager)1 Dispute (io.bitsquare.arbitration.Dispute)1 DisputeManager (io.bitsquare.arbitration.DisputeManager)1 AddressEntry (io.bitsquare.btc.AddressEntry)1 TradeWalletService (io.bitsquare.btc.TradeWalletService)1 WalletService (io.bitsquare.btc.WalletService)1