summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmīls Piņķis <emils@mullvad.net>2019-03-08 13:59:19 +0000
committerEmīls Piņķis <emils@mullvad.net>2019-03-08 13:59:19 +0000
commitd61d3b989ace19a74fe01673aff9e586f9f08132 (patch)
tree9a87e82c8f6f6cc483379969267bcb00729ef471
parente0e7fec6756f5afc2ad8b58a8ebf3b11a9122655 (diff)
parentb7e4c64b244382c2134fc00a754f0d39cdc65a53 (diff)
downloadmullvadvpn-d61d3b989ace19a74fe01673aff9e586f9f08132.tar.xz
mullvadvpn-d61d3b989ace19a74fe01673aff9e586f9f08132.zip
Merge branch 'filter-relays-in-gui'
-rw-r--r--gui/src/main/daemon-rpc.ts16
-rw-r--r--gui/src/main/index.ts54
-rw-r--r--gui/src/shared/daemon-rpc-types.ts20
-rw-r--r--mullvad-daemon/src/relays.rs1
4 files changed, 85 insertions, 6 deletions
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts
index 73c23b7158..f3e4d5a144 100644
--- a/gui/src/main/daemon-rpc.ts
+++ b/gui/src/main/daemon-rpc.ts
@@ -136,6 +136,20 @@ const relayListSchema = partialObject({
ipv4_addr_in: string,
include_in_country: boolean,
weight: number,
+ tunnels: partialObject({
+ openvpn: arrayOf(
+ partialObject({
+ port: number,
+ protocol: string,
+ }),
+ ),
+ wireguard: arrayOf(
+ partialObject({
+ port_ranges: arrayOf(arrayOf(number)),
+ public_key: string,
+ }),
+ ),
+ }),
}),
),
}),
@@ -343,7 +357,7 @@ export class DaemonRpc {
try {
return camelCaseObjectKeys(validate(relayListSchema, response)) as IRelayList;
} catch (error) {
- throw new ResponseParseError('Invalid response from get_relay_locations', error);
+ throw new ResponseParseError(`Invalid response from get_relay_locations: ${error}`, error);
}
}
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index 6bf46b2bdd..87bd2d8165 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -10,7 +10,9 @@ import {
IAppVersionInfo,
ILocation,
IRelayList,
+ IRelayListHostname,
ISettings,
+ RelaySettings,
RelaySettingsUpdate,
TunnelStateTransition,
} from '../shared/daemon-rpc-types';
@@ -375,7 +377,7 @@ class ApplicationMain {
// fetch relays
try {
- this.setRelays(await this.daemonRpc.getRelayLocations());
+ this.setRelays(await this.daemonRpc.getRelayLocations(), this.settings.relaySettings);
} catch (error) {
log.error(`Failed to fetch relay locations: ${error.message}`);
@@ -529,6 +531,10 @@ class ApplicationMain {
if (this.windowController) {
IpcMainEventChannel.settings.notify(this.windowController.webContents, newSettings);
}
+
+ // since settings can have the relay constraints changed, the relay
+ // list should also be updated
+ this.setRelays(this.relays, newSettings.relaySettings);
}
private setLocation(newLocation: ILocation) {
@@ -539,20 +545,60 @@ class ApplicationMain {
}
}
- private setRelays(newRelayList: IRelayList) {
+ private setRelays(newRelayList: IRelayList, relaySettings: RelaySettings) {
this.relays = newRelayList;
+ const filteredRelays = this.processRelaysForPresentation(newRelayList, relaySettings);
if (this.windowController) {
- IpcMainEventChannel.relays.notify(this.windowController.webContents, newRelayList);
+ IpcMainEventChannel.relays.notify(this.windowController.webContents, filteredRelays);
}
}
+ //
+ private processRelaysForPresentation(
+ relayList: IRelayList,
+ relaySettings: RelaySettings,
+ ): IRelayList {
+ // TODO: once wireguard is stable, by default we should only filter by
+ // hasToHaveOpenvpn || hasToHaveWg, until then, only filter wireguard
+ // relays if tunnel constraints specify wireguard tunnels.
+ const hasOpenVpnTunnels = (relay: IRelayListHostname): boolean => {
+ return relay.tunnels.openvpn.length > 0;
+ };
+ const hasWireguardTunnels = (relay: IRelayListHostname): boolean =>
+ relay.tunnels.wireguard.length > 0;
+ let fnHasWantedTunnels = hasOpenVpnTunnels;
+
+ if ('normal' in relaySettings) {
+ const tunnelConstraints = relaySettings.normal.tunnel;
+ if (tunnelConstraints !== 'any' && 'wireguard' in tunnelConstraints.only) {
+ fnHasWantedTunnels = hasWireguardTunnels;
+ }
+ }
+
+ return {
+ countries: relayList.countries.map((country) => {
+ return {
+ ...country,
+ cities: country.cities
+ .map((city) => {
+ return {
+ ...city,
+ relays: city.relays.filter(fnHasWantedTunnels),
+ };
+ })
+ .filter((city) => city.relays.length > 0),
+ };
+ }),
+ };
+ }
+
private startRelaysPeriodicUpdates() {
log.debug('Start relays periodic updates');
const handler = async () => {
try {
- this.setRelays(await this.daemonRpc.getRelayLocations());
+ this.setRelays(await this.daemonRpc.getRelayLocations(), this.settings.relaySettings);
} catch (error) {
log.error(`Failed to fetch relay locations: ${error.message}`);
}
diff --git a/gui/src/shared/daemon-rpc-types.ts b/gui/src/shared/daemon-rpc-types.ts
index a2cd296c0c..4582a66549 100644
--- a/gui/src/shared/daemon-rpc-types.ts
+++ b/gui/src/shared/daemon-rpc-types.ts
@@ -154,6 +154,26 @@ export interface IRelayListHostname {
ipv4AddrIn: string;
includeInCountry: boolean;
weight: number;
+ tunnels: IRelayTunnels;
+}
+
+export interface IRelayTunnels {
+ openvpn: IOpenVpnTunnelData[];
+ wireguard: IWireguardTunnelData[];
+}
+
+export interface IOpenVpnTunnelData {
+ port: number;
+ protocol: RelayProtocol;
+}
+
+export interface IWireguardTunnelData {
+ // Port ranges are an array of pairs, such as [[53,53], [10_000, 60_000]],
+ // which in this case translates that the specific tunnel can be connected on
+ // port 53 and ports 10'000 through 60'000.
+ portRanges: Array<[number, number]>;
+ // Public key of the tunnel.
+ publicKey: string;
}
export interface ITunnelOptions {
diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs
index b38ba42cfc..695f5c48fa 100644
--- a/mullvad-daemon/src/relays.rs
+++ b/mullvad-daemon/src/relays.rs
@@ -99,7 +99,6 @@ impl ParsedRelays {
longitude,
});
relays.push(relay_with_location);
- relay.tunnels.clear();
}
}
}