mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-06 22:29:10 -04:00
Extract clientPort constant
This commit is contained in:
parent
85f5f02378
commit
bad88f1612
6 changed files with 17 additions and 19 deletions
|
@ -36,8 +36,6 @@ import com.google.inject.name.Names;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import net.tomp2p.connection.Ports;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures all non-UI modules necessary to run a Bitsquare application.
|
* Configures all non-UI modules necessary to run a Bitsquare application.
|
||||||
*/
|
*/
|
||||||
|
@ -64,9 +62,6 @@ public class AppModule extends BitsquareModule {
|
||||||
Preconditions.checkArgument(appName != null, "App name must be non-null");
|
Preconditions.checkArgument(appName != null, "App name must be non-null");
|
||||||
|
|
||||||
bindConstant().annotatedWith(Names.named("appName")).to(appName);
|
bindConstant().annotatedWith(Names.named("appName")).to(appName);
|
||||||
|
|
||||||
int randomPort = new Ports().tcpPort();
|
|
||||||
bindConstant().annotatedWith(Names.named("clientPort")).to(randomPort);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MessageModule messageModule() {
|
protected MessageModule messageModule() {
|
||||||
|
|
|
@ -31,8 +31,6 @@ import io.bitsquare.user.User;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.BooleanProperty;
|
import javafx.beans.property.BooleanProperty;
|
||||||
import javafx.beans.property.DoubleProperty;
|
import javafx.beans.property.DoubleProperty;
|
||||||
|
@ -56,7 +54,6 @@ class MainModel extends UIModel {
|
||||||
private final MessageFacade messageFacade;
|
private final MessageFacade messageFacade;
|
||||||
private final TradeManager tradeManager;
|
private final TradeManager tradeManager;
|
||||||
private final Persistence persistence;
|
private final Persistence persistence;
|
||||||
private final int clientPort;
|
|
||||||
|
|
||||||
private boolean messageFacadeInited;
|
private boolean messageFacadeInited;
|
||||||
private boolean walletFacadeInited;
|
private boolean walletFacadeInited;
|
||||||
|
@ -75,14 +72,12 @@ class MainModel extends UIModel {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private MainModel(User user, WalletFacade walletFacade, MessageFacade messageFacade,
|
private MainModel(User user, WalletFacade walletFacade, MessageFacade messageFacade,
|
||||||
TradeManager tradeManager, Persistence persistence,
|
TradeManager tradeManager, Persistence persistence) {
|
||||||
@Named("clientPort") int clientPort) {
|
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.walletFacade = walletFacade;
|
this.walletFacade = walletFacade;
|
||||||
this.messageFacade = messageFacade;
|
this.messageFacade = messageFacade;
|
||||||
this.tradeManager = tradeManager;
|
this.tradeManager = tradeManager;
|
||||||
this.persistence = persistence;
|
this.persistence = persistence;
|
||||||
this.clientPort = clientPort;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,7 +107,7 @@ class MainModel extends UIModel {
|
||||||
// For testing with the serverside seednode we need the BootstrappedPeerFactory which gets started form
|
// For testing with the serverside seednode we need the BootstrappedPeerFactory which gets started form
|
||||||
// messageFacade.init
|
// messageFacade.init
|
||||||
|
|
||||||
messageFacade.init(clientPort, new BootstrapListener() {
|
messageFacade.init(new BootstrapListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCompleted() {
|
public void onCompleted() {
|
||||||
messageFacadeInited = true;
|
messageFacadeInited = true;
|
||||||
|
|
|
@ -45,7 +45,7 @@ public interface MessageFacade extends MessageBroker {
|
||||||
|
|
||||||
void getArbitrators(Locale defaultLanguageLocale);
|
void getArbitrators(Locale defaultLanguageLocale);
|
||||||
|
|
||||||
void init(int clientPort, BootstrapListener bootstrapListener);
|
void init(BootstrapListener bootstrapListener);
|
||||||
|
|
||||||
void getPeerAddress(PublicKey messagePublicKey, GetPeerAddressListener getPeerAddressListener);
|
void getPeerAddress(PublicKey messagePublicKey, GetPeerAddressListener getPeerAddressListener);
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,11 +92,10 @@ class TomP2PMessageFacade implements MessageFacade {
|
||||||
// Public Methods
|
// Public Methods
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
public void init(int port, BootstrapListener bootstrapListener) {
|
public void init(BootstrapListener bootstrapListener) {
|
||||||
p2pNode.setMessageBroker(this);
|
p2pNode.setMessageBroker(this);
|
||||||
p2pNode.setKeyPair(user.getMessageKeyPair());
|
p2pNode.setKeyPair(user.getMessageKeyPair());
|
||||||
|
p2pNode.start(bootstrapListener);
|
||||||
p2pNode.start(port, bootstrapListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutDown() {
|
public void shutDown() {
|
||||||
|
|
|
@ -25,6 +25,8 @@ import com.google.inject.name.Names;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import net.tomp2p.connection.Ports;
|
||||||
|
|
||||||
import static io.bitsquare.msg.tomp2p.BootstrappedPeerFactory.*;
|
import static io.bitsquare.msg.tomp2p.BootstrappedPeerFactory.*;
|
||||||
import static io.bitsquare.network.BootstrapNodes.DEFAULT_BOOTSTRAP_NODE;
|
import static io.bitsquare.network.BootstrapNodes.DEFAULT_BOOTSTRAP_NODE;
|
||||||
|
|
||||||
|
@ -41,6 +43,8 @@ public class TomP2PMessageModule extends MessageModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doConfigure() {
|
protected void doConfigure() {
|
||||||
|
Integer randomPort = new Ports().tcpPort();
|
||||||
|
bindConstant().annotatedWith(Names.named(TomP2PNode.CLIENT_PORT_KEY)).to(randomPort);
|
||||||
bind(boolean.class).annotatedWith(Names.named(TomP2PNode.USE_DISK_STORAGE_KEY)).toInstance(false);
|
bind(boolean.class).annotatedWith(Names.named(TomP2PNode.USE_DISK_STORAGE_KEY)).toInstance(false);
|
||||||
bind(TomP2PNode.class).asEagerSingleton();
|
bind(TomP2PNode.class).asEagerSingleton();
|
||||||
|
|
||||||
|
|
|
@ -79,9 +79,11 @@ public class TomP2PNode {
|
||||||
private static final Logger log = LoggerFactory.getLogger(TomP2PNode.class);
|
private static final Logger log = LoggerFactory.getLogger(TomP2PNode.class);
|
||||||
|
|
||||||
static final String USE_DISK_STORAGE_KEY = "useDiskStorage";
|
static final String USE_DISK_STORAGE_KEY = "useDiskStorage";
|
||||||
|
static final String CLIENT_PORT_KEY = "clientPort";
|
||||||
|
|
||||||
private KeyPair keyPair;
|
private KeyPair keyPair;
|
||||||
private String appName;
|
private String appName;
|
||||||
|
private final int clientPort;
|
||||||
private final Boolean useDiskStorage;
|
private final Boolean useDiskStorage;
|
||||||
private MessageBroker messageBroker;
|
private MessageBroker messageBroker;
|
||||||
|
|
||||||
|
@ -98,9 +100,11 @@ public class TomP2PNode {
|
||||||
@Inject
|
@Inject
|
||||||
public TomP2PNode(BootstrappedPeerFactory bootstrappedPeerFactory,
|
public TomP2PNode(BootstrappedPeerFactory bootstrappedPeerFactory,
|
||||||
@Named("appName") String appName,
|
@Named("appName") String appName,
|
||||||
|
@Named(CLIENT_PORT_KEY) int clientPort,
|
||||||
@Named(USE_DISK_STORAGE_KEY) Boolean useDiskStorage) {
|
@Named(USE_DISK_STORAGE_KEY) Boolean useDiskStorage) {
|
||||||
this.bootstrappedPeerFactory = bootstrappedPeerFactory;
|
this.bootstrappedPeerFactory = bootstrappedPeerFactory;
|
||||||
this.appName = appName;
|
this.appName = appName;
|
||||||
|
this.clientPort = clientPort;
|
||||||
this.useDiskStorage = useDiskStorage;
|
this.useDiskStorage = useDiskStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +115,7 @@ public class TomP2PNode {
|
||||||
peerDHT.peerBean().keyPair(keyPair);
|
peerDHT.peerBean().keyPair(keyPair);
|
||||||
messageBroker = (message, peerAddress) -> {
|
messageBroker = (message, peerAddress) -> {
|
||||||
};
|
};
|
||||||
|
clientPort = -1;
|
||||||
useDiskStorage = false;
|
useDiskStorage = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,13 +133,13 @@ public class TomP2PNode {
|
||||||
bootstrappedPeerFactory.setKeyPair(keyPair);
|
bootstrappedPeerFactory.setKeyPair(keyPair);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(int port, BootstrapListener bootstrapListener) {
|
public void start(BootstrapListener bootstrapListener) {
|
||||||
useDiskStorage(useDiskStorage);
|
useDiskStorage(useDiskStorage);
|
||||||
|
|
||||||
bootstrappedPeerFactory.setStorage(storage);
|
bootstrappedPeerFactory.setStorage(storage);
|
||||||
setupTimerForIPCheck();
|
setupTimerForIPCheck();
|
||||||
|
|
||||||
ListenableFuture<PeerDHT> bootstrapComplete = bootstrap(port);
|
ListenableFuture<PeerDHT> bootstrapComplete = bootstrap(clientPort);
|
||||||
Futures.addCallback(bootstrapComplete, new FutureCallback<PeerDHT>() {
|
Futures.addCallback(bootstrapComplete, new FutureCallback<PeerDHT>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(@Nullable PeerDHT result) {
|
public void onSuccess(@Nullable PeerDHT result) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue