diff --git a/app/build.gradle b/app/build.gradle index 57d7eac..10804e0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,6 +34,7 @@ android { repositories { jcenter() maven { url 'https://jitpack.io' } + maven { url 'https://mvn.freenetproject.org' } } dependencies { @@ -53,39 +54,19 @@ dependencies { implementation 'com.jakewharton:process-phoenix:2.0.0' // Freenet dependencies - implementation 'org.bouncycastle:bcpkix-jdk15on:1.59' - implementation "org.bouncycastle:bcprov-jdk15on:1.59" - - implementation "tanukisoft:wrapper:3.2.3" - implementation "org.apache.commons:commons-compress:1.4.1" - implementation "org.b1.pack:lzma-sdk-4j:9.22.0" - - implementation 'com.github.Bombe:jFCPlib:v0.1.6' - - implementation 'com.github.freenet-mobile:mantissa:0.0.3' - implementation "com.github.freenet-mobile:lzmajio:0.95.4" - implementation 'com.github.freenet-mobile:onion-common:0.0.3' - implementation 'com.github.freenet-mobile:onion-fec:0.0.4' - implementation 'com.github.freenet-mobile:freenet-ext:0.60.3' - - implementation 'net.java.dev.jna:jna:4.5.2@aar' - implementation ('com.github.freenet-mobile:fred:1490.2m') { + implementation ('com.github.freenet-mobile:node-wrapper:0.5') { + exclude group: 'org.freenetproject', module: 'freenet-ext' exclude group: 'net.java.dev.jna', module: 'jna' exclude group: 'net.java.dev.jna', module: 'jna-platform' } - - implementation ('com.github.desyncr:plugin-sharesite:0.4.7.7m') { - exclude group: 'net.java.dev.jna', module: 'jna' - exclude group: 'net.java.dev.jna', module: 'jna-platform' - exclude group: 'net.java', module: 'textile-j' - } + implementation 'net.java.dev.jna:jna:4.5.2@aar' + // End Freenet dependencies // For running a locally built freenet.jar //implementation "net.java.dev.jna:jna:4.5.2" //implementation "net.java.dev.jna:jna-platform:4.5.2" //implementation files('libs/freenet.jar') - implementation 'androidx.preference:preference:1.1.1' testImplementation 'junit:junit:4.12' diff --git a/app/src/main/java/org/freenetproject/mobile/services/node/Installer.java b/app/src/main/java/org/freenetproject/mobile/services/node/Installer.java deleted file mode 100644 index 1ebf6d7..0000000 --- a/app/src/main/java/org/freenetproject/mobile/services/node/Installer.java +++ /dev/null @@ -1,148 +0,0 @@ -package org.freenetproject.mobile.services.node; - -import android.util.Log; - -import org.apache.commons.compress.utils.IOUtils; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; - -public class Installer { - private String path = null; - private static Installer instance = null; - private Installer() { } - - private final String FREENET_INI = "freenet.ini"; - private final String SEEDNODES = "seednodes.fref"; - private final String BOOKMARKS = "bookmarks.dat"; - - public static Installer getInstance() { - if (instance == null) { - instance = new Installer(); - } - return instance; - } - - /** - * Install the node with default configuration and seed nodes both from resources. Some configuration - * properties are dynamically calculated at runtime on the first startup (mostly related to directory paths). - * - * @param path Path to installation location. - * @param seeds Input stream of seeds file. - * @param config Input stream of default configuration. - * @param bookmarks Input stream of default bookmarks - * - * @throws FileNotFoundException - */ - public void install(String path, InputStream seeds, InputStream config, InputStream bookmarks, String lang) throws FileNotFoundException { - File f = new File(path); - if (!f.exists() || !f.canWrite()) { - throw new FileNotFoundException("Invalid installation directory: " + path); - } - - this.path = path; - - // Install bundled configurations - createConfiguration(seeds, getSeednodesPath()); - createConfiguration(config, getFreenetIniPath()); - createConfiguration(bookmarks, getBookmarksPath()); - - // Update freenet.ini with dynamic configuration - final FileOutputStream ini = new FileOutputStream(getFreenetIniPath(), true); - final PrintWriter out = new PrintWriter(new OutputStreamWriter(ini)); - - out.println("node.install.cfgDir=" + path); - out.println("node.install.userDir=" + path); - out.println("node.install.nodeDir=" + path); - out.println("node.install.runDir=" + path); - out.println("node.install.storeDir=" + path + "/pathstore"); - out.println("node.install.tempDir=" + path + "/temp"); - out.println("node.install.pluginDir=" + path + "/plugins"); - out.println("node.install.pluginStoresDir=" + path + "/plugin-path"); - out.println("node.install.persistentTempDir=" + path + "/persistent-temp"); - - out.println("node.masterKeyFile=" + path + "/master.keys"); - out.println("node.downloadsDir=" + path + "/downloads"); - - out.println("logger.dirname=" + path + "/logs"); - - out.println("node.l10n=" + lang); - - out.println("End"); - out.close(); - } - - /** - * Creates the seednodes.fref file in order for the node to bootstrap into the network. - * - * @return Boolean true if the seednodes file exists or was created successfully, false otherwise. - */ - private boolean createConfiguration(InputStream configuration, String filename) { - File f = new File(filename); - if (f.exists()) { - return true; - } - - try { - if (!f.createNewFile()) { - Log.e("Feeenet", "Failed to call createNewFile."); - return false; - } - } catch (IOException e) { - Log.e("Freenet", "Failed to create temporary file."); - Log.e("Freenet", e.getMessage()); - return false; - } - - OutputStream outputStream = null; - try { - outputStream = new FileOutputStream(f); - } catch (FileNotFoundException e) { - Log.e("Freenet", "Failed to create temporary file."); - Log.e("Freenet", e.getMessage()); - return false; - } - - try { - IOUtils.copy(configuration, outputStream); - } catch (IOException e) { - Log.e("Freenet", "Failed to copy temporary file."); - Log.e("Freenet", e.getMessage()); - return false; - } - - return true; - } - - public boolean isInstalled() { - File f = new File(getFreenetIniPath()); - return f.exists(); - } - - // TODO: Implement uninstall - public void uninstall() { - Log.d("Freenet", "Unimplemented uninstall method."); - } - - public String getPath() { - return path; - } - - public String getSeednodesPath() { - return path + "/" + SEEDNODES; - } - - public String getFreenetIniPath() { - return path + "/" + FREENET_INI; - } - - public String getBookmarksPath() { - return path + "/" + BOOKMARKS; - } -} diff --git a/app/src/main/java/org/freenetproject/mobile/services/node/Manager.java b/app/src/main/java/org/freenetproject/mobile/services/node/Manager.java index dc5412e..cf065b7 100644 --- a/app/src/main/java/org/freenetproject/mobile/services/node/Manager.java +++ b/app/src/main/java/org/freenetproject/mobile/services/node/Manager.java @@ -18,6 +18,9 @@ import java.util.HashMap; import java.util.Map; +import org.freenetproject.mobile.Runner; +import org.freenetproject.mobile.Installer; + /** * Class responsible for exposing data to the UI. It also exposes methods for the UI to interact with, * such as startService and stopService. @@ -25,7 +28,7 @@ public class Manager { private static Manager instance = null; - private Runner runner = Runner.getInstance(); + private final Runner runner = Runner.getInstance(); public enum Status { STARTING_UP, diff --git a/app/src/main/java/org/freenetproject/mobile/services/node/Runner.java b/app/src/main/java/org/freenetproject/mobile/services/node/Runner.java deleted file mode 100644 index 9c65ce0..0000000 --- a/app/src/main/java/org/freenetproject/mobile/services/node/Runner.java +++ /dev/null @@ -1,145 +0,0 @@ -package org.freenetproject.mobile.services.node; - -import android.util.Log; - -import net.pterodactylus.fcp.ClientHello; -import net.pterodactylus.fcp.FcpConnection; -import net.pterodactylus.fcp.ModifyConfig; - -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.tanukisoftware.wrapper.WrapperManager; - -import java.io.IOException; -import java.security.Security; - -import freenet.crypt.KeyGenUtils; -import freenet.node.Node; -import freenet.node.NodeStarter; -import freenet.pluginmanager.PluginManager; -import plugins.Sharesite.Plugin; - -/** - * Small wrapper around NodeStarter and WrapperManager to start and stop the node. Also is responsible - * for installing the bundled BouncyCastle security provider. - */ -public class Runner { - private static Runner instance = null; - private FcpConnection fcpConnection; - - private Runner() { - Security.removeProvider("BC"); - Security.insertProviderAt(new BouncyCastleProvider(), 1); - } - - public static Runner getInstance() { - if (instance == null) { - instance = new Runner(); - } - return instance; - } - - /** - * Starts the node through NodeStarter unless it's already started. - * - * @param args Arguments to pass to the NodeStarter - * @return -1 if the node is running or in transition - * -2 if the node is already running - * 0 if the node could be started - */ - public synchronized int start(String[] args) { - if (!isStopped()) { - return -1; - } - - try { - Node node = NodeStarter.start_osgi(args); - - PluginManager pm = node.getPluginManager(); - Plugin sharesite = new Plugin(); - pm.startPlugin(sharesite); - } catch (IllegalStateException e) { - return -2; - } - - return 0; - } - - /** - * Stops the node through WrapperManager unless it's already stopped. - * - * @return -1 if the node is stopped or in transition - * -2 if there's an error stopping the node - * 0 if the node could be stopped - */ - public synchronized int stop() { - if (!isStarted()) { - // Already stopped - return 0; - } - - try { - NodeStarter.stop_osgi(0); - } catch (NullPointerException e){ - // Node was already stopped - } catch (Exception e) { - return -2; - } - - return 0; - } - - /** - * - * @return - */ - public synchronized int pause() throws IOException { - enableOpennet(false); - return 0; - } - - /** - * - * @return - */ - public synchronized int resume() throws IOException { - enableOpennet(true); - return 0; - } - - private FcpConnection getConnection() throws IOException { - if (fcpConnection != null) { - return fcpConnection; - } - - try { - fcpConnection = new FcpConnection("127.0.0.1", 9481); - fcpConnection.connect(); - fcpConnection.sendMessage(new ClientHello("freenet-mobile")); - } catch (Exception e) { - fcpConnection = null; - Log.i("Freenet", "Failed to connect through FCP. Node shutdown or wrong port: " + e.getMessage()); - throw e; - } - - return fcpConnection; - } - - private void enableOpennet(Boolean enabled) throws IOException { - ModifyConfig modifyConfig = new ModifyConfig("identifier"); - modifyConfig.setOption("node.opennet.enabled", enabled.toString()); - getConnection().sendMessage(modifyConfig); - } - - public Boolean isStarted() { - try { - getConnection(); - return true; - } catch (Exception e) { - return false; - } - } - - public Boolean isStopped() { - return !isStarted(); - } -}