-
Notifications
You must be signed in to change notification settings - Fork 71
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 #1128 from alvasw/tor_implement_TestNetworkTorrcGe…
…neratorFactory Implement TestNetworkTorrcGeneratorFactory
- Loading branch information
Showing
12 changed files
with
165 additions
and
64 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
network/tor/common/src/main/java/bisq/network/tor/common/torrc/BaseTorrcGenerator.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,55 @@ | ||
/* | ||
* 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.network.tor.common.torrc; | ||
|
||
import lombok.Builder; | ||
|
||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Builder | ||
public class BaseTorrcGenerator implements TorrcConfigGenerator { | ||
public static final String DISABLE_NETWORK_CONFIG_KEY = "DisableNetwork"; | ||
|
||
private final Path dataDirPath; | ||
private final int controlPort; | ||
private final String hashedControlPassword; | ||
|
||
public BaseTorrcGenerator(Path dataDirPath, int controlPort, String hashedControlPassword) { | ||
this.dataDirPath = dataDirPath; | ||
this.controlPort = controlPort; | ||
this.hashedControlPassword = hashedControlPassword; | ||
} | ||
|
||
@Override | ||
public Map<String, String> generate() { | ||
Map<String, String> torConfigMap = new HashMap<>(); | ||
torConfigMap.put("DataDirectory", dataDirPath.toAbsolutePath().toString()); | ||
|
||
torConfigMap.put(DISABLE_NETWORK_CONFIG_KEY, "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", "0"); | ||
return torConfigMap; | ||
} | ||
} |
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
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
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
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
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
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
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
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
57 changes: 57 additions & 0 deletions
57
...-network/src/main/java/bisq/tor/local_network/torrc/TestNetworkTorrcGeneratorFactory.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,57 @@ | ||
/* | ||
* 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 bisq.network.tor.common.torrc.*; | ||
import bisq.tor.local_network.TorNode; | ||
|
||
public class TestNetworkTorrcGeneratorFactory { | ||
public static TorrcConfigGenerator directoryTorrcGenerator(TorNode directoryNode) { | ||
var testNetworkTorrcGenerator = testNetworkTorrcGenerator(directoryNode); | ||
return new DirectoryAuthorityTorrcGenerator(testNetworkTorrcGenerator, directoryNode.getNickname()); | ||
} | ||
|
||
public static TorrcConfigGenerator relayTorrcGenerator(TorNode relayNode) { | ||
var testNetworkTorrcGenerator = testNetworkTorrcGenerator(relayNode); | ||
return new RelayTorrcGenerator(testNetworkTorrcGenerator); | ||
} | ||
|
||
public static TorrcConfigGenerator clientTorrcGenerator(TorNode clientNode) { | ||
var testNetworkTorrcGenerator = testNetworkTorrcGenerator(clientNode); | ||
return new ClientTorrcGenerator(testNetworkTorrcGenerator); | ||
} | ||
|
||
private static TorrcConfigGenerator testNetworkTorrcGenerator(TorNode torNode) { | ||
return TestNetworkTorrcGenerator.builder() | ||
.baseTorrcConfigGenerator(baseTorrcGenerator(torNode)) | ||
.nickname(torNode.getNickname()) | ||
.orPort(torNode.getOrPort()) | ||
.dirPort(torNode.getDirPort()) | ||
.build(); | ||
} | ||
|
||
private static TorrcConfigGenerator baseTorrcGenerator(TorNode torNode) { | ||
return BaseTorrcGenerator.builder() | ||
.dataDirPath(torNode.getDataDir()) | ||
.controlPort(torNode.getControlPort()) | ||
.hashedControlPassword( | ||
torNode.getControlConnectionPassword() | ||
.getHashedPassword()) | ||
.build(); | ||
} | ||
} |
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
Oops, something went wrong.