Postpone accessing preferences BridgeAddressProvider until needed by Tor.

Previously they would be accessed too early when preferences had not
yet been read from disk.  Now we access them when Tor is started.
This commit is contained in:
jmacxx 2022-01-16 11:38:14 -06:00
parent 808c3ad9d9
commit c9235299a8
No known key found for this signature in database
GPG Key ID: 155297BABFE94A1B
3 changed files with 14 additions and 8 deletions

View File

@ -80,7 +80,7 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
boolean useSafeCookieAuthentication) {
return controlPort != Config.UNSPECIFIED_PORT ?
new RunningTor(torDir, controlPort, password, cookieFile, useSafeCookieAuthentication) :
new NewTor(torDir, torrcFile, torrcOptions, bridgeAddressProvider.getBridgeAddresses());
new NewTor(torDir, torrcFile, torrcOptions, bridgeAddressProvider);
}
@Override

View File

@ -51,19 +51,20 @@ public class NewTor extends TorMode {
private final File torrcFile;
private final String torrcOptions;
private final Collection<String> bridgeEntries;
private final BridgeAddressProvider bridgeAddressProvider;
public NewTor(File torWorkingDirectory, @Nullable File torrcFile, String torrcOptions, Collection<String> bridgeEntries) {
public NewTor(File torWorkingDirectory, @Nullable File torrcFile, String torrcOptions, BridgeAddressProvider bridgeAddressProvider) {
super(torWorkingDirectory);
this.torrcFile = torrcFile;
this.torrcOptions = torrcOptions;
this.bridgeEntries = bridgeEntries;
this.bridgeAddressProvider = bridgeAddressProvider;
}
@Override
public Tor getTor() throws IOException, TorCtlException {
long ts1 = new Date().getTime();
Collection<String> bridgeEntries = bridgeAddressProvider.getBridgeAddresses();
if (bridgeEntries != null)
log.info("Using bridges: {}", bridgeEntries.stream().collect(Collectors.joining(",")));

View File

@ -29,6 +29,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import org.slf4j.Logger;
@ -55,7 +56,7 @@ public class TorNetworkNodeTest {
latch = new CountDownLatch(1);
int port = 9001;
TorNetworkNode node1 = new TorNetworkNode(port, TestUtils.getNetworkProtoResolver(), false,
new NewTor(new File("torNode_" + port), null, "", new ArrayList<String>()), null);
new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null);
node1.start(new SetupListener() {
@Override
public void onTorNodeReady() {
@ -82,7 +83,7 @@ public class TorNetworkNodeTest {
latch = new CountDownLatch(1);
int port2 = 9002;
TorNetworkNode node2 = new TorNetworkNode(port2, TestUtils.getNetworkProtoResolver(), false,
new NewTor(new File("torNode_" + port), null, "", new ArrayList<String>()), null);
new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null);
node2.start(new SetupListener() {
@Override
public void onTorNodeReady() {
@ -140,7 +141,7 @@ public class TorNetworkNodeTest {
latch = new CountDownLatch(2);
int port = 9001;
TorNetworkNode node1 = new TorNetworkNode(port, TestUtils.getNetworkProtoResolver(), false,
new NewTor(new File("torNode_" + port), null, "", new ArrayList<String>()), null);
new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null);
node1.start(new SetupListener() {
@Override
public void onTorNodeReady() {
@ -166,7 +167,7 @@ public class TorNetworkNodeTest {
int port2 = 9002;
TorNetworkNode node2 = new TorNetworkNode(port2, TestUtils.getNetworkProtoResolver(), false,
new NewTor(new File("torNode_" + port), null, "", new ArrayList<String>()), null);
new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null);
node2.start(new SetupListener() {
@Override
public void onTorNodeReady() {
@ -217,4 +218,8 @@ public class TorNetworkNodeTest {
node2.shutDown(latch::countDown);
latch.await();
}
public List<String> getBridgeAddresses() {
return new ArrayList<>();
}
}