summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmīls Piņķis <emils@mullvad.net>2019-03-08 12:34:18 +0000
committerEmīls Piņķis <emils@mullvad.net>2019-03-08 13:40:28 +0000
commitb7e4c64b244382c2134fc00a754f0d39cdc65a53 (patch)
tree9a87e82c8f6f6cc483379969267bcb00729ef471
parent8c2c91d891455db4159c1a5629e9c1d95f4dd679 (diff)
downloadmullvadvpn-b7e4c64b244382c2134fc00a754f0d39cdc65a53.tar.xz
mullvadvpn-b7e4c64b244382c2134fc00a754f0d39cdc65a53.zip
Filter out relay list in UI depending on relay constraints
-rw-r--r--gui/src/main/index.ts54
1 files changed, 50 insertions, 4 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index 6bf46b2bdd..87bd2d8165 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -10,7 +10,9 @@ import {
IAppVersionInfo,
ILocation,
IRelayList,
+ IRelayListHostname,
ISettings,
+ RelaySettings,
RelaySettingsUpdate,
TunnelStateTransition,
} from '../shared/daemon-rpc-types';
@@ -375,7 +377,7 @@ class ApplicationMain {
// fetch relays
try {
- this.setRelays(await this.daemonRpc.getRelayLocations());
+ this.setRelays(await this.daemonRpc.getRelayLocations(), this.settings.relaySettings);
} catch (error) {
log.error(`Failed to fetch relay locations: ${error.message}`);
@@ -529,6 +531,10 @@ class ApplicationMain {
if (this.windowController) {
IpcMainEventChannel.settings.notify(this.windowController.webContents, newSettings);
}
+
+ // since settings can have the relay constraints changed, the relay
+ // list should also be updated
+ this.setRelays(this.relays, newSettings.relaySettings);
}
private setLocation(newLocation: ILocation) {
@@ -539,20 +545,60 @@ class ApplicationMain {
}
}
- private setRelays(newRelayList: IRelayList) {
+ private setRelays(newRelayList: IRelayList, relaySettings: RelaySettings) {
this.relays = newRelayList;
+ const filteredRelays = this.processRelaysForPresentation(newRelayList, relaySettings);
if (this.windowController) {
- IpcMainEventChannel.relays.notify(this.windowController.webContents, newRelayList);
+ IpcMainEventChannel.relays.notify(this.windowController.webContents, filteredRelays);
}
}
+ //
+ private processRelaysForPresentation(
+ relayList: IRelayList,
+ relaySettings: RelaySettings,
+ ): IRelayList {
+ // TODO: once wireguard is stable, by default we should only filter by
+ // hasToHaveOpenvpn || hasToHaveWg, until then, only filter wireguard
+ // relays if tunnel constraints specify wireguard tunnels.
+ const hasOpenVpnTunnels = (relay: IRelayListHostname): boolean => {
+ return relay.tunnels.openvpn.length > 0;
+ };
+ const hasWireguardTunnels = (relay: IRelayListHostname): boolean =>
+ relay.tunnels.wireguard.length > 0;
+ let fnHasWantedTunnels = hasOpenVpnTunnels;
+
+ if ('normal' in relaySettings) {
+ const tunnelConstraints = relaySettings.normal.tunnel;
+ if (tunnelConstraints !== 'any' && 'wireguard' in tunnelConstraints.only) {
+ fnHasWantedTunnels = hasWireguardTunnels;
+ }
+ }
+
+ return {
+ countries: relayList.countries.map((country) => {
+ return {
+ ...country,
+ cities: country.cities
+ .map((city) => {
+ return {
+ ...city,
+ relays: city.relays.filter(fnHasWantedTunnels),
+ };
+ })
+ .filter((city) => city.relays.length > 0),
+ };
+ }),
+ };
+ }
+
private startRelaysPeriodicUpdates() {
log.debug('Start relays periodic updates');
const handler = async () => {
try {
- this.setRelays(await this.daemonRpc.getRelayLocations());
+ this.setRelays(await this.daemonRpc.getRelayLocations(), this.settings.relaySettings);
} catch (error) {
log.error(`Failed to fetch relay locations: ${error.message}`);
}