From a0d6eb6dd9e84b237dcc3c5f60d499327e16f79f Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Mon, 9 Jul 2018 21:52:31 +0100 Subject: [PATCH] create or load a destination from a file --- .../com/muwire/hostcache/HostCache.groovy | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/host-cache/src/main/groovy/com/muwire/hostcache/HostCache.groovy b/host-cache/src/main/groovy/com/muwire/hostcache/HostCache.groovy index 3c3b0d22..d893e0ba 100644 --- a/host-cache/src/main/groovy/com/muwire/hostcache/HostCache.groovy +++ b/host-cache/src/main/groovy/com/muwire/hostcache/HostCache.groovy @@ -1,9 +1,45 @@ package com.muwire.hostcache +import net.i2p.client.I2PClientFactory +import net.i2p.util.SystemVersion + public class HostCache { public static void main(String[] args) { - print "Hello world" + if (SystemVersion.isWindows()) { + println "This will likely not run on windows" + System.exit(1) + } + + def home = System.getProperty("user.home") + "/.MuWireHostCache" + home = new File(home) + if (home.exists() && !home.isDirectory()) { + println "${home} exists but not a directory? Delete it or make it a directory" + System.exit(1) + } + + if (!home.exists()) { + home.mkdir() + } + + def keyfile = new File(home, "key.dat") + + def i2pClientFactory = new I2PClientFactory() + def i2pClient = i2pClientFactory.createClient() + + def myDest + def session + if (!keyfile.exists()) { + def os = new FileOutputStream(keyfile); + myDest = i2pClient.createDestination(os) + os.close() + println "No key.dat file was found, so creating a new destination." + println "This is the destination you want to give out for your new HostCache" + println myDest.toBase64() + } + + session = i2pClient.createSession(new FileInputStream(keyfile), System.getProperties()) + myDest = session.getMyDestination() } }