diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2017-12-13 15:33:20 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2017-12-19 14:12:42 +0100 |
| commit | b02baf60e26a2e5794dc145e72047b1005f0c2d3 (patch) | |
| tree | af41ec8e77d214f0e832000b6d88c573c3ce1885 | |
| parent | e35c46c9e0d4fcd8b146be523550e2a88ff1aecf (diff) | |
| download | mullvadvpn-b02baf60e26a2e5794dc145e72047b1005f0c2d3.tar.xz mullvadvpn-b02baf60e26a2e5794dc145e72047b1005f0c2d3.zip | |
Drop hardcoded servers in favor of relay locations
| -rw-r--r-- | app/components/Connect.js | 56 | ||||
| -rw-r--r-- | app/config.json | 284 | ||||
| -rw-r--r-- | app/containers/ConnectPage.js | 1 | ||||
| -rw-r--r-- | app/lib/backend.js | 31 | ||||
| -rw-r--r-- | test/components/Connect.spec.js | 11 |
5 files changed, 29 insertions, 354 deletions
diff --git a/app/components/Connect.js b/app/components/Connect.js index 0975e18a1a..5267f3e190 100644 --- a/app/components/Connect.js +++ b/app/components/Connect.js @@ -7,7 +7,6 @@ import { Layout, Container, Header } from './Layout'; import { BackendError } from '../lib/backend'; import ExternalLinkSVG from '../assets/images/icon-extLink.svg'; -import type { ServerInfo } from '../lib/backend'; import type { HeaderBarStyle } from './HeaderBar'; import type { ConnectionReduxState } from '../redux/connection/reducers'; import type { SettingsReduxState } from '../redux/settings/reducers'; @@ -23,7 +22,6 @@ export type ConnectProps = { onCopyIP: () => void, onDisconnect: () => void, onExternalLink: (type: string) => void, - getServerInfo: (relayLocation: RelayLocation) => ?ServerInfo }; @@ -94,45 +92,45 @@ export default class Connect extends Component { ); } - _getServerInfo(): ServerInfo { + _findRelayName(relay: RelayLocation): ?string { + const { countries } = this.props.settings.relayLocations; + const countryPredicate = (countryCode) => (country) => country.code === countryCode; + + if(relay.country) { + const country = countries.find(countryPredicate(relay.country)); + if(country) { + return country.name; + } + } else if(relay.city) { + const [countryCode, cityCode] = relay.city; + const country = countries.find(countryPredicate(countryCode)); + if(country) { + const city = country.cities.find((city) => city.code === cityCode); + if(city) { + return city.name; + } + } + } + return null; + } + + _getLocationName(): string { const { relaySettings } = this.props.settings; if(relaySettings.normal) { const location = relaySettings.normal.location; if(location === 'any') { - return { - address: '', - name: 'Automatic', - country: 'Automatic', - city: 'Automatic', - country_code: 'any', - city_code: 'any', - location: [0, 0], - }; + return 'Automatic'; } else { - const serverInfo = this.props.getServerInfo(location); - if(!serverInfo) { - throw new Error('Server info is not available for: ' + JSON.stringify(location)); - } - return serverInfo; + return this._findRelayName(location) || 'Unknown'; } } else if(relaySettings.custom_tunnel_endpoint) { - return { - address: relaySettings.custom_tunnel_endpoint.host, - name: 'Custom', - country: 'Custom', - city: '', - country_code: 'auto', - city_code: 'auto', - location: [0, 0], - }; + return 'Custom'; } else { throw new Error('Unsupported relay settings.'); } } renderMap(): React.Element<*> { - const serverInfo = this._getServerInfo(); - let [ isConnecting, isConnected, isDisconnected ] = [false, false, false]; switch(this.props.connection.status) { case 'connecting': isConnecting = true; break; @@ -246,7 +244,7 @@ export default class Connect extends Component { <div className="connect__server-label">Connect to</div> <div className="connect__server-value"> - <div className="connect__server-name">{ serverInfo.name }</div> + <div className="connect__server-name">{ this._getLocationName() }</div> </div> </div> diff --git a/app/config.json b/app/config.json index 73eb310d3a..b897b5da4a 100644 --- a/app/config.json +++ b/app/config.json @@ -9,287 +9,5 @@ "faq": "https://mullvad.net/faq/", "guides": "https://mullvad.net/guides/", "supportEmail": "mailto:support@mullvad.net" - }, - "defaultServer": "193.138.218.135", - "servers": [ - { - "address": "168.1.6.5", - "name": "Australia", - "city": "Sydney", - "country": "Australia", - "country_code": "au", - "city_code": "syd", - "location": [0, 0] - }, - { - "address": "217.64.127.138", - "name": "Austria", - "city": "Wien", - "country": "Austria", - "country_code": "at", - "city_code": "vie", - "location": [0, 0] - }, - { - "address": "185.104.186.202", - "name": "Belgium", - "city": "Brussels", - "country": "Belgium", - "country_code": "be", - "city_code": "bru", - "location": [0, 0] - }, - { - "address": "185.94.192.42", - "name": "Bulgaria", - "city": "Sofia", - "country": "Bulgaria", - "country_code": "bg", - "city_code": "sof", - "location": [0, 0] - }, - { - "address": "162.219.176.250", - "name": "Canada", - "city": "Toronto", - "country": "Canada", - "country_code": "ca", - "city_code": "tor", - "location": [ - 45.42153, - -75.697193 - ] - }, - { - "address": "185.156.174.146", - "name": "Czech Republic", - "city": "Prague", - "country": "Czech Republic", - "country_code": "cz", - "city_code": "prg", - "location": [0, 0] - }, - { - "address": "82.103.140.213", - "name": "Denmark", - "city": "Copenhagen", - "country": "Denmark", - "country_code": "dk", - "city_code": "cph", - "location": [ - 55.6760968, - 12.5683371 - ] - }, - { - "address": "185.103.110.69", - "name": "Finland", - "city": "Helsinki", - "country": "Finland", - "country_code": "fi", - "city_code": "hel", - "location": [0, 0] - }, - { - "address": "185.156.173.218", - "name": "France", - "city": "Paris", - "country": "France", - "country_code": "fr", - "city_code": "par", - "location": [0, 0] - }, - { - "address": "89.249.64.146", - "name": "Germany", - "city": "Berlin", - "country": "Germany", - "country_code": "de", - "city_code": "ber", - "location": [ - 54.033333, - 10.45 - ] - }, - { - "address": "161.202.48.245", - "name": "Hong Kong", - "city": "Hong Kong", - "country": "Hong Kong", - "country_code": "hk", - "city_code": "hkg", - "location": [0, 0] - }, - { - "address": "185.189.114.10", - "name": "Hungary", - "city": "Budapest", - "country": "Hungary", - "country_code": "hu", - "city_code": "bud", - "location": [0, 0] - }, - { - "address": "213.184.122.34", - "name": "Israel", - "city": "Petach-Tikva", - "country": "Israel", - "country_code": "il", - "city_code": "pet", - "location": [0, 0] - }, - { - "address": "217.64.113.180", - "name": "Italy", - "city": "Milan", - "country": "Italy", - "country_code": "it", - "city_code": "mil", - "location": [0, 0] - }, - { - "address": "161.202.144.203", - "name": "Japan", - "city": "Tokyo", - "country": "Japan", - "country_code": "jp", - "city_code": "tyo", - "location": [0, 0] - }, - { - "address": "185.65.134.140", - "name": "Netherlands", - "city": "Amsterdam", - "country": "Netherlands", - "country_code": "nl", - "city_code": "ams", - "location": [ - 52.3702157, - 4.895167900000001 - ] - }, - { - "address": "31.169.51.154", - "name": "Norway", - "city": "Oslo", - "country": "Norway", - "country_code": "no", - "city_code": "osl", - "location": [ - 59.9138688, - 10.7522454 - ] - }, - { - "address": "212.7.217.30", - "name": "Poland", - "city": "Warsaw", - "country": "Poland", - "country_code": "pl", - "city_code": "waw", - "location": [0, 0] - }, - { - "address": "185.45.13.10", - "name": "Romania", - "city": "Bucharest", - "country": "Romania", - "country_code": "ro", - "city_code": "buh", - "location": [ - 44.4267674, - 26.1025384 - ] - }, - { - "address": "103.57.72.30", - "name": "Singapore", - "city": "Singapore", - "country": "Singapore", - "country_code": "sg", - "city_code": "sin", - "location": [ - 1.352083, - 103.819836 - ] - }, - { - "address": "89.238.178.34", - "name": "Spain", - "city": "Madrid", - "country": "Spain", - "country_code": "es", - "city_code": "mad", - "location": [ - 40.4167754, - -3.7037902 - ] - }, - { - "address": "185.213.152.132", - "name": "Sweden - Helsingborg", - "city": "Helsingborg", - "country": "Sweden", - "country_code": "se", - "city_code": "hel", - "location": [0, 0] - }, - { - "address": "193.138.218.135", - "name": "Sweden - Malmö", - "city": "Malmö", - "country": "Sweden", - "country_code": "se", - "city_code": "mma", - "location": [0, 0] - }, - { - "address": "185.65.135.143", - "name": "Sweden - Stockholm", - "city": "Stockholm", - "country": "Sweden", - "country_code": "se", - "city_code": "sto", - "location": [0, 0] - }, - { - "address": "179.43.128.170", - "name": "Switzerland", - "city": "Zürich", - "country": "Switzerland", - "country_code": "ch", - "city_code": "zrh", - "location": [0, 0] - }, - { - "address": "185.16.85.170", - "name": "United Kingdom", - "city": "London", - "country": "United Kingdom", - "country_code": "gb", - "city_code": "lon", - "location": [ - 51.5073509, - -0.1277583 - ] - }, - { - "address": "173.199.80.130", - "name": "USA - Los Angeles", - "city": "Los Angeles", - "country": "USA", - "country_code": "us", - "city_code": "lax", - "location": [0, 0] - }, - { - "address": "38.132.107.138", - "name": "USA - New York", - "city": "New York", - "country": "USA", - "country_code": "us", - "city_code": "nyc", - "location": [0, 0] - } - ] + } } diff --git a/app/containers/ConnectPage.js b/app/containers/ConnectPage.js index 3d698b371e..6bcfc40cfe 100644 --- a/app/containers/ConnectPage.js +++ b/app/containers/ConnectPage.js @@ -41,7 +41,6 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: SharedRouteProps) => disconnect(backend); }, onExternalLink: (type) => open(links[type]), - getServerInfo: (relayLocation) => backend.serverInfo(relayLocation), }; }; diff --git a/app/lib/backend.js b/app/lib/backend.js index 6e79188043..3099a7f129 100644 --- a/app/lib/backend.js +++ b/app/lib/backend.js @@ -2,7 +2,6 @@ import log from 'electron-log'; import EventEmitter from 'events'; -import { servers } from '../config'; import { IpcFacade, RealIpc } from './ipc-facade'; import accountActions from '../redux/account/actions'; import connectionActions from '../redux/connection/actions'; @@ -10,21 +9,11 @@ import settingsActions from '../redux/settings/actions'; import { push } from 'react-router-redux'; import type { ReduxStore } from '../redux/store'; -import type { AccountToken, BackendState, RelayLocation, RelaySettingsUpdate } from './ipc-facade'; +import type { AccountToken, BackendState, RelaySettingsUpdate } from './ipc-facade'; import type { ConnectionState } from '../redux/connection/reducers'; export type ErrorType = 'NO_CREDIT' | 'NO_INTERNET' | 'INVALID_ACCOUNT' | 'NO_ACCOUNT'; -export type ServerInfo = { - address: string, - name: string, - city: string, - country: string, - country_code: string, - city_code: string, - location: [number, number], -}; - export class BackendError extends Error { type: ErrorType; title: string; @@ -179,24 +168,6 @@ export class Backend { await this._updateAccountHistory(); } - serverInfo(relay: RelayLocation): ?ServerInfo { - const list: Array<ServerInfo> = servers; - if(relay.country) { - const country = relay.country; - return list.find((server) => { - return server.country_code === country; - }); - } else if(relay.city) { - const [country_code, city_code] = relay.city; - return list.find((server) => { - return server.country_code === country_code && - server.city_code === city_code; - }); - } else { - return null; - } - } - async login(accountToken: AccountToken): Promise<void> { log.debug('Attempting to login'); diff --git a/test/components/Connect.spec.js b/test/components/Connect.spec.js index 17ede98454..8257bf4e54 100644 --- a/test/components/Connect.spec.js +++ b/test/components/Connect.spec.js @@ -126,16 +126,6 @@ describe('components/Connect', () => { countries: [], }, }, - getServerInfo: (location) => { - return servers.find((server) => { - if(location.city) { - const [country_code, city_code] = location.city; - return (server.city_code === city_code && - server.country_code === country_code); - } - return false; - }); - }, }); const locationSwitcher = component.find('.connect__server'); @@ -173,7 +163,6 @@ const defaultProps: ConnectProps = { onCopyIP: () => {}, onDisconnect: () => {}, onExternalLink: () => {}, - getServerInfo: _ => null, accountExpiry: '', settings: { relaySettings: { |
