mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-18 14:55:53 -04:00
Cleanup
This commit is contained in:
parent
7dbe3e33b1
commit
c8a6c8b330
@ -66,8 +66,8 @@ import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
||||
/**
|
||||
* Creates a DHT peer and bootstraps to the network via a bootstrap node
|
||||
*/
|
||||
class BootstrappedPeerFactory {
|
||||
private static final Logger log = LoggerFactory.getLogger(BootstrappedPeerFactory.class);
|
||||
class BootstrappedPeerBuilder {
|
||||
private static final Logger log = LoggerFactory.getLogger(BootstrappedPeerBuilder.class);
|
||||
|
||||
static final String BOOTSTRAP_NODE_KEY = "bootstrapNode";
|
||||
static final String NETWORK_INTERFACE_KEY = "interface";
|
||||
@ -93,7 +93,7 @@ class BootstrappedPeerFactory {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
public BootstrappedPeerFactory(@Named(Node.PORT_KEY) int port,
|
||||
public BootstrappedPeerBuilder(@Named(Node.PORT_KEY) int port,
|
||||
@Named(USE_MANUAL_PORT_FORWARDING_KEY) boolean useManualPortForwarding,
|
||||
@Named(BOOTSTRAP_NODE_KEY) Node bootstrapNode,
|
||||
@Named(NETWORK_INTERFACE_KEY) String networkInterface) {
|
@ -30,15 +30,15 @@ import javax.inject.Singleton;
|
||||
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import static io.bitsquare.msg.tomp2p.BootstrappedPeerFactory.*;
|
||||
import static io.bitsquare.msg.tomp2p.BootstrappedPeerBuilder.*;
|
||||
|
||||
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 USE_MANUAL_PORT_FORWARDING_KEY = BootstrappedPeerFactory.USE_MANUAL_PORT_FORWARDING_KEY;
|
||||
public static final String NETWORK_INTERFACE_KEY = BootstrappedPeerBuilder.NETWORK_INTERFACE_KEY;
|
||||
public static final String USE_MANUAL_PORT_FORWARDING_KEY = BootstrappedPeerBuilder.USE_MANUAL_PORT_FORWARDING_KEY;
|
||||
|
||||
public TomP2PMessageModule(Environment env) {
|
||||
super(env);
|
||||
@ -63,14 +63,14 @@ 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(BootstrappedPeerBuilder.class).asEagerSingleton();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doClose(Injector injector) {
|
||||
super.doClose(injector);
|
||||
|
||||
injector.getInstance(BootstrappedPeerFactory.class).shutDown();
|
||||
|
||||
injector.getInstance(BootstrappedPeerBuilder.class).shutDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,7 +80,7 @@ public class TomP2PNode implements ClientNode {
|
||||
private PeerAddress storedPeerAddress;
|
||||
|
||||
private PeerDHT peerDHT;
|
||||
private BootstrappedPeerFactory bootstrappedPeerFactory;
|
||||
private BootstrappedPeerBuilder bootstrappedPeerBuilder;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -88,8 +88,8 @@ public class TomP2PNode implements ClientNode {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
public TomP2PNode(BootstrappedPeerFactory bootstrappedPeerFactory) {
|
||||
this.bootstrappedPeerFactory = bootstrappedPeerFactory;
|
||||
public TomP2PNode(BootstrappedPeerBuilder bootstrappedPeerBuilder) {
|
||||
this.bootstrappedPeerBuilder = bootstrappedPeerBuilder;
|
||||
}
|
||||
|
||||
// for unit testing
|
||||
@ -112,16 +112,16 @@ public class TomP2PNode implements ClientNode {
|
||||
|
||||
this.messageBroker = messageBroker;
|
||||
this.keyPair = keyPair;
|
||||
bootstrappedPeerFactory.setKeyPair(keyPair);
|
||||
bootstrappedPeerBuilder.setKeyPair(keyPair);
|
||||
|
||||
Subject<BootstrapState, BootstrapState> bootstrapStateSubject = BehaviorSubject.create();
|
||||
|
||||
bootstrappedPeerFactory.getBootstrapState().addListener((ov, oldValue, newValue) -> {
|
||||
bootstrappedPeerBuilder.getBootstrapState().addListener((ov, oldValue, newValue) -> {
|
||||
log.debug("BootstrapState changed " + newValue);
|
||||
bootstrapStateSubject.onNext(newValue);
|
||||
});
|
||||
|
||||
SettableFuture<PeerDHT> bootstrapFuture = bootstrappedPeerFactory.start();
|
||||
SettableFuture<PeerDHT> bootstrapFuture = bootstrappedPeerBuilder.start();
|
||||
Futures.addCallback(bootstrapFuture, new FutureCallback<PeerDHT>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable PeerDHT peerDHT) {
|
||||
@ -374,7 +374,7 @@ public class TomP2PNode implements ClientNode {
|
||||
|
||||
@Override
|
||||
public ConnectionType getConnectionType() {
|
||||
BootstrapState bootstrapState = bootstrappedPeerFactory.getBootstrapState().get();
|
||||
BootstrapState bootstrapState = bootstrappedPeerBuilder.getBootstrapState().get();
|
||||
switch (bootstrapState) {
|
||||
case DISCOVERY_DIRECT_SUCCEEDED:
|
||||
return ConnectionType.DIRECT;
|
||||
@ -400,6 +400,6 @@ public class TomP2PNode implements ClientNode {
|
||||
|
||||
@Override
|
||||
public Node getBootstrapNodeAddress() {
|
||||
return bootstrappedPeerFactory.getBootstrapNode();
|
||||
return bootstrappedPeerBuilder.getBootstrapNode();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user