diff options
| author | David Lönnhager <david.l@mullvad.net> | 2023-10-26 01:13:39 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2023-10-31 00:45:17 +0100 |
| commit | fbc8c1675700e1e87d9282ee288e6c0b72c1c7aa (patch) | |
| tree | 85c4cb1d2a5a43826e8f3a0a2552a177e58bbced /gui/src/shared | |
| parent | e02d812d55064fc114d38edbdcbbeda5aca6a6b7 (diff) | |
| download | mullvadvpn-fbc8c1675700e1e87d9282ee288e6c0b72c1c7aa.tar.xz mullvadvpn-fbc8c1675700e1e87d9282ee288e6c0b72c1c7aa.zip | |
Remove RelaySettingsUpdate from gui/
Diffstat (limited to 'gui/src/shared')
| -rw-r--r-- | gui/src/shared/daemon-rpc-types.ts | 21 | ||||
| -rw-r--r-- | gui/src/shared/ipc-schema.ts | 4 | ||||
| -rw-r--r-- | gui/src/shared/relay-settings-builder.ts | 189 |
3 files changed, 10 insertions, 204 deletions
diff --git a/gui/src/shared/daemon-rpc-types.ts b/gui/src/shared/daemon-rpc-types.ts index 51c1d67c0d..6977be4375 100644 --- a/gui/src/shared/daemon-rpc-types.ts +++ b/gui/src/shared/daemon-rpc-types.ts @@ -112,6 +112,14 @@ export type LiftedConstraint<T> = 'any' | T; export function liftConstraint<T>(constraint: Constraint<T>): LiftedConstraint<T> { return constraint === 'any' ? constraint : constraint.only; } +export function wrapConstraint<T>( + constraint: LiftedConstraint<T> | undefined | null, +): Constraint<T> { + if (constraint) { + return constraint === 'any' ? 'any' : { only: constraint }; + } + return 'any'; +} export type ProxyType = 'shadowsocks' | 'custom'; export function proxyTypeToString(proxy: ProxyType): string { @@ -267,19 +275,6 @@ export type RelaySettings = customTunnelEndpoint: IRelaySettingsCustom; }; -// types describing the partial update of RelaySettings -export type RelaySettingsNormalUpdate = Partial< - IRelaySettingsNormal<Partial<IOpenVpnConstraints>, Partial<IWireguardConstraints>> ->; - -export type RelaySettingsUpdate = - | { - normal: RelaySettingsNormalUpdate; - } - | { - customTunnelEndpoint: IRelaySettingsCustom; - }; - export interface IRelayListWithEndpointData { relayList: IRelayList; wireguardEndpointData: IWireguardEndpointData; diff --git a/gui/src/shared/ipc-schema.ts b/gui/src/shared/ipc-schema.ts index 946b4fa99a..7981250c88 100644 --- a/gui/src/shared/ipc-schema.ts +++ b/gui/src/shared/ipc-schema.ts @@ -19,7 +19,7 @@ import { IRelayListWithEndpointData, ISettings, ObfuscationSettings, - RelaySettingsUpdate, + RelaySettings, TunnelState, VoucherResponse, } from './daemon-rpc-types'; @@ -172,7 +172,7 @@ export const ipcSchema = { setOpenVpnMssfix: invoke<number | undefined, void>(), setWireguardMtu: invoke<number | undefined, void>(), setWireguardQuantumResistant: invoke<boolean | undefined, void>(), - updateRelaySettings: invoke<RelaySettingsUpdate, void>(), + updateRelaySettings: invoke<RelaySettings, void>(), updateBridgeSettings: invoke<BridgeSettings, void>(), setDnsOptions: invoke<IDnsOptions, void>(), setObfuscationSettings: invoke<ObfuscationSettings, void>(), diff --git a/gui/src/shared/relay-settings-builder.ts b/gui/src/shared/relay-settings-builder.ts deleted file mode 100644 index e4c11e5132..0000000000 --- a/gui/src/shared/relay-settings-builder.ts +++ /dev/null @@ -1,189 +0,0 @@ -import { - Constraint, - IOpenVpnConstraints, - IpVersion, - IWireguardConstraints, - RelayLocation, - RelayProtocol, - RelaySettingsNormalUpdate, - RelaySettingsUpdate, - TunnelProtocol, -} from './daemon-rpc-types'; -import makeLocationBuilder, { ILocationBuilder } from './relay-location-builder'; - -interface IExactOrAny<T, Self> { - exact(value: T): Self; - any(): Self; -} - -interface IOpenVPNConfigurator { - port: IExactOrAny<number, IOpenVPNConfigurator>; - protocol: IExactOrAny<RelayProtocol, IOpenVPNConfigurator>; -} - -interface IWireguardConfigurator { - port: IExactOrAny<number, IWireguardConfigurator>; - ipVersion: IExactOrAny<IpVersion, IWireguardConfigurator>; - useMultihop: (value: boolean) => IWireguardConfigurator; - entryLocation: IExactOrAny<RelayLocation, IWireguardConfigurator>; -} - -interface ITunnelProtocolConfigurator { - tunnelProtocol: IExactOrAny<TunnelProtocol, ITunnelProtocolConfigurator>; -} - -interface ITunnelBuilder { - openvpn( - configurator: (openVpnConfigurator: IOpenVPNConfigurator) => void, - ): NormalRelaySettingsBuilder; - wireguard( - configurator: (wireguardConfigurator: IWireguardConfigurator) => void, - ): NormalRelaySettingsBuilder; - tunnelProtocol( - configurator: (tunnelProtocolConfigurator: ITunnelProtocolConfigurator) => void, - ): NormalRelaySettingsBuilder; -} - -class NormalRelaySettingsBuilder { - private payload: RelaySettingsNormalUpdate = {}; - - public build(): RelaySettingsUpdate { - return { - normal: this.payload, - }; - } - - get location(): ILocationBuilder<NormalRelaySettingsBuilder> { - return makeLocationBuilder(this, (location) => { - this.payload.location = location; - }); - } - - get tunnel(): ITunnelBuilder { - const updateOpenvpn = (next: Partial<IOpenVpnConstraints>) => { - if (this.payload.openvpnConstraints === undefined) { - this.payload.openvpnConstraints = next; - } else { - const prev = this.payload.openvpnConstraints; - this.payload.openvpnConstraints = { - ...prev, - ...next, - }; - } - }; - - const updateWireguard = (next: Partial<IWireguardConstraints>) => { - if (this.payload.wireguardConstraints === undefined) { - this.payload.wireguardConstraints = next; - } else { - const prev = this.payload.wireguardConstraints; - this.payload.wireguardConstraints = { - ...prev, - ...next, - }; - } - }; - - const updateTunnelProtocol = (next?: Constraint<TunnelProtocol>) => { - this.payload.tunnelProtocol = next; - }; - - return { - openvpn: (configurator: (configurator: IOpenVPNConfigurator) => void) => { - const openvpnBuilder: IOpenVPNConfigurator = { - get port() { - const apply = (port: Constraint<number>) => { - updateOpenvpn({ port }); - return this; - }; - return { - exact: (value: number) => apply({ only: value }), - any: () => apply('any'), - }; - }, - get protocol() { - const apply = (protocol: Constraint<RelayProtocol>) => { - updateOpenvpn({ protocol }); - return this; - }; - return { - exact: (value: RelayProtocol) => apply({ only: value }), - any: () => apply('any'), - }; - }, - }; - - configurator(openvpnBuilder); - - return this; - }, - - wireguard: (configurator: (configurator: IWireguardConfigurator) => void) => { - const wireguardBuilder: IWireguardConfigurator = { - get port() { - const apply = (port: Constraint<number>) => { - updateWireguard({ port }); - return this; - }; - return { - exact: (value: number) => apply({ only: value }), - any: () => apply('any'), - }; - }, - get ipVersion() { - const apply = (ipVersion: Constraint<IpVersion>) => { - updateWireguard({ ipVersion }); - return this; - }; - return { - exact: (value: IpVersion) => apply({ only: value }), - 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; - }, - - tunnelProtocol: (configurator: (configurator: ITunnelProtocolConfigurator) => void) => { - const tunnelProtocolBuilder = { - get tunnelProtocol() { - return { - exact: (value: TunnelProtocol) => { - updateTunnelProtocol({ only: value }); - return this; - }, - any: () => { - updateTunnelProtocol('any'); - return this; - }, - }; - }, - }; - - configurator(tunnelProtocolBuilder); - return this; - }, - }; - } -} - -export default { - normal: () => new NormalRelaySettingsBuilder(), -}; |
