mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-06 06:10:08 -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 net.tomp2p.connection.Ports;
|
||||
|
||||
/**
|
||||
* 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");
|
||||
|
||||
bindConstant().annotatedWith(Names.named("appName")).to(appName);
|
||||
|
||||
int randomPort = new Ports().tcpPort();
|
||||
bindConstant().annotatedWith(Names.named("clientPort")).to(randomPort);
|
||||
}
|
||||
|
||||
protected MessageModule messageModule() {
|
||||
|
|
|
@ -31,8 +31,6 @@ import io.bitsquare.user.User;
|
|||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
|
@ -56,7 +54,6 @@ class MainModel extends UIModel {
|
|||
private final MessageFacade messageFacade;
|
||||
private final TradeManager tradeManager;
|
||||
private final Persistence persistence;
|
||||
private final int clientPort;
|
||||
|
||||
private boolean messageFacadeInited;
|
||||
private boolean walletFacadeInited;
|
||||
|
@ -75,14 +72,12 @@ class MainModel extends UIModel {
|
|||
|
||||
@Inject
|
||||
private MainModel(User user, WalletFacade walletFacade, MessageFacade messageFacade,
|
||||
TradeManager tradeManager, Persistence persistence,
|
||||
@Named("clientPort") int clientPort) {
|
||||
TradeManager tradeManager, Persistence persistence) {
|
||||
this.user = user;
|
||||
this.walletFacade = walletFacade;
|
||||
this.messageFacade = messageFacade;
|
||||
this.tradeManager = tradeManager;
|
||||
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
|
||||
// messageFacade.init
|
||||
|
||||
messageFacade.init(clientPort, new BootstrapListener() {
|
||||
messageFacade.init(new BootstrapListener() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
messageFacadeInited = true;
|
||||
|
|
|
@ -45,7 +45,7 @@ public interface MessageFacade extends MessageBroker {
|
|||
|
||||
void getArbitrators(Locale defaultLanguageLocale);
|
||||
|
||||
void init(int clientPort, BootstrapListener bootstrapListener);
|
||||
void init(BootstrapListener bootstrapListener);
|
||||
|
||||
void getPeerAddress(PublicKey messagePublicKey, GetPeerAddressListener getPeerAddressListener);
|
||||
}
|
||||
|
|
|
@ -92,11 +92,10 @@ class TomP2PMessageFacade implements MessageFacade {
|
|||
// Public Methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void init(int port, BootstrapListener bootstrapListener) {
|
||||
public void init(BootstrapListener bootstrapListener) {
|
||||
p2pNode.setMessageBroker(this);
|
||||
p2pNode.setKeyPair(user.getMessageKeyPair());
|
||||
|
||||
p2pNode.start(port, bootstrapListener);
|
||||
p2pNode.start(bootstrapListener);
|
||||
}
|
||||
|
||||
public void shutDown() {
|
||||
|
|
|
@ -25,6 +25,8 @@ import com.google.inject.name.Names;
|
|||
|
||||
import java.util.Properties;
|
||||
|
||||
import net.tomp2p.connection.Ports;
|
||||
|
||||
import static io.bitsquare.msg.tomp2p.BootstrappedPeerFactory.*;
|
||||
import static io.bitsquare.network.BootstrapNodes.DEFAULT_BOOTSTRAP_NODE;
|
||||
|
||||
|
@ -41,6 +43,8 @@ public class TomP2PMessageModule extends MessageModule {
|
|||
|
||||
@Override
|
||||
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(TomP2PNode.class).asEagerSingleton();
|
||||
|
||||
|
|
|
@ -79,9 +79,11 @@ public class TomP2PNode {
|
|||
private static final Logger log = LoggerFactory.getLogger(TomP2PNode.class);
|
||||
|
||||
static final String USE_DISK_STORAGE_KEY = "useDiskStorage";
|
||||
static final String CLIENT_PORT_KEY = "clientPort";
|
||||
|
||||
private KeyPair keyPair;
|
||||
private String appName;
|
||||
private final int clientPort;
|
||||
private final Boolean useDiskStorage;
|
||||
private MessageBroker messageBroker;
|
||||
|
||||
|
@ -98,9 +100,11 @@ public class TomP2PNode {
|
|||
@Inject
|
||||
public TomP2PNode(BootstrappedPeerFactory bootstrappedPeerFactory,
|
||||
@Named("appName") String appName,
|
||||
@Named(CLIENT_PORT_KEY) int clientPort,
|
||||
@Named(USE_DISK_STORAGE_KEY) Boolean useDiskStorage) {
|
||||
this.bootstrappedPeerFactory = bootstrappedPeerFactory;
|
||||
this.appName = appName;
|
||||
this.clientPort = clientPort;
|
||||
this.useDiskStorage = useDiskStorage;
|
||||
}
|
||||
|
||||
|
@ -111,6 +115,7 @@ public class TomP2PNode {
|
|||
peerDHT.peerBean().keyPair(keyPair);
|
||||
messageBroker = (message, peerAddress) -> {
|
||||
};
|
||||
clientPort = -1;
|
||||
useDiskStorage = false;
|
||||
}
|
||||
|
||||
|
@ -128,13 +133,13 @@ public class TomP2PNode {
|
|||
bootstrappedPeerFactory.setKeyPair(keyPair);
|
||||
}
|
||||
|
||||
public void start(int port, BootstrapListener bootstrapListener) {
|
||||
public void start(BootstrapListener bootstrapListener) {
|
||||
useDiskStorage(useDiskStorage);
|
||||
|
||||
bootstrappedPeerFactory.setStorage(storage);
|
||||
setupTimerForIPCheck();
|
||||
|
||||
ListenableFuture<PeerDHT> bootstrapComplete = bootstrap(port);
|
||||
ListenableFuture<PeerDHT> bootstrapComplete = bootstrap(clientPort);
|
||||
Futures.addCallback(bootstrapComplete, new FutureCallback<PeerDHT>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable PeerDHT result) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue