Shut down if more then 1 all connections lost events

This commit is contained in:
chimp1984 2020-11-10 14:32:16 -05:00
parent 1b7c1ce49a
commit 2486bd512f
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3

View File

@ -22,7 +22,9 @@ import bisq.core.app.misc.ModuleForAppWithP2p;
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;
@ -33,8 +35,10 @@ import lombok.extern.slf4j.Slf4j;
@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);
@ -126,6 +130,7 @@ public class SeedNodeMain extends ExecutableForAppWithP2p {
@Override
public void onHiddenServicePublished() {
startShutDownInterval(SeedNodeMain.this);
UserThread.runAfter(() -> setupConnectionLossCheck(), 60);
}
@Override
@ -140,6 +145,19 @@ public class SeedNodeMain extends ExecutableForAppWithP2p {
});
}
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();