Skip to content

Commit

Permalink
Added a settling period (#2311)
Browse files Browse the repository at this point in the history
I would have made this a state, but since the controller is tied to the UI, it made things difficult.  This works as well and is probably simpler.  Basic flag and timer when we connect and disconnect to ignore errors while the routes and interface become stable.
  • Loading branch information
mkestler-rtp authored Nov 18, 2021
1 parent bc988a8 commit 5a21a2e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
# include "platforms/dummy/dummycontroller.h"
#endif

constexpr auto SETTLE_TIMEOUT = 3000;

constexpr const uint32_t TIMER_MSEC = 1000;

// X connection retries.
Expand Down Expand Up @@ -367,6 +369,9 @@ void Controller::connectionConfirmed() {
}

setState(StateOn);

startUnsettledPeriod();

emit timeChanged();

if (m_nextStep != None) {
Expand Down Expand Up @@ -403,6 +408,8 @@ void Controller::connectionFailed() {
m_impl->deactivate(ControllerImpl::ReasonConfirming);
}

bool Controller::isUnsettled() { return !m_settled; }

void Controller::disconnected() {
logger.debug() << "Disconnected from state:" << m_state;

Expand All @@ -421,6 +428,8 @@ void Controller::disconnected() {
return;
}

startUnsettledPeriod();

m_timer.stop();
resetConnectionCheck();

Expand Down Expand Up @@ -778,6 +787,16 @@ void Controller::resetConnectedTime() {
m_connectedTimeInUTC = QDateTime::currentDateTimeUtc();
}

void Controller::startUnsettledPeriod() {
logger.debug() << "Starting unsettled period.";
m_settled = false;
m_settleTimer.stop();
m_settleTimer.singleShot(SETTLE_TIMEOUT, [this]() {
m_settled = true;
logger.debug() << "Unsettled period over.";
});
}

QString Controller::currentLocalizedCityName() const {
return ServerI18N::translateCityName(m_currentCountryCode, m_currentCity);
}
Expand Down
7 changes: 7 additions & 0 deletions src/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class Controller final : public QObject {

void backendFailure();

bool isUnsettled();

public slots:
// These 2 methods activate/deactivate the VPN. Return true if a signal will
// be emitted at the end of the operation.
Expand Down Expand Up @@ -136,10 +138,15 @@ class Controller final : public QObject {

void resetConnectedTime();

void startUnsettledPeriod();

private:
State m_state = StateInitializing;

QTimer m_timer;
QTimer m_settleTimer;

bool m_settled = true;

QDateTime m_connectedTimeInUTC;

Expand Down
3 changes: 3 additions & 0 deletions src/mozillavpn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,9 @@ void MozillaVPN::errorHandle(ErrorHandler::ErrorType error) {
break;

case ErrorHandler::NoConnectionError:
if (controller()->isUnsettled()) {
return;
}
alert = NoConnectionAlert;
break;

Expand Down

0 comments on commit 5a21a2e

Please sign in to comment.