Skip to content

Commit

Permalink
Merge pull request #1136 from alvasw/Pass_socksPort_in_constructor_to…
Browse files Browse the repository at this point in the history
…_ClientTorrcGenerator

Pass socksPort in constructor to ClientTorrcGenerator
alvasw authored Aug 20, 2023
2 parents 849fbeb + e3d045f commit 3366185
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -17,21 +17,24 @@

package bisq.network.tor.common.torrc;

import bisq.common.util.NetworkUtils;
import lombok.Builder;

import java.util.Map;

@Builder
public class ClientTorrcGenerator implements TorrcConfigGenerator {
private final TorrcConfigGenerator baseTorrcConfigGenerator;
private final int socksPort;

public ClientTorrcGenerator(TorrcConfigGenerator baseTorrcConfigGenerator) {
public ClientTorrcGenerator(TorrcConfigGenerator baseTorrcConfigGenerator, int socksPort) {
this.baseTorrcConfigGenerator = baseTorrcConfigGenerator;
this.socksPort = socksPort;
}

@Override
public Map<String, String> generate() {
Map<String, String> torConfigMap = baseTorrcConfigGenerator.generate();
torConfigMap.put("SocksPort", String.valueOf(NetworkUtils.findFreeSystemPort()));
torConfigMap.put("SocksPort", String.valueOf(socksPort));
return torConfigMap;
}
}
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@

package bisq.tor.local_network.torrc;

import bisq.common.util.NetworkUtils;
import bisq.network.tor.common.torrc.*;
import bisq.tor.local_network.TorNode;

@@ -33,7 +34,10 @@ public static TorrcConfigGenerator relayTorrcGenerator(TorNode relayNode) {

public static TorrcConfigGenerator clientTorrcGenerator(TorNode clientNode) {
var testNetworkTorrcGenerator = testNetworkTorrcGenerator(clientNode);
return new ClientTorrcGenerator(testNetworkTorrcGenerator);
return ClientTorrcGenerator.builder()
.baseTorrcConfigGenerator(testNetworkTorrcGenerator)
.socksPort(NetworkUtils.findFreeSystemPort())
.build();
}

private static TorrcConfigGenerator testNetworkTorrcGenerator(TorNode torNode) {

0 comments on commit 3366185

Please sign in to comment.