Skip to content
Snippets Groups Projects
Verified Commit 8e6cd12f authored by Torsten Grote's avatar Torsten Grote
Browse files

LinuxTorPlugin: Address review comments

parent 3a49ca0d
No related branches found
No related tags found
No related merge requests found
Showing
with 42 additions and 33 deletions
......@@ -22,10 +22,16 @@ class AndroidResourceProvider implements ResourceProvider {
}
@Override
public InputStream getResourceInputStream(String name) {
public InputStream getResourceInputStream(String name, String extension) {
Resources res = appContext.getResources();
if (name.endsWith(".zip")) name = name.substring(0, name.length() - 4);
int resId = res.getIdentifier(name, "raw", appContext.getPackageName());
String fileName;
if (extension.equals(".zip")) {
fileName = name;
} else {
fileName = name + extension;
}
int resId =
res.getIdentifier(fileName, "raw", appContext.getPackageName());
return res.openRawResource(resId);
}
}
......@@ -7,5 +7,5 @@ import java.io.InputStream;
@NotNullByDefault
public interface ResourceProvider {
InputStream getResourceInputStream(String name);
InputStream getResourceInputStream(String name, String extension);
}
......@@ -166,6 +166,12 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
@Override
public void start() throws PluginException {
if (used.getAndSet(true)) throw new IllegalStateException();
if (!torDirectory.exists()) {
if (!torDirectory.mkdirs()) {
LOG.warning("Could not create Tor directory.");
throw new PluginException();
}
}
// Install or update the assets if necessary
if (!assetsAreUpToDate()) installAssets();
if (cookieFile.exists() && !cookieFile.delete())
......@@ -289,14 +295,15 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
if (LOG.isLoggable(INFO))
LOG.info("Installing Tor binary for " + architecture);
InputStream in = resourceProvider
.getResourceInputStream("tor_" + architecture + ".zip");
.getResourceInputStream("tor_" + architecture, ".zip");
ZipInputStream zin = new ZipInputStream(in);
if (zin.getNextEntry() == null) throw new IOException();
return zin;
}
private InputStream getGeoIpInputStream() throws IOException {
InputStream in = resourceProvider.getResourceInputStream("geoip.zip");
InputStream in = resourceProvider.getResourceInputStream("geoip",
".zip");
ZipInputStream zin = new ZipInputStream(in);
if (zin.getNextEntry() == null) throw new IOException();
return zin;
......
......@@ -16,7 +16,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
implementation 'net.java.dev.jna:jna:4.4.0'
implementation 'net.java.dev.jna:jna-platform:4.4.0'
tor 'org.briarproject:tor-linux:0.2.9.16@zip'
tor 'org.briarproject:tor:0.2.9.16@zip'
apt 'com.google.dagger:dagger-compiler:2.0.2'
......
package org.briarproject.bramble.api;
import java.io.File;
public interface ConfigurationManager {
File getAppDir();
}
......@@ -16,6 +16,7 @@ import java.util.logging.Logger;
import javax.inject.Inject;
import static java.net.NetworkInterface.getNetworkInterfaces;
import static java.util.Collections.list;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logException;
......@@ -49,13 +50,12 @@ class JavaNetworkManager implements NetworkManager, Service {
try {
Enumeration<NetworkInterface> interfaces = getNetworkInterfaces();
if (interfaces != null) {
while (interfaces.hasMoreElements()) {
NetworkInterface i = interfaces.nextElement();
for (NetworkInterface i : list(interfaces)) {
if (i.isLoopback()) continue;
if (i.isUp()) {
if (i.isUp() && i.getInetAddresses().hasMoreElements()) {
if (LOG.isLoggable(INFO)) {
LOG.info("Interface " + i.getDisplayName() +
" is up.");
" is up with at least one address.");
}
connected = true;
break;
......
......@@ -12,14 +12,15 @@ import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.CodeSource;
import java.util.concurrent.Executor;
import javax.net.SocketFactory;
@NotNullByDefault
class JavaTorPlugin extends TorPlugin {
class LinuxTorPlugin extends TorPlugin {
JavaTorPlugin(Executor ioExecutor, NetworkManager networkManager,
LinuxTorPlugin(Executor ioExecutor, NetworkManager networkManager,
LocationUtils locationUtils, SocketFactory torSocketFactory,
Clock clock, ResourceProvider resourceProvider,
CircumventionProvider circumventionProvider, Backoff backoff,
......@@ -43,10 +44,13 @@ class JavaTorPlugin extends TorPlugin {
@Override
protected long getLastUpdateTime() {
CodeSource codeSource =
getClass().getProtectionDomain().getCodeSource();
if (codeSource == null) throw new AssertionError("CodeSource null");
try {
URI path = getClass().getProtectionDomain().getCodeSource()
.getLocation().toURI();
return new File(path).lastModified();
URI path = codeSource.getLocation().toURI();
File file = new File(path);
return file.lastModified();
} catch (URISyntaxException e) {
throw new AssertionError(e);
}
......
......@@ -25,10 +25,10 @@ import static org.briarproject.bramble.util.OsUtils.isLinux;
@Immutable
@NotNullByDefault
public class JavaTorPluginFactory implements DuplexPluginFactory {
public class LinuxTorPluginFactory implements DuplexPluginFactory {
private static final Logger LOG =
Logger.getLogger(JavaTorPluginFactory.class.getName());
Logger.getLogger(LinuxTorPluginFactory.class.getName());
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds
......@@ -47,7 +47,7 @@ public class JavaTorPluginFactory implements DuplexPluginFactory {
private final Clock clock;
private final File torDirectory;
public JavaTorPluginFactory(Executor ioExecutor,
public LinuxTorPluginFactory(Executor ioExecutor,
NetworkManager networkManager, LocationUtils locationUtils,
EventBus eventBus, SocketFactory torSocketFactory,
BackoffFactory backoffFactory, ResourceProvider resourceProvider,
......@@ -92,9 +92,8 @@ public class JavaTorPluginFactory implements DuplexPluginFactory {
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
MAX_POLLING_INTERVAL, BACKOFF_BASE);
if (!torDirectory.exists()) torDirectory.mkdirs();
JavaTorPlugin plugin =
new JavaTorPlugin(ioExecutor, networkManager, locationUtils,
LinuxTorPlugin plugin =
new LinuxTorPlugin(ioExecutor, networkManager, locationUtils,
torSocketFactory, clock, resourceProvider,
circumventionProvider, backoff, callback, architecture,
MAX_LATENCY, MAX_IDLE_TIME, torDirectory);
......
......@@ -15,7 +15,8 @@ class JavaResourceProvider implements ResourceProvider {
}
@Override
public InputStream getResourceInputStream(String name) {
return this.getClass().getClassLoader().getResourceAsStream(name);
public InputStream getResourceInputStream(String name, String extension) {
return getClass().getClassLoader()
.getResourceAsStream(name + extension);
}
}
......@@ -12,6 +12,7 @@ dependencyVerification {
'org.apache.ant:ant-launcher:1.9.4:ant-launcher-1.9.4.jar:7bccea20b41801ca17bcbc909a78c835d0f443f12d639c77bd6ae3d05861608d',
'org.apache.ant:ant:1.9.4:ant-1.9.4.jar:649ae0730251de07b8913f49286d46bba7b92d47c5f332610aa426c4f02161d8',
'org.beanshell:bsh:1.3.0:bsh-1.3.0.jar:9b04edc75d19db54f1b4e8b5355e9364384c6cf71eb0a1b9724c159d779879f8',
'org.briarproject:tor:0.2.9.16:tor-0.2.9.16.zip:f33091ba414d6a952263981d9059b3d0a9093fd277ae887b3cdd02e8f1936558',
'org.hamcrest:hamcrest-core:1.3:hamcrest-core-1.3.jar:66fdef91e9739348df7a096aa384a5685f4e875584cce89386a7a47251c4d8e9',
'org.hamcrest:hamcrest-library:1.3:hamcrest-library-1.3.jar:711d64522f9ec410983bd310934296da134be4254a125080a0416ec178dfad1c',
'org.jmock:jmock-junit4:2.8.2:jmock-junit4-2.8.2.jar:f7ee4df4f7bd7b7f1cafad3b99eb74d579f109d5992ff625347352edb55e674c',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment