From 53aaaa5b13bca60e89835118aa1a1934af753bc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20R=C4=99bacz?= Date: Tue, 15 Jan 2019 15:28:51 +0100 Subject: [PATCH 1/2] Added resource queue --- .../matoosh/undernet/p2p/router/Router.java | 26 +++++++++++++---- .../router/data/resource/ResourceManager.java | 28 +++++++++++++------ .../transfer/FileTransferHandler.java | 6 ++-- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/shared/src/main/java/me/matoosh/undernet/p2p/router/Router.java b/shared/src/main/java/me/matoosh/undernet/p2p/router/Router.java index a1136d94..95074495 100755 --- a/shared/src/main/java/me/matoosh/undernet/p2p/router/Router.java +++ b/shared/src/main/java/me/matoosh/undernet/p2p/router/Router.java @@ -25,8 +25,8 @@ import me.matoosh.undernet.p2p.router.data.message.NodeNeighborsRequest; import me.matoosh.undernet.p2p.router.data.message.tunnel.MessageTunnel; import me.matoosh.undernet.p2p.router.data.message.tunnel.MessageTunnelManager; -import me.matoosh.undernet.p2p.router.data.message.tunnel.MessageTunnelSide; import me.matoosh.undernet.p2p.router.data.message.tunnel.TunnelControlMessage; +import me.matoosh.undernet.p2p.router.data.resource.Resource; import me.matoosh.undernet.p2p.router.data.resource.ResourceManager; import me.matoosh.undernet.p2p.router.data.resource.transfer.ResourceTransferHandler; import me.matoosh.undernet.p2p.router.server.Server; @@ -47,7 +47,7 @@ public class Router extends EventHandler { /** * The interval of the control loop. */ - public static final int controlLoopInterval = 30; + public static final int controlLoopInterval = 15; /** * The logger. */ @@ -199,7 +199,7 @@ public void start(NetworkIdentity networkIdentity) { } /** - * Control loop running every 30 seconds. + * Control loop running every 15 seconds. */ private void controlLoop() { logger.info("Checking if everything is running smoothly..."); @@ -216,12 +216,12 @@ private void controlLoop() { //Checking resource transfer activity. for (int i = 0; i < resourceManager.inboundHandlers.size(); i++) { ResourceTransferHandler transferHandler = resourceManager.inboundHandlers.get(i); - if (System.currentTimeMillis() > transferHandler.getLastMessageTime() + controlLoopInterval * 1000) + if (System.currentTimeMillis() > transferHandler.getLastMessageTime() + 2 * controlLoopInterval * 1000) transferHandler.callError(new TimeoutException()); } for (int i = 0; i < resourceManager.outboundHandlers.size(); i++) { ResourceTransferHandler transferHandler = resourceManager.outboundHandlers.get(i); - if (System.currentTimeMillis() > transferHandler.getLastMessageTime() + controlLoopInterval * 1000) + if (System.currentTimeMillis() > transferHandler.getLastMessageTime() + 2 * controlLoopInterval * 1000) transferHandler.callError(new TimeoutException()); } @@ -229,11 +229,25 @@ private void controlLoop() { for (int i = 0; i < messageTunnelManager.messageTunnels.size(); i++) { MessageTunnel tunnel = messageTunnelManager.messageTunnels.get(i); - if (System.currentTimeMillis() > tunnel.getLastMessageTime() + 2 * controlLoopInterval * 1000) + if (System.currentTimeMillis() > tunnel.getLastMessageTime() + 4 * controlLoopInterval * 1000) messageTunnelManager.closeTunnel(tunnel); else if (tunnel.isKeepAlive()) tunnel.sendMessage(new TunnelControlMessage()); } + //Sending pending transfers. + if(resourceManager.outboundHandlers.size() == 0) { + for (int i = 0; i < resourceManager.queuedResources.size(); i++) { + Resource r = resourceManager.queuedResources.get(i); + if (neighborNodesManager.getClosestTo(r.getNetworkID()) != Node.self) { + resourceManager.queuedResources.remove(i); + resourceManager.startPush(r); + break; + } else { + resourceManager.queuedResources.remove(i); + } + } + } + EventManager.callEvent(new RouterControlLoopEvent(this)); } diff --git a/shared/src/main/java/me/matoosh/undernet/p2p/router/data/resource/ResourceManager.java b/shared/src/main/java/me/matoosh/undernet/p2p/router/data/resource/ResourceManager.java index 1f6dfdb3..3e48bcf2 100644 --- a/shared/src/main/java/me/matoosh/undernet/p2p/router/data/resource/ResourceManager.java +++ b/shared/src/main/java/me/matoosh/undernet/p2p/router/data/resource/ResourceManager.java @@ -45,9 +45,9 @@ public class ResourceManager extends Manager { public ArrayList inboundHandlers = new ArrayList<>(); /** - * The last transfer id. + * The queued resources that need to be sent. */ - public int lastTransferId; + public ArrayList queuedResources = new ArrayList<>(); /** * The logger of the class. @@ -61,7 +61,6 @@ public class ResourceManager extends Manager { */ public ResourceManager(Router router) { super(router); - this.lastTransferId = -1; } /** @@ -168,7 +167,7 @@ public ArrayList getStoredFileResources() { * Starts a push of a resource. * @param resource */ - private void startPush(Resource resource) { + public void startPush(Resource resource) { //Creating push tunnel MessageTunnel tunnel = router.messageTunnelManager.createTunnel(Node.self.getIdentity().getNetworkId(), resource.getNetworkID(), MessageTunnelSide.ORIGIN); startPush(resource, tunnel); @@ -179,7 +178,7 @@ private void startPush(Resource resource) { * @param resource * @param tunnel */ - private void startPush(Resource resource, MessageTunnel tunnel) { + public void startPush(Resource resource, MessageTunnel tunnel) { //Getting the transfer handler. ResourceTransferHandler transferHandler = resource.getTransferHandler(ResourceTransferType.OUTBOUND, tunnel, -1, this.router); logger.info("Outbound {} resource transfer, transfer id: {}", resource.getResourceType(), transferHandler.getTransferId()); @@ -320,13 +319,27 @@ else if(messageReceivedEvent.networkMessage.getContent().getType() == MsgType.RE for (FileResource file : getStoredFileResources()) { if(router.neighborNodesManager.getClosestTo(file.getNetworkID()) != Node.self) { - startPush(file); + boolean duplicate = false; + for (Resource r : + queuedResources) { + if (r == file) duplicate = true; + } + if(duplicate) continue; + + queuedResources.add(file); } } for (FlagResource flag : flagResources) { if(router.neighborNodesManager.getClosestTo(flag.getNetworkID()) != Node.self) { - startPush(flag); + boolean duplicate = false; + for (Resource r : + queuedResources) { + if (r == flag) duplicate = true; + } + if(duplicate) continue; + + queuedResources.add(flag); } } } @@ -343,7 +356,6 @@ protected void registerEvents() { EventManager.registerEvent(ResourceTransferFinishedEvent.class); EventManager.registerEvent(ResourceTransferErrorEvent.class); EventManager.registerEvent(ResourceTransferDataSentEvent.class); - EventManager.registerEvent(ResourceTransferDataReceivedEvent.class); } /** diff --git a/shared/src/main/java/me/matoosh/undernet/p2p/router/data/resource/transfer/FileTransferHandler.java b/shared/src/main/java/me/matoosh/undernet/p2p/router/data/resource/transfer/FileTransferHandler.java index 8f3d3bcb..182c6e9f 100644 --- a/shared/src/main/java/me/matoosh/undernet/p2p/router/data/resource/transfer/FileTransferHandler.java +++ b/shared/src/main/java/me/matoosh/undernet/p2p/router/data/resource/transfer/FileTransferHandler.java @@ -3,8 +3,6 @@ import me.matoosh.undernet.event.EventManager; import me.matoosh.undernet.event.resource.transfer.ResourceTransferDataReceivedEvent; import me.matoosh.undernet.event.resource.transfer.ResourceTransferDataSentEvent; -import me.matoosh.undernet.event.resource.transfer.ResourceTransferErrorEvent; -import me.matoosh.undernet.event.resource.transfer.ResourceTransferFinishedEvent; import me.matoosh.undernet.p2p.router.Router; import me.matoosh.undernet.p2p.router.data.message.ResourceDataChunkRequest; import me.matoosh.undernet.p2p.router.data.message.ResourceDataMessage; @@ -35,9 +33,9 @@ public class FileTransferHandler extends ResourceTransferHandler { private long fileLength; /** - * The standard buffer size for file chunks (100kb) + * The standard buffer size for file chunks (1MB) */ - public static final int BUFFER_SIZE = Short.MAX_VALUE; + public static final int BUFFER_SIZE = 1048576; /** * The amount of bytes written from the received chunks. From a55363b8953367b1ba03ed56f8fe5696b0c82dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20R=C4=99bacz?= Date: Tue, 15 Jan 2019 20:54:11 +0100 Subject: [PATCH 2/2] Added the identity menu. Better publishing of large files. Performance improvements. --- build.gradle | 2 +- shared/build.gradle | 4 + .../transfer/ResourceTransferHandler.java | 4 +- standalone/build.gradle | 7 ++ .../standalone/UnderNetStandalone.java | 8 ++ .../undernet/standalone/uix/MainFrame.java | 100 ++++++++++++++++++ .../standalone/uix/ResourcePanel.java | 11 +- .../standalone/uix/VisualPanelDraw.java | 5 +- .../uix/dialog/PublishResourceDialog.java | 39 ++++--- .../src/main/resources/language.properties | 9 +- .../main/resources/language_pl_PL.properties | 9 +- 11 files changed, 175 insertions(+), 23 deletions(-) diff --git a/build.gradle b/build.gradle index 266a7d2d..5265d40c 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ allprojects { sourceCompatibility = "1.8" targetCompatibility = "1.8" group 'me.matoosh.undernet' - version '0.3' + version '0.3.1' } subprojects { repositories { diff --git a/shared/build.gradle b/shared/build.gradle index 5ef468a5..4f278016 100644 --- a/shared/build.gradle +++ b/shared/build.gradle @@ -3,3 +3,7 @@ dependencies { implementation group: 'org.apache.commons', name: 'commons-crypto', version: '1.0.0' implementation group: 'org.bouncycastle', name: 'bcprov-jdk16', version: '1.45' } + +jar { + baseName = 'UnderNet-base' +} \ No newline at end of file diff --git a/shared/src/main/java/me/matoosh/undernet/p2p/router/data/resource/transfer/ResourceTransferHandler.java b/shared/src/main/java/me/matoosh/undernet/p2p/router/data/resource/transfer/ResourceTransferHandler.java index 771a2a02..f37a0c70 100644 --- a/shared/src/main/java/me/matoosh/undernet/p2p/router/data/resource/transfer/ResourceTransferHandler.java +++ b/shared/src/main/java/me/matoosh/undernet/p2p/router/data/resource/transfer/ResourceTransferHandler.java @@ -58,6 +58,8 @@ public ResourceTransferHandler(Resource resource, ResourceTransferType transferT router.resourceManager.inboundHandlers.add(this); } + setLastMessageTime(System.currentTimeMillis() - 10000); + EventManager.callEvent(new ResourceTransferStartedEvent(this)); } @@ -113,7 +115,7 @@ public void close() { * @param dataMessage */ public void callDataReceived(ResourceDataMessage dataMessage) { - lastMessageTime = System.currentTimeMillis(); + setLastMessageTime(System.currentTimeMillis()); onDataReceived(dataMessage); } diff --git a/standalone/build.gradle b/standalone/build.gradle index 0c0bc370..1ba272a0 100644 --- a/standalone/build.gradle +++ b/standalone/build.gradle @@ -17,6 +17,7 @@ distZip.shouldRunAfter(build) jar { // Keep jar clean: exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/*.MF' + baseName = 'UnderNet' manifest { attributes 'Main-Class': 'me.matoosh.undernet.standalone.UnderNetStandalone', @@ -25,4 +26,10 @@ jar { // How-to add class path: // http://stackoverflow.com/questions/22659463/add-classpath-in-manifest-using-gradle // https://gist.github.com/simon04/6865179 +} +distZip { + baseName = 'UnderNet' +} +distTar { + baseName = 'UnderNet' } \ No newline at end of file diff --git a/standalone/src/main/java/me/matoosh/undernet/standalone/UnderNetStandalone.java b/standalone/src/main/java/me/matoosh/undernet/standalone/UnderNetStandalone.java index d3cf962a..7a631a86 100644 --- a/standalone/src/main/java/me/matoosh/undernet/standalone/UnderNetStandalone.java +++ b/standalone/src/main/java/me/matoosh/undernet/standalone/UnderNetStandalone.java @@ -6,6 +6,7 @@ import me.matoosh.undernet.UnderNet; import me.matoosh.undernet.file.StandaloneFileManager; import me.matoosh.undernet.identity.NetworkIdentity; +import me.matoosh.undernet.p2p.router.InterfaceStatus; import me.matoosh.undernet.standalone.config.StandaloneConfig; import me.matoosh.undernet.standalone.config.StandaloneConfigManager; import me.matoosh.undernet.standalone.serialization.SerializationTools; @@ -139,6 +140,10 @@ private static void setup() { * @param identity */ public static void setNetworkIdentity(NetworkIdentity identity, File identityFile) { + if(UnderNet.router.status != InterfaceStatus.STOPPED) { + logger.warn("Can't change identity while the router is running!"); + return; + } if(identity == null || identityFile == null || !identity.isCorrect()) { logger.warn("Network Identity incorrect, creating a new identity!"); identity = new NetworkIdentity(); @@ -149,6 +154,9 @@ public static void setNetworkIdentity(NetworkIdentity identity, File identityFil //Setting the identity. logger.info("Setting the current UnderNet identity to: {}", identity.getNetworkId().getStringValue()); UnderNetStandalone.networkIdentity = identity; + if(MainFrame.instance != null && MainFrame.instance.frame != null) { + MainFrame.instance.frame.repaint(); + } //Save the changed identity. try { diff --git a/standalone/src/main/java/me/matoosh/undernet/standalone/uix/MainFrame.java b/standalone/src/main/java/me/matoosh/undernet/standalone/uix/MainFrame.java index cd8e3b15..5fb50fe8 100644 --- a/standalone/src/main/java/me/matoosh/undernet/standalone/uix/MainFrame.java +++ b/standalone/src/main/java/me/matoosh/undernet/standalone/uix/MainFrame.java @@ -11,15 +11,20 @@ import me.matoosh.undernet.event.resource.transfer.ResourceTransferDataSentEvent; import me.matoosh.undernet.event.resource.transfer.ResourceTransferFinishedEvent; import me.matoosh.undernet.event.router.RouterStatusEvent; +import me.matoosh.undernet.identity.NetworkIdentity; import me.matoosh.undernet.p2p.router.InterfaceStatus; import me.matoosh.undernet.p2p.router.data.resource.transfer.FileTransferHandler; import me.matoosh.undernet.p2p.router.data.resource.transfer.ResourceTransferHandler; import me.matoosh.undernet.standalone.UnderNetStandalone; +import me.matoosh.undernet.standalone.serialization.SerializationTools; +import org.apache.commons.io.FilenameUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; import java.awt.*; +import java.io.File; import java.util.ResourceBundle; public class MainFrame extends EventHandler { @@ -48,9 +53,20 @@ public class MainFrame extends EventHandler { private VisualPanel visualPanel; private TransferPanel transferPanel; + //top menu + JMenuBar menuBar; + JMenu identityMenu; + JMenuItem newIdentityOption; + JMenuItem changeIdentityOption; + public static final int START_HEIGHT = 600; public static final int START_WIDTH = 950; + /** + * Whether the app is running on mac. + */ + public static boolean IS_MAC; + public MainFrame() { $$$setupUI$$$(); mainButton.addActionListener(e -> onMainButtonClicked()); @@ -69,13 +85,38 @@ public static void newInstance() { instance.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); instance.initialize(); instance.frame.pack(); + instance.frame.setLocationRelativeTo(null); instance.frame.setSize(START_WIDTH, START_HEIGHT); instance.frame.setVisible(true); } private void initialize() { + //Check if running on a mac. + String lcOSName = System.getProperty("os.name").toLowerCase(); + IS_MAC = lcOSName.startsWith("mac os x"); + + setLook(); registerListener(); + addMenus(); + } + + private void setLook() { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (UnsupportedLookAndFeelException e) { + e.printStackTrace(); + } + if (IS_MAC) { + System.setProperty("com.apple.mrj.application.apple.menu.about.name", "UnderNet"); + System.setProperty("apple.laf.useScreenMenuBar", "true"); + } } private void registerListener() { @@ -85,6 +126,60 @@ private void registerListener() { EventManager.registerHandler(this, ResourceTransferFinishedEvent.class); } + private void addMenus() { + menuBar = new JMenuBar(); + identityMenu = new JMenu(ResourceBundle.getBundle("language").getString("menu_identity")); + newIdentityOption = new JMenuItem(ResourceBundle.getBundle("language").getString("menu_identity_new")); + newIdentityOption.addActionListener(e -> newIdentityPressed()); + changeIdentityOption = new JMenuItem(ResourceBundle.getBundle("language").getString("menu_identity_change")); + changeIdentityOption.addActionListener(e -> changeIdentityPressed()); + identityMenu.add(newIdentityOption); + identityMenu.add(changeIdentityOption); + menuBar.add(identityMenu); + frame.setJMenuBar(menuBar); + } + + private void newIdentityPressed() { + NetworkIdentity identity = new NetworkIdentity(); + + //Open file choose dialog + File saveFile = null; + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); + FileNameExtensionFilter filter = new FileNameExtensionFilter("Identity Files", "id", "identity"); + fileChooser.setFileFilter(filter); + int result = fileChooser.showSaveDialog(frame); + if (result == JFileChooser.APPROVE_OPTION) { + saveFile = fileChooser.getSelectedFile(); + if (FilenameUtils.getExtension(saveFile.getPath()) != ".id") { + saveFile = new File(saveFile.getPath() + ".id"); + } + } + + if (saveFile == null) return; + + SerializationTools.writeObjectToFile(identity, saveFile); + UnderNetStandalone.setNetworkIdentity(identity, saveFile); + } + + private void changeIdentityPressed() { + //Open file choose dialog + File openFile = null; + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); + FileNameExtensionFilter filter = new FileNameExtensionFilter("Identity Files", "id", "identity"); + fileChooser.setFileFilter(filter); + int result = fileChooser.showOpenDialog(frame); + if (result == JFileChooser.APPROVE_OPTION) { + openFile = fileChooser.getSelectedFile(); + } + + if (openFile == null || !openFile.exists()) return; + + NetworkIdentity identity = (NetworkIdentity) SerializationTools.readObjectFromFile(openFile); + UnderNetStandalone.setNetworkIdentity(identity, openFile); + } + /** * Called when the main button is clicked. */ @@ -104,18 +199,22 @@ public void onEventCalled(Event e) { switch (statusEvent.newStatus) { case STOPPED: mainButton.setEnabled(true); + identityMenu.setEnabled(true); mainButton.setText(ResourceBundle.getBundle("language").getString("button_connect")); this.frame.repaint(); break; case STARTED: instance.mainButton.setEnabled(true); + instance.identityMenu.setEnabled(false); instance.mainButton.setText(ResourceBundle.getBundle("language").getString("button_disconnect")); break; case STOPPING: mainButton.setEnabled(false); + identityMenu.setEnabled(false); break; case STARTING: mainButton.setEnabled(false); + identityMenu.setEnabled(false); new Thread(() -> drawLoop()).start(); break; } @@ -220,4 +319,5 @@ private void createUIComponents() { public JComponent $$$getRootComponent$$$() { return panel; } + } diff --git a/standalone/src/main/java/me/matoosh/undernet/standalone/uix/ResourcePanel.java b/standalone/src/main/java/me/matoosh/undernet/standalone/uix/ResourcePanel.java index 5c61349f..e443cc60 100644 --- a/standalone/src/main/java/me/matoosh/undernet/standalone/uix/ResourcePanel.java +++ b/standalone/src/main/java/me/matoosh/undernet/standalone/uix/ResourcePanel.java @@ -64,7 +64,13 @@ private void registerListeners() { } private void refreshList() { - resourceList.setListData(UnderNet.router.resourceManager.getStoredFileResources().toArray()); + if (resourceList.getModel().getSize() == 0) { + resourceList.setListData(new String[]{ResourceBundle.getBundle("language").getString("string_empty")}); + } + new Thread(() -> { + Object[] resources = UnderNet.router.resourceManager.getStoredFileResources().toArray(); + EventQueue.invokeLater(() -> resourceList.setListData(resources)); + }).start(); } @Override @@ -225,6 +231,7 @@ private void createUIComponents() { public JComponent $$$getRootComponent$$$() { return panel; } + } /** * Renders elements within the resource list. @@ -248,6 +255,8 @@ public Component getListCellRendererComponent(JList list, Object value, int inde if (isSelected) { setBackground(getBackground().darker()); } + } else if (value instanceof String) { + setText((String) value); } else { setText("UNKNOWN"); } diff --git a/standalone/src/main/java/me/matoosh/undernet/standalone/uix/VisualPanelDraw.java b/standalone/src/main/java/me/matoosh/undernet/standalone/uix/VisualPanelDraw.java index 21622516..0ab70b3f 100644 --- a/standalone/src/main/java/me/matoosh/undernet/standalone/uix/VisualPanelDraw.java +++ b/standalone/src/main/java/me/matoosh/undernet/standalone/uix/VisualPanelDraw.java @@ -7,6 +7,7 @@ import me.matoosh.undernet.event.channel.message.MessageReceivedEvent; import me.matoosh.undernet.p2p.node.Node; import me.matoosh.undernet.p2p.router.InterfaceStatus; +import me.matoosh.undernet.standalone.UnderNetStandalone; import javax.swing.*; import java.awt.*; @@ -72,9 +73,9 @@ private void drawSelfNode(Graphics g) { g.setColor(Color.BLACK); g.drawOval(getWidth()/2 - diam/2, getHeight()/2 - diam/2, diam, diam); - if(Node.self.getIdentity() != null) { + if(UnderNetStandalone.networkIdentity != null) { g.setColor(Color.WHITE); - String identity = Node.self.getIdentity().getNetworkId().getStringValue().substring(0, 12) + "..."; + String identity = UnderNetStandalone.networkIdentity.getNetworkId().getStringValue().substring(0, 12) + "..."; g.drawString(identity, getWidth()/2 - g.getFontMetrics().stringWidth(identity) / 2, getHeight()/2 + diam / 2 + g.getFontMetrics().getHeight() + 5); } } diff --git a/standalone/src/main/java/me/matoosh/undernet/standalone/uix/dialog/PublishResourceDialog.java b/standalone/src/main/java/me/matoosh/undernet/standalone/uix/dialog/PublishResourceDialog.java index 70e214d4..ecde8cf2 100644 --- a/standalone/src/main/java/me/matoosh/undernet/standalone/uix/dialog/PublishResourceDialog.java +++ b/standalone/src/main/java/me/matoosh/undernet/standalone/uix/dialog/PublishResourceDialog.java @@ -11,7 +11,10 @@ import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; -import java.awt.event.*; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.io.File; import java.util.ResourceBundle; @@ -59,21 +62,29 @@ public void keyTyped(KeyEvent e) { private void onPublish() { //Button clicked. Checking whether a correct path has been chosen. if (filePathField.getText() != null && !filePathField.getText().trim().equals("")) { - //Publishing resource on UnderNet. - FileResource fileResource = new FileResource(UnderNet.router, new File(filePathField.getText())); - if (!fileResource.copyToContent()) { - JOptionPane.showMessageDialog(MainFrame.instance.frame, String.format(ResourceBundle.getBundle("language").getString("dialog_publishResource_cantPublishMessage"), fileResource.file), ResourceBundle.getBundle("language").getString("dialog_publishResource_cantPublishTitle"), JOptionPane.ERROR_MESSAGE); - return; - } - UnderNet.router.resourceManager.publish(fileResource); + new Thread(() -> { + //Publishing resource on UnderNet. + FileResource fileResource = new FileResource(UnderNet.router, new File(filePathField.getText())); + + //Copying the network to clipboard. + StringSelection stringSelection = new StringSelection(fileResource.getNetworkID().getStringValue()); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(stringSelection, null); - //Copying the network to clipboard. - StringSelection stringSelection = new StringSelection(fileResource.getNetworkID().getStringValue()); - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - clipboard.setContents(stringSelection, null); + //Showing the published network id. + EventQueue.invokeLater(() -> JOptionPane.showMessageDialog(MainFrame.instance.frame, String.format(ResourceBundle.getBundle("language").getString("dialog_publishResource_publishingMessage"), fileResource.file, fileResource.getNetworkID().getStringValue()), ResourceBundle.getBundle("language").getString("dialog_publishResource_publishingTitle"), JOptionPane.INFORMATION_MESSAGE)); - //Showing the published network id. - JOptionPane.showMessageDialog(MainFrame.instance.frame, String.format(ResourceBundle.getBundle("language").getString("dialog_publishResource_publishingMessage"), fileResource.file, fileResource.getNetworkID().getStringValue()), ResourceBundle.getBundle("language").getString("dialog_publishResource_publishingTitle"), JOptionPane.INFORMATION_MESSAGE); + if (!fileResource.copyToContent()) { + EventQueue.invokeLater(() -> JOptionPane.showMessageDialog(MainFrame.instance.frame, String.format(ResourceBundle.getBundle("language").getString("dialog_publishResource_cantPublishMessage"), fileResource.file), ResourceBundle.getBundle("language").getString("dialog_publishResource_cantPublishTitle"), JOptionPane.ERROR_MESSAGE)); + return; + } + try { + UnderNet.router.resourceManager.publish(fileResource); + } catch (Exception e) { + EventQueue.invokeLater(() -> JOptionPane.showMessageDialog(MainFrame.instance.frame, String.format(ResourceBundle.getBundle("language").getString("dialog_publishResource_cantPublishMessage"), fileResource.file), ResourceBundle.getBundle("language").getString("dialog_publishResource_cantPublishTitle"), JOptionPane.ERROR_MESSAGE)); + return; + } + }).start(); dispose(); } else { diff --git a/standalone/src/main/resources/language.properties b/standalone/src/main/resources/language.properties index 4d4c06d4..4a9855bf 100644 --- a/standalone/src/main/resources/language.properties +++ b/standalone/src/main/resources/language.properties @@ -17,9 +17,14 @@ dialog_publishResource_publishingTitle=Publishing resource dialog_publishResource_publishingMessage=Publishing %s\nNetwork ID: %s\nThe Network ID has been copied to your clipboard. dialog_publishResource_cantPublishTitle=Can't publish resource! dialog_publishResource_cantPublishMessage=There was a problem accessing file:\n%s. -dialog_publishResource_chooseFile=Choose... +dialog_publishResource_chooseFile=Choose dialog_publishResource_file=File: dialog_pullResource_transferFinished_title=File Retrieved! dialog_pullResource_transferFinished_message=Retrieved file %s!\nNetwork id: %s\nSaved to: %s dialog_pullResource_saveTo=Save to: -dialog_pullResource_networkID=Network ID: \ No newline at end of file +dialog_pullResource_networkID=Network ID: +menu_identity=Identity +menu_identity_new=Create New Identity +menu_identity_change=Change Identity +string_loading=Loading... +string_empty=... \ No newline at end of file diff --git a/standalone/src/main/resources/language_pl_PL.properties b/standalone/src/main/resources/language_pl_PL.properties index e4ed4c60..19cd240b 100644 --- a/standalone/src/main/resources/language_pl_PL.properties +++ b/standalone/src/main/resources/language_pl_PL.properties @@ -17,9 +17,14 @@ dialog_publishResource_publishingTitle=Publikowanie zasobu dialog_publishResource_publishingMessage=Publikowanie %s\nIdentyfikator: %s\nIdentyfikator zosta\u0142 skopiowany do schowka. dialog_publishResource_cantPublishTitle=Nie mo\u017cna opublikowa\u0107 zasobu! dialog_publishResource_cantPublishMessage=Wystapi\u0142 problem przy pr\u00f3bie odczytu pliku:\n%s. -dialog_publishResource_chooseFile=Wybierz... +dialog_publishResource_chooseFile=Wybierz dialog_publishResource_file=Plik: dialog_pullResource_transferFinished_title=Plik Odebrany! dialog_pullResource_transferFinished_message=Odebrano plik %s!\nIdentyfikator: %s\nZapisano w: %s dialog_pullResource_saveTo=Zapisz w: -dialog_pullResource_networkID=Identyfikator: \ No newline at end of file +dialog_pullResource_networkID=Identyfikator: +menu_identity=To\u017csamo\u015b\u0107 +menu_identity_new=Nowa to\u017csamo\u015b\u0107 +menu_identity_change=Zmie\u0144 to\u017csamo\u015b\u0107 +string_loading=\u0141adowanie... +string_empty=... \ No newline at end of file