diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-12-06 08:55:59 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-01-03 13:48:03 +0100 |
| commit | b896f49438af2f482774a80f14b111c7c896f7be (patch) | |
| tree | 06986f74633f9a131684fc5c02a31dbb9fe8de21 | |
| parent | 71404a0670fde113c76089a137716874174b58c0 (diff) | |
| download | mullvadvpn-b896f49438af2f482774a80f14b111c7c896f7be.tar.xz mullvadvpn-b896f49438af2f482774a80f14b111c7c896f7be.zip | |
Add entry location to relay-settings-builder
| -rw-r--r-- | gui/src/renderer/lib/constraint-updater.ts | 36 | ||||
| -rw-r--r-- | gui/src/shared/relay-settings-builder.ts | 19 |
2 files changed, 55 insertions, 0 deletions
diff --git a/gui/src/renderer/lib/constraint-updater.ts b/gui/src/renderer/lib/constraint-updater.ts new file mode 100644 index 0000000000..ce9f49f376 --- /dev/null +++ b/gui/src/renderer/lib/constraint-updater.ts @@ -0,0 +1,36 @@ +import { RelaySettingsRedux } from '../redux/settings/reducers'; +import RelaySettingsBuilder from '../../shared/relay-settings-builder'; + +export function createWireguardRelayUpdater( + relaySettings: RelaySettingsRedux, +): ReturnType<typeof RelaySettingsBuilder['normal']> { + if ('normal' in relaySettings) { + const constraints = relaySettings.normal.wireguard; + + const relayUpdate = RelaySettingsBuilder.normal().tunnel.wireguard((wireguard) => { + if (constraints.port === 'any') { + wireguard.port.any(); + } else { + wireguard.port.exact(constraints.port); + } + + if (constraints.ipVersion === 'any') { + wireguard.ipVersion.any(); + } else { + wireguard.ipVersion.exact(constraints.ipVersion); + } + + wireguard.useMultihop(constraints.useMultihop); + + if (constraints.entryLocation === 'any') { + wireguard.entryLocation.any(); + } else if (constraints.entryLocation !== undefined) { + wireguard.entryLocation.exact(constraints.entryLocation); + } + }); + + return relayUpdate; + } else { + return RelaySettingsBuilder.normal(); + } +} diff --git a/gui/src/shared/relay-settings-builder.ts b/gui/src/shared/relay-settings-builder.ts index 418de10888..e4c11e5132 100644 --- a/gui/src/shared/relay-settings-builder.ts +++ b/gui/src/shared/relay-settings-builder.ts @@ -3,6 +3,7 @@ import { IOpenVpnConstraints, IpVersion, IWireguardConstraints, + RelayLocation, RelayProtocol, RelaySettingsNormalUpdate, RelaySettingsUpdate, @@ -23,6 +24,8 @@ interface IOpenVPNConfigurator { interface IWireguardConfigurator { port: IExactOrAny<number, IWireguardConfigurator>; ipVersion: IExactOrAny<IpVersion, IWireguardConfigurator>; + useMultihop: (value: boolean) => IWireguardConfigurator; + entryLocation: IExactOrAny<RelayLocation, IWireguardConfigurator>; } interface ITunnelProtocolConfigurator { @@ -137,6 +140,22 @@ class NormalRelaySettingsBuilder { any: () => apply('any'), }; }, + get useMultihop() { + return (useMultihop: boolean) => { + updateWireguard({ useMultihop }); + return this; + }; + }, + get entryLocation() { + const apply = (entryLocation: Constraint<RelayLocation> | undefined) => { + updateWireguard({ entryLocation }); + return this; + }; + return { + exact: (entryLocation: RelayLocation) => apply({ only: entryLocation }), + any: () => apply('any'), + }; + }, }; configurator(wireguardBuilder); return this; |
