mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-12-13 06:55:34 -05:00
Factor out peer node creation in network stress test
This will be useful later when stopping and restarting peer nodes in mailbox send test. I added a getter to ``P2PService`` to get its public keyring.
This commit is contained in:
parent
9ad4f371b2
commit
f74d88cb33
2 changed files with 26 additions and 17 deletions
|
|
@ -775,6 +775,11 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||||
return peerManager;
|
return peerManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public KeyRing getKeyRing() {
|
||||||
|
return optionalKeyRing.get();
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Private
|
// Private
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
||||||
|
|
@ -140,24 +140,9 @@ public class NetworkStressTest {
|
||||||
for (int p = 0; p < nPeers; p++) {
|
for (int p = 0; p < nPeers; p++) {
|
||||||
// peer network port
|
// peer network port
|
||||||
final int peerPort = Utils.findFreeSystemPort();
|
final int peerPort = Utils.findFreeSystemPort();
|
||||||
|
|
||||||
// peer data directories
|
|
||||||
final File peerDir = new File(testDataDir.toFile(), String.format("peer-%06d", p));
|
|
||||||
final File peerTorDir = new File(peerDir, "tor");
|
|
||||||
final File peerStorageDir = new File(peerDir, "db");
|
|
||||||
final File peerKeysDir = new File(peerDir, "keys");
|
|
||||||
//noinspection ResultOfMethodCallIgnored
|
|
||||||
peerKeysDir.mkdirs(); // needed for creating the key ring
|
|
||||||
|
|
||||||
// peer keys
|
|
||||||
final KeyStorage peerKeyStorage = new KeyStorage(peerKeysDir);
|
|
||||||
final KeyRing peerKeyRing = new KeyRing(peerKeyStorage);
|
|
||||||
peerPKRings.add(peerKeyRing.getPubKeyRing());
|
|
||||||
final EncryptionService peerEncryptionService = new EncryptionService(peerKeyRing);
|
|
||||||
|
|
||||||
// create, save and start peer
|
// create, save and start peer
|
||||||
final P2PService peer = new P2PService(seedNodesRepository, peerPort, peerTorDir, useLocalhost,
|
final P2PService peer = createPeerNode(p, peerPort, useLocalhost, seedNodesRepository);
|
||||||
REGTEST_NETWORK_ID, peerStorageDir, new Clock(), peerEncryptionService, peerKeyRing);
|
peerPKRings.add(peer.getKeyRing().getPubKeyRing());
|
||||||
peerNodes.add(peer);
|
peerNodes.add(peer);
|
||||||
peer.start(new PeerServiceListener(localServicesLatch, localServicesFailed));
|
peer.start(new PeerServiceListener(localServicesLatch, localServicesFailed));
|
||||||
}
|
}
|
||||||
|
|
@ -185,6 +170,25 @@ public class NetworkStressTest {
|
||||||
return new NodeAddress("localhost", port);
|
return new NodeAddress("localhost", port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private P2PService createPeerNode(int n, int port, boolean useLocalhost, SeedNodesRepository seedNodesRepository) {
|
||||||
|
// 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
|
||||||
|
peerKeysDir.mkdirs(); // needed for creating the key ring
|
||||||
|
|
||||||
|
// 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, peerStorageDir, new Clock(), peerEncryptionService, peerKeyRing);
|
||||||
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws InterruptedException, IOException {
|
public void tearDown() throws InterruptedException, IOException {
|
||||||
/** A barrier to wait for concurrent shutdown of services. */
|
/** A barrier to wait for concurrent shutdown of services. */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue