Skip to content

Commit

Permalink
Shut down if more then 1 all connections lost events
Browse files Browse the repository at this point in the history
  • Loading branch information
chimp1984 committed Nov 10, 2020
1 parent 0a7a7d9 commit 1a1618d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions seednode/src/main/java/bisq/seednode/SeedNodeMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

import bisq.network.p2p.P2PService;
import bisq.network.p2p.P2PServiceListener;
import bisq.network.p2p.peers.PeerManager;

import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.app.AppModule;
import bisq.common.app.Capabilities;
Expand All @@ -33,8 +35,10 @@

@Slf4j
public class SeedNodeMain extends ExecutableForAppWithP2p {
private static final long CHECK_CONNECTION_LOSS_SEC = 30;
private static final String VERSION = "1.4.2";
private SeedNode seedNode;
private Timer checkConnectionLossTime;

public SeedNodeMain() {
super("Bisq Seednode", "bisq-seednode", "bisq_seednode", VERSION);
Expand Down Expand Up @@ -126,6 +130,7 @@ public void onTorNodeReady() {
@Override
public void onHiddenServicePublished() {
startShutDownInterval(SeedNodeMain.this);
UserThread.runAfter(() -> setupConnectionLossCheck(), 60);
}

@Override
Expand All @@ -140,6 +145,19 @@ public void onRequestCustomBridges() {
});
}

private void setupConnectionLossCheck() {
if (checkConnectionLossTime != null) {
return;
}

checkConnectionLossTime = UserThread.runPeriodically(() -> {
if (injector.getInstance(PeerManager.class).getNumAllConnectionsLostEvents() > 1) {
shutDown(this);
}
}, CHECK_CONNECTION_LOSS_SEC);

}

@Override
public void gracefulShutDown(ResultHandler resultHandler) {
seedNode.shutDown();
Expand Down

0 comments on commit 1a1618d

Please sign in to comment.