Skip to content

Commit

Permalink
Merge pull request #5070 from chimp1984/improve-cleanup-tor-dir-at-seeds
Browse files Browse the repository at this point in the history
Improve cleanup tor dir at seeds
  • Loading branch information
sqrrm authored Jan 12, 2021
2 parents fea52f0 + 8ecfa8b commit 4298c39
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@Getter
public class RequestInfo {
// Carries latest commit hash of feature changes (not latest commit as that is then the commit for editing that field)
public static final String COMMIT_HASH = "1c50cb6c";
public static final String COMMIT_HASH = "c07d47a8";

private final long requestStartTime;
@Setter
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/bisq/core/user/CookieKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public enum CookieKey {
STAGE_Y,
STAGE_W,
STAGE_H,
TRADE_STAT_CHART_USE_USD
TRADE_STAT_CHART_USE_USD,
CLEAN_TOR_DIR_AT_RESTART
}
22 changes: 17 additions & 5 deletions seednode/src/main/java/bisq/seednode/SeedNodeMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import bisq.core.app.misc.ExecutableForAppWithP2p;
import bisq.core.app.misc.ModuleForAppWithP2p;
import bisq.core.dao.state.DaoStateSnapshotService;
import bisq.core.user.Cookie;
import bisq.core.user.CookieKey;
import bisq.core.user.User;

import bisq.network.p2p.P2PService;
import bisq.network.p2p.P2PServiceListener;
Expand Down Expand Up @@ -112,6 +115,16 @@ protected void applyInjector() {

@Override
protected void startApplication() {
Cookie cookie = injector.getInstance(User.class).getCookie();
cookie.getAsOptionalBoolean(CookieKey.CLEAN_TOR_DIR_AT_RESTART).ifPresent(wasCleanTorDirSet -> {
if (wasCleanTorDirSet) {
injector.getInstance(TorSetup.class).cleanupTorFiles(() -> {
log.info("Tor directory reset");
cookie.remove(CookieKey.CLEAN_TOR_DIR_AT_RESTART);
}, log::error);
}
});

seedNode.startApplication();

injector.getInstance(P2PService.class).addP2PServiceListener(new P2PServiceListener() {
Expand Down Expand Up @@ -175,11 +188,10 @@ private void setupConnectionLossCheck() {

checkConnectionLossTime = UserThread.runPeriodically(() -> {
if (injector.getInstance(PeerManager.class).getNumAllConnectionsLostEvents() > 1) {
// Removing cache files help in case the node got flagged from Tor's dos protection
injector.getInstance(TorSetup.class).cleanupTorFiles(() -> {
log.info("Tor directory reset");
shutDown(this);
}, log::error);
// We set a flag to clear tor cache files at re-start. We cannot clear it now as Tor is used and
// that can cause problems.
injector.getInstance(User.class).getCookie().putAsBoolean(CookieKey.CLEAN_TOR_DIR_AT_RESTART, true);
shutDown(this);
}
}, CHECK_CONNECTION_LOSS_SEC);

Expand Down

0 comments on commit 4298c39

Please sign in to comment.