diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-12-06 10:42:20 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-01-03 13:48:03 +0100 |
| commit | a75abb22ed42c8c811aa4967ba82be5077f52ea2 (patch) | |
| tree | eab547f9b27566fa34fab981de6e0eb398c8fb46 /gui/src/renderer/containers | |
| parent | 9b6f208a2135344cb7b6e28ac28b76d31b54130c (diff) | |
| download | mullvadvpn-a75abb22ed42c8c811aa4967ba82be5077f52ea2.tar.xz mullvadvpn-a75abb22ed42c8c811aa4967ba82be5077f52ea2.zip | |
Add entry location selection in SelectLocation
Diffstat (limited to 'gui/src/renderer/containers')
| -rw-r--r-- | gui/src/renderer/containers/SelectLocationPage.tsx | 56 |
1 files changed, 38 insertions, 18 deletions
diff --git a/gui/src/renderer/containers/SelectLocationPage.tsx b/gui/src/renderer/containers/SelectLocationPage.tsx index cd455a01f6..a4f78f87a5 100644 --- a/gui/src/renderer/containers/SelectLocationPage.tsx +++ b/gui/src/renderer/containers/SelectLocationPage.tsx @@ -1,21 +1,21 @@ import { connect } from 'react-redux'; -import { bindActionCreators } from 'redux'; import BridgeSettingsBuilder from '../../shared/bridge-settings-builder'; import { LiftedConstraint, RelayLocation } from '../../shared/daemon-rpc-types'; import log from '../../shared/logging'; import RelaySettingsBuilder from '../../shared/relay-settings-builder'; import SelectLocation from '../components/SelectLocation'; import withAppContext, { IAppContext } from '../context'; +import { createWireguardRelayUpdater } from '../lib/constraint-updater'; import { IHistoryProps, withHistory } from '../lib/history'; import { RoutePath } from '../lib/routes'; import { IRelayLocationRedux } from '../redux/settings/reducers'; import { IReduxState, ReduxDispatch } from '../redux/store'; -import userInterfaceActions from '../redux/userinterface/actions'; -import { LocationScope } from '../redux/userinterface/reducers'; -const mapStateToProps = (state: IReduxState) => { +const mapStateToProps = (state: IReduxState, props: IHistoryProps & IAppContext) => { let selectedExitLocation: RelayLocation | undefined; + let selectedEntryLocation: RelayLocation | undefined; let selectedBridgeLocation: LiftedConstraint<RelayLocation> | undefined; + let multihopEnabled = false; if ('normal' in state.settings.relaySettings) { const exitLocation = state.settings.relaySettings.normal.location; @@ -24,37 +24,57 @@ const mapStateToProps = (state: IReduxState) => { } } - if ('normal' in state.settings.bridgeSettings) { + const relaySettings = state.settings.relaySettings; + const tunnelProtocol = 'normal' in relaySettings ? relaySettings.normal.tunnelProtocol : 'any'; + + if (tunnelProtocol === 'openvpn' && 'normal' in state.settings.bridgeSettings) { selectedBridgeLocation = state.settings.bridgeSettings.normal.location; + } else if ('normal' in relaySettings) { + const entryLocation = relaySettings.normal.wireguard.entryLocation; + if (entryLocation !== 'any') { + selectedEntryLocation = entryLocation; + } + + multihopEnabled = relaySettings.normal.wireguard.useMultihop; } - const allowBridgeSelection = state.settings.bridgeState === 'on'; - const locationScope = allowBridgeSelection - ? state.userInterface.locationScope - : LocationScope.relay; + const allowEntrySelection = + (tunnelProtocol === 'openvpn' && state.settings.bridgeState === 'on') || + ((tunnelProtocol === 'any' || tunnelProtocol === 'wireguard') && multihopEnabled); - const relaySettings = state.settings.relaySettings; const providers = 'normal' in relaySettings ? relaySettings.normal.providers : []; return { selectedExitLocation, + selectedEntryLocation, selectedBridgeLocation, relayLocations: filterLocationsByProvider(state.settings.relayLocations, providers), bridgeLocations: filterLocationsByProvider(state.settings.bridgeLocations, providers), - locationScope, - allowBridgeSelection, + allowEntrySelection, + tunnelProtocol, providers, + + onSelectEntryLocation: async (entryLocation: RelayLocation) => { + // dismiss the view first + props.history.dismiss(); + + const relayUpdate = createWireguardRelayUpdater(state.settings.relaySettings) + .tunnel.wireguard((wireguard) => wireguard.entryLocation.exact(entryLocation)) + .build(); + + try { + await props.app.updateRelaySettings(relayUpdate); + } catch (e) { + const error = e as Error; + log.error('Failed to select the entry location', error.message); + } + }, }; }; -const mapDispatchToProps = (dispatch: ReduxDispatch, props: IHistoryProps & IAppContext) => { - const userInterface = bindActionCreators(userInterfaceActions, dispatch); - +const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAppContext) => { return { onClose: () => props.history.dismiss(), onViewFilterByProvider: () => props.history.push(RoutePath.filterByProvider), - onChangeLocationScope: (scope: LocationScope) => { - userInterface.setLocationScope(scope); - }, onSelectExitLocation: async (relayLocation: RelayLocation) => { // dismiss the view first props.history.dismiss(); |
