Skip to content

Commit

Permalink
Merge pull request #1048 from alvasw/tor_create_production_torrc_config
Browse files Browse the repository at this point in the history
Tor: Create production torrc generator
  • Loading branch information
alvasw authored Jul 30, 2023
2 parents 813c427 + d5d0266 commit 53bb78b
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.tor.local_network.torrc;

import java.nio.file.Path;
import java.util.Map;

public class OverridingTorrcGenerator implements TorrcConfigGenerator {
private final CommonTorrcGenerator template;
private final Map<String, String> clientTorrcConfig;

public OverridingTorrcGenerator(CommonTorrcGenerator template, Map<String, String> clientTorrcConfig) {
this.template = template;
this.clientTorrcConfig = clientTorrcConfig;
}

@Override
public Map<String, String> generate() {
Map<String, String> torrcConfigs = template.generate();
torrcConfigs.putAll(clientTorrcConfig);
return torrcConfigs;
}

public Path getTorrcPath() {
return template.getThisTorNode().getTorrcPath();
}
}
54 changes: 54 additions & 0 deletions network/tor/src/main/java/bisq/tor/ClientTorrcGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.tor;

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

import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;

@Getter
public class ClientTorrcGenerator {
private final Path dataDirPath;
private final int controlPort;
private final String hashedControlPassword;
protected final Map<String, String> torConfigMap = new HashMap<>();

public ClientTorrcGenerator(Path dataDirPath, int controlPort, String hashedControlPassword) {
this.dataDirPath = dataDirPath;
this.controlPort = controlPort;
this.hashedControlPassword = hashedControlPassword;
}

public Map<String, String> generate() {
torConfigMap.put("DataDirectory", dataDirPath.toAbsolutePath().toString());
torConfigMap.put("RunAsDaemon", "1");

torConfigMap.put("ControlPort", "127.0.0.1:" + controlPort);
torConfigMap.put("HashedControlPassword", hashedControlPassword);
torConfigMap.put("Log",
"debug file " + dataDirPath.resolve("debug.log").toAbsolutePath()
);

torConfigMap.put("SocksPort", String.valueOf(NetworkUtils.findFreeSystemPort()));

return torConfigMap;
}
}

0 comments on commit 53bb78b

Please sign in to comment.