Make Tor ports configurable at runtime

Instead of using hard-coded values 59050 and 59051 for the Tor socks and
control ports, provide them via a TorPorts interface. This makes it possible
to pass the ports to a TorPortsImpl in modules. Hence it is possible to
configure the Tor port for different types of builds or via command line
options in case of briar headless or other clients using the core code.
This commit is contained in:
Sebastian Kürten
2021-10-14 09:03:22 +02:00
parent 807677532c
commit d4656df384
15 changed files with 124 additions and 22 deletions

View File

@@ -8,6 +8,7 @@ import org.briarproject.bramble.api.plugin.PluginCallback;
import org.briarproject.bramble.api.system.Clock;
import org.briarproject.bramble.api.system.LocationUtils;
import org.briarproject.bramble.api.system.ResourceProvider;
import org.briarproject.bramble.plugin.TorPorts;
import java.io.File;
import java.net.URI;
@@ -25,6 +26,7 @@ abstract class JavaTorPlugin extends TorPlugin {
NetworkManager networkManager,
LocationUtils locationUtils,
SocketFactory torSocketFactory,
TorPorts torPorts,
Clock clock,
ResourceProvider resourceProvider,
CircumventionProvider circumventionProvider,
@@ -37,7 +39,7 @@ abstract class JavaTorPlugin extends TorPlugin {
int maxIdleTime,
File torDirectory) {
super(ioExecutor, wakefulIoExecutor, networkManager, locationUtils,
torSocketFactory, clock, resourceProvider,
torSocketFactory, torPorts, clock, resourceProvider,
circumventionProvider, batteryManager, backoff,
torRendezvousCrypto, callback, architecture,
maxLatency, maxIdleTime, torDirectory);

View File

@@ -11,6 +11,7 @@ import org.briarproject.bramble.api.plugin.PluginCallback;
import org.briarproject.bramble.api.system.Clock;
import org.briarproject.bramble.api.system.LocationUtils;
import org.briarproject.bramble.api.system.ResourceProvider;
import org.briarproject.bramble.plugin.TorPorts;
import java.io.File;
import java.util.concurrent.Executor;
@@ -25,6 +26,7 @@ class UnixTorPlugin extends JavaTorPlugin {
NetworkManager networkManager,
LocationUtils locationUtils,
SocketFactory torSocketFactory,
TorPorts torPorts,
Clock clock,
ResourceProvider resourceProvider,
CircumventionProvider circumventionProvider,
@@ -37,7 +39,7 @@ class UnixTorPlugin extends JavaTorPlugin {
int maxIdleTime,
File torDirectory) {
super(ioExecutor, wakefulIoExecutor, networkManager, locationUtils,
torSocketFactory, clock, resourceProvider,
torSocketFactory, torPorts, clock, resourceProvider,
circumventionProvider, batteryManager, backoff,
torRendezvousCrypto, callback, architecture,
maxLatency, maxIdleTime, torDirectory);

View File

@@ -17,6 +17,7 @@ import org.briarproject.bramble.api.system.Clock;
import org.briarproject.bramble.api.system.LocationUtils;
import org.briarproject.bramble.api.system.ResourceProvider;
import org.briarproject.bramble.api.system.WakefulIoExecutor;
import org.briarproject.bramble.plugin.TorPorts;
import java.io.File;
import java.util.concurrent.Executor;
@@ -48,6 +49,7 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
private final LocationUtils locationUtils;
private final EventBus eventBus;
private final SocketFactory torSocketFactory;
private final TorPorts torPorts;
private final BackoffFactory backoffFactory;
private final ResourceProvider resourceProvider;
private final CircumventionProvider circumventionProvider;
@@ -62,6 +64,7 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
LocationUtils locationUtils,
EventBus eventBus,
SocketFactory torSocketFactory,
TorPorts torPorts,
BackoffFactory backoffFactory,
ResourceProvider resourceProvider,
CircumventionProvider circumventionProvider,
@@ -74,6 +77,7 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
this.locationUtils = locationUtils;
this.eventBus = eventBus;
this.torSocketFactory = torSocketFactory;
this.torPorts = torPorts;
this.backoffFactory = backoffFactory;
this.resourceProvider = resourceProvider;
this.circumventionProvider = circumventionProvider;
@@ -122,8 +126,8 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
MAX_POLLING_INTERVAL, BACKOFF_BASE);
TorRendezvousCrypto torRendezvousCrypto = new TorRendezvousCryptoImpl();
UnixTorPlugin plugin = new UnixTorPlugin(ioExecutor, wakefulIoExecutor,
networkManager, locationUtils, torSocketFactory, clock,
resourceProvider, circumventionProvider, batteryManager,
networkManager, locationUtils, torSocketFactory, torPorts,
clock, resourceProvider, circumventionProvider, batteryManager,
backoff, torRendezvousCrypto, callback, architecture,
MAX_LATENCY, MAX_IDLE_TIME, torDirectory);
eventBus.addListener(plugin);