Skip to content
Snippets Groups Projects
Unverified Commit 59720ad8 authored by David Bohn's avatar David Bohn
Browse files

Enabled network-wide access and enabled name entry for remote launch

parent 4313ee7c
No related branches found
No related tags found
1 merge request!3Preliminary result of the software
...@@ -11,6 +11,8 @@ import fucoin.supervisor.SuperVisorImpl; ...@@ -11,6 +11,8 @@ import fucoin.supervisor.SuperVisorImpl;
import fucoin.wallet.WalletImpl; import fucoin.wallet.WalletImpl;
import java.io.File; import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -26,6 +28,13 @@ public class Main { ...@@ -26,6 +28,13 @@ public class Main {
private static List<ActorRef> cActiveActors = new ArrayList<>(); private static List<ActorRef> cActiveActors = new ArrayList<>();
static { static {
String hostname = "127.0.0.1";
try {
// Fetch IP address to enable network connection
hostname = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
}
//Load configuration from current directory or from resources directory of jar //Load configuration from current directory or from resources directory of jar
File file = new File("application.conf"); File file = new File("application.conf");
Config config = ConfigFactory.parseFile(file); Config config = ConfigFactory.parseFile(file);
...@@ -37,7 +46,7 @@ public class Main { ...@@ -37,7 +46,7 @@ public class Main {
} }
//Init System Actor System //Init System Actor System
cSystem = ActorSystem.create("Core", config); cSystem = ActorSystem.create("Core", ConfigFactory.parseString("akka.remote.netty.tcp.hostname=" + hostname).withFallback(config));
cSuperVisorActor = cSystem.actorOf(SuperVisorImpl.props(), "SuperVisorImpl"); cSuperVisorActor = cSystem.actorOf(SuperVisorImpl.props(), "SuperVisorImpl");
System.out.print("Supervisor address: "); System.out.print("Supervisor address: ");
System.out.println(cSuperVisorActor.path().toStringWithAddress(cSystem.provider().getDefaultAddress())); System.out.println(cSuperVisorActor.path().toStringWithAddress(cSystem.provider().getDefaultAddress()));
......
...@@ -6,7 +6,6 @@ import java.util.concurrent.TimeUnit; ...@@ -6,7 +6,6 @@ import java.util.concurrent.TimeUnit;
import akka.actor.ActorRef; import akka.actor.ActorRef;
import akka.actor.ActorSelection; import akka.actor.ActorSelection;
import akka.actor.ActorSystem; import akka.actor.ActorSystem;
import akka.actor.Address;
import akka.util.Timeout; import akka.util.Timeout;
import com.typesafe.config.Config; import com.typesafe.config.Config;
...@@ -19,6 +18,9 @@ import javax.swing.*; ...@@ -19,6 +18,9 @@ import javax.swing.*;
public class MainRemote { public class MainRemote {
public static ActorRef remoteSuperVisorActor; public static ActorRef remoteSuperVisorActor;
private static JTextField walletNameField = new JTextField(5);
private static JTextField pathField = new JTextField(5);
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
//Load configuration from current directory or from resources directory of jar //Load configuration from current directory or from resources directory of jar
...@@ -34,14 +36,22 @@ public class MainRemote { ...@@ -34,14 +36,22 @@ public class MainRemote {
//Init System Actor System //Init System Actor System
ActorSystem system = ActorSystem.create("Remote", config); ActorSystem system = ActorSystem.create("Remote", config);
JPanel dialogPanel = createDialogPanel();
Timeout timeout = new Timeout(5, TimeUnit.SECONDS); Timeout timeout = new Timeout(5, TimeUnit.SECONDS);
ActorRef preknownNeighbour = null; ActorRef preknownNeighbour = null;
String walletName = null;
String path = null;
while (preknownNeighbour == null) { while (preknownNeighbour == null) {
// get an address from a node which should be our preknown neighbour int result = JOptionPane.showConfirmDialog(null, dialogPanel, "Connect to wallet network", JOptionPane.OK_CANCEL_OPTION);
String path = JOptionPane.showInputDialog(null, "Enter a neighbour node address: ");
if (result == JOptionPane.OK_OPTION) {
walletName = walletNameField.getText();
path = pathField.getText();
}
// terminate if user clicked abort // terminate if user clicked abort
if (path == null) { if (path == null) {
...@@ -59,7 +69,17 @@ public class MainRemote { ...@@ -59,7 +69,17 @@ public class MainRemote {
} }
// spawn wallet // spawn wallet
system.actorOf(WalletImpl.props(preknownNeighbour, "Remote1"), "Remote1"); system.actorOf(WalletImpl.props(preknownNeighbour, walletName), walletName);
}
private static JPanel createDialogPanel() {
JPanel dialogPanel = new JPanel();
dialogPanel.setLayout(new BoxLayout(dialogPanel, BoxLayout.PAGE_AXIS));
dialogPanel.add(new JLabel("Pick your wallet name: "));
dialogPanel.add(walletNameField);
dialogPanel.add(new JLabel("Enter a neighbour node address: "));
dialogPanel.add(pathField);
return dialogPanel;
} }
} }
...@@ -17,7 +17,7 @@ public class WalletGuiControlImpl implements WalletGuiControl { ...@@ -17,7 +17,7 @@ public class WalletGuiControlImpl implements WalletGuiControl {
private JLabel lblMyAddress = new JLabel("My Address:"); private JLabel lblMyAddress = new JLabel("My Address:");
private JTextField txtMyAddress = new JTextField("<MyAddress>"); private JTextField txtMyAddress = new JTextField("<MyAddress>");
private JLabel lblEmpty = new JLabel(""); private JLabel lblEmpty = new JLabel("");
private JLabel lblMyAmount = new JLabel("My FUCs"); private JLabel lblMyAmount = new JLabel("My FUCs:");
private JTextField txtMyAmount = new JTextField("<MyFUCs>"); private JTextField txtMyAmount = new JTextField("<MyFUCs>");
private JPanel centerPanel = new JPanel(); private JPanel centerPanel = new JPanel();
private JLabel lblSendTo = new JLabel("Send to:"); private JLabel lblSendTo = new JLabel("Send to:");
...@@ -37,14 +37,20 @@ public class WalletGuiControlImpl implements WalletGuiControl { ...@@ -37,14 +37,20 @@ public class WalletGuiControlImpl implements WalletGuiControl {
window.setSize(400, 600); window.setSize(400, 600);
window.setLayout(new GridLayout(3, 1)); window.setLayout(new GridLayout(3, 1));
topPanel.setLayout(new GridLayout(2, 3)); topPanel.setLayout(new GridLayout(2, 1));
// Row 1 // Row 1
topPanel.add(lblMyAddress); JPanel row1 = new JPanel();
topPanel.add(txtMyAddress); row1.setLayout(new BoxLayout(row1, BoxLayout.PAGE_AXIS));
topPanel.add(lblEmpty); row1.add(lblMyAddress);
row1.add(txtMyAddress);
topPanel.add(row1);
// Row 2 // Row 2
topPanel.add(lblMyAmount); JPanel row2 = new JPanel();
topPanel.add(txtMyAmount); row2.setLayout(new GridLayout(1, 3));
row2.add(lblMyAmount);
row2.add(txtMyAmount);
row2.add(lblEmpty);
topPanel.add(row2);
window.add(topPanel); window.add(topPanel);
//<hr> //<hr>
centerPanel.setLayout(new GridLayout(4, 1)); centerPanel.setLayout(new GridLayout(4, 1));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment