From dc90a950cbbef95a58d25cc2ceaedf2d06ae6b5b Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Fri, 6 May 2016 10:07:28 +0200 Subject: [PATCH] Pass max connections to ``SeedNode.createAndStartP2PService()`` Still keep calls to ``PeerManager.setMaxConnections()`` until it is retired. --- .../main/java/io/bitsquare/p2p/seed/SeedNode.java | 13 +++++++------ .../test/java/io/bitsquare/p2p/PeerServiceTest.java | 11 ++++++----- .../src/test/java/io/bitsquare/p2p/TestUtils.java | 2 +- .../io/bitsquare/p2p/routing/PeerManagerTest.java | 11 ++++++----- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/network/src/main/java/io/bitsquare/p2p/seed/SeedNode.java b/network/src/main/java/io/bitsquare/p2p/seed/SeedNode.java index 389fa7fb91..1f081dea08 100644 --- a/network/src/main/java/io/bitsquare/p2p/seed/SeedNode.java +++ b/network/src/main/java/io/bitsquare/p2p/seed/SeedNode.java @@ -30,6 +30,7 @@ public class SeedNode { public static final int MAX_CONNECTIONS_DEFAULT = 50; private NodeAddress mySeedNodeAddress = new NodeAddress("localhost:8001"); + private int maxConnections = MAX_CONNECTIONS_DEFAULT; // we keep default a higher connection size for seed nodes private boolean useLocalhost = false; private Set progArgSeedNodes; private P2PService seedNodeP2PService; @@ -67,13 +68,10 @@ public class SeedNode { Version.setBtcNetworkId(networkId); if (args.length > 2) { String arg2 = args[2]; - int maxConnections = Integer.parseInt(arg2); + maxConnections = Integer.parseInt(arg2); log.info("From processArgs: maxConnections=" + maxConnections); checkArgument(maxConnections < MAX_CONNECTIONS_LIMIT, "maxConnections seems to be a bit too high..."); PeerManager.setMaxConnections(maxConnections); - } else { - // we keep default a higher connection size for seed nodes - PeerManager.setMaxConnections(MAX_CONNECTIONS_DEFAULT); } if (args.length > 3) { String arg3 = args[3]; @@ -107,11 +105,13 @@ public class SeedNode { } public void createAndStartP2PService(boolean useDetailedLogging) { - createAndStartP2PService(mySeedNodeAddress, useLocalhost, Version.getBtcNetworkId(), useDetailedLogging, progArgSeedNodes, null); + createAndStartP2PService(mySeedNodeAddress, maxConnections, useLocalhost, + Version.getBtcNetworkId(), useDetailedLogging, progArgSeedNodes, null); } @VisibleForTesting public void createAndStartP2PService(NodeAddress mySeedNodeAddress, + int maxConnections, boolean useLocalhost, int networkId, boolean useDetailedLogging, @@ -144,7 +144,8 @@ public class SeedNode { log.info("Created torDir at " + torDir.getAbsolutePath()); seedNodesRepository.setNodeAddressToExclude(mySeedNodeAddress); - seedNodeP2PService = new P2PService(seedNodesRepository, mySeedNodeAddress.port, torDir, useLocalhost, networkId, storageDir, new Clock(), null, null); + seedNodeP2PService = new P2PService(seedNodesRepository, mySeedNodeAddress.port, maxConnections, + torDir, useLocalhost, networkId, storageDir, new Clock(), null, null); seedNodeP2PService.start(listener); } diff --git a/network/src/test/java/io/bitsquare/p2p/PeerServiceTest.java b/network/src/test/java/io/bitsquare/p2p/PeerServiceTest.java index 8723561751..068295185c 100644 --- a/network/src/test/java/io/bitsquare/p2p/PeerServiceTest.java +++ b/network/src/test/java/io/bitsquare/p2p/PeerServiceTest.java @@ -23,6 +23,7 @@ import java.util.concurrent.CountDownLatch; // Run it once then lookup for onion address at: tor/hiddenservice/hostname and use that for the NodeAddress param. public class PeerServiceTest { private static final Logger log = LoggerFactory.getLogger(PeerServiceTest.class); + public static final int MAX_CONNECTIONS = 100; final boolean useLocalhost = true; private CountDownLatch latch; @@ -37,7 +38,7 @@ public class PeerServiceTest { public void setup() throws InterruptedException { LocalhostNetworkNode.setSimulateTorDelayTorNode(50); LocalhostNetworkNode.setSimulateTorDelayHiddenService(8); - PeerManager.setMaxConnections(100); + PeerManager.setMaxConnections(MAX_CONNECTIONS); if (useLocalhost) { seedNodeAddresses.add(new NodeAddress("localhost:8001")); @@ -127,7 +128,7 @@ public class PeerServiceTest { /* latch = new CountDownLatch(2); - seedNode.createAndStartP2PService(nodeAddress, useLocalhost, 2, true, + seedNode.createAndStartP2PService(nodeAddress, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodeAddresses, new P2PServiceListener() { @Override public void onRequestingDataCompleted() { @@ -181,7 +182,7 @@ public class PeerServiceTest { latch = new CountDownLatch(6); seedNode1 = new SeedNode("test_dummy_dir"); - seedNode1.createAndStartP2PService(nodeAddress1, useLocalhost, 2, true, seedNodeAddresses, new P2PServiceListener() { + seedNode1.createAndStartP2PService(nodeAddress1, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodeAddresses, new P2PServiceListener() { @Override public void onRequestingDataCompleted() { latch.countDown(); @@ -219,7 +220,7 @@ public class PeerServiceTest { Thread.sleep(500); seedNode2 = new SeedNode("test_dummy_dir"); - seedNode2.createAndStartP2PService(nodeAddress2, useLocalhost, 2, true, seedNodeAddresses, new P2PServiceListener() { + seedNode2.createAndStartP2PService(nodeAddress2, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodeAddresses, new P2PServiceListener() { @Override public void onRequestingDataCompleted() { latch.countDown(); @@ -456,7 +457,7 @@ public class PeerServiceTest { SeedNode seedNode = new SeedNode("test_dummy_dir"); latch = new CountDownLatch(1); - seedNode.createAndStartP2PService(new NodeAddress("localhost", port), useLocalhost, 2, true, seedNodeAddresses, new P2PServiceListener() { + seedNode.createAndStartP2PService(new NodeAddress("localhost", port), MAX_CONNECTIONS, useLocalhost, 2, true, seedNodeAddresses, new P2PServiceListener() { @Override public void onRequestingDataCompleted() { latch.countDown(); diff --git a/network/src/test/java/io/bitsquare/p2p/TestUtils.java b/network/src/test/java/io/bitsquare/p2p/TestUtils.java index b5b40cdd95..25a6fdcc01 100644 --- a/network/src/test/java/io/bitsquare/p2p/TestUtils.java +++ b/network/src/test/java/io/bitsquare/p2p/TestUtils.java @@ -82,7 +82,7 @@ public class TestUtils { } CountDownLatch latch = new CountDownLatch(1); - seedNode.createAndStartP2PService(new NodeAddress("localhost", port), useLocalhost, 2, true, + seedNode.createAndStartP2PService(new NodeAddress("localhost", port), SeedNode.MAX_CONNECTIONS_DEFAULT, useLocalhost, 2, true, seedNodes, new P2PServiceListener() { @Override public void onRequestingDataCompleted() { diff --git a/network/src/test/java/io/bitsquare/p2p/routing/PeerManagerTest.java b/network/src/test/java/io/bitsquare/p2p/routing/PeerManagerTest.java index 96ec47e6ca..aefde4cd6f 100644 --- a/network/src/test/java/io/bitsquare/p2p/routing/PeerManagerTest.java +++ b/network/src/test/java/io/bitsquare/p2p/routing/PeerManagerTest.java @@ -26,6 +26,7 @@ import java.util.concurrent.CountDownLatch; @Ignore public class PeerManagerTest { private static final Logger log = LoggerFactory.getLogger(PeerManagerTest.class); + public static final int MAX_CONNECTIONS = 100; final boolean useLocalhost = true; private CountDownLatch latch; @@ -37,7 +38,7 @@ public class PeerManagerTest { public void setup() throws InterruptedException { LocalhostNetworkNode.setSimulateTorDelayTorNode(50); LocalhostNetworkNode.setSimulateTorDelayHiddenService(8); - PeerManager.setMaxConnections(100); + PeerManager.setMaxConnections(MAX_CONNECTIONS); seedNodes = new HashSet<>(); if (useLocalhost) { @@ -84,7 +85,7 @@ public class PeerManagerTest { seedNodes.add(nodeAddress); seedNode1 = new SeedNode("test_dummy_dir"); latch = new CountDownLatch(2); - seedNode1.createAndStartP2PService(nodeAddress, useLocalhost, 2, true, + seedNode1.createAndStartP2PService(nodeAddress, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() { @Override public void onRequestingDataCompleted() { @@ -136,7 +137,7 @@ public class PeerManagerTest { latch = new CountDownLatch(6); seedNode1 = new SeedNode("test_dummy_dir"); - seedNode1.createAndStartP2PService(nodeAddress1, useLocalhost, 2, true, seedNodes, new P2PServiceListener() { + seedNode1.createAndStartP2PService(nodeAddress1, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() { @Override public void onRequestingDataCompleted() { latch.countDown(); @@ -174,7 +175,7 @@ public class PeerManagerTest { Thread.sleep(500); seedNode2 = new SeedNode("test_dummy_dir"); - seedNode2.createAndStartP2PService(nodeAddress2, useLocalhost, 2, true, seedNodes, new P2PServiceListener() { + seedNode2.createAndStartP2PService(nodeAddress2, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() { @Override public void onRequestingDataCompleted() { latch.countDown(); @@ -411,7 +412,7 @@ public class PeerManagerTest { SeedNode seedNode = new SeedNode("test_dummy_dir"); latch = new CountDownLatch(1); - seedNode.createAndStartP2PService(new NodeAddress("localhost", port), useLocalhost, 2, true, seedNodes, new P2PServiceListener() { + seedNode.createAndStartP2PService(new NodeAddress("localhost", port), MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() { @Override public void onRequestingDataCompleted() { latch.countDown();