mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-05-14 20:42:21 -04:00
use deamon for seednode
This commit is contained in:
parent
af30d89921
commit
7d72122a91
6 changed files with 222 additions and 97 deletions
|
@ -1,6 +1,7 @@
|
||||||
package io.bitsquare;
|
package io.bitsquare;
|
||||||
|
|
||||||
import io.bitsquare.msg.SeedNodeAddress;
|
import io.bitsquare.msg.SeedNodeAddress;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.tomp2p.dht.PeerBuilderDHT;
|
import net.tomp2p.dht.PeerBuilderDHT;
|
||||||
import net.tomp2p.futures.BaseFuture;
|
import net.tomp2p.futures.BaseFuture;
|
||||||
|
@ -25,20 +26,17 @@ import org.slf4j.LoggerFactory;
|
||||||
* <p>
|
* <p>
|
||||||
* TODO: Alternative bootstrap methods will follow later (save locally list of known nodes reported form other peers,...)
|
* TODO: Alternative bootstrap methods will follow later (save locally list of known nodes reported form other peers,...)
|
||||||
*/
|
*/
|
||||||
public class SeedNode
|
public class SeedNode extends Thread
|
||||||
{
|
{
|
||||||
private static final Logger log = LoggerFactory.getLogger(SeedNode.class);
|
private static final Logger log = LoggerFactory.getLogger(SeedNode.class);
|
||||||
|
|
||||||
private static final List<SeedNodeAddress.StaticSeedNodeAddresses> staticSedNodeAddresses = SeedNodeAddress.StaticSeedNodeAddresses.getAllSeedNodeAddresses();
|
private static final List<SeedNodeAddress.StaticSeedNodeAddresses> staticSedNodeAddresses = SeedNodeAddress.StaticSeedNodeAddresses.getAllSeedNodeAddresses();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args If no args passed we use localhost, otherwise the param is used as index for selecting an address from seedNodeAddresses
|
* @param args If no args passed we use localhost, otherwise the param is used as index for selecting an address from seedNodeAddresses
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
SeedNode seedNode = new SeedNode();
|
|
||||||
if (args.length > 0)
|
if (args.length > 0)
|
||||||
{
|
{
|
||||||
// use host index passes as param
|
// use host index passes as param
|
||||||
|
@ -46,24 +44,32 @@ public class SeedNode
|
||||||
if (param < staticSedNodeAddresses.size())
|
if (param < staticSedNodeAddresses.size())
|
||||||
index = param;
|
index = param;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SeedNode seedNode = new SeedNode(new SeedNodeAddress(staticSedNodeAddresses.get(index)));
|
||||||
|
seedNode.setDaemon(true);
|
||||||
|
seedNode.start();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
seedNode.startupUsingAddress(new SeedNodeAddress(staticSedNodeAddresses.get(index)));
|
// keep main thread up
|
||||||
} catch (Exception e)
|
Thread.sleep(Long.MAX_VALUE);
|
||||||
|
} catch (InterruptedException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
|
||||||
log.error(e.toString());
|
log.error(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private final SeedNodeAddress seedNodeAddress;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public SeedNode(SeedNodeAddress seedNodeAddress)
|
||||||
public SeedNode()
|
|
||||||
{
|
{
|
||||||
|
this.seedNodeAddress = seedNodeAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,11 +77,30 @@ public class SeedNode
|
||||||
// Public Methods
|
// Public Methods
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
public void startupUsingAddress(SeedNodeAddress seedNodeAddress)
|
public void run()
|
||||||
{
|
{
|
||||||
|
Peer peer = startupPeer();
|
||||||
|
|
||||||
|
for (; ; )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// ping(peer);
|
||||||
|
|
||||||
|
Thread.sleep(300);
|
||||||
|
} catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
log.error(e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Peer startupPeer()
|
||||||
|
{
|
||||||
|
Peer peer = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Peer peer = new PeerBuilder(Number160.createHash(seedNodeAddress.getId())).ports(seedNodeAddress.getPort()).start();
|
peer = new PeerBuilder(Number160.createHash(seedNodeAddress.getId())).ports(seedNodeAddress.getPort()).start();
|
||||||
|
|
||||||
// Need to add all features the clients will use (otherwise msg type is UNKNOWN_ID)
|
// Need to add all features the clients will use (otherwise msg type is UNKNOWN_ID)
|
||||||
new PeerBuilderDHT(peer).start();
|
new PeerBuilderDHT(peer).start();
|
||||||
|
@ -106,64 +131,69 @@ public class SeedNode
|
||||||
log.debug("Peer updated: peerAddress=" + peerAddress + ", peerStatistics=" + peerStatistics);
|
log.debug("Peer updated: peerAddress=" + peerAddress + ", peerStatistics=" + peerStatistics);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return peer;
|
||||||
|
}
|
||||||
|
|
||||||
// We keep server in endless loop
|
private void ping(Peer peer)
|
||||||
for (; ; )
|
{
|
||||||
|
if (peer != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Optional pinging
|
||||||
|
for (PeerAddress peerAddress : peer.peerBean().peerMap().all())
|
||||||
{
|
{
|
||||||
// Optional pinging
|
BaseFuture future = peer.ping().peerAddress(peerAddress).tcpPing().start();
|
||||||
boolean pingPeers = false;
|
future.addListener(new BaseFutureListener<BaseFuture>()
|
||||||
if (pingPeers)
|
|
||||||
{
|
{
|
||||||
for (PeerAddress peerAddress : peer.peerBean().peerMap().all())
|
@Override
|
||||||
|
public void operationComplete(BaseFuture future) throws Exception
|
||||||
{
|
{
|
||||||
BaseFuture future = peer.ping().peerAddress(peerAddress).tcpPing().start();
|
if (future.isSuccess())
|
||||||
future.addListener(new BaseFutureListener<BaseFuture>()
|
|
||||||
{
|
{
|
||||||
@Override
|
log.debug("peer online (TCP):" + peerAddress);
|
||||||
public void operationComplete(BaseFuture future) throws Exception
|
}
|
||||||
{
|
else
|
||||||
if (future.isSuccess())
|
|
||||||
{
|
|
||||||
log.debug("peer online (TCP):" + peerAddress);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log.debug("offline " + peerAddress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void exceptionCaught(Throwable t) throws Exception
|
|
||||||
{
|
|
||||||
log.error("exceptionCaught " + t);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
future = peer.ping().peerAddress(peerAddress).start();
|
|
||||||
future.addListener(new BaseFutureListener<BaseFuture>()
|
|
||||||
{
|
{
|
||||||
@Override
|
log.debug("offline " + peerAddress);
|
||||||
public void operationComplete(BaseFuture future) throws Exception
|
}
|
||||||
{
|
|
||||||
if (future.isSuccess())
|
|
||||||
{
|
|
||||||
log.debug("peer online (UDP):" + peerAddress);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log.debug("offline " + peerAddress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void exceptionCaught(Throwable t) throws Exception
|
|
||||||
{
|
|
||||||
log.error("exceptionCaught " + t);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Thread.sleep(1500);
|
|
||||||
}
|
@Override
|
||||||
|
public void exceptionCaught(Throwable t) throws Exception
|
||||||
|
{
|
||||||
|
log.error("exceptionCaught " + t);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
future = peer.ping().peerAddress(peerAddress).start();
|
||||||
|
future.addListener(new BaseFutureListener<BaseFuture>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void operationComplete(BaseFuture future) throws Exception
|
||||||
|
{
|
||||||
|
if (future.isSuccess())
|
||||||
|
{
|
||||||
|
log.debug("peer online (UDP):" + peerAddress);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log.debug("offline " + peerAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exceptionCaught(Throwable t) throws Exception
|
||||||
|
{
|
||||||
|
log.error("exceptionCaught " + t);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Thread.sleep(1500);
|
||||||
}
|
}
|
||||||
} catch (Exception e)
|
} catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
package io.bitsquare.di;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import javafx.util.Callback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A JavaFX controller factory for constructing controllers via Guice DI. To
|
|
||||||
* install this in the {@link javafx.fxml.FXMLLoader}, pass it as a parameter to
|
|
||||||
* {@link javafx.fxml.FXMLLoader#setControllerFactory(Callback)}.
|
|
||||||
* <p>
|
|
||||||
* Once set, make sure you do <b>not</b> use the static methods on
|
|
||||||
* {@link javafx.fxml.FXMLLoader} when creating your JavaFX node.
|
|
||||||
*/
|
|
||||||
class GuiceControllerFactory implements Callback<Class<?>, Object>
|
|
||||||
{
|
|
||||||
|
|
||||||
private final Injector injector;
|
|
||||||
|
|
||||||
public GuiceControllerFactory(Injector injector)
|
|
||||||
{
|
|
||||||
this.injector = injector;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object call(Class<?> aClass)
|
|
||||||
{
|
|
||||||
return injector.getInstance(aClass);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,6 +4,7 @@ import com.google.inject.Injector;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.util.Callback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Guice support for fxml controllers
|
* Guice support for fxml controllers
|
||||||
|
@ -16,10 +17,12 @@ public class GuiceFXMLLoader extends FXMLLoader
|
||||||
{
|
{
|
||||||
GuiceFXMLLoader.injector = injector;
|
GuiceFXMLLoader.injector = injector;
|
||||||
}
|
}
|
||||||
|
// private static ClassLoader cachingClassLoader = new CachingClassLoader(FXMLLoader.getDefaultClassLoader());
|
||||||
public GuiceFXMLLoader(URL url, ResourceBundle resourceBundle)
|
public GuiceFXMLLoader(URL url, ResourceBundle resourceBundle)
|
||||||
{
|
{
|
||||||
super(url, resourceBundle);
|
super(url, resourceBundle);
|
||||||
|
// might be helpful for performance, but need further profiling. has memory drawbacks
|
||||||
|
//setClassLoader(cachingClassLoader);
|
||||||
setupControllerFactory();
|
setupControllerFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,5 +33,30 @@ public class GuiceFXMLLoader extends FXMLLoader
|
||||||
setControllerFactory(new GuiceControllerFactory(GuiceFXMLLoader.injector));
|
setControllerFactory(new GuiceControllerFactory(GuiceFXMLLoader.injector));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A JavaFX controller factory for constructing controllers via Guice DI. To
|
||||||
|
* install this in the {@link javafx.fxml.FXMLLoader}, pass it as a parameter to
|
||||||
|
* {@link javafx.fxml.FXMLLoader#setControllerFactory(javafx.util.Callback)}.
|
||||||
|
* <p>
|
||||||
|
* Once set, make sure you do <b>not</b> use the static methods on
|
||||||
|
* {@link javafx.fxml.FXMLLoader} when creating your JavaFX node.
|
||||||
|
*/
|
||||||
|
class GuiceControllerFactory implements Callback<Class<?>, Object>
|
||||||
|
{
|
||||||
|
|
||||||
|
private final Injector injector;
|
||||||
|
|
||||||
|
public GuiceControllerFactory(Injector injector)
|
||||||
|
{
|
||||||
|
this.injector = injector;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object call(Class<?> aClass)
|
||||||
|
{
|
||||||
|
return injector.getInstance(aClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@ public class LazyLoadingTabPane extends TabPane
|
||||||
throw new IllegalArgumentException("No tabContentFXMLUrls defined");
|
throw new IllegalArgumentException("No tabContentFXMLUrls defined");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tabContentFXMLUrls = tabContentFXMLUrls;
|
|
||||||
this.navigationController = navigationController;
|
this.navigationController = navigationController;
|
||||||
this.tabContentFXMLUrls = tabContentFXMLUrls;
|
this.tabContentFXMLUrls = tabContentFXMLUrls;
|
||||||
this.persistence = persistence;
|
this.persistence = persistence;
|
||||||
|
@ -117,6 +116,7 @@ public class LazyLoadingTabPane extends TabPane
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
view = loader.load();
|
view = loader.load();
|
||||||
|
log.debug("######## " + view.toString());
|
||||||
views.put(index, view);
|
views.put(index, view);
|
||||||
|
|
||||||
childController = loader.getController();
|
childController = loader.getController();
|
||||||
|
|
|
@ -57,14 +57,12 @@ class ViewModel
|
||||||
final StringProperty directionLabel = new SimpleStringProperty();
|
final StringProperty directionLabel = new SimpleStringProperty();
|
||||||
final StringProperty collateralLabel = new SimpleStringProperty();
|
final StringProperty collateralLabel = new SimpleStringProperty();
|
||||||
final StringProperty feeLabel = new SimpleStringProperty();
|
final StringProperty feeLabel = new SimpleStringProperty();
|
||||||
|
|
||||||
final StringProperty bankAccountType = new SimpleStringProperty();
|
final StringProperty bankAccountType = new SimpleStringProperty();
|
||||||
final StringProperty bankAccountCurrency = new SimpleStringProperty();
|
final StringProperty bankAccountCurrency = new SimpleStringProperty();
|
||||||
final StringProperty bankAccountCounty = new SimpleStringProperty();
|
final StringProperty bankAccountCounty = new SimpleStringProperty();
|
||||||
final StringProperty acceptedCountries = new SimpleStringProperty();
|
final StringProperty acceptedCountries = new SimpleStringProperty();
|
||||||
final StringProperty acceptedLanguages = new SimpleStringProperty();
|
final StringProperty acceptedLanguages = new SimpleStringProperty();
|
||||||
final StringProperty transactionId = new SimpleStringProperty();
|
final StringProperty transactionId = new SimpleStringProperty();
|
||||||
|
|
||||||
final BooleanProperty isOfferPlacedScreen = new SimpleBooleanProperty();
|
final BooleanProperty isOfferPlacedScreen = new SimpleBooleanProperty();
|
||||||
final BooleanProperty isPlaceOfferButtonDisabled = new SimpleBooleanProperty();
|
final BooleanProperty isPlaceOfferButtonDisabled = new SimpleBooleanProperty();
|
||||||
}
|
}
|
||||||
|
@ -149,7 +147,6 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||||
// Interface implementation: Initializable
|
// Interface implementation: Initializable
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle rb)
|
public void initialize(URL url, ResourceBundle rb)
|
||||||
{
|
{
|
||||||
|
@ -232,6 +229,7 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// UI Handlers
|
// UI Handlers
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void onPlaceOffer()
|
public void onPlaceOffer()
|
||||||
{
|
{
|
||||||
|
|
98
src/main/java/io/bitsquare/util/CachingClassLoader.java
Normal file
98
src/main/java/io/bitsquare/util/CachingClassLoader.java
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
package io.bitsquare.util;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class CachingClassLoader extends ClassLoader
|
||||||
|
{
|
||||||
|
private final Map<String, Class> classes = new HashMap<String, Class>();
|
||||||
|
private final ClassLoader parent;
|
||||||
|
|
||||||
|
public CachingClassLoader(ClassLoader parent)
|
||||||
|
{
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> loadClass(String name) throws ClassNotFoundException
|
||||||
|
{
|
||||||
|
Class<?> c = findClass(name);
|
||||||
|
if (c == null)
|
||||||
|
{
|
||||||
|
throw new ClassNotFoundException(name);
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<?> findClass(String className) throws ClassNotFoundException
|
||||||
|
{
|
||||||
|
if (classes.containsKey(className))
|
||||||
|
{
|
||||||
|
// System.out.print("############## cached " + className);
|
||||||
|
Class<?> result = classes.get(className);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class<?> result = parent.loadClass(className);
|
||||||
|
System.out.print("############## not cached " + className);
|
||||||
|
classes.put(className, result);
|
||||||
|
return result;
|
||||||
|
} catch (ClassNotFoundException ignore)
|
||||||
|
{
|
||||||
|
// System.out.println();
|
||||||
|
classes.put(className, null);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========= delegating methods =============
|
||||||
|
@Override
|
||||||
|
public URL getResource(String name)
|
||||||
|
{
|
||||||
|
return parent.getResource(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Enumeration<URL> getResources(String name) throws IOException
|
||||||
|
{
|
||||||
|
return parent.getResources(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return parent.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDefaultAssertionStatus(boolean enabled)
|
||||||
|
{
|
||||||
|
parent.setDefaultAssertionStatus(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPackageAssertionStatus(String packageName, boolean enabled)
|
||||||
|
{
|
||||||
|
parent.setPackageAssertionStatus(packageName, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setClassAssertionStatus(String className, boolean enabled)
|
||||||
|
{
|
||||||
|
parent.setClassAssertionStatus(className, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearAssertionStatus()
|
||||||
|
{
|
||||||
|
parent.clearAssertionStatus();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue