Pass client port form args

This commit is contained in:
Manfred Karrer 2014-10-15 10:36:59 +02:00
parent 28e1ce4239
commit 793b3d0f37
6 changed files with 34 additions and 20 deletions

View File

@ -26,6 +26,7 @@ import java.util.concurrent.TimeoutException;
import javafx.application.Application;
import net.tomp2p.connection.Ports;
import net.tomp2p.peers.Number160;
import org.slf4j.Logger;
@ -43,11 +44,16 @@ public class BitSquare {
private static final Logger log = LoggerFactory.getLogger(BitSquare.class);
private static String appName = "Bitsquare";
private static int clientPort;
public static String getAppName() {
return appName;
}
public static int getClientPort() {
return clientPort;
}
public static void main(String[] args) {
BitsquareArgumentParser parser = new BitsquareArgumentParser();
@ -64,11 +70,12 @@ public class BitSquare {
appName = appName + "-" + namespace.getString(BitsquareArgumentParser.NAME_FLAG);
}
Integer port = BitsquareArgumentParser.PORT_DEFAULT;
if (namespace.getString(BitsquareArgumentParser.PORT_FLAG) != null) {
port = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG));
}
if (namespace.getBoolean(BitsquareArgumentParser.SEED_FLAG) == true) {
Integer port = BitsquareArgumentParser.PORT_DEFAULT;
if (namespace.getString(BitsquareArgumentParser.PORT_FLAG) != null) {
port = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG));
}
ActorSystem actorSystem = ActorSystem.create(getAppName());
ActorRef seedNode = actorSystem.actorOf(DHTManager.getProps(), DHTManager.SEED_NAME);
@ -104,6 +111,10 @@ public class BitSquare {
seedNodeThread.start();
}
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);
}
}

View File

@ -17,6 +17,7 @@
package io.bitsquare.gui.main;
import io.bitsquare.BitSquare;
import io.bitsquare.bank.BankAccount;
import io.bitsquare.btc.WalletFacade;
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
// messageFacade.init
messageFacade.init(new BootstrapListener() {
messageFacade.init(BitSquare.getClientPort(), new BootstrapListener() {
@Override
public void onCompleted() {
messageFacadeInited = true;

View File

@ -39,7 +39,6 @@ import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import net.tomp2p.connection.Ports;
import net.tomp2p.dht.PeerBuilderDHT;
import net.tomp2p.dht.PeerDHT;
import net.tomp2p.dht.StorageLayer;
@ -112,15 +111,13 @@ public class BootstrappedPeerFactory {
// Public methods
///////////////////////////////////////////////////////////////////////////////////////////
public ListenableFuture<PeerDHT> start() {
public ListenableFuture<PeerDHT> start(int port) {
try {
int randomPort = new Ports().tcpPort();
//randomPort = 6500;
/* ChannelServerConficuration csc = PeerBuilder.createDefaultChannelServerConfiguration();
csc.idleTCPSeconds(20).idleUDPSeconds(20).connectionTimeoutTCPMillis(20000);
Peer peer = new PeerBuilder(keyPair).ports(randomPort).channelServerConfiguration(csc).start();*/
Peer peer = new PeerBuilder(keyPair).ports(randomPort).start();
/* Peer peer = new PeerBuilder(keyPair).ports(randomPort).portsExternal(randomPort)
Peer peer = new PeerBuilder(keyPair).ports(port).channelServerConfiguration(csc).start();*/
Peer peer = new PeerBuilder(keyPair).ports(port).start();
/* Peer peer = new PeerBuilder(keyPair).ports(port).portsExternal(port)
.channelServerConfiguration(csc).start();
*/
PeerDHT peerDHT = new PeerBuilderDHT(peer).storageLayer(new StorageLayer
@ -139,6 +136,7 @@ public class BootstrappedPeerFactory {
@Override
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)
lastSuccessfulBootstrap = "default";
// TODO
//lastSuccessfulBootstrap = "default";
log.debug("lastSuccessfulBootstrap = " + lastSuccessfulBootstrap);
switch (lastSuccessfulBootstrap) {
case "relay":
@ -333,7 +334,7 @@ public class BootstrappedPeerFactory {
DistributedRelay distributedRelay = nodeBehindNat.startSetupRelay(futureRelay);
distributedRelay.addRelayListener((distributedRelay1, peerConnection) -> {
log.error("startSetupRelay Failed");
log.debug("startSetupRelay distributedRelay handler called " + distributedRelay1 + "/" + peerConnection);
settableFuture.setException(new Exception("startSetupRelay Failed"));
});
}

View File

@ -103,11 +103,11 @@ public class MessageFacade implements MessageBroker {
// Public Methods
///////////////////////////////////////////////////////////////////////////////////////////
public void init(BootstrapListener bootstrapListener) {
public void init(int port, BootstrapListener bootstrapListener) {
p2pNode.setMessageBroker(this);
p2pNode.setKeyPair(user.getMessageKeyPair());
p2pNode.start(new FutureCallback<PeerDHT>() {
p2pNode.start(port, new FutureCallback<PeerDHT>() {
@Override
public void onSuccess(@Nullable PeerDHT result) {
log.debug("p2pNode.start success result = " + result);

View File

@ -114,13 +114,13 @@ public class P2PNode {
bootstrappedPeerFactory.setKeyPair(keyPair);
}
public void start(FutureCallback<PeerDHT> callback) {
public void start(int port, FutureCallback<PeerDHT> callback) {
useDiscStorage(useDiskStorage);
bootstrappedPeerFactory.setStorage(storage);
setupTimerForIPCheck();
ListenableFuture<PeerDHT> bootstrapComplete = bootstrap();
ListenableFuture<PeerDHT> bootstrapComplete = bootstrap(port);
Futures.addCallback(bootstrapComplete, callback);
}
@ -209,8 +209,8 @@ public class P2PNode {
// Private
///////////////////////////////////////////////////////////////////////////////////////////
private ListenableFuture<PeerDHT> bootstrap() {
ListenableFuture<PeerDHT> bootstrapComplete = bootstrappedPeerFactory.start();
private ListenableFuture<PeerDHT> bootstrap(int port) {
ListenableFuture<PeerDHT> bootstrapComplete = bootstrappedPeerFactory.start(port);
Futures.addCallback(bootstrapComplete, new FutureCallback<PeerDHT>() {
@Override
public void onSuccess(@Nullable PeerDHT peerDHT) {

View File

@ -17,6 +17,7 @@
package io.bitsquare.msg.dhttest;
import io.bitsquare.BitSquare;
import io.bitsquare.bank.BankAccountType;
import io.bitsquare.gui.main.trade.orderbook.OrderBookListItem;
import io.bitsquare.locale.CountryUtil;
@ -76,7 +77,7 @@ public class DHTTestController implements Initializable {
@Override
public void initialize(URL url, ResourceBundle rb) {
messageFacade.init(new BootstrapListener() {
messageFacade.init(BitSquare.getClientPort(), new BootstrapListener() {
@Override
public void onCompleted() {
onMessageFacadeInitialised();