-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1048 from alvasw/tor_create_production_torrc_config
Tor: Create production torrc generator
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...or-local-network/src/main/java/bisq/tor/local_network/torrc/OverridingTorrcGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
54
network/tor/src/main/java/bisq/tor/ClientTorrcGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |