From c9ca1bb878adee4ea118e53de92a4208dabdfc62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20K=C3=B6nnecke?= <simonkoennecke@gmail.com> Date: Thu, 7 Jul 2016 20:20:18 +0200 Subject: [PATCH] By spawning new Wallets send them only two neighbours, random transaction is based on the overlay network. Add Graph --- pom.xml | 7 ++ .../control/ActionWalletGetNeighbours.java | 17 +++++ .../ActionWalletGetNeighboursAnswer.java | 38 ++++++++++ .../java/fucoin/actions/join/ActionJoin.java | 26 ++++--- .../fucoin/actions/join/ActionJoinAnswer.java | 18 ++--- .../fucoin/actions/join/ServerActionJoin.java | 7 +- .../actions/persist/ActionInvokeRevive.java | 2 +- .../search/ActionSearchWalletReference.java | 3 + ...ionCommitDistributedCommittedTransfer.java | 11 ++- .../transaction/ActionInvokeSentMoney.java | 5 +- .../configurations/AbstractConfiguration.java | 33 +++++++-- .../MassWalletConfiguration.java | 4 +- .../java/fucoin/gui/SuperVisorGraphGUI.java | 71 +++++++++++++++++++ .../fucoin/gui/SuperVisorGuiControlImpl.java | 42 +++++++++-- .../java/fucoin/gui/SuperVisorThreadGUI.java | 15 +++- src/main/java/fucoin/wallet/WalletImpl.java | 4 +- 16 files changed, 259 insertions(+), 44 deletions(-) create mode 100644 src/main/java/fucoin/actions/control/ActionWalletGetNeighbours.java create mode 100644 src/main/java/fucoin/actions/control/ActionWalletGetNeighboursAnswer.java create mode 100644 src/main/java/fucoin/gui/SuperVisorGraphGUI.java diff --git a/pom.xml b/pom.xml index 1a37142..a9f4391 100644 --- a/pom.xml +++ b/pom.xml @@ -56,5 +56,12 @@ <artifactId>reflections</artifactId> <version>0.9.10</version> </dependency> + <!-- https://mvnrepository.com/artifact/org.tinyjee.jgraphx/jgraphx --> + <dependency> + <groupId>org.tinyjee.jgraphx</groupId> + <artifactId>jgraphx</artifactId> + <version>1.10.1.3</version> + </dependency> + </dependencies> </project> \ No newline at end of file diff --git a/src/main/java/fucoin/actions/control/ActionWalletGetNeighbours.java b/src/main/java/fucoin/actions/control/ActionWalletGetNeighbours.java new file mode 100644 index 0000000..9b70205 --- /dev/null +++ b/src/main/java/fucoin/actions/control/ActionWalletGetNeighbours.java @@ -0,0 +1,17 @@ +package fucoin.actions.control; + +import akka.actor.ActorRef; +import akka.actor.UntypedActorContext; +import fucoin.actions.ClientAction; +import fucoin.wallet.AbstractWallet; + +/** + * Ask Wallet x for his known neighbours. + */ +public class ActionWalletGetNeighbours extends ClientAction { + + @Override + protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context, AbstractWallet abstractNode) { + sender.tell(new ActionWalletGetNeighboursAnswer(abstractNode), self); + } +} diff --git a/src/main/java/fucoin/actions/control/ActionWalletGetNeighboursAnswer.java b/src/main/java/fucoin/actions/control/ActionWalletGetNeighboursAnswer.java new file mode 100644 index 0000000..7de65b6 --- /dev/null +++ b/src/main/java/fucoin/actions/control/ActionWalletGetNeighboursAnswer.java @@ -0,0 +1,38 @@ +package fucoin.actions.control; + +import akka.actor.ActorRef; +import akka.actor.UntypedActorContext; +import fucoin.actions.ClientAction; +import fucoin.wallet.AbstractWallet; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * Tell + */ +public class ActionWalletGetNeighboursAnswer extends ClientAction { + + private final HashMap<String, ActorRef> neighbour; + private final String name; + + + public ActionWalletGetNeighboursAnswer(AbstractWallet wallet) { + this.neighbour = wallet.getKnownNeighbors(); + this.name = wallet.getName(); + } + + @Override + protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context, AbstractWallet abstractNode) { + + } + + public String getName() { + return name; + } + + public HashMap<String, ActorRef> getNeighbour() { + return neighbour; + } +} diff --git a/src/main/java/fucoin/actions/join/ActionJoin.java b/src/main/java/fucoin/actions/join/ActionJoin.java index 4c3e083..0e42281 100644 --- a/src/main/java/fucoin/actions/join/ActionJoin.java +++ b/src/main/java/fucoin/actions/join/ActionJoin.java @@ -6,6 +6,7 @@ import fucoin.actions.ClientAction; import fucoin.wallet.AbstractWallet; import java.util.HashMap; +import java.util.Set; import java.util.concurrent.ThreadLocalRandom; /** @@ -14,20 +15,34 @@ import java.util.concurrent.ThreadLocalRandom; public class ActionJoin extends ClientAction { private static final Integer sShareNNeighbour = 2; + private final String walletName; + + public ActionJoin(String walletName) { + this.walletName = walletName; + } + @Override protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context, AbstractWallet node) { + node.addKnownNeighbor(walletName, sender); + + if (node.getRemoteSuperVisorActor() == null) { + node.deferSendOfSuperVisorActor(sender); + } else { + sender.tell(new ActionTellSupervisor(node.getRemoteSuperVisorActor()), self); + } //Choose sShareNNeighbour to send the new wallet. HashMap<String, ActorRef> sendNeighbours = new HashMap<>(); if (node.getKnownNeighbors().size() > 0) { - String[] rndNeighbours = (String[]) node.getKnownNeighbors().keySet().toArray(); + String[] rndNeighbours = new String[node.getKnownNeighbors().size()]; + node.getKnownNeighbors().keySet().toArray(rndNeighbours); int sizeKnownNeighbours = rndNeighbours.length; for (int i = 0; i < sShareNNeighbour; i++) { String walletName = rndNeighbours[ThreadLocalRandom.current().nextInt(sizeKnownNeighbours)]; if (sendNeighbours.containsKey(walletName)) { continue; - } else if (i < sizeKnownNeighbours) { + } else if (i > sizeKnownNeighbours) { break; } else { sendNeighbours.put(walletName, node.getKnownNeighbors().get(walletName)); @@ -36,13 +51,8 @@ public class ActionJoin extends ClientAction { } //Tell the wallet the chosen wallets - ActionJoinAnswer aja = new ActionJoinAnswer(sendNeighbours); + ActionJoinAnswer aja = new ActionJoinAnswer(sendNeighbours, node.getRemoteSuperVisorActor()); sender.tell(aja, self); - if (node.getRemoteSuperVisorActor() == null) { - node.deferSendOfSuperVisorActor(sender); - } else { - sender.tell(new ActionTellSupervisor(node.getRemoteSuperVisorActor()), self); - } } } diff --git a/src/main/java/fucoin/actions/join/ActionJoinAnswer.java b/src/main/java/fucoin/actions/join/ActionJoinAnswer.java index 4a6dc15..e3418d6 100644 --- a/src/main/java/fucoin/actions/join/ActionJoinAnswer.java +++ b/src/main/java/fucoin/actions/join/ActionJoinAnswer.java @@ -2,13 +2,10 @@ package fucoin.actions.join; import akka.actor.ActorRef; import akka.actor.UntypedActorContext; -import akka.dispatch.OnSuccess; import fucoin.actions.ClientAction; import fucoin.actions.persist.ActionSearchMyWallet; +import fucoin.supervisor.SuperVisorImpl; import fucoin.wallet.AbstractWallet; -import scala.Function1; -import scala.concurrent.Future; -import scala.runtime.BoxedUnit; import java.util.HashMap; import java.util.Map.Entry; @@ -16,7 +13,7 @@ import java.util.Map.Entry; /** * This action is the response from a wallet which is already in the network * to a wallet which wants to join the network. - * <p> + * <p/> * The node in the network sends all its known neighbours which then become * neighbours of the new node. This action also contains a reference to the * supervisor. If this is the first time the new node learned about the systems @@ -24,9 +21,11 @@ import java.util.Map.Entry; */ public class ActionJoinAnswer extends ClientAction { private final HashMap<String, ActorRef> someNeighbors; + private final ActorRef superVisor; - public ActionJoinAnswer(HashMap<String, ActorRef> someNeighbors) { + public ActionJoinAnswer(HashMap<String, ActorRef> someNeighbors, ActorRef superVisor) { this.someNeighbors = someNeighbors; + this.superVisor = superVisor; } protected void onAction(ActorRef sender, ActorRef self, @@ -34,14 +33,17 @@ public class ActionJoinAnswer extends ClientAction { wallet.addLogMsg("Addressed to " + self.path().name() + " from " + sender.path().name() + ": someNeighbors:" + someNeighbors); + //Set SuperVisor + wallet.setRemoteSuperVisorActor(superVisor); + // your neighbours? my neighbours! for (Entry<String, ActorRef> neighbor : someNeighbors.entrySet()) { wallet.addKnownNeighbor(neighbor.getKey(), neighbor.getValue()); } - /* + for (Entry<String, ActorRef> neighbor : someNeighbors.entrySet()) { neighbor.getValue().tell(new ActionSearchMyWallet(wallet.getName()), self); - }*/ + } } } diff --git a/src/main/java/fucoin/actions/join/ServerActionJoin.java b/src/main/java/fucoin/actions/join/ServerActionJoin.java index e385619..8c491e5 100644 --- a/src/main/java/fucoin/actions/join/ServerActionJoin.java +++ b/src/main/java/fucoin/actions/join/ServerActionJoin.java @@ -21,11 +21,12 @@ public class ServerActionJoin extends SuperVisorAction { @Override protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context, SuperVisorImpl node) { - ActionJoinAnswer aja = new ActionJoinAnswer(node.getKnownNeighbors()); // TODO: Might need added TellSupervisor - sender.tell(aja, self); + //ActionJoinAnswer aja = new ActionJoinAnswer(node.getKnownNeighbors()); // TODO: Might need added TellSupervisor + //sender.tell(aja, self); node.addKnownNeighbor(name, sender); + self.tell( - new ActionInvokeDistributedCommittedTransfer(self, sender, 100, self), + new ActionInvokeDistributedCommittedTransfer(self, sender, 100, node.getBankCommitObserver()), sender); } } diff --git a/src/main/java/fucoin/actions/persist/ActionInvokeRevive.java b/src/main/java/fucoin/actions/persist/ActionInvokeRevive.java index 6bfdb84..4345876 100644 --- a/src/main/java/fucoin/actions/persist/ActionInvokeRevive.java +++ b/src/main/java/fucoin/actions/persist/ActionInvokeRevive.java @@ -11,7 +11,7 @@ public class ActionInvokeRevive extends Persist { protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context, AbstractWallet wallet) { wallet.setActive(true); - wallet.getPreKnownNeighbour().tell(new ActionJoin(), self); + wallet.getPreKnownNeighbour().tell(new ActionJoin(wallet.getName()), self); } } diff --git a/src/main/java/fucoin/actions/search/ActionSearchWalletReference.java b/src/main/java/fucoin/actions/search/ActionSearchWalletReference.java index 9d0727a..900d4fb 100644 --- a/src/main/java/fucoin/actions/search/ActionSearchWalletReference.java +++ b/src/main/java/fucoin/actions/search/ActionSearchWalletReference.java @@ -23,6 +23,9 @@ public class ActionSearchWalletReference extends Search { @Override protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context, AbstractWallet wallet) { + if (sender.equals(self)) { + return; + } wallet.addLogMsg(wallet.getKnownNeighbors() + "contains " + name + "?"); ttl.add(self); ActionSearchWalletReferenceAnswer answer = null; diff --git a/src/main/java/fucoin/actions/transaction/ActionCommitDistributedCommittedTransfer.java b/src/main/java/fucoin/actions/transaction/ActionCommitDistributedCommittedTransfer.java index 641fc12..f44d084 100644 --- a/src/main/java/fucoin/actions/transaction/ActionCommitDistributedCommittedTransfer.java +++ b/src/main/java/fucoin/actions/transaction/ActionCommitDistributedCommittedTransfer.java @@ -52,10 +52,6 @@ public class ActionCommitDistributedCommittedTransfer extends ClientAction { } else if (target.compareTo(self) == 0) { wallet.setAmount(wallet.getAmount() + amount); wallet.addTransactionLogMessageSuccess("Received " + amount + " FUC from " + source.path().name()); - // recipient should notify a possible observer - if (observer != null) { - observer.tell(new ActionNotifyObserver(source, target, amount, granted, timestamp, id), self); - } } } else { @@ -69,12 +65,13 @@ public class ActionCommitDistributedCommittedTransfer extends ClientAction { if (source.compareTo(self) == 0) { wallet.addTransactionLogMessageFail("Failed to send " + amount + " FUC to " + target.path().name() + " (Commit has not been granted)"); - if (observer != null) { - observer.tell(new ActionNotifyObserver(source, target, amount, granted, timestamp, id), self); - } } } + // recipient should notify a possible observer + if (observer != null) { + observer.tell(new ActionNotifyObserver(source, target, amount, granted, timestamp, id), self); + } //wallet.addLogMsg("wallet.amounts:" + wallet.amounts); } diff --git a/src/main/java/fucoin/actions/transaction/ActionInvokeSentMoney.java b/src/main/java/fucoin/actions/transaction/ActionInvokeSentMoney.java index 9f7c2f2..81fa556 100644 --- a/src/main/java/fucoin/actions/transaction/ActionInvokeSentMoney.java +++ b/src/main/java/fucoin/actions/transaction/ActionInvokeSentMoney.java @@ -23,9 +23,12 @@ public class ActionInvokeSentMoney extends Transaction { wallet.addLogMsg(wallet.getKnownNeighbors() + ""); if (wallet.getKnownNeighbors().containsKey(name)) { wallet.getRemoteSuperVisorActor().tell( - new ActionInvokeDistributedCommittedTransfer(self, wallet.getKnownNeighbors().get(name), amount, observer), sender); + new ActionInvokeDistributedCommittedTransfer(self, wallet.getKnownNeighbors().get(name), + amount, observer), sender); } else { + //Search the wallet ActionSearchWalletReference aswr = new ActionSearchWalletReference(name); + //Ask all neighbors for (ActorRef neighbor : wallet.getKnownNeighbors().values()) { neighbor.tell(aswr, self); } diff --git a/src/main/java/fucoin/configurations/AbstractConfiguration.java b/src/main/java/fucoin/configurations/AbstractConfiguration.java index 8493704..5be8b9a 100644 --- a/src/main/java/fucoin/configurations/AbstractConfiguration.java +++ b/src/main/java/fucoin/configurations/AbstractConfiguration.java @@ -6,10 +6,13 @@ import akka.pattern.Patterns; import akka.util.Timeout; import fucoin.AbstractNode; import fucoin.actions.control.ActionAnnounceWalletCreation; +import fucoin.actions.control.ActionWalletGetNeighbours; +import fucoin.actions.control.ActionWalletGetNeighboursAnswer; import fucoin.actions.control.ActionWalletSendMoney; import fucoin.actions.join.ActionTellSupervisor; import fucoin.actions.transaction.ActionGetAmount; import fucoin.actions.transaction.ActionGetAmountAnswer; +import fucoin.actions.transaction.ActionInvokeDistributedCommittedTransfer; import fucoin.actions.transaction.ActionNotifyObserver; import fucoin.configurations.internal.ConfigurationCreator; import fucoin.supervisor.SuperVisorImpl; @@ -69,9 +72,13 @@ public abstract class AbstractConfiguration extends AbstractNode { activeActors.add(actorRef); - if (numOfWallets == 0) { - actorRef.tell(new ActionTellSupervisor(superVisor), superVisor); - } + //if (numOfWallets == 0) { + actorRef.tell(new ActionTellSupervisor(superVisor), superVisor); + /* + superVisor.tell( new ActionInvokeDistributedCommittedTransfer(superVisor, + actorRef, 100, superVisor), actorRef); + */ + //} return actorRef; } @@ -126,13 +133,27 @@ public abstract class AbstractConfiguration extends AbstractNode { Collections.shuffle(wallets); ActorRef sender = wallets.get(0); - ActorRef recipient = wallets.get(1); + //Choose a random neighbour from sender + ActorRef recipient = null; + Future<Object> futureNeighbour = Patterns.ask(sender, new ActionWalletGetNeighbours(), timeout); + ActionWalletGetNeighboursAnswer neighboursAnswer = (ActionWalletGetNeighboursAnswer) Await.result(futureNeighbour, + timeout.duration()); + for (int i=1; i < wallets.size(); i++) { + if (neighboursAnswer.getNeighbour().containsValue(wallets.get(i))) { + recipient = wallets.get(i); + } + } + + //cancel here when no neighbour was found. + if (recipient == null) { + return; + } Future<Object> future = Patterns.ask(sender, new ActionGetAmount(), timeout); ActionGetAmountAnswer answer = (ActionGetAmountAnswer) Await.result(future, timeout.duration()); - int transferAmount = 1 + ThreadLocalRandom.current().nextInt(answer.amount); + int transferAmount = 1 + ThreadLocalRandom.current().nextInt(answer.amount - 1); sender.tell(new ActionWalletSendMoney(recipient.path().name(), transferAmount, self()), self()); } @@ -143,7 +164,7 @@ public abstract class AbstractConfiguration extends AbstractNode { */ ActorRef initSupervisor() { superVisor = context().actorOf(SuperVisorImpl.props(), "SuperVisorImpl"); - + superVisor.tell(new ActionAnnounceWalletCreation(1, self()), self()); // Don't ask. try { Thread.sleep(200); diff --git a/src/main/java/fucoin/configurations/MassWalletConfiguration.java b/src/main/java/fucoin/configurations/MassWalletConfiguration.java index fcaaadf..bbcd338 100644 --- a/src/main/java/fucoin/configurations/MassWalletConfiguration.java +++ b/src/main/java/fucoin/configurations/MassWalletConfiguration.java @@ -1,5 +1,6 @@ package fucoin.configurations; +import fucoin.actions.transaction.ActionNotifyObserver; import fucoin.configurations.internal.ConfigurationName; /** @@ -11,8 +12,9 @@ public class MassWalletConfiguration extends AbstractConfiguration { public void run() { initSupervisor(); try { - spawnWallets(200, false); + spawnWallets(20, false); System.out.println("Wallet spawning done!"); + Thread.sleep(4000); } catch (Exception e) { System.out.println("Wallet spawning timed out!"); } diff --git a/src/main/java/fucoin/gui/SuperVisorGraphGUI.java b/src/main/java/fucoin/gui/SuperVisorGraphGUI.java new file mode 100644 index 0000000..4ef3e87 --- /dev/null +++ b/src/main/java/fucoin/gui/SuperVisorGraphGUI.java @@ -0,0 +1,71 @@ +package fucoin.gui; + +import akka.actor.ActorRef; +import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.view.mxGraph; + +import javax.swing.*; +import java.util.*; + +/** + * + */ +public class SuperVisorGraphGUI extends JFrame { + + private SuperVisorGuiControlImpl superVisorGuiControl; + + private static final int width = 1200; + private static final int height = 800; + private static final int margin = 100; + private static final int radius = (width - margin * 2) / 3; + private static final int centerX = ((width - margin * 2) / 2) + (margin / 2); + private static final int centerY = ((height - margin * 2) / 2) + (margin / 2); + + private HashMap<String, Object> vertex = new HashMap<>(); + + public SuperVisorGraphGUI(SuperVisorGuiControlImpl superVisorGuiControl) { + super("Distributed Network Graph"); + this.superVisorGuiControl = superVisorGuiControl; + setVisible(true); + setSize(width, height); + } + + public void init() { + mxGraph graph = new mxGraph(); + Object parent = graph.getDefaultParent(); + + graph.getModel().beginUpdate(); + try { + Vector rows = superVisorGuiControl.getAmountTableModel().getDataVector(); + int numberOfWallets = rows.size(); + double rad = Math.PI * 2 / numberOfWallets; + for (int i = 0; i < numberOfWallets; i++) { + if (rows.get(i) instanceof Vector) { + Vector<Object> row = (Vector<Object>) rows.get(i); + long[] p = getPointOnCircle(rad * i); + vertex.put((String) row.get(1), graph.insertVertex(parent, + (String) row.get(1), (String) row.get(1) + "\n" + String.valueOf(row.get(2)), + p[0], p[1], //x, y, + 80, 30) //width, height + ); + } + } + + for (Map.Entry<String, HashMap<String, ActorRef>> item1 : + superVisorGuiControl.getNodeNeighbourList().entrySet()) { + for (Map.Entry<String, ActorRef> item2: item1.getValue().entrySet()) { + graph.insertEdge(parent, null, "", vertex.get(item1.getKey()), vertex.get(item2.getKey())); + } + } + } finally { + graph.getModel().endUpdate(); + } + + mxGraphComponent graphComponent = new mxGraphComponent(graph); + getContentPane().add(graphComponent); + } + + private static long[] getPointOnCircle(double t) { + return new long[]{Math.round(radius * Math.cos(t) + centerX), Math.round(radius * Math.sin(t) + centerY)}; + } +} diff --git a/src/main/java/fucoin/gui/SuperVisorGuiControlImpl.java b/src/main/java/fucoin/gui/SuperVisorGuiControlImpl.java index b0c9a12..333ba6c 100644 --- a/src/main/java/fucoin/gui/SuperVisorGuiControlImpl.java +++ b/src/main/java/fucoin/gui/SuperVisorGuiControlImpl.java @@ -1,21 +1,27 @@ package fucoin.gui; +import akka.actor.ActorRef; +import akka.pattern.Patterns; +import akka.util.Timeout; +import fucoin.actions.control.ActionWalletGetNeighbours; +import fucoin.actions.control.ActionWalletGetNeighboursAnswer; import fucoin.supervisor.AmountTableModel; import fucoin.supervisor.SuperVisorImpl; +import scala.concurrent.Await; +import scala.concurrent.Future; +import scala.concurrent.duration.Duration; -import javax.swing.*; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import java.awt.*; -import java.awt.event.ItemEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; public class SuperVisorGuiControlImpl implements SuperVisorGuiControl { private SuperVisorImpl superVisor; private AmountTableModel amountTableModel; + private HashMap<String, HashMap<String, ActorRef>> nodeNeighbours = new HashMap<>(); + private SuperVisorThreadGUI threadGUI; private boolean logActive = false; @@ -34,6 +40,28 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl { } + public void updateNodeNeighbourList() { + try { + Timeout timeout = new Timeout(Duration.create(10, "seconds")); + + for (Map.Entry<String, ActorRef> item : superVisor.getKnownNeighbors().entrySet()) { + Future<Object> futureNeighbour = Patterns.ask(item.getValue(), new ActionWalletGetNeighbours(), timeout); + ActionWalletGetNeighboursAnswer neighboursAnswer = (ActionWalletGetNeighboursAnswer) + Await.result(futureNeighbour, timeout.duration()); + addNodeNeighbourList(item.getKey(), neighboursAnswer.getNeighbour()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void addNodeNeighbourList(String name, HashMap<String, ActorRef> list) { + nodeNeighbours.put(name, list); + } + + public HashMap<String, HashMap<String, ActorRef>> getNodeNeighbourList() { + return nodeNeighbours; + } public void guiTerminated() { superVisor.exit(); } diff --git a/src/main/java/fucoin/gui/SuperVisorThreadGUI.java b/src/main/java/fucoin/gui/SuperVisorThreadGUI.java index d5d7a1b..6f6b4b0 100644 --- a/src/main/java/fucoin/gui/SuperVisorThreadGUI.java +++ b/src/main/java/fucoin/gui/SuperVisorThreadGUI.java @@ -72,19 +72,32 @@ public class SuperVisorThreadGUI { frame.add(contentPanel, BorderLayout.CENTER); + JPanel btnPanel = new JPanel(); + + JButton showGraphBtn = new JButton("Show Graph"); + showGraphBtn.addActionListener(e -> { + superVisorGuiControl.updateNodeNeighbourList(); + new SuperVisorGraphGUI(superVisorGuiControl).init(); + }); + btnPanel.add(showGraphBtn); + + //Exit Button and shutdown supervisor JButton exitBtn = new JButton("Stop Supervisor"); exitBtn.addActionListener(e -> { superVisorGuiControl.guiTerminated(); frame.setVisible(false); frame.dispose(); + System.exit(0); }); if (!superVisorGuiControl.isLogActive()) { this.log(new LogMessage("Logging is currently disabled.")); } - frame.add(exitBtn, BorderLayout.PAGE_END); + btnPanel.add(exitBtn); + frame.add(btnPanel, BorderLayout.PAGE_END); + frame.setSize(800, 600); frame.setVisible(true); diff --git a/src/main/java/fucoin/wallet/WalletImpl.java b/src/main/java/fucoin/wallet/WalletImpl.java index 8b7c59d..6f668e5 100644 --- a/src/main/java/fucoin/wallet/WalletImpl.java +++ b/src/main/java/fucoin/wallet/WalletImpl.java @@ -89,13 +89,15 @@ public class WalletImpl extends AbstractWallet { if (preKnownNeighbour != null) { addKnownNeighbor(preKnownNeighbourName, preKnownNeighbour); - preKnownNeighbour.tell(new ActionJoin(), getSelf()); + preKnownNeighbour.tell(new ActionJoin(getName()), getSelf()); + /* HashMap neighborsList = new HashMap(); neighborsList.putAll(getKnownNeighbors()); neighborsList.put(name, getSelf()); ActionJoinAnswer aja = new ActionJoinAnswer(neighborsList); preKnownNeighbour.tell(aja, getSelf()); + */ if (this.getRemoteSuperVisorActor() != null) { -- GitLab