Only show notification after three timeouts during handshake

This commit is contained in:
TebbeUbben 2019-02-17 22:01:01 +01:00
parent 5fb0fe62f4
commit 8f7a29bd7a

View file

@ -89,6 +89,7 @@ public class InsightConnectionService extends Service implements ConnectionEstab
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
private static final int BUFFER_SIZE = 1024; private static final int BUFFER_SIZE = 1024;
private static final int TIMEOUT_DURING_HANDSHAKE_NOTIFICATION_THRESHOLD = 3;
private static final long RESPONSE_TIMEOUT = 6000; private static final long RESPONSE_TIMEOUT = 6000;
private List<StateCallback> stateCallbacks = new ArrayList<>(); private List<StateCallback> stateCallbacks = new ArrayList<>();
@ -117,6 +118,7 @@ public class InsightConnectionService extends Service implements ConnectionEstab
private long lastDataTime; private long lastDataTime;
private long lastConnected; private long lastConnected;
private long recoveryDuration = 0; private long recoveryDuration = 0;
private int timeoutDuringHandshakeCounter;
KeyPair getKeyPair() { KeyPair getKeyPair() {
if (keyPair == null) keyPair = Cryptograph.generateRSAKey(); if (keyPair == null) keyPair = Cryptograph.generateRSAKey();
@ -274,6 +276,7 @@ public class InsightConnectionService extends Service implements ConnectionEstab
} }
if (state == InsightState.DISCONNECTED && pairingDataStorage.isPaired()) { if (state == InsightState.DISCONNECTED && pairingDataStorage.isPaired()) {
recoveryDuration = 0; recoveryDuration = 0;
timeoutDuringHandshakeCounter = 0;
connect(); connect();
} }
} }
@ -353,8 +356,10 @@ public class InsightConnectionService extends Service implements ConnectionEstab
log.info("Exception occurred: " + e.getClass().getSimpleName()); log.info("Exception occurred: " + e.getClass().getSimpleName());
if (pairingDataStorage.isPaired()) { if (pairingDataStorage.isPaired()) {
if (e instanceof TimeoutException && (state == InsightState.SATL_SYN_REQUEST || state == InsightState.APP_CONNECT_MESSAGE)) { if (e instanceof TimeoutException && (state == InsightState.SATL_SYN_REQUEST || state == InsightState.APP_CONNECT_MESSAGE)) {
for (StateCallback stateCallback : stateCallbacks) { if (++timeoutDuringHandshakeCounter == TIMEOUT_DURING_HANDSHAKE_NOTIFICATION_THRESHOLD) {
stateCallback.onTimeoutDuringHandshake(); for (StateCallback stateCallback : stateCallbacks) {
stateCallback.onTimeoutDuringHandshake();
}
} }
} }
setState(connectionRequests.size() != 0 ? InsightState.RECOVERING : InsightState.DISCONNECTED); setState(connectionRequests.size() != 0 ? InsightState.RECOVERING : InsightState.DISCONNECTED);