mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-19 23:36:00 -04:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
501a3ccbc2
@ -33,7 +33,6 @@ repositories {
|
||||
dependencies {
|
||||
compile 'org.bitcoinj:bitcoinj-core:0.12'
|
||||
compile 'net.tomp2p:tomp2p-all:5.0-Alpha.32cd9f9-SNAPSHOT'
|
||||
compile 'com.typesafe.akka:akka-actor_2.10:2.3.4'
|
||||
compile 'org.slf4j:slf4j-api:1.7.7'
|
||||
compile 'ch.qos.logback:logback-core:1.1.2'
|
||||
compile 'ch.qos.logback:logback-classic:1.1.2'
|
||||
|
@ -38,17 +38,11 @@ import java.util.Properties;
|
||||
|
||||
import net.tomp2p.connection.Ports;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import akka.actor.ActorSystem;
|
||||
import scala.concurrent.duration.Duration;
|
||||
|
||||
/**
|
||||
* Configures all non-UI modules necessary to run a Bitsquare application.
|
||||
*/
|
||||
public class AppModule extends BitsquareModule {
|
||||
private static final Logger log = LoggerFactory.getLogger(AppModule.class);
|
||||
public static final String APP_NAME_KEY = "appName";
|
||||
|
||||
public AppModule(Properties properties) {
|
||||
super(properties);
|
||||
@ -66,11 +60,10 @@ public class AppModule extends BitsquareModule {
|
||||
install(tradeModule());
|
||||
install(offerModule());
|
||||
|
||||
String appName = properties.getProperty(ArgumentParser.NAME_FLAG);
|
||||
String appName = properties.getProperty(APP_NAME_KEY);
|
||||
Preconditions.checkArgument(appName != null, "App name must be non-null");
|
||||
|
||||
bindConstant().annotatedWith(Names.named("appName")).to(appName);
|
||||
bind(ActorSystem.class).toInstance(ActorSystem.create(appName));
|
||||
|
||||
int randomPort = new Ports().tcpPort();
|
||||
bindConstant().annotatedWith(Names.named("clientPort")).to(randomPort);
|
||||
@ -98,13 +91,6 @@ public class AppModule extends BitsquareModule {
|
||||
|
||||
@Override
|
||||
protected void doClose(Injector injector) {
|
||||
ActorSystem actorSystem = injector.getInstance(ActorSystem.class);
|
||||
actorSystem.shutdown();
|
||||
try {
|
||||
actorSystem.awaitTermination(Duration.create(5L, "seconds"));
|
||||
} catch (Exception ex) {
|
||||
log.error("Actor system failed to shut down properly", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,13 +21,10 @@ import net.sourceforge.argparse4j.ArgumentParsers;
|
||||
import net.sourceforge.argparse4j.inf.ArgumentParserException;
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
|
||||
public class ArgumentParser {
|
||||
import static io.bitsquare.app.AppModule.APP_NAME_KEY;
|
||||
import static io.bitsquare.msg.MessageModule.*;
|
||||
|
||||
public static final String SEED_ID_FLAG = "id";
|
||||
public static final String SEED_IP_FLAG = "ip";
|
||||
public static final String SEED_PORT_FLAG = "port";
|
||||
public static final String INTERFACE_HINT_FLAG = "interface";
|
||||
public static final String NAME_FLAG = "name";
|
||||
public class ArgumentParser {
|
||||
|
||||
private final net.sourceforge.argparse4j.inf.ArgumentParser parser;
|
||||
|
||||
@ -37,17 +34,15 @@ public class ArgumentParser {
|
||||
.description("Bitsquare - The decentralized bitcoin exchange");
|
||||
|
||||
// Args for seed node config
|
||||
parser.addArgument("-d", "--" + SEED_ID_FLAG)
|
||||
parser.addArgument("-d", "--" + BOOTSTRAP_NODE_ID_KEY)
|
||||
.help("Seed node ID");
|
||||
parser.addArgument("-s", "--" + SEED_IP_FLAG)
|
||||
parser.addArgument("-s", "--" + BOOTSTRAP_NODE_IP_KEY)
|
||||
.help("Seed node IP");
|
||||
parser.addArgument("-p", "--" + SEED_PORT_FLAG)
|
||||
parser.addArgument("-p", "--" + BOOTSTRAP_NODE_PORT_KEY)
|
||||
.help("Seed node port");
|
||||
parser.addArgument("-i", "--" + INTERFACE_HINT_FLAG)
|
||||
.help("Network interface to listen on");
|
||||
|
||||
// Args for app config
|
||||
parser.addArgument("-n", "--" + NAME_FLAG)
|
||||
parser.addArgument("-n", "--" + APP_NAME_KEY)
|
||||
.help("Name to append to default application name");
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,8 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
|
||||
import static io.bitsquare.msg.MessageModule.*;
|
||||
|
||||
public class SeedNode {
|
||||
private static final Logger log = LoggerFactory.getLogger(SeedNode.class);
|
||||
|
||||
@ -51,13 +53,13 @@ public class SeedNode {
|
||||
int port = defaultNode.getPort();
|
||||
|
||||
// Passed program args will override the properties of the default bootstrapNode
|
||||
// So you can use the same id but different ports (e.g. running several nodes on one server with
|
||||
// So you can use the same id but different ports (e.g. running several nodes on one server with
|
||||
// different ports)
|
||||
if (namespace.getString(ArgumentParser.SEED_ID_FLAG) != null)
|
||||
id = namespace.getString(ArgumentParser.SEED_ID_FLAG);
|
||||
if (namespace.getString(BOOTSTRAP_NODE_ID_KEY) != null)
|
||||
id = namespace.getString(BOOTSTRAP_NODE_ID_KEY);
|
||||
|
||||
if (namespace.getString(ArgumentParser.SEED_PORT_FLAG) != null)
|
||||
port = Integer.valueOf(namespace.getString(ArgumentParser.SEED_PORT_FLAG));
|
||||
if (namespace.getString(BOOTSTRAP_NODE_PORT_KEY) != null)
|
||||
port = Integer.valueOf(namespace.getString(BOOTSTRAP_NODE_PORT_KEY));
|
||||
|
||||
try {
|
||||
Number160 peerId = Number160.createHash(id);
|
||||
@ -105,8 +107,8 @@ public class SeedNode {
|
||||
}
|
||||
peer = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*public static void main(String[] args) throws Exception {
|
||||
ArgumentParser parser = new ArgumentParser();
|
||||
Namespace namespace = parser.parseArgs(args);
|
||||
@ -116,7 +118,7 @@ public class SeedNode {
|
||||
int port = defaultNode.getPort();
|
||||
|
||||
// Passed program args will override the properties of the default bootstrapNode
|
||||
// So you can use the same id but different ports (e.g. running several nodes on one server with
|
||||
// So you can use the same id but different ports (e.g. running several nodes on one server with
|
||||
// different ports)
|
||||
if (namespace.getString(ArgumentParser.SEED_ID_FLAG) != null)
|
||||
id = namespace.getString(ArgumentParser.SEED_ID_FLAG);
|
||||
|
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* This file is part of Bitsquare.
|
||||
*
|
||||
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.app.cli;
|
||||
|
||||
import io.bitsquare.app.ArgumentParser;
|
||||
import io.bitsquare.msg.actor.DHTManager;
|
||||
import io.bitsquare.msg.actor.command.InitializePeer;
|
||||
import io.bitsquare.msg.actor.event.PeerInitialized;
|
||||
import io.bitsquare.network.BootstrapNodes;
|
||||
import io.bitsquare.network.Node;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import net.tomp2p.peers.Number160;
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.actor.Inbox;
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
|
||||
public class SeedNodeUsingAkka {
|
||||
private static final Logger log = LoggerFactory.getLogger(SeedNodeUsingAkka.class);
|
||||
|
||||
private static String interfaceHint;
|
||||
|
||||
public static void main(String[] args) {
|
||||
ArgumentParser parser = new ArgumentParser();
|
||||
Namespace namespace = parser.parseArgs(args);
|
||||
|
||||
if (namespace.getString(ArgumentParser.INTERFACE_HINT_FLAG) != null)
|
||||
interfaceHint = namespace.getString(ArgumentParser.INTERFACE_HINT_FLAG);
|
||||
|
||||
int serverPort = Integer.valueOf(namespace.getString(ArgumentParser.SEED_PORT_FLAG));
|
||||
String seedID = BootstrapNodes.LOCALHOST.getId();
|
||||
if (namespace.getString(ArgumentParser.SEED_ID_FLAG) != null) {
|
||||
seedID = namespace.getString(ArgumentParser.SEED_ID_FLAG);
|
||||
}
|
||||
|
||||
final Set<PeerAddress> peerAddresses = new HashSet<>();
|
||||
for (Node node : BootstrapNodes.all()) {
|
||||
if (!node.getId().equals(seedID)) {
|
||||
try {
|
||||
peerAddresses.add(new PeerAddress(Number160.createHash(node.getId()), node.getIp(),
|
||||
node.getPort(), node.getPort()));
|
||||
} catch (UnknownHostException uhe) {
|
||||
log.error("Unknown Host [" + node.getIp() + "]: " + uhe.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ActorSystem actorSystem = ActorSystem.create("BitsquareSeedNode");
|
||||
Inbox inbox = Inbox.create(actorSystem);
|
||||
ActorRef seedNode = actorSystem.actorOf(DHTManager.getProps(), DHTManager.SEED_NODE);
|
||||
inbox.send(seedNode, new InitializePeer(Number160.createHash(seedID), serverPort, interfaceHint,
|
||||
peerAddresses));
|
||||
|
||||
final String _seedID = seedID;
|
||||
Thread seedNodeThread = new Thread(() -> {
|
||||
Boolean quit = false;
|
||||
while (!quit) {
|
||||
try {
|
||||
Object m = inbox.receive(FiniteDuration.create(5L, "seconds"));
|
||||
if (m instanceof PeerInitialized) {
|
||||
log.debug("Seed Peer with ID " + _seedID +
|
||||
" initialized on port " + ((PeerInitialized) m).getPort());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof TimeoutException)) {
|
||||
quit = true;
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
actorSystem.shutdown();
|
||||
try {
|
||||
actorSystem.awaitTermination(Duration.create(5L, "seconds"));
|
||||
} catch (Exception ex) {
|
||||
if (ex instanceof TimeoutException)
|
||||
log.error("ActorSystem did not shutdown properly.");
|
||||
else
|
||||
log.error(ex.getMessage());
|
||||
}
|
||||
});
|
||||
seedNodeThread.start();
|
||||
}
|
||||
}
|
@ -49,7 +49,8 @@ import org.slf4j.LoggerFactory;
|
||||
import lighthouse.files.AppDirectory;
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
|
||||
import static io.bitsquare.app.ArgumentParser.*;
|
||||
import static io.bitsquare.app.AppModule.APP_NAME_KEY;
|
||||
import static io.bitsquare.msg.MessageModule.*;
|
||||
|
||||
public class Main extends Application {
|
||||
private static final Logger log = LoggerFactory.getLogger(Main.class);
|
||||
@ -62,21 +63,21 @@ public class Main extends Application {
|
||||
public static void main(String[] args) {
|
||||
Namespace argumentsNamespace = new ArgumentParser().parseArgs(args);
|
||||
|
||||
if (argumentsNamespace.getString(NAME_FLAG) != null)
|
||||
appName = appName + "-" + argumentsNamespace.getString(NAME_FLAG);
|
||||
if (argumentsNamespace.getString(APP_NAME_KEY) != null)
|
||||
appName = appName + "-" + argumentsNamespace.getString(APP_NAME_KEY);
|
||||
|
||||
properties = ConfigLoader.loadConfig(appName);
|
||||
|
||||
properties.setProperty(NAME_FLAG, appName);
|
||||
properties.setProperty(APP_NAME_KEY, appName);
|
||||
|
||||
if (argumentsNamespace.getString(SEED_ID_FLAG) != null)
|
||||
properties.setProperty(SEED_ID_FLAG, argumentsNamespace.getString(SEED_ID_FLAG));
|
||||
if (argumentsNamespace.getString(BOOTSTRAP_NODE_ID_KEY) != null)
|
||||
properties.setProperty(BOOTSTRAP_NODE_ID_KEY, argumentsNamespace.getString(BOOTSTRAP_NODE_ID_KEY));
|
||||
|
||||
if (argumentsNamespace.getString(SEED_IP_FLAG) != null)
|
||||
properties.setProperty(SEED_IP_FLAG, argumentsNamespace.getString(SEED_IP_FLAG));
|
||||
if (argumentsNamespace.getString(BOOTSTRAP_NODE_IP_KEY) != null)
|
||||
properties.setProperty(BOOTSTRAP_NODE_IP_KEY, argumentsNamespace.getString(BOOTSTRAP_NODE_IP_KEY));
|
||||
|
||||
if (argumentsNamespace.getString(SEED_PORT_FLAG) != null)
|
||||
properties.setProperty(SEED_PORT_FLAG, argumentsNamespace.getString(SEED_PORT_FLAG));
|
||||
if (argumentsNamespace.getString(BOOTSTRAP_NODE_PORT_KEY) != null)
|
||||
properties.setProperty(BOOTSTRAP_NODE_PORT_KEY, argumentsNamespace.getString(BOOTSTRAP_NODE_PORT_KEY));
|
||||
|
||||
Application.launch(Main.class, args);
|
||||
}
|
||||
|
@ -91,7 +91,6 @@ import static org.bitcoinj.script.ScriptOpCodes.OP_RETURN;
|
||||
/**
|
||||
* TODO: use walletextension (with protobuffer) instead of saving addressEntryList via storage
|
||||
* TODO: break that class up. maybe a bitsquarewallet
|
||||
* Wait until steve's akka version to see how to continue here
|
||||
*/
|
||||
public class WalletFacade {
|
||||
private static final Logger log = LoggerFactory.getLogger(WalletFacade.class);
|
||||
|
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* This file is part of Bitsquare.
|
||||
*
|
||||
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.msg;
|
||||
|
||||
import io.bitsquare.util.MessageHandler;
|
||||
|
||||
import javafx.concurrent.Service;
|
||||
import javafx.concurrent.Task;
|
||||
|
||||
import akka.actor.ActorSelection;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.actor.Inbox;
|
||||
import akka.event.Logging;
|
||||
import akka.event.LoggingAdapter;
|
||||
import com.sun.glass.ui.Application;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
|
||||
public abstract class ActorService extends Service<String> {
|
||||
|
||||
private final LoggingAdapter log;
|
||||
|
||||
private final ActorSystem system;
|
||||
private final Inbox inbox;
|
||||
private final ActorSelection actor;
|
||||
|
||||
private MessageHandler handler;
|
||||
|
||||
protected ActorService(ActorSystem system, String actorPath) {
|
||||
this.log = Logging.getLogger(system, this);
|
||||
this.system = system;
|
||||
this.inbox = Inbox.create(system);
|
||||
this.actor = system.actorSelection(actorPath);
|
||||
log.debug(actor.pathString());
|
||||
this.start();
|
||||
}
|
||||
|
||||
public void setHandler(MessageHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void send(Object command) {
|
||||
if (actor != null) {
|
||||
actor.tell(command, inbox.getRef());
|
||||
}
|
||||
}
|
||||
|
||||
protected Task<String> createTask() {
|
||||
|
||||
return new Task<String>() {
|
||||
protected String call() throws Exception {
|
||||
|
||||
while (!isCancelled()) {
|
||||
if (inbox != null) {
|
||||
try {
|
||||
Object result = inbox.receive(FiniteDuration.create(1l, "minute"));
|
||||
if (result != null) {
|
||||
System.out.println(result.toString());
|
||||
if (handler != null) {
|
||||
Application.invokeLater(() -> handler.handle(result));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//System.out.println(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* This file is part of Bitsquare.
|
||||
*
|
||||
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.msg;
|
||||
|
||||
import io.bitsquare.msg.actor.DHTManager;
|
||||
import io.bitsquare.msg.actor.command.InitializePeer;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import net.tomp2p.peers.Number160;
|
||||
|
||||
import akka.actor.ActorSystem;
|
||||
|
||||
public class DHTSeedService extends ActorService {
|
||||
|
||||
@Inject
|
||||
public DHTSeedService(ActorSystem system) {
|
||||
super(system, "/user/" + DHTManager.SEED_NODE);
|
||||
}
|
||||
|
||||
public void initializePeer(String id, Integer port) {
|
||||
|
||||
// TODO hard coded seed peer config for now, should read from config properties file
|
||||
send(new InitializePeer(Number160.createHash(id), port, null, null));
|
||||
}
|
||||
}
|
@ -18,8 +18,6 @@
|
||||
package io.bitsquare.msg;
|
||||
|
||||
import io.bitsquare.BitsquareModule;
|
||||
import io.bitsquare.app.ArgumentParser;
|
||||
import io.bitsquare.network.BootstrapNodes;
|
||||
import io.bitsquare.network.Node;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
@ -27,11 +25,14 @@ import com.google.inject.name.Names;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static io.bitsquare.app.ArgumentParser.*;
|
||||
import static io.bitsquare.network.BootstrapNodes.DEFAULT_BOOTSTRAP_NODE;
|
||||
|
||||
public abstract class MessageModule extends BitsquareModule {
|
||||
|
||||
public static final String BOOTSTRAP_NODE_ID_KEY = "id";
|
||||
public static final String BOOTSTRAP_NODE_IP_KEY = "ip";
|
||||
public static final String BOOTSTRAP_NODE_PORT_KEY = "port";
|
||||
|
||||
protected MessageModule(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
@ -39,15 +40,14 @@ public abstract class MessageModule extends BitsquareModule {
|
||||
@Override
|
||||
protected final void configure() {
|
||||
bind(MessageFacade.class).to(messageFacade()).asEagerSingleton();
|
||||
bind(DHTSeedService.class);
|
||||
|
||||
// we will probably later use disk storage instead of memory storage for TomP2P
|
||||
bind(Boolean.class).annotatedWith(Names.named("useDiskStorage")).toInstance(false);
|
||||
|
||||
Node bootstrapNode = Node.at(
|
||||
properties.getProperty(SEED_ID_FLAG, DEFAULT_BOOTSTRAP_NODE.getId()),
|
||||
properties.getProperty(SEED_IP_FLAG, DEFAULT_BOOTSTRAP_NODE.getIp()),
|
||||
properties.getProperty(SEED_PORT_FLAG, DEFAULT_BOOTSTRAP_NODE.getPortAsString())
|
||||
properties.getProperty(BOOTSTRAP_NODE_ID_KEY, DEFAULT_BOOTSTRAP_NODE.getId()),
|
||||
properties.getProperty(BOOTSTRAP_NODE_IP_KEY, DEFAULT_BOOTSTRAP_NODE.getIp()),
|
||||
properties.getProperty(BOOTSTRAP_NODE_PORT_KEY, DEFAULT_BOOTSTRAP_NODE.getPortAsString())
|
||||
);
|
||||
|
||||
bind(Node.class)
|
||||
|
@ -1,135 +0,0 @@
|
||||
/*
|
||||
* This file is part of Bitsquare.
|
||||
*
|
||||
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.msg.actor;
|
||||
|
||||
import io.bitsquare.msg.actor.command.InitializePeer;
|
||||
import io.bitsquare.msg.actor.event.PeerInitialized;
|
||||
|
||||
import net.tomp2p.connection.Bindings;
|
||||
import net.tomp2p.connection.StandardProtocolFamily;
|
||||
import net.tomp2p.dht.PeerBuilderDHT;
|
||||
import net.tomp2p.dht.PeerDHT;
|
||||
import net.tomp2p.nat.PeerBuilderNAT;
|
||||
import net.tomp2p.nat.PeerNAT;
|
||||
import net.tomp2p.p2p.Peer;
|
||||
import net.tomp2p.p2p.PeerBuilder;
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
import net.tomp2p.peers.PeerMapChangeListener;
|
||||
import net.tomp2p.peers.PeerStatistic;
|
||||
|
||||
import akka.actor.AbstractActor;
|
||||
import akka.actor.Props;
|
||||
import akka.event.Logging;
|
||||
import akka.event.LoggingAdapter;
|
||||
import akka.japi.pf.ReceiveBuilder;
|
||||
|
||||
public class DHTManager extends AbstractActor {
|
||||
|
||||
public static final String MY_NODE = "myNodeDhtManager";
|
||||
public static final String SEED_NODE = "seedNodeDhtManager";
|
||||
|
||||
private final LoggingAdapter log = Logging.getLogger(context().system(), this);
|
||||
|
||||
// TODO move into app setup
|
||||
// timeout in ms
|
||||
private final Long bootstrapTimeout = 10000L;
|
||||
|
||||
public static Props getProps() {
|
||||
return Props.create(DHTManager.class);
|
||||
}
|
||||
|
||||
private PeerDHT peerDHT;
|
||||
private PeerNAT peerNAT;
|
||||
|
||||
public DHTManager() {
|
||||
receive(ReceiveBuilder
|
||||
.match(InitializePeer.class, this::doInitializePeer)
|
||||
.matchAny(o -> log.info("received unknown message")).build()
|
||||
);
|
||||
}
|
||||
|
||||
private void doInitializePeer(InitializePeer initializePeer) {
|
||||
log.debug("Received message: {}", initializePeer);
|
||||
|
||||
try {
|
||||
Bindings bindings = new Bindings();
|
||||
bindings.addProtocol(StandardProtocolFamily.INET);
|
||||
|
||||
if (initializePeer.getInterfaceHint() != null) {
|
||||
bindings.addInterface(initializePeer.getInterfaceHint());
|
||||
}
|
||||
|
||||
Peer peer = new PeerBuilder(initializePeer.getPeerId()).ports(initializePeer.getPort()).bindings(bindings)
|
||||
.start();
|
||||
peer.objectDataReply((sender, request) -> {
|
||||
log.debug("received request: ", request.toString());
|
||||
return "pong";
|
||||
});
|
||||
|
||||
// For the moment we want not to bootstrap to other seed nodes to keep test scenarios
|
||||
// simple
|
||||
/* if (ip.getBootstrapPeers() != null && ip.getBootstrapPeers().size() > 0) {
|
||||
peer.bootstrap().bootstrapTo(ip.getBootstrapPeers()).start();
|
||||
}*/
|
||||
|
||||
// Needed for DHT support
|
||||
peerDHT = new PeerBuilderDHT(peer).start();
|
||||
// Needed for NAT support
|
||||
peerNAT = new PeerBuilderNAT(peer).start();
|
||||
|
||||
new PeerBuilderNAT(peer).start();
|
||||
peer.peerBean().peerMap().addPeerMapChangeListener(new PeerMapChangeListener() {
|
||||
@Override
|
||||
public void peerInserted(PeerAddress peerAddress, boolean verified) {
|
||||
log.debug("Peer inserted: peerAddress=" + peerAddress + ", " +
|
||||
"verified=" + verified);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void peerRemoved(PeerAddress peerAddress, PeerStatistic peerStatistics) {
|
||||
log.debug("Peer removed: peerAddress=" + peerAddress + ", " +
|
||||
"peerStatistics=" + peerStatistics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void peerUpdated(PeerAddress peerAddress, PeerStatistic peerStatistics) {
|
||||
// log.debug("Peer updated: peerAddress=" + peerAddress + ",
|
||||
// peerStatistics=" + peerStatistics);
|
||||
}
|
||||
});
|
||||
|
||||
sender().tell(new PeerInitialized(peer.peerID(), initializePeer.getPort()), self());
|
||||
} catch (Throwable t) {
|
||||
log.error(t.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void postStop() throws Exception {
|
||||
log.debug("postStop");
|
||||
if (peerDHT != null)
|
||||
peerDHT.shutdown();
|
||||
|
||||
if (peerNAT != null)
|
||||
peerNAT.natUtils().shutdown();
|
||||
|
||||
super.postStop();
|
||||
}
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* This file is part of Bitsquare.
|
||||
*
|
||||
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.msg.actor.command;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.tomp2p.peers.Number160;
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
/**
|
||||
* <p>Command to initialize TomP2P Peer.</p>
|
||||
*/
|
||||
public class InitializePeer {
|
||||
|
||||
private final Number160 peerId;
|
||||
private final Integer port;
|
||||
private final String interfaceHint;
|
||||
|
||||
private final Collection<PeerAddress> bootstrapPeers;
|
||||
|
||||
public InitializePeer(Number160 peerId, Integer port, String interfaceHint,
|
||||
Collection<PeerAddress> bootstrapPeers) {
|
||||
this.peerId = peerId;
|
||||
this.port = port;
|
||||
this.interfaceHint = interfaceHint;
|
||||
this.bootstrapPeers = bootstrapPeers;
|
||||
}
|
||||
|
||||
public Number160 getPeerId() {
|
||||
return peerId;
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public String getInterfaceHint() {
|
||||
return interfaceHint;
|
||||
}
|
||||
|
||||
public Collection<PeerAddress> getBootstrapPeers() {
|
||||
return bootstrapPeers;
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* This file is part of Bitsquare.
|
||||
*
|
||||
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.msg.actor.event;
|
||||
|
||||
|
||||
import net.tomp2p.peers.Number160;
|
||||
|
||||
/**
|
||||
* <p>TomP2P Peer Initialized event.</p>
|
||||
*/
|
||||
public class PeerInitialized {
|
||||
|
||||
private final Number160 peerId;
|
||||
private final Integer port;
|
||||
|
||||
public PeerInitialized(Number160 peerId, Integer port) {
|
||||
this.peerId = peerId;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public Number160 getPeerId() {
|
||||
return peerId;
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
}
|
||||
}
|
@ -319,7 +319,7 @@ public class SellerTakesOfferProtocol {
|
||||
log.debug("state " + state);
|
||||
checkState(state.ordinal() >= State.SendSignedTakerDepositTxAsHex.ordinal());
|
||||
checkArgument(tradeId.equals(message.getTradeId()));
|
||||
//TODO takerCommitDepositTx should be in task as well, but will be probably changed anyway when akka is used...
|
||||
//TODO takerCommitDepositTx should be in task as well
|
||||
Transaction tx = walletFacade.takerCommitDepositTx(message.getDepositTxAsHex());
|
||||
listener.onDepositTxPublished(tx);
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
akka {
|
||||
|
||||
# Loggers to register at boot time (akka.event.Logging$DefaultLogger logs
|
||||
# to STDOUT)
|
||||
#loggers = ["akka.event.slf4j.Slf4jLogger"]
|
||||
|
||||
# Log level used by the configured loggers (see "loggers") as soon
|
||||
# as they have been started; before that, see "stdout-loglevel"
|
||||
# Options: OFF, ERROR, WARNING, INFO, DEBUG
|
||||
loglevel = "DEBUG"
|
||||
|
||||
# Log level for the very basic logger activated during ActorSystem startup.
|
||||
# This logger prints the log messages to stdout (System.out).
|
||||
# Options: OFF, ERROR, WARNING, INFO, DEBUG
|
||||
stdout-loglevel = "DEBUG"
|
||||
|
||||
}
|
@ -17,7 +17,6 @@
|
||||
|
||||
package io.bitsquare.app.gui;
|
||||
|
||||
import io.bitsquare.app.ArgumentParser;
|
||||
import io.bitsquare.gui.FatalException;
|
||||
import io.bitsquare.gui.Navigation;
|
||||
import io.bitsquare.gui.ViewLoader;
|
||||
@ -25,7 +24,6 @@ import io.bitsquare.gui.ViewLoader;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
|
||||
import javafx.application.Application;
|
||||
@ -36,7 +34,7 @@ import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import static io.bitsquare.app.AppModule.APP_NAME_KEY;
|
||||
|
||||
public class ViewLoaderTests {
|
||||
|
||||
@ -66,7 +64,7 @@ public class ViewLoaderTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(ArgumentParser.NAME_FLAG, "testApp");
|
||||
properties.setProperty(APP_NAME_KEY, "testApp");
|
||||
Injector injector = Guice.createInjector(new MainModule(properties, TestApp.primaryStage));
|
||||
ViewLoader.setInjector(injector);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user