summaryrefslogtreecommitdiffhomepage
path: root/gui/src/shared
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2019-09-10 14:35:00 +0200
committerAndrej Mihajlov <and@mullvad.net>2019-09-12 12:50:51 +0200
commit57f5d8f246fa688a36e3138cbbcd51dd95fdf7ea (patch)
treefc85b595edbdda91e5f7e894d7ed536d0ac69ba8 /gui/src/shared
parentef20b724201e5c374e6080298974bc8e97818cf2 (diff)
downloadmullvadvpn-57f5d8f246fa688a36e3138cbbcd51dd95fdf7ea.tar.xz
mullvadvpn-57f5d8f246fa688a36e3138cbbcd51dd95fdf7ea.zip
Add bridge selector
Diffstat (limited to 'gui/src/shared')
-rw-r--r--gui/src/shared/daemon-rpc-types.ts27
-rw-r--r--gui/src/shared/ipc-event-channel.ts16
2 files changed, 30 insertions, 13 deletions
diff --git a/gui/src/shared/daemon-rpc-types.ts b/gui/src/shared/daemon-rpc-types.ts
index c2368364ac..86dd5ab9b2 100644
--- a/gui/src/shared/daemon-rpc-types.ts
+++ b/gui/src/shared/daemon-rpc-types.ts
@@ -327,17 +327,22 @@ export function parseSocketAddress(socketAddrStr: string): ISocketAddress {
return socketAddress;
}
-export function compareRelayLocation(lhs: RelayLocation, rhs: RelayLocation) {
- if ('country' in lhs && 'country' in rhs && lhs.country && rhs.country) {
- return lhs.country === rhs.country;
- } else if ('city' in lhs && 'city' in rhs && lhs.city && rhs.city) {
- return lhs.city[0] === rhs.city[0] && lhs.city[1] === rhs.city[1];
- } else if ('hostname' in lhs && 'hostname' in rhs && lhs.hostname && rhs.hostname) {
- return (
- lhs.hostname[0] === rhs.hostname[0] &&
- lhs.hostname[1] === rhs.hostname[1] &&
- lhs.hostname[2] === rhs.hostname[2]
- );
+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 compareRelayLocation(lhs: RelayLocation, rhs: RelayLocation): boolean {
+ const lhsComponents = relayLocationComponents(lhs);
+ const rhsComponents = relayLocationComponents(rhs);
+
+ if (lhsComponents.length === rhsComponents.length) {
+ return lhsComponents.every((value, index) => value === rhsComponents[index]);
} else {
return false;
}
diff --git a/gui/src/shared/ipc-event-channel.ts b/gui/src/shared/ipc-event-channel.ts
index 7bdeb6e759..3df81c2eea 100644
--- a/gui/src/shared/ipc-event-channel.ts
+++ b/gui/src/shared/ipc-event-channel.ts
@@ -15,6 +15,7 @@ import {
ISettings,
IWireguardPublicKey,
KeygenEvent,
+ RelayLocation,
RelaySettingsUpdate,
TunnelState,
} from './daemon-rpc-types';
@@ -29,12 +30,18 @@ export interface IAppStateSnapshot {
settings: ISettings;
location?: ILocation;
relays: IRelayList;
+ bridges: IRelayList;
currentVersion: ICurrentAppVersionInfo;
upgradeVersion: IAppUpgradeInfo;
guiSettings: IGuiSettingsState;
wireguardPublicKey?: IWireguardPublicKey;
}
+export interface IRelayListPair {
+ relays: IRelayList;
+ bridges: IRelayList;
+}
+
interface ISender<T> {
notify(webContents: WebContents, value: T): void;
}
@@ -64,6 +71,7 @@ interface ISettingsMethods extends IReceiver<ISettings> {
setBridgeState(state: BridgeState): Promise<void>;
setOpenVpnMssfix(mssfix?: number): Promise<void>;
updateRelaySettings(update: RelaySettingsUpdate): Promise<void>;
+ updateBridgeLocation(location: RelayLocation): Promise<void>;
}
interface ISettingsHandlers extends ISender<ISettings> {
@@ -73,6 +81,7 @@ interface ISettingsHandlers extends ISender<ISettings> {
handleBridgeState(fn: (state: BridgeState) => Promise<void>): void;
handleOpenVpnMssfix(fn: (mssfix?: number) => Promise<void>): void;
handleUpdateRelaySettings(fn: (update: RelaySettingsUpdate) => Promise<void>): void;
+ handleUpdateBridgeLocation(fn: (location: RelayLocation) => Promise<void>): void;
}
interface IGuiSettingsMethods extends IReceiver<IGuiSettingsState> {
@@ -145,6 +154,7 @@ const SET_BLOCK_WHEN_DISCONNECTED = 'set-block-when-disconnected';
const SET_BRIDGE_STATE = 'set-bridge-state';
const SET_OPENVPN_MSSFIX = 'set-openvpn-mssfix';
const UPDATE_RELAY_SETTINGS = 'update-relay-settings';
+const UPDATE_BRIDGE_LOCATION = 'update-bridge-location';
const LOCATION_CHANGED = 'location-changed';
const RELAYS_CHANGED = 'relays-changed';
@@ -213,13 +223,14 @@ export class IpcRendererEventChannel {
setBridgeState: requestSender(SET_BRIDGE_STATE),
setOpenVpnMssfix: requestSender(SET_OPENVPN_MSSFIX),
updateRelaySettings: requestSender(UPDATE_RELAY_SETTINGS),
+ updateBridgeLocation: requestSender(UPDATE_BRIDGE_LOCATION),
};
public static location: IReceiver<ILocation> = {
listen: listen(LOCATION_CHANGED),
};
- public static relays: IReceiver<IRelayList> = {
+ public static relays: IReceiver<IRelayListPair> = {
listen: listen(RELAYS_CHANGED),
};
@@ -302,9 +313,10 @@ export class IpcMainEventChannel {
handleBridgeState: requestHandler(SET_BRIDGE_STATE),
handleOpenVpnMssfix: requestHandler(SET_OPENVPN_MSSFIX),
handleUpdateRelaySettings: requestHandler(UPDATE_RELAY_SETTINGS),
+ handleUpdateBridgeLocation: requestHandler(UPDATE_BRIDGE_LOCATION),
};
- public static relays: ISender<IRelayList> = {
+ public static relays: ISender<IRelayListPair> = {
notify: sender(RELAYS_CHANGED),
};