Rethrow TorNotRunningException to get a crash report.

This commit is contained in:
akwizgran
2022-05-30 17:10:28 +01:00
parent 804049209d
commit 285a5f2928

View File

@@ -2,6 +2,7 @@ package org.briarproject.bramble.plugin.tor;
import net.freehaven.tor.control.EventHandler; import net.freehaven.tor.control.EventHandler;
import net.freehaven.tor.control.TorControlConnection; import net.freehaven.tor.control.TorControlConnection;
import net.freehaven.tor.control.TorNotRunningException;
import org.briarproject.bramble.PoliteExecutor; import org.briarproject.bramble.PoliteExecutor;
import org.briarproject.bramble.api.Pair; import org.briarproject.bramble.api.Pair;
@@ -321,6 +322,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
LOG.info("Tor has already built a circuit"); LOG.info("Tor has already built a circuit");
state.getAndSetCircuitBuilt(true); state.getAndSetCircuitBuilt(true);
} }
} catch (TorNotRunningException e) {
throw new RuntimeException(e);
} catch (IOException e) { } catch (IOException e) {
throw new PluginException(e); throw new PluginException(e);
} }
@@ -492,6 +495,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
} else { } else {
response = controlConnection.addOnion(privKey, portLines); response = controlConnection.addOnion(privKey, portLines);
} }
} catch (TorNotRunningException e) {
throw new RuntimeException(e);
} catch (IOException e) { } catch (IOException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
return; return;
@@ -540,11 +545,16 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
protected void enableNetwork(boolean enable) throws IOException { protected void enableNetwork(boolean enable) throws IOException {
state.enableNetwork(enable); state.enableNetwork(enable);
try {
controlConnection.setConf("DisableNetwork", enable ? "0" : "1"); controlConnection.setConf("DisableNetwork", enable ? "0" : "1");
} catch (TorNotRunningException e) {
throw new RuntimeException(e);
}
} }
private void enableBridges(boolean enable, List<BridgeType> bridgeTypes) private void enableBridges(boolean enable, List<BridgeType> bridgeTypes)
throws IOException { throws IOException {
try {
if (enable) { if (enable) {
Collection<String> conf = new ArrayList<>(); Collection<String> conf = new ArrayList<>();
conf.add("UseBridges 1"); conf.add("UseBridges 1");
@@ -565,6 +575,9 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
} else { } else {
controlConnection.setConf("UseBridges", "0"); controlConnection.setConf("UseBridges", "0");
} }
} catch (TorNotRunningException e) {
throw new RuntimeException(e);
}
} }
@Override @Override
@@ -577,6 +590,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
controlConnection.setConf("DisableNetwork", "1"); controlConnection.setConf("DisableNetwork", "1");
controlConnection.shutdownTor("TERM"); controlConnection.shutdownTor("TERM");
controlSocket.close(); controlSocket.close();
} catch (TorNotRunningException e) {
throw new RuntimeException(e);
} catch (IOException e) { } catch (IOException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
} }
@@ -708,7 +723,11 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
}); });
Map<Integer, String> portLines = Map<Integer, String> portLines =
singletonMap(80, "127.0.0.1:" + port); singletonMap(80, "127.0.0.1:" + port);
try {
controlConnection.addOnion(blob, portLines); controlConnection.addOnion(blob, portLines);
} catch (TorNotRunningException e) {
throw new RuntimeException(e);
}
return new RendezvousEndpoint() { return new RendezvousEndpoint() {
@Override @Override
@@ -718,7 +737,11 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
@Override @Override
public void close() throws IOException { public void close() throws IOException {
try {
controlConnection.delOnion(localOnion); controlConnection.delOnion(localOnion);
} catch (TorNotRunningException e) {
throw new RuntimeException(e);
}
tryToClose(ss, LOG, WARNING); tryToClose(ss, LOG, WARNING);
} }
}; };
@@ -950,12 +973,20 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
} }
private void enableConnectionPadding(boolean enable) throws IOException { private void enableConnectionPadding(boolean enable) throws IOException {
try {
controlConnection.setConf("ConnectionPadding", enable ? "1" : "0"); controlConnection.setConf("ConnectionPadding", enable ? "1" : "0");
} catch (TorNotRunningException e) {
throw new RuntimeException(e);
}
} }
private void useIpv6(boolean ipv6Only) throws IOException { private void useIpv6(boolean ipv6Only) throws IOException {
try {
controlConnection.setConf("ClientUseIPv4", ipv6Only ? "0" : "1"); controlConnection.setConf("ClientUseIPv4", ipv6Only ? "0" : "1");
controlConnection.setConf("ClientUseIPv6", ipv6Only ? "1" : "0"); controlConnection.setConf("ClientUseIPv6", ipv6Only ? "1" : "0");
} catch (TorNotRunningException e) {
throw new RuntimeException(e);
}
} }
@ThreadSafe @ThreadSafe