Move {MessageModule=>BootstrappedPeerFactory}#BOOTSTRAP_NODE_KEY

This commit is contained in:
Chris Beams 2014-11-10 08:20:15 +01:00
parent 426ee28b93
commit 9bdb4b4249
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
3 changed files with 17 additions and 16 deletions

View File

@ -18,15 +18,12 @@
package io.bitsquare.msg;
import io.bitsquare.BitsquareModule;
import io.bitsquare.network.Node;
import com.google.inject.Injector;
import com.google.inject.name.Names;
import java.util.Properties;
import static io.bitsquare.network.BootstrapNodes.DEFAULT_BOOTSTRAP_NODE;
public abstract class MessageModule extends BitsquareModule {
public static final String BOOTSTRAP_NODE_ID_KEY = "id";
@ -34,8 +31,6 @@ public abstract class MessageModule extends BitsquareModule {
public static final String BOOTSTRAP_NODE_PORT_KEY = "port";
public static final String NETWORK_INTERFACE_KEY = "networkInterface";
public static final String BOOTSTRAP_NODE_KEY = "bootstrapNode";
protected MessageModule(Properties properties) {
super(properties);
}
@ -44,16 +39,6 @@ public abstract class MessageModule extends BitsquareModule {
protected final void configure() {
bind(MessageFacade.class).to(messageFacade()).asEagerSingleton();
Node bootstrapNode = Node.at(
properties.getProperty(BOOTSTRAP_NODE_ID_KEY, DEFAULT_BOOTSTRAP_NODE.getId()),
properties.getProperty(BOOTSTRAP_NODE_IP_KEY, DEFAULT_BOOTSTRAP_NODE.getIp()),
properties.getProperty(BOOTSTRAP_NODE_PORT_KEY, DEFAULT_BOOTSTRAP_NODE.getPortAsString())
);
bind(Node.class)
.annotatedWith(Names.named(BOOTSTRAP_NODE_KEY))
.toInstance(bootstrapNode);
bind(String.class)
.annotatedWith(Names.named("networkInterface"))
.toInstance(properties.getProperty(NETWORK_INTERFACE_KEY, ""));

View File

@ -68,7 +68,7 @@ import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static io.bitsquare.msg.MessageModule.BOOTSTRAP_NODE_KEY;
/**
* Creates a DHT peer and bootstrap to the network via a seed node
@ -76,6 +76,8 @@ import static io.bitsquare.msg.MessageModule.BOOTSTRAP_NODE_KEY;
class BootstrappedPeerFactory {
private static final Logger log = LoggerFactory.getLogger(BootstrappedPeerFactory.class);
static final String BOOTSTRAP_NODE_KEY = "bootstrapNode";
private KeyPair keyPair;
private Storage storage;
private final Node bootstrapNode;

View File

@ -19,11 +19,14 @@ package io.bitsquare.msg.tomp2p;
import io.bitsquare.msg.MessageFacade;
import io.bitsquare.msg.MessageModule;
import io.bitsquare.network.Node;
import com.google.inject.name.Names;
import java.util.Properties;
import static io.bitsquare.network.BootstrapNodes.DEFAULT_BOOTSTRAP_NODE;
public class TomP2PMessageModule extends MessageModule {
public TomP2PMessageModule(Properties properties) {
@ -36,6 +39,17 @@ public class TomP2PMessageModule extends MessageModule {
bind(Boolean.class).annotatedWith(Names.named(TomP2PNode.USE_DISK_STORAGE_KEY)).toInstance(false);
bind(TomP2PNode.class).asEagerSingleton();
Node bootstrapNode = Node.at(
properties.getProperty(BOOTSTRAP_NODE_ID_KEY, DEFAULT_BOOTSTRAP_NODE.getId()),
properties.getProperty(BOOTSTRAP_NODE_IP_KEY, DEFAULT_BOOTSTRAP_NODE.getIp()),
properties.getProperty(BOOTSTRAP_NODE_PORT_KEY, DEFAULT_BOOTSTRAP_NODE.getPortAsString())
);
bind(Node.class)
.annotatedWith(Names.named(BootstrappedPeerFactory.BOOTSTRAP_NODE_KEY))
.toInstance(bootstrapNode);
bind(BootstrappedPeerFactory.class).asEagerSingleton();
}