mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-25 07:27:18 +01:00
Rename io.bitsquare.{msg.SeedNodeAddress=>network.Node}
This commit is contained in:
parent
11b6a4a341
commit
d77af7900f
8 changed files with 100 additions and 119 deletions
|
@ -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<PeerAddress> peerAddresses = new HashSet<PeerAddress>();
|
||||
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;
|
||||
|
||||
|
|
|
@ -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<PeerDHT> 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;
|
||||
|
|
|
@ -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<SeedNodeAddress.StaticSeedNodeAddresses> staticSedNodeAddresses = SeedNodeAddress
|
||||
.StaticSeedNodeAddresses.getAllSeedNodeAddresses();
|
||||
|
||||
@Inject
|
||||
public DHTSeedService(ActorSystem system) {
|
||||
super(system, "/user/" + DHTManager.SEED_NAME);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<StaticSeedNodeAddresses> getAllSeedNodeAddresses() {
|
||||
return new ArrayList<>(Arrays.asList(StaticSeedNodeAddresses.values()));
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
}
|
||||
}
|
47
src/main/java/io/bitsquare/network/BootstrapNode.java
Normal file
47
src/main/java/io/bitsquare/network/BootstrapNode.java
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
29
src/main/java/io/bitsquare/network/Node.java
Normal file
29
src/main/java/io/bitsquare/network/Node.java
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.network;
|
||||
|
||||
public interface Node {
|
||||
|
||||
String getId();
|
||||
|
||||
String getIp();
|
||||
|
||||
int getPort();
|
||||
|
||||
}
|
||||
|
|
@ -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.");
|
||||
|
|
Loading…
Add table
Reference in a new issue