mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Merge branch '2366-tor-not-running-exception' into 'master'
No longer crash when the Tor process crashes Closes #2366 See merge request briar/briar!1715
This commit is contained in:
@@ -2,7 +2,6 @@ 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;
|
||||||
@@ -314,8 +313,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
LOG.info("Tor has already built a circuit");
|
LOG.info("Tor has already built a circuit");
|
||||||
state.setCircuitBuilt(true);
|
state.setCircuitBuilt(true);
|
||||||
}
|
}
|
||||||
} catch (TorNotRunningException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new PluginException(e);
|
throw new PluginException(e);
|
||||||
}
|
}
|
||||||
@@ -522,8 +519,6 @@ 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;
|
||||||
@@ -572,32 +567,24 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
|
|
||||||
protected void enableNetwork(boolean enable) throws IOException {
|
protected void enableNetwork(boolean enable) throws IOException {
|
||||||
if (!state.enableNetwork(enable)) return; // Unchanged
|
if (!state.enableNetwork(enable)) return; // Unchanged
|
||||||
try {
|
controlConnection.setConf("DisableNetwork", enable ? "0" : "1");
|
||||||
controlConnection.setConf("DisableNetwork", enable ? "0" : "1");
|
|
||||||
} catch (TorNotRunningException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableBridges(List<BridgeType> bridgeTypes, String countryCode)
|
private void enableBridges(List<BridgeType> bridgeTypes, String countryCode)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (!state.setBridgeTypes(bridgeTypes)) return; // Unchanged
|
if (!state.setBridgeTypes(bridgeTypes)) return; // Unchanged
|
||||||
try {
|
if (bridgeTypes.isEmpty()) {
|
||||||
if (bridgeTypes.isEmpty()) {
|
controlConnection.setConf("UseBridges", "0");
|
||||||
controlConnection.setConf("UseBridges", "0");
|
controlConnection.resetConf(singletonList("Bridge"));
|
||||||
controlConnection.resetConf(singletonList("Bridge"));
|
} else {
|
||||||
} else {
|
Collection<String> conf = new ArrayList<>();
|
||||||
Collection<String> conf = new ArrayList<>();
|
conf.add("UseBridges 1");
|
||||||
conf.add("UseBridges 1");
|
boolean letsEncrypt = canVerifyLetsEncryptCerts();
|
||||||
boolean letsEncrypt = canVerifyLetsEncryptCerts();
|
for (BridgeType bridgeType : bridgeTypes) {
|
||||||
for (BridgeType bridgeType : bridgeTypes) {
|
conf.addAll(circumventionProvider
|
||||||
conf.addAll(circumventionProvider
|
.getBridges(bridgeType, countryCode, letsEncrypt));
|
||||||
.getBridges(bridgeType, countryCode, letsEncrypt));
|
|
||||||
}
|
|
||||||
controlConnection.setConf(conf);
|
|
||||||
}
|
}
|
||||||
} catch (TorNotRunningException e) {
|
controlConnection.setConf(conf);
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,8 +606,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
LOG.info("Stopping Tor");
|
LOG.info("Stopping Tor");
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -752,11 +737,7 @@ 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
|
||||||
@@ -766,11 +747,7 @@ 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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1012,21 +989,13 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
|
|
||||||
private void enableConnectionPadding(boolean enable) throws IOException {
|
private void enableConnectionPadding(boolean enable) throws IOException {
|
||||||
if (!state.enableConnectionPadding(enable)) return; // Unchanged
|
if (!state.enableConnectionPadding(enable)) return; // Unchanged
|
||||||
try {
|
controlConnection.setConf("ConnectionPadding", enable ? "1" : "0");
|
||||||
controlConnection.setConf("ConnectionPadding", enable ? "1" : "0");
|
|
||||||
} catch (TorNotRunningException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableIpv6(boolean enable) throws IOException {
|
private void enableIpv6(boolean enable) throws IOException {
|
||||||
if (!state.enableIpv6(enable)) return; // Unchanged
|
if (!state.enableIpv6(enable)) return; // Unchanged
|
||||||
try {
|
controlConnection.setConf("ClientUseIPv4", enable ? "0" : "1");
|
||||||
controlConnection.setConf("ClientUseIPv4", enable ? "0" : "1");
|
controlConnection.setConf("ClientUseIPv6", enable ? "1" : "0");
|
||||||
controlConnection.setConf("ClientUseIPv6", enable ? "1" : "0");
|
|
||||||
} catch (TorNotRunningException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
|
|||||||
Reference in New Issue
Block a user