diff --git a/src/main/java/io/bitsquare/app/cli/SeedNode.java b/src/main/java/io/bitsquare/app/cli/SeedNode.java index bbd21fab5b..cf3cb9491c 100644 --- a/src/main/java/io/bitsquare/app/cli/SeedNode.java +++ b/src/main/java/io/bitsquare/app/cli/SeedNode.java @@ -17,10 +17,11 @@ package io.bitsquare.app.cli; -import io.bitsquare.msg.SeedNodeAddress; import io.bitsquare.msg.actor.DHTManager; import io.bitsquare.msg.actor.command.InitializePeer; import io.bitsquare.msg.actor.event.PeerInitialized; +import io.bitsquare.network.BootstrapNode; +import io.bitsquare.network.Node; import io.bitsquare.util.BitsquareArgumentParser; import java.net.UnknownHostException; @@ -65,7 +66,7 @@ public class SeedNode { port = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG)); } - String seedID = SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN1.getId(); + String seedID = BootstrapNode.DIGITAL_OCEAN1.getId(); if (namespace.getString(BitsquareArgumentParser.PEER_ID_FLAG) != null) { seedID = namespace.getString(BitsquareArgumentParser.PEER_ID_FLAG); } @@ -74,16 +75,16 @@ public class SeedNode { final Set peerAddresses = new HashSet(); final String sid = seedID; - SeedNodeAddress.StaticSeedNodeAddresses.getAllSeedNodeAddresses().forEach(a -> { - if (!a.getId().equals(sid)) { + for (Node node : BootstrapNode.values()) { + if (!node.getId().equals(sid)) { try { - peerAddresses.add(new PeerAddress(Number160.createHash(a.getId()), a.getIp(), - a.getPort(), a.getPort())); + peerAddresses.add(new PeerAddress(Number160.createHash(node.getId()), node.getIp(), + node.getPort(), node.getPort())); } catch (UnknownHostException uhe) { - log.error("Unknown Host [" + a.getIp() + "]: " + uhe.getMessage()); + log.error("Unknown Host [" + node.getIp() + "]: " + uhe.getMessage()); } } - }); + } int serverPort = (port == -1) ? BitsquareArgumentParser.PORT_DEFAULT : port; diff --git a/src/main/java/io/bitsquare/msg/BootstrappedPeerFactory.java b/src/main/java/io/bitsquare/msg/BootstrappedPeerFactory.java index 9e15f4c5e1..0a3481fba0 100644 --- a/src/main/java/io/bitsquare/msg/BootstrappedPeerFactory.java +++ b/src/main/java/io/bitsquare/msg/BootstrappedPeerFactory.java @@ -17,6 +17,7 @@ package io.bitsquare.msg; +import io.bitsquare.network.Node; import io.bitsquare.persistence.Persistence; import com.google.common.util.concurrent.ListenableFuture; @@ -62,8 +63,6 @@ import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static io.bitsquare.msg.SeedNodeAddress.StaticSeedNodeAddresses; - /** * Creates a DHT peer and bootstrap to the network via a seed node */ @@ -73,7 +72,7 @@ public class BootstrappedPeerFactory { private KeyPair keyPair; private Storage storage; - private final SeedNodeAddress seedNodeAddress; + private final Node bootstrapNode; private final Persistence persistence; private final SettableFuture settableFuture = SettableFuture.create(); @@ -85,10 +84,9 @@ public class BootstrappedPeerFactory { /////////////////////////////////////////////////////////////////////////////////////////// @Inject - public BootstrappedPeerFactory(Persistence persistence, - @Named("defaultSeedNode") StaticSeedNodeAddresses defaultStaticSeedNodeAddresses) { + public BootstrappedPeerFactory(Persistence persistence, @Named("bootstrapNode") Node bootstrapNode) { this.persistence = persistence; - this.seedNodeAddress = new SeedNodeAddress(defaultStaticSeedNodeAddresses); + this.bootstrapNode = bootstrapNode; } @@ -303,10 +301,10 @@ public class BootstrappedPeerFactory { private PeerAddress getBootstrapAddress() { try { - return new PeerAddress(Number160.createHash(seedNodeAddress.getId()), - InetAddress.getByName(seedNodeAddress.getIp()), - seedNodeAddress.getPort(), - seedNodeAddress.getPort()); + return new PeerAddress(Number160.createHash(bootstrapNode.getId()), + InetAddress.getByName(bootstrapNode.getIp()), + bootstrapNode.getPort(), + bootstrapNode.getPort()); } catch (UnknownHostException e) { log.error("getBootstrapAddress failed: " + e.getMessage()); return null; diff --git a/src/main/java/io/bitsquare/msg/DHTSeedService.java b/src/main/java/io/bitsquare/msg/DHTSeedService.java index ab4912cf36..a2dc92aa38 100644 --- a/src/main/java/io/bitsquare/msg/DHTSeedService.java +++ b/src/main/java/io/bitsquare/msg/DHTSeedService.java @@ -22,17 +22,12 @@ import io.bitsquare.msg.actor.command.InitializePeer; import com.google.inject.Inject; -import java.util.List; - import net.tomp2p.peers.Number160; import akka.actor.ActorSystem; public class DHTSeedService extends ActorService { - private static final List staticSedNodeAddresses = SeedNodeAddress - .StaticSeedNodeAddresses.getAllSeedNodeAddresses(); - @Inject public DHTSeedService(ActorSystem system) { super(system, "/user/" + DHTManager.SEED_NAME); diff --git a/src/main/java/io/bitsquare/msg/DefaultMessageModule.java b/src/main/java/io/bitsquare/msg/DefaultMessageModule.java index acfe38eceb..bacba0cd7d 100644 --- a/src/main/java/io/bitsquare/msg/DefaultMessageModule.java +++ b/src/main/java/io/bitsquare/msg/DefaultMessageModule.java @@ -18,6 +18,8 @@ package io.bitsquare.msg; import io.bitsquare.AbstractBitsquareModule; +import io.bitsquare.network.BootstrapNode; +import io.bitsquare.network.Node; import com.google.inject.Injector; import com.google.inject.name.Names; @@ -40,9 +42,9 @@ public class DefaultMessageModule extends AbstractBitsquareModule implements Mes // we will probably later use disk storage instead of memory storage for TomP2P bind(Boolean.class).annotatedWith(Names.named("useDiskStorage")).toInstance(false); - bind(SeedNodeAddress.StaticSeedNodeAddresses.class) - .annotatedWith(Names.named("defaultSeedNode")) - .toInstance(SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN1); + bind(Node.class) + .annotatedWith(Names.named("bootstrapNode")) + .toInstance(BootstrapNode.DIGITAL_OCEAN1); } @Override diff --git a/src/main/java/io/bitsquare/msg/SeedNodeAddress.java b/src/main/java/io/bitsquare/msg/SeedNodeAddress.java deleted file mode 100644 index eb971973b5..0000000000 --- a/src/main/java/io/bitsquare/msg/SeedNodeAddress.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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 . - */ - -package io.bitsquare.msg; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -// TODO Might be better with a config file -public class SeedNodeAddress { - private final String id; - private final String ip; - private final int port; - - public SeedNodeAddress(StaticSeedNodeAddresses staticSeedNodeAddresses) { - this(staticSeedNodeAddresses.getId(), staticSeedNodeAddresses.getIp(), staticSeedNodeAddresses.getPort()); - } - - public SeedNodeAddress(String id, String ip, int port) { - this.id = id; - this.ip = ip; - this.port = port; - } - - public String getId() { - return id; - } - - public String getIp() { - return ip; - } - - public int getPort() { - return port; - } - - - /////////////////////////////////////////////////////////////////////////////////////////// - // Enum - /////////////////////////////////////////////////////////////////////////////////////////// - - public enum StaticSeedNodeAddresses { - // Manfreds server: "188.226.179.109" - // Steves server: "128.199.251.106" - DIGITAL_OCEAN1("digitalocean1.bitsquare.io", "188.226.179.109", 5000), - LOCALHOST("localhost", "127.0.0.1", 5000); - // DIGITAL_OCEAN2("digitalocean2.bitsquare.io", "128.199.251.106", 5000); - //LOCALHOST("localhost", "127.0.0.1", 5000); - - private final String id; - private final String ip; - private final int port; - - StaticSeedNodeAddresses(String id, String ip, int port) { - this.id = id; - this.ip = ip; - this.port = port; - } - - public static List getAllSeedNodeAddresses() { - return new ArrayList<>(Arrays.asList(StaticSeedNodeAddresses.values())); - } - - public String getId() { - return id; - } - - public String getIp() { - return ip; - } - - public int getPort() { - return port; - } - } -} diff --git a/src/main/java/io/bitsquare/network/BootstrapNode.java b/src/main/java/io/bitsquare/network/BootstrapNode.java new file mode 100644 index 0000000000..0d8d7daa90 --- /dev/null +++ b/src/main/java/io/bitsquare/network/BootstrapNode.java @@ -0,0 +1,47 @@ +/* + * 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 . + */ + +package io.bitsquare.network; + +public enum BootstrapNode implements Node { + DIGITAL_OCEAN1("digitalocean1.bitsquare.io", "188.226.179.109", 5000); + + private final String id; + private final String ip; + private final int port; + + BootstrapNode(String id, String ip, int port) { + this.id = id; + this.ip = ip; + this.port = port; + } + + @Override + public String getId() { + return id; + } + + @Override + public String getIp() { + return ip; + } + + @Override + public int getPort() { + return port; + } +} diff --git a/src/main/java/io/bitsquare/network/Node.java b/src/main/java/io/bitsquare/network/Node.java new file mode 100644 index 0000000000..e0f10b3b07 --- /dev/null +++ b/src/main/java/io/bitsquare/network/Node.java @@ -0,0 +1,29 @@ +/* + * 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 . + */ + +package io.bitsquare.network; + +public interface Node { + + String getId(); + + String getIp(); + + int getPort(); + +} + diff --git a/src/main/java/io/bitsquare/util/BitsquareArgumentParser.java b/src/main/java/io/bitsquare/util/BitsquareArgumentParser.java index 43c1765e17..590b36d542 100644 --- a/src/main/java/io/bitsquare/util/BitsquareArgumentParser.java +++ b/src/main/java/io/bitsquare/util/BitsquareArgumentParser.java @@ -17,7 +17,7 @@ package io.bitsquare.util; -import io.bitsquare.msg.SeedNodeAddress; +import io.bitsquare.network.BootstrapNode; import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.inf.ArgumentParser; @@ -48,7 +48,7 @@ public class BitsquareArgumentParser { .defaultHelp(true) .description("Bitsquare - The decentralized bitcoin exchange."); parser.addArgument("-d", "--" + PEER_ID_FLAG) - .setDefault(SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN1.getId()) + .setDefault(BootstrapNode.DIGITAL_OCEAN1.getId()) .help("Seed peer ID."); parser.addArgument("-p", "--" + PORT_FLAG) .help("IP port to listen on.");