diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2022-11-25 14:47:33 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-11-25 14:47:33 +0100 |
| commit | 044b3868dfa1bd8c4573624aecd4c17b053d256e (patch) | |
| tree | 2f1b8d921540a9736a96eac6ddba115624c04ac9 /gui/src/main | |
| parent | 1fcdf3c0ab63dd78fc491f0537a0a09a367b804c (diff) | |
| parent | 29e5fadc291946de824ea36fd94a0db197f42af7 (diff) | |
| download | mullvadvpn-044b3868dfa1bd8c4573624aecd4c17b053d256e.tar.xz mullvadvpn-044b3868dfa1bd8c4573624aecd4c17b053d256e.zip | |
Merge branch 'add-location-list-filter'
Diffstat (limited to 'gui/src/main')
| -rw-r--r-- | gui/src/main/index.ts | 36 | ||||
| -rw-r--r-- | gui/src/main/relay-list.ts | 121 |
2 files changed, 16 insertions, 141 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 94607766a0..320185abd8 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -7,7 +7,13 @@ import util from 'util'; import config from '../config.json'; import { hasExpired } from '../shared/account-expiry'; import { IWindowsApplication } from '../shared/application-types'; -import { DaemonEvent, DeviceEvent, ISettings, TunnelState } from '../shared/daemon-rpc-types'; +import { + DaemonEvent, + DeviceEvent, + IRelayListWithEndpointData, + ISettings, + TunnelState, +} from '../shared/daemon-rpc-types'; import { messages, relayLocations } from '../shared/gettext'; import { SYSTEM_PREFERRED_LOCALE_KEY } from '../shared/gui-settings-state'; import { ITranslations, MacOsScrollbarVisibility } from '../shared/ipc-schema'; @@ -40,7 +46,6 @@ import NotificationController, { } from './notification-controller'; import * as problemReport from './problem-report'; import ReconnectionBackoff from './reconnection-backoff'; -import RelayList from './relay-list'; import Settings, { SettingsDelegate } from './settings'; import TunnelStateHandler, { TunnelStateHandlerDelegate, @@ -75,7 +80,6 @@ class ApplicationMain private notificationController = new NotificationController(this); private version = new Version(this, this.daemonRpc, UPDATE_NOTIFICATION_DISABLED); private settings = new Settings(this, this.daemonRpc, this.version.currentVersion); - private relayList = new RelayList(); private userInterface?: UserInterface; private account: Account = new Account(this, this.daemonRpc); private tunnelState = new TunnelStateHandler(this); @@ -102,6 +106,8 @@ class ApplicationMain private navigationHistory?: IHistoryObject; + private relayList?: IRelayListWithEndpointData; + public run() { // Remove window animations to combat window flickering when opening window. Can be removed when // this issue has been resolved: https://github.com/electron/electron/issues/12130 @@ -514,11 +520,7 @@ class ApplicationMain // fetch relays try { - this.relayList.setRelays( - await this.daemonRpc.getRelayLocations(), - this.settings.relaySettings, - this.settings.bridgeState, - ); + this.setRelayList(await this.daemonRpc.getRelayLocations()); } catch (e) { const error = e as Error; log.error(`Failed to fetch relay locations: ${error.message}`); @@ -610,11 +612,7 @@ class ApplicationMain } else if ('settings' in daemonEvent) { this.setSettings(daemonEvent.settings); } else if ('relayList' in daemonEvent) { - this.relayList.setRelays( - daemonEvent.relayList, - this.settings.relaySettings, - this.settings.bridgeState, - ); + IpcMainEventChannel.relays.notify?.(daemonEvent.relayList); } else if ('appVersionInfo' in daemonEvent) { this.version.setLatestVersion(daemonEvent.appVersionInfo); } else if ('device' in daemonEvent) { @@ -652,10 +650,11 @@ class ApplicationMain if (windowsSplitTunneling) { void this.updateSplitTunnelingApplications(newSettings.splitTunnel.appsList); } + } - // since settings can have the relay constraints changed, the relay - // list should also be updated - this.relayList.updateSettings(newSettings.relaySettings, newSettings.bridgeState); + private setRelayList(relayList: IRelayListWithEndpointData) { + this.relayList = relayList; + IpcMainEventChannel.relays.notify?.(relayList); } private async updateSplitTunnelingApplications(appList: string[]): Promise<void> { @@ -677,10 +676,7 @@ class ApplicationMain settings: this.settings.all, isPerformingPostUpgrade: this.isPerformingPostUpgrade, deviceState: this.account.deviceState, - relayListPair: this.relayList.getProcessedRelays( - this.settings.relaySettings, - this.settings.bridgeState, - ), + relayList: this.relayList, currentVersion: this.version.currentVersion, upgradeVersion: this.version.upgradeVersion, guiSettings: this.settings.gui.state, diff --git a/gui/src/main/relay-list.ts b/gui/src/main/relay-list.ts deleted file mode 100644 index c7b4a1fff1..0000000000 --- a/gui/src/main/relay-list.ts +++ /dev/null @@ -1,121 +0,0 @@ -import { - BridgeState, - IRelayList, - IRelayListWithEndpointData, - liftConstraint, - RelaySettings, -} from '../shared/daemon-rpc-types'; -import { IRelayListPair } from '../shared/ipc-schema'; -import { IpcMainEventChannel } from './ipc-event-channel'; - -export default class RelayList { - private relays: IRelayListWithEndpointData = { - relayList: { - countries: [], - }, - wireguardEndpointData: { - portRanges: [], - udp2tcpPorts: [], - }, - }; - - public setRelays( - newRelayList: IRelayListWithEndpointData, - relaySettings: RelaySettings, - bridgeState: BridgeState, - ) { - this.relays = newRelayList; - - const processedRelays = this.processRelays(newRelayList, relaySettings, bridgeState); - IpcMainEventChannel.relays.notify?.(processedRelays); - } - - public updateSettings(relaySettings: RelaySettings, bridgeState: BridgeState) { - this.setRelays(this.relays, relaySettings, bridgeState); - } - - public getProcessedRelays(relaySettings: RelaySettings, bridgeState: BridgeState) { - return this.processRelays(this.relays, relaySettings, bridgeState); - } - - private processRelays( - relayList: IRelayListWithEndpointData, - relaySettings: RelaySettings, - bridgeState: BridgeState, - ): IRelayListPair { - const filteredRelays = this.processRelaysForPresentation(relayList.relayList, relaySettings); - const filteredBridges = this.processBridgesForPresentation(relayList.relayList, bridgeState); - - return { - relays: filteredRelays, - bridges: filteredBridges, - wireguardEndpointData: relayList.wireguardEndpointData, - }; - } - - private processRelaysForPresentation( - relayList: IRelayList, - relaySettings: RelaySettings, - ): IRelayList { - const tunnelProtocol = - 'normal' in relaySettings ? liftConstraint(relaySettings.normal.tunnelProtocol) : undefined; - - const filteredCountries = relayList.countries - .map((country) => ({ - ...country, - cities: country.cities - .map((city) => ({ - ...city, - relays: city.relays.filter((relay) => { - if (relay.endpointType != 'bridge') { - switch (tunnelProtocol) { - case 'openvpn': - return relay.endpointType == 'openvpn'; - - case 'wireguard': - return relay.endpointType == 'wireguard'; - - case 'any': { - const useMultihop = - 'normal' in relaySettings && - relaySettings.normal.wireguardConstraints.useMultihop; - return !useMultihop || relay.endpointType == 'wireguard'; - } - default: - return false; - } - } else { - return false; - } - }), - })) - .filter((city) => city.relays.length > 0), - })) - .filter((country) => country.cities.length > 0); - - return { countries: filteredCountries }; - } - - private processBridgesForPresentation( - relayList: IRelayList, - bridgeState: BridgeState, - ): IRelayList { - if (bridgeState === 'on') { - const filteredCountries = relayList.countries - .map((country) => ({ - ...country, - cities: country.cities - .map((city) => ({ - ...city, - relays: city.relays.filter((relay) => relay.endpointType == 'bridge'), - })) - .filter((city) => city.relays.length > 0), - })) - .filter((country) => country.cities.length > 0); - - return { countries: filteredCountries }; - } else { - return { countries: [] }; - } - } -} |
