diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2019-09-12 12:54:00 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2019-09-12 12:54:00 +0200 |
| commit | d21b83805b8bfca7a89aad3419347d0cc2b391ad (patch) | |
| tree | 0948bb07f104c92b2ad5f5054f6a2a26c44ec74a /gui/src/shared | |
| parent | ff18ea9d2c9e3d99ea58946cbdd5e1ed87829f8f (diff) | |
| parent | 657a1036375f2c253901fb19a987f517d9125074 (diff) | |
| download | mullvadvpn-d21b83805b8bfca7a89aad3419347d0cc2b391ad.tar.xz mullvadvpn-d21b83805b8bfca7a89aad3419347d0cc2b391ad.zip | |
Merge branch 'select-bridge-location'
Diffstat (limited to 'gui/src/shared')
| -rw-r--r-- | gui/src/shared/daemon-rpc-types.ts | 61 | ||||
| -rw-r--r-- | gui/src/shared/ipc-event-channel.ts | 16 |
2 files changed, 41 insertions, 36 deletions
diff --git a/gui/src/shared/daemon-rpc-types.ts b/gui/src/shared/daemon-rpc-types.ts index b16355af8f..86dd5ab9b2 100644 --- a/gui/src/shared/daemon-rpc-types.ts +++ b/gui/src/shared/daemon-rpc-types.ts @@ -50,11 +50,11 @@ 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 Constraint<T> = 'any' | { only: T }; +export type LiftedConstraint<T> = 'any' | T; + +export function liftConstraint<T>(constraint: Constraint<T>): LiftedConstraint<T> { + return constraint === 'any' ? constraint : constraint.only; } export type ProxyType = 'shadowsocks' | 'custom'; @@ -106,27 +106,19 @@ export type RelayLocation = | { country: string }; export interface IOpenVpnConstraints { - port: 'any' | { only: number }; - protocol: 'any' | { only: RelayProtocol }; + port: Constraint<number>; + protocol: Constraint<RelayProtocol>; } export interface IWireguardConstraints { - port: 'any' | { only: number }; + port: Constraint<number>; } export type TunnelProtocol = 'wireguard' | 'openvpn'; interface IRelaySettingsNormal<OpenVpn, Wireguard> { - location: - | 'any' - | { - only: RelayLocation; - }; - tunnelProtocol: - | 'any' - | { - only: TunnelProtocol; - }; + location: Constraint<RelayLocation>; + tunnelProtocol: Constraint<TunnelProtocol>; openvpnConstraints: OpenVpn; wireguardConstraints: Wireguard; } @@ -311,11 +303,7 @@ export interface IWireguardPublicKey { export type BridgeState = 'auto' | 'on' | 'off'; export interface IBridgeConstraints { - location: - | 'any' - | { - only: RelayLocation; - }; + location: Constraint<RelayLocation>; } export type BridgeSettings = { normal: IBridgeConstraints } | { custom: ProxySettings }; @@ -339,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), }; |
