Search in sources :

Example 1 with SeedNodesRepository

use of io.bitsquare.p2p.seed.SeedNodesRepository in project bitsquare by bitsquare.

the class DummySeedNode method createAndStartP2PService.

@VisibleForTesting
public void createAndStartP2PService(NodeAddress mySeedNodeAddress, int maxConnections, boolean useLocalhost, int networkId, boolean useDetailedLogging, @Nullable Set<NodeAddress> progArgSeedNodes, @Nullable P2PServiceListener listener) {
    Path appPath = Paths.get(defaultUserDataDir, "Bitsquare_seed_node_" + String.valueOf(mySeedNodeAddress.getFullAddress().replace(":", "_")));
    String logPath = Paths.get(appPath.toString(), "logs").toString();
    Log.setup(logPath);
    log.debug("Log files under: " + logPath);
    Version.printVersion();
    Utilities.printSysInfo();
    Log.setLevel(logLevel);
    SeedNodesRepository seedNodesRepository = new SeedNodesRepository();
    if (progArgSeedNodes != null && !progArgSeedNodes.isEmpty()) {
        if (useLocalhost)
            seedNodesRepository.setLocalhostSeedNodeAddresses(progArgSeedNodes);
        else
            seedNodesRepository.setTorSeedNodeAddresses(progArgSeedNodes);
    }
    File storageDir = Paths.get(appPath.toString(), "db").toFile();
    if (storageDir.mkdirs())
        log.debug("Created storageDir at " + storageDir.getAbsolutePath());
    File torDir = Paths.get(appPath.toString(), "tor").toFile();
    if (torDir.mkdirs())
        log.debug("Created torDir at " + torDir.getAbsolutePath());
    seedNodesRepository.setNodeAddressToExclude(mySeedNodeAddress);
    seedNodeP2PService = new P2PService(seedNodesRepository, mySeedNodeAddress.port, maxConnections, torDir, useLocalhost, networkId, storageDir, null, null, null, new Clock(), null, null, null);
    seedNodeP2PService.start(listener);
}
Also used : Path(java.nio.file.Path) SeedNodesRepository(io.bitsquare.p2p.seed.SeedNodesRepository) Clock(io.bitsquare.common.Clock) File(java.io.File) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with SeedNodesRepository

use of io.bitsquare.p2p.seed.SeedNodesRepository in project bitsquare by bitsquare.

the class TestUtils method getAndAuthenticateP2PService.

public static P2PService getAndAuthenticateP2PService(int port, EncryptionService encryptionService, KeyRing keyRing, boolean useLocalhost, Set<NodeAddress> seedNodes) throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    SeedNodesRepository seedNodesRepository = new SeedNodesRepository();
    if (seedNodes != null && !seedNodes.isEmpty()) {
        if (useLocalhost)
            seedNodesRepository.setLocalhostSeedNodeAddresses(seedNodes);
        else
            seedNodesRepository.setTorSeedNodeAddresses(seedNodes);
    }
    P2PService p2PService = new P2PService(seedNodesRepository, port, new File("seed_node_" + port), useLocalhost, 2, P2PService.MAX_CONNECTIONS_DEFAULT, new File("dummy"), null, null, null, new Clock(), null, encryptionService, keyRing);
    p2PService.start(new P2PServiceListener() {

        @Override
        public void onRequestingDataCompleted() {
        }

        @Override
        public void onNoSeedNodeAvailable() {
        }

        @Override
        public void onNoPeersAvailable() {
        }

        @Override
        public void onTorNodeReady() {
        }

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

        @Override
        public void onHiddenServicePublished() {
        }

        @Override
        public void onSetupFailed(Throwable throwable) {
        }
    });
    latch.await();
    Thread.sleep(2000);
    return p2PService;
}
Also used : SeedNodesRepository(io.bitsquare.p2p.seed.SeedNodesRepository) CountDownLatch(java.util.concurrent.CountDownLatch) Clock(io.bitsquare.common.Clock)

Aggregations

Clock (io.bitsquare.common.Clock)2 SeedNodesRepository (io.bitsquare.p2p.seed.SeedNodesRepository)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 File (java.io.File)1 Path (java.nio.file.Path)1 CountDownLatch (java.util.concurrent.CountDownLatch)1