Update tor binary to 0.4.7.10 (#810)

This commit is contained in:
napoly 2024-03-11 13:05:06 +01:00 committed by GitHub
parent 82b6bcfda5
commit 78098e49d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 97 additions and 39 deletions

View file

@ -47,6 +47,7 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
@Named(Config.TOR_DIR) File torDir,
@Nullable @Named(Config.TORRC_FILE) File torrcFile,
@Named(Config.TORRC_OPTIONS) String torrcOptions,
@Named(Config.TOR_CONTROL_HOST) String controlHost,
@Named(Config.TOR_CONTROL_PORT) int controlPort,
@Named(Config.TOR_CONTROL_PASSWORD) String password,
@Nullable @Named(Config.TOR_CONTROL_COOKIE_FILE) File cookieFile,
@ -59,11 +60,12 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
torDir,
torrcFile,
torrcOptions,
controlHost,
controlPort,
password,
cookieFile,
useSafeCookieAuthentication);
networkNode = new TorNetworkNode(port, networkProtoResolver, streamIsolation, torMode, banFilter, maxConnections);
networkNode = new TorNetworkNode(port, networkProtoResolver, streamIsolation, torMode, banFilter, maxConnections, controlHost);
}
}
@ -71,12 +73,13 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
File torDir,
@Nullable File torrcFile,
String torrcOptions,
String controlHost,
int controlPort,
String password,
@Nullable File cookieFile,
boolean useSafeCookieAuthentication) {
return controlPort != Config.UNSPECIFIED_PORT ?
new RunningTor(torDir, controlPort, password, cookieFile, useSafeCookieAuthentication) :
new RunningTor(torDir, controlHost, controlPort, password, cookieFile, useSafeCookieAuthentication) :
new NewTor(torDir, torrcFile, torrcOptions, bridgeAddressProvider);
}

View file

@ -19,8 +19,26 @@ package haveno.network.p2p;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import static com.google.inject.name.Names.named;
import static com.google.inject.util.Providers.of;
import haveno.common.app.AppModule;
import haveno.common.config.Config;
import static haveno.common.config.Config.BAN_LIST;
import static haveno.common.config.Config.MAX_CONNECTIONS;
import static haveno.common.config.Config.NODE_PORT;
import static haveno.common.config.Config.REPUBLISH_MAILBOX_ENTRIES;
import static haveno.common.config.Config.SOCKS_5_PROXY_HTTP_ADDRESS;
import static haveno.common.config.Config.SOCKS_5_PROXY_XMR_ADDRESS;
import static haveno.common.config.Config.TORRC_FILE;
import static haveno.common.config.Config.TORRC_OPTIONS;
import static haveno.common.config.Config.TOR_CONTROL_COOKIE_FILE;
import static haveno.common.config.Config.TOR_CONTROL_HOST;
import static haveno.common.config.Config.TOR_CONTROL_PASSWORD;
import static haveno.common.config.Config.TOR_CONTROL_PORT;
import static haveno.common.config.Config.TOR_CONTROL_USE_SAFE_COOKIE_AUTH;
import static haveno.common.config.Config.TOR_DIR;
import static haveno.common.config.Config.TOR_STREAM_ISOLATION;
import static haveno.common.config.Config.USE_LOCALHOST_FOR_P2P;
import haveno.network.Socks5ProxyProvider;
import haveno.network.http.HttpClient;
import haveno.network.http.HttpClientImpl;
@ -35,29 +53,10 @@ import haveno.network.p2p.storage.P2PDataStorage;
import haveno.network.p2p.storage.persistence.AppendOnlyDataStoreService;
import haveno.network.p2p.storage.persistence.ProtectedDataStoreService;
import haveno.network.p2p.storage.persistence.ResourceDataStoreService;
import java.io.File;
import java.time.Clock;
import java.util.List;
import static com.google.inject.name.Names.named;
import static com.google.inject.util.Providers.of;
import static haveno.common.config.Config.BAN_LIST;
import static haveno.common.config.Config.MAX_CONNECTIONS;
import static haveno.common.config.Config.NODE_PORT;
import static haveno.common.config.Config.REPUBLISH_MAILBOX_ENTRIES;
import static haveno.common.config.Config.SOCKS_5_PROXY_XMR_ADDRESS;
import static haveno.common.config.Config.SOCKS_5_PROXY_HTTP_ADDRESS;
import static haveno.common.config.Config.TORRC_FILE;
import static haveno.common.config.Config.TORRC_OPTIONS;
import static haveno.common.config.Config.TOR_CONTROL_COOKIE_FILE;
import static haveno.common.config.Config.TOR_CONTROL_PASSWORD;
import static haveno.common.config.Config.TOR_CONTROL_PORT;
import static haveno.common.config.Config.TOR_CONTROL_USE_SAFE_COOKIE_AUTH;
import static haveno.common.config.Config.TOR_DIR;
import static haveno.common.config.Config.TOR_STREAM_ISOLATION;
import static haveno.common.config.Config.USE_LOCALHOST_FOR_P2P;
public class P2PModule extends AppModule {
public P2PModule(Config config) {
@ -96,6 +95,7 @@ public class P2PModule extends AppModule {
bindConstant().annotatedWith(named(SOCKS_5_PROXY_HTTP_ADDRESS)).to(config.socks5ProxyHttpAddress);
bind(File.class).annotatedWith(named(TORRC_FILE)).toProvider(of(config.torrcFile)); // allow null value
bindConstant().annotatedWith(named(TORRC_OPTIONS)).to(config.torrcOptions);
bindConstant().annotatedWith(named(TOR_CONTROL_HOST)).to(config.torControlHost);
bindConstant().annotatedWith(named(TOR_CONTROL_PORT)).to(config.torControlPort);
bindConstant().annotatedWith(named(TOR_CONTROL_PASSWORD)).to(config.torControlPassword);
bind(File.class).annotatedWith(named(TOR_CONTROL_COOKIE_FILE)).toProvider(of(config.torControlCookieFile));

View file

@ -17,15 +17,13 @@
package haveno.network.p2p.network;
import java.io.File;
import java.util.Date;
import lombok.extern.slf4j.Slf4j;
import org.berndpruenster.netlayer.tor.ExternalTor;
import org.berndpruenster.netlayer.tor.Tor;
import org.berndpruenster.netlayer.tor.TorCtlException;
import java.io.File;
import java.io.IOException;
import java.util.Date;
/**
* This class creates a brand new instance of the Tor onion router.
*
@ -39,15 +37,21 @@ import java.util.Date;
@Slf4j
public class RunningTor extends TorMode {
private final String controlHost;
private final int controlPort;
private final String password;
private final File cookieFile;
private final boolean useSafeCookieAuthentication;
public RunningTor(final File torDir, final int controlPort, final String password, final File cookieFile,
final boolean useSafeCookieAuthentication) {
public RunningTor(final File torDir,
final String controlHost,
final int controlPort,
final String password,
final File cookieFile,
final boolean useSafeCookieAuthentication) {
super(torDir);
this.controlHost = controlHost;
this.controlPort = controlPort;
this.password = password;
this.cookieFile = cookieFile;
@ -55,18 +59,18 @@ public class RunningTor extends TorMode {
}
@Override
public Tor getTor() throws IOException, TorCtlException {
public Tor getTor() throws TorCtlException {
long ts1 = new Date().getTime();
log.info("Connecting to running tor");
Tor result;
if (!password.isEmpty())
result = new ExternalTor(controlPort, password);
result = new ExternalTor(controlHost, controlPort, password);
else if (cookieFile != null && cookieFile.exists())
result = new ExternalTor(controlPort, cookieFile, useSafeCookieAuthentication);
result = new ExternalTor(controlHost, controlPort, cookieFile, useSafeCookieAuthentication);
else
result = new ExternalTor(controlPort);
result = new ExternalTor(controlHost, controlPort);
log.info(
"\n################################################################\n"

View file

@ -51,6 +51,8 @@ import static com.google.common.base.Preconditions.checkArgument;
public class TorNetworkNode extends NetworkNode {
private static final long SHUT_DOWN_TIMEOUT = 2;
private final String torControlHost;
private HiddenServiceSocket hiddenServiceSocket;
private Timer shutDownTimeoutTimer;
private Tor tor;
@ -70,10 +72,11 @@ public class TorNetworkNode extends NetworkNode {
boolean useStreamIsolation,
TorMode torMode,
@Nullable BanFilter banFilter,
int maxConnections) {
int maxConnections, String torControlHost) {
super(servicePort, networkProtoResolver, banFilter, maxConnections);
this.torMode = torMode;
this.streamIsolation = useStreamIsolation;
this.torControlHost = torControlHost;
executor = SingleThreadExecutorUtils.getSingleThreadExecutor("StartTor");
}
@ -97,7 +100,7 @@ public class TorNetworkNode extends NetworkNode {
checkArgument(peerNodeAddress.getHostName().endsWith(".onion"), "PeerAddress is not an onion address");
// If streamId is null stream isolation gets deactivated.
// Hidden services use stream isolation by default, so we pass null.
return new TorSocket(peerNodeAddress.getHostName(), peerNodeAddress.getPort(), null);
return new TorSocket(peerNodeAddress.getHostName(), peerNodeAddress.getPort(), torControlHost, null);
}
public Socks5Proxy getSocksProxy() {
@ -111,7 +114,7 @@ public class TorNetworkNode extends NetworkNode {
if (socksProxy == null || streamIsolation) {
tor = Tor.getDefault();
socksProxy = tor != null ? tor.getProxy(stream) : null;
socksProxy = tor != null ? tor.getProxy(torControlHost, stream) : null;
}
return socksProxy;
} catch (Throwable t) {