Merge pull request #1637 from TebbeUbben/insight-dev

Improvement for timeout during handshake notification
This commit is contained in:
AdrianLxM 2019-02-17 22:21:14 +01:00 committed by GitHub
commit 58f4012323
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View file

@ -1535,8 +1535,10 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
@Override
public void onStateChanged(InsightState state) {
if (state == InsightState.CONNECTED) statusLoaded = false;
else if (state == InsightState.NOT_PAIRED) {
if (state == InsightState.CONNECTED) {
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);
statusLoaded = false;
profileBlocks = null;

View file

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