Skip to content

Commit

Permalink
Merge pull request #1164 from alvasw/tor_fix
Browse files Browse the repository at this point in the history
Fix multiple TorService creations
  • Loading branch information
alvasw authored Sep 7, 2023
2 parents ff53a9a + bcfb2ba commit 882e2a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
public class TorTransport implements Transport {
public final static int DEFAULT_PORT = 9999;

private final TorService torService;
private static TorService torService;

public TorTransport(TransportConfig config) {
torService = new TorService((TorTransportConfig) config);
if (torService == null) {
torService = new TorService((TorTransportConfig) config);
}
}

@Override
Expand Down
8 changes: 8 additions & 0 deletions network/tor/tor/src/main/java/bisq/tor/TorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;

@Slf4j
public class TorService implements Service {
Expand All @@ -49,6 +50,8 @@ public class TorService implements Service {
private final NativeTorController nativeTorController = new NativeTorController();
private final OnionServicePublishService onionServicePublishService;

private final AtomicBoolean isRunning = new AtomicBoolean();

private Optional<NativeTorProcess> torProcess = Optional.empty();
private Optional<Integer> socksPort = Optional.empty();
private Optional<TorSocksProxyFactory> torSocksProxyFactory = Optional.empty();
Expand All @@ -61,6 +64,11 @@ public TorService(TorTransportConfig transportConfig) {

@Override
public CompletableFuture<Boolean> initialize() {
boolean isAlreadyRunning = isRunning.getAndSet(true);
if (isAlreadyRunning) {
return CompletableFuture.completedFuture(true);
}

installTorIfNotUpToDate();

int controlPort = NetworkUtils.findFreeSystemPort();
Expand Down

0 comments on commit 882e2a9

Please sign in to comment.