Merge pull request #1637 from TebbeUbben/insight-dev
Improvement for timeout during handshake notification
This commit is contained in:
commit
58f4012323
|
@ -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,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);
|
||||||
|
|
Loading…
Reference in a new issue