summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-09-20 12:01:43 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-09-20 12:01:43 -0300
commit43b9f42fa4f00892850bd3f793717d61d1e20e68 (patch)
treee9737c9c3583abc686ae3e750ec596d971b571ad
parent510fe266c62d401c1a36d3b18388bf84d32bd50c (diff)
parent258a34d4c6d06e31c61449cfcb5502f56f9d3f9b (diff)
downloadmullvadvpn-43b9f42fa4f00892850bd3f793717d61d1e20e68.tar.xz
mullvadvpn-43b9f42fa4f00892850bd3f793717d61d1e20e68.zip
Merge branch 'relay-list-polling'
-rw-r--r--CHANGELOG.md1
-rw-r--r--gui/packages/desktop/src/renderer/app.js57
2 files changed, 49 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 434f8d1da6..1859e343d5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -35,6 +35,7 @@ Line wrap the file at 100 chars. Th
### Fixed
- Don't temporarily show the unsecured state in the GUI when the app is reconnecting or blocking.
+- Periodically update list of relays in the GUI.
## [2018.3] - 2018-09-17
diff --git a/gui/packages/desktop/src/renderer/app.js b/gui/packages/desktop/src/renderer/app.js
index a99fbc3fed..fe38ab21d6 100644
--- a/gui/packages/desktop/src/renderer/app.js
+++ b/gui/packages/desktop/src/renderer/app.js
@@ -34,6 +34,7 @@ import type {
AccountToken,
Settings,
TunnelStateTransition,
+ RelayList,
RelaySettingsUpdate,
RelaySettings,
TunnelState,
@@ -43,6 +44,8 @@ import type {
import type { ReduxStore } from './redux/store';
import type { TrayIconType } from '../main/tray-icon-controller';
+const RELAY_LIST_UPDATE_INTERVAL = 60 * 60 * 1000;
+
export default class AppRenderer {
_notificationController = new NotificationController();
_daemonRpc: DaemonRpcProtocol = new DaemonRpc();
@@ -61,6 +64,14 @@ export default class AppRenderer {
_accountDataCache = new AccountDataCache((accountToken) => {
return this._daemonRpc.getAccountData(accountToken);
});
+ _relayListCache = new RelayListCache(
+ () => {
+ return this._daemonRpc.getRelayLocations();
+ },
+ (relayList) => {
+ this._updateRelayLocations(relayList);
+ },
+ );
_tunnelStateProxy = new TunnelStateProxy(this._daemonRpc, (tunnelState) => {
this._setTunnelState(tunnelState);
});
@@ -297,13 +308,12 @@ export default class AppRenderer {
actions.account.updateAccountHistory(accountHistory);
}
- async _fetchRelayLocations() {
+ _updateRelayLocations(relayList: RelayList) {
const actions = this._reduxActions;
- const locations = await this._daemonRpc.getRelayLocations();
log.info('Got relay locations');
- const storedLocations = locations.countries.map((country) => ({
+ const locations = relayList.countries.map((country) => ({
name: country.name,
code: country.code,
hasActiveRelays: country.cities.some((city) => city.relays.length > 0),
@@ -317,7 +327,7 @@ export default class AppRenderer {
})),
}));
- actions.settings.updateRelayLocations(storedLocations);
+ actions.settings.updateRelayLocations(locations);
}
async _fetchLocation() {
@@ -404,11 +414,7 @@ export default class AppRenderer {
log.error(`Cannot fetch the current version: ${error.message}`);
}
- try {
- await this._fetchRelayLocations();
- } catch (error) {
- log.error(`Cannot fetch the relay locations: ${error.message}`);
- }
+ this._relayListCache.startUpdating();
try {
await this._fetchAccountHistory();
@@ -500,6 +506,8 @@ export default class AppRenderer {
_onCloseConnection(error: ?Error) {
const actions = this._reduxActions;
+ this._relayListCache.stopUpdating();
+
// recover connection on error
if (error) {
log.debug(`Lost connection to daemon: ${error.message}`);
@@ -664,6 +672,37 @@ class AccountDataCache {
}
}
+class RelayListCache {
+ _fetch: () => Promise<RelayList>;
+ _listener: (RelayList) => void;
+ _updateTimer: ?IntervalID = null;
+
+ constructor(fetch: () => Promise<RelayList>, listener: (RelayList) => void) {
+ this._fetch = fetch;
+ this._listener = listener;
+ }
+
+ startUpdating() {
+ this.stopUpdating();
+ this._updateTimer = setInterval(() => this._update(), RELAY_LIST_UPDATE_INTERVAL);
+ this._update();
+ }
+
+ stopUpdating() {
+ if (this._updateTimer) {
+ clearInterval(this._updateTimer);
+ }
+ }
+
+ async _update() {
+ try {
+ this._listener(await this._fetch());
+ } catch (error) {
+ log.error(`Cannot fetch the relay locations: ${error.message}`);
+ }
+ }
+}
+
function getIpcPath(): string {
if (process.platform === 'win32') {
return '//./pipe/Mullvad VPN';