Rename BootstrappedPeerFactory to BootstrappedPeerDHTBuilder

This commit is contained in:
Manfred Karrer 2014-11-13 12:13:51 +01:00
parent a134c85f24
commit 00455dfd7a
4 changed files with 21 additions and 21 deletions

View File

@ -19,7 +19,7 @@ package io.bitsquare.gui.main.preferences.network;
import io.bitsquare.BitsquareException;
import io.bitsquare.gui.PresentationModel;
import io.bitsquare.msg.tomp2p.BootstrappedPeerFactory;
import io.bitsquare.msg.tomp2p.BootstrappedPeerDHTBuilder;
import io.bitsquare.msg.tomp2p.TomP2PNode;
import io.bitsquare.network.BootstrapState;
import io.bitsquare.network.Node;
@ -49,9 +49,9 @@ public class NetworkPreferencesPM extends PresentationModel {
@Inject
NetworkPreferencesPM(NetworkParameters networkParameters,
BootstrappedPeerFactory bootstrappedPeerFactory,
BootstrappedPeerDHTBuilder bootstrappedPeerDHTBuilder,
TomP2PNode tomP2PNode,
@Named(BootstrappedPeerFactory.BOOTSTRAP_NODE_KEY) Node bootstrapNode) {
@Named(BootstrappedPeerDHTBuilder.BOOTSTRAP_NODE_KEY) Node bootstrapNode) {
switch (networkParameters.getId()) {
case NetworkParameters.ID_REGTEST:
@ -77,7 +77,7 @@ public class NetworkPreferencesPM extends PresentationModel {
+ ", IP: " + bootstrapNode.getIp()
+ ", Port: " + bootstrapNode.getPortAsString();
BootstrapState state = bootstrappedPeerFactory.bootstrapState.get();
BootstrapState state = bootstrappedPeerDHTBuilder.bootstrapState.get();
if (state == BootstrapState.DIRECT_SUCCESS)
p2pNetworkConnection = "Direct connection";
else if (state == BootstrapState.NAT_SUCCESS)

View File

@ -70,8 +70,8 @@ import org.slf4j.LoggerFactory;
/**
* Creates a DHT peer and bootstraps to the network via a bootstrap node
*/
public class BootstrappedPeerFactory {
private static final Logger log = LoggerFactory.getLogger(BootstrappedPeerFactory.class);
public class BootstrappedPeerDHTBuilder {
private static final Logger log = LoggerFactory.getLogger(BootstrappedPeerDHTBuilder.class);
public static final String BOOTSTRAP_NODE_KEY = "bootstrapNode";
static final String NETWORK_INTERFACE_KEY = "interface";
@ -94,10 +94,10 @@ public class BootstrappedPeerFactory {
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public BootstrappedPeerFactory(Persistence persistence,
@Named(Node.PORT_KEY) int port,
@Named(BOOTSTRAP_NODE_KEY) Node bootstrapNode,
@Named(NETWORK_INTERFACE_KEY) String networkInterface) {
public BootstrappedPeerDHTBuilder(Persistence persistence,
@Named(Node.PORT_KEY) int port,
@Named(BOOTSTRAP_NODE_KEY) Node bootstrapNode,
@Named(NETWORK_INTERFACE_KEY) String networkInterface) {
this.persistence = persistence;
this.port = port;
this.bootstrapNode = bootstrapNode;
@ -314,7 +314,7 @@ public class BootstrappedPeerFactory {
public void operationComplete(BaseFuture future) throws Exception {
if (futureBootstrap.isSuccess()) {
setState(state, "Bootstrap successful.");
persistence.write(BootstrappedPeerFactory.this, "lastSuccessfulBootstrap", state);
persistence.write(BootstrappedPeerDHTBuilder.this, "lastSuccessfulBootstrap", state);
settableFuture.set(peerDHT);
}
else {

View File

@ -26,14 +26,14 @@ import com.google.inject.name.Names;
import org.springframework.core.env.Environment;
import static io.bitsquare.msg.tomp2p.BootstrappedPeerFactory.*;
import static io.bitsquare.msg.tomp2p.BootstrappedPeerDHTBuilder.*;
public class TomP2PMessageModule extends MessageModule {
public static final String BOOTSTRAP_NODE_NAME_KEY = "bootstrap.node.name";
public static final String BOOTSTRAP_NODE_IP_KEY = "bootstrap.node.ip";
public static final String BOOTSTRAP_NODE_PORT_KEY = "bootstrap.node.port";
public static final String NETWORK_INTERFACE_KEY = BootstrappedPeerFactory.NETWORK_INTERFACE_KEY;
public static final String NETWORK_INTERFACE_KEY = BootstrappedPeerDHTBuilder.NETWORK_INTERFACE_KEY;
public TomP2PMessageModule(Environment env) {
super(env);
@ -54,7 +54,7 @@ public class TomP2PMessageModule extends MessageModule {
);
bindConstant().annotatedWith(Names.named(NETWORK_INTERFACE_KEY)).to(
env.getProperty(NETWORK_INTERFACE_KEY, NETWORK_INTERFACE_UNSPECIFIED));
bind(BootstrappedPeerFactory.class).asEagerSingleton();
bind(BootstrappedPeerDHTBuilder.class).asEagerSingleton();
}
@Override

View File

@ -76,7 +76,7 @@ public class TomP2PNode {
private PeerAddress storedPeerAddress;
private PeerDHT peerDHT;
private BootstrappedPeerFactory bootstrappedPeerFactory;
private BootstrappedPeerDHTBuilder bootstrappedPeerDHTBuilder;
///////////////////////////////////////////////////////////////////////////////////////////
@ -84,8 +84,8 @@ public class TomP2PNode {
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public TomP2PNode(BootstrappedPeerFactory bootstrappedPeerFactory) {
this.bootstrappedPeerFactory = bootstrappedPeerFactory;
public TomP2PNode(BootstrappedPeerDHTBuilder bootstrappedPeerDHTBuilder) {
this.bootstrappedPeerDHTBuilder = bootstrappedPeerDHTBuilder;
}
// for unit testing
@ -108,17 +108,17 @@ public class TomP2PNode {
public void setKeyPair(@NotNull KeyPair keyPair) {
this.keyPair = keyPair;
bootstrappedPeerFactory.setKeyPair(keyPair);
bootstrappedPeerDHTBuilder.setKeyPair(keyPair);
}
public void bootstrap(BootstrapListener bootstrapListener) {
checkNotNull(keyPair, "keyPair must not be null.");
checkNotNull(messageBroker, "messageBroker must not be null.");
bootstrappedPeerFactory.bootstrapState.addListener((ov, oldValue, newValue) ->
bootstrappedPeerDHTBuilder.bootstrapState.addListener((ov, oldValue, newValue) ->
bootstrapListener.onBootstrapStateChanged(newValue));
SettableFuture<PeerDHT> bootstrapFuture = bootstrappedPeerFactory.start();
SettableFuture<PeerDHT> bootstrapFuture = bootstrappedPeerDHTBuilder.start();
Futures.addCallback(bootstrapFuture, new FutureCallback<PeerDHT>() {
@Override
public void onSuccess(@Nullable PeerDHT peerDHT) {
@ -149,7 +149,7 @@ public class TomP2PNode {
}
public void shutDown() {
bootstrappedPeerFactory.shutDown();
bootstrappedPeerDHTBuilder.shutDown();
if (peerDHT != null)
peerDHT.shutdown();