From 55d1b62cfec84ee4220900594425713a9ab3539b Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Thu, 7 Mar 2019 15:31:34 +0300 Subject: [PATCH] Added config file to store peerID and modified .gitignore --- .gitignore | 16 ++-------- .../github/chronosx88/dhtBootstrap/Main.java | 31 ++++++++++++++++--- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 38518ea..605d812 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,3 @@ -*.iml -.gradle -/local.properties -/.idea/caches -/.idea/libraries -/.idea/modules.xml -/.idea/workspace.xml -/.idea/navEditor.xml -/.idea/assetWizardSettings.xml -.DS_Store -/out -/captures -.externalNativeBuild +/out/ +/build/ +/.idea/ \ No newline at end of file diff --git a/src/main/java/io/github/chronosx88/dhtBootstrap/Main.java b/src/main/java/io/github/chronosx88/dhtBootstrap/Main.java index ed747fe..f8c8def 100644 --- a/src/main/java/io/github/chronosx88/dhtBootstrap/Main.java +++ b/src/main/java/io/github/chronosx88/dhtBootstrap/Main.java @@ -7,17 +7,40 @@ import net.tomp2p.p2p.PeerBuilder; import net.tomp2p.peers.Number160; import net.tomp2p.storage.StorageDisk; -import java.io.File; -import java.io.IOException; +import java.io.*; +import java.util.Properties; import java.util.UUID; public class Main { private static PeerDHT peerDHT; private static Number160 peerID; + private static Properties props; + private static final String DATA_DIR_PATH = System.getProperty("user.home") + "/.local/share/Influence-Bootstrap/"; public static void main(String[] args) { - //TODO: Save peerID and route table to config - peerID = Number160.createHash(UUID.randomUUID().toString()); + props = new Properties(); + File dataDir = new File(DATA_DIR_PATH); + File config = new File(DATA_DIR_PATH + "config.properties"); + try { + if(!dataDir.exists() && !config.exists()) { + dataDir.mkdir(); + config.createNewFile(); + props.setProperty("isFirstRun", "false"); + props.setProperty("peerID", UUID.randomUUID().toString()); + props.store(new FileWriter(config), ""); + } + } catch (IOException e) { + e.printStackTrace(); + } + + try{ + props.load(new FileInputStream(config)); + } catch (IOException e) { + e.printStackTrace(); + } + + peerID = Number160.createHash(props.getProperty("peerID")); + try { peerDHT = new PeerBuilderDHT(new PeerBuilder(peerID).ports(7243).start())