clean up for internal/external tor changes

This commit is contained in:
woodser 2024-07-29 07:57:47 -04:00 committed by GitHub
parent 3d44f3777c
commit cf282fd930
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 14 deletions

View File

@ -123,7 +123,6 @@ public class Config {
public static final String DEFAULT_REGTEST_HOST = "none"; public static final String DEFAULT_REGTEST_HOST = "none";
public static final int DEFAULT_NUM_CONNECTIONS_FOR_BTC = 9; // down from BitcoinJ default of 12 public static final int DEFAULT_NUM_CONNECTIONS_FOR_BTC = 9; // down from BitcoinJ default of 12
static final String DEFAULT_CONFIG_FILE_NAME = "haveno.properties"; static final String DEFAULT_CONFIG_FILE_NAME = "haveno.properties";
public static final String UNSPECIFIED_HIDDENSERVICE_ADDRESS = "placeholder.onion";
// Static fields that provide access to Config properties in locations where injecting // Static fields that provide access to Config properties in locations where injecting
// a Config instance is not feasible. See Javadoc for corresponding static accessors. // a Config instance is not feasible. See Javadoc for corresponding static accessors.
@ -293,7 +292,7 @@ public class Config {
parser.accepts(HIDDEN_SERVICE_ADDRESS, "Hidden Service Address to listen on") parser.accepts(HIDDEN_SERVICE_ADDRESS, "Hidden Service Address to listen on")
.withRequiredArg() .withRequiredArg()
.ofType(String.class) .ofType(String.class)
.defaultsTo(UNSPECIFIED_HIDDENSERVICE_ADDRESS); .defaultsTo("");
ArgumentAcceptingOptionSpec<Integer> walletRpcBindPortOpt = ArgumentAcceptingOptionSpec<Integer> walletRpcBindPortOpt =
parser.accepts(WALLET_RPC_BIND_PORT, "Port to bind the wallet RPC on") parser.accepts(WALLET_RPC_BIND_PORT, "Port to bind the wallet RPC on")

View File

@ -87,13 +87,11 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
String password, String password,
@Nullable File cookieFile, @Nullable File cookieFile,
boolean useSafeCookieAuthentication) { boolean useSafeCookieAuthentication) {
if (!hiddenServiceAddress.equals(Config.UNSPECIFIED_HIDDENSERVICE_ADDRESS)) { if (!hiddenServiceAddress.equals("")) {
return new DirectBindTor(); return new DirectBindTor();
} } else if (controlPort != Config.UNSPECIFIED_PORT) {
else if (controlPort != Config.UNSPECIFIED_PORT) {
return new RunningTor(torDir, controlHost, controlPort, password, cookieFile, useSafeCookieAuthentication); return new RunningTor(torDir, controlHost, controlPort, password, cookieFile, useSafeCookieAuthentication);
} } else {
else {
return new NewTor(torDir, torrcFile, torrcOptions, bridgeAddressProvider); return new NewTor(torDir, torrcFile, torrcOptions, bridgeAddressProvider);
} }
} }

View File

@ -31,7 +31,8 @@ public class TorNetworkNodeDirectBind extends TorNetworkNode {
public TorNetworkNodeDirectBind(int servicePort, public TorNetworkNodeDirectBind(int servicePort,
NetworkProtoResolver networkProtoResolver, NetworkProtoResolver networkProtoResolver,
@Nullable BanFilter banFilter, @Nullable BanFilter banFilter,
int maxConnections, String hiddenServiceAddress) { int maxConnections,
String hiddenServiceAddress) {
super(servicePort, networkProtoResolver, banFilter, maxConnections); super(servicePort, networkProtoResolver, banFilter, maxConnections);
this.serviceAddress = hiddenServiceAddress; this.serviceAddress = hiddenServiceAddress;
} }
@ -39,7 +40,7 @@ public class TorNetworkNodeDirectBind extends TorNetworkNode {
@Override @Override
public void shutDown(@Nullable Runnable shutDownCompleteHandler) { public void shutDown(@Nullable Runnable shutDownCompleteHandler) {
super.shutDown(() -> { super.shutDown(() -> {
log.info("TorNetworkNode shutdown already completed"); log.info("TorNetworkNodeDirectBind shutdown completed");
if (shutDownCompleteHandler != null) shutDownCompleteHandler.run(); if (shutDownCompleteHandler != null) shutDownCompleteHandler.run();
}); });
} }
@ -53,7 +54,7 @@ public class TorNetworkNodeDirectBind extends TorNetworkNode {
@Override @Override
protected Socket createSocket(NodeAddress peerNodeAddress) throws IOException { protected Socket createSocket(NodeAddress peerNodeAddress) throws IOException {
// https://www.ietf.org/rfc1928.txt SOCKS5 Protocol // https://datatracker.ietf.org/doc/html/rfc1928 SOCKS5 Protocol
try { try {
checkArgument(peerNodeAddress.getHostName().endsWith(".onion"), "PeerAddress is not an onion address"); checkArgument(peerNodeAddress.getHostName().endsWith(".onion"), "PeerAddress is not an onion address");
Socket sock = new Socket(InetAddress.getLoopbackAddress(), TOR_DATA_PORT); Socket sock = new Socket(InetAddress.getLoopbackAddress(), TOR_DATA_PORT);
@ -93,7 +94,7 @@ public class TorNetworkNodeDirectBind extends TorNetworkNode {
ServerSocket socket = new ServerSocket(servicePort); ServerSocket socket = new ServerSocket(servicePort);
nodeAddressProperty.set(new NodeAddress(serviceAddress + ":" + servicePort)); nodeAddressProperty.set(new NodeAddress(serviceAddress + ":" + servicePort));
log.info("\n################################################################\n" + log.info("\n################################################################\n" +
"Tor hidden service published: {} Port: {}\n" + "Bound to Tor hidden service: {} Port: {}\n" +
"################################################################", "################################################################",
serviceAddress, servicePort); serviceAddress, servicePort);
UserThread.execute(() -> setupListeners.forEach(SetupListener::onTorNodeReady)); UserThread.execute(() -> setupListeners.forEach(SetupListener::onTorNodeReady));

View File

@ -64,9 +64,9 @@ public class TorNetworkNodeNetlayer extends TorNetworkNode {
@Override @Override
public void shutDown(@Nullable Runnable shutDownCompleteHandler) { public void shutDown(@Nullable Runnable shutDownCompleteHandler) {
log.info("TorNetworkNode shutdown started"); log.info("TorNetworkNodeNetlayer shutdown started");
if (shutDownComplete) { if (shutDownComplete) {
log.info("TorNetworkNode shutdown already completed"); log.info("TorNetworkNodeNetlayer shutdown already completed");
if (shutDownCompleteHandler != null) shutDownCompleteHandler.run(); if (shutDownCompleteHandler != null) shutDownCompleteHandler.run();
return; return;
} }
@ -93,7 +93,7 @@ public class TorNetworkNodeNetlayer extends TorNetworkNode {
} }
executor.shutdownNow(); executor.shutdownNow();
} catch (Throwable e) { } catch (Throwable e) {
log.error("Shutdown torNetworkNode failed with exception", e); log.error("Shutdown TorNetworkNodeNetlayer failed with exception", e);
} finally { } finally {
shutDownTimeoutTimer.stop(); shutDownTimeoutTimer.stop();
shutDownComplete = true; shutDownComplete = true;