Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TorNode.Type enum #977

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void generateKeys(@TempDir Path dataDir) throws IOException, InterruptedE
.isTrue();

var directoryAuthority = TorNode.builder()
.type(TorNode.Type.DIRECTORY_AUTHORITY)
.nickname("Nick")
.dataDir(dataDir)
.controlPort(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class DirectoryAuthorityTests {
@Test
public void createOneDA(@TempDir Path tempDir) throws IOException, InterruptedException {
var firstDirectoryAuthority = TorNode.builder()
.type(TorNode.Type.DIRECTORY_AUTHORITY)
.nickname("DA_1")
.dataDir(tempDir)
.controlPort(NetworkUtils.findFreeSystemPort())
Expand All @@ -54,6 +55,7 @@ public void createThreeDA(@TempDir Path tempDir) throws IOException, Interrupted

Path firstDaDataDir = tempDir.resolve("da_1");
var firstDirectoryAuthority = TorNode.builder()
.type(TorNode.Type.DIRECTORY_AUTHORITY)
.nickname("DA_1")
.dataDir(firstDaDataDir)
.controlPort(NetworkUtils.findFreeSystemPort())
Expand All @@ -64,6 +66,7 @@ public void createThreeDA(@TempDir Path tempDir) throws IOException, Interrupted

Path secondDaDataDir = tempDir.resolve("da_2");
var secondDirectoryAuthority = TorNode.builder()
.type(TorNode.Type.DIRECTORY_AUTHORITY)
.nickname("DA_2")
.dataDir(secondDaDataDir)
.controlPort(NetworkUtils.findFreeSystemPort())
Expand All @@ -74,6 +77,7 @@ public void createThreeDA(@TempDir Path tempDir) throws IOException, Interrupted

Path thirdDaDataDir = tempDir.resolve("da_3");
var thirdDirectoryAuthority = TorNode.builder()
.type(TorNode.Type.DIRECTORY_AUTHORITY)
.nickname("DA_3")
.dataDir(thirdDaDataDir)
.controlPort(NetworkUtils.findFreeSystemPort())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@

@Getter
public class TorNode {

public enum Type {
DIRECTORY_AUTHORITY,
RELAY
}

private final Type type;
private final String nickname;

private final Path dataDir;
Expand All @@ -47,7 +54,8 @@ public class TorNode {
private Optional<String> relayKeyFingerprint = Optional.empty();

@Builder
public TorNode(String nickname, Path dataDir, int controlPort, int orPort, int dirPort) {
public TorNode(Type type, String nickname, Path dataDir, int controlPort, int orPort, int dirPort) {
this.type = type;
this.nickname = nickname;
this.dataDir = dataDir;
this.controlPort = controlPort;
Expand All @@ -61,6 +69,10 @@ public Path getTorrcPath() {
}

public Optional<String> getIdentityKeyFingerprint() {
if (type != Type.DIRECTORY_AUTHORITY) {
return Optional.empty();
}

if (identityKeyFingerprint.isPresent()) {
return identityKeyFingerprint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void basicTest(@TempDir Path tempDir) throws IOException {

TorNode firstDirAuth = spy(
TorNode.builder()
.type(TorNode.Type.DIRECTORY_AUTHORITY)
.nickname("A")
.dataDir(daAPath)

Expand All @@ -59,6 +60,7 @@ void basicTest(@TempDir Path tempDir) throws IOException {

TorNode secondDirAuth = spy(
TorNode.builder()
.type(TorNode.Type.DIRECTORY_AUTHORITY)
.nickname("B")
.dataDir(tempDir.resolve("DA_B"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void basicTest(@TempDir Path tempDir) throws IOException {

TorNode firstDirAuth = spy(
TorNode.builder()
.type(TorNode.Type.RELAY)
.nickname("A")
.dataDir(daAPath)

Expand All @@ -59,6 +60,7 @@ void basicTest(@TempDir Path tempDir) throws IOException {

TorNode secondDirAuth = spy(
TorNode.builder()
.type(TorNode.Type.RELAY)
.nickname("B")
.dataDir(tempDir.resolve("DA_B"))

Expand Down