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(); + } } 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) {