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());
}
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());
}
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);
}
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);
});
}
Aggregations