diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2019-09-12 13:55:48 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2019-09-13 11:29:04 +0200 |
| commit | 4c5cc66fe0fc59d399225b7f2eff199785f94fa1 (patch) | |
| tree | 2f01b083434af6d9bb70fe9de1de94a85e9bd4d7 /gui/src/main | |
| parent | d3238497e9485f2ebc56d7ca5efc44be5b9eb68e (diff) | |
| download | mullvadvpn-4c5cc66fe0fc59d399225b7f2eff199785f94fa1.tar.xz mullvadvpn-4c5cc66fe0fc59d399225b7f2eff199785f94fa1.zip | |
Migrate UI to use the new "active" flag in the relay list v3 schema
Diffstat (limited to 'gui/src/main')
| -rw-r--r-- | gui/src/main/daemon-rpc.ts | 1 | ||||
| -rw-r--r-- | gui/src/main/index.ts | 62 |
2 files changed, 33 insertions, 30 deletions
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts index 25f0d32748..1ce4450af3 100644 --- a/gui/src/main/daemon-rpc.ts +++ b/gui/src/main/daemon-rpc.ts @@ -137,6 +137,7 @@ const relayListSchema = partialObject({ hostname: string, ipv4_addr_in: string, include_in_country: boolean, + active: boolean, weight: number, bridges: maybe( partialObject({ diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index ac583f4300..05edd6af6c 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -13,10 +13,10 @@ import { IAppVersionInfo, ILocation, IRelayList, - IRelayListHostname, ISettings, IWireguardPublicKey, KeygenEvent, + liftConstraint, RelayLocation, RelaySettings, RelaySettingsUpdate, @@ -663,42 +663,44 @@ class ApplicationMain { 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 => { - if (relay.tunnels) { - return relay.tunnels.openvpn.length > 0; - } else { - return false; - } - }; - const hasWireguardTunnels = (relay: IRelayListHostname): boolean => { - if (relay.tunnels) { - return relay.tunnels.wireguard.length > 0; - } else { - return false; - } - }; - let fnHasWantedTunnels = hasOpenVpnTunnels; + const tunnelProtocol = + 'normal' in relaySettings ? liftConstraint(relaySettings.normal.tunnelProtocol) : undefined; - if ('normal' in relaySettings) { - const tunnelConstraints = relaySettings.normal.tunnelProtocol; - if (tunnelConstraints !== 'any' && 'wireguard' === tunnelConstraints.only) { - fnHasWantedTunnels = hasWireguardTunnels; - } - } - - return { - countries: relayList.countries.map((country) => ({ + const filteredCountries = relayList.countries + .map((country) => ({ ...country, cities: country.cities .map((city) => ({ ...city, - relays: city.relays.filter(fnHasWantedTunnels), + relays: city.relays.filter((relay) => { + if (relay.tunnels) { + switch (tunnelProtocol) { + case 'openvpn': + return relay.tunnels.openvpn.length > 0; + + case 'wireguard': + return relay.tunnels.wireguard.length > 0; + + case 'any': + // 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. + return relay.tunnels.openvpn.length > 0; + + default: + return false; + } + } else { + return false; + } + }), })) .filter((city) => city.relays.length > 0), - })), + })) + .filter((country) => country.cities.length > 0); + + return { + countries: filteredCountries, }; } |
