summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmīls Piņķis <emils@mullvad.net>2019-07-18 18:02:54 +0100
committerEmīls Piņķis <emils@mullvad.net>2019-07-26 11:25:54 +0100
commit7106c34585f3db116307bc908f1eb1fbf51a73cf (patch)
tree196e3baf05d1366ae59d8ac6f1fd0a189defec62
parentace147c273e058e85df619fb4300e3953cedd2dd (diff)
downloadmullvadvpn-7106c34585f3db116307bc908f1eb1fbf51a73cf.tar.xz
mullvadvpn-7106c34585f3db116307bc908f1eb1fbf51a73cf.zip
Adjust GUI code to the new settings schema
-rw-r--r--gui/src/main/daemon-rpc.ts23
-rw-r--r--gui/src/main/index.ts13
-rw-r--r--gui/src/renderer/app.tsx44
-rw-r--r--gui/src/renderer/lib/relay-settings-builder.ts22
-rw-r--r--gui/src/renderer/redux/settings/reducers.ts3
-rw-r--r--gui/src/shared/daemon-rpc-types.ts23
-rw-r--r--gui/test/relay-settings-builder.spec.ts20
7 files changed, 66 insertions, 82 deletions
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts
index e317ffb794..24671fac23 100644
--- a/gui/src/main/daemon-rpc.ts
+++ b/gui/src/main/daemon-rpc.ts
@@ -101,21 +101,14 @@ const relaySettingsSchema = oneOf(
object({
normal: partialObject({
location: locationConstraintSchema,
- tunnel: constraint(
- oneOf(
- object({
- openvpn: partialObject({
- port: constraint(number),
- protocol: constraint(enumeration('udp', 'tcp')),
- }),
- }),
- object({
- wireguard: partialObject({
- port: constraint(number),
- }),
- }),
- ),
- ),
+ tunnel_protocol: constraint(enumeration('wireguard', 'openvpn')),
+ wireguard_constraints: partialObject({
+ port: constraint(number),
+ }),
+ openvpn_constraints: partialObject({
+ port: constraint(number),
+ protocol: constraint(enumeration('udp', 'tcp')),
+ }),
}),
}),
object({
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index a0dcbeb50b..1d766629cf 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -83,7 +83,14 @@ class ApplicationMain {
relaySettings: {
normal: {
location: 'any',
- tunnel: 'any',
+ tunnelProtocol: 'any',
+ openvpnConstraints: {
+ port: 'any',
+ protocol: 'any',
+ },
+ wireguardConstraints: {
+ port: 'any',
+ },
},
},
bridgeSettings: {
@@ -611,8 +618,8 @@ class ApplicationMain {
let fnHasWantedTunnels = hasOpenVpnTunnels;
if ('normal' in relaySettings) {
- const tunnelConstraints = relaySettings.normal.tunnel;
- if (tunnelConstraints !== 'any' && 'wireguard' in tunnelConstraints.only) {
+ const tunnelConstraints = relaySettings.normal.tunnelProtocol;
+ if (tunnelConstraints !== 'any' && 'wireguard' === tunnelConstraints.only) {
fnHasWantedTunnels = hasWireguardTunnels;
}
}
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx
index 6d5d9ae5ab..d77cf65e89 100644
--- a/gui/src/renderer/app.tsx
+++ b/gui/src/renderer/app.tsx
@@ -37,6 +37,7 @@ import {
IRelayList,
ISettings,
KeygenEvent,
+ liftConstraint,
RelaySettings,
RelaySettingsUpdate,
TunnelState,
@@ -375,43 +376,30 @@ export default class AppRenderer {
if ('normal' in relaySettings) {
const normal = relaySettings.normal;
- const tunnel = normal.tunnel;
+ const tunnelProtocol = normal.tunnelProtocol;
const location = normal.location;
-
const relayLocation = location === 'any' ? 'any' : location.only;
- if (tunnel === 'any') {
+ if (tunnelProtocol === 'any' || tunnelProtocol.only === 'openvpn') {
+ const { port, protocol } = normal.openvpnConstraints;
actions.settings.updateRelay({
normal: {
location: relayLocation,
- port: 'any',
- protocol: 'any',
+ port: port === 'any' ? port : port.only,
+ protocol: protocol === 'any' ? protocol : protocol.only,
+ tunnelProtocol: liftConstraint(tunnelProtocol),
},
});
} else {
- const constraints = tunnel.only;
-
- if ('openvpn' in constraints) {
- const { port, protocol } = constraints.openvpn;
-
- actions.settings.updateRelay({
- normal: {
- location: relayLocation,
- port: port === 'any' ? port : port.only,
- protocol: protocol === 'any' ? protocol : protocol.only,
- },
- });
- } else if ('wireguard' in constraints) {
- const { port } = constraints.wireguard;
-
- actions.settings.updateRelay({
- normal: {
- location: relayLocation,
- port: port === 'any' ? port : port.only,
- protocol: 'udp',
- },
- });
- }
+ const { port } = normal.wireguardConstraints;
+ actions.settings.updateRelay({
+ normal: {
+ tunnelProtocol: liftConstraint(tunnelProtocol),
+ location: relayLocation,
+ port: port === 'any' ? port : port.only,
+ protocol: 'udp',
+ },
+ });
}
} else if ('customTunnelEndpoint' in relaySettings) {
const customTunnelEndpoint = relaySettings.customTunnelEndpoint;
diff --git a/gui/src/renderer/lib/relay-settings-builder.ts b/gui/src/renderer/lib/relay-settings-builder.ts
index 72dc95e759..bbf85b1fed 100644
--- a/gui/src/renderer/lib/relay-settings-builder.ts
+++ b/gui/src/renderer/lib/relay-settings-builder.ts
@@ -80,19 +80,13 @@ class NormalRelaySettingsBuilder {
get tunnel(): ITunnelBuilder {
const updateOpenvpn = (next: Partial<IOpenVpnConstraints>) => {
- const tunnel = this.payload.tunnel;
- if (typeof tunnel === 'string' || typeof tunnel === 'undefined') {
- this.payload.tunnel = {
- only: {
- openvpn: next,
- },
- };
- } else if (typeof tunnel === 'object') {
- const prev = tunnel.only && 'openvpn' in tunnel.only ? tunnel.only.openvpn : {};
- this.payload.tunnel = {
- only: {
- openvpn: { ...prev, ...next },
- },
+ if (this.payload.openvpnConstraints === undefined) {
+ this.payload.openvpnConstraints = next;
+ } else {
+ const prev = this.payload.openvpnConstraints;
+ this.payload.openvpnConstraints = {
+ ...prev,
+ ...next,
};
}
};
@@ -127,7 +121,7 @@ class NormalRelaySettingsBuilder {
return this;
},
any: () => {
- this.payload.tunnel = 'any';
+ this.payload.tunnelProtocol = 'any';
return this;
},
};
diff --git a/gui/src/renderer/redux/settings/reducers.ts b/gui/src/renderer/redux/settings/reducers.ts
index 97a6a21ee4..e41750b496 100644
--- a/gui/src/renderer/redux/settings/reducers.ts
+++ b/gui/src/renderer/redux/settings/reducers.ts
@@ -4,6 +4,7 @@ import {
KeygenEvent,
RelayLocation,
RelayProtocol,
+ TunnelProtocol,
} from '../../../shared/daemon-rpc-types';
import { IGuiSettingsState } from '../../../shared/gui-settings-state';
import { ReduxAction } from '../store';
@@ -11,6 +12,7 @@ import { ReduxAction } from '../store';
export type RelaySettingsRedux =
| {
normal: {
+ tunnelProtocol: 'any' | TunnelProtocol;
location: 'any' | RelayLocation;
port: 'any' | number;
protocol: 'any' | RelayProtocol;
@@ -108,6 +110,7 @@ const initialState: ISettingsReduxState = {
relaySettings: {
normal: {
location: 'any',
+ tunnelProtocol: 'any',
port: 'any',
protocol: 'any',
},
diff --git a/gui/src/shared/daemon-rpc-types.ts b/gui/src/shared/daemon-rpc-types.ts
index 5d2c77d223..8dc87cc2b1 100644
--- a/gui/src/shared/daemon-rpc-types.ts
+++ b/gui/src/shared/daemon-rpc-types.ts
@@ -44,6 +44,13 @@ export function tunnelTypeToString(tunnel: TunnelType): string {
export type RelayProtocol = 'tcp' | 'udp';
+export function liftConstraint<T>(constraint: 'any' | { only: T }): 'any' | T {
+ if (constraint === 'any') {
+ return 'any';
+ }
+ return constraint.only;
+}
+
export type ProxyType = 'shadowsocks' | 'custom';
export function proxyTypeToString(proxy: ProxyType): string {
switch (proxy) {
@@ -101,19 +108,21 @@ export interface IWireguardConstraints {
port: 'any' | { only: number };
}
-type TunnelConstraints<OpenVpn, Wireguard> = { wireguard: Wireguard } | { openvpn: OpenVpn };
+export type TunnelProtocol = 'wireguard' | 'openvpn';
-interface IRelaySettingsNormal<TTunnelConstraints> {
+interface IRelaySettingsNormal<OpenVpn, Wireguard> {
location:
| 'any'
| {
only: RelayLocation;
};
- tunnel:
+ tunnelProtocol:
| 'any'
| {
- only: TTunnelConstraints;
+ only: TunnelProtocol;
};
+ openvpnConstraints: OpenVpn;
+ wireguardConstraints: Wireguard;
}
export type ConnectionConfig =
@@ -150,7 +159,7 @@ export interface IRelaySettingsCustom {
}
export type RelaySettings =
| {
- normal: IRelaySettingsNormal<TunnelConstraints<IOpenVpnConstraints, IWireguardConstraints>>;
+ normal: IRelaySettingsNormal<IOpenVpnConstraints, IWireguardConstraints>;
}
| {
customTunnelEndpoint: IRelaySettingsCustom;
@@ -158,9 +167,7 @@ export type RelaySettings =
// types describing the partial update of RelaySettings
export type RelaySettingsNormalUpdate = Partial<
- IRelaySettingsNormal<
- TunnelConstraints<Partial<IOpenVpnConstraints>, Partial<IWireguardConstraints>>
- >
+ IRelaySettingsNormal<Partial<IOpenVpnConstraints>, Partial<IWireguardConstraints>>
>;
export type RelaySettingsUpdate =
diff --git a/gui/test/relay-settings-builder.spec.ts b/gui/test/relay-settings-builder.spec.ts
index fd7f4c1cf4..f9ceccd744 100644
--- a/gui/test/relay-settings-builder.spec.ts
+++ b/gui/test/relay-settings-builder.spec.ts
@@ -54,13 +54,9 @@ describe('Relay settings builder', () => {
.build(),
).to.deep.equal({
normal: {
- tunnel: {
- only: {
- openvpn: {
- port: 'any',
- protocol: 'any',
- },
- },
+ openvpnConstraints: {
+ port: 'any',
+ protocol: 'any',
},
},
});
@@ -75,13 +71,9 @@ describe('Relay settings builder', () => {
.build(),
).to.deep.equal({
normal: {
- tunnel: {
- only: {
- openvpn: {
- port: { only: 80 },
- protocol: { only: 'tcp' },
- },
- },
+ openvpnConstraints: {
+ port: { only: 80 },
+ protocol: { only: 'tcp' },
},
},
});