use of io.bitsquare.common.Clock in project bitsquare by bitsquare.
the class P2PService method init.
private void init(boolean useLocalhost, int networkId, File storageDir, String seedNodes, String myAddress, String banList) {
if (!useLocalhost)
FileUtil.rollingBackup(new File(Paths.get(torDir.getAbsolutePath(), "hiddenservice").toString()), "private_key", 20);
if (banList != null && !banList.isEmpty())
BanList.setList(Arrays.asList(banList.replace(" ", "").split(",")).stream().map(NodeAddress::new).collect(Collectors.toList()));
if (myAddress != null && !myAddress.isEmpty())
seedNodesRepository.setNodeAddressToExclude(new NodeAddress(myAddress));
networkNode = useLocalhost ? new LocalhostNetworkNode(port) : new TorNetworkNode(port, torDir);
networkNode.addConnectionListener(this);
networkNode.addMessageListener(this);
Set<NodeAddress> seedNodeAddresses;
if (seedNodes != null && !seedNodes.isEmpty())
seedNodeAddresses = Arrays.asList(seedNodes.replace(" ", "").split(",")).stream().map(NodeAddress::new).collect(Collectors.toSet());
else
seedNodeAddresses = seedNodesRepository.getSeedNodeAddresses(useLocalhost, networkId);
peerManager = new PeerManager(networkNode, maxConnections, seedNodeAddresses, storageDir, clock);
broadcaster = new Broadcaster(networkNode, peerManager);
p2PDataStorage = new P2PDataStorage(broadcaster, networkNode, storageDir);
p2PDataStorage.addHashMapChangedListener(this);
requestDataManager = new RequestDataManager(networkNode, p2PDataStorage, peerManager, seedNodeAddresses, this);
peerExchangeManager = new PeerExchangeManager(networkNode, peerManager, seedNodeAddresses);
keepAliveManager = new KeepAliveManager(networkNode, peerManager);
// We need to have both the initial data delivered and the hidden service published
networkReadyBinding = EasyBind.combine(hiddenServicePublished, preliminaryDataReceived, (hiddenServicePublished, preliminaryDataReceived) -> hiddenServicePublished && preliminaryDataReceived);
networkReadySubscription = networkReadyBinding.subscribe((observable, oldValue, newValue) -> {
if (newValue)
onNetworkReady();
});
}
use of io.bitsquare.common.Clock in project bitsquare by bitsquare.
the class StressTestMailboxMessage method createPeerNode.
@NotNull
private P2PService createPeerNode(int n, int port) {
// peer data directories
final File peerDir = new File(testDataDir.toFile(), String.format("peer-%06d", n));
final File peerTorDir = new File(peerDir, "tor");
final File peerStorageDir = new File(peerDir, "db");
final File peerKeysDir = new File(peerDir, "keys");
//noinspection ResultOfMethodCallIgnored
// needed for creating the key ring
peerKeysDir.mkdirs();
// peer keys
final KeyStorage peerKeyStorage = new KeyStorage(peerKeysDir);
final KeyRing peerKeyRing = new KeyRing(peerKeyStorage);
final EncryptionService peerEncryptionService = new EncryptionService(peerKeyRing);
return new P2PService(seedNodesRepository, port, peerTorDir, useLocalhost, REGTEST_NETWORK_ID, P2PService.MAX_CONNECTIONS_DEFAULT, peerStorageDir, null, null, null, new Clock(), null, peerEncryptionService, peerKeyRing);
}
use of io.bitsquare.common.Clock 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);
}
use of io.bitsquare.common.Clock 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;
}
Aggregations