Move old seednode class to tests, remove seednode module

This commit is contained in:
Manfred Karrer 2016-07-12 17:17:21 +02:00
parent e1037d4eac
commit 9f5634fa90
9 changed files with 40 additions and 235 deletions

View file

@ -9,7 +9,6 @@ public class OptionKeys {
public static final String SEED_NODES_KEY = "seedNodes";
public static final String MY_ADDRESS = "myAddress";
public static final String BAN_LIST = "banList";
public static final String SEED_NODES_LIST = "seedNodes";
public static final String HELP = "help";
}

View file

@ -1,4 +1,4 @@
package io.bitsquare.p2p.seed;
package io.bitsquare.p2p;
import ch.qos.logback.classic.Level;
import com.google.common.annotations.VisibleForTesting;
@ -8,10 +8,8 @@ import io.bitsquare.common.Clock;
import io.bitsquare.common.UserThread;
import io.bitsquare.common.util.Utilities;
import io.bitsquare.network.OptionKeys;
import io.bitsquare.p2p.NodeAddress;
import io.bitsquare.p2p.P2PService;
import io.bitsquare.p2p.P2PServiceListener;
import io.bitsquare.p2p.peers.BanList;
import io.bitsquare.p2p.seed.SeedNodesRepository;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -26,11 +24,13 @@ import java.util.Set;
import static com.google.common.base.Preconditions.checkArgument;
public class SeedNode {
private static final Logger log = LoggerFactory.getLogger(SeedNode.class);
// Previously used seednode class, replaced now by bootstrap module. We keep it here as it was used in tests...
public class DummySeedNode {
private static final Logger log = LoggerFactory.getLogger(DummySeedNode.class);
public static final int MAX_CONNECTIONS_LIMIT = 1000;
public static final int MAX_CONNECTIONS_DEFAULT = 50;
public static final String SEED_NODES_LIST = "seedNodes";
public static final String HELP = "help";
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;
@ -40,7 +40,7 @@ public class SeedNode {
private final String defaultUserDataDir;
private Level logLevel = Level.WARN;
public SeedNode(String defaultUserDataDir) {
public DummySeedNode(String defaultUserDataDir) {
Log.traceCall("defaultUserDataDir=" + defaultUserDataDir);
this.defaultUserDataDir = defaultUserDataDir;
}
@ -103,8 +103,8 @@ public class SeedNode {
arg = arg.substring(io.bitsquare.common.OptionKeys.LOG_LEVEL_KEY.length() + 1);
logLevel = Level.toLevel(arg.toUpperCase());
log.info("From processArgs: logLevel=" + logLevel);
} else if (arg.startsWith(OptionKeys.SEED_NODES_LIST)) {
arg = arg.substring(OptionKeys.SEED_NODES_LIST.length() + 1);
} else if (arg.startsWith(SEED_NODES_LIST)) {
arg = arg.substring(SEED_NODES_LIST.length() + 1);
checkArgument(arg.contains(":") && arg.split(":").length > 1 && arg.split(":")[1].length() > 3,
"Wrong program argument " + arg);
List<String> list = Arrays.asList(arg.split(","));
@ -127,7 +127,7 @@ public class SeedNode {
BanList.add(new NodeAddress(e));
});
log.info("From processArgs: ignoreList=" + list);
} else if (arg.startsWith(OptionKeys.HELP)) {
} else if (arg.startsWith(HELP)) {
log.info(USAGE);
} else {
log.error("Invalid argument. " + arg + "\n" + USAGE);

View file

@ -1,7 +1,6 @@
package io.bitsquare.p2p;
import io.bitsquare.p2p.network.LocalhostNetworkNode;
import io.bitsquare.p2p.seed.SeedNode;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -27,9 +26,9 @@ public class PeerServiceTest {
final boolean useLocalhost = true;
private CountDownLatch latch;
private int sleepTime;
private SeedNode seedNode1, seedNode2, seedNode3;
private DummySeedNode seedNode1, seedNode2, seedNode3;
private Set<NodeAddress> seedNodeAddresses = new HashSet<>();
private List<SeedNode> seedNodes = new ArrayList<>();
private List<DummySeedNode> seedNodes = new ArrayList<>();
private String test_dummy_dir = "test_dummy_dir";
;
@ -81,7 +80,7 @@ public class PeerServiceTest {
int port = 8000 + i;
NodeAddress nodeAddress = new NodeAddress("localhost:" + port);
seedNodeAddresses.add(nodeAddress);
SeedNode seedNode = new SeedNode(test_dummy_dir);
DummySeedNode seedNode = new DummySeedNode(test_dummy_dir);
seedNodes.add(seedNode);
seedNode.createAndStartP2PService(true);
@ -180,7 +179,7 @@ public class PeerServiceTest {
latch = new CountDownLatch(6);
seedNode1 = new SeedNode("test_dummy_dir");
seedNode1 = new DummySeedNode("test_dummy_dir");
seedNode1.createAndStartP2PService(nodeAddress1, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodeAddresses, new P2PServiceListener() {
@Override
public void onRequestingDataCompleted() {
@ -225,7 +224,7 @@ public class PeerServiceTest {
Thread.sleep(500);
seedNode2 = new SeedNode("test_dummy_dir");
seedNode2 = new DummySeedNode("test_dummy_dir");
seedNode2.createAndStartP2PService(nodeAddress2, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodeAddresses, new P2PServiceListener() {
@Override
public void onRequestingDataCompleted() {
@ -277,12 +276,12 @@ public class PeerServiceTest {
log.debug("### start");
LocalhostNetworkNode.setSimulateTorDelayTorNode(0);
LocalhostNetworkNode.setSimulateTorDelayHiddenService(0);
SeedNode seedNode1 = getAndStartSeedNode(8001);
DummySeedNode seedNode1 = getAndStartSeedNode(8001);
log.debug("### seedNode1");
Thread.sleep(100);
log.debug("### seedNode1 100");
Thread.sleep(1000);
SeedNode seedNode2 = getAndStartSeedNode(8002);
DummySeedNode seedNode2 = getAndStartSeedNode(8002);
// authentication:
// node2 -> node1 RequestAuthenticationMessage
@ -466,8 +465,8 @@ public class PeerServiceTest {
shutDownLatch.await();*/
}
private SeedNode getAndStartSeedNode(int port) throws InterruptedException {
SeedNode seedNode = new SeedNode("test_dummy_dir");
private DummySeedNode getAndStartSeedNode(int port) throws InterruptedException {
DummySeedNode seedNode = new DummySeedNode("test_dummy_dir");
latch = new CountDownLatch(1);
seedNode.createAndStartP2PService(new NodeAddress("localhost", port), MAX_CONNECTIONS, useLocalhost, 2, true, seedNodeAddresses, new P2PServiceListener() {

View file

@ -3,7 +3,6 @@ package io.bitsquare.p2p;
import io.bitsquare.common.Clock;
import io.bitsquare.common.crypto.KeyRing;
import io.bitsquare.crypto.EncryptionService;
import io.bitsquare.p2p.seed.SeedNode;
import io.bitsquare.p2p.seed.SeedNodesRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -64,25 +63,25 @@ public class TestUtils {
return result;
}
public static SeedNode getAndStartSeedNode(int port, boolean useLocalhost, Set<NodeAddress> seedNodes) throws InterruptedException {
SeedNode seedNode;
public static DummySeedNode getAndStartSeedNode(int port, boolean useLocalhost, Set<NodeAddress> seedNodes) throws InterruptedException {
DummySeedNode seedNode;
if (useLocalhost) {
seedNodes.add(new NodeAddress("localhost:8001"));
seedNodes.add(new NodeAddress("localhost:8002"));
seedNodes.add(new NodeAddress("localhost:8003"));
sleepTime = 100;
seedNode = new SeedNode(test_dummy_dir);
seedNode = new DummySeedNode(test_dummy_dir);
} else {
seedNodes.add(new NodeAddress("3omjuxn7z73pxoee.onion:8001"));
seedNodes.add(new NodeAddress("j24fxqyghjetgpdx.onion:8002"));
seedNodes.add(new NodeAddress("45367tl6unwec6kw.onion:8003"));
sleepTime = 10000;
seedNode = new SeedNode(test_dummy_dir);
seedNode = new DummySeedNode(test_dummy_dir);
}
CountDownLatch latch = new CountDownLatch(1);
seedNode.createAndStartP2PService(new NodeAddress("localhost", port), SeedNode.MAX_CONNECTIONS_DEFAULT, useLocalhost, 2, true,
seedNode.createAndStartP2PService(new NodeAddress("localhost", port), DummySeedNode.MAX_CONNECTIONS_DEFAULT, useLocalhost, 2, true,
seedNodes, new P2PServiceListener() {
@Override
public void onRequestingDataCompleted() {

View file

@ -9,12 +9,8 @@ import io.bitsquare.common.crypto.PubKeyRing;
import io.bitsquare.common.util.Tuple3;
import io.bitsquare.crypto.DecryptedMsgWithPubKey;
import io.bitsquare.crypto.EncryptionService;
import io.bitsquare.p2p.NodeAddress;
import io.bitsquare.p2p.P2PService;
import io.bitsquare.p2p.P2PServiceListener;
import io.bitsquare.p2p.Utils;
import io.bitsquare.p2p.*;
import io.bitsquare.p2p.messaging.*;
import io.bitsquare.p2p.seed.SeedNode;
import io.bitsquare.p2p.seed.SeedNodesRepository;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
@ -140,7 +136,7 @@ public class NetworkStressTest {
/**
* A single seed node that other nodes will contact to request initial data.
*/
private SeedNode seedNode;
private DummySeedNode seedNode;
/**
* The repository of seed nodes used in the test.
*/
@ -271,12 +267,12 @@ public class NetworkStressTest {
UserThread.setExecutor(Executors.newSingleThreadExecutor());
// Create and start the seed node.
seedNode = new SeedNode(testDataDir.toString());
seedNode = new DummySeedNode(testDataDir.toString());
final NodeAddress seedNodeAddress = newSeedNodeAddress();
useLocalhost = seedNodeAddress.hostName.equals("localhost");
final Set<NodeAddress> seedNodes = new HashSet<>(1);
seedNodes.add(seedNodeAddress); // the only seed node in tests
seedNode.createAndStartP2PService(seedNodeAddress, SeedNode.MAX_CONNECTIONS_DEFAULT, useLocalhost,
seedNode.createAndStartP2PService(seedNodeAddress, DummySeedNode.MAX_CONNECTIONS_DEFAULT, useLocalhost,
REGTEST_NETWORK_ID, USE_DETAILED_LOGGING, seedNodes,
new SeedServiceListener(localServicesLatch, localServicesFailed));
print("created seed node");

View file

@ -1,10 +1,10 @@
package io.bitsquare.p2p.routing;
import io.bitsquare.p2p.DummySeedNode;
import io.bitsquare.p2p.NodeAddress;
import io.bitsquare.p2p.P2PService;
import io.bitsquare.p2p.P2PServiceListener;
import io.bitsquare.p2p.network.LocalhostNetworkNode;
import io.bitsquare.p2p.seed.SeedNode;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
@ -31,7 +31,7 @@ public class PeerManagerTest {
private CountDownLatch latch;
private Set<NodeAddress> seedNodes;
private int sleepTime;
private SeedNode seedNode1, seedNode2, seedNode3;
private DummySeedNode seedNode1, seedNode2, seedNode3;
@Before
public void setup() throws InterruptedException {
@ -81,7 +81,7 @@ public class PeerManagerTest {
seedNodes = new HashSet<>();
NodeAddress nodeAddress = new NodeAddress("localhost:8001");
seedNodes.add(nodeAddress);
seedNode1 = new SeedNode("test_dummy_dir");
seedNode1 = new DummySeedNode("test_dummy_dir");
latch = new CountDownLatch(2);
seedNode1.createAndStartP2PService(nodeAddress, MAX_CONNECTIONS, useLocalhost, 2, true,
seedNodes, new P2PServiceListener() {
@ -142,7 +142,7 @@ public class PeerManagerTest {
latch = new CountDownLatch(6);
seedNode1 = new SeedNode("test_dummy_dir");
seedNode1 = new DummySeedNode("test_dummy_dir");
seedNode1.createAndStartP2PService(nodeAddress1, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() {
@Override
public void onRequestingDataCompleted() {
@ -187,7 +187,7 @@ public class PeerManagerTest {
Thread.sleep(500);
seedNode2 = new SeedNode("test_dummy_dir");
seedNode2 = new DummySeedNode("test_dummy_dir");
seedNode2.createAndStartP2PService(nodeAddress2, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() {
@Override
public void onRequestingDataCompleted() {
@ -239,12 +239,12 @@ public class PeerManagerTest {
log.debug("### start");
LocalhostNetworkNode.setSimulateTorDelayTorNode(0);
LocalhostNetworkNode.setSimulateTorDelayHiddenService(0);
SeedNode seedNode1 = getAndStartSeedNode(8001);
DummySeedNode seedNode1 = getAndStartSeedNode(8001);
log.debug("### seedNode1");
Thread.sleep(100);
log.debug("### seedNode1 100");
Thread.sleep(1000);
SeedNode seedNode2 = getAndStartSeedNode(8002);
DummySeedNode seedNode2 = getAndStartSeedNode(8002);
// authentication:
// node2 -> node1 RequestAuthenticationMessage
@ -428,8 +428,8 @@ public class PeerManagerTest {
shutDownLatch.await();*/
}
private SeedNode getAndStartSeedNode(int port) throws InterruptedException {
SeedNode seedNode = new SeedNode("test_dummy_dir");
private DummySeedNode getAndStartSeedNode(int port) throws InterruptedException {
DummySeedNode seedNode = new DummySeedNode("test_dummy_dir");
latch = new CountDownLatch(1);
seedNode.createAndStartP2PService(new NodeAddress("localhost", port), MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() {

View file

@ -1,85 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>parent</artifactId>
<groupId>io.bitsquare</groupId>
<version>0.4.9</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>seednode</artifactId>
<build>
<resources>
<resource>
<filtering>false</filtering>
<directory>${basedir}/src/main/java</directory>
<includes>
<include>**/*.fxml</include>
<include>**/*.css</include>
</includes>
</resource>
<resource>
<filtering>false</filtering>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<!-- broken with Java 8 (MSHADE-174), using ProGuard instead. -->
<minimizeJar>false</minimizeJar>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>io.bitsquare.p2p.seed.SeedNodeMain</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<!-- exclude signatures, the bundling process breaks them for some reason -->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>bundled</shadedClassifierName>
<finalName>SeedNode</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.bitsquare</groupId>
<artifactId>core</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</project>

View file

@ -1,61 +0,0 @@
package io.bitsquare.p2p.seed;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.bitsquare.app.BitsquareEnvironment;
import io.bitsquare.common.UserThread;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.security.Security;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
public class SeedNodeMain {
private static final Logger log = LoggerFactory.getLogger(SeedNodeMain.class);
private static final boolean USE_DETAILED_LOGGING = false;
private SeedNode seedNode;
// args: myAddress (incl. port) useLocalhost seedNodes (separated with |)
// eg. lmvdenjkyvx2ovga.onion:8001 false eo5ay2lyzrfvx2nr.onion:8002|si3uu56adkyqkldl.onion:8003
public static void main(String[] args) throws InterruptedException {
new SeedNodeMain(args);
}
private SeedNodeMain(String[] args) throws InterruptedException {
final ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setNameFormat("SeedNodeMain")
.setDaemon(true)
.build();
UserThread.setExecutor(Executors.newSingleThreadExecutor(threadFactory));
// setup UncaughtExceptionHandler
Thread.UncaughtExceptionHandler handler = (thread, throwable) -> {
// Might come from another thread
log.error("Uncaught Exception from thread " + Thread.currentThread().getName());
log.error("Uncaught Exception throwableMessage= " + throwable.getMessage());
throwable.printStackTrace();
};
Thread.setDefaultUncaughtExceptionHandler(handler);
Thread.currentThread().setUncaughtExceptionHandler(handler);
Security.addProvider(new BouncyCastleProvider());
UserThread.execute(() -> {
try {
seedNode = new SeedNode(BitsquareEnvironment.defaultUserDataDir());
seedNode.processArgs(args);
seedNode.createAndStartP2PService(USE_DETAILED_LOGGING);
} catch (Throwable t) {
log.error("Executing task failed. " + t.getMessage());
t.printStackTrace();
}
});
while (true) {
Thread.sleep(Long.MAX_VALUE);
}
}
}

View file

@ -1,42 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ This file is part of Bitsquare.
~
~ Bitsquare is free software: you can redistribute it and/or modify it
~ under the terms of the GNU Affero General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or (at
~ your option) any later version.
~
~ Bitsquare is distributed in the hope that it will be useful, but WITHOUT
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
~ License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
-->
<configuration>
<appender name="CONSOLE_APPENDER" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%highlight(%d{MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{15}: %msg %xEx%n)</pattern>
</encoder>
</appender>
<root level="TRACE">
<appender-ref ref="CONSOLE_APPENDER"/>
</root>
<logger name="io.bitsquare.storage.Storage" level="WARN"/>
<logger name="io.bitsquare.storage.FileManager" level="WARN"/>
<!-- <logger name="io.bitsquare.p2p.peers.PeerGroup" level="INFO"/>
<logger name="io.bitsquare.p2p.P2PService" level="INFO"/>
<logger name="io.bitsquare.p2p.storage.ProtectedExpirableDataStorage" level="INFO"/>
<logger name="io.bitsquare.p2p.network.LocalhostNetworkNode" level="INFO"/>
<logger name="io.bitsquare.p2p.network.TorNetworkNode" level="TRACE"/>
<logger name="io.bitsquare.p2p.network.NetworkNode" level="TRACE"/>-->
<logger name="com.msopentech.thali.toronionproxy.OnionProxyManagerEventHandler" level="INFO"/>
</configuration>