diff options
| author | Markus Pettersson <markus.pettersson@mullvad.net> | 2025-03-10 10:14:58 +0100 |
|---|---|---|
| committer | Markus Pettersson <markus.pettersson@mullvad.net> | 2025-03-10 10:14:58 +0100 |
| commit | e125f6adce0cb7d5ae6c785f563ffacd2244e5ec (patch) | |
| tree | 8bf87002635b55e95fc723fb3105445c0aa75683 | |
| parent | 44f98be09578c7bbcfa9b8c1fee92b9d14a25ded (diff) | |
| parent | c4d84fcf104bd3da042104a0e89ef1419cc4c489 (diff) | |
| download | mullvadvpn-e125f6adce0cb7d5ae6c785f563ffacd2244e5ec.tar.xz mullvadvpn-e125f6adce0cb7d5ae6c785f563ffacd2244e5ec.zip | |
Merge branch 'remove-automatic-tunnel-option-from-gui-des-1787'
18 files changed, 92 insertions, 141 deletions
diff --git a/desktop/packages/mullvad-vpn/locales/messages.pot b/desktop/packages/mullvad-vpn/locales/messages.pot index f199110840..8f2d1cba41 100644 --- a/desktop/packages/mullvad-vpn/locales/messages.pot +++ b/desktop/packages/mullvad-vpn/locales/messages.pot @@ -1312,8 +1312,8 @@ msgstr "" #. available. #. Available placeholders: #. %(transportProtocol)s - the name of the transport protocol setting -#. %(automat)s - the translation of "Automatic" -#. %(openvpn)s - will be replaced with OpenVPN +#. %(automatic)s - the translation of "Automatic" +#. %(tcp)s - the translation of "TCP" msgctxt "openvpn-settings-view" msgid "To activate Bridge mode, change <b>%(transportProtocol)s</b> to <b>%(automatic)s</b> or <b>%(tcp)s</b>." msgstr "" @@ -2217,7 +2217,7 @@ msgid "Shadowsocks" msgstr "" msgctxt "wireguard-settings-view" -msgid "Switch to “%(wireguard)s” or “%(automatic)s” in Settings > %(tunnelProtocol)s to make %(setting)s available." +msgid "Switch to “%(wireguard)s” in Settings > %(tunnelProtocol)s to make %(setting)s available." msgstr "" msgctxt "wireguard-settings-view" diff --git a/desktop/packages/mullvad-vpn/src/main/default-settings.ts b/desktop/packages/mullvad-vpn/src/main/default-settings.ts index bebc5b9a4e..a80afa03e1 100644 --- a/desktop/packages/mullvad-vpn/src/main/default-settings.ts +++ b/desktop/packages/mullvad-vpn/src/main/default-settings.ts @@ -1,10 +1,35 @@ import { ApiAccessMethodSettings, + IOpenVpnConstraints, + IRelaySettingsNormal, ISettings, + IWireguardConstraints, ObfuscationType, Ownership, } from '../shared/daemon-rpc-types'; +export function getDefaultRelaySettingsNormal(): IRelaySettingsNormal< + IOpenVpnConstraints, + IWireguardConstraints +> { + return { + location: 'any', + tunnelProtocol: 'wireguard', + providers: [], + ownership: Ownership.any, + openvpnConstraints: { + port: 'any', + protocol: 'any', + }, + wireguardConstraints: { + port: 'any', + ipVersion: 'any', + useMultihop: false, + entryLocation: 'any', + }, + }; +} + export function getDefaultSettings(): ISettings { return { allowLan: false, @@ -16,22 +41,7 @@ export function getDefaultSettings(): ISettings { appsList: [], }, relaySettings: { - normal: { - location: 'any', - tunnelProtocol: 'any', - providers: [], - ownership: Ownership.any, - openvpnConstraints: { - port: 'any', - protocol: 'any', - }, - wireguardConstraints: { - port: 'any', - ipVersion: 'any', - useMultihop: false, - entryLocation: 'any', - }, - }, + normal: getDefaultRelaySettingsNormal(), }, bridgeSettings: { type: 'normal', diff --git a/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts b/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts index 11da55b6bf..d24b77c222 100644 --- a/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts +++ b/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts @@ -498,10 +498,7 @@ function convertFromRelaySettings( const normal = relaySettings.getNormal()!; const locationConstraint = convertFromLocationConstraint(normal.getLocation()); const location = wrapConstraint(locationConstraint); - // `getTunnelType()` is not falsy if type is 'any' - const tunnelProtocol = convertFromTunnelTypeConstraint( - normal.hasTunnelType() ? normal.getTunnelType() : undefined, - ); + const tunnelProtocol = convertFromTunnelType(normal.getTunnelType()); const providers = normal.getProvidersList(); const ownership = convertFromOwnership(normal.getOwnership()); const openvpnConstraints = convertFromOpenVpnConstraints(normal.getOpenvpnConstraints()!); @@ -824,22 +821,6 @@ function convertFromWireguardConstraints( return result; } -function convertFromTunnelTypeConstraint( - constraint: grpcTypes.TunnelType | undefined, -): Constraint<TunnelProtocol> { - switch (constraint) { - case grpcTypes.TunnelType.WIREGUARD: { - return { only: 'wireguard' }; - } - case grpcTypes.TunnelType.OPENVPN: { - return { only: 'openvpn' }; - } - default: { - return 'any'; - } - } -} - function convertFromConstraint<T>(value: T | undefined): Constraint<T> { if (value) { return { only: value }; @@ -853,9 +834,7 @@ export function convertToRelayConstraints( ): grpcTypes.NormalRelaySettings { const relayConstraints = new grpcTypes.NormalRelaySettings(); - if (constraints.tunnelProtocol !== 'any') { - relayConstraints.setTunnelType(convertToTunnelType(constraints.tunnelProtocol.only)); - } + relayConstraints.setTunnelType(convertToTunnelType(constraints.tunnelProtocol)); relayConstraints.setLocation(convertToLocation(unwrapConstraint(constraints.location))); relayConstraints.setWireguardConstraints( convertToWireguardConstraints(constraints.wireguardConstraints), diff --git a/desktop/packages/mullvad-vpn/src/renderer/app.tsx b/desktop/packages/mullvad-vpn/src/renderer/app.tsx index 14fdd537b0..b519b1b381 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/app.tsx +++ b/desktop/packages/mullvad-vpn/src/renderer/app.tsx @@ -650,7 +650,7 @@ export default class AppRenderer { useMultihop: wireguardConstraints.useMultihop, entryLocation: liftConstraint(wireguardConstraints.entryLocation), }, - tunnelProtocol: liftConstraint(tunnelProtocol), + tunnelProtocol, }, }); } else if ('customTunnelEndpoint' in relaySettings) { diff --git a/desktop/packages/mullvad-vpn/src/renderer/components/DaitaSettings.tsx b/desktop/packages/mullvad-vpn/src/renderer/components/DaitaSettings.tsx index 38de8d3ff1..477f9f3f45 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/components/DaitaSettings.tsx +++ b/desktop/packages/mullvad-vpn/src/renderer/components/DaitaSettings.tsx @@ -273,14 +273,19 @@ function DirectOnlyModalMessage() { } function featureUnavailableMessage() { - const automatic = messages.gettext('Automatic'); const tunnelProtocol = messages.pgettext('vpn-settings-view', 'Tunnel protocol'); return sprintf( messages.pgettext( + // TRANSLATORS: Informs the user that the the feature is only available when WireGuard + // TRANSLATORS: is selected. + // TRANSLATORS: Available placeholders: + // TRANSLATORS: %(wireguard)s - will be replaced with WireGuard + // TRANSLATORS: %(tunnelProtocol)s - the name of the tunnel protocol setting + // TRANSLATORS: %(setting)s - the name of the setting 'wireguard-settings-view', - 'Switch to “%(wireguard)s” or “%(automatic)s” in Settings > %(tunnelProtocol)s to make %(setting)s available.', + 'Switch to “%(wireguard)s” in Settings > %(tunnelProtocol)s to make %(setting)s available.', ), - { wireguard: strings.wireguard, automatic, tunnelProtocol, setting: strings.daita }, + { wireguard: strings.wireguard, tunnelProtocol, setting: strings.daita }, ); } diff --git a/desktop/packages/mullvad-vpn/src/renderer/components/Filter.tsx b/desktop/packages/mullvad-vpn/src/renderer/components/Filter.tsx index d63caffe6d..aa08ade946 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/components/Filter.tsx +++ b/desktop/packages/mullvad-vpn/src/renderer/components/Filter.tsx @@ -114,7 +114,6 @@ export default function Filter() { // Returns only the ownership options that are compatible with the other filters function useFilteredOwnershipOptions(providers: string[], ownership: Ownership): Ownership[] { - const relaySettings = useNormalRelaySettings(); const tunnelProtocol = useTunnelProtocol(); const bridgeState = useSelector((state) => state.settings.bridgeState); const locations = useSelector((state) => state.settings.relayLocations); @@ -126,7 +125,6 @@ function useFilteredOwnershipOptions(providers: string[], ownership: Ownership): locations, endpointType, tunnelProtocol, - relaySettings, ); const relaylistForFilters = filterLocations(relayListForEndpointType, ownership, providers); @@ -143,14 +141,13 @@ function useFilteredOwnershipOptions(providers: string[], ownership: Ownership): } return ownershipOptions; - }, [locations, endpointType, tunnelProtocol, relaySettings, ownership, providers]); + }, [locations, endpointType, tunnelProtocol, ownership, providers]); return availableOwnershipOptions; } // Returns only the providers that are compatible with the other filters export function useFilteredProviders(providers: string[], ownership: Ownership): string[] { - const relaySettings = useNormalRelaySettings(); const tunnelProtocol = useTunnelProtocol(); const bridgeState = useSelector((state) => state.settings.bridgeState); const locations = useSelector((state) => state.settings.relayLocations); @@ -162,11 +159,10 @@ export function useFilteredProviders(providers: string[], ownership: Ownership): locations, endpointType, tunnelProtocol, - relaySettings, ); const relaylistForFilters = filterLocations(relayListForEndpointType, ownership, providers); return providersFromRelays(relaylistForFilters); - }, [endpointType, locations, ownership, providers, relaySettings, tunnelProtocol]); + }, [endpointType, locations, ownership, providers, tunnelProtocol]); return availableProviders; } @@ -188,12 +184,7 @@ function useProviders(): Record<string, boolean> { const endpointType = tunnelProtocol === 'openvpn' && bridgeState === 'on' ? EndpointType.any : EndpointType.exit; - const relays = filterLocationsByEndPointType( - relayLocations, - endpointType, - tunnelProtocol, - relaySettings, - ); + const relays = filterLocationsByEndPointType(relayLocations, endpointType, tunnelProtocol); const providers = providersFromRelays(relays); // Empty containt array means that all providers are selected. No selection isn't possible. diff --git a/desktop/packages/mullvad-vpn/src/renderer/components/MultihopSettings.tsx b/desktop/packages/mullvad-vpn/src/renderer/components/MultihopSettings.tsx index f2681f9614..87ce98f6c8 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/components/MultihopSettings.tsx +++ b/desktop/packages/mullvad-vpn/src/renderer/components/MultihopSettings.tsx @@ -106,15 +106,20 @@ function MultihopSetting() { } function featureUnavailableMessage() { - const automatic = messages.gettext('Automatic'); const tunnelProtocol = messages.pgettext('vpn-settings-view', 'Tunnel protocol'); const multihop = messages.pgettext('wireguard-settings-view', 'Multihop'); return sprintf( messages.pgettext( + // TRANSLATORS: Informs the user that the the feature is only available when WireGuard + // TRANSLATORS: is selected. + // TRANSLATORS: Available placeholders: + // TRANSLATORS: %(wireguard)s - will be replaced with WireGuard + // TRANSLATORS: %(tunnelProtocol)s - the name of the tunnel protocol setting + // TRANSLATORS: %(setting)s - the name of the setting 'wireguard-settings-view', - 'Switch to “%(wireguard)s” or “%(automatic)s” in Settings > %(tunnelProtocol)s to make %(setting)s available.', + 'Switch to “%(wireguard)s” in Settings > %(tunnelProtocol)s to make %(setting)s available.', ), - { wireguard: strings.wireguard, automatic, tunnelProtocol, setting: multihop }, + { wireguard: strings.wireguard, tunnelProtocol, setting: multihop }, ); } diff --git a/desktop/packages/mullvad-vpn/src/renderer/components/OpenVpnSettings.tsx b/desktop/packages/mullvad-vpn/src/renderer/components/OpenVpnSettings.tsx index 36097f76b5..0d68b5e80b 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/components/OpenVpnSettings.tsx +++ b/desktop/packages/mullvad-vpn/src/renderer/components/OpenVpnSettings.tsx @@ -375,8 +375,8 @@ function bridgeModeFooterText( // TRANSLATORS: available. // TRANSLATORS: Available placeholders: // TRANSLATORS: %(transportProtocol)s - the name of the transport protocol setting - // TRANSLATORS: %(automat)s - the translation of "Automatic" - // TRANSLATORS: %(openvpn)s - will be replaced with OpenVPN + // TRANSLATORS: %(automatic)s - the translation of "Automatic" + // TRANSLATORS: %(tcp)s - the translation of "TCP" messages.pgettext( 'openvpn-settings-view', 'To activate Bridge mode, change <b>%(transportProtocol)s</b> to <b>%(automatic)s</b> or <b>%(tcp)s</b>.', diff --git a/desktop/packages/mullvad-vpn/src/renderer/components/VpnSettings.tsx b/desktop/packages/mullvad-vpn/src/renderer/components/VpnSettings.tsx index befa4e80c9..a3b0174e98 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/components/VpnSettings.tsx +++ b/desktop/packages/mullvad-vpn/src/renderer/components/VpnSettings.tsx @@ -3,7 +3,7 @@ import { sprintf } from 'sprintf-js'; import styled from 'styled-components'; import { strings } from '../../shared/constants'; -import { IDnsOptions, TunnelProtocol, wrapConstraint } from '../../shared/daemon-rpc-types'; +import { IDnsOptions, TunnelProtocol } from '../../shared/daemon-rpc-types'; import { messages } from '../../shared/gettext'; import log from '../../shared/logging'; import { useAppContext } from '../context'; @@ -664,9 +664,8 @@ function LockdownMode() { } function TunnelProtocolSetting() { - const tunnelProtocol = useSelector((state) => - mapRelaySettingsToProtocol(state.settings.relaySettings), - ); + const tunnelProtocol = useTunnelProtocol(); + const relaySettingsUpdater = useRelaySettingsUpdater(); const relaySettings = useSelector((state) => state.settings.relaySettings); @@ -689,11 +688,11 @@ function TunnelProtocolSetting() { } const setTunnelProtocol = useCallback( - async (tunnelProtocol: TunnelProtocol | null) => { + async (tunnelProtocol: TunnelProtocol) => { try { await relaySettingsUpdater((settings) => ({ ...settings, - tunnelProtocol: wrapConstraint(tunnelProtocol), + tunnelProtocol, })); } catch (e) { const error = e as Error; @@ -723,9 +722,8 @@ function TunnelProtocolSetting() { <Selector title={messages.pgettext('vpn-settings-view', 'Tunnel protocol')} items={tunnelProtocolItems} - value={tunnelProtocol ?? null} + value={tunnelProtocol} onSelect={setTunnelProtocol} - automaticValue={null} /> {openVpnDisabled ? ( <Cell.CellFooter> @@ -749,7 +747,7 @@ function TunnelProtocolSetting() { function mapRelaySettingsToProtocol(relaySettings: RelaySettingsRedux) { if ('normal' in relaySettings) { const { tunnelProtocol } = relaySettings.normal; - return tunnelProtocol === 'any' ? undefined : tunnelProtocol; + return tunnelProtocol; // since the GUI doesn't display custom settings, just display the default ones. // If the user sets any settings, then those will be applied. } else if ('customTunnelEndpoint' in relaySettings) { diff --git a/desktop/packages/mullvad-vpn/src/renderer/components/select-location/RelayListContext.tsx b/desktop/packages/mullvad-vpn/src/renderer/components/select-location/RelayListContext.tsx index 3165a95824..07b2aa9c62 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/components/select-location/RelayListContext.tsx +++ b/desktop/packages/mullvad-vpn/src/renderer/components/select-location/RelayListContext.tsx @@ -78,13 +78,8 @@ export function RelayListContextProvider(props: RelayListContextProviderProps) { const relayListForEndpointType = useMemo(() => { const endpointType = locationType === LocationType.entry ? EndpointType.entry : EndpointType.exit; - return filterLocationsByEndPointType( - fullRelayList, - endpointType, - tunnelProtocol, - relaySettings, - ); - }, [fullRelayList, locationType, relaySettings, tunnelProtocol]); + return filterLocationsByEndPointType(fullRelayList, endpointType, tunnelProtocol); + }, [fullRelayList, locationType, tunnelProtocol]); const relayListForDaita = useMemo(() => { return filterLocationsByDaita( @@ -92,7 +87,7 @@ export function RelayListContextProvider(props: RelayListContextProviderProps) { daita, directOnly, locationType, - relaySettings?.tunnelProtocol ?? 'any', + tunnelProtocol, relaySettings?.wireguard.useMultihop ?? false, ); }, [ @@ -100,7 +95,7 @@ export function RelayListContextProvider(props: RelayListContextProviderProps) { directOnly, locationType, relayListForEndpointType, - relaySettings?.tunnelProtocol, + tunnelProtocol, relaySettings?.wireguard.useMultihop, ]); diff --git a/desktop/packages/mullvad-vpn/src/renderer/components/select-location/SelectLocation.tsx b/desktop/packages/mullvad-vpn/src/renderer/components/select-location/SelectLocation.tsx index 2bf725dc29..c7af9a306b 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/components/select-location/SelectLocation.tsx +++ b/desktop/packages/mullvad-vpn/src/renderer/components/select-location/SelectLocation.tsx @@ -9,7 +9,7 @@ import { useRelaySettingsUpdater } from '../../lib/constraint-updater'; import { daitaFilterActive, filterSpecialLocations } from '../../lib/filter-locations'; import { useHistory } from '../../lib/history'; import { formatHtml } from '../../lib/html-formatter'; -import { useNormalRelaySettings } from '../../lib/relay-settings-hooks'; +import { useNormalRelaySettings, useTunnelProtocol } from '../../lib/relay-settings-hooks'; import { RoutePath } from '../../lib/routes'; import { useSelector } from '../../redux/store'; import { AppNavigationHeader } from '../'; @@ -56,6 +56,7 @@ export default function SelectLocation() { const { expandSearchResults } = useRelayListContext(); const relaySettings = useNormalRelaySettings(); + const tunnelProtocol = useTunnelProtocol(); const ownership = relaySettings?.ownership ?? Ownership.any; const providers = relaySettings?.providers ?? []; const filteredProviders = useFilteredProviders(providers, ownership); @@ -65,7 +66,7 @@ export default function SelectLocation() { daita, directOnly, locationType, - relaySettings?.tunnelProtocol ?? 'any', + tunnelProtocol, relaySettings?.wireguard.useMultihop ?? false, ); @@ -74,7 +75,6 @@ export default function SelectLocation() { const onClose = useCallback(() => history.pop(), [history]); const onViewFilter = useCallback(() => history.push(RoutePath.filter), [history]); - const tunnelProtocol = relaySettings?.tunnelProtocol ?? 'any'; const bridgeState = useSelector((state) => state.settings.bridgeState); const allowEntrySelection = (tunnelProtocol === 'openvpn' && bridgeState === 'on') || diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/constraint-updater.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/constraint-updater.ts index 6ea021ece9..78d9de93c1 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/lib/constraint-updater.ts +++ b/desktop/packages/mullvad-vpn/src/renderer/lib/constraint-updater.ts @@ -1,5 +1,6 @@ import { useCallback } from 'react'; +import { getDefaultRelaySettingsNormal } from '../../main/default-settings'; import { BridgeSettings, IBridgeConstraints, @@ -28,7 +29,7 @@ export function wrapRelaySettingsOrDefault( const wgIpVersion = wrapConstraint(relaySettings.wireguard.ipVersion); const wgEntryLocation = wrapConstraint(relaySettings.wireguard.entryLocation); const location = wrapConstraint(relaySettings.location); - const tunnelProtocol = wrapConstraint(relaySettings.tunnelProtocol); + const tunnelProtocol = relaySettings.tunnelProtocol; return { providers: [...relaySettings.providers], @@ -48,22 +49,9 @@ export function wrapRelaySettingsOrDefault( }; } - return { - location: 'any', - tunnelProtocol: 'any', - providers: [], - ownership: Ownership.any, - openvpnConstraints: { - port: 'any', - protocol: 'any', - }, - wireguardConstraints: { - port: 'any', - ipVersion: 'any', - useMultihop: false, - entryLocation: 'any', - }, - }; + const defaultSettings = getDefaultRelaySettingsNormal(); + + return defaultSettings; } type RelaySettingsUpdateFunction = ( diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/filter-locations.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/filter-locations.ts index c3a0f7feb9..f73bd14a9e 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/lib/filter-locations.ts +++ b/desktop/packages/mullvad-vpn/src/renderer/lib/filter-locations.ts @@ -1,5 +1,4 @@ import { - LiftedConstraint, Ownership, RelayEndpointType, RelayLocation, @@ -17,7 +16,6 @@ import { IRelayLocationCityRedux, IRelayLocationCountryRedux, IRelayLocationRelayRedux, - NormalRelaySettingsRedux, } from '../redux/settings/reducers'; export enum EndpointType { @@ -29,13 +27,9 @@ export enum EndpointType { export function filterLocationsByEndPointType( locations: IRelayLocationCountryRedux[], endpointType: EndpointType, - tunnelProtocol: LiftedConstraint<TunnelProtocol>, - relaySettings?: NormalRelaySettingsRedux, + tunnelProtocol: TunnelProtocol, ): IRelayLocationCountryRedux[] { - return filterLocationsImpl( - locations, - getTunnelProtocolFilter(endpointType, tunnelProtocol, relaySettings), - ); + return filterLocationsImpl(locations, getTunnelProtocolFilter(endpointType, tunnelProtocol)); } export function filterLocationsByDaita( @@ -43,7 +37,7 @@ export function filterLocationsByDaita( daita: boolean, directOnly: boolean, locationType: LocationType, - tunnelProtocol: LiftedConstraint<TunnelProtocol>, + tunnelProtocol: TunnelProtocol, multihop: boolean, ): IRelayLocationCountryRedux[] { return daitaFilterActive(daita, directOnly, locationType, tunnelProtocol, multihop) @@ -55,7 +49,7 @@ export function daitaFilterActive( daita: boolean, directOnly: boolean, locationType: LocationType, - tunnelProtocol: LiftedConstraint<TunnelProtocol>, + tunnelProtocol: TunnelProtocol, multihop: boolean, ) { const isEntry = multihop @@ -78,17 +72,11 @@ export function filterLocations( function getTunnelProtocolFilter( endpointType: EndpointType, - tunnelProtocol: LiftedConstraint<TunnelProtocol>, - relaySettings?: NormalRelaySettingsRedux, + tunnelProtocol: TunnelProtocol, ): (relay: IRelayLocationRelayRedux) => boolean { const endpointTypes: Array<RelayEndpointType> = []; if (endpointType !== EndpointType.exit && tunnelProtocol === 'openvpn') { endpointTypes.push('bridge'); - } else if (tunnelProtocol === 'any') { - endpointTypes.push('wireguard'); - if (!relaySettings?.wireguard.useMultihop) { - endpointTypes.push('openvpn'); - } } else { endpointTypes.push(tunnelProtocol); } diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/relay-settings-hooks.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/relay-settings-hooks.ts index 14fe99849d..d6db9ea4c0 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/lib/relay-settings-hooks.ts +++ b/desktop/packages/mullvad-vpn/src/renderer/lib/relay-settings-hooks.ts @@ -1,4 +1,4 @@ -import { LiftedConstraint, TunnelProtocol } from '../../shared/daemon-rpc-types'; +import { TunnelProtocol } from '../../shared/daemon-rpc-types'; import { useSelector } from '../redux/store'; export function useNormalRelaySettings() { @@ -9,14 +9,18 @@ export function useNormalRelaySettings() { // Some features are considered core privacy features and when enabled prevent OpenVPN from being // used. This hook returns the tunnelprotocol with the exception that it always returns WireGuard // when any of those features are enabled. -export function useTunnelProtocol(): LiftedConstraint<TunnelProtocol> { +export function useTunnelProtocol(): TunnelProtocol { const relaySettings = useNormalRelaySettings(); const multihop = relaySettings?.wireguard.useMultihop ?? false; const daita = useSelector((state) => state.settings.wireguard.daita?.enabled ?? false); const quantumResistant = useSelector((state) => state.settings.wireguard.quantumResistant); const openVpnDisabled = daita || multihop || quantumResistant; - return openVpnDisabled ? 'wireguard' : (relaySettings?.tunnelProtocol ?? 'any'); + if (openVpnDisabled || relaySettings?.tunnelProtocol === undefined) { + return 'wireguard'; + } + + return relaySettings.tunnelProtocol; } export function useNormalBridgeSettings() { diff --git a/desktop/packages/mullvad-vpn/src/renderer/redux/settings/reducers.ts b/desktop/packages/mullvad-vpn/src/renderer/redux/settings/reducers.ts index 6eb595467b..1540179289 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/redux/settings/reducers.ts +++ b/desktop/packages/mullvad-vpn/src/renderer/redux/settings/reducers.ts @@ -25,7 +25,7 @@ import { IGuiSettingsState } from '../../../shared/gui-settings-state'; import { ReduxAction } from '../store'; export type NormalRelaySettingsRedux = { - tunnelProtocol: LiftedConstraint<TunnelProtocol>; + tunnelProtocol: TunnelProtocol; location: LiftedConstraint<RelayLocation>; providers: string[]; ownership: Ownership; @@ -139,7 +139,7 @@ const initialState: ISettingsReduxState = { relaySettings: { normal: { location: 'any', - tunnelProtocol: 'any', + tunnelProtocol: 'wireguard', providers: [], ownership: Ownership.any, wireguard: { port: 'any', ipVersion: 'any', useMultihop: false, entryLocation: 'any' }, diff --git a/desktop/packages/mullvad-vpn/src/shared/daemon-rpc-types.ts b/desktop/packages/mullvad-vpn/src/shared/daemon-rpc-types.ts index 1522d43b39..00228667c9 100644 --- a/desktop/packages/mullvad-vpn/src/shared/daemon-rpc-types.ts +++ b/desktop/packages/mullvad-vpn/src/shared/daemon-rpc-types.ts @@ -99,15 +99,13 @@ export type ErrorStateDetails = export type AfterDisconnect = 'nothing' | 'block' | 'reconnect'; -export type TunnelType = 'any' | 'wireguard' | 'openvpn'; +export type TunnelType = 'wireguard' | 'openvpn'; export function tunnelTypeToString(tunnel: TunnelType): string { switch (tunnel) { case 'wireguard': return 'WireGuard'; case 'openvpn': return 'OpenVPN'; - case 'any': - return ''; } } @@ -264,7 +262,7 @@ export type IpVersion = 'ipv4' | 'ipv6'; export interface IRelaySettingsNormal<OpenVpn, Wireguard> { location: Constraint<RelayLocation>; - tunnelProtocol: Constraint<TunnelProtocol>; + tunnelProtocol: TunnelProtocol; providers: string[]; ownership: Ownership; openvpnConstraints: OpenVpn; diff --git a/mullvad-management-interface/proto/management_interface.proto b/mullvad-management-interface/proto/management_interface.proto index 4ce1bc1792..2b2e0bfe59 100644 --- a/mullvad-management-interface/proto/management_interface.proto +++ b/mullvad-management-interface/proto/management_interface.proto @@ -496,7 +496,7 @@ message RelaySettings { message NormalRelaySettings { LocationConstraint location = 1; repeated string providers = 2; - optional TunnelType tunnel_type = 3; + TunnelType tunnel_type = 3; WireguardConstraints wireguard_constraints = 4; OpenvpnConstraints openvpn_constraints = 5; Ownership ownership = 6; diff --git a/mullvad-management-interface/src/types/conversions/relay_constraints.rs b/mullvad-management-interface/src/types/conversions/relay_constraints.rs index 94cd5b6f64..aebaede49a 100644 --- a/mullvad-management-interface/src/types/conversions/relay_constraints.rs +++ b/mullvad-management-interface/src/types/conversions/relay_constraints.rs @@ -97,13 +97,8 @@ impl TryFrom<proto::RelaySettings> for mullvad_types::relay_constraints::RelaySe .unwrap_or(Constraint::Any); let providers = try_providers_constraint_from_proto(&settings.providers)?; let ownership = try_ownership_constraint_from_i32(settings.ownership)?; - let tunnel_protocol = settings - .tunnel_type - .map(try_tunnel_type_from_i32) - .transpose()? - .ok_or(FromProtobufTypeError::InvalidArgument( - "missing tunnel protocol", - ))?; + let tunnel_protocol = try_tunnel_type_from_i32(settings.tunnel_type)?; + let openvpn_constraints = mullvad_constraints::OpenVpnConstraints::try_from( &settings.openvpn_constraints.ok_or( @@ -227,7 +222,6 @@ impl From<mullvad_types::relay_constraints::RelaySettings> for proto::RelaySetti fn from(settings: mullvad_types::relay_constraints::RelaySettings) -> Self { use mullvad_types::relay_constraints::RelaySettings as MullvadRelaySettings; use proto::relay_settings; - use talpid_types::net as talpid_net; let endpoint = match settings { MullvadRelaySettings::CustomTunnelEndpoint(endpoint) => { @@ -244,11 +238,7 @@ impl From<mullvad_types::relay_constraints::RelaySettings> for proto::RelaySetti .map(proto::LocationConstraint::from), providers: convert_providers_constraint(&constraints.providers), ownership: convert_ownership_constraint(&constraints.ownership) as i32, - tunnel_type: match constraints.tunnel_protocol { - talpid_net::TunnelType::Wireguard => Some(proto::TunnelType::Wireguard), - talpid_net::TunnelType::OpenVpn => Some(proto::TunnelType::Openvpn), - } - .map(i32::from), + tunnel_type: constraints.tunnel_protocol as i32, wireguard_constraints: Some(proto::WireguardConstraints { port: constraints |
