From cf282fd930f4766f395b2b899bf4729843d5b7d3 Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 29 Jul 2024 07:57:47 -0400 Subject: [PATCH] clean up for internal/external tor changes --- common/src/main/java/haveno/common/config/Config.java | 3 +-- .../java/haveno/network/p2p/NetworkNodeProvider.java | 8 +++----- .../network/p2p/network/TorNetworkNodeDirectBind.java | 9 +++++---- .../network/p2p/network/TorNetworkNodeNetlayer.java | 6 +++--- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/haveno/common/config/Config.java b/common/src/main/java/haveno/common/config/Config.java index 816c87b1..92359c76 100644 --- a/common/src/main/java/haveno/common/config/Config.java +++ b/common/src/main/java/haveno/common/config/Config.java @@ -123,7 +123,6 @@ public class Config { public static final String DEFAULT_REGTEST_HOST = "none"; 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"; - public static final String UNSPECIFIED_HIDDENSERVICE_ADDRESS = "placeholder.onion"; // Static fields that provide access to Config properties in locations where injecting // 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") .withRequiredArg() .ofType(String.class) - .defaultsTo(UNSPECIFIED_HIDDENSERVICE_ADDRESS); + .defaultsTo(""); ArgumentAcceptingOptionSpec walletRpcBindPortOpt = parser.accepts(WALLET_RPC_BIND_PORT, "Port to bind the wallet RPC on") diff --git a/p2p/src/main/java/haveno/network/p2p/NetworkNodeProvider.java b/p2p/src/main/java/haveno/network/p2p/NetworkNodeProvider.java index 9dd8fcb9..798d1623 100644 --- a/p2p/src/main/java/haveno/network/p2p/NetworkNodeProvider.java +++ b/p2p/src/main/java/haveno/network/p2p/NetworkNodeProvider.java @@ -87,13 +87,11 @@ public class NetworkNodeProvider implements Provider { String password, @Nullable File cookieFile, boolean useSafeCookieAuthentication) { - if (!hiddenServiceAddress.equals(Config.UNSPECIFIED_HIDDENSERVICE_ADDRESS)) { + if (!hiddenServiceAddress.equals("")) { return new DirectBindTor(); - } - else if (controlPort != Config.UNSPECIFIED_PORT) { + } else if (controlPort != Config.UNSPECIFIED_PORT) { return new RunningTor(torDir, controlHost, controlPort, password, cookieFile, useSafeCookieAuthentication); - } - else { + } else { return new NewTor(torDir, torrcFile, torrcOptions, bridgeAddressProvider); } } diff --git a/p2p/src/main/java/haveno/network/p2p/network/TorNetworkNodeDirectBind.java b/p2p/src/main/java/haveno/network/p2p/network/TorNetworkNodeDirectBind.java index cb03dea7..8333af3f 100644 --- a/p2p/src/main/java/haveno/network/p2p/network/TorNetworkNodeDirectBind.java +++ b/p2p/src/main/java/haveno/network/p2p/network/TorNetworkNodeDirectBind.java @@ -31,7 +31,8 @@ public class TorNetworkNodeDirectBind extends TorNetworkNode { public TorNetworkNodeDirectBind(int servicePort, NetworkProtoResolver networkProtoResolver, @Nullable BanFilter banFilter, - int maxConnections, String hiddenServiceAddress) { + int maxConnections, + String hiddenServiceAddress) { super(servicePort, networkProtoResolver, banFilter, maxConnections); this.serviceAddress = hiddenServiceAddress; } @@ -39,7 +40,7 @@ public class TorNetworkNodeDirectBind extends TorNetworkNode { @Override public void shutDown(@Nullable Runnable shutDownCompleteHandler) { super.shutDown(() -> { - log.info("TorNetworkNode shutdown already completed"); + log.info("TorNetworkNodeDirectBind shutdown completed"); if (shutDownCompleteHandler != null) shutDownCompleteHandler.run(); }); } @@ -53,7 +54,7 @@ public class TorNetworkNodeDirectBind extends TorNetworkNode { @Override 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 { checkArgument(peerNodeAddress.getHostName().endsWith(".onion"), "PeerAddress is not an onion address"); Socket sock = new Socket(InetAddress.getLoopbackAddress(), TOR_DATA_PORT); @@ -93,7 +94,7 @@ public class TorNetworkNodeDirectBind extends TorNetworkNode { ServerSocket socket = new ServerSocket(servicePort); nodeAddressProperty.set(new NodeAddress(serviceAddress + ":" + servicePort)); log.info("\n################################################################\n" + - "Tor hidden service published: {} Port: {}\n" + + "Bound to Tor hidden service: {} Port: {}\n" + "################################################################", serviceAddress, servicePort); UserThread.execute(() -> setupListeners.forEach(SetupListener::onTorNodeReady)); diff --git a/p2p/src/main/java/haveno/network/p2p/network/TorNetworkNodeNetlayer.java b/p2p/src/main/java/haveno/network/p2p/network/TorNetworkNodeNetlayer.java index 30f7e5ca..b4d7e978 100644 --- a/p2p/src/main/java/haveno/network/p2p/network/TorNetworkNodeNetlayer.java +++ b/p2p/src/main/java/haveno/network/p2p/network/TorNetworkNodeNetlayer.java @@ -64,9 +64,9 @@ public class TorNetworkNodeNetlayer extends TorNetworkNode { @Override public void shutDown(@Nullable Runnable shutDownCompleteHandler) { - log.info("TorNetworkNode shutdown started"); + log.info("TorNetworkNodeNetlayer shutdown started"); if (shutDownComplete) { - log.info("TorNetworkNode shutdown already completed"); + log.info("TorNetworkNodeNetlayer shutdown already completed"); if (shutDownCompleteHandler != null) shutDownCompleteHandler.run(); return; } @@ -93,7 +93,7 @@ public class TorNetworkNodeNetlayer extends TorNetworkNode { } executor.shutdownNow(); } catch (Throwable e) { - log.error("Shutdown torNetworkNode failed with exception", e); + log.error("Shutdown TorNetworkNodeNetlayer failed with exception", e); } finally { shutDownTimeoutTimer.stop(); shutDownComplete = true;