summaryrefslogtreecommitdiffhomepage
path: root/gui/src/shared
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2023-10-04 11:35:59 +0200
committerOskar Nyberg <oskar@mullvad.net>2023-10-09 10:16:53 +0200
commit469c501f736e98ea6a20f1e76b40550d6ad995cd (patch)
tree88c0fbab003216eff6bcaf2fb87c02d634025558 /gui/src/shared
parent4e26e4c36345afbca25a1a1e760927cd74d2c1a5 (diff)
downloadmullvadvpn-469c501f736e98ea6a20f1e76b40550d6ad995cd.tar.xz
mullvadvpn-469c501f736e98ea6a20f1e76b40550d6ad995cd.zip
Add custom lists to settings, ipc and rpc calls
Diffstat (limited to 'gui/src/shared')
-rw-r--r--gui/src/shared/daemon-rpc-types.ts87
-rw-r--r--gui/src/shared/ipc-schema.ts7
-rw-r--r--gui/src/shared/relay-location-builder.ts4
3 files changed, 80 insertions, 18 deletions
diff --git a/gui/src/shared/daemon-rpc-types.ts b/gui/src/shared/daemon-rpc-types.ts
index 9af927070a..51c1d67c0d 100644
--- a/gui/src/shared/daemon-rpc-types.ts
+++ b/gui/src/shared/daemon-rpc-types.ts
@@ -179,10 +179,28 @@ export type TunnelState =
| { state: 'disconnecting'; details: AfterDisconnect }
| { state: 'error'; details: ErrorState };
-export type RelayLocation =
- | { hostname: [string, string, string] }
- | { city: [string, string] }
- | { country: string };
+export interface RelayLocationCountry extends Partial<RelayLocationCustomList> {
+ country: string;
+}
+
+export interface RelayLocationCity extends RelayLocationCountry {
+ city: string;
+}
+
+export interface RelayLocationRelay extends RelayLocationCity {
+ hostname: string;
+}
+
+export interface RelayLocationCustomList {
+ customList: string;
+}
+
+export type RelayLocationGeographical =
+ | RelayLocationRelay
+ | RelayLocationCountry
+ | RelayLocationCity;
+
+export type RelayLocation = RelayLocationGeographical | RelayLocationCustomList;
export interface IOpenVpnConstraints {
port: Constraint<number>;
@@ -386,6 +404,16 @@ export interface IDeviceRemoval {
deviceId: string;
}
+export type CustomLists = Array<ICustomList>;
+
+export interface ICustomList {
+ id: string;
+ name: string;
+ locations: Array<RelayLocationGeographical>;
+}
+
+export type CustomListError = { type: 'name already exists' };
+
export interface ISettings {
allowLan: boolean;
autoConnect: boolean;
@@ -397,6 +425,7 @@ export interface ISettings {
bridgeState: BridgeState;
splitTunnel: SplitTunnelSettings;
obfuscationSettings: ObfuscationSettings;
+ customLists: CustomLists;
}
export type BridgeState = 'auto' | 'on' | 'off';
@@ -452,25 +481,51 @@ export function parseSocketAddress(socketAddrStr: string): ISocketAddress {
return socketAddress;
}
-export function relayLocationComponents(location: RelayLocation): string[] {
- if ('country' in location) {
- return [location.country];
- } else if ('city' in location) {
- return location.city;
- } else {
- return location.hostname;
+export function compareRelayLocationCount(lhs: RelayLocation, rhs: RelayLocation): boolean {
+ if (
+ ('count' in lhs || 'count' in rhs) &&
+ !('count' in lhs && 'count' in rhs && lhs.count === rhs.count)
+ ) {
+ return false;
}
+
+ return compareRelayLocation(lhs, rhs);
}
export function compareRelayLocation(lhs: RelayLocation, rhs: RelayLocation): boolean {
- const lhsComponents = relayLocationComponents(lhs);
- const rhsComponents = relayLocationComponents(rhs);
+ if (
+ ('customList' in lhs || 'customList' in rhs) &&
+ !('customList' in lhs && 'customList' in rhs && lhs.customList === rhs.customList)
+ ) {
+ return false;
+ }
- if (lhsComponents.length === rhsComponents.length) {
- return lhsComponents.every((value, index) => value === rhsComponents[index]);
- } else {
+ return compareRelayLocationGeographical(lhs, rhs);
+}
+
+export function compareRelayLocationGeographical(lhs: RelayLocation, rhs: RelayLocation): boolean {
+ if (
+ ('country' in lhs || 'country' in rhs) &&
+ !('country' in lhs && 'country' in rhs && lhs.country === rhs.country)
+ ) {
+ return false;
+ }
+
+ if (
+ ('city' in lhs || 'city' in rhs) &&
+ !('city' in lhs && 'city' in rhs && lhs.city === rhs.city)
+ ) {
return false;
}
+
+ if (
+ ('hostname' in lhs || 'hostname' in rhs) &&
+ !('hostname' in lhs && 'hostname' in rhs && lhs.hostname === rhs.hostname)
+ ) {
+ return false;
+ }
+
+ return true;
}
export function compareRelayLocationLoose(lhs?: RelayLocation, rhs?: RelayLocation) {
diff --git a/gui/src/shared/ipc-schema.ts b/gui/src/shared/ipc-schema.ts
index 265d546b5d..946b4fa99a 100644
--- a/gui/src/shared/ipc-schema.ts
+++ b/gui/src/shared/ipc-schema.ts
@@ -6,10 +6,12 @@ import {
AccountToken,
BridgeSettings,
BridgeState,
+ CustomListError,
DeviceEvent,
DeviceState,
IAccountData,
IAppVersionInfo,
+ ICustomList,
IDevice,
IDeviceRemoval,
IDnsOptions,
@@ -133,6 +135,11 @@ export const ipcSchema = {
relays: {
'': notifyRenderer<IRelayListWithEndpointData>(),
},
+ customLists: {
+ createCustomList: invoke<string, void | CustomListError>(),
+ deleteCustomList: invoke<string, void>(),
+ updateCustomList: invoke<ICustomList, void | CustomListError>(),
+ },
currentVersion: {
'': notifyRenderer<ICurrentAppVersionInfo>(),
displayedChangelog: send<void>(),
diff --git a/gui/src/shared/relay-location-builder.ts b/gui/src/shared/relay-location-builder.ts
index 14bf72b65f..7e585f9eaf 100644
--- a/gui/src/shared/relay-location-builder.ts
+++ b/gui/src/shared/relay-location-builder.ts
@@ -18,11 +18,11 @@ export default function makeLocationBuilder<T>(
return context;
},
city: (country: string, city: string) => {
- receiver({ only: { city: [country, city] } });
+ receiver({ only: { country, city } });
return context;
},
hostname: (country: string, city: string, hostname: string) => {
- receiver({ only: { hostname: [country, city, hostname] } });
+ receiver({ only: { country, city, hostname } });
return context;
},
any: () => {