Search in sources :

Example 1 with P2PService

use of io.bitsquare.p2p.P2PService 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 P2PService

use of io.bitsquare.p2p.P2PService 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 P2PService

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

the class ProtectedDataStorageTest method setup.

@Before
public void setup() throws InterruptedException, NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, CryptoException, SignatureException, InvalidKeyException {
    Security.addProvider(new BouncyCastleProvider());
    dir1 = File.createTempFile("temp_tests1", "");
    dir1.delete();
    dir1.mkdir();
    dir2 = File.createTempFile("temp_tests2", "");
    dir2.delete();
    dir2.mkdir();
    UserThread.setExecutor(Executors.newSingleThreadExecutor());
    P2PDataStorage.CHECK_TTL_INTERVAL_SEC = 500;
    keyRing1 = new KeyRing(new KeyStorage(dir1));
    storageSignatureKeyPair1 = keyRing1.getSignatureKeyPair();
    encryptionService1 = new EncryptionService(keyRing1);
    P2PService p2PService = TestUtils.getAndStartSeedNode(8001, useClearNet, seedNodes).getSeedNodeP2PService();
    networkNode1 = p2PService.getNetworkNode();
    peerManager1 = p2PService.getPeerManager();
    dataStorage1 = p2PService.getP2PDataStorage();
    // for mailbox
    keyRing2 = new KeyRing(new KeyStorage(dir2));
    storageSignatureKeyPair2 = keyRing2.getSignatureKeyPair();
    encryptionService2 = new EncryptionService(keyRing2);
    mockData = new MockData("mockData", keyRing1.getSignatureKeyPair().getPublic());
    Thread.sleep(sleepTime);
}
Also used : EncryptionService(io.bitsquare.crypto.EncryptionService) MockData(io.bitsquare.p2p.storage.mocks.MockData) P2PService(io.bitsquare.p2p.P2PService) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 4 with P2PService

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

the class TradeStatisticsManager method init.

private void init(P2PService p2PService) {
    if (dumpStatistics) {
        this.statisticsJsonStorage.initWithFileName("trade_statistics.json");
        this.fiatCurrencyListJsonStorage.initWithFileName("fiat_currency_list.json");
        ArrayList<CurrencyTuple> fiatCurrencyList = new ArrayList<>(CurrencyUtil.getAllSortedFiatCurrencies().stream().map(e -> new CurrencyTuple(e.getCode(), e.getName(), 8)).collect(Collectors.toList()));
        fiatCurrencyListJsonStorage.queueUpForSave(new PlainTextWrapper(Utilities.objectToJson(fiatCurrencyList)), 2000);
        this.cryptoCurrencyListJsonStorage.initWithFileName("crypto_currency_list.json");
        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("BTC", "Bitcoin", 8));
        cryptoCurrencyListJsonStorage.queueUpForSave(new PlainTextWrapper(Utilities.objectToJson(cryptoCurrencyList)), 2000);
    }
    HashSet<TradeStatistics> persisted = statisticsStorage.initAndGetPersistedWithFileName("TradeStatistics");
    if (persisted != null)
        persisted.stream().forEach(e -> add(e, false));
    p2PService.addHashSetChangedListener(new HashMapChangedListener() {

        @Override
        public void onAdded(ProtectedStorageEntry data) {
            final StoragePayload storagePayload = data.getStoragePayload();
            if (storagePayload instanceof TradeStatistics)
                add((TradeStatistics) storagePayload, true);
        }

        @Override
        public void onRemoved(ProtectedStorageEntry data) {
        // We don't remove items
        }
    });
    // At startup the P2PDataStorage inits earlier, otherwise we ge the listener called.
    p2PService.getP2PDataStorage().getMap().values().forEach(e -> {
        final StoragePayload storagePayload = e.getStoragePayload();
        if (storagePayload instanceof TradeStatistics)
            add((TradeStatistics) storagePayload, false);
    });
}
Also used : CurrencyTuple(io.bitsquare.locale.CurrencyTuple) ObservableSet(javafx.collections.ObservableSet) Utilities(io.bitsquare.common.util.Utilities) Logger(org.slf4j.Logger) P2PService(io.bitsquare.p2p.P2PService) Inject(com.google.inject.Inject) ProtectedStorageEntry(io.bitsquare.p2p.storage.storageentry.ProtectedStorageEntry) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) HashMapChangedListener(io.bitsquare.p2p.storage.HashMapChangedListener) StoragePayload(io.bitsquare.p2p.storage.payload.StoragePayload) Collectors(java.util.stream.Collectors) AppOptionKeys(io.bitsquare.app.AppOptionKeys) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) PlainTextWrapper(io.bitsquare.storage.PlainTextWrapper) Named(com.google.inject.name.Named) Storage(io.bitsquare.storage.Storage) CurrencyUtil(io.bitsquare.locale.CurrencyUtil) CurrencyTuple(io.bitsquare.locale.CurrencyTuple) HashMapChangedListener(io.bitsquare.p2p.storage.HashMapChangedListener) ArrayList(java.util.ArrayList) PlainTextWrapper(io.bitsquare.storage.PlainTextWrapper) StoragePayload(io.bitsquare.p2p.storage.payload.StoragePayload) ProtectedStorageEntry(io.bitsquare.p2p.storage.storageentry.ProtectedStorageEntry)

Aggregations

P2PService (io.bitsquare.p2p.P2PService)4 DummySeedNode (io.bitsquare.p2p.DummySeedNode)2 NodeAddress (io.bitsquare.p2p.NodeAddress)2 P2PServiceListener (io.bitsquare.p2p.P2PServiceListener)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Inject (com.google.inject.Inject)1 Named (com.google.inject.name.Named)1 AppOptionKeys (io.bitsquare.app.AppOptionKeys)1 Utilities (io.bitsquare.common.util.Utilities)1 EncryptionService (io.bitsquare.crypto.EncryptionService)1 CurrencyTuple (io.bitsquare.locale.CurrencyTuple)1 CurrencyUtil (io.bitsquare.locale.CurrencyUtil)1 HashMapChangedListener (io.bitsquare.p2p.storage.HashMapChangedListener)1 MockData (io.bitsquare.p2p.storage.mocks.MockData)1 StoragePayload (io.bitsquare.p2p.storage.payload.StoragePayload)1 ProtectedStorageEntry (io.bitsquare.p2p.storage.storageentry.ProtectedStorageEntry)1 PlainTextWrapper (io.bitsquare.storage.PlainTextWrapper)1 Storage (io.bitsquare.storage.Storage)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1