Merge pull request #1637 from TebbeUbben/insight-dev
Improvement for timeout during handshake notification
This commit is contained in:
commit
58f4012323
2 changed files with 11 additions and 4 deletions
|
@ -1535,8 +1535,10 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStateChanged(InsightState state) {
|
public void onStateChanged(InsightState state) {
|
||||||
if (state == InsightState.CONNECTED) statusLoaded = false;
|
if (state == InsightState.CONNECTED) {
|
||||||
else if (state == InsightState.NOT_PAIRED) {
|
statusLoaded = false;
|
||||||
|
new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventDismissNotification(Notification.INSIGHT_TIMEOUT_DURING_HANDSHAKE)));
|
||||||
|
} else if (state == InsightState.NOT_PAIRED) {
|
||||||
connectionService.withdrawConnectionRequest(this);
|
connectionService.withdrawConnectionRequest(this);
|
||||||
statusLoaded = false;
|
statusLoaded = false;
|
||||||
profileBlocks = null;
|
profileBlocks = null;
|
||||||
|
|
|
@ -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,10 +356,12 @@ 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)) {
|
||||||
|
if (++timeoutDuringHandshakeCounter == TIMEOUT_DURING_HANDSHAKE_NOTIFICATION_THRESHOLD) {
|
||||||
for (StateCallback stateCallback : stateCallbacks) {
|
for (StateCallback stateCallback : stateCallbacks) {
|
||||||
stateCallback.onTimeoutDuringHandshake();
|
stateCallback.onTimeoutDuringHandshake();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
setState(connectionRequests.size() != 0 ? InsightState.RECOVERING : InsightState.DISCONNECTED);
|
setState(connectionRequests.size() != 0 ? InsightState.RECOVERING : InsightState.DISCONNECTED);
|
||||||
if (e instanceof ConnectionFailedException) {
|
if (e instanceof ConnectionFailedException) {
|
||||||
cleanup(((ConnectionFailedException) e).getDurationOfConnectionAttempt() <= 1000);
|
cleanup(((ConnectionFailedException) e).getDurationOfConnectionAttempt() <= 1000);
|
||||||
|
|
Loading…
Reference in a new issue