mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
LinuxTorPlugin: Address review comments
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user