From 37f22f53e0fcc05c0d6f8b1bd4752dbdd958fbbe Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Fri, 18 Aug 2023 12:14:23 +0200 Subject: [PATCH 1/2] tor: Create testnet when argument was passed --- .../bisq/tor/TorrcClientConfigFactory.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/network/tor/tor/src/main/java/bisq/tor/TorrcClientConfigFactory.java b/network/tor/tor/src/main/java/bisq/tor/TorrcClientConfigFactory.java index caf030e9b2..f1fe8f0812 100644 --- a/network/tor/tor/src/main/java/bisq/tor/TorrcClientConfigFactory.java +++ b/network/tor/tor/src/main/java/bisq/tor/TorrcClientConfigFactory.java @@ -19,6 +19,7 @@ import bisq.network.tor.common.torrc.BaseTorrcGenerator; import bisq.network.tor.common.torrc.ClientTorrcGenerator; +import bisq.network.tor.common.torrc.TestNetworkTorrcGenerator; import bisq.network.tor.common.torrc.TorrcConfigGenerator; import lombok.Builder; import net.freehaven.tor.control.PasswordDigest; @@ -30,12 +31,18 @@ public class TorrcClientConfigFactory { public static final String DISABLE_NETWORK_CONFIG_KEY = "DisableNetwork"; + private final boolean isTestNetwork; private final Path dataDir; private final int controlPort; private final int socksPort; private final PasswordDigest hashedControlPassword; - public TorrcClientConfigFactory(Path dataDir, int controlPort, int socksPort, PasswordDigest hashedControlPassword) { + public TorrcClientConfigFactory(boolean isTestNetwork, + Path dataDir, + int controlPort, + int socksPort, + PasswordDigest hashedControlPassword) { + this.isTestNetwork = isTestNetwork; this.dataDir = dataDir; this.controlPort = controlPort; this.socksPort = socksPort; @@ -50,8 +57,13 @@ public Map torrcClientConfigMap(Map torrcOverrid } private TorrcConfigGenerator clientTorrcGenerator() { + TorrcConfigGenerator baseTorrcGenerator = baseTorrcGenerator(); + if (isTestNetwork) { + baseTorrcGenerator = testNetworkTorrcGenerator(baseTorrcGenerator); + } + return ClientTorrcGenerator.builder() - .baseTorrcConfigGenerator(baseTorrcGenerator()) + .baseTorrcConfigGenerator(baseTorrcGenerator) .socksPort(socksPort) .build(); } @@ -63,4 +75,10 @@ private TorrcConfigGenerator baseTorrcGenerator() { .hashedControlPassword(hashedControlPassword.getHashedPassword()) .build(); } + + private static TorrcConfigGenerator testNetworkTorrcGenerator(TorrcConfigGenerator baseTorrcGenerator) { + return TestNetworkTorrcGenerator.builder() + .baseTorrcConfigGenerator(baseTorrcGenerator) + .build(); + } } From d64fa82a3673d7544d64f143f30cd5a69f36c148 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Fri, 18 Aug 2023 12:58:54 +0200 Subject: [PATCH 2/2] TorrcFileGenerator: Add customDirectoryAuthorities support --- .../main/java/bisq/tor/TorrcFileGenerator.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/network/tor/tor/src/main/java/bisq/tor/TorrcFileGenerator.java b/network/tor/tor/src/main/java/bisq/tor/TorrcFileGenerator.java index 4ebf8a91bc..5d939257d8 100644 --- a/network/tor/tor/src/main/java/bisq/tor/TorrcFileGenerator.java +++ b/network/tor/tor/src/main/java/bisq/tor/TorrcFileGenerator.java @@ -21,14 +21,19 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; +import java.util.Set; public class TorrcFileGenerator { private final Path torrcPath; private final Map torrcConfigMap; + private final Set customDirectoryAuthorities; - public TorrcFileGenerator(Path torrcPath, Map torrcConfigMap) { + public TorrcFileGenerator(Path torrcPath, + Map torrcConfigMap, + Set customDirectoryAuthorities) { this.torrcPath = torrcPath; this.torrcConfigMap = torrcConfigMap; + this.customDirectoryAuthorities = customDirectoryAuthorities; } public void generate() { @@ -40,6 +45,14 @@ public void generate() { .append("\n") ); + customDirectoryAuthorities.forEach(dirAuthority -> + torrcStringBuilder.append("DirAuthority ").append(dirAuthority.getNickname()) + .append(" orport=").append(dirAuthority.getOrPort()) + .append(" v3ident=").append(dirAuthority.getV3Ident()) + .append(" 127.0.0.1:").append(dirAuthority.getDirPort()) + .append(" ").append(dirAuthority.getRelayFingerprint()) + .append("\n")); + try { Files.writeString(torrcPath, torrcStringBuilder.toString()); } catch (IOException e) {