mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-26 16:35:18 -04:00
Pass client port form args
This commit is contained in:
parent
28e1ce4239
commit
793b3d0f37
6 changed files with 34 additions and 20 deletions
|
@ -26,6 +26,7 @@ import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
|
||||||
|
import net.tomp2p.connection.Ports;
|
||||||
import net.tomp2p.peers.Number160;
|
import net.tomp2p.peers.Number160;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -43,11 +44,16 @@ public class BitSquare {
|
||||||
private static final Logger log = LoggerFactory.getLogger(BitSquare.class);
|
private static final Logger log = LoggerFactory.getLogger(BitSquare.class);
|
||||||
|
|
||||||
private static String appName = "Bitsquare";
|
private static String appName = "Bitsquare";
|
||||||
|
private static int clientPort;
|
||||||
|
|
||||||
public static String getAppName() {
|
public static String getAppName() {
|
||||||
return appName;
|
return appName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getClientPort() {
|
||||||
|
return clientPort;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
BitsquareArgumentParser parser = new BitsquareArgumentParser();
|
BitsquareArgumentParser parser = new BitsquareArgumentParser();
|
||||||
|
@ -64,11 +70,12 @@ public class BitSquare {
|
||||||
appName = appName + "-" + namespace.getString(BitsquareArgumentParser.NAME_FLAG);
|
appName = appName + "-" + namespace.getString(BitsquareArgumentParser.NAME_FLAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (namespace.getBoolean(BitsquareArgumentParser.SEED_FLAG) == true) {
|
||||||
Integer port = BitsquareArgumentParser.PORT_DEFAULT;
|
Integer port = BitsquareArgumentParser.PORT_DEFAULT;
|
||||||
if (namespace.getString(BitsquareArgumentParser.PORT_FLAG) != null) {
|
if (namespace.getString(BitsquareArgumentParser.PORT_FLAG) != null) {
|
||||||
port = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG));
|
port = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG));
|
||||||
}
|
}
|
||||||
if (namespace.getBoolean(BitsquareArgumentParser.SEED_FLAG) == true) {
|
|
||||||
ActorSystem actorSystem = ActorSystem.create(getAppName());
|
ActorSystem actorSystem = ActorSystem.create(getAppName());
|
||||||
|
|
||||||
ActorRef seedNode = actorSystem.actorOf(DHTManager.getProps(), DHTManager.SEED_NAME);
|
ActorRef seedNode = actorSystem.actorOf(DHTManager.getProps(), DHTManager.SEED_NAME);
|
||||||
|
@ -104,6 +111,10 @@ public class BitSquare {
|
||||||
seedNodeThread.start();
|
seedNodeThread.start();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
clientPort = new Ports().tcpPort(); // default we use a random port for the client
|
||||||
|
if (namespace.getString(BitsquareArgumentParser.PORT_FLAG) != null)
|
||||||
|
clientPort = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG));
|
||||||
|
|
||||||
Application.launch(BitSquareUI.class, args);
|
Application.launch(BitSquareUI.class, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package io.bitsquare.gui.main;
|
package io.bitsquare.gui.main;
|
||||||
|
|
||||||
|
import io.bitsquare.BitSquare;
|
||||||
import io.bitsquare.bank.BankAccount;
|
import io.bitsquare.bank.BankAccount;
|
||||||
import io.bitsquare.btc.WalletFacade;
|
import io.bitsquare.btc.WalletFacade;
|
||||||
import io.bitsquare.gui.UIModel;
|
import io.bitsquare.gui.UIModel;
|
||||||
|
@ -106,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(new BootstrapListener() {
|
messageFacade.init(BitSquare.getClientPort(), new BootstrapListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCompleted() {
|
public void onCompleted() {
|
||||||
messageFacadeInited = true;
|
messageFacadeInited = true;
|
||||||
|
|
|
@ -39,7 +39,6 @@ import javafx.application.Platform;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
|
|
||||||
import net.tomp2p.connection.Ports;
|
|
||||||
import net.tomp2p.dht.PeerBuilderDHT;
|
import net.tomp2p.dht.PeerBuilderDHT;
|
||||||
import net.tomp2p.dht.PeerDHT;
|
import net.tomp2p.dht.PeerDHT;
|
||||||
import net.tomp2p.dht.StorageLayer;
|
import net.tomp2p.dht.StorageLayer;
|
||||||
|
@ -112,15 +111,13 @@ public class BootstrappedPeerFactory {
|
||||||
// Public methods
|
// Public methods
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
public ListenableFuture<PeerDHT> start() {
|
public ListenableFuture<PeerDHT> start(int port) {
|
||||||
try {
|
try {
|
||||||
int randomPort = new Ports().tcpPort();
|
|
||||||
//randomPort = 6500;
|
|
||||||
/* ChannelServerConficuration csc = PeerBuilder.createDefaultChannelServerConfiguration();
|
/* ChannelServerConficuration csc = PeerBuilder.createDefaultChannelServerConfiguration();
|
||||||
csc.idleTCPSeconds(20).idleUDPSeconds(20).connectionTimeoutTCPMillis(20000);
|
csc.idleTCPSeconds(20).idleUDPSeconds(20).connectionTimeoutTCPMillis(20000);
|
||||||
Peer peer = new PeerBuilder(keyPair).ports(randomPort).channelServerConfiguration(csc).start();*/
|
Peer peer = new PeerBuilder(keyPair).ports(port).channelServerConfiguration(csc).start();*/
|
||||||
Peer peer = new PeerBuilder(keyPair).ports(randomPort).start();
|
Peer peer = new PeerBuilder(keyPair).ports(port).start();
|
||||||
/* Peer peer = new PeerBuilder(keyPair).ports(randomPort).portsExternal(randomPort)
|
/* Peer peer = new PeerBuilder(keyPair).ports(port).portsExternal(port)
|
||||||
.channelServerConfiguration(csc).start();
|
.channelServerConfiguration(csc).start();
|
||||||
*/
|
*/
|
||||||
PeerDHT peerDHT = new PeerBuilderDHT(peer).storageLayer(new StorageLayer
|
PeerDHT peerDHT = new PeerBuilderDHT(peer).storageLayer(new StorageLayer
|
||||||
|
@ -139,6 +136,7 @@ public class BootstrappedPeerFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void peerUpdated(PeerAddress peerAddress, PeerStatatistic peerStatistics) {
|
public void peerUpdated(PeerAddress peerAddress, PeerStatatistic peerStatistics) {
|
||||||
|
log.debug("Peer updated: peerAddress=" + peerAddress + ", peerStatistics=" + peerStatistics);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -159,6 +157,9 @@ public class BootstrappedPeerFactory {
|
||||||
if (lastSuccessfulBootstrap == null)
|
if (lastSuccessfulBootstrap == null)
|
||||||
lastSuccessfulBootstrap = "default";
|
lastSuccessfulBootstrap = "default";
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
//lastSuccessfulBootstrap = "default";
|
||||||
|
|
||||||
log.debug("lastSuccessfulBootstrap = " + lastSuccessfulBootstrap);
|
log.debug("lastSuccessfulBootstrap = " + lastSuccessfulBootstrap);
|
||||||
switch (lastSuccessfulBootstrap) {
|
switch (lastSuccessfulBootstrap) {
|
||||||
case "relay":
|
case "relay":
|
||||||
|
@ -333,7 +334,7 @@ public class BootstrappedPeerFactory {
|
||||||
|
|
||||||
DistributedRelay distributedRelay = nodeBehindNat.startSetupRelay(futureRelay);
|
DistributedRelay distributedRelay = nodeBehindNat.startSetupRelay(futureRelay);
|
||||||
distributedRelay.addRelayListener((distributedRelay1, peerConnection) -> {
|
distributedRelay.addRelayListener((distributedRelay1, peerConnection) -> {
|
||||||
log.error("startSetupRelay Failed");
|
log.debug("startSetupRelay distributedRelay handler called " + distributedRelay1 + "/" + peerConnection);
|
||||||
settableFuture.setException(new Exception("startSetupRelay Failed"));
|
settableFuture.setException(new Exception("startSetupRelay Failed"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,11 +103,11 @@ public class MessageFacade implements MessageBroker {
|
||||||
// Public Methods
|
// Public Methods
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
public void init(BootstrapListener bootstrapListener) {
|
public void init(int port, BootstrapListener bootstrapListener) {
|
||||||
p2pNode.setMessageBroker(this);
|
p2pNode.setMessageBroker(this);
|
||||||
p2pNode.setKeyPair(user.getMessageKeyPair());
|
p2pNode.setKeyPair(user.getMessageKeyPair());
|
||||||
|
|
||||||
p2pNode.start(new FutureCallback<PeerDHT>() {
|
p2pNode.start(port, new FutureCallback<PeerDHT>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(@Nullable PeerDHT result) {
|
public void onSuccess(@Nullable PeerDHT result) {
|
||||||
log.debug("p2pNode.start success result = " + result);
|
log.debug("p2pNode.start success result = " + result);
|
||||||
|
|
|
@ -114,13 +114,13 @@ public class P2PNode {
|
||||||
bootstrappedPeerFactory.setKeyPair(keyPair);
|
bootstrappedPeerFactory.setKeyPair(keyPair);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(FutureCallback<PeerDHT> callback) {
|
public void start(int port, FutureCallback<PeerDHT> callback) {
|
||||||
useDiscStorage(useDiskStorage);
|
useDiscStorage(useDiskStorage);
|
||||||
|
|
||||||
bootstrappedPeerFactory.setStorage(storage);
|
bootstrappedPeerFactory.setStorage(storage);
|
||||||
setupTimerForIPCheck();
|
setupTimerForIPCheck();
|
||||||
|
|
||||||
ListenableFuture<PeerDHT> bootstrapComplete = bootstrap();
|
ListenableFuture<PeerDHT> bootstrapComplete = bootstrap(port);
|
||||||
Futures.addCallback(bootstrapComplete, callback);
|
Futures.addCallback(bootstrapComplete, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,8 +209,8 @@ public class P2PNode {
|
||||||
// Private
|
// Private
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
private ListenableFuture<PeerDHT> bootstrap() {
|
private ListenableFuture<PeerDHT> bootstrap(int port) {
|
||||||
ListenableFuture<PeerDHT> bootstrapComplete = bootstrappedPeerFactory.start();
|
ListenableFuture<PeerDHT> bootstrapComplete = bootstrappedPeerFactory.start(port);
|
||||||
Futures.addCallback(bootstrapComplete, new FutureCallback<PeerDHT>() {
|
Futures.addCallback(bootstrapComplete, new FutureCallback<PeerDHT>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(@Nullable PeerDHT peerDHT) {
|
public void onSuccess(@Nullable PeerDHT peerDHT) {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package io.bitsquare.msg.dhttest;
|
package io.bitsquare.msg.dhttest;
|
||||||
|
|
||||||
|
import io.bitsquare.BitSquare;
|
||||||
import io.bitsquare.bank.BankAccountType;
|
import io.bitsquare.bank.BankAccountType;
|
||||||
import io.bitsquare.gui.main.trade.orderbook.OrderBookListItem;
|
import io.bitsquare.gui.main.trade.orderbook.OrderBookListItem;
|
||||||
import io.bitsquare.locale.CountryUtil;
|
import io.bitsquare.locale.CountryUtil;
|
||||||
|
@ -76,7 +77,7 @@ public class DHTTestController implements Initializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle rb) {
|
public void initialize(URL url, ResourceBundle rb) {
|
||||||
messageFacade.init(new BootstrapListener() {
|
messageFacade.init(BitSquare.getClientPort(), new BootstrapListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCompleted() {
|
public void onCompleted() {
|
||||||
onMessageFacadeInitialised();
|
onMessageFacadeInitialised();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue